| 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/workspace/workspace_layout_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/wm/property_util.h" | 13 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_settings.h" | |
| 15 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 16 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
| 17 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 18 #include "ui/aura/test/test_windows.h" | 17 #include "ui/aura/test/test_windows.h" |
| 19 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 20 #include "ui/gfx/insets.h" | 19 #include "ui/gfx/insets.h" |
| 21 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
| 23 | 22 |
| 24 namespace ash { | 23 namespace ash { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 50 typedef test::AshTestBase WorkspaceLayoutManagerTest; | 49 typedef test::AshTestBase WorkspaceLayoutManagerTest; |
| 51 | 50 |
| 52 // Verifies that a window containing a restore coordinate will be restored to | 51 // Verifies that a window containing a restore coordinate will be restored to |
| 53 // to the size prior to minimize, keeping the restore rectangle in tact (if | 52 // to the size prior to minimize, keeping the restore rectangle in tact (if |
| 54 // there is one). | 53 // there is one). |
| 55 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { | 54 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { |
| 56 scoped_ptr<aura::Window> window( | 55 scoped_ptr<aura::Window> window( |
| 57 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 56 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
| 58 gfx::Rect bounds(10, 15, 25, 35); | 57 gfx::Rect bounds(10, 15, 25, 35); |
| 59 window->SetBounds(bounds); | 58 window->SetBounds(bounds); |
| 59 |
| 60 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 61 |
| 60 // This will not be used for un-minimizing window. | 62 // This will not be used for un-minimizing window. |
| 61 SetRestoreBoundsInScreen(window.get(), gfx::Rect(0, 0, 100, 100)); | 63 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); |
| 62 wm::MinimizeWindow(window.get()); | 64 window_state->Minimize(); |
| 63 wm::RestoreWindow(window.get()); | 65 window_state->Restore(); |
| 64 EXPECT_EQ("0,0 100x100", GetRestoreBoundsInScreen(window.get())->ToString()); | 66 EXPECT_EQ("0,0 100x100", window_state->GetRestoreBoundsInScreen().ToString()); |
| 65 EXPECT_EQ("10,15 25x35", window.get()->bounds().ToString()); | 67 EXPECT_EQ("10,15 25x35", window.get()->bounds().ToString()); |
| 66 | 68 |
| 67 if (!SupportsMultipleDisplays()) | 69 if (!SupportsMultipleDisplays()) |
| 68 return; | 70 return; |
| 69 | 71 |
| 70 UpdateDisplay("400x300,500x400"); | 72 UpdateDisplay("400x300,500x400"); |
| 71 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), | 73 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), |
| 72 ScreenAsh::GetSecondaryDisplay()); | 74 ScreenAsh::GetSecondaryDisplay()); |
| 73 EXPECT_EQ(Shell::GetAllRootWindows()[1], window->GetRootWindow()); | 75 EXPECT_EQ(Shell::GetAllRootWindows()[1], window->GetRootWindow()); |
| 74 wm::MinimizeWindow(window.get()); | 76 window_state->Minimize(); |
| 75 // This will not be used for un-minimizing window. | 77 // This will not be used for un-minimizing window. |
| 76 SetRestoreBoundsInScreen(window.get(), gfx::Rect(0, 0, 100, 100)); | 78 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); |
| 77 wm::RestoreWindow(window.get()); | 79 window_state->Restore(); |
| 78 EXPECT_EQ("600,0 100x100", window->GetBoundsInScreen().ToString()); | 80 EXPECT_EQ("600,0 100x100", window->GetBoundsInScreen().ToString()); |
| 79 | 81 |
| 80 // Make sure the unminimized window moves inside the display when | 82 // Make sure the unminimized window moves inside the display when |
| 81 // 2nd display is disconnected. | 83 // 2nd display is disconnected. |
| 82 wm::MinimizeWindow(window.get()); | 84 window_state->Minimize(); |
| 83 UpdateDisplay("400x300"); | 85 UpdateDisplay("400x300"); |
| 84 wm::RestoreWindow(window.get()); | 86 window_state->Restore(); |
| 85 EXPECT_EQ(Shell::GetPrimaryRootWindow(), window->GetRootWindow()); | 87 EXPECT_EQ(Shell::GetPrimaryRootWindow(), window->GetRootWindow()); |
| 86 EXPECT_TRUE( | 88 EXPECT_TRUE( |
| 87 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 89 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); |
| 88 } | 90 } |
| 89 | 91 |
| 90 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { | 92 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { |
| 91 if (!SupportsHostWindowResize()) | 93 if (!SupportsHostWindowResize()) |
| 92 return; | 94 return; |
| 93 scoped_ptr<aura::Window> window( | 95 scoped_ptr<aura::Window> window( |
| 94 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 96 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); |
| 97 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 98 |
| 95 // Maximized -> Normal transition. | 99 // Maximized -> Normal transition. |
| 96 wm::MaximizeWindow(window.get()); | 100 window_state->Maximize(); |
| 97 SetRestoreBoundsInScreen(window.get(), gfx::Rect(-100, -100, 30, 40)); | 101 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); |
| 98 wm::RestoreWindow(window.get()); | 102 window_state->Restore(); |
| 99 EXPECT_TRUE( | 103 EXPECT_TRUE( |
| 100 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 104 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); |
| 101 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); | 105 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); |
| 102 | 106 |
| 103 // Minimized -> Normal transition. | 107 // Minimized -> Normal transition. |
| 104 window->SetBounds(gfx::Rect(-100, -100, 30, 40)); | 108 window->SetBounds(gfx::Rect(-100, -100, 30, 40)); |
| 105 wm::MinimizeWindow(window.get()); | 109 window_state->Minimize(); |
| 106 EXPECT_FALSE( | 110 EXPECT_FALSE( |
| 107 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 111 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); |
| 108 EXPECT_EQ("-100,-100 30x40", window->bounds().ToString()); | 112 EXPECT_EQ("-100,-100 30x40", window->bounds().ToString()); |
| 109 window->Show(); | 113 window->Show(); |
| 110 EXPECT_TRUE( | 114 EXPECT_TRUE( |
| 111 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 115 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); |
| 112 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); | 116 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); |
| 113 | 117 |
| 114 // Fullscreen -> Normal transition. | 118 // Fullscreen -> Normal transition. |
| 115 window->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds. | 119 window->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds. |
| 116 ASSERT_EQ("0,0 30x40", window->bounds().ToString()); | 120 ASSERT_EQ("0,0 30x40", window->bounds().ToString()); |
| 117 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 121 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 118 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds()); | 122 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds()); |
| 119 SetRestoreBoundsInScreen(window.get(), gfx::Rect(-100, -100, 30, 40)); | 123 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); |
| 120 wm::RestoreWindow(window.get()); | 124 window_state->Restore(); |
| 121 EXPECT_TRUE( | 125 EXPECT_TRUE( |
| 122 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 126 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); |
| 123 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); | 127 EXPECT_EQ("-20,-30 30x40", window->bounds().ToString()); |
| 124 } | 128 } |
| 125 | 129 |
| 126 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) { | 130 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) { |
| 127 if (!SupportsMultipleDisplays()) | 131 if (!SupportsMultipleDisplays()) |
| 128 return; | 132 return; |
| 129 UpdateDisplay("300x400,400x500"); | 133 UpdateDisplay("300x400,400x500"); |
| 130 | 134 |
| 131 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 135 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 132 | 136 |
| 133 scoped_ptr<aura::Window> window( | 137 scoped_ptr<aura::Window> window( |
| 134 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 138 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); |
| 135 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 139 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 136 | 140 |
| 137 SetRestoreBoundsInScreen(window.get(), gfx::Rect(400, 0, 30, 40)); | 141 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 142 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
| 138 // Maximize the window in 2nd display as the restore bounds | 143 // Maximize the window in 2nd display as the restore bounds |
| 139 // is inside 2nd display. | 144 // is inside 2nd display. |
| 140 wm::MaximizeWindow(window.get()); | 145 window_state->Maximize(); |
| 141 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 146 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 142 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString()); | 147 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString()); |
| 143 | 148 |
| 144 wm::RestoreWindow(window.get()); | 149 window_state->Restore(); |
| 145 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 150 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 146 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString()); | 151 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString()); |
| 147 | 152 |
| 148 // If the restore bounds intersects with the current display, | 153 // If the restore bounds intersects with the current display, |
| 149 // don't move. | 154 // don't move. |
| 150 SetRestoreBoundsInScreen(window.get(), gfx::Rect(280, 0, 30, 40)); | 155 window_state->SetRestoreBoundsInScreen(gfx::Rect(280, 0, 30, 40)); |
| 151 wm::MaximizeWindow(window.get()); | 156 window_state->Maximize(); |
| 152 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 157 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 153 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString()); | 158 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString()); |
| 154 | 159 |
| 155 wm::RestoreWindow(window.get()); | 160 window_state->Restore(); |
| 156 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 161 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 157 EXPECT_EQ("280,0 30x40", window->GetBoundsInScreen().ToString()); | 162 EXPECT_EQ("280,0 30x40", window->GetBoundsInScreen().ToString()); |
| 158 | 163 |
| 159 // Restoring widget state. | 164 // Restoring widget state. |
| 160 scoped_ptr<views::Widget> w1(new views::Widget); | 165 scoped_ptr<views::Widget> w1(new views::Widget); |
| 161 views::Widget::InitParams params; | 166 views::Widget::InitParams params; |
| 162 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 167 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 163 params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40)); | 168 params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40)); |
| 164 params.context = root_windows[0]; | 169 params.context = root_windows[0]; |
| 165 w1->Init(params); | 170 w1->Init(params); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 176 if (!SupportsMultipleDisplays()) | 181 if (!SupportsMultipleDisplays()) |
| 177 return; | 182 return; |
| 178 UpdateDisplay("300x400,400x500"); | 183 UpdateDisplay("300x400,400x500"); |
| 179 | 184 |
| 180 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 185 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 181 | 186 |
| 182 scoped_ptr<aura::Window> window( | 187 scoped_ptr<aura::Window> window( |
| 183 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 188 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); |
| 184 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 189 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 185 | 190 |
| 186 SetRestoreBoundsInScreen(window.get(), gfx::Rect(400, 0, 30, 40)); | 191 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 192 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
| 187 // Maximize the window in 2nd display as the restore bounds | 193 // Maximize the window in 2nd display as the restore bounds |
| 188 // is inside 2nd display. | 194 // is inside 2nd display. |
| 189 window->SetProperty(aura::client::kShowStateKey, | 195 window->SetProperty(aura::client::kShowStateKey, |
| 190 ui::SHOW_STATE_FULLSCREEN); | 196 ui::SHOW_STATE_FULLSCREEN); |
| 191 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 197 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 192 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); | 198 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); |
| 193 | 199 |
| 194 wm::RestoreWindow(window.get()); | 200 window_state->Restore(); |
| 195 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 201 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 196 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString()); | 202 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString()); |
| 197 | 203 |
| 198 // If the restore bounds intersects with the current display, | 204 // If the restore bounds intersects with the current display, |
| 199 // don't move. | 205 // don't move. |
| 200 SetRestoreBoundsInScreen(window.get(), gfx::Rect(280, 0, 30, 40)); | 206 window_state->SetRestoreBoundsInScreen(gfx::Rect(280, 0, 30, 40)); |
| 201 window->SetProperty(aura::client::kShowStateKey, | 207 window->SetProperty(aura::client::kShowStateKey, |
| 202 ui::SHOW_STATE_FULLSCREEN); | 208 ui::SHOW_STATE_FULLSCREEN); |
| 203 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 209 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 204 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); | 210 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); |
| 205 | 211 |
| 206 wm::RestoreWindow(window.get()); | 212 window_state->Restore(); |
| 207 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 213 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 208 EXPECT_EQ("280,0 30x40", window->GetBoundsInScreen().ToString()); | 214 EXPECT_EQ("280,0 30x40", window->GetBoundsInScreen().ToString()); |
| 209 } | 215 } |
| 210 | 216 |
| 211 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. | 217 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver. |
| 212 // This code mirrors what BrowserFrameAura does. In particular when this code | 218 // This code mirrors what BrowserFrameAura does. In particular when this code |
| 213 // sees the window was maximized it changes the bounds of a secondary | 219 // sees the window was maximized it changes the bounds of a secondary |
| 214 // window. The secondary window mirrors the status window. | 220 // window. The secondary window mirrors the status window. |
| 215 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver { | 221 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver { |
| 216 public: | 222 public: |
| 217 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {} | 223 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {} |
| 218 | 224 |
| 219 void set_window(aura::Window* window) { window_ = window; } | 225 void set_window(aura::Window* window) { window_ = window; } |
| 220 | 226 |
| 221 virtual void OnWindowPropertyChanged(aura::Window* window, | 227 virtual void OnWindowPropertyChanged(aura::Window* window, |
| 222 const void* key, | 228 const void* key, |
| 223 intptr_t old) OVERRIDE { | 229 intptr_t old) OVERRIDE { |
| 224 if (!window_) | 230 if (!window_) |
| 225 return; | 231 return; |
| 226 | 232 |
| 227 if (wm::IsWindowMaximized(window)) { | 233 if (wm::GetWindowState(window)->IsMaximized()) { |
| 228 aura::Window* w = window_; | 234 aura::Window* w = window_; |
| 229 window_ = NULL; | 235 window_ = NULL; |
| 230 | 236 |
| 231 gfx::Rect shelf_bounds(Shell::GetPrimaryRootWindowController()-> | 237 gfx::Rect shelf_bounds(Shell::GetPrimaryRootWindowController()-> |
| 232 GetShelfLayoutManager()->GetIdealBounds()); | 238 GetShelfLayoutManager()->GetIdealBounds()); |
| 233 const gfx::Rect& window_bounds(w->bounds()); | 239 const gfx::Rect& window_bounds(w->bounds()); |
| 234 w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1, | 240 w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1, |
| 235 window_bounds.width(), window_bounds.height())); | 241 window_bounds.width(), window_bounds.height())); |
| 236 } | 242 } |
| 237 } | 243 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 249 DontClobberRestoreBoundsWindowObserver window_observer; | 255 DontClobberRestoreBoundsWindowObserver window_observer; |
| 250 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 256 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
| 251 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 257 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
| 252 window->Init(ui::LAYER_TEXTURED); | 258 window->Init(ui::LAYER_TEXTURED); |
| 253 window->SetBounds(gfx::Rect(10, 20, 30, 40)); | 259 window->SetBounds(gfx::Rect(10, 20, 30, 40)); |
| 254 // NOTE: for this test to exercise the failure the observer needs to be added | 260 // NOTE: for this test to exercise the failure the observer needs to be added |
| 255 // before the parent set. This mimics what BrowserFrameAura does. | 261 // before the parent set. This mimics what BrowserFrameAura does. |
| 256 window->AddObserver(&window_observer); | 262 window->AddObserver(&window_observer); |
| 257 SetDefaultParentByPrimaryRootWindow(window.get()); | 263 SetDefaultParentByPrimaryRootWindow(window.get()); |
| 258 window->Show(); | 264 window->Show(); |
| 259 wm::ActivateWindow(window.get()); | 265 |
| 266 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 267 window_state->Activate(); |
| 260 | 268 |
| 261 scoped_ptr<aura::Window> window2( | 269 scoped_ptr<aura::Window> window2( |
| 262 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40))); | 270 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40))); |
| 263 window->AddTransientChild(window2.get()); | 271 window->AddTransientChild(window2.get()); |
| 264 window2->Show(); | 272 window2->Show(); |
| 265 | 273 |
| 266 window_observer.set_window(window2.get()); | 274 window_observer.set_window(window2.get()); |
| 267 wm::MaximizeWindow(window.get()); | 275 window_state->Maximize(); |
| 268 EXPECT_EQ("10,20 30x40", GetRestoreBoundsInScreen(window.get())->ToString()); | 276 EXPECT_EQ("10,20 30x40", |
| 277 window_state->GetRestoreBoundsInScreen().ToString()); |
| 269 window->RemoveObserver(&window_observer); | 278 window->RemoveObserver(&window_observer); |
| 270 } | 279 } |
| 271 | 280 |
| 272 // Verifies when a window is maximized all descendant windows have a size. | 281 // Verifies when a window is maximized all descendant windows have a size. |
| 273 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { | 282 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { |
| 274 scoped_ptr<aura::Window> window( | 283 scoped_ptr<aura::Window> window( |
| 275 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40))); | 284 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40))); |
| 276 window->Show(); | 285 window->Show(); |
| 277 wm::ActivateWindow(window.get()); | 286 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 287 window_state->Activate(); |
| 278 scoped_ptr<aura::Window> child_window( | 288 scoped_ptr<aura::Window> child_window( |
| 279 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), | 289 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), |
| 280 window.get())); | 290 window.get())); |
| 281 child_window->Show(); | 291 child_window->Show(); |
| 282 wm::MaximizeWindow(window.get()); | 292 window_state->Maximize(); |
| 283 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); | 293 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); |
| 284 } | 294 } |
| 285 | 295 |
| 286 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { | 296 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { |
| 287 // Normal window bounds shouldn't be changed. | 297 // Normal window bounds shouldn't be changed. |
| 288 gfx::Rect window_bounds(100, 100, 200, 200); | 298 gfx::Rect window_bounds(100, 100, 200, 200); |
| 289 scoped_ptr<aura::Window> window( | 299 scoped_ptr<aura::Window> window( |
| 290 CreateTestWindowInShellWithBounds(window_bounds)); | 300 CreateTestWindowInShellWithBounds(window_bounds)); |
| 291 EXPECT_EQ(window_bounds, window->bounds()); | 301 EXPECT_EQ(window_bounds, window->bounds()); |
| 292 | 302 |
| 293 // If the window is out of the workspace, it would be moved on screen. | 303 // If the window is out of the workspace, it would be moved on screen. |
| 294 gfx::Rect root_window_bounds = | 304 gfx::Rect root_window_bounds = |
| 295 Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); | 305 Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); |
| 296 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); | 306 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); |
| 297 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); | 307 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); |
| 298 scoped_ptr<aura::Window> out_window( | 308 scoped_ptr<aura::Window> out_window( |
| 299 CreateTestWindowInShellWithBounds(window_bounds)); | 309 CreateTestWindowInShellWithBounds(window_bounds)); |
| 300 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); | 310 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); |
| 301 gfx::Rect bounds = out_window->bounds(); | 311 gfx::Rect bounds = out_window->bounds(); |
| 302 bounds.Intersect(root_window_bounds); | 312 bounds.Intersect(root_window_bounds); |
| 303 | 313 |
| 304 // 30% of the window edge must be visible. | 314 // 30% of the window edge must be visible. |
| 305 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); | 315 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); |
| 306 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | 316 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); |
| 307 | 317 |
| 308 aura::Window* parent = out_window->parent(); | 318 aura::Window* parent = out_window->parent(); |
| 309 parent->RemoveChild(out_window.get()); | 319 parent->RemoveChild(out_window.get()); |
| 310 out_window->SetBounds(gfx::Rect(-200, -200, 200, 200)); | 320 out_window->SetBounds(gfx::Rect(-200, -200, 200, 200)); |
| 311 // UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior. | 321 // UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior. |
| 312 wm::GetWindowSettings(window.get())->set_bounds_changed_by_user(true); | 322 wm::GetWindowState(window.get())->set_bounds_changed_by_user(true); |
| 313 parent->AddChild(out_window.get()); | 323 parent->AddChild(out_window.get()); |
| 314 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); | 324 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); |
| 315 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); | 325 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); |
| 316 | 326 |
| 317 // Make sure we always make more than 1/3 of the window edge visible even | 327 // Make sure we always make more than 1/3 of the window edge visible even |
| 318 // if the initial bounds intersects with display. | 328 // if the initial bounds intersects with display. |
| 319 window_bounds.SetRect(-150, -150, 200, 200); | 329 window_bounds.SetRect(-150, -150, 200, 200); |
| 320 bounds = window_bounds; | 330 bounds = window_bounds; |
| 321 bounds.Intersect(root_window_bounds); | 331 bounds.Intersect(root_window_bounds); |
| 322 | 332 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 window->bounds().ToString()); | 373 window->bounds().ToString()); |
| 364 | 374 |
| 365 // Directly setting the bounds triggers a slightly different code path. Verify | 375 // Directly setting the bounds triggers a slightly different code path. Verify |
| 366 // that too. | 376 // that too. |
| 367 window->SetBounds(window_bounds); | 377 window->SetBounds(window_bounds); |
| 368 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 378 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
| 369 window->bounds().ToString()); | 379 window->bounds().ToString()); |
| 370 } | 380 } |
| 371 | 381 |
| 372 } // namespace ash | 382 } // namespace ash |
| OLD | NEW |