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/common/ash_layout_constants.h" | 7 #include "ash/common/ash_layout_constants.h" |
8 #include "ash/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
9 #include "ash/frame/caption_buttons/frame_caption_button.h" | 9 #include "ash/frame/caption_buttons/frame_caption_button.h" |
10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 // Overridden from views::View: | 46 // Overridden from views::View: |
47 void Layout() override { | 47 void Layout() override { |
48 caption_button_container_->Layout(); | 48 caption_button_container_->Layout(); |
49 | 49 |
50 // Right align the caption button container. | 50 // Right align the caption button container. |
51 gfx::Size preferred_size = caption_button_container_->GetPreferredSize(); | 51 gfx::Size preferred_size = caption_button_container_->GetPreferredSize(); |
52 caption_button_container_->SetBounds(width() - preferred_size.width(), 0, | 52 caption_button_container_->SetBounds(width() - preferred_size.width(), 0, |
53 preferred_size.width(), preferred_size.height()); | 53 preferred_size.width(), |
| 54 preferred_size.height()); |
54 } | 55 } |
55 | 56 |
56 void ViewHierarchyChanged( | 57 void ViewHierarchyChanged( |
57 const ViewHierarchyChangedDetails& details) override { | 58 const ViewHierarchyChangedDetails& details) override { |
58 if (details.is_add && details.child == this) { | 59 if (details.is_add && details.child == this) { |
59 caption_button_container_ = | 60 caption_button_container_ = |
60 new FrameCaptionButtonContainerView(GetWidget()); | 61 new FrameCaptionButtonContainerView(GetWidget()); |
61 | 62 |
62 // Set arbitrary images for the button icons and assign the default | 63 // Set arbitrary images for the button icons and assign the default |
63 // caption button size. | 64 // caption button size. |
(...skipping 28 matching lines...) Expand all Loading... |
92 } | 93 } |
93 | 94 |
94 // Returns true if the window has |state_type|. | 95 // Returns true if the window has |state_type|. |
95 bool HasStateType(wm::WindowStateType state_type) const { | 96 bool HasStateType(wm::WindowStateType state_type) const { |
96 return window_state()->GetStateType() == state_type; | 97 return window_state()->GetStateType() == state_type; |
97 } | 98 } |
98 | 99 |
99 // Returns true if all three buttons are in the normal state. | 100 // Returns true if all three buttons are in the normal state. |
100 bool AllButtonsInNormalState() const { | 101 bool AllButtonsInNormalState() const { |
101 return minimize_button_->state() == views::Button::STATE_NORMAL && | 102 return minimize_button_->state() == views::Button::STATE_NORMAL && |
102 size_button_->state() == views::Button::STATE_NORMAL && | 103 size_button_->state() == views::Button::STATE_NORMAL && |
103 close_button_->state() == views::Button::STATE_NORMAL; | 104 close_button_->state() == views::Button::STATE_NORMAL; |
104 } | 105 } |
105 | 106 |
106 // Creates a widget with |delegate|. The returned widget takes ownership of | 107 // Creates a widget with |delegate|. The returned widget takes ownership of |
107 // |delegate|. | 108 // |delegate|. |
108 views::Widget* CreateWidget(views::WidgetDelegate* delegate) { | 109 views::Widget* CreateWidget(views::WidgetDelegate* delegate) { |
109 views::Widget* widget = new views::Widget; | 110 views::Widget* widget = new views::Widget; |
110 views::Widget::InitParams params( | 111 views::Widget::InitParams params( |
111 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 112 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
112 params.context = CurrentContext(); | 113 params.context = CurrentContext(); |
113 params.delegate = delegate; | 114 params.delegate = delegate; |
114 params.bounds = gfx::Rect(10, 10, 100, 100); | 115 params.bounds = gfx::Rect(10, 10, 100, 100); |
115 widget->Init(params); | 116 widget->Init(params); |
116 widget->Show(); | 117 widget->Show(); |
117 return widget; | 118 return widget; |
118 } | 119 } |
119 | 120 |
120 // AshTestBase overrides: | 121 // AshTestBase overrides: |
121 void SetUp() override { | 122 void SetUp() override { |
122 AshTestBase::SetUp(); | 123 AshTestBase::SetUp(); |
123 | 124 |
124 TestWidgetDelegate* delegate = new TestWidgetDelegate(); | 125 TestWidgetDelegate* delegate = new TestWidgetDelegate(); |
125 window_state_ = ash::wm::GetWindowState( | 126 window_state_ = |
126 CreateWidget(delegate)->GetNativeWindow()); | 127 ash::wm::GetWindowState(CreateWidget(delegate)->GetNativeWindow()); |
127 | 128 |
128 FrameCaptionButtonContainerView::TestApi test( | 129 FrameCaptionButtonContainerView::TestApi test( |
129 delegate->caption_button_container()); | 130 delegate->caption_button_container()); |
130 | 131 |
131 minimize_button_ = test.minimize_button(); | 132 minimize_button_ = test.minimize_button(); |
132 size_button_ = test.size_button(); | 133 size_button_ = test.size_button(); |
133 static_cast<FrameSizeButton*>( | 134 static_cast<FrameSizeButton*>(size_button_) |
134 size_button_)->set_delay_to_set_buttons_to_snap_mode(0); | 135 ->set_delay_to_set_buttons_to_snap_mode(0); |
135 close_button_ = test.close_button(); | 136 close_button_ = test.close_button(); |
136 } | 137 } |
137 | 138 |
138 ash::wm::WindowState* window_state() { return window_state_; } | 139 ash::wm::WindowState* window_state() { return window_state_; } |
139 const ash::wm::WindowState* window_state() const { return window_state_; } | 140 const ash::wm::WindowState* window_state() const { return window_state_; } |
140 | 141 |
141 FrameCaptionButton* minimize_button() { return minimize_button_; } | 142 FrameCaptionButton* minimize_button() { return minimize_button_; } |
142 FrameCaptionButton* size_button() { return size_button_; } | 143 FrameCaptionButton* size_button() { return size_button_; } |
143 FrameCaptionButton* close_button() { return close_button_; } | 144 FrameCaptionButton* close_button() { return close_button_; } |
144 | 145 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // Snap left. | 215 // Snap left. |
215 generator.MoveMouseTo(CenterPointInScreen(size_button())); | 216 generator.MoveMouseTo(CenterPointInScreen(size_button())); |
216 generator.PressLeftButton(); | 217 generator.PressLeftButton(); |
217 generator.MoveMouseTo(CenterPointInScreen(minimize_button())); | 218 generator.MoveMouseTo(CenterPointInScreen(minimize_button())); |
218 generator.ReleaseLeftButton(); | 219 generator.ReleaseLeftButton(); |
219 RunAllPendingInMessageLoop(); | 220 RunAllPendingInMessageLoop(); |
220 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED)); | 221 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED)); |
221 | 222 |
222 // 2) Test with scroll gestures. | 223 // 2) Test with scroll gestures. |
223 // Snap right. | 224 // Snap right. |
224 generator.GestureScrollSequence( | 225 generator.GestureScrollSequence(CenterPointInScreen(size_button()), |
225 CenterPointInScreen(size_button()), | 226 CenterPointInScreen(close_button()), |
226 CenterPointInScreen(close_button()), | 227 base::TimeDelta::FromMilliseconds(100), 3); |
227 base::TimeDelta::FromMilliseconds(100), | |
228 3); | |
229 RunAllPendingInMessageLoop(); | 228 RunAllPendingInMessageLoop(); |
230 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED)); | 229 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED)); |
231 | 230 |
232 // Snap left. | 231 // Snap left. |
233 generator.GestureScrollSequence( | 232 generator.GestureScrollSequence(CenterPointInScreen(size_button()), |
234 CenterPointInScreen(size_button()), | 233 CenterPointInScreen(minimize_button()), |
235 CenterPointInScreen(minimize_button()), | 234 base::TimeDelta::FromMilliseconds(100), 3); |
236 base::TimeDelta::FromMilliseconds(100), | |
237 3); | |
238 RunAllPendingInMessageLoop(); | 235 RunAllPendingInMessageLoop(); |
239 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED)); | 236 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED)); |
240 | 237 |
241 // 3) Test with tap gestures. | 238 // 3) Test with tap gestures. |
242 const float touch_default_radius = | 239 const float touch_default_radius = |
243 ui::GestureConfiguration::GetInstance()->default_radius(); | 240 ui::GestureConfiguration::GetInstance()->default_radius(); |
244 ui::GestureConfiguration::GetInstance()->set_default_radius(0); | 241 ui::GestureConfiguration::GetInstance()->set_default_radius(0); |
245 // Snap right. | 242 // Snap right. |
246 generator.MoveMouseTo(CenterPointInScreen(size_button())); | 243 generator.MoveMouseTo(CenterPointInScreen(size_button())); |
247 generator.PressMoveAndReleaseTouchTo(CenterPointInScreen(close_button())); | 244 generator.PressMoveAndReleaseTouchTo(CenterPointInScreen(close_button())); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 457 |
461 // None of the buttons should stay pressed and the buttons should have their | 458 // None of the buttons should stay pressed and the buttons should have their |
462 // regular icons. | 459 // regular icons. |
463 EXPECT_TRUE(AllButtonsInNormalState()); | 460 EXPECT_TRUE(AllButtonsInNormalState()); |
464 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon()); | 461 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon()); |
465 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon()); | 462 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon()); |
466 } | 463 } |
467 | 464 |
468 } // namespace test | 465 } // namespace test |
469 } // namespace ash | 466 } // namespace ash |
OLD | NEW |