| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/frame/caption_buttons/frame_size_button.h" | 5 #include "ash/frame/caption_buttons/frame_size_button.h" |
| 6 | 6 |
| 7 #include "ash/frame/caption_buttons/frame_caption_button.h" | 7 #include "ash/frame/caption_buttons/frame_caption_button.h" |
| 8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
| 22 | 22 |
| 23 namespace ash { | 23 namespace ash { |
| 24 namespace test { | 24 namespace test { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class TestWidgetDelegate : public views::WidgetDelegateView { | 28 class TestWidgetDelegate : public views::WidgetDelegateView { |
| 29 public: | 29 public: |
| 30 TestWidgetDelegate() {} | 30 TestWidgetDelegate() {} |
| 31 virtual ~TestWidgetDelegate() {} | 31 ~TestWidgetDelegate() override {} |
| 32 | 32 |
| 33 // Overridden from views::WidgetDelegate: | 33 // Overridden from views::WidgetDelegate: |
| 34 virtual views::View* GetContentsView() override { | 34 views::View* GetContentsView() override { return this; } |
| 35 return this; | 35 bool CanResize() const override { return true; } |
| 36 } | 36 bool CanMaximize() const override { return true; } |
| 37 virtual bool CanResize() const override { | 37 bool CanMinimize() const override { return true; } |
| 38 return true; | |
| 39 } | |
| 40 virtual bool CanMaximize() const override { | |
| 41 return true; | |
| 42 } | |
| 43 virtual bool CanMinimize() const override { | |
| 44 return true; | |
| 45 } | |
| 46 | 38 |
| 47 ash::FrameCaptionButtonContainerView* caption_button_container() { | 39 ash::FrameCaptionButtonContainerView* caption_button_container() { |
| 48 return caption_button_container_; | 40 return caption_button_container_; |
| 49 } | 41 } |
| 50 | 42 |
| 51 private: | 43 private: |
| 52 // Overridden from views::View: | 44 // Overridden from views::View: |
| 53 virtual void Layout() override { | 45 void Layout() override { |
| 54 caption_button_container_->Layout(); | 46 caption_button_container_->Layout(); |
| 55 | 47 |
| 56 // Right align the caption button container. | 48 // Right align the caption button container. |
| 57 gfx::Size preferred_size = caption_button_container_->GetPreferredSize(); | 49 gfx::Size preferred_size = caption_button_container_->GetPreferredSize(); |
| 58 caption_button_container_->SetBounds(width() - preferred_size.width(), 0, | 50 caption_button_container_->SetBounds(width() - preferred_size.width(), 0, |
| 59 preferred_size.width(), preferred_size.height()); | 51 preferred_size.width(), preferred_size.height()); |
| 60 } | 52 } |
| 61 | 53 |
| 62 virtual void ViewHierarchyChanged( | 54 void ViewHierarchyChanged( |
| 63 const ViewHierarchyChangedDetails& details) override { | 55 const ViewHierarchyChangedDetails& details) override { |
| 64 if (details.is_add && details.child == this) { | 56 if (details.is_add && details.child == this) { |
| 65 caption_button_container_ = | 57 caption_button_container_ = |
| 66 new FrameCaptionButtonContainerView(GetWidget()); | 58 new FrameCaptionButtonContainerView(GetWidget()); |
| 67 | 59 |
| 68 // Set arbitrary images for the container's buttons so that the buttons | 60 // Set arbitrary images for the container's buttons so that the buttons |
| 69 // have non-empty sizes. | 61 // have non-empty sizes. |
| 70 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) { | 62 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) { |
| 71 caption_button_container_->SetButtonImages( | 63 caption_button_container_->SetButtonImages( |
| 72 static_cast<CaptionButtonIcon>(icon), | 64 static_cast<CaptionButtonIcon>(icon), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 84 ash::FrameCaptionButtonContainerView* caption_button_container_; | 76 ash::FrameCaptionButtonContainerView* caption_button_container_; |
| 85 | 77 |
| 86 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); | 78 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); |
| 87 }; | 79 }; |
| 88 | 80 |
| 89 } // namespace | 81 } // namespace |
| 90 | 82 |
| 91 class FrameSizeButtonTest : public AshTestBase { | 83 class FrameSizeButtonTest : public AshTestBase { |
| 92 public: | 84 public: |
| 93 FrameSizeButtonTest() {} | 85 FrameSizeButtonTest() {} |
| 94 virtual ~FrameSizeButtonTest() {} | 86 ~FrameSizeButtonTest() override {} |
| 95 | 87 |
| 96 // Returns the center point of |view| in screen coordinates. | 88 // Returns the center point of |view| in screen coordinates. |
| 97 gfx::Point CenterPointInScreen(views::View* view) { | 89 gfx::Point CenterPointInScreen(views::View* view) { |
| 98 return view->GetBoundsInScreen().CenterPoint(); | 90 return view->GetBoundsInScreen().CenterPoint(); |
| 99 } | 91 } |
| 100 | 92 |
| 101 // Returns true if the window has |state_type|. | 93 // Returns true if the window has |state_type|. |
| 102 bool HasStateType(wm::WindowStateType state_type) const { | 94 bool HasStateType(wm::WindowStateType state_type) const { |
| 103 return window_state()->GetStateType() == state_type; | 95 return window_state()->GetStateType() == state_type; |
| 104 } | 96 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 110 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 119 params.context = CurrentContext(); | 111 params.context = CurrentContext(); |
| 120 params.delegate = delegate; | 112 params.delegate = delegate; |
| 121 params.bounds = gfx::Rect(10, 10, 100, 100); | 113 params.bounds = gfx::Rect(10, 10, 100, 100); |
| 122 widget->Init(params); | 114 widget->Init(params); |
| 123 widget->Show(); | 115 widget->Show(); |
| 124 return widget; | 116 return widget; |
| 125 } | 117 } |
| 126 | 118 |
| 127 // AshTestBase overrides: | 119 // AshTestBase overrides: |
| 128 virtual void SetUp() override { | 120 void SetUp() override { |
| 129 AshTestBase::SetUp(); | 121 AshTestBase::SetUp(); |
| 130 | 122 |
| 131 TestWidgetDelegate* delegate = new TestWidgetDelegate(); | 123 TestWidgetDelegate* delegate = new TestWidgetDelegate(); |
| 132 window_state_ = ash::wm::GetWindowState( | 124 window_state_ = ash::wm::GetWindowState( |
| 133 CreateWidget(delegate)->GetNativeWindow()); | 125 CreateWidget(delegate)->GetNativeWindow()); |
| 134 | 126 |
| 135 FrameCaptionButtonContainerView::TestApi test( | 127 FrameCaptionButtonContainerView::TestApi test( |
| 136 delegate->caption_button_container()); | 128 delegate->caption_button_container()); |
| 137 | 129 |
| 138 minimize_button_ = test.minimize_button(); | 130 minimize_button_ = test.minimize_button(); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 EXPECT_TRUE(AllButtonsInNormalState()); | 391 EXPECT_TRUE(AllButtonsInNormalState()); |
| 400 generator.MoveMouseTo(CenterPointInScreen(close_button())); | 392 generator.MoveMouseTo(CenterPointInScreen(close_button())); |
| 401 EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state()); | 393 EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state()); |
| 402 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state()); | 394 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state()); |
| 403 EXPECT_EQ(views::Button::STATE_HOVERED, close_button()->state()); | 395 EXPECT_EQ(views::Button::STATE_HOVERED, close_button()->state()); |
| 404 } | 396 } |
| 405 | 397 |
| 406 class FrameSizeButtonTestRTL : public FrameSizeButtonTest { | 398 class FrameSizeButtonTestRTL : public FrameSizeButtonTest { |
| 407 public: | 399 public: |
| 408 FrameSizeButtonTestRTL() {} | 400 FrameSizeButtonTestRTL() {} |
| 409 virtual ~FrameSizeButtonTestRTL() {} | 401 ~FrameSizeButtonTestRTL() override {} |
| 410 | 402 |
| 411 virtual void SetUp() override { | 403 void SetUp() override { |
| 412 original_locale_ = l10n_util::GetApplicationLocale(std::string()); | 404 original_locale_ = l10n_util::GetApplicationLocale(std::string()); |
| 413 base::i18n::SetICUDefaultLocale("he"); | 405 base::i18n::SetICUDefaultLocale("he"); |
| 414 | 406 |
| 415 FrameSizeButtonTest::SetUp(); | 407 FrameSizeButtonTest::SetUp(); |
| 416 } | 408 } |
| 417 | 409 |
| 418 virtual void TearDown() override { | 410 void TearDown() override { |
| 419 FrameSizeButtonTest::TearDown(); | 411 FrameSizeButtonTest::TearDown(); |
| 420 base::i18n::SetICUDefaultLocale(original_locale_); | 412 base::i18n::SetICUDefaultLocale(original_locale_); |
| 421 } | 413 } |
| 422 | 414 |
| 423 private: | 415 private: |
| 424 std::string original_locale_; | 416 std::string original_locale_; |
| 425 | 417 |
| 426 DISALLOW_COPY_AND_ASSIGN(FrameSizeButtonTestRTL); | 418 DISALLOW_COPY_AND_ASSIGN(FrameSizeButtonTestRTL); |
| 427 }; | 419 }; |
| 428 | 420 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 458 |
| 467 // None of the buttons should stay pressed and the buttons should have their | 459 // None of the buttons should stay pressed and the buttons should have their |
| 468 // regular icons. | 460 // regular icons. |
| 469 EXPECT_TRUE(AllButtonsInNormalState()); | 461 EXPECT_TRUE(AllButtonsInNormalState()); |
| 470 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon()); | 462 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon()); |
| 471 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon()); | 463 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon()); |
| 472 } | 464 } |
| 473 | 465 |
| 474 } // namespace test | 466 } // namespace test |
| 475 } // namespace ash | 467 } // namespace ash |
| OLD | NEW |