| 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/view_manager/public/cpp/lib/view_manager_client_impl.h" | 5 #include "view_manager/public/cpp/lib/view_manager_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
| 11 #include "mojo/public/cpp/application/connect.h" | 11 #include "mojo/public/cpp/application/connect.h" |
| 12 #include "mojo/public/cpp/application/service_provider_impl.h" | 12 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 13 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 13 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| 14 #include "mojo/public/interfaces/application/shell.mojom.h" | 14 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 15 #include "mojo/services/view_manager/public/cpp/lib/view_private.h" | 15 #include "view_manager/public/cpp/lib/view_private.h" |
| 16 #include "mojo/services/view_manager/public/cpp/util.h" | 16 #include "view_manager/public/cpp/util.h" |
| 17 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h" | 17 #include "view_manager/public/cpp/view_manager_delegate.h" |
| 18 #include "mojo/services/view_manager/public/cpp/view_observer.h" | 18 #include "view_manager/public/cpp/view_observer.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 | 21 |
| 22 Id MakeTransportId(ConnectionSpecificId connection_id, | 22 Id MakeTransportId(ConnectionSpecificId connection_id, |
| 23 ConnectionSpecificId local_id) { | 23 ConnectionSpecificId local_id) { |
| 24 return (connection_id << 16) | local_id; | 24 return (connection_id << 16) | local_id; |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Helper called to construct a local view object from transport data. | 27 // Helper called to construct a local view object from transport data. |
| 28 View* AddViewToViewManager(ViewManagerClientImpl* client, | 28 View* AddViewToViewManager(ViewManagerClientImpl* client, |
| 29 View* parent, | 29 View* parent, |
| 30 const ViewDataPtr& view_data) { | 30 const ViewDataPtr& view_data) { |
| 31 // We don't use the ctor that takes a ViewManager here, since it will call | 31 // We don't use the ctor that takes a ViewManager here, since it will call |
| 32 // back to the service and attempt to create a new view. | 32 // back to the service and attempt to create a new view. |
| 33 View* view = ViewPrivate::LocalCreate(); | 33 View* view = ViewPrivate::LocalCreate(); |
| 34 ViewPrivate private_view(view); | 34 ViewPrivate private_view(view); |
| 35 private_view.set_view_manager(client); | 35 private_view.set_view_manager(client); |
| 36 private_view.set_id(view_data->view_id); | 36 private_view.set_id(view_data->view_id); |
| 37 private_view.set_visible(view_data->visible); | 37 private_view.set_visible(view_data->visible); |
| 38 private_view.set_drawn(view_data->drawn); | 38 private_view.set_drawn(view_data->drawn); |
| 39 private_view.set_viewport_metrics(view_data->viewport_metrics.Pass()); |
| 39 private_view.set_properties( | 40 private_view.set_properties( |
| 40 view_data->properties.To<std::map<std::string, std::vector<uint8_t>>>()); | 41 view_data->properties.To<std::map<std::string, std::vector<uint8_t>>>()); |
| 41 client->AddView(view); | 42 client->AddView(view); |
| 42 private_view.LocalSetBounds(Rect(), *view_data->bounds); | 43 private_view.LocalSetBounds(Rect(), *view_data->bounds); |
| 43 if (parent) | 44 if (parent) |
| 44 ViewPrivate(parent).LocalAddChild(view); | 45 ViewPrivate(parent).LocalAddChild(view); |
| 45 return view; | 46 return view; |
| 46 } | 47 } |
| 47 | 48 |
| 48 View* BuildViewTree(ViewManagerClientImpl* client, | 49 View* BuildViewTree(ViewManagerClientImpl* client, |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 connection_id_ = connection_id; | 268 connection_id_ = connection_id; |
| 268 creator_url_ = String::From(creator_url); | 269 creator_url_ = String::From(creator_url); |
| 269 | 270 |
| 270 DCHECK(!root_); | 271 DCHECK(!root_); |
| 271 root_ = AddViewToViewManager(this, nullptr, root_data); | 272 root_ = AddViewToViewManager(this, nullptr, root_data); |
| 272 root_->AddObserver(new RootObserver(root_)); | 273 root_->AddObserver(new RootObserver(root_)); |
| 273 | 274 |
| 274 ServiceProviderImpl* exported_services = nullptr; | 275 ServiceProviderImpl* exported_services = nullptr; |
| 275 scoped_ptr<ServiceProvider> remote; | 276 scoped_ptr<ServiceProvider> remote; |
| 276 | 277 |
| 277 if (parent_services.is_pending()) { | 278 // BindToRequest() binds the lifetime of |exported_services| to the pipe. |
| 278 // BindToRequest() binds the lifetime of |exported_services| to the pipe. | 279 exported_services = new ServiceProviderImpl; |
| 279 exported_services = new ServiceProviderImpl; | 280 BindToRequest(exported_services, &parent_services); |
| 280 BindToRequest(exported_services, &parent_services); | 281 remote.reset(exported_services->CreateRemoteServiceProvider()); |
| 281 remote.reset(exported_services->CreateRemoteServiceProvider()); | 282 |
| 282 } | |
| 283 window_manager_.Bind(window_manager_pipe.Pass()); | 283 window_manager_.Bind(window_manager_pipe.Pass()); |
| 284 window_manager_.set_client(this); | 284 window_manager_.set_client(this); |
| 285 // base::Unretained() is safe here as |window_manager_| is bound to our | 285 // base::Unretained() is safe here as |window_manager_| is bound to our |
| 286 // lifetime. | 286 // lifetime. |
| 287 window_manager_->GetFocusedAndActiveViews( | 287 window_manager_->GetFocusedAndActiveViews( |
| 288 base::Bind(&ViewManagerClientImpl::OnGotFocusedAndActiveViews, | 288 base::Bind(&ViewManagerClientImpl::OnGotFocusedAndActiveViews, |
| 289 base::Unretained(this))); | 289 base::Unretained(this))); |
| 290 delegate_->OnEmbed(root_, exported_services, remote.Pass()); | 290 delegate_->OnEmbed(root_, exported_services, remote.Pass()); |
| 291 } | 291 } |
| 292 | 292 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 uint32 active_view_id) { | 477 uint32 active_view_id) { |
| 478 if (GetViewById(focused_view_id) != focused_view_) | 478 if (GetViewById(focused_view_id) != focused_view_) |
| 479 OnFocusChanged(focused_view_ ? focused_view_->id() : 0, focused_view_id); | 479 OnFocusChanged(focused_view_ ? focused_view_->id() : 0, focused_view_id); |
| 480 if (GetViewById(active_view_id) != activated_view_) { | 480 if (GetViewById(active_view_id) != activated_view_) { |
| 481 OnActiveWindowChanged(activated_view_ ? activated_view_->id() : 0, | 481 OnActiveWindowChanged(activated_view_ ? activated_view_->id() : 0, |
| 482 active_view_id); | 482 active_view_id); |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 | 485 |
| 486 } // namespace mojo | 486 } // namespace mojo |
| OLD | NEW |