OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/wm/dock/docked_window_layout_manager.h" | 5 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/aura/wm_window_aura.h" |
8 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
9 #include "ash/common/wm/panels/panel_layout_manager.h" | 10 #include "ash/common/wm/panels/panel_layout_manager.h" |
10 #include "ash/common/wm/window_resizer.h" | 11 #include "ash/common/wm/window_resizer.h" |
11 #include "ash/common/wm/window_state.h" | 12 #include "ash/common/wm/window_state.h" |
12 #include "ash/display/display_manager.h" | 13 #include "ash/display/display_manager.h" |
13 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
14 #include "ash/shelf/shelf.h" | 15 #include "ash/shelf/shelf.h" |
15 #include "ash/shelf/shelf_layout_manager.h" | 16 #include "ash/shelf/shelf_layout_manager.h" |
16 #include "ash/shelf/shelf_model.h" | 17 #include "ash/shelf/shelf_model.h" |
17 #include "ash/shelf/shelf_types.h" | 18 #include "ash/shelf/shelf_types.h" |
18 #include "ash/shelf/shelf_widget.h" | 19 #include "ash/shelf/shelf_widget.h" |
19 #include "ash/shell.h" | 20 #include "ash/shell.h" |
20 #include "ash/test/ash_test_base.h" | 21 #include "ash/test/ash_test_base.h" |
21 #include "ash/test/display_manager_test_api.h" | 22 #include "ash/test/display_manager_test_api.h" |
22 #include "ash/test/shelf_test_api.h" | 23 #include "ash/test/shelf_test_api.h" |
23 #include "ash/test/shelf_view_test_api.h" | 24 #include "ash/test/shelf_view_test_api.h" |
24 #include "ash/test/shell_test_api.h" | 25 #include "ash/test/shell_test_api.h" |
25 #include "ash/test/test_shelf_delegate.h" | 26 #include "ash/test/test_shelf_delegate.h" |
26 #include "ash/wm/aura/wm_window_aura.h" | |
27 #include "ash/wm/window_state_aura.h" | 27 #include "ash/wm/window_state_aura.h" |
28 #include "ash/wm/window_util.h" | 28 #include "ash/wm/window_util.h" |
29 #include "base/command_line.h" | 29 #include "base/command_line.h" |
30 #include "base/strings/string_number_conversions.h" | 30 #include "base/strings/string_number_conversions.h" |
31 #include "ui/aura/client/aura_constants.h" | 31 #include "ui/aura/client/aura_constants.h" |
32 #include "ui/aura/test/test_window_delegate.h" | 32 #include "ui/aura/test/test_window_delegate.h" |
33 #include "ui/aura/window.h" | 33 #include "ui/aura/window.h" |
34 #include "ui/aura/window_event_dispatcher.h" | 34 #include "ui/aura/window_event_dispatcher.h" |
35 #include "ui/base/hit_test.h" | 35 #include "ui/base/hit_test.h" |
36 #include "ui/display/manager/display_layout.h" | 36 #include "ui/display/manager/display_layout.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | 73 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { |
74 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 74 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
75 nullptr, window_type_, 0, bounds); | 75 nullptr, window_type_, 0, bounds); |
76 if (window_type_ == ui::wm::WINDOW_TYPE_PANEL) { | 76 if (window_type_ == ui::wm::WINDOW_TYPE_PANEL) { |
77 test::TestShelfDelegate* shelf_delegate = | 77 test::TestShelfDelegate* shelf_delegate = |
78 test::TestShelfDelegate::instance(); | 78 test::TestShelfDelegate::instance(); |
79 shelf_delegate->AddShelfItem(window); | 79 shelf_delegate->AddShelfItem(window); |
80 PanelLayoutManager* manager = | 80 PanelLayoutManager* manager = |
81 PanelLayoutManager::Get(wm::WmWindowAura::Get(window)); | 81 PanelLayoutManager::Get(WmWindowAura::Get(window)); |
82 manager->Relayout(); | 82 manager->Relayout(); |
83 } | 83 } |
84 return window; | 84 return window; |
85 } | 85 } |
86 | 86 |
87 aura::Window* CreateTestWindowWithDelegate( | 87 aura::Window* CreateTestWindowWithDelegate( |
88 const gfx::Rect& bounds, | 88 const gfx::Rect& bounds, |
89 aura::test::TestWindowDelegate* delegate) { | 89 aura::test::TestWindowDelegate* delegate) { |
90 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 90 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
91 delegate, window_type_, 0, bounds); | 91 delegate, window_type_, 0, bounds); |
92 if (window_type_ == ui::wm::WINDOW_TYPE_PANEL) { | 92 if (window_type_ == ui::wm::WINDOW_TYPE_PANEL) { |
93 test::TestShelfDelegate* shelf_delegate = | 93 test::TestShelfDelegate* shelf_delegate = |
94 test::TestShelfDelegate::instance(); | 94 test::TestShelfDelegate::instance(); |
95 shelf_delegate->AddShelfItem(window); | 95 shelf_delegate->AddShelfItem(window); |
96 PanelLayoutManager* manager = | 96 PanelLayoutManager* manager = |
97 PanelLayoutManager::Get(wm::WmWindowAura::Get(window)); | 97 PanelLayoutManager::Get(WmWindowAura::Get(window)); |
98 manager->Relayout(); | 98 manager->Relayout(); |
99 } | 99 } |
100 return window; | 100 return window; |
101 } | 101 } |
102 | 102 |
103 static WindowResizer* CreateSomeWindowResizer( | 103 static WindowResizer* CreateSomeWindowResizer( |
104 aura::Window* window, | 104 aura::Window* window, |
105 const gfx::Point& point_in_parent, | 105 const gfx::Point& point_in_parent, |
106 int window_component) { | 106 int window_component) { |
107 return CreateWindowResizer(wm::WmWindowAura::Get(window), point_in_parent, | 107 return CreateWindowResizer(WmWindowAura::Get(window), point_in_parent, |
108 window_component, | 108 window_component, |
109 aura::client::WINDOW_MOVE_SOURCE_MOUSE) | 109 aura::client::WINDOW_MOVE_SOURCE_MOUSE) |
110 .release(); | 110 .release(); |
111 } | 111 } |
112 | 112 |
113 void DragStart(aura::Window* window) { | 113 void DragStart(aura::Window* window) { |
114 DragStartAtOffsetFromwindowOrigin(window, 0, 0); | 114 DragStartAtOffsetFromwindowOrigin(window, 0, 0); |
115 } | 115 } |
116 | 116 |
117 void DragStartAtOffsetFromwindowOrigin(aura::Window* window, | 117 void DragStartAtOffsetFromwindowOrigin(aura::Window* window, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 gfx::Rect bounds(0, 0, 201, 201); | 259 gfx::Rect bounds(0, 0, 201, 201); |
260 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 260 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
261 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0); | 261 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0); |
262 | 262 |
263 // The window should be attached and snapped to the right side of the screen. | 263 // The window should be attached and snapped to the right side of the screen. |
264 EXPECT_EQ(window->GetRootWindow()->bounds().x(), | 264 EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
265 window->GetBoundsInScreen().x()); | 265 window->GetBoundsInScreen().x()); |
266 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 266 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
267 | 267 |
268 DockedWindowLayoutManager* manager = | 268 DockedWindowLayoutManager* manager = |
269 DockedWindowLayoutManager::Get(wm::WmWindowAura::Get(window.get())); | 269 DockedWindowLayoutManager::Get(WmWindowAura::Get(window.get())); |
270 | 270 |
271 // Create two additional windows and test their auto-placement | 271 // Create two additional windows and test their auto-placement |
272 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 272 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
273 gfx::Rect desktop_area = window1->parent()->bounds(); | 273 gfx::Rect desktop_area = window1->parent()->bounds(); |
274 wm::GetWindowState(window1.get())->set_window_position_managed(true); | 274 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
275 window1->Hide(); | 275 window1->Hide(); |
276 window1->SetBounds(gfx::Rect(250, 32, 231, 320)); | 276 window1->SetBounds(gfx::Rect(250, 32, 231, 320)); |
277 window1->Show(); | 277 window1->Show(); |
278 // |window1| should be centered in work area. | 278 // |window1| should be centered in work area. |
279 EXPECT_EQ(base::IntToString( | 279 EXPECT_EQ(base::IntToString( |
(...skipping 29 matching lines...) Expand all Loading... |
309 gfx::Rect bounds(0, 0, 201, 201); | 309 gfx::Rect bounds(0, 0, 201, 201); |
310 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 310 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
311 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 311 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
312 | 312 |
313 // The window should be attached and snapped to the right side of the screen. | 313 // The window should be attached and snapped to the right side of the screen. |
314 EXPECT_EQ(window->GetRootWindow()->bounds().right(), | 314 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
315 window->GetBoundsInScreen().right()); | 315 window->GetBoundsInScreen().right()); |
316 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 316 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
317 | 317 |
318 DockedWindowLayoutManager* manager = | 318 DockedWindowLayoutManager* manager = |
319 DockedWindowLayoutManager::Get(wm::WmWindowAura::Get(window.get())); | 319 DockedWindowLayoutManager::Get(WmWindowAura::Get(window.get())); |
320 | 320 |
321 // Create two additional windows and test their auto-placement | 321 // Create two additional windows and test their auto-placement |
322 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 322 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
323 gfx::Rect desktop_area = window1->parent()->bounds(); | 323 gfx::Rect desktop_area = window1->parent()->bounds(); |
324 wm::GetWindowState(window1.get())->set_window_position_managed(true); | 324 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
325 window1->Hide(); | 325 window1->Hide(); |
326 window1->SetBounds(gfx::Rect(16, 32, 231, 320)); | 326 window1->SetBounds(gfx::Rect(16, 32, 231, 320)); |
327 window1->Show(); | 327 window1->Show(); |
328 | 328 |
329 // |window1| should be centered in work area. | 329 // |window1| should be centered in work area. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); | 363 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds)); |
364 // Drag pointer to the right edge of the second screen. | 364 // Drag pointer to the right edge of the second screen. |
365 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 365 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
366 | 366 |
367 // The window should be attached and snapped to the right side of the screen. | 367 // The window should be attached and snapped to the right side of the screen. |
368 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(), | 368 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(), |
369 window->GetBoundsInScreen().right()); | 369 window->GetBoundsInScreen().right()); |
370 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 370 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
371 | 371 |
372 DockedWindowLayoutManager* manager = | 372 DockedWindowLayoutManager* manager = |
373 DockedWindowLayoutManager::Get(wm::WmWindowAura::Get(window.get())); | 373 DockedWindowLayoutManager::Get(WmWindowAura::Get(window.get())); |
374 | 374 |
375 // Create two additional windows and test their auto-placement | 375 // Create two additional windows and test their auto-placement |
376 bounds = gfx::Rect(616, 32, 231, 320); | 376 bounds = gfx::Rect(616, 32, 231, 320); |
377 std::unique_ptr<aura::Window> window1( | 377 std::unique_ptr<aura::Window> window1( |
378 CreateTestWindowInShellWithDelegate(nullptr, 1, bounds)); | 378 CreateTestWindowInShellWithDelegate(nullptr, 1, bounds)); |
379 gfx::Rect desktop_area = window1->parent()->bounds(); | 379 gfx::Rect desktop_area = window1->parent()->bounds(); |
380 wm::GetWindowState(window1.get())->set_window_position_managed(true); | 380 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
381 window1->Hide(); | 381 window1->Hide(); |
382 window1->Show(); | 382 window1->Show(); |
383 | 383 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 EXPECT_EQ(work_area.height(), window->GetBoundsInScreen().height()); | 862 EXPECT_EQ(work_area.height(), window->GetBoundsInScreen().height()); |
863 } | 863 } |
864 | 864 |
865 // Tests run twice - on both panels and normal windows | 865 // Tests run twice - on both panels and normal windows |
866 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 866 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
867 DockedWindowLayoutManagerTest, | 867 DockedWindowLayoutManagerTest, |
868 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, | 868 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, |
869 ui::wm::WINDOW_TYPE_PANEL)); | 869 ui::wm::WINDOW_TYPE_PANEL)); |
870 | 870 |
871 } // namespace ash | 871 } // namespace ash |
OLD | NEW |