Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: components/mus/ws/server_window.cc

Issue 1759523002: mus: Server-side implementation of modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SetAsModal -> SetModal + Other review comments addressed Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/mus/ws/server_window.h ('k') | components/mus/ws/window_manager_access_policy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
21 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, const WindowId& id) 43 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, const WindowId& id)
22 : ServerWindow(delegate, id, Properties()) {} 44 : ServerWindow(delegate, id, Properties()) {}
23 45
24 ServerWindow::ServerWindow(ServerWindowDelegate* delegate, 46 ServerWindow::ServerWindow(ServerWindowDelegate* delegate,
25 const WindowId& id, 47 const WindowId& id,
26 const Properties& properties) 48 const Properties& properties)
27 : delegate_(delegate), 49 : delegate_(delegate),
28 id_(id), 50 id_(id),
29 parent_(nullptr), 51 parent_(nullptr),
30 stacking_target_(nullptr), 52 stacking_target_(nullptr),
31 transient_parent_(nullptr), 53 transient_parent_(nullptr),
54 is_modal_(false),
32 visible_(false), 55 visible_(false),
33 cursor_id_(mojom::Cursor::CURSOR_NULL), 56 cursor_id_(mojom::Cursor::CURSOR_NULL),
34 opacity_(1), 57 opacity_(1),
35 can_focus_(true), 58 can_focus_(true),
36 properties_(properties), 59 properties_(properties),
37 // Don't notify newly added observers during notification. This causes 60 // Don't notify newly added observers during notification. This causes
38 // problems for code that adds an observer as part of an observer 61 // problems for code that adds an observer as part of an observer
39 // notification (such as ServerWindowDrawTracker). 62 // notification (such as ServerWindowDrawTracker).
40 observers_( 63 observers_(
41 base::ObserverList<ServerWindowObserver>::NOTIFY_EXISTING_ONLY) { 64 base::ObserverList<ServerWindowObserver>::NOTIFY_EXISTING_ONLY) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // If |child| and its former transient parent share the same parent, |child| 257 // If |child| and its former transient parent share the same parent, |child|
235 // should be restacked properly so it is not among transient children of its 258 // should be restacked properly so it is not among transient children of its
236 // former parent, anymore. 259 // former parent, anymore.
237 if (parent() == child->parent()) 260 if (parent() == child->parent())
238 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); 261 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl);
239 262
240 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, 263 FOR_EACH_OBSERVER(ServerWindowObserver, observers_,
241 OnTransientWindowRemoved(this, child)); 264 OnTransientWindowRemoved(this, child));
242 } 265 }
243 266
267 void ServerWindow::SetModal() {
268 is_modal_ = true;
269 }
270
271 bool ServerWindow::IsBlockedByModalWindow() const {
272 return !!GetModalChildForWindowAncestor(this);
273 }
274
275 const ServerWindow* ServerWindow::GetModalTarget() const {
276 return GetModalTargetForWindow(this);
277 }
278
244 bool ServerWindow::Contains(const ServerWindow* window) const { 279 bool ServerWindow::Contains(const ServerWindow* window) const {
245 for (const ServerWindow* parent = window; parent; parent = parent->parent_) { 280 for (const ServerWindow* parent = window; parent; parent = parent->parent_) {
246 if (parent == this) 281 if (parent == this)
247 return true; 282 return true;
248 } 283 }
249 return false; 284 return false;
250 } 285 }
251 286
252 void ServerWindow::SetVisible(bool value) { 287 void ServerWindow::SetVisible(bool value) {
253 if (visible_ == value) 288 if (visible_ == value)
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 456 }
422 457
423 // static 458 // static
424 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) { 459 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) {
425 return &window->stacking_target_; 460 return &window->stacking_target_;
426 } 461 }
427 462
428 } // namespace ws 463 } // namespace ws
429 464
430 } // namespace mus 465 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/server_window.h ('k') | components/mus/ws/window_manager_access_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698