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/shelf/shelf_model.h" | 9 #include "ash/common/shelf/shelf_model.h" |
10 #include "ash/common/shelf/shelf_types.h" | 10 #include "ash/common/shelf/shelf_types.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 class PanelLayoutManagerTest : public test::AshTestBase { | 45 class PanelLayoutManagerTest : public test::AshTestBase { |
46 public: | 46 public: |
47 PanelLayoutManagerTest() {} | 47 PanelLayoutManagerTest() {} |
48 ~PanelLayoutManagerTest() override {} | 48 ~PanelLayoutManagerTest() override {} |
49 | 49 |
50 void SetUp() override { | 50 void SetUp() override { |
51 test::AshTestBase::SetUp(); | 51 test::AshTestBase::SetUp(); |
52 ASSERT_TRUE(test::TestShelfDelegate::instance()); | 52 ASSERT_TRUE(test::TestShelfDelegate::instance()); |
53 | 53 |
54 shelf_view_test_.reset(new test::ShelfViewTestAPI( | 54 shelf_view_test_.reset( |
55 GetShelfView(Shelf::ForPrimaryDisplay()))); | 55 new test::ShelfViewTestAPI(GetShelfView(Shelf::ForPrimaryDisplay()))); |
56 shelf_view_test_->SetAnimationDuration(1); | 56 shelf_view_test_->SetAnimationDuration(1); |
57 } | 57 } |
58 | 58 |
59 aura::Window* CreateNormalWindow(const gfx::Rect& bounds) { | 59 aura::Window* CreateNormalWindow(const gfx::Rect& bounds) { |
60 return CreateTestWindowInShellWithBounds(bounds); | 60 return CreateTestWindowInShellWithBounds(bounds); |
61 } | 61 } |
62 | 62 |
63 aura::Window* CreatePanelWindowWithDelegate(aura::WindowDelegate* delegate, | 63 aura::Window* CreatePanelWindowWithDelegate(aura::WindowDelegate* delegate, |
64 const gfx::Rect& bounds) { | 64 const gfx::Rect& bounds) { |
65 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 65 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
(...skipping 27 matching lines...) Expand all Loading... |
93 } | 93 } |
94 | 94 |
95 void PanelInScreen(aura::Window* panel) { | 95 void PanelInScreen(aura::Window* panel) { |
96 gfx::Rect panel_bounds = panel->GetBoundsInRootWindow(); | 96 gfx::Rect panel_bounds = panel->GetBoundsInRootWindow(); |
97 gfx::Point root_point = gfx::Point(panel_bounds.x(), panel_bounds.y()); | 97 gfx::Point root_point = gfx::Point(panel_bounds.x(), panel_bounds.y()); |
98 display::Display display = | 98 display::Display display = |
99 ScreenUtil::FindDisplayContainingPoint(root_point); | 99 ScreenUtil::FindDisplayContainingPoint(root_point); |
100 | 100 |
101 gfx::Rect panel_bounds_in_screen = panel->GetBoundsInScreen(); | 101 gfx::Rect panel_bounds_in_screen = panel->GetBoundsInScreen(); |
102 gfx::Point screen_bottom_right = gfx::Point( | 102 gfx::Point screen_bottom_right = gfx::Point( |
103 panel_bounds_in_screen.right(), | 103 panel_bounds_in_screen.right(), panel_bounds_in_screen.bottom()); |
104 panel_bounds_in_screen.bottom()); | |
105 gfx::Rect display_bounds = display.bounds(); | 104 gfx::Rect display_bounds = display.bounds(); |
106 EXPECT_TRUE(screen_bottom_right.x() < display_bounds.width() && | 105 EXPECT_TRUE(screen_bottom_right.x() < display_bounds.width() && |
107 screen_bottom_right.y() < display_bounds.height()); | 106 screen_bottom_right.y() < display_bounds.height()); |
108 } | 107 } |
109 | 108 |
110 void PanelsNotOverlapping(aura::Window* panel1, aura::Window* panel2) { | 109 void PanelsNotOverlapping(aura::Window* panel1, aura::Window* panel2) { |
111 // Waits until all shelf view animations are done. | 110 // Waits until all shelf view animations are done. |
112 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 111 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
113 gfx::Rect window1_bounds = panel1->GetBoundsInRootWindow(); | 112 gfx::Rect window1_bounds = panel1->GetBoundsInRootWindow(); |
114 gfx::Rect window2_bounds = panel2->GetBoundsInRootWindow(); | 113 gfx::Rect window2_bounds = panel2->GetBoundsInRootWindow(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 ShelfAlignment alignment = GetAlignment(panel->GetRootWindow()); | 167 ShelfAlignment alignment = GetAlignment(panel->GetRootWindow()); |
169 if (alignment == SHELF_ALIGNMENT_LEFT) | 168 if (alignment == SHELF_ALIGNMENT_LEFT) |
170 EXPECT_EQ(panel_bounds.x(), callout_bounds.right()); | 169 EXPECT_EQ(panel_bounds.x(), callout_bounds.right()); |
171 else if (alignment == SHELF_ALIGNMENT_RIGHT) | 170 else if (alignment == SHELF_ALIGNMENT_RIGHT) |
172 EXPECT_EQ(panel_bounds.right(), callout_bounds.x()); | 171 EXPECT_EQ(panel_bounds.right(), callout_bounds.x()); |
173 else | 172 else |
174 EXPECT_EQ(panel_bounds.bottom(), callout_bounds.y()); | 173 EXPECT_EQ(panel_bounds.bottom(), callout_bounds.y()); |
175 | 174 |
176 if (IsHorizontal(alignment)) { | 175 if (IsHorizontal(alignment)) { |
177 EXPECT_NEAR(icon_bounds.CenterPoint().x(), | 176 EXPECT_NEAR(icon_bounds.CenterPoint().x(), |
178 widget->GetWindowBoundsInScreen().CenterPoint().x(), | 177 widget->GetWindowBoundsInScreen().CenterPoint().x(), 1); |
179 1); | |
180 } else { | 178 } else { |
181 EXPECT_NEAR(icon_bounds.CenterPoint().y(), | 179 EXPECT_NEAR(icon_bounds.CenterPoint().y(), |
182 widget->GetWindowBoundsInScreen().CenterPoint().y(), | 180 widget->GetWindowBoundsInScreen().CenterPoint().y(), 1); |
183 1); | |
184 } | 181 } |
185 } | 182 } |
186 | 183 |
187 bool IsPanelCalloutVisible(aura::Window* panel) { | 184 bool IsPanelCalloutVisible(aura::Window* panel) { |
188 views::Widget* widget = GetCalloutWidgetForPanel(panel); | 185 views::Widget* widget = GetCalloutWidgetForPanel(panel); |
189 return widget->IsVisible(); | 186 return widget->IsVisible(); |
190 } | 187 } |
191 | 188 |
192 test::ShelfViewTestAPI* shelf_view_test() { | 189 test::ShelfViewTestAPI* shelf_view_test() { return shelf_view_test_.get(); } |
193 return shelf_view_test_.get(); | |
194 } | |
195 | 190 |
196 // Clicks the shelf items on |shelf_view| that is associated with given | 191 // Clicks the shelf items on |shelf_view| that is associated with given |
197 // |window|. | 192 // |window|. |
198 void ClickShelfItemForWindow(ShelfView* shelf_view, aura::Window* window) { | 193 void ClickShelfItemForWindow(ShelfView* shelf_view, aura::Window* window) { |
199 test::ShelfViewTestAPI test_api(shelf_view); | 194 test::ShelfViewTestAPI test_api(shelf_view); |
200 test_api.SetAnimationDuration(1); | 195 test_api.SetAnimationDuration(1); |
201 test_api.RunMessageLoopUntilAnimationsDone(); | 196 test_api.RunMessageLoopUntilAnimationsDone(); |
202 ShelfModel* model = test::ShellTestApi(Shell::GetInstance()).shelf_model(); | 197 ShelfModel* model = test::ShellTestApi(Shell::GetInstance()).shelf_model(); |
203 int index = model->ItemIndexByID(GetShelfIDForWindow(window)); | 198 int index = model->ItemIndexByID(GetShelfIDForWindow(window)); |
204 gfx::Rect bounds = test_api.GetButton(index)->GetBoundsInScreen(); | 199 gfx::Rect bounds = test_api.GetButton(index)->GetBoundsInScreen(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 300 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
306 | 301 |
307 std::unique_ptr<aura::Window> normal_window( | 302 std::unique_ptr<aura::Window> normal_window( |
308 CreateNormalWindow(gfx::Rect(450, 0, 100, 100))); | 303 CreateNormalWindow(gfx::Rect(450, 0, 100, 100))); |
309 std::unique_ptr<aura::Window> panel( | 304 std::unique_ptr<aura::Window> panel( |
310 CreatePanelWindow(gfx::Rect(400, 0, 50, 50))); | 305 CreatePanelWindow(gfx::Rect(400, 0, 50, 50))); |
311 EXPECT_EQ(root_windows[1], panel->GetRootWindow()); | 306 EXPECT_EQ(root_windows[1], panel->GetRootWindow()); |
312 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(panel.get())); | 307 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(panel.get())); |
313 gfx::Rect shelf_visible_position = panel->GetBoundsInScreen(); | 308 gfx::Rect shelf_visible_position = panel->GetBoundsInScreen(); |
314 | 309 |
315 SetShelfAutoHideBehavior(root_windows[1], | 310 SetShelfAutoHideBehavior(root_windows[1], SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
316 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
317 // Expect the panel X position to remain the same after the shelf is hidden | 311 // Expect the panel X position to remain the same after the shelf is hidden |
318 // but the Y to move down. | 312 // but the Y to move down. |
319 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(panel.get())); | 313 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(panel.get())); |
320 EXPECT_EQ(shelf_visible_position.x(), panel->GetBoundsInScreen().x()); | 314 EXPECT_EQ(shelf_visible_position.x(), panel->GetBoundsInScreen().x()); |
321 EXPECT_GT(panel->GetBoundsInScreen().y(), shelf_visible_position.y()); | 315 EXPECT_GT(panel->GetBoundsInScreen().y(), shelf_visible_position.y()); |
322 } | 316 } |
323 | 317 |
324 // Tests interactions between multiple panels | 318 // Tests interactions between multiple panels |
325 TEST_F(PanelLayoutManagerTest, MultiplePanelsAreAboveIcons) { | 319 TEST_F(PanelLayoutManagerTest, MultiplePanelsAreAboveIcons) { |
326 gfx::Rect odd_bounds(0, 0, 201, 201); | 320 gfx::Rect odd_bounds(0, 0, 201, 201); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 std::unique_ptr<aura::Window> p1_d1( | 572 std::unique_ptr<aura::Window> p1_d1( |
579 CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); | 573 CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); |
580 std::unique_ptr<aura::Window> p2_d1( | 574 std::unique_ptr<aura::Window> p2_d1( |
581 CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); | 575 CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); |
582 std::unique_ptr<aura::Window> p1_d2( | 576 std::unique_ptr<aura::Window> p1_d2( |
583 CreatePanelWindow(gfx::Rect(600, 0, 50, 50))); | 577 CreatePanelWindow(gfx::Rect(600, 0, 50, 50))); |
584 std::unique_ptr<aura::Window> p2_d2( | 578 std::unique_ptr<aura::Window> p2_d2( |
585 CreatePanelWindow(gfx::Rect(600, 0, 50, 50))); | 579 CreatePanelWindow(gfx::Rect(600, 0, 50, 50))); |
586 | 580 |
587 ShelfView* shelf_view_1st = GetShelfView(Shelf::ForPrimaryDisplay()); | 581 ShelfView* shelf_view_1st = GetShelfView(Shelf::ForPrimaryDisplay()); |
588 ShelfView* shelf_view_2nd = | 582 ShelfView* shelf_view_2nd = GetShelfView(Shelf::ForWindow(root_windows[1])); |
589 GetShelfView(Shelf::ForWindow(root_windows[1])); | |
590 | 583 |
591 EXPECT_EQ(root_windows[0], p1_d1->GetRootWindow()); | 584 EXPECT_EQ(root_windows[0], p1_d1->GetRootWindow()); |
592 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); | 585 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); |
593 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); | 586 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); |
594 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); | 587 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); |
595 | 588 |
596 EXPECT_EQ(kShellWindowId_PanelContainer, p1_d1->parent()->id()); | 589 EXPECT_EQ(kShellWindowId_PanelContainer, p1_d1->parent()->id()); |
597 EXPECT_EQ(kShellWindowId_PanelContainer, p2_d1->parent()->id()); | 590 EXPECT_EQ(kShellWindowId_PanelContainer, p2_d1->parent()->id()); |
598 EXPECT_EQ(kShellWindowId_PanelContainer, p1_d2->parent()->id()); | 591 EXPECT_EQ(kShellWindowId_PanelContainer, p1_d2->parent()->id()); |
599 EXPECT_EQ(kShellWindowId_PanelContainer, p2_d2->parent()->id()); | 592 EXPECT_EQ(kShellWindowId_PanelContainer, p2_d2->parent()->id()); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 // arbitrarily-selected small numbers which will ensure the point is | 767 // arbitrarily-selected small numbers which will ensure the point is |
775 // within the default extended region surrounding the panel. This value | 768 // within the default extended region surrounding the panel. This value |
776 // is calculated as | 769 // is calculated as |
777 // kResizeOutsideBoundsSize * kResizeOutsideBoundsScaleForTouch | 770 // kResizeOutsideBoundsSize * kResizeOutsideBoundsScaleForTouch |
778 // in src/ash/root_window_controller.cc. | 771 // in src/ash/root_window_controller.cc. |
779 | 772 |
780 // Hit test outside the right edge with a bottom-aligned shelf. | 773 // Hit test outside the right edge with a bottom-aligned shelf. |
781 SetAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_BOTTOM); | 774 SetAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_BOTTOM); |
782 gfx::Rect bounds(w->bounds()); | 775 gfx::Rect bounds(w->bounds()); |
783 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, | 776 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, |
784 gfx::Point(bounds.right() + 3, bounds.y() + 2), | 777 gfx::Point(bounds.right() + 3, bounds.y() + 2), 0, |
785 0, ui::EventTimeForNow()); | 778 ui::EventTimeForNow()); |
786 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); | 779 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); |
787 EXPECT_EQ(w.get(), target); | 780 EXPECT_EQ(w.get(), target); |
788 | 781 |
789 // Hit test outside the bottom edge with a bottom-aligned shelf. | 782 // Hit test outside the bottom edge with a bottom-aligned shelf. |
790 touch.set_location(gfx::Point(bounds.x() + 6, bounds.bottom() + 5)); | 783 touch.set_location(gfx::Point(bounds.x() + 6, bounds.bottom() + 5)); |
791 target = targeter->FindTargetForEvent(root, &touch); | 784 target = targeter->FindTargetForEvent(root, &touch); |
792 EXPECT_NE(w.get(), target); | 785 EXPECT_NE(w.get(), target); |
793 | 786 |
794 // Hit test outside the bottom edge with a right-aligned shelf. | 787 // Hit test outside the bottom edge with a right-aligned shelf. |
795 SetAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_RIGHT); | 788 SetAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_RIGHT); |
(...skipping 13 matching lines...) Expand all Loading... |
809 touch.set_location(gfx::Point(bounds.x() + 4, bounds.y() - 6)); | 802 touch.set_location(gfx::Point(bounds.x() + 4, bounds.y() - 6)); |
810 target = targeter->FindTargetForEvent(root, &touch); | 803 target = targeter->FindTargetForEvent(root, &touch); |
811 EXPECT_EQ(w.get(), target); | 804 EXPECT_EQ(w.get(), target); |
812 | 805 |
813 // Hit test outside the left edge with a left-aligned shelf. | 806 // Hit test outside the left edge with a left-aligned shelf. |
814 touch.set_location(gfx::Point(bounds.x() - 1, bounds.y() + 5)); | 807 touch.set_location(gfx::Point(bounds.x() - 1, bounds.y() + 5)); |
815 target = targeter->FindTargetForEvent(root, &touch); | 808 target = targeter->FindTargetForEvent(root, &touch); |
816 EXPECT_NE(w.get(), target); | 809 EXPECT_NE(w.get(), target); |
817 } | 810 } |
818 | 811 |
819 INSTANTIATE_TEST_CASE_P(LtrRtl, PanelLayoutManagerTextDirectionTest, | 812 INSTANTIATE_TEST_CASE_P(LtrRtl, |
| 813 PanelLayoutManagerTextDirectionTest, |
820 testing::Bool()); | 814 testing::Bool()); |
821 | 815 |
822 } // namespace ash | 816 } // namespace ash |
OLD | NEW |