| 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/wm/dock/docked_window_resizer.h" | 5 #include "ash/wm/dock/docked_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/display/window_tree_host_manager.h" | 8 #include "ash/display/window_tree_host_manager.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 aura::Window* CreateModalWindow(const gfx::Rect& bounds) { | 93 aura::Window* CreateModalWindow(const gfx::Rect& bounds) { |
| 94 aura::Window* window = new aura::Window(&delegate_); | 94 aura::Window* window = new aura::Window(&delegate_); |
| 95 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | 95 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); |
| 96 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 96 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 97 window->Init(ui::LAYER_TEXTURED); | 97 window->Init(ui::LAYER_TEXTURED); |
| 98 window->Show(); | 98 window->Show(); |
| 99 | 99 |
| 100 if (bounds.IsEmpty()) { | 100 if (bounds.IsEmpty()) { |
| 101 ParentWindowInPrimaryRootWindow(window); | 101 ParentWindowInPrimaryRootWindow(window); |
| 102 } else { | 102 } else { |
| 103 gfx::Display display = | 103 display::Display display = |
| 104 gfx::Screen::GetScreen()->GetDisplayMatching(bounds); | 104 display::Screen::GetScreen()->GetDisplayMatching(bounds); |
| 105 aura::Window* root = ash::Shell::GetInstance() | 105 aura::Window* root = ash::Shell::GetInstance() |
| 106 ->window_tree_host_manager() | 106 ->window_tree_host_manager() |
| 107 ->GetRootWindowForDisplayId(display.id()); | 107 ->GetRootWindowForDisplayId(display.id()); |
| 108 gfx::Point origin = bounds.origin(); | 108 gfx::Point origin = bounds.origin(); |
| 109 ::wm::ConvertPointFromScreen(root, &origin); | 109 ::wm::ConvertPointFromScreen(root, &origin); |
| 110 window->SetBounds(gfx::Rect(origin, bounds.size())); | 110 window->SetBounds(gfx::Rect(origin, bounds.size())); |
| 111 aura::client::ParentWindowWithContext(window, root, bounds); | 111 aura::client::ParentWindowWithContext(window, root, bounds); |
| 112 } | 112 } |
| 113 return window; | 113 return window; |
| 114 } | 114 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // horizontally to the edge with an added offset from the edge of |dx|. | 206 // horizontally to the edge with an added offset from the edge of |dx|. |
| 207 void DragVerticallyAndRelativeToEdge(DockedEdge edge, | 207 void DragVerticallyAndRelativeToEdge(DockedEdge edge, |
| 208 aura::Window* window, | 208 aura::Window* window, |
| 209 int dx, int dy, | 209 int dx, int dy, |
| 210 int grab_x, int grab_y) { | 210 int grab_x, int grab_y) { |
| 211 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 211 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| 212 // avoid snap by clicking away from the border | 212 // avoid snap by clicking away from the border |
| 213 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(window, | 213 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(window, |
| 214 grab_x, grab_y)); | 214 grab_x, grab_y)); |
| 215 | 215 |
| 216 gfx::Rect work_area = | 216 gfx::Rect work_area = display::Screen::GetScreen() |
| 217 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area(); | 217 ->GetDisplayNearestWindow(window) |
| 218 .work_area(); |
| 218 gfx::Point initial_location_in_screen = initial_location_in_parent_; | 219 gfx::Point initial_location_in_screen = initial_location_in_parent_; |
| 219 ::wm::ConvertPointToScreen(window->parent(), &initial_location_in_screen); | 220 ::wm::ConvertPointToScreen(window->parent(), &initial_location_in_screen); |
| 220 // Drag the window left or right to the edge (or almost to it). | 221 // Drag the window left or right to the edge (or almost to it). |
| 221 if (edge == DOCKED_EDGE_LEFT) | 222 if (edge == DOCKED_EDGE_LEFT) |
| 222 dx += work_area.x() - initial_location_in_screen.x(); | 223 dx += work_area.x() - initial_location_in_screen.x(); |
| 223 else if (edge == DOCKED_EDGE_RIGHT) | 224 else if (edge == DOCKED_EDGE_RIGHT) |
| 224 dx += work_area.right() - 1 - initial_location_in_screen.x(); | 225 dx += work_area.right() - 1 - initial_location_in_screen.x(); |
| 225 DragMove(dx, dy); | 226 DragMove(dx, dy); |
| 226 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 227 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 227 // Release the mouse and the panel should be attached to the dock. | 228 // Release the mouse and the panel should be attached to the dock. |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(), | 599 EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(), |
| 599 w1->GetBoundsInScreen().right()); | 600 w1->GetBoundsInScreen().right()); |
| 600 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); | 601 EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id()); |
| 601 | 602 |
| 602 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegateAndType( | 603 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegateAndType( |
| 603 NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20))); | 604 NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20))); |
| 604 wm::GetWindowState(w2.get())->Maximize(); | 605 wm::GetWindowState(w2.get())->Maximize(); |
| 605 EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id()); | 606 EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 606 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized()); | 607 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized()); |
| 607 | 608 |
| 608 gfx::Rect work_area = | 609 gfx::Rect work_area = display::Screen::GetScreen() |
| 609 gfx::Screen::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); | 610 ->GetDisplayNearestWindow(w1.get()) |
| 611 .work_area(); |
| 610 DockedWindowLayoutManager* manager = | 612 DockedWindowLayoutManager* manager = |
| 611 DockedWindowLayoutManager::Get(wm::WmWindowAura::Get(w1.get())); | 613 DockedWindowLayoutManager::Get(wm::WmWindowAura::Get(w1.get())); |
| 612 | 614 |
| 613 // Docked window should be centered vertically in the work area. | 615 // Docked window should be centered vertically in the work area. |
| 614 EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y()); | 616 EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y()); |
| 615 // Docked background should extend to the bottom of work area. | 617 // Docked background should extend to the bottom of work area. |
| 616 EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom()); | 618 EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom()); |
| 617 | 619 |
| 618 // set launcher shelf to be aligned on the right | 620 // set launcher shelf to be aligned on the right |
| 619 ash::Shell* shell = ash::Shell::GetInstance(); | 621 ash::Shell* shell = ash::Shell::GetInstance(); |
| 620 shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, | 622 shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, |
| 621 shell->GetPrimaryRootWindow()); | 623 shell->GetPrimaryRootWindow()); |
| 622 work_area = | 624 work_area = display::Screen::GetScreen() |
| 623 gfx::Screen::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); | 625 ->GetDisplayNearestWindow(w1.get()) |
| 626 .work_area(); |
| 624 // Docked window should be centered vertically in the work area. | 627 // Docked window should be centered vertically in the work area. |
| 625 EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y()); | 628 EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y()); |
| 626 // Docked background should extend to the bottom of work area. | 629 // Docked background should extend to the bottom of work area. |
| 627 EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom()); | 630 EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom()); |
| 628 } | 631 } |
| 629 | 632 |
| 630 // Dock one window, try to dock another window on the opposite side (should not | 633 // Dock one window, try to dock another window on the opposite side (should not |
| 631 // dock). | 634 // dock). |
| 632 TEST_P(DockedWindowResizerTest, AttachOnTwoSides) { | 635 TEST_P(DockedWindowResizerTest, AttachOnTwoSides) { |
| 633 if (!SupportsHostWindowResize()) | 636 if (!SupportsHostWindowResize()) |
| (...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 EXPECT_TRUE(window_state->IsMaximized()); | 1618 EXPECT_TRUE(window_state->IsMaximized()); |
| 1616 } | 1619 } |
| 1617 | 1620 |
| 1618 // Tests run twice - on both panels and normal windows | 1621 // Tests run twice - on both panels and normal windows |
| 1619 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 1622 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
| 1620 DockedWindowResizerTest, | 1623 DockedWindowResizerTest, |
| 1621 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, | 1624 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, |
| 1622 ui::wm::WINDOW_TYPE_PANEL)); | 1625 ui::wm::WINDOW_TYPE_PANEL)); |
| 1623 | 1626 |
| 1624 } // namespace ash | 1627 } // namespace ash |
| OLD | NEW |