OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/mus/ws/modal_window_controller.h" | |
6 | |
7 #include "components/mus/ws/event_dispatcher.h" | |
8 #include "components/mus/ws/server_window.h" | |
9 | |
10 namespace mus { | |
11 namespace ws { | |
12 namespace { | |
13 | |
14 const ServerWindow* GetModalChildForWindowAncestor(const ServerWindow* window) { | |
15 for (const ServerWindow* ancestor = window; ancestor; | |
16 ancestor = ancestor->parent()) { | |
17 for (const auto& transient_child : ancestor->transient_children()) { | |
18 if (transient_child->is_modal() && transient_child->IsDrawn()) | |
19 return transient_child; | |
20 } | |
21 } | |
22 return nullptr; | |
23 } | |
24 | |
25 const ServerWindow* GetWindowModalTargetForWindow(const ServerWindow* window) { | |
26 const ServerWindow* modal_window = GetModalChildForWindowAncestor(window); | |
27 if (!modal_window) | |
28 return window; | |
29 return GetWindowModalTargetForWindow(modal_window); | |
30 } | |
31 | |
32 } // namespace | |
33 | |
34 ModalWindowController::ModalWindowController(EventDispatcher* event_dispatcher) | |
35 : event_dispatcher_(event_dispatcher) {} | |
36 | |
37 ModalWindowController::~ModalWindowController() { | |
38 for (auto it = system_modal_windows_.begin(); | |
39 it != system_modal_windows_.end();) { | |
40 auto remove_it = it++; | |
41 RemoveSystemModalWindow(remove_it); | |
42 } | |
43 } | |
44 | |
45 void ModalWindowController::AddSystemModalWindow(ServerWindow* window) { | |
46 DCHECK(window); | |
47 DCHECK(std::find(system_modal_windows_.begin(), system_modal_windows_.end(), | |
sky
2016/04/26 23:40:08
!ContainsValue (in stl_util).
mohsen
2016/04/27 20:18:25
Done.
| |
48 window) == system_modal_windows_.end()); | |
49 | |
50 window->SetModal(); | |
51 system_modal_windows_.push_front(window); | |
52 window->AddObserver(this); | |
53 | |
54 event_dispatcher_->ReleaseCaptureBlockedByModalWindow(window); | |
55 } | |
56 | |
57 bool ModalWindowController::IsWindowBlockedBy( | |
58 const ServerWindow* window, | |
59 const ServerWindow* modal_window) const { | |
60 DCHECK(window); | |
61 DCHECK(modal_window); | |
62 if (!modal_window->is_modal() || !modal_window->IsDrawn()) | |
63 return false; | |
64 | |
65 if (modal_window->transient_parent() && | |
66 !modal_window->transient_parent()->Contains(window)) { | |
67 return false; | |
68 } | |
69 | |
70 return true; | |
71 } | |
72 | |
73 bool ModalWindowController::IsWindowBlocked(const ServerWindow* window) const { | |
74 DCHECK(window); | |
75 return GetActiveSystemModalWindow() || GetModalChildForWindowAncestor(window); | |
76 } | |
77 | |
78 const ServerWindow* ModalWindowController::GetTargetForWindow( | |
79 const ServerWindow* window) const { | |
80 ServerWindow* system_modal_window = GetActiveSystemModalWindow(); | |
81 return system_modal_window ? system_modal_window | |
82 : GetWindowModalTargetForWindow(window); | |
83 } | |
84 | |
85 ServerWindow* ModalWindowController::GetActiveSystemModalWindow() const { | |
86 for (auto modal : system_modal_windows_) { | |
87 if (modal->IsDrawn()) | |
88 return modal; | |
89 } | |
90 return nullptr; | |
91 } | |
92 | |
93 void ModalWindowController::RemoveSystemModalWindow( | |
94 ServerWindowList::iterator it) { | |
95 DCHECK(it != system_modal_windows_.end()); | |
96 (*it)->RemoveObserver(this); | |
97 system_modal_windows_.erase(it); | |
98 } | |
99 | |
100 void ModalWindowController::OnWindowVisibilityChanged(ServerWindow* window) { | |
101 if (!window->IsDrawn()) | |
sky
2016/04/26 23:40:08
You need to use a ServerWindowDrawnTracker as OnWi
mohsen
2016/04/27 20:18:25
Done. I've used similar approach in WindowServer t
| |
102 return; | |
103 | |
104 auto it = std::find(system_modal_windows_.begin(), | |
105 system_modal_windows_.end(), window); | |
106 DCHECK(it != system_modal_windows_.end()); | |
107 system_modal_windows_.splice(system_modal_windows_.begin(), | |
sky
2016/04/26 23:40:08
Don't you need to tell EventDispatcher when the mo
mohsen
2016/04/27 20:18:25
This is already handled in WindowServer, for all (
| |
108 system_modal_windows_, it); | |
109 } | |
110 | |
111 void ModalWindowController::OnWindowDestroyed(ServerWindow* window) { | |
112 auto it = std::find(system_modal_windows_.begin(), | |
113 system_modal_windows_.end(), window); | |
114 DCHECK(it != system_modal_windows_.end()); | |
115 RemoveSystemModalWindow(it); | |
116 } | |
117 | |
118 } // namespace ws | |
119 } // namespace mus | |
OLD | NEW |