OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_positioning_utils.h" | 5 #include "ash/wm/window_positioning_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
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" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/wm/system_modal_container_layout_manager.h" | 12 #include "ash/wm/system_modal_container_layout_manager.h" |
13 #include "ash/wm/window_properties.h" | |
13 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
15 #include "ash/wm/wm_event.h" | 16 #include "ash/wm/wm_event.h" |
16 #include "ash/wm_window.h" | 17 #include "ash/wm_window.h" |
17 #include "ui/aura/client/focus_client.h" | 18 #include "ui/aura/client/focus_client.h" |
18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 20 #include "ui/aura/window_delegate.h" |
20 #include "ui/aura/window_tracker.h" | 21 #include "ui/aura/window_tracker.h" |
21 #include "ui/display/display.h" | 22 #include "ui/display/display.h" |
23 #include "ui/display/screen.h" | |
22 #include "ui/display/types/display_constants.h" | 24 #include "ui/display/types/display_constants.h" |
23 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
24 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
27 #include "ui/wm/core/window_util.h" | |
25 | 28 |
26 namespace ash { | 29 namespace ash { |
27 namespace wm { | 30 namespace wm { |
28 | 31 |
29 namespace { | 32 namespace { |
30 | 33 |
31 // Returns the default width of a snapped window. | 34 // Returns the default width of a snapped window. |
32 int GetDefaultSnappedWindowWidth(aura::Window* window) { | 35 int GetDefaultSnappedWindowWidth(aura::Window* window) { |
33 const float kSnappedWidthWorkspaceRatio = 0.5f; | 36 const float kSnappedWidthWorkspaceRatio = 0.5f; |
34 | 37 |
35 int work_area_width = | 38 int work_area_width = |
36 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window).width(); | 39 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window).width(); |
37 int min_width = | 40 int min_width = |
38 window->delegate() ? window->delegate()->GetMinimumSize().width() : 0; | 41 window->delegate() ? window->delegate()->GetMinimumSize().width() : 0; |
39 int ideal_width = | 42 int ideal_width = |
40 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); | 43 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); |
41 return std::min(work_area_width, std::max(ideal_width, min_width)); | 44 return std::min(work_area_width, std::max(ideal_width, min_width)); |
42 } | 45 } |
43 | 46 |
44 // Return true if the window or one of its ancestor returns true from | 47 // Return true if the window or one of its ancestor returns true from |
45 // IsLockedToRoot(). | 48 // IsLockedToRoot(). |
46 bool IsWindowOrAncestorLockedToRoot(const WmWindow* window) { | 49 bool IsWindowOrAncestorLockedToRoot(const aura::Window* window) { |
47 return window && (window->IsLockedToRoot() || | 50 return window && (window->GetProperty(kLockedToRootKey) || |
48 IsWindowOrAncestorLockedToRoot(window->GetParent())); | 51 IsWindowOrAncestorLockedToRoot(window->parent())); |
49 } | 52 } |
50 | 53 |
51 // Move all transient children to |dst_root|, including the ones in | 54 // Move all transient children to |dst_root|, including the ones in |
52 // the child windows and transient children of the transient children. | 55 // the child windows and transient children of the transient children. |
53 void MoveAllTransientChildrenToNewRoot(const display::Display& display, | 56 void MoveAllTransientChildrenToNewRoot(const display::Display& display, |
54 WmWindow* window) { | 57 aura::Window* window) { |
55 WmWindow* dst_root = | 58 aura::Window* dst_root = |
56 Shell::GetRootWindowControllerWithDisplayId(display.id())->GetWindow(); | 59 Shell::GetRootWindowControllerWithDisplayId(display.id()) |
57 for (WmWindow* transient_child : window->GetTransientChildren()) { | 60 ->GetRootWindow(); |
58 const int container_id = transient_child->GetParent()->aura_window()->id(); | 61 for (aura::Window* transient_child : ::wm::GetTransientChildren(window)) { |
62 const int container_id = transient_child->parent()->id(); | |
59 DCHECK_GE(container_id, 0); | 63 DCHECK_GE(container_id, 0); |
60 WmWindow* container = dst_root->GetChildByShellWindowId(container_id); | 64 aura::Window* container = dst_root->GetChildById(container_id); |
61 const gfx::Rect transient_child_bounds_in_screen = | 65 const gfx::Rect transient_child_bounds_in_screen = |
62 transient_child->GetBoundsInScreen(); | 66 transient_child->GetBoundsInScreen(); |
63 container->AddChild(transient_child); | 67 container->AddChild(transient_child); |
64 transient_child->SetBoundsInScreen(transient_child_bounds_in_screen, | 68 transient_child->SetBoundsInScreen(transient_child_bounds_in_screen, |
65 display); | 69 display); |
66 | 70 |
67 // Transient children may have transient children. | 71 // Transient children may have transient children. |
68 MoveAllTransientChildrenToNewRoot(display, transient_child); | 72 MoveAllTransientChildrenToNewRoot(display, transient_child); |
69 } | 73 } |
70 // Move transient children of the child windows if any. | 74 // Move transient children of the child windows if any. |
71 for (WmWindow* child : window->GetChildren()) | 75 for (aura::Window* child : window->children()) |
James Cook
2017/05/25 17:19:01
Thanks for explicitly listing the type.
varkha
2017/05/25 18:24:09
Acknowledged.
| |
72 MoveAllTransientChildrenToNewRoot(display, child); | 76 MoveAllTransientChildrenToNewRoot(display, child); |
73 } | 77 } |
74 | 78 |
75 } // namespace | 79 } // namespace |
76 | 80 |
77 void AdjustBoundsSmallerThan(const gfx::Size& max_size, gfx::Rect* bounds) { | 81 void AdjustBoundsSmallerThan(const gfx::Size& max_size, gfx::Rect* bounds) { |
78 bounds->set_width(std::min(bounds->width(), max_size.width())); | 82 bounds->set_width(std::min(bounds->width(), max_size.width())); |
79 bounds->set_height(std::min(bounds->height(), max_size.height())); | 83 bounds->set_height(std::min(bounds->height(), max_size.height())); |
80 } | 84 } |
81 | 85 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 124 } |
121 | 125 |
122 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(aura::Window* window) { | 126 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(aura::Window* window) { |
123 gfx::Rect work_area_in_parent( | 127 gfx::Rect work_area_in_parent( |
124 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window)); | 128 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window)); |
125 int width = GetDefaultSnappedWindowWidth(window); | 129 int width = GetDefaultSnappedWindowWidth(window); |
126 return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), | 130 return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), |
127 width, work_area_in_parent.height()); | 131 width, work_area_in_parent.height()); |
128 } | 132 } |
129 | 133 |
130 void CenterWindow(WmWindow* window) { | 134 void CenterWindow(aura::Window* window) { |
131 WMEvent event(WM_EVENT_CENTER); | 135 WMEvent event(WM_EVENT_CENTER); |
132 window->GetWindowState()->OnWMEvent(&event); | 136 wm::GetWindowState(window)->OnWMEvent(&event); |
133 } | 137 } |
134 | 138 |
135 void SetBoundsInScreen(WmWindow* window, | 139 void SetBoundsInScreen(aura::Window* window, |
136 const gfx::Rect& bounds_in_screen, | 140 const gfx::Rect& bounds_in_screen, |
137 const display::Display& display) { | 141 const display::Display& display) { |
138 DCHECK_NE(display::kInvalidDisplayId, display.id()); | 142 DCHECK_NE(display::kInvalidDisplayId, display.id()); |
139 // Don't move a window to other root window if: | 143 // Don't move a window to other root window if: |
140 // a) the window is a transient window. It moves when its | 144 // a) the window is a transient window. It moves when its |
141 // transient parent moves. | 145 // transient parent moves. |
142 // b) if the window or its ancestor has IsLockedToRoot(). It's intentionally | 146 // b) if the window or its ancestor has IsLockedToRoot(). It's intentionally |
143 // kept in the same root window even if the bounds is outside of the | 147 // kept in the same root window even if the bounds is outside of the |
144 // display. | 148 // display. |
145 if (!window->GetTransientParent() && | 149 if (!::wm::GetTransientParent(window) && |
146 !IsWindowOrAncestorLockedToRoot(window)) { | 150 !IsWindowOrAncestorLockedToRoot(window)) { |
147 RootWindowController* dst_root_window_controller = | 151 RootWindowController* dst_root_window_controller = |
148 Shell::GetRootWindowControllerWithDisplayId(display.id()); | 152 Shell::GetRootWindowControllerWithDisplayId(display.id()); |
149 DCHECK(dst_root_window_controller); | 153 DCHECK(dst_root_window_controller); |
150 WmWindow* dst_root = dst_root_window_controller->GetWindow(); | 154 aura::Window* dst_root = dst_root_window_controller->GetRootWindow(); |
151 DCHECK(dst_root); | 155 DCHECK(dst_root); |
152 WmWindow* dst_container = nullptr; | 156 aura::Window* dst_container = nullptr; |
153 if (dst_root != window->GetRootWindow()) { | 157 if (dst_root != window->GetRootWindow()) { |
154 int container_id = window->GetParent()->aura_window()->id(); | 158 int container_id = window->parent()->id(); |
155 // All containers that uses screen coordinates must have valid window ids. | 159 // All containers that use screen coordinates must have valid window ids. |
156 DCHECK_GE(container_id, 0); | 160 DCHECK_GE(container_id, 0); |
157 // Don't move modal background. | 161 // Don't move modal background. |
158 if (!SystemModalContainerLayoutManager::IsModalBackground( | 162 if (!SystemModalContainerLayoutManager::IsModalBackground(window)) |
159 window->aura_window())) | 163 dst_container = dst_root->GetChildById(container_id); |
160 dst_container = dst_root->GetChildByShellWindowId(container_id); | |
161 } | 164 } |
162 | 165 |
163 if (dst_container && window->GetParent() != dst_container) { | 166 if (dst_container && window->parent() != dst_container) { |
164 aura::Window* focused = GetFocusedWindow(); | 167 aura::Window* focused = GetFocusedWindow(); |
165 aura::Window* active = GetActiveWindow(); | 168 aura::Window* active = GetActiveWindow(); |
166 | 169 |
167 aura::WindowTracker tracker; | 170 aura::WindowTracker tracker; |
168 if (focused) | 171 if (focused) |
169 tracker.Add(focused); | 172 tracker.Add(focused); |
170 if (active && focused != active) | 173 if (active && focused != active) |
171 tracker.Add(active); | 174 tracker.Add(active); |
172 | 175 |
173 gfx::Point origin = bounds_in_screen.origin(); | 176 gfx::Point origin = bounds_in_screen.origin(); |
(...skipping 17 matching lines...) Expand all Loading... | |
191 wm::ActivateWindow(active); | 194 wm::ActivateWindow(active); |
192 } | 195 } |
193 // TODO(oshima): We should not have to update the bounds again | 196 // TODO(oshima): We should not have to update the bounds again |
194 // below in theory, but we currently do need as there is a code | 197 // below in theory, but we currently do need as there is a code |
195 // that assumes that the bounds will never be overridden by the | 198 // that assumes that the bounds will never be overridden by the |
196 // layout mananger. We should have more explicit control how | 199 // layout mananger. We should have more explicit control how |
197 // constraints are applied by the layout manager. | 200 // constraints are applied by the layout manager. |
198 } | 201 } |
199 } | 202 } |
200 gfx::Point origin(bounds_in_screen.origin()); | 203 gfx::Point origin(bounds_in_screen.origin()); |
201 const gfx::Point display_origin = | 204 const gfx::Point display_origin = display::Screen::GetScreen() |
202 window->GetDisplayNearestWindow().bounds().origin(); | 205 ->GetDisplayNearestWindow(window) |
206 .bounds() | |
207 .origin(); | |
203 origin.Offset(-display_origin.x(), -display_origin.y()); | 208 origin.Offset(-display_origin.x(), -display_origin.y()); |
204 window->SetBounds(gfx::Rect(origin, bounds_in_screen.size())); | 209 window->SetBounds(gfx::Rect(origin, bounds_in_screen.size())); |
205 } | 210 } |
206 | 211 |
207 } // namespace wm | 212 } // namespace wm |
208 } // namespace ash | 213 } // namespace ash |
OLD | NEW |