| 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/aura/aura_init.h" | 9 #include "mojo/aura/aura_init.h" |
| 10 #include "mojo/converters/input_events/input_events_type_converters.h" | 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 //////////////////////////////////////////////////////////////////////////////// | 77 //////////////////////////////////////////////////////////////////////////////// |
| 78 // WindowManagerApp, public: | 78 // WindowManagerApp, public: |
| 79 | 79 |
| 80 WindowManagerApp::WindowManagerApp( | 80 WindowManagerApp::WindowManagerApp( |
| 81 ViewManagerDelegate* view_manager_delegate, | 81 ViewManagerDelegate* view_manager_delegate, |
| 82 WindowManagerDelegate* window_manager_delegate) | 82 WindowManagerDelegate* window_manager_delegate) |
| 83 : shell_(nullptr), | 83 : shell_(nullptr), |
| 84 window_manager_service2_factory_(this), |
| 84 window_manager_service_factory_(this), | 85 window_manager_service_factory_(this), |
| 85 wrapped_view_manager_delegate_(view_manager_delegate), | 86 wrapped_view_manager_delegate_(view_manager_delegate), |
| 86 wrapped_window_manager_delegate_(window_manager_delegate), | 87 window_manager_delegate_(window_manager_delegate), |
| 87 view_manager_(NULL), | 88 view_manager_(NULL), |
| 88 root_(NULL), | 89 root_(NULL), |
| 89 dummy_delegate_(new DummyDelegate) { | 90 dummy_delegate_(new DummyDelegate), |
| 91 window_manager_client_(nullptr) { |
| 90 } | 92 } |
| 91 | 93 |
| 92 WindowManagerApp::~WindowManagerApp() {} | 94 WindowManagerApp::~WindowManagerApp() {} |
| 93 | 95 |
| 94 // static | 96 // static |
| 95 View* WindowManagerApp::GetViewForWindow(aura::Window* window) { | 97 View* WindowManagerApp::GetViewForWindow(aura::Window* window) { |
| 96 return window->GetProperty(kViewKey); | 98 return window->GetProperty(kViewKey); |
| 97 } | 99 } |
| 98 | 100 |
| 99 aura::Window* WindowManagerApp::GetWindowForViewId(Id view) { | 101 aura::Window* WindowManagerApp::GetWindowForViewId(Id view) { |
| 100 ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view); | 102 ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view); |
| 101 return it != view_id_to_window_map_.end() ? it->second : NULL; | 103 return it != view_id_to_window_map_.end() ? it->second : NULL; |
| 102 } | 104 } |
| 103 | 105 |
| 104 void WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) { | 106 void WindowManagerApp::AddConnection(WindowManagerService2Impl* connection) { |
| 105 DCHECK(connections_.find(connection) == connections_.end()); | 107 DCHECK(connections_.find(connection) == connections_.end()); |
| 106 connections_.insert(connection); | 108 connections_.insert(connection); |
| 107 } | 109 } |
| 108 | 110 |
| 109 void WindowManagerApp::RemoveConnection(WindowManagerServiceImpl* connection) { | 111 void WindowManagerApp::RemoveConnection(WindowManagerService2Impl* connection) { |
| 110 DCHECK(connections_.find(connection) != connections_.end()); | 112 DCHECK(connections_.find(connection) != connections_.end()); |
| 111 connections_.erase(connection); | 113 connections_.erase(connection); |
| 112 } | 114 } |
| 113 | 115 |
| 114 void WindowManagerApp::SetCapture(Id view) { | 116 void WindowManagerApp::SetCapture(Id view) { |
| 115 capture_client_->capture_client()->SetCapture(GetWindowForViewId(view)); | 117 capture_client_->capture_client()->SetCapture(GetWindowForViewId(view)); |
| 116 // TODO(beng): notify connected clients that capture has changed, probably | 118 // TODO(beng): notify connected clients that capture has changed, probably |
| 117 // by implementing some capture-client observer. | 119 // by implementing some capture-client observer. |
| 118 } | 120 } |
| 119 | 121 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 150 | 152 |
| 151 void WindowManagerApp::Initialize(ApplicationImpl* impl) { | 153 void WindowManagerApp::Initialize(ApplicationImpl* impl) { |
| 152 shell_ = impl->shell(); | 154 shell_ = impl->shell(); |
| 153 aura_init_.reset(new AuraInit); | 155 aura_init_.reset(new AuraInit); |
| 154 view_manager_client_factory_.reset( | 156 view_manager_client_factory_.reset( |
| 155 new ViewManagerClientFactory(shell_, this)); | 157 new ViewManagerClientFactory(shell_, this)); |
| 156 } | 158 } |
| 157 | 159 |
| 158 bool WindowManagerApp::ConfigureIncomingConnection( | 160 bool WindowManagerApp::ConfigureIncomingConnection( |
| 159 ApplicationConnection* connection) { | 161 ApplicationConnection* connection) { |
| 162 connection->AddService(&window_manager_service2_factory_); |
| 163 connection->AddService(view_manager_client_factory_.get()); |
| 160 connection->AddService(&window_manager_service_factory_); | 164 connection->AddService(&window_manager_service_factory_); |
| 161 connection->AddService(view_manager_client_factory_.get()); | |
| 162 return true; | 165 return true; |
| 163 } | 166 } |
| 164 | 167 |
| 165 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
| 166 // WindowManagerApp, ViewManagerDelegate implementation: | 169 // WindowManagerApp, ViewManagerDelegate implementation: |
| 167 | 170 |
| 168 void WindowManagerApp::OnEmbed(ViewManager* view_manager, | 171 void WindowManagerApp::OnEmbed(ViewManager* view_manager, |
| 169 View* root, | 172 View* root, |
| 170 ServiceProviderImpl* exported_services, | 173 ServiceProviderImpl* exported_services, |
| 171 scoped_ptr<ServiceProvider> imported_services) { | 174 scoped_ptr<ServiceProvider> imported_services) { |
| 172 DCHECK(!view_manager_ && !root_); | 175 DCHECK(!view_manager_ && !root_); |
| 173 view_manager_ = view_manager; | 176 view_manager_ = view_manager; |
| 174 view_manager_->SetWindowManagerDelegate(this); | |
| 175 root_ = root; | 177 root_ = root; |
| 176 | 178 |
| 177 window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_)); | 179 window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_)); |
| 178 window_tree_host_->window()->SetBounds(root->bounds()); | 180 window_tree_host_->window()->SetBounds(root->bounds()); |
| 179 window_tree_host_->window()->Show(); | 181 window_tree_host_->window()->Show(); |
| 180 | 182 |
| 181 RegisterSubtree(root_, window_tree_host_->window()); | 183 RegisterSubtree(root_, window_tree_host_->window()); |
| 182 | 184 |
| 183 capture_client_.reset( | 185 capture_client_.reset( |
| 184 new wm::ScopedCaptureClient(window_tree_host_->window())); | 186 new wm::ScopedCaptureClient(window_tree_host_->window())); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 197 void WindowManagerApp::OnViewManagerDisconnected( | 199 void WindowManagerApp::OnViewManagerDisconnected( |
| 198 ViewManager* view_manager) { | 200 ViewManager* view_manager) { |
| 199 DCHECK_EQ(view_manager_, view_manager); | 201 DCHECK_EQ(view_manager_, view_manager); |
| 200 if (wrapped_view_manager_delegate_) | 202 if (wrapped_view_manager_delegate_) |
| 201 wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager); | 203 wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager); |
| 202 view_manager_ = NULL; | 204 view_manager_ = NULL; |
| 203 base::MessageLoop::current()->Quit(); | 205 base::MessageLoop::current()->Quit(); |
| 204 } | 206 } |
| 205 | 207 |
| 206 //////////////////////////////////////////////////////////////////////////////// | 208 //////////////////////////////////////////////////////////////////////////////// |
| 207 // WindowManagerApp, WindowManagerDelegate implementation: | |
| 208 | |
| 209 void WindowManagerApp::Embed( | |
| 210 const String& url, | |
| 211 InterfaceRequest<ServiceProvider> service_provider) { | |
| 212 if (wrapped_window_manager_delegate_) | |
| 213 wrapped_window_manager_delegate_->Embed(url, service_provider.Pass()); | |
| 214 } | |
| 215 | |
| 216 void WindowManagerApp::DispatchEvent(EventPtr event) { | |
| 217 scoped_ptr<ui::Event> ui_event = event.To<scoped_ptr<ui::Event> >(); | |
| 218 if (ui_event) | |
| 219 window_tree_host_->SendEventToProcessor(ui_event.get()); | |
| 220 } | |
| 221 | |
| 222 //////////////////////////////////////////////////////////////////////////////// | |
| 223 // WindowManagerApp, ViewObserver implementation: | 209 // WindowManagerApp, ViewObserver implementation: |
| 224 | 210 |
| 225 void WindowManagerApp::OnTreeChanged( | 211 void WindowManagerApp::OnTreeChanged( |
| 226 const ViewObserver::TreeChangeParams& params) { | 212 const ViewObserver::TreeChangeParams& params) { |
| 227 if (params.receiver != root_) | 213 if (params.receiver != root_) |
| 228 return; | 214 return; |
| 229 DCHECK(params.old_parent || params.new_parent); | 215 DCHECK(params.old_parent || params.new_parent); |
| 230 if (!params.target) | 216 if (!params.target) |
| 231 return; | 217 return; |
| 232 | 218 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 263 const gfx::Rect& old_bounds, | 249 const gfx::Rect& old_bounds, |
| 264 const gfx::Rect& new_bounds) { | 250 const gfx::Rect& new_bounds) { |
| 265 aura::Window* window = GetWindowForViewId(view->id()); | 251 aura::Window* window = GetWindowForViewId(view->id()); |
| 266 window->SetBounds(new_bounds); | 252 window->SetBounds(new_bounds); |
| 267 } | 253 } |
| 268 | 254 |
| 269 //////////////////////////////////////////////////////////////////////////////// | 255 //////////////////////////////////////////////////////////////////////////////// |
| 270 // WindowManagerApp, ui::EventHandler implementation: | 256 // WindowManagerApp, ui::EventHandler implementation: |
| 271 | 257 |
| 272 void WindowManagerApp::OnEvent(ui::Event* event) { | 258 void WindowManagerApp::OnEvent(ui::Event* event) { |
| 273 aura::Window* window = static_cast<aura::Window*>(event->target()); | 259 if (!window_manager_client_) |
| 274 view_manager_->DispatchEvent(GetViewForWindow(window), Event::From(*event)); | 260 return; |
| 261 |
| 262 View* view = GetViewForWindow(static_cast<aura::Window*>(event->target())); |
| 263 if (!view) |
| 264 return; |
| 265 |
| 266 window_manager_client_->DispatchInputEventToView(view->id(), |
| 267 Event::From(*event)); |
| 275 } | 268 } |
| 276 | 269 |
| 277 //////////////////////////////////////////////////////////////////////////////// | 270 //////////////////////////////////////////////////////////////////////////////// |
| 278 // WindowManagerApp, aura::client::FocusChangeObserver implementation: | 271 // WindowManagerApp, aura::client::FocusChangeObserver implementation: |
| 279 | 272 |
| 280 void WindowManagerApp::OnWindowFocused(aura::Window* gained_focus, | 273 void WindowManagerApp::OnWindowFocused(aura::Window* gained_focus, |
| 281 aura::Window* lost_focus) { | 274 aura::Window* lost_focus) { |
| 282 for (Connections::const_iterator it = connections_.begin(); | 275 for (Connections::const_iterator it = connections_.begin(); |
| 283 it != connections_.end(); ++it) { | 276 it != connections_.end(); ++it) { |
| 284 (*it)->NotifyViewFocused(GetIdForWindow(gained_focus), | 277 (*it)->NotifyViewFocused(GetIdForWindow(gained_focus), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 } | 333 } |
| 341 view->RemoveObserver(this); | 334 view->RemoveObserver(this); |
| 342 DCHECK(it != view_id_to_window_map_.end()); | 335 DCHECK(it != view_id_to_window_map_.end()); |
| 343 // Delete before we remove from map as destruction may want to look up view | 336 // Delete before we remove from map as destruction may want to look up view |
| 344 // for window. | 337 // for window. |
| 345 delete it->second; | 338 delete it->second; |
| 346 view_id_to_window_map_.erase(it); | 339 view_id_to_window_map_.erase(it); |
| 347 } | 340 } |
| 348 | 341 |
| 349 } // namespace mojo | 342 } // namespace mojo |
| OLD | NEW |