| 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/views/bubble/bubble_frame_view.h" | 5 #include "ui/views/bubble/bubble_frame_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "ui/gfx/geometry/insets.h" | 11 #include "ui/gfx/geometry/insets.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/views/bubble/bubble_border.h" | 14 #include "ui/views/bubble/bubble_border.h" |
| 15 #include "ui/views/controls/button/label_button.h" |
| 15 #include "ui/views/test/test_views.h" | 16 #include "ui/views/test/test_views.h" |
| 16 #include "ui/views/test/views_test_base.h" | 17 #include "ui/views/test/views_test_base.h" |
| 17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 18 #include "ui/views/widget/widget_delegate.h" | 19 #include "ui/views/widget/widget_delegate.h" |
| 19 | 20 |
| 20 namespace views { | 21 namespace views { |
| 21 | 22 |
| 22 typedef ViewsTestBase BubbleFrameViewTest; | 23 typedef ViewsTestBase BubbleFrameViewTest; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 54 gfx::Size(kPreferredClientWidth, kPreferredClientHeight)); | 55 gfx::Size(kPreferredClientWidth, kPreferredClientHeight)); |
| 55 contents_view->set_minimum_size( | 56 contents_view->set_minimum_size( |
| 56 gfx::Size(kMinimumClientWidth, kMinimumClientHeight)); | 57 gfx::Size(kMinimumClientWidth, kMinimumClientHeight)); |
| 57 contents_view->set_maximum_size( | 58 contents_view->set_maximum_size( |
| 58 gfx::Size(kMaximumClientWidth, kMaximumClientHeight)); | 59 gfx::Size(kMaximumClientWidth, kMaximumClientHeight)); |
| 59 contents_view_ = contents_view; | 60 contents_view_ = contents_view; |
| 60 } | 61 } |
| 61 return contents_view_; | 62 return contents_view_; |
| 62 } | 63 } |
| 63 | 64 |
| 65 bool ShouldShowCloseButton() const override { return should_show_close_; } |
| 66 void SetShouldShowCloseButton(bool should_show_close) { |
| 67 should_show_close_ = should_show_close; |
| 68 } |
| 69 |
| 64 private: | 70 private: |
| 65 Widget* widget_; | 71 Widget* widget_; |
| 66 View* contents_view_ = nullptr; // Owned by |widget_|. | 72 View* contents_view_ = nullptr; // Owned by |widget_|. |
| 73 bool should_show_close_ = false; |
| 67 }; | 74 }; |
| 68 | 75 |
| 69 class TestBubbleFrameView : public BubbleFrameView { | 76 class TestBubbleFrameView : public BubbleFrameView { |
| 70 public: | 77 public: |
| 71 TestBubbleFrameView(ViewsTestBase* test_base) | 78 TestBubbleFrameView(ViewsTestBase* test_base) |
| 72 : BubbleFrameView(gfx::Insets(), gfx::Insets(kMargin)), | 79 : BubbleFrameView(gfx::Insets(), gfx::Insets(kMargin)), |
| 73 test_base_(test_base), | 80 test_base_(test_base), |
| 74 available_bounds_(gfx::Rect(0, 0, 1000, 1000)) { | 81 available_bounds_(gfx::Rect(0, 0, 1000, 1000)) { |
| 75 SetBubbleBorder(std::unique_ptr<BubbleBorder>( | 82 SetBubbleBorder(std::unique_ptr<BubbleBorder>( |
| 76 new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor))); | 83 new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor))); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 } | 98 } |
| 92 | 99 |
| 93 return widget_.get(); | 100 return widget_.get(); |
| 94 } | 101 } |
| 95 | 102 |
| 96 // BubbleFrameView overrides: | 103 // BubbleFrameView overrides: |
| 97 gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override { | 104 gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override { |
| 98 return available_bounds_; | 105 return available_bounds_; |
| 99 } | 106 } |
| 100 | 107 |
| 108 TestBubbleFrameViewWidgetDelegate* widget_delegate() { |
| 109 return widget_delegate_.get(); |
| 110 } |
| 111 |
| 101 private: | 112 private: |
| 102 ViewsTestBase* test_base_; | 113 ViewsTestBase* test_base_; |
| 103 | 114 |
| 104 gfx::Rect available_bounds_; | 115 gfx::Rect available_bounds_; |
| 105 | 116 |
| 106 // Widget returned by GetWidget(). Only created if GetWidget() is called. | 117 // Widget returned by GetWidget(). Only created if GetWidget() is called. |
| 107 mutable std::unique_ptr<TestBubbleFrameViewWidgetDelegate> widget_delegate_; | 118 mutable std::unique_ptr<TestBubbleFrameViewWidgetDelegate> widget_delegate_; |
| 108 mutable std::unique_ptr<Widget> widget_; | 119 mutable std::unique_ptr<Widget> widget_; |
| 109 | 120 |
| 110 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); | 121 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); |
| 111 }; | 122 }; |
| 112 | 123 |
| 113 } // namespace | 124 } // namespace |
| 114 | 125 |
| 115 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { | 126 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { |
| 116 TestBubbleFrameView frame(this); | 127 TestBubbleFrameView frame(this); |
| 117 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); | 128 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); |
| 118 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); | 129 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); |
| 119 | 130 |
| 120 int margin_x = frame.content_margins().left(); | 131 int margin_x = frame.content_margins().left(); |
| 121 int margin_y = frame.content_margins().top(); | 132 int margin_y = frame.content_margins().top(); |
| 122 gfx::Insets insets = frame.bubble_border()->GetInsets(); | 133 gfx::Insets insets = frame.bubble_border()->GetInsets(); |
| 123 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); | 134 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); |
| 124 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); | 135 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); |
| 125 } | 136 } |
| 126 | 137 |
| 138 TEST_F(BubbleFrameViewTest, GetBoundsForClientViewWithClose) { |
| 139 TestBubbleFrameView frame(this); |
| 140 // TestBubbleFrameView::GetWidget() is responsible for creating the widget and |
| 141 // widget delegate at first call, so it is called here for that side-effect. |
| 142 ignore_result(frame.GetWidget()); |
| 143 frame.widget_delegate()->SetShouldShowCloseButton(true); |
| 144 frame.ResetWindowControls(); |
| 145 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); |
| 146 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); |
| 147 |
| 148 int margin_x = frame.content_margins().left(); |
| 149 int margin_y = frame.content_margins().top() + |
| 150 frame.GetCloseButtonForTest()->height(); |
| 151 gfx::Insets insets = frame.bubble_border()->GetInsets(); |
| 152 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); |
| 153 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); |
| 154 } |
| 155 |
| 127 // Tests that the arrow is mirrored as needed to better fit the screen. | 156 // Tests that the arrow is mirrored as needed to better fit the screen. |
| 128 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { | 157 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| 129 TestBubbleFrameView frame(this); | 158 TestBubbleFrameView frame(this); |
| 130 gfx::Rect window_bounds; | 159 gfx::Rect window_bounds; |
| 131 | 160 |
| 132 gfx::Insets insets = frame.bubble_border()->GetInsets(); | 161 gfx::Insets insets = frame.bubble_border()->GetInsets(); |
| 133 int xposition = 95 - insets.width(); | 162 int xposition = 95 - insets.width(); |
| 134 | 163 |
| 135 // Test that the info bubble displays normally when it fits. | 164 // Test that the info bubble displays normally when it fits. |
| 136 frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT); | 165 frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT); |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 maximum_rect.Inset(frame.bubble_border()->GetInsets()); | 482 maximum_rect.Inset(frame.bubble_border()->GetInsets()); |
| 454 | 483 |
| 455 // Should ignore the contents view's maximum size and use the preferred size. | 484 // Should ignore the contents view's maximum size and use the preferred size. |
| 456 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, | 485 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, |
| 457 kPreferredClientHeight + kExpectedAdditionalHeight); | 486 kPreferredClientHeight + kExpectedAdditionalHeight); |
| 458 EXPECT_EQ(expected_size, maximum_rect.size()); | 487 EXPECT_EQ(expected_size, maximum_rect.size()); |
| 459 #endif | 488 #endif |
| 460 } | 489 } |
| 461 | 490 |
| 462 } // namespace views | 491 } // namespace views |
| OLD | NEW |