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 // Move the |window| to the target |root|, using the corresponding container. | |
James Cook
2017/02/15 00:44:40
nit: document return value ("True if it actually m
msw
2017/02/15 19:59:18
Done.
| |
37 bool MoveWindowToRoot(aura::Window* window, aura::Window* root) { | |
38 if (!root || root == window->GetRootWindow()) | |
39 return false; | |
40 aura::Window* container = RootWindowController::ForWindow(root)->GetContainer( | |
41 window->parent()->id()); | |
42 if (!container) | |
43 return false; | |
44 container->AddChild(window); | |
45 return true; | |
46 } | |
47 | |
48 } // namespace | |
49 | |
32 // TODO(beng): replace many of these functions with the corewm versions. | 50 // TODO(beng): replace many of these functions with the corewm versions. |
33 void ActivateWindow(aura::Window* window) { | 51 void ActivateWindow(aura::Window* window) { |
34 ::wm::ActivateWindow(window); | 52 ::wm::ActivateWindow(window); |
35 } | 53 } |
36 | 54 |
37 void DeactivateWindow(aura::Window* window) { | 55 void DeactivateWindow(aura::Window* window) { |
38 ::wm::DeactivateWindow(window); | 56 ::wm::DeactivateWindow(window); |
39 } | 57 } |
40 | 58 |
41 bool IsActiveWindow(aura::Window* window) { | 59 bool IsActiveWindow(aura::Window* window) { |
(...skipping 15 matching lines...) Expand all Loading... | |
57 | 75 |
58 bool IsWindowUserPositionable(aura::Window* window) { | 76 bool IsWindowUserPositionable(aura::Window* window) { |
59 return GetWindowState(window)->IsUserPositionable(); | 77 return GetWindowState(window)->IsUserPositionable(); |
60 } | 78 } |
61 | 79 |
62 void PinWindow(aura::Window* window, bool trusted) { | 80 void PinWindow(aura::Window* window, bool trusted) { |
63 wm::WMEvent event(trusted ? wm::WM_EVENT_TRUSTED_PIN : wm::WM_EVENT_PIN); | 81 wm::WMEvent event(trusted ? wm::WM_EVENT_TRUSTED_PIN : wm::WM_EVENT_PIN); |
64 wm::GetWindowState(window)->OnWMEvent(&event); | 82 wm::GetWindowState(window)->OnWMEvent(&event); |
65 } | 83 } |
66 | 84 |
85 bool MoveWindowToDisplay(aura::Window* window, int64_t display_id) { | |
James Cook
2017/02/15 00:44:40
DCHECK(window) and that display_id is valid?
msw
2017/02/15 19:59:18
Added DCHECK(window), but left it returning false
| |
86 WmWindow* root = WmShell::Get()->GetRootWindowForDisplayId(display_id); | |
87 return root && MoveWindowToRoot(window, root->aura_window()); | |
88 } | |
89 | |
67 bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) { | 90 bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) { |
68 views::View* target = static_cast<views::View*>(event.target()); | 91 views::View* target = static_cast<views::View*>(event.target()); |
69 if (!target) | 92 if (!target) |
70 return false; | 93 return false; |
71 aura::Window* target_root = | 94 aura::Window* root = target->GetWidget()->GetNativeView()->GetRootWindow(); |
72 target->GetWidget()->GetNativeView()->GetRootWindow(); | 95 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 } | 96 } |
81 | 97 |
82 void SnapWindowToPixelBoundary(aura::Window* window) { | 98 void SnapWindowToPixelBoundary(aura::Window* window) { |
83 window->SetProperty(kSnapChildrenToPixelBoundary, true); | 99 window->SetProperty(kSnapChildrenToPixelBoundary, true); |
84 aura::Window* snapped_ancestor = window->parent(); | 100 aura::Window* snapped_ancestor = window->parent(); |
85 while (snapped_ancestor) { | 101 while (snapped_ancestor) { |
86 if (snapped_ancestor->GetProperty(kSnapChildrenToPixelBoundary)) { | 102 if (snapped_ancestor->GetProperty(kSnapChildrenToPixelBoundary)) { |
87 ui::SnapLayerToPhysicalPixelBoundary(snapped_ancestor->layer(), | 103 ui::SnapLayerToPhysicalPixelBoundary(snapped_ancestor->layer(), |
88 window->layer()); | 104 window->layer()); |
89 return; | 105 return; |
90 } | 106 } |
91 snapped_ancestor = snapped_ancestor->parent(); | 107 snapped_ancestor = snapped_ancestor->parent(); |
92 } | 108 } |
93 } | 109 } |
94 | 110 |
95 void SetSnapsChildrenToPhysicalPixelBoundary(aura::Window* container) { | 111 void SetSnapsChildrenToPhysicalPixelBoundary(aura::Window* container) { |
96 DCHECK(!container->GetProperty(kSnapChildrenToPixelBoundary)) | 112 DCHECK(!container->GetProperty(kSnapChildrenToPixelBoundary)) |
97 << container->GetName(); | 113 << container->GetName(); |
98 container->SetProperty(kSnapChildrenToPixelBoundary, true); | 114 container->SetProperty(kSnapChildrenToPixelBoundary, true); |
99 } | 115 } |
100 | 116 |
101 } // namespace wm | 117 } // namespace wm |
102 } // namespace ash | 118 } // namespace ash |
OLD | NEW |