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 "ash/common/wm/panels/panel_layout_manager.h" | 5 #include "ash/common/wm/panels/panel_layout_manager.h" |
6 | 6 |
7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
8 #include "ash/common/ash_switches.h" | 8 #include "ash/common/ash_switches.h" |
9 #include "ash/common/display/display_info.h" | 9 #include "ash/common/display/display_info.h" |
10 #include "ash/common/shelf/shelf.h" | |
11 #include "ash/common/shelf/shelf_button.h" | 10 #include "ash/common/shelf/shelf_button.h" |
12 #include "ash/common/shelf/shelf_layout_manager.h" | 11 #include "ash/common/shelf/shelf_layout_manager.h" |
13 #include "ash/common/shelf/shelf_model.h" | 12 #include "ash/common/shelf/shelf_model.h" |
14 #include "ash/common/shelf/shelf_types.h" | 13 #include "ash/common/shelf/shelf_types.h" |
15 #include "ash/common/shelf/shelf_view.h" | 14 #include "ash/common/shelf/shelf_view.h" |
16 #include "ash/common/shelf/shelf_widget.h" | 15 #include "ash/common/shelf/shelf_widget.h" |
| 16 #include "ash/common/shelf/wm_shelf.h" |
17 #include "ash/common/shell_window_ids.h" | 17 #include "ash/common/shell_window_ids.h" |
18 #include "ash/common/system/web_notification/web_notification_tray.h" | 18 #include "ash/common/system/web_notification/web_notification_tray.h" |
19 #include "ash/common/wm/mru_window_tracker.h" | 19 #include "ash/common/wm/mru_window_tracker.h" |
20 #include "ash/common/wm/window_state.h" | 20 #include "ash/common/wm/window_state.h" |
| 21 #include "ash/common/wm_root_window_controller.h" |
21 #include "ash/common/wm_shell.h" | 22 #include "ash/common/wm_shell.h" |
22 #include "ash/display/display_manager.h" | 23 #include "ash/display/display_manager.h" |
23 #include "ash/screen_util.h" | 24 #include "ash/screen_util.h" |
24 #include "ash/shelf/shelf_util.h" | 25 #include "ash/shelf/shelf_util.h" |
25 #include "ash/shell.h" | 26 #include "ash/shell.h" |
26 #include "ash/test/ash_test_base.h" | 27 #include "ash/test/ash_test_base.h" |
27 #include "ash/test/display_manager_test_api.h" | 28 #include "ash/test/display_manager_test_api.h" |
28 #include "ash/test/shelf_test_api.h" | 29 #include "ash/test/shelf_test_api.h" |
29 #include "ash/test/shelf_view_test_api.h" | 30 #include "ash/test/shelf_view_test_api.h" |
30 #include "ash/test/test_shelf_delegate.h" | 31 #include "ash/test/test_shelf_delegate.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 68 |
68 class PanelLayoutManagerTest : public test::AshTestBase { | 69 class PanelLayoutManagerTest : public test::AshTestBase { |
69 public: | 70 public: |
70 PanelLayoutManagerTest() {} | 71 PanelLayoutManagerTest() {} |
71 ~PanelLayoutManagerTest() override {} | 72 ~PanelLayoutManagerTest() override {} |
72 | 73 |
73 void SetUp() override { | 74 void SetUp() override { |
74 test::AshTestBase::SetUp(); | 75 test::AshTestBase::SetUp(); |
75 ASSERT_TRUE(test::TestShelfDelegate::instance()); | 76 ASSERT_TRUE(test::TestShelfDelegate::instance()); |
76 | 77 |
77 shelf_view_test_.reset( | 78 shelf_view_test_.reset(new test::ShelfViewTestAPI( |
78 new test::ShelfViewTestAPI(GetShelfView(Shelf::ForPrimaryDisplay()))); | 79 GetPrimaryShelf()->GetShelfViewForTesting())); |
79 shelf_view_test_->SetAnimationDuration(1); | 80 shelf_view_test_->SetAnimationDuration(1); |
80 | 81 |
81 WebNotificationTray::DisableAnimationsForTest(true); | 82 WebNotificationTray::DisableAnimationsForTest(true); |
82 } | 83 } |
83 | 84 |
84 void TearDown() override { | 85 void TearDown() override { |
85 test::AshTestBase::TearDown(); | 86 test::AshTestBase::TearDown(); |
86 | 87 |
87 WebNotificationTray::DisableAnimationsForTest(false); // Reenable animation | 88 WebNotificationTray::DisableAnimationsForTest(false); // Reenable animation |
88 } | 89 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 gfx::Rect window2_bounds = panel2->GetBoundsInRootWindow(); | 145 gfx::Rect window2_bounds = panel2->GetBoundsInRootWindow(); |
145 | 146 |
146 EXPECT_FALSE(window1_bounds.Intersects(window2_bounds)); | 147 EXPECT_FALSE(window1_bounds.Intersects(window2_bounds)); |
147 } | 148 } |
148 | 149 |
149 void IsPanelAboveLauncherIcon(aura::Window* panel) { | 150 void IsPanelAboveLauncherIcon(aura::Window* panel) { |
150 // Waits until all shelf view animations are done. | 151 // Waits until all shelf view animations are done. |
151 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 152 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
152 | 153 |
153 WmWindow* wm_panel = WmWindowAura::Get(panel); | 154 WmWindow* wm_panel = WmWindowAura::Get(panel); |
154 Shelf* shelf = Shelf::ForWindow(wm_panel); | 155 WmShelf* shelf = wm_panel->GetRootWindowController()->GetShelf(); |
155 gfx::Rect icon_bounds = shelf->GetScreenBoundsOfItemIconForWindow(wm_panel); | 156 gfx::Rect icon_bounds = shelf->GetScreenBoundsOfItemIconForWindow(wm_panel); |
156 ASSERT_FALSE(icon_bounds.width() == 0 && icon_bounds.height() == 0); | 157 ASSERT_FALSE(icon_bounds.width() == 0 && icon_bounds.height() == 0); |
157 | 158 |
158 gfx::Rect window_bounds = panel->GetBoundsInScreen(); | 159 gfx::Rect window_bounds = panel->GetBoundsInScreen(); |
159 ASSERT_LT(icon_bounds.width(), window_bounds.width()); | 160 ASSERT_LT(icon_bounds.width(), window_bounds.width()); |
160 ASSERT_LT(icon_bounds.height(), window_bounds.height()); | 161 ASSERT_LT(icon_bounds.height(), window_bounds.height()); |
161 gfx::Rect shelf_bounds = shelf->shelf_widget()->GetWindowBoundsInScreen(); | 162 gfx::Rect shelf_bounds = |
| 163 shelf->GetShelfWidgetForTesting()->GetWindowBoundsInScreen(); |
162 const ShelfAlignment alignment = shelf->alignment(); | 164 const ShelfAlignment alignment = shelf->alignment(); |
163 | 165 |
164 if (IsHorizontal(alignment)) { | 166 if (IsHorizontal(alignment)) { |
165 // The horizontal bounds of the panel window should contain the bounds of | 167 // The horizontal bounds of the panel window should contain the bounds of |
166 // the shelf icon. | 168 // the shelf icon. |
167 EXPECT_LE(window_bounds.x(), icon_bounds.x()); | 169 EXPECT_LE(window_bounds.x(), icon_bounds.x()); |
168 EXPECT_GE(window_bounds.right(), icon_bounds.right()); | 170 EXPECT_GE(window_bounds.right(), icon_bounds.right()); |
169 } else { | 171 } else { |
170 // The vertical bounds of the panel window should contain the bounds of | 172 // The vertical bounds of the panel window should contain the bounds of |
171 // the shelf icon. | 173 // the shelf icon. |
172 EXPECT_LE(window_bounds.y(), icon_bounds.y()); | 174 EXPECT_LE(window_bounds.y(), icon_bounds.y()); |
173 EXPECT_GE(window_bounds.bottom(), icon_bounds.bottom()); | 175 EXPECT_GE(window_bounds.bottom(), icon_bounds.bottom()); |
174 } | 176 } |
175 | 177 |
176 if (alignment == SHELF_ALIGNMENT_LEFT) | 178 if (alignment == SHELF_ALIGNMENT_LEFT) |
177 EXPECT_EQ(shelf_bounds.right(), window_bounds.x()); | 179 EXPECT_EQ(shelf_bounds.right(), window_bounds.x()); |
178 else if (alignment == SHELF_ALIGNMENT_RIGHT) | 180 else if (alignment == SHELF_ALIGNMENT_RIGHT) |
179 EXPECT_EQ(shelf_bounds.x(), window_bounds.right()); | 181 EXPECT_EQ(shelf_bounds.x(), window_bounds.right()); |
180 else | 182 else |
181 EXPECT_EQ(shelf_bounds.y(), window_bounds.bottom()); | 183 EXPECT_EQ(shelf_bounds.y(), window_bounds.bottom()); |
182 } | 184 } |
183 | 185 |
184 void IsCalloutAboveLauncherIcon(aura::Window* panel) { | 186 void IsCalloutAboveLauncherIcon(aura::Window* panel) { |
185 // Flush the message loop, since callout updates use a delayed task. | 187 // Flush the message loop, since callout updates use a delayed task. |
186 base::RunLoop().RunUntilIdle(); | 188 base::RunLoop().RunUntilIdle(); |
187 views::Widget* widget = GetCalloutWidgetForPanel(panel); | 189 views::Widget* widget = GetCalloutWidgetForPanel(panel); |
188 | 190 |
189 WmWindow* wm_panel = WmWindowAura::Get(panel); | 191 WmWindow* wm_panel = WmWindowAura::Get(panel); |
190 Shelf* shelf = Shelf::ForWindow(wm_panel); | 192 WmShelf* shelf = wm_panel->GetRootWindowController()->GetShelf(); |
191 gfx::Rect icon_bounds = shelf->GetScreenBoundsOfItemIconForWindow(wm_panel); | 193 gfx::Rect icon_bounds = shelf->GetScreenBoundsOfItemIconForWindow(wm_panel); |
192 ASSERT_FALSE(icon_bounds.IsEmpty()); | 194 ASSERT_FALSE(icon_bounds.IsEmpty()); |
193 | 195 |
194 gfx::Rect panel_bounds = panel->GetBoundsInScreen(); | 196 gfx::Rect panel_bounds = panel->GetBoundsInScreen(); |
195 gfx::Rect callout_bounds = widget->GetWindowBoundsInScreen(); | 197 gfx::Rect callout_bounds = widget->GetWindowBoundsInScreen(); |
196 ASSERT_FALSE(icon_bounds.IsEmpty()); | 198 ASSERT_FALSE(icon_bounds.IsEmpty()); |
197 | 199 |
198 EXPECT_TRUE(widget->IsVisible()); | 200 EXPECT_TRUE(widget->IsVisible()); |
199 | 201 |
200 const ShelfAlignment alignment = shelf->alignment(); | 202 const ShelfAlignment alignment = shelf->alignment(); |
(...skipping 30 matching lines...) Expand all Loading... |
231 GetShelfIDForWindow(window)); | 233 GetShelfIDForWindow(window)); |
232 gfx::Rect bounds = test_api.GetButton(index)->GetBoundsInScreen(); | 234 gfx::Rect bounds = test_api.GetButton(index)->GetBoundsInScreen(); |
233 | 235 |
234 ui::test::EventGenerator& event_generator = GetEventGenerator(); | 236 ui::test::EventGenerator& event_generator = GetEventGenerator(); |
235 event_generator.MoveMouseTo(bounds.CenterPoint()); | 237 event_generator.MoveMouseTo(bounds.CenterPoint()); |
236 event_generator.ClickLeftButton(); | 238 event_generator.ClickLeftButton(); |
237 | 239 |
238 test_api.RunMessageLoopUntilAnimationsDone(); | 240 test_api.RunMessageLoopUntilAnimationsDone(); |
239 } | 241 } |
240 | 242 |
| 243 WmShelf* GetShelfForWindow(aura::Window* window) { |
| 244 return WmWindowAura::Get(window)->GetRootWindowController()->GetShelf(); |
| 245 } |
| 246 |
241 void SetAlignment(aura::Window* root_window, ShelfAlignment alignment) { | 247 void SetAlignment(aura::Window* root_window, ShelfAlignment alignment) { |
242 Shelf::ForWindow(WmWindowAura::Get(root_window))->SetAlignment(alignment); | 248 GetShelfForWindow(root_window)->SetAlignment(alignment); |
243 } | 249 } |
244 | 250 |
245 void SetShelfAutoHideBehavior(aura::Window* window, | 251 void SetShelfAutoHideBehavior(aura::Window* window, |
246 ShelfAutoHideBehavior behavior) { | 252 ShelfAutoHideBehavior behavior) { |
247 Shelf* shelf = Shelf::ForWindow(WmWindowAura::Get(window)); | 253 WmShelf* shelf = GetShelfForWindow(window); |
248 shelf->SetAutoHideBehavior(behavior); | 254 shelf->SetAutoHideBehavior(behavior); |
249 test::ShelfViewTestAPI test_api(GetShelfView(shelf)); | 255 test::ShelfViewTestAPI test_api(shelf->GetShelfViewForTesting()); |
250 test_api.RunMessageLoopUntilAnimationsDone(); | 256 test_api.RunMessageLoopUntilAnimationsDone(); |
251 } | 257 } |
252 | 258 |
253 void SetShelfVisibilityState(aura::Window* window, | 259 void SetShelfVisibilityState(aura::Window* window, |
254 ShelfVisibilityState visibility_state) { | 260 ShelfVisibilityState visibility_state) { |
255 Shelf* shelf = Shelf::ForWindow(WmWindowAura::Get(window)); | 261 WmShelf* shelf = GetShelfForWindow(window); |
256 shelf->shelf_layout_manager()->SetState(visibility_state); | 262 shelf->shelf_layout_manager()->SetState(visibility_state); |
257 } | 263 } |
258 | 264 |
259 ShelfView* GetShelfView(Shelf* shelf) { | |
260 return test::ShelfTestAPI(shelf).shelf_view(); | |
261 } | |
262 | |
263 private: | 265 private: |
264 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; | 266 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; |
265 | 267 |
266 bool IsHorizontal(ShelfAlignment alignment) { | 268 bool IsHorizontal(ShelfAlignment alignment) { |
267 return alignment == SHELF_ALIGNMENT_BOTTOM; | 269 return alignment == SHELF_ALIGNMENT_BOTTOM; |
268 } | 270 } |
269 | 271 |
270 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); | 272 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); |
271 }; | 273 }; |
272 | 274 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 TEST_F(PanelLayoutManagerTest, FanWindows) { | 607 TEST_F(PanelLayoutManagerTest, FanWindows) { |
606 gfx::Rect bounds(0, 0, 201, 201); | 608 gfx::Rect bounds(0, 0, 201, 201); |
607 std::unique_ptr<aura::Window> w1(CreatePanelWindow(bounds)); | 609 std::unique_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
608 std::unique_ptr<aura::Window> w2(CreatePanelWindow(bounds)); | 610 std::unique_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
609 std::unique_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | 611 std::unique_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
610 | 612 |
611 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 613 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
612 int window_x1 = w1->GetBoundsInRootWindow().CenterPoint().x(); | 614 int window_x1 = w1->GetBoundsInRootWindow().CenterPoint().x(); |
613 int window_x2 = w2->GetBoundsInRootWindow().CenterPoint().x(); | 615 int window_x2 = w2->GetBoundsInRootWindow().CenterPoint().x(); |
614 int window_x3 = w3->GetBoundsInRootWindow().CenterPoint().x(); | 616 int window_x3 = w3->GetBoundsInRootWindow().CenterPoint().x(); |
615 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 617 WmShelf* shelf = GetPrimaryShelf(); |
616 int icon_x1 = | 618 int icon_x1 = |
617 shelf->GetScreenBoundsOfItemIconForWindow(WmWindowAura::Get(w1.get())) | 619 shelf->GetScreenBoundsOfItemIconForWindow(WmWindowAura::Get(w1.get())) |
618 .x(); | 620 .x(); |
619 int icon_x2 = | 621 int icon_x2 = |
620 shelf->GetScreenBoundsOfItemIconForWindow(WmWindowAura::Get(w2.get())) | 622 shelf->GetScreenBoundsOfItemIconForWindow(WmWindowAura::Get(w2.get())) |
621 .x(); | 623 .x(); |
622 EXPECT_EQ(window_x2 - window_x1, window_x3 - window_x2); | 624 EXPECT_EQ(window_x2 - window_x1, window_x3 - window_x2); |
623 int spacing = window_x2 - window_x1; | 625 int spacing = window_x2 - window_x1; |
624 EXPECT_GT(spacing, icon_x2 - icon_x1); | 626 EXPECT_GT(spacing, icon_x2 - icon_x1); |
625 } | 627 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 | 676 |
675 std::unique_ptr<aura::Window> p1_d1( | 677 std::unique_ptr<aura::Window> p1_d1( |
676 CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); | 678 CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); |
677 std::unique_ptr<aura::Window> p2_d1( | 679 std::unique_ptr<aura::Window> p2_d1( |
678 CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); | 680 CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); |
679 std::unique_ptr<aura::Window> p1_d2( | 681 std::unique_ptr<aura::Window> p1_d2( |
680 CreatePanelWindow(gfx::Rect(600, 0, 50, 50))); | 682 CreatePanelWindow(gfx::Rect(600, 0, 50, 50))); |
681 std::unique_ptr<aura::Window> p2_d2( | 683 std::unique_ptr<aura::Window> p2_d2( |
682 CreatePanelWindow(gfx::Rect(600, 0, 50, 50))); | 684 CreatePanelWindow(gfx::Rect(600, 0, 50, 50))); |
683 | 685 |
684 ShelfView* shelf_view_1st = GetShelfView(Shelf::ForPrimaryDisplay()); | 686 ShelfView* shelf_view_1st = GetPrimaryShelf()->GetShelfViewForTesting(); |
685 ShelfView* shelf_view_2nd = | 687 ShelfView* shelf_view_2nd = |
686 GetShelfView(Shelf::ForWindow(WmWindowAura::Get(root_windows[1]))); | 688 GetShelfForWindow(root_windows[1])->GetShelfViewForTesting(); |
687 | 689 |
688 EXPECT_EQ(root_windows[0], p1_d1->GetRootWindow()); | 690 EXPECT_EQ(root_windows[0], p1_d1->GetRootWindow()); |
689 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); | 691 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); |
690 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); | 692 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); |
691 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); | 693 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); |
692 | 694 |
693 EXPECT_EQ(kShellWindowId_PanelContainer, p1_d1->parent()->id()); | 695 EXPECT_EQ(kShellWindowId_PanelContainer, p1_d1->parent()->id()); |
694 EXPECT_EQ(kShellWindowId_PanelContainer, p2_d1->parent()->id()); | 696 EXPECT_EQ(kShellWindowId_PanelContainer, p2_d1->parent()->id()); |
695 EXPECT_EQ(kShellWindowId_PanelContainer, p1_d2->parent()->id()); | 697 EXPECT_EQ(kShellWindowId_PanelContainer, p1_d2->parent()->id()); |
696 EXPECT_EQ(kShellWindowId_PanelContainer, p2_d2->parent()->id()); | 698 EXPECT_EQ(kShellWindowId_PanelContainer, p2_d2->parent()->id()); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 touch.set_location(gfx::Point(bounds.x() - 1, bounds.y() + 5)); | 913 touch.set_location(gfx::Point(bounds.x() - 1, bounds.y() + 5)); |
912 target = targeter->FindTargetForEvent(root, &touch); | 914 target = targeter->FindTargetForEvent(root, &touch); |
913 EXPECT_NE(w.get(), target); | 915 EXPECT_NE(w.get(), target); |
914 } | 916 } |
915 | 917 |
916 INSTANTIATE_TEST_CASE_P(LtrRtl, | 918 INSTANTIATE_TEST_CASE_P(LtrRtl, |
917 PanelLayoutManagerTextDirectionTest, | 919 PanelLayoutManagerTextDirectionTest, |
918 testing::Bool()); | 920 testing::Bool()); |
919 | 921 |
920 } // namespace ash | 922 } // namespace ash |
OLD | NEW |