| 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 for (ServerWindow* child : children_) { | 200 for (ServerWindow* child : children_) { |
| 223 ServerWindow* window = child->GetChildWindow(window_id); | 201 ServerWindow* window = child->GetChildWindow(window_id); |
| 224 if (window) | 202 if (window) |
| 225 return window; | 203 return window; |
| 226 } | 204 } |
| 227 | 205 |
| 228 return nullptr; | 206 return nullptr; |
| 229 } | 207 } |
| 230 | 208 |
| 231 void ServerWindow::AddTransientWindow(ServerWindow* child) { | 209 void ServerWindow::AddTransientWindow(ServerWindow* child) { |
| 210 // A system modal window cannot become a transient child. |
| 211 DCHECK(!child->is_modal() || child->transient_parent()); |
| 212 |
| 232 if (child->transient_parent()) | 213 if (child->transient_parent()) |
| 233 child->transient_parent()->RemoveTransientWindow(child); | 214 child->transient_parent()->RemoveTransientWindow(child); |
| 234 | 215 |
| 235 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), | 216 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), |
| 236 child) == transient_children_.end()); | 217 child) == transient_children_.end()); |
| 237 transient_children_.push_back(child); | 218 transient_children_.push_back(child); |
| 238 child->transient_parent_ = this; | 219 child->transient_parent_ = this; |
| 239 | 220 |
| 240 // Restack |child| properly above its transient parent, if they share the same | 221 // Restack |child| properly above its transient parent, if they share the same |
| 241 // parent. | 222 // parent. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 261 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); | 242 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); |
| 262 | 243 |
| 263 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, | 244 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, |
| 264 OnTransientWindowRemoved(this, child)); | 245 OnTransientWindowRemoved(this, child)); |
| 265 } | 246 } |
| 266 | 247 |
| 267 void ServerWindow::SetModal() { | 248 void ServerWindow::SetModal() { |
| 268 is_modal_ = true; | 249 is_modal_ = true; |
| 269 } | 250 } |
| 270 | 251 |
| 271 bool ServerWindow::IsBlockedByModalWindow() const { | |
| 272 return !!GetModalChildForWindowAncestor(this); | |
| 273 } | |
| 274 | |
| 275 const ServerWindow* ServerWindow::GetModalTarget() const { | |
| 276 return GetModalTargetForWindow(this); | |
| 277 } | |
| 278 | |
| 279 bool ServerWindow::Contains(const ServerWindow* window) const { | 252 bool ServerWindow::Contains(const ServerWindow* window) const { |
| 280 for (const ServerWindow* parent = window; parent; parent = parent->parent_) { | 253 for (const ServerWindow* parent = window; parent; parent = parent->parent_) { |
| 281 if (parent == this) | 254 if (parent == this) |
| 282 return true; | 255 return true; |
| 283 } | 256 } |
| 284 return false; | 257 return false; |
| 285 } | 258 } |
| 286 | 259 |
| 287 void ServerWindow::SetVisible(bool value) { | 260 void ServerWindow::SetVisible(bool value) { |
| 288 if (visible_ == value) | 261 if (visible_ == value) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 432 } |
| 460 | 433 |
| 461 // static | 434 // static |
| 462 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) { | 435 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) { |
| 463 return &window->stacking_target_; | 436 return &window->stacking_target_; |
| 464 } | 437 } |
| 465 | 438 |
| 466 } // namespace ws | 439 } // namespace ws |
| 467 | 440 |
| 468 } // namespace mus | 441 } // namespace mus |
| OLD | NEW |