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 kColor = SK_ColorRED; |
23 const int kDefaultMargin = 6; | 23 const int kMargin = 6; |
24 | 24 |
25 class SizedBubbleDelegateView : public BubbleDelegateView { | 25 class SizedBubbleDelegateView : public BubbleDelegateView { |
26 public: | 26 public: |
27 SizedBubbleDelegateView(View* anchor_view); | 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: |
(...skipping 18 matching lines...) Expand all Loading... |
52 protected: | 52 protected: |
53 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) OVERRIDE; | 53 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) OVERRIDE; |
54 | 54 |
55 private: | 55 private: |
56 gfx::Rect monitor_bounds_; | 56 gfx::Rect monitor_bounds_; |
57 | 57 |
58 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); | 58 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); |
59 }; | 59 }; |
60 | 60 |
61 TestBubbleFrameView::TestBubbleFrameView() | 61 TestBubbleFrameView::TestBubbleFrameView() |
62 : BubbleFrameView(gfx::Insets(kDefaultMargin, | 62 : BubbleFrameView(gfx::Insets(kMargin, kMargin, kMargin, kMargin)), |
63 kDefaultMargin, | |
64 kDefaultMargin, | |
65 kDefaultMargin), | |
66 new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW)), | |
67 monitor_bounds_(gfx::Rect(0, 0, 1000, 1000)) { | 63 monitor_bounds_(gfx::Rect(0, 0, 1000, 1000)) { |
68 bubble_border()->set_background_color(kBackgroundColor); | 64 SetBubbleBorder(new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor)); |
69 } | 65 } |
70 | 66 |
71 TestBubbleFrameView::~TestBubbleFrameView() {} | 67 TestBubbleFrameView::~TestBubbleFrameView() {} |
72 | 68 |
73 gfx::Rect TestBubbleFrameView::GetMonitorBounds(const gfx::Rect& rect) { | 69 gfx::Rect TestBubbleFrameView::GetMonitorBounds(const gfx::Rect& rect) { |
74 return monitor_bounds_; | 70 return monitor_bounds_; |
75 } | 71 } |
76 | 72 |
77 } // namespace | 73 } // namespace |
78 | 74 |
79 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { | 75 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { |
80 TestBubbleFrameView frame; | 76 TestBubbleFrameView frame; |
81 EXPECT_EQ(kArrow, frame.bubble_border()->arrow_location()); | 77 EXPECT_EQ(kArrow, frame.bubble_border()->arrow_location()); |
82 EXPECT_EQ(kBackgroundColor, frame.bubble_border()->background_color()); | 78 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); |
83 | 79 |
84 int margin_x = frame.content_margins().left(); | 80 int margin_x = frame.content_margins().left(); |
85 int margin_y = frame.content_margins().top(); | 81 int margin_y = frame.content_margins().top(); |
86 gfx::Insets insets = frame.bubble_border()->GetInsets(); | 82 gfx::Insets insets = frame.bubble_border()->GetInsets(); |
87 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); | 83 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); |
88 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); | 84 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); |
89 } | 85 } |
90 | 86 |
91 TEST_F(BubbleFrameViewTest, NonClientHitTest) { | 87 TEST_F(BubbleFrameViewTest, NonClientHitTest) { |
92 // Create the anchor and parent widgets. | 88 // Create the anchor and parent widgets. |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 gfx::Size(500, 500), // |client_size| | 366 gfx::Size(500, 500), // |client_size| |
371 true); // |adjust_if_offscreen| | 367 true); // |adjust_if_offscreen| |
372 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, | 368 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, |
373 frame.bubble_border()->arrow_location()); | 369 frame.bubble_border()->arrow_location()); |
374 EXPECT_EQ(window_bounds.bottom(), 1000); | 370 EXPECT_EQ(window_bounds.bottom(), 1000); |
375 EXPECT_EQ(window_bounds.y() + | 371 EXPECT_EQ(window_bounds.y() + |
376 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); | 372 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); |
377 } | 373 } |
378 | 374 |
379 } // namespace views | 375 } // namespace views |
OLD | NEW |