| 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" |
| 6 |
| 7 #include <memory> |
| 8 |
| 5 #include "base/macros.h" | 9 #include "base/macros.h" |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 8 #include "ui/gfx/geometry/insets.h" | 11 #include "ui/gfx/geometry/insets.h" |
| 9 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 11 #include "ui/views/bubble/bubble_border.h" | 14 #include "ui/views/bubble/bubble_border.h" |
| 12 #include "ui/views/bubble/bubble_frame_view.h" | |
| 13 #include "ui/views/test/test_views.h" | 15 #include "ui/views/test/test_views.h" |
| 14 #include "ui/views/test/views_test_base.h" | 16 #include "ui/views/test/views_test_base.h" |
| 15 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 16 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
| 17 | 19 |
| 18 namespace views { | 20 namespace views { |
| 19 | 21 |
| 20 typedef ViewsTestBase BubbleFrameViewTest; | 22 typedef ViewsTestBase BubbleFrameViewTest; |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 Widget* widget_; | 65 Widget* widget_; |
| 64 View* contents_view_ = nullptr; // Owned by |widget_|. | 66 View* contents_view_ = nullptr; // Owned by |widget_|. |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 class TestBubbleFrameView : public BubbleFrameView { | 69 class TestBubbleFrameView : public BubbleFrameView { |
| 68 public: | 70 public: |
| 69 TestBubbleFrameView(ViewsTestBase* test_base) | 71 TestBubbleFrameView(ViewsTestBase* test_base) |
| 70 : BubbleFrameView(gfx::Insets(), gfx::Insets(kMargin)), | 72 : BubbleFrameView(gfx::Insets(), gfx::Insets(kMargin)), |
| 71 test_base_(test_base), | 73 test_base_(test_base), |
| 72 available_bounds_(gfx::Rect(0, 0, 1000, 1000)) { | 74 available_bounds_(gfx::Rect(0, 0, 1000, 1000)) { |
| 73 SetBubbleBorder(scoped_ptr<BubbleBorder>( | 75 SetBubbleBorder(std::unique_ptr<BubbleBorder>( |
| 74 new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor))); | 76 new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor))); |
| 75 } | 77 } |
| 76 ~TestBubbleFrameView() override {} | 78 ~TestBubbleFrameView() override {} |
| 77 | 79 |
| 78 // View overrides: | 80 // View overrides: |
| 79 const Widget* GetWidget() const override { | 81 const Widget* GetWidget() const override { |
| 80 if (!widget_) { | 82 if (!widget_) { |
| 81 widget_.reset(new Widget); | 83 widget_.reset(new Widget); |
| 82 widget_delegate_.reset( | 84 widget_delegate_.reset( |
| 83 new TestBubbleFrameViewWidgetDelegate(widget_.get())); | 85 new TestBubbleFrameViewWidgetDelegate(widget_.get())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 95 gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override { | 97 gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override { |
| 96 return available_bounds_; | 98 return available_bounds_; |
| 97 } | 99 } |
| 98 | 100 |
| 99 private: | 101 private: |
| 100 ViewsTestBase* test_base_; | 102 ViewsTestBase* test_base_; |
| 101 | 103 |
| 102 gfx::Rect available_bounds_; | 104 gfx::Rect available_bounds_; |
| 103 | 105 |
| 104 // Widget returned by GetWidget(). Only created if GetWidget() is called. | 106 // Widget returned by GetWidget(). Only created if GetWidget() is called. |
| 105 mutable scoped_ptr<TestBubbleFrameViewWidgetDelegate> widget_delegate_; | 107 mutable std::unique_ptr<TestBubbleFrameViewWidgetDelegate> widget_delegate_; |
| 106 mutable scoped_ptr<Widget> widget_; | 108 mutable std::unique_ptr<Widget> widget_; |
| 107 | 109 |
| 108 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); | 110 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 } // namespace | 113 } // namespace |
| 112 | 114 |
| 113 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { | 115 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { |
| 114 TestBubbleFrameView frame(this); | 116 TestBubbleFrameView frame(this); |
| 115 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); | 117 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); |
| 116 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); | 118 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 maximum_rect.Inset(frame.bubble_border()->GetInsets()); | 453 maximum_rect.Inset(frame.bubble_border()->GetInsets()); |
| 452 | 454 |
| 453 // Should ignore the contents view's maximum size and use the preferred size. | 455 // Should ignore the contents view's maximum size and use the preferred size. |
| 454 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, | 456 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, |
| 455 kPreferredClientHeight + kExpectedAdditionalHeight); | 457 kPreferredClientHeight + kExpectedAdditionalHeight); |
| 456 EXPECT_EQ(expected_size, maximum_rect.size()); | 458 EXPECT_EQ(expected_size, maximum_rect.size()); |
| 457 #endif | 459 #endif |
| 458 } | 460 } |
| 459 | 461 |
| 460 } // namespace views | 462 } // namespace views |
| OLD | NEW |