| 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" |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 public: | 495 public: |
| 496 TestBubbleDialogDelegateView() | 496 TestBubbleDialogDelegateView() |
| 497 : BubbleDialogDelegateView(nullptr, BubbleBorder::NONE) { | 497 : BubbleDialogDelegateView(nullptr, BubbleBorder::NONE) { |
| 498 set_shadow(BubbleBorder::NO_ASSETS); | 498 set_shadow(BubbleBorder::NO_ASSETS); |
| 499 SetAnchorRect(gfx::Rect()); | 499 SetAnchorRect(gfx::Rect()); |
| 500 } | 500 } |
| 501 ~TestBubbleDialogDelegateView() override {} | 501 ~TestBubbleDialogDelegateView() override {} |
| 502 | 502 |
| 503 using BubbleDialogDelegateView::SetAnchorView; | 503 using BubbleDialogDelegateView::SetAnchorView; |
| 504 | 504 |
| 505 void set_override_snap(bool value) { override_snap_ = value; } |
| 506 |
| 505 // BubbleDialogDelegateView: | 507 // BubbleDialogDelegateView: |
| 506 void DeleteDelegate() override { | 508 void DeleteDelegate() override { |
| 507 // This delegate is owned by the test case itself, so it should not delete | 509 // This delegate is owned by the test case itself, so it should not delete |
| 508 // itself here. | 510 // itself here. |
| 509 } | 511 } |
| 510 | |
| 511 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } | 512 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } |
| 512 | 513 bool ShouldSnapFrameWidth() const override { |
| 514 return override_snap_.value_or( |
| 515 BubbleDialogDelegateView::ShouldSnapFrameWidth()); |
| 516 } |
| 513 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } | 517 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } |
| 514 | 518 |
| 515 private: | 519 private: |
| 520 base::Optional<bool> override_snap_; |
| 521 |
| 516 DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegateView); | 522 DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegateView); |
| 517 }; | 523 }; |
| 518 | 524 |
| 519 class TestLayoutProvider : public LayoutProvider { | 525 class TestLayoutProvider : public LayoutProvider { |
| 520 public: | 526 public: |
| 521 TestLayoutProvider() : LayoutProvider() {} | 527 TestLayoutProvider() : LayoutProvider() {} |
| 522 ~TestLayoutProvider() override {} | 528 ~TestLayoutProvider() override {} |
| 523 | 529 |
| 524 // LayoutProvider: | 530 // LayoutProvider: |
| 525 int GetSnappedDialogWidth(int min_width) const override { | 531 int GetSnappedDialogWidth(int min_width) const override { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 565 |
| 560 constexpr int kTestWidth = 300; | 566 constexpr int kTestWidth = 300; |
| 561 provider.set_snap_to(kTestWidth); | 567 provider.set_snap_to(kTestWidth); |
| 562 | 568 |
| 563 // The Widget's snapped width should exactly match the width returned by the | 569 // The Widget's snapped width should exactly match the width returned by the |
| 564 // LayoutProvider. | 570 // LayoutProvider. |
| 565 Widget* w1 = BubbleDialogDelegateView::CreateBubble(&delegate); | 571 Widget* w1 = BubbleDialogDelegateView::CreateBubble(&delegate); |
| 566 w1->Show(); | 572 w1->Show(); |
| 567 EXPECT_EQ(kTestWidth, w1->GetWindowBoundsInScreen().width()); | 573 EXPECT_EQ(kTestWidth, w1->GetWindowBoundsInScreen().width()); |
| 568 w1->CloseNow(); | 574 w1->CloseNow(); |
| 575 |
| 576 // If the DialogDelegate asks not to snap, it should not snap. |
| 577 delegate.set_override_snap(false); |
| 578 Widget* w2 = BubbleDialogDelegateView::CreateBubble(&delegate); |
| 579 w2->Show(); |
| 580 EXPECT_EQ(delegate.GetPreferredSize().width(), |
| 581 w2->GetWindowBoundsInScreen().width()); |
| 582 w2->CloseNow(); |
| 569 } | 583 } |
| 570 | 584 |
| 571 } // namespace views | 585 } // namespace views |
| OLD | NEW |