| 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/public/cpp/view_manager/lib/view_manager_client_impl.h" | 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
| 12 #include "mojo/public/cpp/application/connect.h" | 12 #include "mojo/public/cpp/application/connect.h" |
| 13 #include "mojo/public/cpp/application/service_provider_impl.h" | 13 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 14 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 14 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| 15 #include "mojo/public/interfaces/application/shell.mojom.h" | 15 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 16 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 16 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
| 17 #include "mojo/services/public/cpp/view_manager/util.h" | 17 #include "mojo/services/public/cpp/view_manager/util.h" |
| 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 20 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | |
| 21 | 20 |
| 22 namespace mojo { | 21 namespace mojo { |
| 23 | 22 |
| 24 Id MakeTransportId(ConnectionSpecificId connection_id, | 23 Id MakeTransportId(ConnectionSpecificId connection_id, |
| 25 ConnectionSpecificId local_id) { | 24 ConnectionSpecificId local_id) { |
| 26 return (connection_id << 16) | local_id; | 25 return (connection_id << 16) | local_id; |
| 27 } | 26 } |
| 28 | 27 |
| 29 // Helper called to construct a local view object from transport data. | 28 // Helper called to construct a local view object from transport data. |
| 30 View* AddViewToViewManager(ViewManagerClientImpl* client, | 29 View* AddViewToViewManager(ViewManagerClientImpl* client, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 delete this; | 85 delete this; |
| 87 } | 86 } |
| 88 | 87 |
| 89 View* root_; | 88 View* root_; |
| 90 | 89 |
| 91 DISALLOW_COPY_AND_ASSIGN(RootObserver); | 90 DISALLOW_COPY_AND_ASSIGN(RootObserver); |
| 92 }; | 91 }; |
| 93 | 92 |
| 94 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, | 93 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, |
| 95 Shell* shell) | 94 Shell* shell) |
| 96 : connected_(false), | 95 : connected_(false), connection_id_(0), next_id_(1), delegate_(delegate) { |
| 97 connection_id_(0), | |
| 98 next_id_(1), | |
| 99 delegate_(delegate), | |
| 100 window_manager_delegate_(NULL) { | |
| 101 // TODO(beng): Come up with a better way of establishing a configuration for | 96 // TODO(beng): Come up with a better way of establishing a configuration for |
| 102 // what the active window manager is. | 97 // what the active window manager is. |
| 103 std::string window_manager_url = "mojo:mojo_window_manager"; | 98 std::string window_manager_url = "mojo:mojo_window_manager"; |
| 104 if (base::CommandLine::ForCurrentProcess()->HasSwitch("window-manager")) { | 99 if (base::CommandLine::ForCurrentProcess()->HasSwitch("window-manager")) { |
| 105 window_manager_url = | 100 window_manager_url = |
| 106 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 101 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 107 "window-manager"); | 102 "window-manager"); |
| 108 } | 103 } |
| 109 InterfacePtr<ServiceProvider> sp; | 104 InterfacePtr<ServiceProvider> sp; |
| 110 shell->ConnectToApplication(window_manager_url, GetProxy(&sp)); | 105 shell->ConnectToApplication(window_manager_url, GetProxy(&sp)); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 208 |
| 214 void ViewManagerClientImpl::RemoveView(Id view_id) { | 209 void ViewManagerClientImpl::RemoveView(Id view_id) { |
| 215 IdToViewMap::iterator it = views_.find(view_id); | 210 IdToViewMap::iterator it = views_.find(view_id); |
| 216 if (it != views_.end()) | 211 if (it != views_.end()) |
| 217 views_.erase(it); | 212 views_.erase(it); |
| 218 } | 213 } |
| 219 | 214 |
| 220 //////////////////////////////////////////////////////////////////////////////// | 215 //////////////////////////////////////////////////////////////////////////////// |
| 221 // ViewManagerClientImpl, ViewManager implementation: | 216 // ViewManagerClientImpl, ViewManager implementation: |
| 222 | 217 |
| 223 void ViewManagerClientImpl::SetWindowManagerDelegate( | |
| 224 WindowManagerDelegate* window_manager_delegate) { | |
| 225 CHECK(NULL != GetViewById(1)); | |
| 226 CHECK(!window_manager_delegate_); | |
| 227 window_manager_delegate_ = window_manager_delegate; | |
| 228 } | |
| 229 | |
| 230 void ViewManagerClientImpl::DispatchEvent(View* target, EventPtr event) { | |
| 231 CHECK(window_manager_delegate_); | |
| 232 service_->DispatchOnViewInputEvent(target->id(), event.Pass()); | |
| 233 } | |
| 234 | |
| 235 const std::string& ViewManagerClientImpl::GetEmbedderURL() const { | 218 const std::string& ViewManagerClientImpl::GetEmbedderURL() const { |
| 236 return creator_url_; | 219 return creator_url_; |
| 237 } | 220 } |
| 238 | 221 |
| 239 const std::vector<View*>& ViewManagerClientImpl::GetRoots() const { | 222 const std::vector<View*>& ViewManagerClientImpl::GetRoots() const { |
| 240 return roots_; | 223 return roots_; |
| 241 } | 224 } |
| 242 | 225 |
| 243 View* ViewManagerClientImpl::GetViewById(Id id) { | 226 View* ViewManagerClientImpl::GetViewById(Id id) { |
| 244 IdToViewMap::const_iterator it = views_.find(id); | 227 IdToViewMap::const_iterator it = views_.find(id); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 const Callback<void()>& ack_callback) { | 329 const Callback<void()>& ack_callback) { |
| 347 View* view = GetViewById(view_id); | 330 View* view = GetViewById(view_id); |
| 348 if (view) { | 331 if (view) { |
| 349 FOR_EACH_OBSERVER(ViewObserver, | 332 FOR_EACH_OBSERVER(ViewObserver, |
| 350 *ViewPrivate(view).observers(), | 333 *ViewPrivate(view).observers(), |
| 351 OnViewInputEvent(view, event)); | 334 OnViewInputEvent(view, event)); |
| 352 } | 335 } |
| 353 ack_callback.Run(); | 336 ack_callback.Run(); |
| 354 } | 337 } |
| 355 | 338 |
| 356 void ViewManagerClientImpl::Embed( | |
| 357 const String& url, | |
| 358 InterfaceRequest<ServiceProvider> service_provider) { | |
| 359 if (window_manager_delegate_) | |
| 360 window_manager_delegate_->Embed(url, service_provider.Pass()); | |
| 361 } | |
| 362 | |
| 363 void ViewManagerClientImpl::DispatchOnViewInputEvent(EventPtr event) { | |
| 364 if (window_manager_delegate_) | |
| 365 window_manager_delegate_->DispatchEvent(event.Pass()); | |
| 366 } | |
| 367 | |
| 368 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
| 369 // ViewManagerClientImpl, WindowManagerClient2 implementation: | 340 // ViewManagerClientImpl, WindowManagerClient2 implementation: |
| 370 | 341 |
| 371 void ViewManagerClientImpl::OnWindowManagerReady() {} | 342 void ViewManagerClientImpl::OnWindowManagerReady() {} |
| 372 | 343 |
| 373 void ViewManagerClientImpl::OnCaptureChanged(Id old_capture_view_id, | 344 void ViewManagerClientImpl::OnCaptureChanged(Id old_capture_view_id, |
| 374 Id new_capture_view_id) {} | 345 Id new_capture_view_id) {} |
| 375 | 346 |
| 376 void ViewManagerClientImpl::OnFocusChanged(Id old_focused_view_id, | 347 void ViewManagerClientImpl::OnFocusChanged(Id old_focused_view_id, |
| 377 Id new_focused_view_id) { | 348 Id new_focused_view_id) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 base::Unretained(this)); | 387 base::Unretained(this)); |
| 417 } | 388 } |
| 418 | 389 |
| 419 base::Callback<void(ErrorCode)> | 390 base::Callback<void(ErrorCode)> |
| 420 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { | 391 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { |
| 421 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, | 392 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, |
| 422 base::Unretained(this)); | 393 base::Unretained(this)); |
| 423 } | 394 } |
| 424 | 395 |
| 425 } // namespace mojo | 396 } // namespace mojo |
| OLD | NEW |