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/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() + ShelfLayoutManager::kWorkspaceAreaBottomInset, | 63 EXPECT_EQ(shelf->max_height() + ShelfLayoutManager::kWorkspaceAreaBottomInset, |
| 58 screen->work_area_insets().bottom()); | 64 monitor->work_area_insets().bottom()); |
| 59 | 65 |
| 60 // Hide the shelf. | 66 // Hide the shelf. |
| 61 shelf->SetVisible(false); | 67 shelf->SetVisible(false); |
| 62 // Run the animation to completion. | 68 // Run the animation to completion. |
| 63 StepWidgetLayerAnimatorToEnd(shelf->launcher()); | 69 StepWidgetLayerAnimatorToEnd(shelf->launcher()); |
| 64 StepWidgetLayerAnimatorToEnd(shelf->status()); | 70 StepWidgetLayerAnimatorToEnd(shelf->status()); |
| 65 EXPECT_FALSE(shelf->visible()); | 71 EXPECT_FALSE(shelf->visible()); |
| 66 EXPECT_EQ(0, screen->work_area_insets().bottom()); | 72 EXPECT_EQ(0, monitor->work_area_insets().bottom()); |
| 67 | 73 |
| 68 // Make sure the bounds of the two widgets changed. | 74 // Make sure the bounds of the two widgets changed. |
| 69 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), | 75 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), |
| 70 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 76 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
| 71 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 77 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), |
| 72 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 78 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
| 73 | 79 |
| 74 // And show it again. | 80 // And show it again. |
| 75 shelf->SetVisible(true); | 81 shelf->SetVisible(true); |
| 76 // Run the animation to completion. | 82 // Run the animation to completion. |
| 77 StepWidgetLayerAnimatorToEnd(shelf->launcher()); | 83 StepWidgetLayerAnimatorToEnd(shelf->launcher()); |
| 78 StepWidgetLayerAnimatorToEnd(shelf->status()); | 84 StepWidgetLayerAnimatorToEnd(shelf->status()); |
| 79 EXPECT_TRUE(shelf->visible()); | 85 EXPECT_TRUE(shelf->visible()); |
| 80 EXPECT_EQ(shelf->max_height() + ShelfLayoutManager::kWorkspaceAreaBottomInset, | 86 EXPECT_EQ(shelf->max_height() + ShelfLayoutManager::kWorkspaceAreaBottomInset, |
| 81 screen->work_area_insets().bottom()); | 87 monitor->work_area_insets().bottom()); |
| 82 | 88 |
| 83 // Make sure the bounds of the two widgets changed. | 89 // Make sure the bounds of the two widgets changed. |
| 84 gfx::Rect launcher_bounds(shelf->launcher()->GetNativeView()->bounds()); | 90 gfx::Rect launcher_bounds(shelf->launcher()->GetNativeView()->bounds()); |
| 85 int bottom = gfx::Screen::GetPrimaryMonitorBounds().bottom() - | 91 int bottom = gfx::Screen::GetPrimaryMonitorBounds().bottom() - |
| 86 shelf->max_height(); | 92 shelf->max_height(); |
| 87 EXPECT_EQ(launcher_bounds.y(), | 93 EXPECT_EQ(launcher_bounds.y(), |
| 88 bottom + (shelf->max_height() - launcher_bounds.height()) / 2); | 94 bottom + (shelf->max_height() - launcher_bounds.height()) / 2); |
| 89 gfx::Rect status_bounds(shelf->status()->GetNativeView()->bounds()); | 95 gfx::Rect status_bounds(shelf->status()->GetNativeView()->bounds()); |
| 90 EXPECT_EQ(status_bounds.y(), | 96 EXPECT_EQ(status_bounds.y(), |
| 91 bottom + shelf->max_height() - status_bounds.height()); | 97 bottom + shelf->max_height() - status_bounds.height()); |
| 92 } | 98 } |
| 93 | 99 |
| 94 // Makes sure LayoutShelf invoked while animating cleans things up. | 100 // Makes sure LayoutShelf invoked while animating cleans things up. |
| 95 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { | 101 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { |
| 96 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 102 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
| 97 // Force an initial layout. | 103 // Force an initial layout. |
| 98 shelf->LayoutShelf(); | 104 shelf->LayoutShelf(); |
| 99 ASSERT_TRUE(shelf->visible()); | 105 ASSERT_TRUE(shelf->visible()); |
| 100 | 106 |
| 101 const ash::ScreenAsh* screen = Shell::GetInstance()->screen(); | 107 const aura::MonitorManager* manager = |
| 108 aura::Env::GetInstance()->monitor_manager(); | |
| 109 const aura::Monitor* monitor = | |
| 110 manager->GetMonitorNearestWindow(Shell::GetRootWindow()); | |
|
Ben Goodger (Google)
2012/03/14 17:01:26
I suspect we'll want some convenience function tha
oshima
2012/03/14 17:19:43
I'm thinking of refacotring gfx::Screen to return
| |
| 102 | 111 |
| 103 // Hide the shelf. | 112 // Hide the shelf. |
| 104 shelf->SetVisible(false); | 113 shelf->SetVisible(false); |
| 105 shelf->LayoutShelf(); | 114 shelf->LayoutShelf(); |
| 106 EXPECT_FALSE(shelf->visible()); | 115 EXPECT_FALSE(shelf->visible()); |
| 107 EXPECT_FALSE(shelf->visible()); | 116 EXPECT_FALSE(shelf->visible()); |
| 108 EXPECT_EQ(0, screen->work_area_insets().bottom()); | 117 EXPECT_EQ(0, monitor->work_area_insets().bottom()); |
| 109 // Make sure the bounds of the two widgets changed. | 118 // Make sure the bounds of the two widgets changed. |
| 110 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), | 119 EXPECT_GE(shelf->launcher()->GetNativeView()->bounds().y(), |
| 111 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 120 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
| 112 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 121 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), |
| 113 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 122 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
| 114 } | 123 } |
| 115 | 124 |
| 116 // Makes sure the launcher is initially sized correctly. | 125 // Makes sure the launcher is initially sized correctly. |
| 117 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { | 126 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { |
| 118 Launcher* launcher = Shell::GetInstance()->launcher(); | 127 Launcher* launcher = Shell::GetInstance()->launcher(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 144 views::Widget* widget = new views::Widget; | 153 views::Widget* widget = new views::Widget; |
| 145 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 154 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 146 params.bounds = gfx::Rect(0, 0, 200, 200); | 155 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 147 // Widget is now owned by the parent window. | 156 // Widget is now owned by the parent window. |
| 148 widget->Init(params); | 157 widget->Init(params); |
| 149 widget->SetFullscreen(true); | 158 widget->SetFullscreen(true); |
| 150 } | 159 } |
| 151 | 160 |
| 152 } // namespace internal | 161 } // namespace internal |
| 153 } // namespace ash | 162 } // namespace ash |
| OLD | NEW |