OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/mus/ws/server_window.h" | 5 #include "components/mus/ws/server_window.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "components/mus/common/transient_window_utils.h" | 11 #include "components/mus/common/transient_window_utils.h" |
12 #include "components/mus/ws/server_window_delegate.h" | 12 #include "components/mus/ws/server_window_delegate.h" |
13 #include "components/mus/ws/server_window_observer.h" | 13 #include "components/mus/ws/server_window_observer.h" |
14 #include "components/mus/ws/server_window_surface_manager.h" | 14 #include "components/mus/ws/server_window_surface_manager.h" |
15 #include "mojo/converters/geometry/geometry_type_converters.h" | 15 #include "mojo/converters/geometry/geometry_type_converters.h" |
16 | 16 |
17 namespace mus { | 17 namespace mus { |
18 | 18 |
19 namespace ws { | 19 namespace ws { |
20 | 20 |
21 namespace { | |
22 | |
23 const ServerWindow* GetModalChildForWindowAncestor(const ServerWindow* window) { | |
24 for (const ServerWindow* ancestor = window; ancestor; | |
25 ancestor = ancestor->parent()) { | |
26 for (const auto& transient_child : ancestor->transient_children()) { | |
27 if (transient_child->is_modal() && transient_child->IsDrawn()) | |
28 return transient_child; | |
29 } | |
30 } | |
31 return nullptr; | |
32 } | |
33 | |
34 const ServerWindow* GetModalTargetForWindow(const ServerWindow* window) { | |
35 const ServerWindow* modal_window = GetModalChildForWindowAncestor(window); | |
36 if (!modal_window) | |
37 return window; | |
38 return GetModalTargetForWindow(modal_window); | |
39 } | |
40 | |
41 } // namespace | |
42 | |
43 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, const WindowId& id) | 21 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, const WindowId& id) |
44 : ServerWindow(delegate, id, Properties()) {} | 22 : ServerWindow(delegate, id, Properties()) {} |
45 | 23 |
46 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, | 24 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, |
47 const WindowId& id, | 25 const WindowId& id, |
48 const Properties& properties) | 26 const Properties& properties) |
49 : delegate_(delegate), | 27 : delegate_(delegate), |
50 id_(id), | 28 id_(id), |
51 parent_(nullptr), | 29 parent_(nullptr), |
52 stacking_target_(nullptr), | 30 stacking_target_(nullptr), |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 200 |
223 for (ServerWindow* child : children_) { | 201 for (ServerWindow* child : children_) { |
224 ServerWindow* window = child->GetChildWindow(window_id); | 202 ServerWindow* window = child->GetChildWindow(window_id); |
225 if (window) | 203 if (window) |
226 return window; | 204 return window; |
227 } | 205 } |
228 | 206 |
229 return nullptr; | 207 return nullptr; |
230 } | 208 } |
231 | 209 |
232 void ServerWindow::AddTransientWindow(ServerWindow* child) { | 210 bool ServerWindow::AddTransientWindow(ServerWindow* child) { |
| 211 // A system modal window cannot become a transient child. |
| 212 if (child->is_modal() && !child->transient_parent()) |
| 213 return false; |
| 214 |
233 if (child->transient_parent()) | 215 if (child->transient_parent()) |
234 child->transient_parent()->RemoveTransientWindow(child); | 216 child->transient_parent()->RemoveTransientWindow(child); |
235 | 217 |
236 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), | 218 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), |
237 child) == transient_children_.end()); | 219 child) == transient_children_.end()); |
238 transient_children_.push_back(child); | 220 transient_children_.push_back(child); |
239 child->transient_parent_ = this; | 221 child->transient_parent_ = this; |
240 | 222 |
241 // Restack |child| properly above its transient parent, if they share the same | 223 // Restack |child| properly above its transient parent, if they share the same |
242 // parent. | 224 // parent. |
243 if (child->parent() == parent()) | 225 if (child->parent() == parent()) |
244 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); | 226 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); |
245 | 227 |
246 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, | 228 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, |
247 OnTransientWindowAdded(this, child)); | 229 OnTransientWindowAdded(this, child)); |
| 230 return true; |
248 } | 231 } |
249 | 232 |
250 void ServerWindow::RemoveTransientWindow(ServerWindow* child) { | 233 void ServerWindow::RemoveTransientWindow(ServerWindow* child) { |
251 Windows::iterator i = | 234 Windows::iterator i = |
252 std::find(transient_children_.begin(), transient_children_.end(), child); | 235 std::find(transient_children_.begin(), transient_children_.end(), child); |
253 DCHECK(i != transient_children_.end()); | 236 DCHECK(i != transient_children_.end()); |
254 transient_children_.erase(i); | 237 transient_children_.erase(i); |
255 DCHECK_EQ(this, child->transient_parent()); | 238 DCHECK_EQ(this, child->transient_parent()); |
256 child->transient_parent_ = nullptr; | 239 child->transient_parent_ = nullptr; |
257 | 240 |
258 // If |child| and its former transient parent share the same parent, |child| | 241 // If |child| and its former transient parent share the same parent, |child| |
259 // should be restacked properly so it is not among transient children of its | 242 // should be restacked properly so it is not among transient children of its |
260 // former parent, anymore. | 243 // former parent, anymore. |
261 if (parent() == child->parent()) | 244 if (parent() == child->parent()) |
262 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); | 245 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); |
263 | 246 |
264 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, | 247 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, |
265 OnTransientWindowRemoved(this, child)); | 248 OnTransientWindowRemoved(this, child)); |
266 } | 249 } |
267 | 250 |
268 void ServerWindow::SetModal() { | 251 void ServerWindow::SetModal() { |
269 is_modal_ = true; | 252 is_modal_ = true; |
270 } | 253 } |
271 | 254 |
272 bool ServerWindow::IsBlockedByModalWindow() const { | |
273 return !!GetModalChildForWindowAncestor(this); | |
274 } | |
275 | |
276 const ServerWindow* ServerWindow::GetModalTarget() const { | |
277 return GetModalTargetForWindow(this); | |
278 } | |
279 | |
280 bool ServerWindow::Contains(const ServerWindow* window) const { | 255 bool ServerWindow::Contains(const ServerWindow* window) const { |
281 for (const ServerWindow* parent = window; parent; parent = parent->parent_) { | 256 for (const ServerWindow* parent = window; parent; parent = parent->parent_) { |
282 if (parent == this) | 257 if (parent == this) |
283 return true; | 258 return true; |
284 } | 259 } |
285 return false; | 260 return false; |
286 } | 261 } |
287 | 262 |
288 void ServerWindow::SetVisible(bool value) { | 263 void ServerWindow::SetVisible(bool value) { |
289 if (visible_ == value) | 264 if (visible_ == value) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 435 } |
461 | 436 |
462 // static | 437 // static |
463 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) { | 438 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) { |
464 return &window->stacking_target_; | 439 return &window->stacking_target_; |
465 } | 440 } |
466 | 441 |
467 } // namespace ws | 442 } // namespace ws |
468 | 443 |
469 } // namespace mus | 444 } // namespace mus |
OLD | NEW |