| 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 "mojo/services/window_manager/window_manager_app.h" | 5 #include "mojo/services/window_manager/window_manager_app.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 10 #include "mojo/converters/input_events/input_events_type_converters.h" | 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 wrapped_view_manager_delegate_(view_manager_delegate), | 78 wrapped_view_manager_delegate_(view_manager_delegate), |
| 79 window_manager_delegate_(window_manager_delegate), | 79 window_manager_delegate_(window_manager_delegate), |
| 80 view_manager_(nullptr), | 80 view_manager_(nullptr), |
| 81 root_(nullptr) { | 81 root_(nullptr) { |
| 82 } | 82 } |
| 83 | 83 |
| 84 WindowManagerApp::~WindowManagerApp() { | 84 WindowManagerApp::~WindowManagerApp() { |
| 85 STLDeleteElements(&connections_); | 85 STLDeleteElements(&connections_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // static | |
| 89 View* WindowManagerApp::GetViewForViewTarget(ViewTarget* target) { | |
| 90 return target->view(); | |
| 91 } | |
| 92 | |
| 93 ViewTarget* WindowManagerApp::GetViewTargetForViewId(Id view) { | |
| 94 ViewIdToViewTargetMap::const_iterator it = | |
| 95 view_id_to_view_target_map_.find(view); | |
| 96 return it != view_id_to_view_target_map_.end() ? it->second : nullptr; | |
| 97 } | |
| 98 | |
| 99 void WindowManagerApp::AddConnection(WindowManagerImpl* connection) { | 88 void WindowManagerApp::AddConnection(WindowManagerImpl* connection) { |
| 100 DCHECK(connections_.find(connection) == connections_.end()); | 89 DCHECK(connections_.find(connection) == connections_.end()); |
| 101 connections_.insert(connection); | 90 connections_.insert(connection); |
| 102 } | 91 } |
| 103 | 92 |
| 104 void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) { | 93 void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) { |
| 105 DCHECK(connections_.find(connection) != connections_.end()); | 94 DCHECK(connections_.find(connection) != connections_.end()); |
| 106 connections_.erase(connection); | 95 connections_.erase(connection); |
| 107 } | 96 } |
| 108 | 97 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void WindowManagerApp::OnEmbed(ViewManager* view_manager, | 158 void WindowManagerApp::OnEmbed(ViewManager* view_manager, |
| 170 View* root, | 159 View* root, |
| 171 ServiceProviderImpl* exported_services, | 160 ServiceProviderImpl* exported_services, |
| 172 scoped_ptr<ServiceProvider> imported_services) { | 161 scoped_ptr<ServiceProvider> imported_services) { |
| 173 DCHECK(!view_manager_ && !root_); | 162 DCHECK(!view_manager_ && !root_); |
| 174 view_manager_ = view_manager; | 163 view_manager_ = view_manager; |
| 175 root_ = root; | 164 root_ = root; |
| 176 | 165 |
| 177 view_event_dispatcher_.reset(new ViewEventDispatcher()); | 166 view_event_dispatcher_.reset(new ViewEventDispatcher()); |
| 178 | 167 |
| 179 RegisterSubtree(root_, nullptr); | 168 RegisterSubtree(root_); |
| 180 | 169 |
| 181 // TODO(erg): Also move the capture client over. | 170 // TODO(erg): Also move the capture client over. |
| 182 // | 171 // |
| 183 // capture_client_.reset( | 172 // capture_client_.reset( |
| 184 // new wm::ScopedCaptureClient(window_tree_host_->window())); | 173 // new wm::ScopedCaptureClient(window_tree_host_->window())); |
| 185 | 174 |
| 186 if (wrapped_view_manager_delegate_) { | 175 if (wrapped_view_manager_delegate_) { |
| 187 wrapped_view_manager_delegate_->OnEmbed( | 176 wrapped_view_manager_delegate_->OnEmbed( |
| 188 view_manager, root, exported_services, imported_services.Pass()); | 177 view_manager, root, exported_services, imported_services.Pass()); |
| 189 } | 178 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 212 DCHECK(params.old_parent || params.new_parent); | 201 DCHECK(params.old_parent || params.new_parent); |
| 213 if (!params.target) | 202 if (!params.target) |
| 214 return; | 203 return; |
| 215 | 204 |
| 216 if (params.new_parent) { | 205 if (params.new_parent) { |
| 217 if (view_id_to_view_target_map_.find(params.target->id()) == | 206 if (view_id_to_view_target_map_.find(params.target->id()) == |
| 218 view_id_to_view_target_map_.end()) { | 207 view_id_to_view_target_map_.end()) { |
| 219 ViewIdToViewTargetMap::const_iterator it = | 208 ViewIdToViewTargetMap::const_iterator it = |
| 220 view_id_to_view_target_map_.find(params.new_parent->id()); | 209 view_id_to_view_target_map_.find(params.new_parent->id()); |
| 221 DCHECK(it != view_id_to_view_target_map_.end()); | 210 DCHECK(it != view_id_to_view_target_map_.end()); |
| 222 RegisterSubtree(params.target, it->second); | 211 RegisterSubtree(params.target); |
| 223 } | 212 } |
| 224 } else if (params.old_parent) { | 213 } else if (params.old_parent) { |
| 225 UnregisterSubtree(params.target); | 214 UnregisterSubtree(params.target); |
| 226 } | 215 } |
| 227 } | 216 } |
| 228 | 217 |
| 229 void WindowManagerApp::OnViewDestroying(View* view) { | 218 void WindowManagerApp::OnViewDestroying(View* view) { |
| 230 if (view != root_) { | 219 if (view != root_) { |
| 231 Unregister(view); | 220 Unregister(view); |
| 232 return; | 221 return; |
| 233 } | 222 } |
| 234 root_ = nullptr; | 223 root_ = nullptr; |
| 235 if (focus_controller_) | 224 if (focus_controller_) |
| 236 focus_controller_->RemoveObserver(this); | 225 focus_controller_->RemoveObserver(this); |
| 237 } | 226 } |
| 238 | 227 |
| 239 void WindowManagerApp::OnViewBoundsChanged(View* view, | |
| 240 const Rect& old_bounds, | |
| 241 const Rect& new_bounds) { | |
| 242 // aura::Window* window = GetWindowForViewId(view->id()); | |
| 243 // window->SetBounds(new_bounds.To<gfx::Rect>()); | |
| 244 } | |
| 245 | |
| 246 //////////////////////////////////////////////////////////////////////////////// | 228 //////////////////////////////////////////////////////////////////////////////// |
| 247 // WindowManagerApp, ui::EventHandler implementation: | 229 // WindowManagerApp, ui::EventHandler implementation: |
| 248 | 230 |
| 249 void WindowManagerApp::OnEvent(ui::Event* event) { | 231 void WindowManagerApp::OnEvent(ui::Event* event) { |
| 250 if (!window_manager_client_) | 232 if (!window_manager_client_) |
| 251 return; | 233 return; |
| 252 | 234 |
| 253 View* view = GetViewForViewTarget(static_cast<ViewTarget*>(event->target())); | 235 View* view = static_cast<ViewTarget*>(event->target())->view(); |
| 254 if (!view) | 236 if (!view) |
| 255 return; | 237 return; |
| 256 | 238 |
| 257 if (focus_controller_) | 239 if (focus_controller_) |
| 258 focus_controller_->OnEvent(event); | 240 focus_controller_->OnEvent(event); |
| 259 | 241 |
| 260 window_manager_client_->DispatchInputEventToView(view->id(), | 242 window_manager_client_->DispatchInputEventToView(view->id(), |
| 261 Event::From(*event)); | 243 Event::From(*event)); |
| 262 } | 244 } |
| 263 | 245 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 280 (*it)->NotifyWindowActivated(GetIdForView(gained_active), | 262 (*it)->NotifyWindowActivated(GetIdForView(gained_active), |
| 281 GetIdForView(lost_active)); | 263 GetIdForView(lost_active)); |
| 282 } | 264 } |
| 283 if (gained_active) | 265 if (gained_active) |
| 284 gained_active->MoveToFront(); | 266 gained_active->MoveToFront(); |
| 285 } | 267 } |
| 286 | 268 |
| 287 //////////////////////////////////////////////////////////////////////////////// | 269 //////////////////////////////////////////////////////////////////////////////// |
| 288 // WindowManagerApp, private: | 270 // WindowManagerApp, private: |
| 289 | 271 |
| 290 void WindowManagerApp::RegisterSubtree(View* view, ViewTarget* parent) { | 272 void WindowManagerApp::RegisterSubtree(View* view) { |
| 291 view->AddObserver(this); | 273 view->AddObserver(this); |
| 292 DCHECK(view_id_to_view_target_map_.find(view->id()) == | 274 DCHECK(view_id_to_view_target_map_.find(view->id()) == |
| 293 view_id_to_view_target_map_.end()); | 275 view_id_to_view_target_map_.end()); |
| 294 ViewTarget* target = new ViewTarget(this, view); | 276 ViewTarget* target = new ViewTarget(view); |
| 295 // All events pass through the root during dispatch, so we only need a handler | 277 // All events pass through the root during dispatch, so we only need a handler |
| 296 // installed there. | 278 // installed there. |
| 297 if (view == root_) { | 279 if (view == root_) { |
| 298 target->SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter())); | 280 target->SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter())); |
| 299 target->AddPreTargetHandler(this); | 281 target->AddPreTargetHandler(this); |
| 300 view_event_dispatcher_->SetRootViewTarget(target); | 282 view_event_dispatcher_->SetRootViewTarget(target); |
| 301 } | 283 } |
| 302 // TODO(erg): Why is there no matching RemoveChild()? How does that work in | |
| 303 // the aura version? | |
| 304 view_id_to_view_target_map_[view->id()] = target; | 284 view_id_to_view_target_map_[view->id()] = target; |
| 305 View::Children::const_iterator it = view->children().begin(); | 285 View::Children::const_iterator it = view->children().begin(); |
| 306 for (; it != view->children().end(); ++it) | 286 for (; it != view->children().end(); ++it) |
| 307 RegisterSubtree(*it, target); | 287 RegisterSubtree(*it); |
| 308 } | 288 } |
| 309 | 289 |
| 310 void WindowManagerApp::UnregisterSubtree(View* view) { | 290 void WindowManagerApp::UnregisterSubtree(View* view) { |
| 311 for (View* child : view->children()) | 291 for (View* child : view->children()) |
| 312 UnregisterSubtree(child); | 292 UnregisterSubtree(child); |
| 313 Unregister(view); | 293 Unregister(view); |
| 314 } | 294 } |
| 315 | 295 |
| 316 void WindowManagerApp::Unregister(View* view) { | 296 void WindowManagerApp::Unregister(View* view) { |
| 317 ViewIdToViewTargetMap::iterator it = | 297 ViewIdToViewTargetMap::iterator it = |
| 318 view_id_to_view_target_map_.find(view->id()); | 298 view_id_to_view_target_map_.find(view->id()); |
| 319 if (it == view_id_to_view_target_map_.end()) { | 299 if (it == view_id_to_view_target_map_.end()) { |
| 320 // Because we unregister in OnViewDestroying() we can still get a subsequent | 300 // Because we unregister in OnViewDestroying() we can still get a subsequent |
| 321 // OnTreeChanged for the same view. Ignore this one. | 301 // OnTreeChanged for the same view. Ignore this one. |
| 322 return; | 302 return; |
| 323 } | 303 } |
| 324 view->RemoveObserver(this); | 304 view->RemoveObserver(this); |
| 325 DCHECK(it != view_id_to_view_target_map_.end()); | 305 DCHECK(it != view_id_to_view_target_map_.end()); |
| 326 // Delete before we remove from map as destruction may want to look up view | 306 |
| 327 // for window. | |
| 328 delete it->second; | |
| 329 view_id_to_view_target_map_.erase(it); | 307 view_id_to_view_target_map_.erase(it); |
| 330 } | 308 } |
| 331 | 309 |
| 332 void WindowManagerApp::DispatchInputEventToView(View* view, EventPtr event) { | 310 void WindowManagerApp::DispatchInputEventToView(View* view, EventPtr event) { |
| 333 window_manager_client_->DispatchInputEventToView(view->id(), event.Pass()); | 311 window_manager_client_->DispatchInputEventToView(view->id(), event.Pass()); |
| 334 } | 312 } |
| 335 | 313 |
| 336 void WindowManagerApp::SetViewportSize(const gfx::Size& size) { | 314 void WindowManagerApp::SetViewportSize(const gfx::Size& size) { |
| 337 window_manager_client_->SetViewportSize(Size::From(size)); | 315 window_manager_client_->SetViewportSize(Size::From(size)); |
| 338 } | 316 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 358 view_manager_app->ConnectToService(&window_manager_client_); | 336 view_manager_app->ConnectToService(&window_manager_client_); |
| 359 } | 337 } |
| 360 | 338 |
| 361 void WindowManagerApp::Create(ApplicationConnection* connection, | 339 void WindowManagerApp::Create(ApplicationConnection* connection, |
| 362 InterfaceRequest<WindowManagerInternal> request) { | 340 InterfaceRequest<WindowManagerInternal> request) { |
| 363 WindowManagerInternalImpl* impl = new WindowManagerInternalImpl(this); | 341 WindowManagerInternalImpl* impl = new WindowManagerInternalImpl(this); |
| 364 BindToRequest(impl, &request); | 342 BindToRequest(impl, &request); |
| 365 } | 343 } |
| 366 | 344 |
| 367 } // namespace mojo | 345 } // namespace mojo |
| OLD | NEW |