| 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/wm/shelf_layout_manager.h" | 5 #include "ash/wm/shelf_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ui/aura/env.h" |
| 13 #include "ui/aura/monitor.h" |
| 14 #include "ui/aura/monitor_manager.h" |
| 12 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 14 #include "ui/base/animation/animation_container_element.h" | 17 #include "ui/base/animation/animation_container_element.h" |
| 15 #include "ui/gfx/compositor/layer_animator.h" | 18 #include "ui/gfx/compositor/layer_animator.h" |
| 16 #include "ui/gfx/compositor/layer.h" | 19 #include "ui/gfx/compositor/layer.h" |
| 20 #include "ui/gfx/screen.h" |
| 17 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 18 | 22 |
| 19 namespace ash { | 23 namespace ash { |
| 20 namespace internal { | 24 namespace internal { |
| 21 | 25 |
| 22 namespace { | 26 namespace { |
| 23 | 27 |
| 24 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) { | 28 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) { |
| 25 ui::AnimationContainerElement* element = | 29 ui::AnimationContainerElement* element = |
| 26 static_cast<ui::AnimationContainerElement*>( | 30 static_cast<ui::AnimationContainerElement*>( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 43 #define MAYBE_SetVisible FAILS_SetVisible | 47 #define MAYBE_SetVisible FAILS_SetVisible |
| 44 #else | 48 #else |
| 45 #define MAYBE_SetVisible SetVisible | 49 #define MAYBE_SetVisible SetVisible |
| 46 #endif | 50 #endif |
| 47 // Makes sure SetVisible updates work area and widget appropriately. | 51 // Makes sure SetVisible updates work area and widget appropriately. |
| 48 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { | 52 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { |
| 49 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 53 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
| 50 // Force an initial layout. | 54 // Force an initial layout. |
| 51 shelf->LayoutShelf(); | 55 shelf->LayoutShelf(); |
| 52 ASSERT_TRUE(shelf->visible()); | 56 ASSERT_TRUE(shelf->visible()); |
| 53 | 57 const aura::MonitorManager* manager = |
| 54 const ash::ScreenAsh* screen = Shell::GetInstance()->screen(); | 58 aura::Env::GetInstance()->monitor_manager(); |
| 55 ASSERT_TRUE(screen); | 59 const aura::Monitor* monitor = |
| 60 manager->GetMonitorNearestWindow(Shell::GetRootWindow()); |
| 61 ASSERT_TRUE(monitor); |
| 56 // Bottom inset should be the max of widget heights. | 62 // Bottom inset should be the max of widget heights. |
| 57 EXPECT_EQ(shelf->max_height(), screen->work_area_insets().bottom()); | 63 EXPECT_EQ(shelf->max_height(), monitor->work_area_insets().bottom()); |
| 58 | 64 |
| 59 // Hide the shelf. | 65 // Hide the shelf. |
| 60 shelf->SetVisible(false); | 66 shelf->SetVisible(false); |
| 61 // Run the animation to completion. | 67 // Run the animation to completion. |
| 62 StepWidgetLayerAnimatorToEnd(shelf->launcher()); | 68 StepWidgetLayerAnimatorToEnd(shelf->launcher()); |
| 63 StepWidgetLayerAnimatorToEnd(shelf->status()); | 69 StepWidgetLayerAnimatorToEnd(shelf->status()); |
| 64 EXPECT_FALSE(shelf->visible()); | 70 EXPECT_FALSE(shelf->visible()); |
| 65 EXPECT_EQ(0, screen->work_area_insets().bottom()); | 71 EXPECT_EQ(0, monitor->work_area_insets().bottom()); |
| 66 | 72 |
| 67 // Make sure the bounds of the two widgets changed. | 73 // Make sure the bounds of the two widgets changed. |
| 68 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), | 74 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), |
| 69 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 75 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
| 70 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 76 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), |
| 71 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 77 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
| 72 | 78 |
| 73 // And show it again. | 79 // And show it again. |
| 74 shelf->SetVisible(true); | 80 shelf->SetVisible(true); |
| 75 // Run the animation to completion. | 81 // Run the animation to completion. |
| 76 StepWidgetLayerAnimatorToEnd(shelf->launcher()); | 82 StepWidgetLayerAnimatorToEnd(shelf->launcher()); |
| 77 StepWidgetLayerAnimatorToEnd(shelf->status()); | 83 StepWidgetLayerAnimatorToEnd(shelf->status()); |
| 78 EXPECT_TRUE(shelf->visible()); | 84 EXPECT_TRUE(shelf->visible()); |
| 79 EXPECT_EQ(shelf->max_height(), screen->work_area_insets().bottom()); | 85 EXPECT_EQ(shelf->max_height(), monitor->work_area_insets().bottom()); |
| 80 | 86 |
| 81 // Make sure the bounds of the two widgets changed. | 87 // Make sure the bounds of the two widgets changed. |
| 82 gfx::Rect launcher_bounds(shelf->launcher()->GetNativeView()->bounds()); | 88 gfx::Rect launcher_bounds(shelf->launcher()->GetNativeView()->bounds()); |
| 83 int bottom = gfx::Screen::GetPrimaryMonitorBounds().bottom() - | 89 int bottom = gfx::Screen::GetPrimaryMonitorBounds().bottom() - |
| 84 shelf->max_height(); | 90 shelf->max_height(); |
| 85 EXPECT_EQ(launcher_bounds.y(), | 91 EXPECT_EQ(launcher_bounds.y(), |
| 86 bottom + (shelf->max_height() - launcher_bounds.height()) / 2); | 92 bottom + (shelf->max_height() - launcher_bounds.height()) / 2); |
| 87 gfx::Rect status_bounds(shelf->status()->GetNativeView()->bounds()); | 93 gfx::Rect status_bounds(shelf->status()->GetNativeView()->bounds()); |
| 88 EXPECT_EQ(status_bounds.y(), | 94 EXPECT_EQ(status_bounds.y(), |
| 89 bottom + shelf->max_height() - status_bounds.height()); | 95 bottom + shelf->max_height() - status_bounds.height()); |
| 90 } | 96 } |
| 91 | 97 |
| 92 // Makes sure LayoutShelf invoked while animating cleans things up. | 98 // Makes sure LayoutShelf invoked while animating cleans things up. |
| 93 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { | 99 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { |
| 94 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 100 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
| 95 // Force an initial layout. | 101 // Force an initial layout. |
| 96 shelf->LayoutShelf(); | 102 shelf->LayoutShelf(); |
| 97 ASSERT_TRUE(shelf->visible()); | 103 ASSERT_TRUE(shelf->visible()); |
| 98 | 104 |
| 99 const ash::ScreenAsh* screen = Shell::GetInstance()->screen(); | 105 const aura::MonitorManager* manager = |
| 106 aura::Env::GetInstance()->monitor_manager(); |
| 107 const aura::Monitor* monitor = |
| 108 manager->GetMonitorNearestWindow(Shell::GetRootWindow()); |
| 100 | 109 |
| 101 // Hide the shelf. | 110 // Hide the shelf. |
| 102 shelf->SetVisible(false); | 111 shelf->SetVisible(false); |
| 103 shelf->LayoutShelf(); | 112 shelf->LayoutShelf(); |
| 104 EXPECT_FALSE(shelf->visible()); | 113 EXPECT_FALSE(shelf->visible()); |
| 105 EXPECT_FALSE(shelf->visible()); | 114 EXPECT_FALSE(shelf->visible()); |
| 106 EXPECT_EQ(0, screen->work_area_insets().bottom()); | 115 EXPECT_EQ(0, monitor->work_area_insets().bottom()); |
| 107 // Make sure the bounds of the two widgets changed. | 116 // Make sure the bounds of the two widgets changed. |
| 108 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), | 117 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), |
| 109 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 118 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
| 110 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 119 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), |
| 111 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 120 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
| 112 } | 121 } |
| 113 | 122 |
| 114 // Makes sure the launcher is initially sized correctly. | 123 // Makes sure the launcher is initially sized correctly. |
| 115 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { | 124 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { |
| 116 Launcher* launcher = Shell::GetInstance()->launcher(); | 125 Launcher* launcher = Shell::GetInstance()->launcher(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 142 views::Widget* widget = new views::Widget; | 151 views::Widget* widget = new views::Widget; |
| 143 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 152 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 144 params.bounds = gfx::Rect(0, 0, 200, 200); | 153 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 145 // Widget is now owned by the parent window. | 154 // Widget is now owned by the parent window. |
| 146 widget->Init(params); | 155 widget->Init(params); |
| 147 widget->SetFullscreen(true); | 156 widget->SetFullscreen(true); |
| 148 } | 157 } |
| 149 | 158 |
| 150 } // namespace internal | 159 } // namespace internal |
| 151 } // namespace ash | 160 } // namespace ash |
| OLD | NEW |