| 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/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 11 #include "ash/display/window_tree_host_manager.h" | 11 #include "ash/display/window_tree_host_manager.h" |
| 12 #include "ash/focus_cycler.h" | 12 #include "ash/focus_cycler.h" |
| 13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 14 #include "ash/session/session_state_delegate.h" | 14 #include "ash/session/session_state_delegate.h" |
| 15 #include "ash/shelf/shelf.h" | 15 #include "ash/shelf/shelf.h" |
| 16 #include "ash/shelf/shelf_constants.h" |
| 16 #include "ash/shelf/shelf_layout_manager_observer.h" | 17 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 17 #include "ash/shelf/shelf_locking_manager.h" | 18 #include "ash/shelf/shelf_locking_manager.h" |
| 18 #include "ash/shelf/shelf_view.h" | 19 #include "ash/shelf/shelf_view.h" |
| 19 #include "ash/shelf/shelf_widget.h" | 20 #include "ash/shelf/shelf_widget.h" |
| 20 #include "ash/shell.h" | 21 #include "ash/shell.h" |
| 21 #include "ash/shell_window_ids.h" | 22 #include "ash/shell_window_ids.h" |
| 22 #include "ash/system/status_area_widget.h" | 23 #include "ash/system/status_area_widget.h" |
| 23 #include "ash/system/tray/system_tray.h" | 24 #include "ash/system/tray/system_tray.h" |
| 24 #include "ash/system/tray/system_tray_item.h" | 25 #include "ash/system/tray/system_tray_item.h" |
| 25 #include "ash/test/ash_test_base.h" | 26 #include "ash/test/ash_test_base.h" |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 // Widget is now owned by the parent window. | 839 // Widget is now owned by the parent window. |
| 839 widget->Init(params); | 840 widget->Init(params); |
| 840 widget->Maximize(); | 841 widget->Maximize(); |
| 841 widget->Show(); | 842 widget->Show(); |
| 842 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 843 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
| 843 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 844 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 844 | 845 |
| 845 // LayoutShelf() forces the animation to completion, at which point the | 846 // LayoutShelf() forces the animation to completion, at which point the |
| 846 // shelf should go off the screen. | 847 // shelf should go off the screen. |
| 847 shelf->LayoutShelf(); | 848 shelf->LayoutShelf(); |
| 848 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 849 EXPECT_EQ(root->bounds().bottom() - kAutoHideSize, |
| 849 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 850 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 850 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 851 EXPECT_EQ(root->bounds().bottom() - kAutoHideSize, |
| 851 display::Screen::GetScreen() | 852 display::Screen::GetScreen() |
| 852 ->GetDisplayNearestWindow(root) | 853 ->GetDisplayNearestWindow(root) |
| 853 .work_area() | 854 .work_area() |
| 854 .bottom()); | 855 .bottom()); |
| 855 | 856 |
| 856 // Move the mouse to the bottom of the screen. | 857 // Move the mouse to the bottom of the screen. |
| 857 generator.MoveMouseTo(0, root->bounds().bottom() - 1); | 858 generator.MoveMouseTo(0, root->bounds().bottom() - 1); |
| 858 | 859 |
| 859 // Shelf should be shown again (but it shouldn't have changed the work area). | 860 // Shelf should be shown again (but it shouldn't have changed the work area). |
| 860 SetState(shelf, SHELF_AUTO_HIDE); | 861 SetState(shelf, SHELF_AUTO_HIDE); |
| 861 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 862 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
| 862 shelf->LayoutShelf(); | 863 shelf->LayoutShelf(); |
| 863 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(), | 864 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(), |
| 864 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 865 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 865 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 866 EXPECT_EQ(root->bounds().bottom() - kAutoHideSize, |
| 866 display::Screen::GetScreen() | 867 display::Screen::GetScreen() |
| 867 ->GetDisplayNearestWindow(root) | 868 ->GetDisplayNearestWindow(root) |
| 868 .work_area() | 869 .work_area() |
| 869 .bottom()); | 870 .bottom()); |
| 870 | 871 |
| 871 // Move mouse back up. | 872 // Move mouse back up. |
| 872 generator.MoveMouseTo(0, 0); | 873 generator.MoveMouseTo(0, 0); |
| 873 SetState(shelf, SHELF_AUTO_HIDE); | 874 SetState(shelf, SHELF_AUTO_HIDE); |
| 874 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 875 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 875 shelf->LayoutShelf(); | 876 shelf->LayoutShelf(); |
| 876 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 877 EXPECT_EQ(root->bounds().bottom() - kAutoHideSize, |
| 877 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 878 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 878 | 879 |
| 879 // Drag mouse to bottom of screen. | 880 // Drag mouse to bottom of screen. |
| 880 generator.PressLeftButton(); | 881 generator.PressLeftButton(); |
| 881 generator.MoveMouseTo(0, root->bounds().bottom() - 1); | 882 generator.MoveMouseTo(0, root->bounds().bottom() - 1); |
| 882 UpdateAutoHideStateNow(); | 883 UpdateAutoHideStateNow(); |
| 883 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 884 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 884 | 885 |
| 885 generator.ReleaseLeftButton(); | 886 generator.ReleaseLeftButton(); |
| 886 generator.MoveMouseTo(1, root->bounds().bottom() - 1); | 887 generator.MoveMouseTo(1, root->bounds().bottom() - 1); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 widget->Init(params); | 1008 widget->Init(params); |
| 1008 widget->Maximize(); | 1009 widget->Maximize(); |
| 1009 widget->Show(); | 1010 widget->Show(); |
| 1010 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | 1011 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); |
| 1011 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1012 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 1012 | 1013 |
| 1013 aura::Window* root = Shell::GetPrimaryRootWindow(); | 1014 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 1014 // LayoutShelf() forces the animation to completion, at which point the | 1015 // LayoutShelf() forces the animation to completion, at which point the |
| 1015 // shelf should go off the screen. | 1016 // shelf should go off the screen. |
| 1016 shelf->LayoutShelf(); | 1017 shelf->LayoutShelf(); |
| 1017 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 1018 EXPECT_EQ(root->bounds().bottom() - kAutoHideSize, |
| 1018 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 1019 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 1019 | 1020 |
| 1020 aura::Window* lock_container = Shell::GetContainer( | 1021 aura::Window* lock_container = Shell::GetContainer( |
| 1021 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer); | 1022 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer); |
| 1022 | 1023 |
| 1023 views::Widget* lock_widget = new views::Widget; | 1024 views::Widget* lock_widget = new views::Widget; |
| 1024 views::Widget::InitParams lock_params( | 1025 views::Widget::InitParams lock_params( |
| 1025 views::Widget::InitParams::TYPE_WINDOW); | 1026 views::Widget::InitParams::TYPE_WINDOW); |
| 1026 lock_params.bounds = gfx::Rect(0, 0, 200, 200); | 1027 lock_params.bounds = gfx::Rect(0, 0, 200, 200); |
| 1027 params.context = CurrentContext(); | 1028 params.context = CurrentContext(); |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 EXPECT_EQ(shelf->GetIdealBounds().width(), | 1688 EXPECT_EQ(shelf->GetIdealBounds().width(), |
| 1688 display.GetWorkAreaInsets().left()); | 1689 display.GetWorkAreaInsets().left()); |
| 1689 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 1690 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
| 1690 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 1691 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
| 1691 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); | 1692 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); |
| 1692 EXPECT_EQ(display.bounds().x(), shelf_bounds.x()); | 1693 EXPECT_EQ(display.bounds().x(), shelf_bounds.x()); |
| 1693 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); | 1694 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); |
| 1694 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); | 1695 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); |
| 1695 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1696 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 1696 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1697 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1697 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 1698 EXPECT_EQ(kAutoHideSize, display.GetWorkAreaInsets().left()); |
| 1698 display.GetWorkAreaInsets().left()); | 1699 EXPECT_EQ(kAutoHideSize, display.work_area().x()); |
| 1699 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x()); | |
| 1700 | 1700 |
| 1701 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1701 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 1702 shelf->SetAlignment(wm::SHELF_ALIGNMENT_RIGHT); | 1702 shelf->SetAlignment(wm::SHELF_ALIGNMENT_RIGHT); |
| 1703 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1703 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1704 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); | 1704 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); |
| 1705 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1705 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1706 ASSERT_NE(-1, display.id()); | 1706 ASSERT_NE(-1, display.id()); |
| 1707 EXPECT_EQ(shelf->GetIdealBounds().width(), | 1707 EXPECT_EQ(shelf->GetIdealBounds().width(), |
| 1708 display.GetWorkAreaInsets().right()); | 1708 display.GetWorkAreaInsets().right()); |
| 1709 EXPECT_GE(shelf_bounds.width(), | 1709 EXPECT_GE(shelf_bounds.width(), |
| 1710 GetShelfWidget()->GetContentsView()->GetPreferredSize().width()); | 1710 GetShelfWidget()->GetContentsView()->GetPreferredSize().width()); |
| 1711 EXPECT_EQ(wm::SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment()); | 1711 EXPECT_EQ(wm::SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment()); |
| 1712 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); | 1712 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); |
| 1713 EXPECT_GE(status_bounds.width(), | 1713 EXPECT_GE(status_bounds.width(), |
| 1714 status_area_widget->GetContentsView()->GetPreferredSize().width()); | 1714 status_area_widget->GetContentsView()->GetPreferredSize().width()); |
| 1715 EXPECT_EQ(shelf->GetIdealBounds().width(), | 1715 EXPECT_EQ(shelf->GetIdealBounds().width(), |
| 1716 display.GetWorkAreaInsets().right()); | 1716 display.GetWorkAreaInsets().right()); |
| 1717 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 1717 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
| 1718 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 1718 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
| 1719 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); | 1719 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); |
| 1720 EXPECT_EQ(display.work_area().right(), shelf_bounds.x()); | 1720 EXPECT_EQ(display.work_area().right(), shelf_bounds.x()); |
| 1721 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); | 1721 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); |
| 1722 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); | 1722 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); |
| 1723 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1723 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 1724 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1724 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1725 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 1725 EXPECT_EQ(kAutoHideSize, display.GetWorkAreaInsets().right()); |
| 1726 display.GetWorkAreaInsets().right()); | 1726 EXPECT_EQ(kAutoHideSize, |
| 1727 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, | 1727 display.bounds().right() - display.work_area().right()); |
| 1728 display.bounds().right() - display.work_area().right()); | |
| 1729 } | 1728 } |
| 1730 | 1729 |
| 1731 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) { | 1730 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) { |
| 1732 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 1731 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
| 1733 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1732 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 1734 views::Widget* widget = new views::Widget; | 1733 views::Widget* widget = new views::Widget; |
| 1735 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 1734 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 1736 params.bounds = gfx::Rect(0, 0, 200, 200); | 1735 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 1737 params.context = CurrentContext(); | 1736 params.context = CurrentContext(); |
| 1738 widget->Init(params); | 1737 widget->Init(params); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2294 StatusAreaWidget* status_area_widget = | 2293 StatusAreaWidget* status_area_widget = |
| 2295 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget(); | 2294 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget(); |
| 2296 EXPECT_TRUE(status_area_widget->IsVisible()); | 2295 EXPECT_TRUE(status_area_widget->IsVisible()); |
| 2297 // Shelf should be in the first display's area. | 2296 // Shelf should be in the first display's area. |
| 2298 gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen()); | 2297 gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen()); |
| 2299 EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds)); | 2298 EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds)); |
| 2300 EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right()); | 2299 EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right()); |
| 2301 } | 2300 } |
| 2302 | 2301 |
| 2303 } // namespace ash | 2302 } // namespace ash |
| OLD | NEW |