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

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

Issue 1949603002: Revert of mus: Enable system modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/test_utils.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),
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 221
200 for (ServerWindow* child : children_) { 222 for (ServerWindow* child : children_) {
201 ServerWindow* window = child->GetChildWindow(window_id); 223 ServerWindow* window = child->GetChildWindow(window_id);
202 if (window) 224 if (window)
203 return window; 225 return window;
204 } 226 }
205 227
206 return nullptr; 228 return nullptr;
207 } 229 }
208 230
209 bool ServerWindow::AddTransientWindow(ServerWindow* child) { 231 void ServerWindow::AddTransientWindow(ServerWindow* child) {
210 // A system modal window cannot become a transient child.
211 if (child->is_modal() && !child->transient_parent())
212 return false;
213
214 if (child->transient_parent()) 232 if (child->transient_parent())
215 child->transient_parent()->RemoveTransientWindow(child); 233 child->transient_parent()->RemoveTransientWindow(child);
216 234
217 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), 235 DCHECK(std::find(transient_children_.begin(), transient_children_.end(),
218 child) == transient_children_.end()); 236 child) == transient_children_.end());
219 transient_children_.push_back(child); 237 transient_children_.push_back(child);
220 child->transient_parent_ = this; 238 child->transient_parent_ = this;
221 239
222 // Restack |child| properly above its transient parent, if they share the same 240 // Restack |child| properly above its transient parent, if they share the same
223 // parent. 241 // parent.
224 if (child->parent() == parent()) 242 if (child->parent() == parent())
225 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); 243 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl);
226 244
227 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, 245 FOR_EACH_OBSERVER(ServerWindowObserver, observers_,
228 OnTransientWindowAdded(this, child)); 246 OnTransientWindowAdded(this, child));
229 return true;
230 } 247 }
231 248
232 void ServerWindow::RemoveTransientWindow(ServerWindow* child) { 249 void ServerWindow::RemoveTransientWindow(ServerWindow* child) {
233 Windows::iterator i = 250 Windows::iterator i =
234 std::find(transient_children_.begin(), transient_children_.end(), child); 251 std::find(transient_children_.begin(), transient_children_.end(), child);
235 DCHECK(i != transient_children_.end()); 252 DCHECK(i != transient_children_.end());
236 transient_children_.erase(i); 253 transient_children_.erase(i);
237 DCHECK_EQ(this, child->transient_parent()); 254 DCHECK_EQ(this, child->transient_parent());
238 child->transient_parent_ = nullptr; 255 child->transient_parent_ = nullptr;
239 256
240 // 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|
241 // 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
242 // former parent, anymore. 259 // former parent, anymore.
243 if (parent() == child->parent()) 260 if (parent() == child->parent())
244 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl); 261 RestackTransientDescendants(this, &GetStackingTarget, &ReorderImpl);
245 262
246 FOR_EACH_OBSERVER(ServerWindowObserver, observers_, 263 FOR_EACH_OBSERVER(ServerWindowObserver, observers_,
247 OnTransientWindowRemoved(this, child)); 264 OnTransientWindowRemoved(this, child));
248 } 265 }
249 266
250 void ServerWindow::SetModal() { 267 void ServerWindow::SetModal() {
251 is_modal_ = true; 268 is_modal_ = true;
252 } 269 }
253 270
271 bool ServerWindow::IsBlockedByModalWindow() const {
272 return !!GetModalChildForWindowAncestor(this);
273 }
274
275 const ServerWindow* ServerWindow::GetModalTarget() const {
276 return GetModalTargetForWindow(this);
277 }
278
254 bool ServerWindow::Contains(const ServerWindow* window) const { 279 bool ServerWindow::Contains(const ServerWindow* window) const {
255 for (const ServerWindow* parent = window; parent; parent = parent->parent_) { 280 for (const ServerWindow* parent = window; parent; parent = parent->parent_) {
256 if (parent == this) 281 if (parent == this)
257 return true; 282 return true;
258 } 283 }
259 return false; 284 return false;
260 } 285 }
261 286
262 void ServerWindow::SetVisible(bool value) { 287 void ServerWindow::SetVisible(bool value) {
263 if (visible_ == value) 288 if (visible_ == value)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 459 }
435 460
436 // static 461 // static
437 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) { 462 ServerWindow** ServerWindow::GetStackingTarget(ServerWindow* window) {
438 return &window->stacking_target_; 463 return &window->stacking_target_;
439 } 464 }
440 465
441 } // namespace ws 466 } // namespace ws
442 467
443 } // namespace mus 468 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/server_window.h ('k') | components/mus/ws/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698