OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/window_tree_host_impl.h" | 5 #include "components/mus/ws/window_tree_host_impl.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "components/mus/common/types.h" | 8 #include "components/mus/common/types.h" |
9 #include "components/mus/ws/connection_manager.h" | 9 #include "components/mus/ws/connection_manager.h" |
10 #include "components/mus/ws/display_manager.h" | 10 #include "components/mus/ws/display_manager.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 mojo::ApplicationImpl* app_impl, | 23 mojo::ApplicationImpl* app_impl, |
24 const scoped_refptr<GpuState>& gpu_state, | 24 const scoped_refptr<GpuState>& gpu_state, |
25 const scoped_refptr<SurfacesState>& surfaces_state, | 25 const scoped_refptr<SurfacesState>& surfaces_state, |
26 mojom::WindowManagerPtr window_manager) | 26 mojom::WindowManagerPtr window_manager) |
27 : delegate_(nullptr), | 27 : delegate_(nullptr), |
28 connection_manager_(connection_manager), | 28 connection_manager_(connection_manager), |
29 client_(client.Pass()), | 29 client_(client.Pass()), |
30 event_dispatcher_(this), | 30 event_dispatcher_(this), |
31 display_manager_( | 31 display_manager_( |
32 DisplayManager::Create(app_impl, gpu_state, surfaces_state)), | 32 DisplayManager::Create(app_impl, gpu_state, surfaces_state)), |
33 focus_controller_(new FocusController), | 33 focus_controller_(new FocusController(this)), |
34 window_manager_(window_manager.Pass()) { | 34 window_manager_(window_manager.Pass()) { |
35 focus_controller_->AddObserver(this); | 35 focus_controller_->AddObserver(this); |
36 display_manager_->Init(this); | 36 display_manager_->Init(this); |
37 if (client_) { | 37 if (client_) { |
38 client_.set_connection_error_handler(base::Bind( | 38 client_.set_connection_error_handler(base::Bind( |
39 &WindowTreeHostImpl::OnClientClosed, base::Unretained(this))); | 39 &WindowTreeHostImpl::OnClientClosed, base::Unretained(this))); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 WindowTreeHostImpl::~WindowTreeHostImpl() { | 43 WindowTreeHostImpl::~WindowTreeHostImpl() { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 void WindowTreeHostImpl::AddAccelerator(uint32_t id, | 131 void WindowTreeHostImpl::AddAccelerator(uint32_t id, |
132 mojom::EventMatcherPtr event_matcher) { | 132 mojom::EventMatcherPtr event_matcher) { |
133 event_dispatcher_.AddAccelerator(id, event_matcher.Pass()); | 133 event_dispatcher_.AddAccelerator(id, event_matcher.Pass()); |
134 } | 134 } |
135 | 135 |
136 void WindowTreeHostImpl::RemoveAccelerator(uint32_t id) { | 136 void WindowTreeHostImpl::RemoveAccelerator(uint32_t id) { |
137 event_dispatcher_.RemoveAccelerator(id); | 137 event_dispatcher_.RemoveAccelerator(id); |
138 } | 138 } |
139 | 139 |
| 140 void WindowTreeHostImpl::AddActivationParent(uint32_t window_id) { |
| 141 ServerWindow* window = |
| 142 connection_manager_->GetWindow(WindowIdFromTransportId(window_id)); |
| 143 if (window) |
| 144 activation_parents_.insert(window->id()); |
| 145 } |
| 146 |
| 147 void WindowTreeHostImpl::RemoveActivationParent(uint32_t window_id) { |
| 148 ServerWindow* window = |
| 149 connection_manager_->GetWindow(WindowIdFromTransportId(window_id)); |
| 150 if (window) |
| 151 activation_parents_.erase(window->id()); |
| 152 } |
| 153 |
140 void WindowTreeHostImpl::OnClientClosed() { | 154 void WindowTreeHostImpl::OnClientClosed() { |
141 // |display_manager_.reset()| destroys the display-manager first, and then | 155 // |display_manager_.reset()| destroys the display-manager first, and then |
142 // sets |display_manager_| to nullptr. However, destroying |display_manager_| | 156 // sets |display_manager_| to nullptr. However, destroying |display_manager_| |
143 // can destroy the corresponding WindowTreeHostConnection, and |this|. So | 157 // can destroy the corresponding WindowTreeHostConnection, and |this|. So |
144 // setting it to nullptr afterwards in reset() ends up writing on free'd | 158 // setting it to nullptr afterwards in reset() ends up writing on free'd |
145 // memory. So transfer over to a local scoped_ptr<> before destroying it. | 159 // memory. So transfer over to a local scoped_ptr<> before destroying it. |
146 scoped_ptr<DisplayManager> temp = display_manager_.Pass(); | 160 scoped_ptr<DisplayManager> temp = display_manager_.Pass(); |
147 } | 161 } |
148 | 162 |
149 ServerWindow* WindowTreeHostImpl::GetRootWindow() { | 163 ServerWindow* WindowTreeHostImpl::GetRootWindow() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 197 |
184 void WindowTreeHostImpl::OnCompositorFrameDrawn() { | 198 void WindowTreeHostImpl::OnCompositorFrameDrawn() { |
185 std::set<ServerWindow*> windows; | 199 std::set<ServerWindow*> windows; |
186 windows.swap(windows_needing_frame_destruction_); | 200 windows.swap(windows_needing_frame_destruction_); |
187 for (ServerWindow* window : windows) { | 201 for (ServerWindow* window : windows) { |
188 window->RemoveObserver(this); | 202 window->RemoveObserver(this); |
189 window->DestroySurfacesScheduledForDestruction(); | 203 window->DestroySurfacesScheduledForDestruction(); |
190 } | 204 } |
191 } | 205 } |
192 | 206 |
| 207 bool WindowTreeHostImpl::CanHaveActiveChildren(ServerWindow* window) const { |
| 208 return window && activation_parents_.count(window->id()) > 0; |
| 209 } |
| 210 |
| 211 void WindowTreeHostImpl::OnActivationChanged(ServerWindow* old_active_window, |
| 212 ServerWindow* new_active_window) { |
| 213 DCHECK_NE(new_active_window, old_active_window); |
| 214 if (new_active_window && new_active_window->parent()) { |
| 215 // Raise the new active window. |
| 216 // TODO(sad): Let the WM dictate whether to raise the window or not? |
| 217 new_active_window->parent()->StackChildAtTop(new_active_window); |
| 218 } |
| 219 } |
| 220 |
193 void WindowTreeHostImpl::OnFocusChanged( | 221 void WindowTreeHostImpl::OnFocusChanged( |
194 FocusControllerChangeSource change_source, | 222 FocusControllerChangeSource change_source, |
195 ServerWindow* old_focused_window, | 223 ServerWindow* old_focused_window, |
196 ServerWindow* new_focused_window) { | 224 ServerWindow* new_focused_window) { |
197 // There are up to four connections that need to be notified: | 225 // There are up to four connections that need to be notified: |
198 // . the connection containing |old_focused_window|. | 226 // . the connection containing |old_focused_window|. |
199 // . the connection with |old_focused_window| as its root. | 227 // . the connection with |old_focused_window| as its root. |
200 // . the connection containing |new_focused_window|. | 228 // . the connection containing |new_focused_window|. |
201 // . the connection with |new_focused_window| as its root. | 229 // . the connection with |new_focused_window| as its root. |
202 // Some of these connections may be the same. The following takes care to | 230 // Some of these connections may be the same. The following takes care to |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 base::Bind(&base::DoNothing)); | 315 base::Bind(&base::DoNothing)); |
288 } | 316 } |
289 | 317 |
290 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { | 318 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { |
291 windows_needing_frame_destruction_.erase(window); | 319 windows_needing_frame_destruction_.erase(window); |
292 window->RemoveObserver(this); | 320 window->RemoveObserver(this); |
293 } | 321 } |
294 | 322 |
295 } // namespace ws | 323 } // namespace ws |
296 } // namespace mus | 324 } // namespace mus |
OLD | NEW |