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/window_util.h" | 5 #include "ash/wm/window_util.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
11 #include "ash/common/wm/wm_event.h" | 11 #include "ash/common/wm/wm_event.h" |
12 #include "ash/common/wm/wm_screen_util.h" | 12 #include "ash/common/wm/wm_screen_util.h" |
| 13 #include "ash/common/wm_shell.h" |
| 14 #include "ash/common/wm_window.h" |
13 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
14 #include "ash/shell.h" | 16 #include "ash/shell.h" |
15 #include "ash/wm/window_properties.h" | 17 #include "ash/wm/window_properties.h" |
16 #include "ash/wm/window_state_aura.h" | 18 #include "ash/wm/window_state_aura.h" |
17 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
18 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
20 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
21 #include "ui/compositor/dip_util.h" | 23 #include "ui/compositor/dip_util.h" |
22 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
23 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
24 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
25 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
26 #include "ui/wm/core/window_util.h" | 28 #include "ui/wm/core/window_util.h" |
27 #include "ui/wm/public/activation_client.h" | 29 #include "ui/wm/public/activation_client.h" |
28 | 30 |
29 namespace ash { | 31 namespace ash { |
30 namespace wm { | 32 namespace wm { |
31 | 33 |
| 34 namespace { |
| 35 |
| 36 // Moves |window| to the given |root| window's corresponding container, if it is |
| 37 // not already in the same root window. Returns true if |window| was moved. |
| 38 bool MoveWindowToRoot(aura::Window* window, aura::Window* root) { |
| 39 if (!root || root == window->GetRootWindow()) |
| 40 return false; |
| 41 aura::Window* container = RootWindowController::ForWindow(root)->GetContainer( |
| 42 window->parent()->id()); |
| 43 if (!container) |
| 44 return false; |
| 45 container->AddChild(window); |
| 46 return true; |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
32 // TODO(beng): replace many of these functions with the corewm versions. | 51 // TODO(beng): replace many of these functions with the corewm versions. |
33 void ActivateWindow(aura::Window* window) { | 52 void ActivateWindow(aura::Window* window) { |
34 ::wm::ActivateWindow(window); | 53 ::wm::ActivateWindow(window); |
35 } | 54 } |
36 | 55 |
37 void DeactivateWindow(aura::Window* window) { | 56 void DeactivateWindow(aura::Window* window) { |
38 ::wm::DeactivateWindow(window); | 57 ::wm::DeactivateWindow(window); |
39 } | 58 } |
40 | 59 |
41 bool IsActiveWindow(aura::Window* window) { | 60 bool IsActiveWindow(aura::Window* window) { |
(...skipping 15 matching lines...) Expand all Loading... |
57 | 76 |
58 bool IsWindowUserPositionable(aura::Window* window) { | 77 bool IsWindowUserPositionable(aura::Window* window) { |
59 return GetWindowState(window)->IsUserPositionable(); | 78 return GetWindowState(window)->IsUserPositionable(); |
60 } | 79 } |
61 | 80 |
62 void PinWindow(aura::Window* window, bool trusted) { | 81 void PinWindow(aura::Window* window, bool trusted) { |
63 wm::WMEvent event(trusted ? wm::WM_EVENT_TRUSTED_PIN : wm::WM_EVENT_PIN); | 82 wm::WMEvent event(trusted ? wm::WM_EVENT_TRUSTED_PIN : wm::WM_EVENT_PIN); |
64 wm::GetWindowState(window)->OnWMEvent(&event); | 83 wm::GetWindowState(window)->OnWMEvent(&event); |
65 } | 84 } |
66 | 85 |
| 86 bool MoveWindowToDisplay(aura::Window* window, int64_t display_id) { |
| 87 DCHECK(window); |
| 88 WmWindow* root = WmShell::Get()->GetRootWindowForDisplayId(display_id); |
| 89 return root && MoveWindowToRoot(window, root->aura_window()); |
| 90 } |
| 91 |
67 bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) { | 92 bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) { |
| 93 DCHECK(window); |
68 views::View* target = static_cast<views::View*>(event.target()); | 94 views::View* target = static_cast<views::View*>(event.target()); |
69 if (!target) | 95 if (!target) |
70 return false; | 96 return false; |
71 aura::Window* target_root = | 97 aura::Window* root = target->GetWidget()->GetNativeView()->GetRootWindow(); |
72 target->GetWidget()->GetNativeView()->GetRootWindow(); | 98 return root && MoveWindowToRoot(window, root); |
73 if (!target_root || target_root == window->GetRootWindow()) | |
74 return false; | |
75 aura::Window* window_container = RootWindowController::ForWindow(target_root) | |
76 ->GetContainer(window->parent()->id()); | |
77 // Move the window to the target launcher. | |
78 window_container->AddChild(window); | |
79 return true; | |
80 } | 99 } |
81 | 100 |
82 void SnapWindowToPixelBoundary(aura::Window* window) { | 101 void SnapWindowToPixelBoundary(aura::Window* window) { |
83 window->SetProperty(kSnapChildrenToPixelBoundary, true); | 102 window->SetProperty(kSnapChildrenToPixelBoundary, true); |
84 aura::Window* snapped_ancestor = window->parent(); | 103 aura::Window* snapped_ancestor = window->parent(); |
85 while (snapped_ancestor) { | 104 while (snapped_ancestor) { |
86 if (snapped_ancestor->GetProperty(kSnapChildrenToPixelBoundary)) { | 105 if (snapped_ancestor->GetProperty(kSnapChildrenToPixelBoundary)) { |
87 ui::SnapLayerToPhysicalPixelBoundary(snapped_ancestor->layer(), | 106 ui::SnapLayerToPhysicalPixelBoundary(snapped_ancestor->layer(), |
88 window->layer()); | 107 window->layer()); |
89 return; | 108 return; |
90 } | 109 } |
91 snapped_ancestor = snapped_ancestor->parent(); | 110 snapped_ancestor = snapped_ancestor->parent(); |
92 } | 111 } |
93 } | 112 } |
94 | 113 |
95 void SetSnapsChildrenToPhysicalPixelBoundary(aura::Window* container) { | 114 void SetSnapsChildrenToPhysicalPixelBoundary(aura::Window* container) { |
96 DCHECK(!container->GetProperty(kSnapChildrenToPixelBoundary)) | 115 DCHECK(!container->GetProperty(kSnapChildrenToPixelBoundary)) |
97 << container->GetName(); | 116 << container->GetName(); |
98 container->SetProperty(kSnapChildrenToPixelBoundary, true); | 117 container->SetProperty(kSnapChildrenToPixelBoundary, true); |
99 } | 118 } |
100 | 119 |
101 } // namespace wm | 120 } // namespace wm |
102 } // namespace ash | 121 } // namespace ash |
OLD | NEW |