Chromium Code Reviews| 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/shelf/shelf_layout_manager.h" | 5 #include "ash/shelf/shelf_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
| 9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| 11 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
| 12 #include "ash/common/wm/window_state.h" | 12 #include "ash/common/wm/window_state.h" |
| 13 #include "ash/display/display_manager.h" | 13 #include "ash/display/display_manager.h" |
| 14 #include "ash/display/window_tree_host_manager.h" | 14 #include "ash/display/window_tree_host_manager.h" |
| 15 #include "ash/focus_cycler.h" | 15 #include "ash/focus_cycler.h" |
| 16 #include "ash/root_window_controller.h" | 16 #include "ash/root_window_controller.h" |
| 17 #include "ash/shelf/shelf.h" | 17 #include "ash/shelf/shelf.h" |
| 18 #include "ash/shelf/shelf_constants.h" | |
|
tdanderson
2016/06/10 22:54:43
This file moved to ash/common. (If you don't run t
yiyix
2016/06/13 18:43:54
I only build the chrome target... thanks, I will d
| |
| 18 #include "ash/shelf/shelf_layout_manager_observer.h" | 19 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 19 #include "ash/shelf/shelf_locking_manager.h" | 20 #include "ash/shelf/shelf_locking_manager.h" |
| 20 #include "ash/shelf/shelf_view.h" | 21 #include "ash/shelf/shelf_view.h" |
| 21 #include "ash/shelf/shelf_widget.h" | 22 #include "ash/shelf/shelf_widget.h" |
| 22 #include "ash/shell.h" | 23 #include "ash/shell.h" |
| 23 #include "ash/system/status_area_widget.h" | 24 #include "ash/system/status_area_widget.h" |
| 24 #include "ash/system/tray/system_tray.h" | 25 #include "ash/system/tray/system_tray.h" |
| 25 #include "ash/system/tray/system_tray_item.h" | 26 #include "ash/system/tray/system_tray_item.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" |
| (...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 // Widget is now owned by the parent window. | 855 // Widget is now owned by the parent window. |
| 855 widget->Init(params); | 856 widget->Init(params); |
| 856 widget->Maximize(); | 857 widget->Maximize(); |
| 857 widget->Show(); | 858 widget->Show(); |
| 858 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 859 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
| 859 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 860 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 860 | 861 |
| 861 // LayoutShelf() forces the animation to completion, at which point the | 862 // LayoutShelf() forces the animation to completion, at which point the |
| 862 // shelf should go off the screen. | 863 // shelf should go off the screen. |
| 863 layout_manager->LayoutShelf(); | 864 layout_manager->LayoutShelf(); |
| 864 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 865 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, |
| 865 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 866 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 866 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 867 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, |
| 867 display::Screen::GetScreen() | 868 display::Screen::GetScreen() |
| 868 ->GetDisplayNearestWindow(root) | 869 ->GetDisplayNearestWindow(root) |
| 869 .work_area() | 870 .work_area() |
| 870 .bottom()); | 871 .bottom()); |
| 871 | 872 |
| 872 // Move the mouse to the bottom of the screen. | 873 // Move the mouse to the bottom of the screen. |
| 873 generator.MoveMouseTo(0, root->bounds().bottom() - 1); | 874 generator.MoveMouseTo(0, root->bounds().bottom() - 1); |
| 874 | 875 |
| 875 // Shelf should be shown again (but it shouldn't have changed the work area). | 876 // Shelf should be shown again (but it shouldn't have changed the work area). |
| 876 SetState(layout_manager, SHELF_AUTO_HIDE); | 877 SetState(layout_manager, SHELF_AUTO_HIDE); |
| 877 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); | 878 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); |
| 878 layout_manager->LayoutShelf(); | 879 layout_manager->LayoutShelf(); |
| 879 EXPECT_EQ(root->bounds().bottom() - layout_manager->GetIdealBounds().height(), | 880 EXPECT_EQ(root->bounds().bottom() - layout_manager->GetIdealBounds().height(), |
| 880 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 881 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 881 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 882 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, |
| 882 display::Screen::GetScreen() | 883 display::Screen::GetScreen() |
| 883 ->GetDisplayNearestWindow(root) | 884 ->GetDisplayNearestWindow(root) |
| 884 .work_area() | 885 .work_area() |
| 885 .bottom()); | 886 .bottom()); |
| 886 | 887 |
| 887 // Move mouse back up. | 888 // Move mouse back up. |
| 888 generator.MoveMouseTo(0, 0); | 889 generator.MoveMouseTo(0, 0); |
| 889 SetState(layout_manager, SHELF_AUTO_HIDE); | 890 SetState(layout_manager, SHELF_AUTO_HIDE); |
| 890 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 891 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 891 layout_manager->LayoutShelf(); | 892 layout_manager->LayoutShelf(); |
| 892 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 893 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, |
| 893 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 894 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 894 | 895 |
| 895 // Drag mouse to bottom of screen. | 896 // Drag mouse to bottom of screen. |
| 896 generator.PressLeftButton(); | 897 generator.PressLeftButton(); |
| 897 generator.MoveMouseTo(0, root->bounds().bottom() - 1); | 898 generator.MoveMouseTo(0, root->bounds().bottom() - 1); |
| 898 UpdateAutoHideStateNow(); | 899 UpdateAutoHideStateNow(); |
| 899 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 900 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 900 | 901 |
| 901 generator.ReleaseLeftButton(); | 902 generator.ReleaseLeftButton(); |
| 902 generator.MoveMouseTo(1, root->bounds().bottom() - 1); | 903 generator.MoveMouseTo(1, root->bounds().bottom() - 1); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1024 widget->Init(params); | 1025 widget->Init(params); |
| 1025 widget->Maximize(); | 1026 widget->Maximize(); |
| 1026 widget->Show(); | 1027 widget->Show(); |
| 1027 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 1028 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
| 1028 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 1029 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 1029 | 1030 |
| 1030 aura::Window* root = Shell::GetPrimaryRootWindow(); | 1031 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 1031 // LayoutShelf() forces the animation to completion, at which point the | 1032 // LayoutShelf() forces the animation to completion, at which point the |
| 1032 // shelf should go off the screen. | 1033 // shelf should go off the screen. |
| 1033 layout_manager->LayoutShelf(); | 1034 layout_manager->LayoutShelf(); |
| 1034 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 1035 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, |
| 1035 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 1036 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 1036 | 1037 |
| 1037 aura::Window* lock_container = Shell::GetContainer( | 1038 aura::Window* lock_container = Shell::GetContainer( |
| 1038 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer); | 1039 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer); |
| 1039 | 1040 |
| 1040 views::Widget* lock_widget = new views::Widget; | 1041 views::Widget* lock_widget = new views::Widget; |
| 1041 views::Widget::InitParams lock_params( | 1042 views::Widget::InitParams lock_params( |
| 1042 views::Widget::InitParams::TYPE_WINDOW); | 1043 views::Widget::InitParams::TYPE_WINDOW); |
| 1043 lock_params.bounds = gfx::Rect(0, 0, 200, 200); | 1044 lock_params.bounds = gfx::Rect(0, 0, 200, 200); |
| 1044 params.context = CurrentContext(); | 1045 params.context = CurrentContext(); |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1703 EXPECT_EQ(layout_manager->GetIdealBounds().width(), | 1704 EXPECT_EQ(layout_manager->GetIdealBounds().width(), |
| 1704 display.GetWorkAreaInsets().left()); | 1705 display.GetWorkAreaInsets().left()); |
| 1705 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 1706 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
| 1706 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 1707 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
| 1707 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); | 1708 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); |
| 1708 EXPECT_EQ(display.bounds().x(), shelf_bounds.x()); | 1709 EXPECT_EQ(display.bounds().x(), shelf_bounds.x()); |
| 1709 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); | 1710 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); |
| 1710 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); | 1711 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); |
| 1711 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1712 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 1712 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1713 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1713 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 1714 EXPECT_EQ(kShelfAutoHideSize, display.GetWorkAreaInsets().left()); |
| 1714 display.GetWorkAreaInsets().left()); | 1715 EXPECT_EQ(kShelfAutoHideSize, display.work_area().x()); |
| 1715 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x()); | |
| 1716 | 1716 |
| 1717 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1717 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 1718 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); | 1718 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
| 1719 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1719 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1720 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); | 1720 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); |
| 1721 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1721 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1722 ASSERT_NE(-1, display.id()); | 1722 ASSERT_NE(-1, display.id()); |
| 1723 EXPECT_EQ(layout_manager->GetIdealBounds().width(), | 1723 EXPECT_EQ(layout_manager->GetIdealBounds().width(), |
| 1724 display.GetWorkAreaInsets().right()); | 1724 display.GetWorkAreaInsets().right()); |
| 1725 EXPECT_GE(shelf_bounds.width(), | 1725 EXPECT_GE(shelf_bounds.width(), |
| 1726 GetShelfWidget()->GetContentsView()->GetPreferredSize().width()); | 1726 GetShelfWidget()->GetContentsView()->GetPreferredSize().width()); |
| 1727 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment()); | 1727 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment()); |
| 1728 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); | 1728 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); |
| 1729 EXPECT_GE(status_bounds.width(), | 1729 EXPECT_GE(status_bounds.width(), |
| 1730 status_area_widget->GetContentsView()->GetPreferredSize().width()); | 1730 status_area_widget->GetContentsView()->GetPreferredSize().width()); |
| 1731 EXPECT_EQ(layout_manager->GetIdealBounds().width(), | 1731 EXPECT_EQ(layout_manager->GetIdealBounds().width(), |
| 1732 display.GetWorkAreaInsets().right()); | 1732 display.GetWorkAreaInsets().right()); |
| 1733 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 1733 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
| 1734 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 1734 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
| 1735 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); | 1735 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); |
| 1736 EXPECT_EQ(display.work_area().right(), shelf_bounds.x()); | 1736 EXPECT_EQ(display.work_area().right(), shelf_bounds.x()); |
| 1737 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); | 1737 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); |
| 1738 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); | 1738 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); |
| 1739 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1739 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 1740 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1740 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1741 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 1741 EXPECT_EQ(kShelfAutoHideSize, display.GetWorkAreaInsets().right()); |
| 1742 display.GetWorkAreaInsets().right()); | 1742 EXPECT_EQ(kShelfAutoHideSize, |
| 1743 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 1743 display.bounds().right() - display.work_area().right()); |
| 1744 display.bounds().right() - display.work_area().right()); | |
| 1745 } | 1744 } |
| 1746 | 1745 |
| 1747 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) { | 1746 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) { |
| 1748 Shelf* shelf = GetShelf(); | 1747 Shelf* shelf = GetShelf(); |
| 1749 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); | 1748 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); |
| 1750 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1749 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 1751 views::Widget* widget = new views::Widget; | 1750 views::Widget* widget = new views::Widget; |
| 1752 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 1751 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 1753 params.bounds = gfx::Rect(0, 0, 200, 200); | 1752 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 1754 params.context = CurrentContext(); | 1753 params.context = CurrentContext(); |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2319 ->shelf_widget() | 2318 ->shelf_widget() |
| 2320 ->status_area_widget(); | 2319 ->status_area_widget(); |
| 2321 EXPECT_TRUE(status_area_widget->IsVisible()); | 2320 EXPECT_TRUE(status_area_widget->IsVisible()); |
| 2322 // Shelf should be in the first display's area. | 2321 // Shelf should be in the first display's area. |
| 2323 gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen()); | 2322 gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen()); |
| 2324 EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds)); | 2323 EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds)); |
| 2325 EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right()); | 2324 EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right()); |
| 2326 } | 2325 } |
| 2327 | 2326 |
| 2328 } // namespace ash | 2327 } // namespace ash |
| OLD | NEW |