| 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/bubble/bubble_dialog_delegate.h" | 15 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 16 #include "ui/views/controls/button/label_button.h" | 16 #include "ui/views/controls/button/label_button.h" |
| 17 #include "ui/views/test/test_layout_provider.h" |
| 17 #include "ui/views/test/test_views.h" | 18 #include "ui/views/test/test_views.h" |
| 18 #include "ui/views/test/views_test_base.h" | 19 #include "ui/views/test/views_test_base.h" |
| 19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 20 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
| 21 | 22 |
| 22 namespace views { | 23 namespace views { |
| 23 | 24 |
| 24 typedef ViewsTestBase BubbleFrameViewTest; | 25 typedef ViewsTestBase BubbleFrameViewTest; |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 } | 510 } |
| 510 | 511 |
| 511 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } | 512 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } |
| 512 | 513 |
| 513 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } | 514 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } |
| 514 | 515 |
| 515 private: | 516 private: |
| 516 DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegateView); | 517 DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegateView); |
| 517 }; | 518 }; |
| 518 | 519 |
| 519 class TestLayoutProvider : public LayoutProvider { | |
| 520 public: | |
| 521 TestLayoutProvider() : LayoutProvider() {} | |
| 522 ~TestLayoutProvider() override {} | |
| 523 | |
| 524 // LayoutProvider: | |
| 525 int GetSnappedDialogWidth(int min_width) const override { | |
| 526 return snap_to_ ? snap_to_ : min_width; | |
| 527 } | |
| 528 | |
| 529 void set_snap_to(int width) { snap_to_ = width; } | |
| 530 | |
| 531 private: | |
| 532 int snap_to_ = 0; | |
| 533 | |
| 534 DISALLOW_COPY_AND_ASSIGN(TestLayoutProvider); | |
| 535 }; | |
| 536 | |
| 537 } // namespace | 520 } // namespace |
| 538 | 521 |
| 539 // This test ensures that if the installed LayoutProvider snaps dialog widths, | 522 // This test ensures that if the installed LayoutProvider snaps dialog widths, |
| 540 // BubbleFrameView correctly sizes itself to that width. | 523 // BubbleFrameView correctly sizes itself to that width. |
| 541 TEST_F(BubbleFrameViewTest, WidthSnaps) { | 524 TEST_F(BubbleFrameViewTest, WidthSnaps) { |
| 542 TestLayoutProvider provider; | 525 test::TestLayoutProvider provider; |
| 543 TestBubbleDialogDelegateView delegate; | 526 TestBubbleDialogDelegateView delegate; |
| 544 | 527 |
| 545 Widget anchor; | 528 Widget anchor; |
| 546 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 529 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 547 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 530 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 548 anchor.Init(params); | 531 anchor.Init(params); |
| 549 anchor.Show(); | 532 anchor.Show(); |
| 550 | 533 |
| 551 delegate.SetAnchorView(anchor.GetContentsView()); | 534 delegate.SetAnchorView(anchor.GetContentsView()); |
| 552 delegate.set_margins(gfx::Insets()); | 535 delegate.set_margins(gfx::Insets()); |
| 553 | 536 |
| 554 Widget* w0 = BubbleDialogDelegateView::CreateBubble(&delegate); | 537 Widget* w0 = BubbleDialogDelegateView::CreateBubble(&delegate); |
| 555 w0->Show(); | 538 w0->Show(); |
| 556 EXPECT_EQ(delegate.GetPreferredSize().width(), | 539 EXPECT_EQ(delegate.GetPreferredSize().width(), |
| 557 w0->GetWindowBoundsInScreen().width()); | 540 w0->GetWindowBoundsInScreen().width()); |
| 558 w0->CloseNow(); | 541 w0->CloseNow(); |
| 559 | 542 |
| 560 constexpr int kTestWidth = 300; | 543 constexpr int kTestWidth = 300; |
| 561 provider.set_snap_to(kTestWidth); | 544 provider.SetSnappedDialogWidth(kTestWidth); |
| 562 | 545 |
| 563 // The Widget's snapped width should exactly match the width returned by the | 546 // The Widget's snapped width should exactly match the width returned by the |
| 564 // LayoutProvider. | 547 // LayoutProvider. |
| 565 Widget* w1 = BubbleDialogDelegateView::CreateBubble(&delegate); | 548 Widget* w1 = BubbleDialogDelegateView::CreateBubble(&delegate); |
| 566 w1->Show(); | 549 w1->Show(); |
| 567 EXPECT_EQ(kTestWidth, w1->GetWindowBoundsInScreen().width()); | 550 EXPECT_EQ(kTestWidth, w1->GetWindowBoundsInScreen().width()); |
| 568 w1->CloseNow(); | 551 w1->CloseNow(); |
| 569 } | 552 } |
| 570 | 553 |
| 571 } // namespace views | 554 } // namespace views |
| OLD | NEW |