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/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
| 11 #include "ash/common/focus_cycler.h" | 11 #include "ash/common/focus_cycler.h" |
| 12 #include "ash/common/material_design/material_design_controller.h" | |
| 12 #include "ash/common/session/session_state_delegate.h" | 13 #include "ash/common/session/session_state_delegate.h" |
| 13 #include "ash/common/shelf/shelf_constants.h" | 14 #include "ash/common/shelf/shelf_constants.h" |
| 14 #include "ash/common/shell_window_ids.h" | 15 #include "ash/common/shell_window_ids.h" |
| 15 #include "ash/common/system/tray/system_tray_item.h" | 16 #include "ash/common/system/tray/system_tray_item.h" |
| 16 #include "ash/common/wm/window_state.h" | 17 #include "ash/common/wm/window_state.h" |
| 17 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
| 18 #include "ash/display/display_manager.h" | 19 #include "ash/display/display_manager.h" |
| 19 #include "ash/display/window_tree_host_manager.h" | 20 #include "ash/display/window_tree_host_manager.h" |
| 20 #include "ash/root_window_controller.h" | 21 #include "ash/root_window_controller.h" |
| 21 #include "ash/shelf/shelf.h" | 22 #include "ash/shelf/shelf.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 GetShelfLayoutManager()->GetAlignment()) { | 177 GetShelfLayoutManager()->GetAlignment()) { |
| 177 EXPECT_EQ(not_visible_bounds_.x(), shelf_bounds.x()); | 178 EXPECT_EQ(not_visible_bounds_.x(), shelf_bounds.x()); |
| 178 EXPECT_EQ(visible_bounds_.x(), shelf_bounds.x()); | 179 EXPECT_EQ(visible_bounds_.x(), shelf_bounds.x()); |
| 179 } | 180 } |
| 180 | 181 |
| 181 // if the shelf is being dimmed test dimmer bounds as well. | 182 // if the shelf is being dimmed test dimmer bounds as well. |
| 182 if (GetShelfWidget()->GetDimsShelf()) | 183 if (GetShelfWidget()->GetDimsShelf()) |
| 183 EXPECT_EQ(GetShelfWidget()->GetWindowBoundsInScreen(), | 184 EXPECT_EQ(GetShelfWidget()->GetWindowBoundsInScreen(), |
| 184 GetShelfWidget()->GetDimmerBoundsForTest()); | 185 GetShelfWidget()->GetDimmerBoundsForTest()); |
| 185 | 186 |
| 186 // The shelf should never be smaller than the hidden state when shelf is | 187 // For non-MD, the shelf should never be smaller than the hidden state. |
| 187 // visible; the shelf has a height of 0 when it is hidden. | 188 if (!ash::MaterialDesignController::IsShelfMaterial()) { |
| 188 if (was_visible_on_drag_start_) | |
| 189 EXPECT_GE(shelf_bounds.height(), not_visible_bounds_.height()); | 189 EXPECT_GE(shelf_bounds.height(), not_visible_bounds_.height()); |
| 190 | |
| 191 // For MD, when shelf is at the auto hidden state, it has visible height | |
| 192 // of 0 and not_visible_bounds height is non zero and it is used to detect | |
| 193 // movements. | |
| 194 } else { | |
| 195 if (GetShelf()->GetAutoHideState() != ash::SHELF_AUTO_HIDE_HIDDEN) { | |
|
bruthig
2016/07/13 19:36:51
Can you collapse this 'if'/'else if' into a single
yiyix
2016/07/14 18:24:49
Done.
| |
| 196 EXPECT_GE(shelf_bounds.height(), not_visible_bounds_.height()); | |
| 197 } | |
| 198 } | |
| 190 float scroll_delta = | 199 float scroll_delta = |
| 191 GetShelfLayoutManager()->PrimaryAxisValue(scroll_.y(), scroll_.x()); | 200 GetShelfLayoutManager()->PrimaryAxisValue(scroll_.y(), scroll_.x()); |
| 192 bool increasing_drag = | 201 bool increasing_drag = |
| 193 GetShelfWidget()->shelf()->SelectValueForShelfAlignment( | 202 GetShelfWidget()->shelf()->SelectValueForShelfAlignment( |
| 194 scroll_delta<0, scroll_delta> 0, scroll_delta < 0); | 203 scroll_delta<0, scroll_delta> 0, scroll_delta < 0); |
| 195 int shelf_size = GetShelfLayoutManager()->PrimaryAxisValue( | 204 int shelf_size = GetShelfLayoutManager()->PrimaryAxisValue( |
| 196 shelf_bounds.height(), shelf_bounds.width()); | 205 shelf_bounds.height(), shelf_bounds.width()); |
| 197 int visible_bounds_size = GetShelfLayoutManager()->PrimaryAxisValue( | 206 int visible_bounds_size = GetShelfLayoutManager()->PrimaryAxisValue( |
| 198 visible_bounds_.height(), visible_bounds_.width()); | 207 visible_bounds_.height(), visible_bounds_.width()); |
| 199 int not_visible_bounds_size = GetShelfLayoutManager()->PrimaryAxisValue( | 208 int not_visible_bounds_size = GetShelfLayoutManager()->PrimaryAxisValue( |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 GetShelfWidget()->GetWindowBoundsInScreen().ToString()); | 594 GetShelfWidget()->GetWindowBoundsInScreen().ToString()); |
| 586 | 595 |
| 587 // Put |widget| into fullscreen. Set the shelf to be auto hidden when |widget| | 596 // Put |widget| into fullscreen. Set the shelf to be auto hidden when |widget| |
| 588 // is fullscreen. (eg browser immersive fullscreen). | 597 // is fullscreen. (eg browser immersive fullscreen). |
| 589 widget->SetFullscreen(true); | 598 widget->SetFullscreen(true); |
| 590 wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(false); | 599 wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(false); |
| 591 layout_manager->UpdateVisibilityState(); | 600 layout_manager->UpdateVisibilityState(); |
| 592 | 601 |
| 593 gfx::Rect bounds_fullscreen = window->bounds(); | 602 gfx::Rect bounds_fullscreen = window->bounds(); |
| 594 EXPECT_TRUE(widget->IsFullscreen()); | 603 EXPECT_TRUE(widget->IsFullscreen()); |
| 595 EXPECT_NE(bounds_noshelf.ToString(), bounds_fullscreen.ToString()); | 604 |
| 605 // For non-MD, some immersive hints are shown on both top and bottom in | |
| 606 // immersive mode; and for MD, the window has the same behavior in both | |
| 607 // immersive mode and full screen mode. | |
| 608 if (ash::MaterialDesignController::IsShelfMaterial()) | |
| 609 EXPECT_EQ(bounds_noshelf.ToString(), bounds_fullscreen.ToString()); | |
| 610 else | |
| 611 EXPECT_NE(bounds_noshelf.ToString(), bounds_fullscreen.ToString()); | |
| 596 | 612 |
| 597 // Swipe up. This should show the shelf. | 613 // Swipe up. This should show the shelf. |
| 598 end = below_start - delta; | 614 end = below_start - delta; |
| 599 generator.GestureScrollSequenceWithCallback( | 615 generator.GestureScrollSequenceWithCallback( |
| 600 below_start, end, kTimeDelta, kNumScrollSteps, | 616 below_start, end, kTimeDelta, kNumScrollSteps, |
| 601 base::Bind(&ShelfDragCallback::ProcessScroll, | 617 base::Bind(&ShelfDragCallback::ProcessScroll, |
| 602 base::Unretained(&handler))); | 618 base::Unretained(&handler))); |
| 603 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 619 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
| 604 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); | 620 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); |
| 605 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); | 621 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 widget->Init(params); | 822 widget->Init(params); |
| 807 widget->Maximize(); | 823 widget->Maximize(); |
| 808 widget->Show(); | 824 widget->Show(); |
| 809 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 825 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
| 810 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 826 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 811 | 827 |
| 812 // LayoutShelf() forces the animation to completion, at which point the | 828 // LayoutShelf() forces the animation to completion, at which point the |
| 813 // shelf should go off the screen. | 829 // shelf should go off the screen. |
| 814 layout_manager->LayoutShelf(); | 830 layout_manager->LayoutShelf(); |
| 815 int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); | 831 int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); |
| 816 EXPECT_EQ(root->bounds().bottom() - shelf_insets, | 832 |
| 833 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, | |
| 817 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 834 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 818 EXPECT_EQ(root->bounds().bottom() - shelf_insets, | 835 EXPECT_EQ(root->bounds().bottom() - shelf_insets, |
| 819 display::Screen::GetScreen() | 836 display::Screen::GetScreen() |
| 820 ->GetDisplayNearestWindow(root) | 837 ->GetDisplayNearestWindow(root) |
| 821 .work_area() | 838 .work_area() |
| 822 .bottom()); | 839 .bottom()); |
| 823 | 840 |
| 824 // Move the mouse to the bottom of the screen. | 841 // Move the mouse to the bottom of the screen. |
| 825 generator.MoveMouseTo(0, root->bounds().bottom() - 1); | 842 generator.MoveMouseTo(0, root->bounds().bottom() - 1); |
| 826 | 843 |
| 827 // Shelf should be shown again (but it shouldn't have changed the work area). | 844 // Shelf should be shown again (but it shouldn't have changed the work area). |
| 828 SetState(layout_manager, SHELF_AUTO_HIDE); | 845 SetState(layout_manager, SHELF_AUTO_HIDE); |
| 829 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); | 846 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); |
| 830 layout_manager->LayoutShelf(); | 847 layout_manager->LayoutShelf(); |
| 831 EXPECT_EQ(root->bounds().bottom() - layout_manager->GetIdealBounds().height(), | 848 EXPECT_EQ(root->bounds().bottom() - layout_manager->GetIdealBounds().height(), |
| 832 GetShelfWidget()->GetWindowBoundsInScreen().y()); | 849 GetShelfWidget()->GetWindowBoundsInScreen().y()); |
| 833 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, | 850 EXPECT_EQ(root->bounds().bottom() - shelf_insets, |
| 834 display::Screen::GetScreen() | 851 display::Screen::GetScreen() |
| 835 ->GetDisplayNearestWindow(root) | 852 ->GetDisplayNearestWindow(root) |
| 836 .work_area() | 853 .work_area() |
| 837 .bottom()); | 854 .bottom()); |
| 838 | 855 |
| 839 // Move mouse back up. | 856 // Move mouse back up. |
| 840 generator.MoveMouseTo(0, 0); | 857 generator.MoveMouseTo(0, 0); |
| 841 SetState(layout_manager, SHELF_AUTO_HIDE); | 858 SetState(layout_manager, SHELF_AUTO_HIDE); |
| 842 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 859 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 843 layout_manager->LayoutShelf(); | 860 layout_manager->LayoutShelf(); |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1697 EXPECT_EQ(layout_manager->GetIdealBounds().width(), | 1714 EXPECT_EQ(layout_manager->GetIdealBounds().width(), |
| 1698 display.GetWorkAreaInsets().right()); | 1715 display.GetWorkAreaInsets().right()); |
| 1699 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 1716 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
| 1700 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 1717 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
| 1701 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); | 1718 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); |
| 1702 EXPECT_EQ(display.work_area().right(), shelf_bounds.x()); | 1719 EXPECT_EQ(display.work_area().right(), shelf_bounds.x()); |
| 1703 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); | 1720 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); |
| 1704 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); | 1721 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); |
| 1705 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1722 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 1706 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 1723 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
| 1707 EXPECT_EQ(kShelfAutoHideSize, display.GetWorkAreaInsets().right()); | 1724 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE), |
| 1708 EXPECT_EQ(kShelfAutoHideSize, | 1725 display.GetWorkAreaInsets().right()); |
| 1726 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE), | |
| 1709 display.bounds().right() - display.work_area().right()); | 1727 display.bounds().right() - display.work_area().right()); |
| 1710 } | 1728 } |
| 1711 | 1729 |
| 1712 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) { | 1730 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) { |
| 1713 Shelf* shelf = GetShelf(); | 1731 Shelf* shelf = GetShelf(); |
| 1714 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); | 1732 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); |
| 1715 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1733 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 1716 views::Widget* widget = new views::Widget; | 1734 views::Widget* widget = new views::Widget; |
| 1717 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 1735 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 1718 params.bounds = gfx::Rect(0, 0, 200, 200); | 1736 params.bounds = gfx::Rect(0, 0, 200, 200); |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2265 ->shelf_widget() | 2283 ->shelf_widget() |
| 2266 ->status_area_widget(); | 2284 ->status_area_widget(); |
| 2267 EXPECT_TRUE(status_area_widget->IsVisible()); | 2285 EXPECT_TRUE(status_area_widget->IsVisible()); |
| 2268 // Shelf should be in the first display's area. | 2286 // Shelf should be in the first display's area. |
| 2269 gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen()); | 2287 gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen()); |
| 2270 EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds)); | 2288 EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds)); |
| 2271 EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right()); | 2289 EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right()); |
| 2272 } | 2290 } |
| 2273 | 2291 |
| 2274 } // namespace ash | 2292 } // namespace ash |
| OLD | NEW |