| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace mojo { | 24 namespace mojo { |
| 25 | 25 |
| 26 Id MakeTransportId(ConnectionSpecificId connection_id, | 26 Id MakeTransportId(ConnectionSpecificId connection_id, |
| 27 ConnectionSpecificId local_id) { | 27 ConnectionSpecificId local_id) { |
| 28 return (connection_id << 16) | local_id; | 28 return (connection_id << 16) | local_id; |
| 29 } | 29 } |
| 30 | 30 |
| 31 // Helper called to construct a local view object from transport data. | 31 // Helper called to construct a local view object from transport data. |
| 32 View* AddViewToViewManager(ViewManagerClientImpl* client, | 32 View* AddViewToViewManager(ViewManagerClientImpl* client, |
| 33 View* parent, | 33 View* parent, |
| 34 Id view_id, | 34 const ViewDataPtr& view_data) { |
| 35 const gfx::Rect& bounds) { | |
| 36 // We don't use the ctor that takes a ViewManager here, since it will call | 35 // We don't use the ctor that takes a ViewManager here, since it will call |
| 37 // back to the service and attempt to create a new view. | 36 // back to the service and attempt to create a new view. |
| 38 View* view = ViewPrivate::LocalCreate(); | 37 View* view = ViewPrivate::LocalCreate(); |
| 39 ViewPrivate private_view(view); | 38 ViewPrivate private_view(view); |
| 40 private_view.set_view_manager(client); | 39 private_view.set_view_manager(client); |
| 41 private_view.set_id(view_id); | 40 private_view.set_id(view_data->view_id); |
| 41 private_view.set_visible(view_data->visible); |
| 42 private_view.set_drawn(view_data->drawn); |
| 42 client->AddView(view); | 43 client->AddView(view); |
| 43 private_view.LocalSetBounds(gfx::Rect(), bounds); | 44 private_view.LocalSetBounds(gfx::Rect(), view_data->bounds.To<gfx::Rect>()); |
| 44 if (parent) | 45 if (parent) |
| 45 ViewPrivate(parent).LocalAddChild(view); | 46 ViewPrivate(parent).LocalAddChild(view); |
| 46 return view; | 47 return view; |
| 47 } | 48 } |
| 48 | 49 |
| 49 View* BuildViewTree(ViewManagerClientImpl* client, | 50 View* BuildViewTree(ViewManagerClientImpl* client, |
| 50 const Array<ViewDataPtr>& views, | 51 const Array<ViewDataPtr>& views, |
| 51 View* initial_parent) { | 52 View* initial_parent) { |
| 52 std::vector<View*> parents; | 53 std::vector<View*> parents; |
| 53 View* root = NULL; | 54 View* root = NULL; |
| 54 View* last_view = NULL; | 55 View* last_view = NULL; |
| 55 if (initial_parent) | 56 if (initial_parent) |
| 56 parents.push_back(initial_parent); | 57 parents.push_back(initial_parent); |
| 57 for (size_t i = 0; i < views.size(); ++i) { | 58 for (size_t i = 0; i < views.size(); ++i) { |
| 58 if (last_view && views[i]->parent_id == last_view->id()) { | 59 if (last_view && views[i]->parent_id == last_view->id()) { |
| 59 parents.push_back(last_view); | 60 parents.push_back(last_view); |
| 60 } else if (!parents.empty()) { | 61 } else if (!parents.empty()) { |
| 61 while (parents.back()->id() != views[i]->parent_id) | 62 while (parents.back()->id() != views[i]->parent_id) |
| 62 parents.pop_back(); | 63 parents.pop_back(); |
| 63 } | 64 } |
| 64 View* view = AddViewToViewManager( | 65 View* view = AddViewToViewManager( |
| 65 client, | 66 client, !parents.empty() ? parents.back() : NULL, views[i]); |
| 66 !parents.empty() ? parents.back() : NULL, | |
| 67 views[i]->view_id, | |
| 68 views[i]->bounds.To<gfx::Rect>()); | |
| 69 if (!last_view) | 67 if (!last_view) |
| 70 root = view; | 68 root = view; |
| 71 last_view = view; | 69 last_view = view; |
| 72 } | 70 } |
| 73 return root; | 71 return root; |
| 74 } | 72 } |
| 75 | 73 |
| 76 // Responsible for removing a root from the ViewManager when that view is | 74 // Responsible for removing a root from the ViewManager when that view is |
| 77 // destroyed. | 75 // destroyed. |
| 78 class RootObserver : public ViewObserver { | 76 class RootObserver : public ViewObserver { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 connected_ = true; | 267 connected_ = true; |
| 270 connection_id_ = connection_id; | 268 connection_id_ = connection_id; |
| 271 creator_url_ = String::From(creator_url); | 269 creator_url_ = String::From(creator_url); |
| 272 } else { | 270 } else { |
| 273 DCHECK_EQ(connection_id_, connection_id); | 271 DCHECK_EQ(connection_id_, connection_id); |
| 274 DCHECK_EQ(creator_url_, creator_url); | 272 DCHECK_EQ(creator_url_, creator_url); |
| 275 } | 273 } |
| 276 | 274 |
| 277 // A new root must not already exist as a root or be contained by an existing | 275 // A new root must not already exist as a root or be contained by an existing |
| 278 // hierarchy visible to this view manager. | 276 // hierarchy visible to this view manager. |
| 279 View* root = AddViewToViewManager(this, NULL, root_data->view_id, | 277 View* root = AddViewToViewManager(this, NULL, root_data); |
| 280 root_data->bounds.To<gfx::Rect>()); | |
| 281 roots_.push_back(root); | 278 roots_.push_back(root); |
| 282 root->AddObserver(new RootObserver(root)); | 279 root->AddObserver(new RootObserver(root)); |
| 283 | 280 |
| 284 // BindToRequest() binds the lifetime of |exported_services| to the pipe. | 281 // BindToRequest() binds the lifetime of |exported_services| to the pipe. |
| 285 ServiceProviderImpl* exported_services = new ServiceProviderImpl; | 282 ServiceProviderImpl* exported_services = new ServiceProviderImpl; |
| 286 BindToRequest(exported_services, &service_provider); | 283 BindToRequest(exported_services, &service_provider); |
| 287 scoped_ptr<ServiceProvider> remote( | 284 scoped_ptr<ServiceProvider> remote( |
| 288 exported_services->CreateRemoteServiceProvider()); | 285 exported_services->CreateRemoteServiceProvider()); |
| 289 delegate_->OnEmbed(this, root, exported_services, remote.Pass()); | 286 delegate_->OnEmbed(this, root, exported_services, remote.Pass()); |
| 290 } | 287 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 ViewPrivate(view).LocalReorder(relative_view, direction); | 322 ViewPrivate(view).LocalReorder(relative_view, direction); |
| 326 } | 323 } |
| 327 | 324 |
| 328 void ViewManagerClientImpl::OnViewDeleted(Id view_id) { | 325 void ViewManagerClientImpl::OnViewDeleted(Id view_id) { |
| 329 View* view = GetViewById(view_id); | 326 View* view = GetViewById(view_id); |
| 330 if (view) | 327 if (view) |
| 331 ViewPrivate(view).LocalDestroy(); | 328 ViewPrivate(view).LocalDestroy(); |
| 332 } | 329 } |
| 333 | 330 |
| 334 void ViewManagerClientImpl::OnViewVisibilityChanged(Id view_id, bool visible) { | 331 void ViewManagerClientImpl::OnViewVisibilityChanged(Id view_id, bool visible) { |
| 335 // TODO(sky): implement me. | 332 // TODO(sky): there is a race condition here. If this client and another |
| 336 NOTIMPLEMENTED(); | 333 // client change the visibility at the same time the wrong value may be set. |
| 334 // Deal with this some how. |
| 335 View* view = GetViewById(view_id); |
| 336 if (view) |
| 337 view->SetVisible(visible); |
| 337 } | 338 } |
| 338 | 339 |
| 339 void ViewManagerClientImpl::OnViewDrawnStateChanged(Id view_id, bool drawn) { | 340 void ViewManagerClientImpl::OnViewDrawnStateChanged(Id view_id, bool drawn) { |
| 340 // TODO(sky): implement me. | 341 View* view = GetViewById(view_id); |
| 341 NOTIMPLEMENTED(); | 342 if (view) |
| 343 ViewPrivate(view).LocalSetDrawn(drawn); |
| 342 } | 344 } |
| 343 | 345 |
| 344 void ViewManagerClientImpl::OnViewInputEvent( | 346 void ViewManagerClientImpl::OnViewInputEvent( |
| 345 Id view_id, | 347 Id view_id, |
| 346 EventPtr event, | 348 EventPtr event, |
| 347 const Callback<void()>& ack_callback) { | 349 const Callback<void()>& ack_callback) { |
| 348 View* view = GetViewById(view_id); | 350 View* view = GetViewById(view_id); |
| 349 if (view) { | 351 if (view) { |
| 350 FOR_EACH_OBSERVER(ViewObserver, | 352 FOR_EACH_OBSERVER(ViewObserver, |
| 351 *ViewPrivate(view).observers(), | 353 *ViewPrivate(view).observers(), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 base::Unretained(this)); | 419 base::Unretained(this)); |
| 418 } | 420 } |
| 419 | 421 |
| 420 base::Callback<void(ErrorCode)> | 422 base::Callback<void(ErrorCode)> |
| 421 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { | 423 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { |
| 422 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, | 424 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, |
| 423 base::Unretained(this)); | 425 base::Unretained(this)); |
| 424 } | 426 } |
| 425 | 427 |
| 426 } // namespace mojo | 428 } // namespace mojo |
| OLD | NEW |