| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/hit_test.h" | 5 #include "ui/base/hit_test.h" |
| 6 #include "ui/gfx/insets.h" | 6 #include "ui/gfx/insets.h" |
| 7 #include "ui/views/bubble/bubble_border.h" | 7 #include "ui/views/bubble/bubble_border.h" |
| 8 #include "ui/views/bubble/bubble_delegate.h" | 8 #include "ui/views/bubble/bubble_delegate.h" |
| 9 #include "ui/views/bubble/bubble_frame_view.h" | 9 #include "ui/views/bubble/bubble_frame_view.h" |
| 10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
| 11 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
| 12 | 12 |
| 13 namespace views { | 13 namespace views { |
| 14 | 14 |
| 15 typedef ViewsTestBase BubbleFrameViewTest; | 15 typedef ViewsTestBase BubbleFrameViewTest; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const BubbleBorder::ArrowLocation kArrow = BubbleBorder::TOP_LEFT; | 19 const BubbleBorder::ArrowLocation kArrow = BubbleBorder::TOP_LEFT; |
| 20 const int kBubbleWidth = 200; | 20 const int kBubbleWidth = 200; |
| 21 const int kBubbleHeight = 200; | 21 const int kBubbleHeight = 200; |
| 22 const SkColor kBackgroundColor = SK_ColorRED; | 22 const SkColor kBackgroundColor = SK_ColorRED; |
| 23 const int kDefaultMargin = 6; | 23 const int kDefaultMargin = 6; |
| 24 | 24 |
| 25 class SizedBubbleDelegateView : public BubbleDelegateView { | 25 class SizedBubbleDelegateView : public BubbleDelegateView { |
| 26 public: | 26 public: |
| 27 SizedBubbleDelegateView(); | 27 SizedBubbleDelegateView(View* anchor_view); |
| 28 virtual ~SizedBubbleDelegateView(); | 28 virtual ~SizedBubbleDelegateView(); |
| 29 | 29 |
| 30 // View overrides: | 30 // View overrides: |
| 31 virtual gfx::Size GetPreferredSize() OVERRIDE; | 31 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(SizedBubbleDelegateView); | 34 DISALLOW_COPY_AND_ASSIGN(SizedBubbleDelegateView); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 SizedBubbleDelegateView::SizedBubbleDelegateView() {} | 37 SizedBubbleDelegateView::SizedBubbleDelegateView(View* anchor_view) |
| 38 : BubbleDelegateView(anchor_view, BubbleBorder::TOP_LEFT) { |
| 39 } |
| 38 | 40 |
| 39 SizedBubbleDelegateView::~SizedBubbleDelegateView() {} | 41 SizedBubbleDelegateView::~SizedBubbleDelegateView() {} |
| 40 | 42 |
| 41 gfx::Size SizedBubbleDelegateView::GetPreferredSize() { | 43 gfx::Size SizedBubbleDelegateView::GetPreferredSize() { |
| 42 return gfx::Size(kBubbleWidth, kBubbleHeight); | 44 return gfx::Size(kBubbleWidth, kBubbleHeight); |
| 43 } | 45 } |
| 44 | 46 |
| 45 class TestBubbleFrameView : public BubbleFrameView { | 47 class TestBubbleFrameView : public BubbleFrameView { |
| 46 public: | 48 public: |
| 47 TestBubbleFrameView(); | 49 TestBubbleFrameView(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 EXPECT_EQ(kBackgroundColor, frame.bubble_border()->background_color()); | 82 EXPECT_EQ(kBackgroundColor, frame.bubble_border()->background_color()); |
| 81 | 83 |
| 82 int margin_x = frame.content_margins().left(); | 84 int margin_x = frame.content_margins().left(); |
| 83 int margin_y = frame.content_margins().top(); | 85 int margin_y = frame.content_margins().top(); |
| 84 gfx::Insets insets = frame.bubble_border()->GetInsets(); | 86 gfx::Insets insets = frame.bubble_border()->GetInsets(); |
| 85 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); | 87 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); |
| 86 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); | 88 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); |
| 87 } | 89 } |
| 88 | 90 |
| 89 TEST_F(BubbleFrameViewTest, NonClientHitTest) { | 91 TEST_F(BubbleFrameViewTest, NonClientHitTest) { |
| 90 BubbleDelegateView* delegate = new SizedBubbleDelegateView(); | 92 // Create the anchor and parent widgets. |
| 93 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 94 scoped_ptr<Widget> anchor_widget(new Widget); |
| 95 anchor_widget->Init(params); |
| 96 anchor_widget->Show(); |
| 97 |
| 98 BubbleDelegateView* delegate = |
| 99 new SizedBubbleDelegateView(anchor_widget->GetContentsView()); |
| 91 Widget* widget(BubbleDelegateView::CreateBubble(delegate)); | 100 Widget* widget(BubbleDelegateView::CreateBubble(delegate)); |
| 92 delegate->Show(); | 101 delegate->Show(); |
| 93 gfx::Point kPtInBound(100, 100); | 102 gfx::Point kPtInBound(100, 100); |
| 94 gfx::Point kPtOutsideBound(1000, 1000); | 103 gfx::Point kPtOutsideBound(1000, 1000); |
| 95 BubbleFrameView* bubble_frame_view = delegate->GetBubbleFrameView(); | 104 BubbleFrameView* bubble_frame_view = delegate->GetBubbleFrameView(); |
| 96 EXPECT_EQ(HTCLIENT, bubble_frame_view->NonClientHitTest(kPtInBound)); | 105 EXPECT_EQ(HTCLIENT, bubble_frame_view->NonClientHitTest(kPtInBound)); |
| 97 EXPECT_EQ(HTNOWHERE, bubble_frame_view->NonClientHitTest(kPtOutsideBound)); | 106 EXPECT_EQ(HTNOWHERE, bubble_frame_view->NonClientHitTest(kPtOutsideBound)); |
| 98 widget->CloseNow(); | 107 widget->CloseNow(); |
| 99 RunPendingMessages(); | 108 RunPendingMessages(); |
| 100 } | 109 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 gfx::Size(500, 500), // |client_size| | 369 gfx::Size(500, 500), // |client_size| |
| 361 true); // |adjust_if_offscreen| | 370 true); // |adjust_if_offscreen| |
| 362 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, | 371 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, |
| 363 frame.bubble_border()->arrow_location()); | 372 frame.bubble_border()->arrow_location()); |
| 364 EXPECT_EQ(window_bounds.bottom(), 1000); | 373 EXPECT_EQ(window_bounds.bottom(), 1000); |
| 365 EXPECT_EQ(window_bounds.y() + | 374 EXPECT_EQ(window_bounds.y() + |
| 366 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); | 375 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); |
| 367 } | 376 } |
| 368 | 377 |
| 369 } // namespace views | 378 } // namespace views |
| OLD | NEW |