| 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 "components/mus/public/cpp/lib/view_tree_client_impl.h" | 5 #include "components/mus/public/cpp/lib/view_tree_client_impl.h" |
| 6 | 6 |
| 7 #include "components/mus/public/cpp/lib/view_private.h" | 7 #include "components/mus/public/cpp/lib/view_private.h" |
| 8 #include "components/mus/public/cpp/util.h" | 8 #include "components/mus/public/cpp/util.h" |
| 9 #include "components/mus/public/cpp/view_observer.h" | 9 #include "components/mus/public/cpp/view_observer.h" |
| 10 #include "components/mus/public/cpp/view_tree_connection.h" | 10 #include "components/mus/public/cpp/view_tree_connection.h" |
| 11 #include "components/mus/public/cpp/view_tree_delegate.h" | 11 #include "components/mus/public/cpp/view_tree_delegate.h" |
| 12 #include "mojo/application/public/cpp/application_impl.h" | 12 #include "mojo/application/public/cpp/application_impl.h" |
| 13 #include "mojo/application/public/cpp/connect.h" | 13 #include "mojo/application/public/cpp/connect.h" |
| 14 #include "mojo/application/public/cpp/service_provider_impl.h" | 14 #include "mojo/application/public/cpp/service_provider_impl.h" |
| 15 #include "mojo/application/public/interfaces/service_provider.mojom.h" | 15 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mus { |
| 18 | 18 |
| 19 Id MakeTransportId(ConnectionSpecificId connection_id, | 19 Id MakeTransportId(ConnectionSpecificId connection_id, |
| 20 ConnectionSpecificId local_id) { | 20 ConnectionSpecificId local_id) { |
| 21 return (connection_id << 16) | local_id; | 21 return (connection_id << 16) | local_id; |
| 22 } | 22 } |
| 23 | 23 |
| 24 // Helper called to construct a local view object from transport data. | 24 // Helper called to construct a local view object from transport data. |
| 25 View* AddViewToConnection(ViewTreeClientImpl* client, | 25 View* AddViewToConnection(ViewTreeClientImpl* client, |
| 26 View* parent, | 26 View* parent, |
| 27 const ViewDataPtr& view_data) { | 27 const mojo::ViewDataPtr& view_data) { |
| 28 // We don't use the cto that takes a ViewTreeConnection here, since it will | 28 // We don't use the cto that takes a ViewTreeConnection here, since it will |
| 29 // call back to the service and attempt to create a new view. | 29 // call back to the service and attempt to create a new view. |
| 30 View* view = ViewPrivate::LocalCreate(); | 30 View* view = ViewPrivate::LocalCreate(); |
| 31 ViewPrivate private_view(view); | 31 ViewPrivate private_view(view); |
| 32 private_view.set_connection(client); | 32 private_view.set_connection(client); |
| 33 private_view.set_id(view_data->view_id); | 33 private_view.set_id(view_data->view_id); |
| 34 private_view.set_visible(view_data->visible); | 34 private_view.set_visible(view_data->visible); |
| 35 private_view.set_drawn(view_data->drawn); | 35 private_view.set_drawn(view_data->drawn); |
| 36 private_view.LocalSetViewportMetrics(ViewportMetrics(), | 36 private_view.LocalSetViewportMetrics(mojo::ViewportMetrics(), |
| 37 *view_data->viewport_metrics); | 37 *view_data->viewport_metrics); |
| 38 private_view.set_properties( | 38 private_view.set_properties( |
| 39 view_data->properties.To<std::map<std::string, std::vector<uint8_t>>>()); | 39 view_data->properties.To<std::map<std::string, std::vector<uint8_t>>>()); |
| 40 client->AddView(view); | 40 client->AddView(view); |
| 41 private_view.LocalSetBounds(Rect(), *view_data->bounds); | 41 private_view.LocalSetBounds(mojo::Rect(), *view_data->bounds); |
| 42 if (parent) | 42 if (parent) |
| 43 ViewPrivate(parent).LocalAddChild(view); | 43 ViewPrivate(parent).LocalAddChild(view); |
| 44 return view; | 44 return view; |
| 45 } | 45 } |
| 46 | 46 |
| 47 View* BuildViewTree(ViewTreeClientImpl* client, | 47 View* BuildViewTree(ViewTreeClientImpl* client, |
| 48 const Array<ViewDataPtr>& views, | 48 const mojo::Array<mojo::ViewDataPtr>& views, |
| 49 View* initial_parent) { | 49 View* initial_parent) { |
| 50 std::vector<View*> parents; | 50 std::vector<View*> parents; |
| 51 View* root = NULL; | 51 View* root = NULL; |
| 52 View* last_view = NULL; | 52 View* last_view = NULL; |
| 53 if (initial_parent) | 53 if (initial_parent) |
| 54 parents.push_back(initial_parent); | 54 parents.push_back(initial_parent); |
| 55 for (size_t i = 0; i < views.size(); ++i) { | 55 for (size_t i = 0; i < views.size(); ++i) { |
| 56 if (last_view && views[i]->parent_id == last_view->id()) { | 56 if (last_view && views[i]->parent_id == last_view->id()) { |
| 57 parents.push_back(last_view); | 57 parents.push_back(last_view); |
| 58 } else if (!parents.empty()) { | 58 } else if (!parents.empty()) { |
| 59 while (parents.back()->id() != views[i]->parent_id) | 59 while (parents.back()->id() != views[i]->parent_id) |
| 60 parents.pop_back(); | 60 parents.pop_back(); |
| 61 } | 61 } |
| 62 View* view = AddViewToConnection( | 62 View* view = AddViewToConnection( |
| 63 client, !parents.empty() ? parents.back() : NULL, views[i]); | 63 client, !parents.empty() ? parents.back() : NULL, views[i]); |
| 64 if (!last_view) | 64 if (!last_view) |
| 65 root = view; | 65 root = view; |
| 66 last_view = view; | 66 last_view = view; |
| 67 } | 67 } |
| 68 return root; | 68 return root; |
| 69 } | 69 } |
| 70 | 70 |
| 71 ViewTreeConnection* ViewTreeConnection::Create( | 71 ViewTreeConnection* ViewTreeConnection::Create( |
| 72 ViewTreeDelegate* delegate, | 72 ViewTreeDelegate* delegate, |
| 73 InterfaceRequest<ViewTreeClient> request) { | 73 mojo::InterfaceRequest<mojo::ViewTreeClient> request) { |
| 74 return new ViewTreeClientImpl(delegate, request.Pass()); | 74 return new ViewTreeClientImpl(delegate, request.Pass()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 ViewTreeClientImpl::ViewTreeClientImpl(ViewTreeDelegate* delegate, | 77 ViewTreeClientImpl::ViewTreeClientImpl( |
| 78 InterfaceRequest<ViewTreeClient> request) | 78 ViewTreeDelegate* delegate, |
| 79 mojo::InterfaceRequest<mojo::ViewTreeClient> request) |
| 79 : connection_id_(0), | 80 : connection_id_(0), |
| 80 next_id_(1), | 81 next_id_(1), |
| 81 delegate_(delegate), | 82 delegate_(delegate), |
| 82 root_(nullptr), | 83 root_(nullptr), |
| 83 capture_view_(nullptr), | 84 capture_view_(nullptr), |
| 84 focused_view_(nullptr), | 85 focused_view_(nullptr), |
| 85 activated_view_(nullptr), | 86 activated_view_(nullptr), |
| 86 binding_(this, request.Pass()), | 87 binding_(this, request.Pass()), |
| 87 is_embed_root_(false), | 88 is_embed_root_(false), |
| 88 in_destructor_(false) {} | 89 in_destructor_(false) {} |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 tree_->AddView(parent_id, child_id, ActionCompletedCallback()); | 122 tree_->AddView(parent_id, child_id, ActionCompletedCallback()); |
| 122 } | 123 } |
| 123 | 124 |
| 124 void ViewTreeClientImpl::RemoveChild(Id child_id, Id parent_id) { | 125 void ViewTreeClientImpl::RemoveChild(Id child_id, Id parent_id) { |
| 125 DCHECK(tree_); | 126 DCHECK(tree_); |
| 126 tree_->RemoveViewFromParent(child_id, ActionCompletedCallback()); | 127 tree_->RemoveViewFromParent(child_id, ActionCompletedCallback()); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void ViewTreeClientImpl::Reorder(Id view_id, | 130 void ViewTreeClientImpl::Reorder(Id view_id, |
| 130 Id relative_view_id, | 131 Id relative_view_id, |
| 131 OrderDirection direction) { | 132 mojo::OrderDirection direction) { |
| 132 DCHECK(tree_); | 133 DCHECK(tree_); |
| 133 tree_->ReorderView(view_id, relative_view_id, direction, | 134 tree_->ReorderView(view_id, relative_view_id, direction, |
| 134 ActionCompletedCallback()); | 135 ActionCompletedCallback()); |
| 135 } | 136 } |
| 136 | 137 |
| 137 bool ViewTreeClientImpl::OwnsView(Id id) const { | 138 bool ViewTreeClientImpl::OwnsView(Id id) const { |
| 138 return HiWord(id) == connection_id_; | 139 return HiWord(id) == connection_id_; |
| 139 } | 140 } |
| 140 | 141 |
| 141 void ViewTreeClientImpl::SetBounds(Id view_id, const Rect& bounds) { | 142 void ViewTreeClientImpl::SetBounds(Id view_id, const mojo::Rect& bounds) { |
| 142 DCHECK(tree_); | 143 DCHECK(tree_); |
| 143 tree_->SetViewBounds(view_id, bounds.Clone(), ActionCompletedCallback()); | 144 tree_->SetViewBounds(view_id, bounds.Clone(), ActionCompletedCallback()); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void ViewTreeClientImpl::SetFocus(Id view_id) { | 147 void ViewTreeClientImpl::SetFocus(Id view_id) { |
| 147 // In order for us to get here we had to have exposed a view, which implies we | 148 // In order for us to get here we had to have exposed a view, which implies we |
| 148 // got a connection. | 149 // got a connection. |
| 149 DCHECK(tree_); | 150 DCHECK(tree_); |
| 150 tree_->SetFocus(view_id); | 151 tree_->SetFocus(view_id); |
| 151 } | 152 } |
| 152 | 153 |
| 153 void ViewTreeClientImpl::SetVisible(Id view_id, bool visible) { | 154 void ViewTreeClientImpl::SetVisible(Id view_id, bool visible) { |
| 154 DCHECK(tree_); | 155 DCHECK(tree_); |
| 155 tree_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); | 156 tree_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void ViewTreeClientImpl::SetProperty(Id view_id, | 159 void ViewTreeClientImpl::SetProperty(Id view_id, |
| 159 const std::string& name, | 160 const std::string& name, |
| 160 const std::vector<uint8_t>& data) { | 161 const std::vector<uint8_t>& data) { |
| 161 DCHECK(tree_); | 162 DCHECK(tree_); |
| 162 tree_->SetViewProperty(view_id, String(name), Array<uint8_t>::From(data), | 163 tree_->SetViewProperty(view_id, mojo::String(name), |
| 164 mojo::Array<uint8_t>::From(data), |
| 163 ActionCompletedCallback()); | 165 ActionCompletedCallback()); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void ViewTreeClientImpl::SetViewTextInputState(Id view_id, | 168 void ViewTreeClientImpl::SetViewTextInputState(Id view_id, |
| 167 TextInputStatePtr state) { | 169 mojo::TextInputStatePtr state) { |
| 168 DCHECK(tree_); | 170 DCHECK(tree_); |
| 169 tree_->SetViewTextInputState(view_id, state.Pass()); | 171 tree_->SetViewTextInputState(view_id, state.Pass()); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void ViewTreeClientImpl::SetImeVisibility(Id view_id, | 174 void ViewTreeClientImpl::SetImeVisibility(Id view_id, |
| 173 bool visible, | 175 bool visible, |
| 174 TextInputStatePtr state) { | 176 mojo::TextInputStatePtr state) { |
| 175 DCHECK(tree_); | 177 DCHECK(tree_); |
| 176 tree_->SetImeVisibility(view_id, visible, state.Pass()); | 178 tree_->SetImeVisibility(view_id, visible, state.Pass()); |
| 177 } | 179 } |
| 178 | 180 |
| 179 void ViewTreeClientImpl::SetAccessPolicy(Id view_id, uint32_t access_policy) { | 181 void ViewTreeClientImpl::SetAccessPolicy(Id view_id, uint32_t access_policy) { |
| 180 DCHECK(tree_); | 182 DCHECK(tree_); |
| 181 tree_->SetAccessPolicy(view_id, access_policy); | 183 tree_->SetAccessPolicy(view_id, access_policy); |
| 182 } | 184 } |
| 183 | 185 |
| 184 void ViewTreeClientImpl::Embed(Id view_id, | 186 void ViewTreeClientImpl::Embed(Id view_id, |
| 185 ViewTreeClientPtr client, | 187 mojo::ViewTreeClientPtr client, |
| 186 const ViewTree::EmbedCallback& callback) { | 188 const mojo::ViewTree::EmbedCallback& callback) { |
| 187 DCHECK(tree_); | 189 DCHECK(tree_); |
| 188 tree_->Embed(view_id, client.Pass(), callback); | 190 tree_->Embed(view_id, client.Pass(), callback); |
| 189 } | 191 } |
| 190 | 192 |
| 191 void ViewTreeClientImpl::RequestSurface(Id view_id, | 193 void ViewTreeClientImpl::RequestSurface( |
| 192 InterfaceRequest<Surface> surface, | 194 Id view_id, |
| 193 SurfaceClientPtr client) { | 195 mojo::InterfaceRequest<mojo::Surface> surface, |
| 196 mojo::SurfaceClientPtr client) { |
| 194 DCHECK(tree_); | 197 DCHECK(tree_); |
| 195 tree_->RequestSurface(view_id, surface.Pass(), client.Pass()); | 198 tree_->RequestSurface(view_id, surface.Pass(), client.Pass()); |
| 196 } | 199 } |
| 197 | 200 |
| 198 void ViewTreeClientImpl::AddView(View* view) { | 201 void ViewTreeClientImpl::AddView(View* view) { |
| 199 DCHECK(views_.find(view->id()) == views_.end()); | 202 DCHECK(views_.find(view->id()) == views_.end()); |
| 200 views_[view->id()] = view; | 203 views_[view->id()] = view; |
| 201 } | 204 } |
| 202 | 205 |
| 203 void ViewTreeClientImpl::RemoveView(Id view_id) { | 206 void ViewTreeClientImpl::RemoveView(Id view_id) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 217 if (!in_destructor_) | 220 if (!in_destructor_) |
| 218 delete this; | 221 delete this; |
| 219 } | 222 } |
| 220 | 223 |
| 221 //////////////////////////////////////////////////////////////////////////////// | 224 //////////////////////////////////////////////////////////////////////////////// |
| 222 // ViewTreeClientImpl, ViewTreeConnection implementation: | 225 // ViewTreeClientImpl, ViewTreeConnection implementation: |
| 223 | 226 |
| 224 Id ViewTreeClientImpl::CreateViewOnServer() { | 227 Id ViewTreeClientImpl::CreateViewOnServer() { |
| 225 DCHECK(tree_); | 228 DCHECK(tree_); |
| 226 const Id view_id = MakeTransportId(connection_id_, ++next_id_); | 229 const Id view_id = MakeTransportId(connection_id_, ++next_id_); |
| 227 tree_->CreateView(view_id, [this](ErrorCode code) { | 230 tree_->CreateView(view_id, [this](mojo::ErrorCode code) { |
| 228 OnActionCompleted(code == ERROR_CODE_NONE); | 231 OnActionCompleted(code == mojo::ERROR_CODE_NONE); |
| 229 }); | 232 }); |
| 230 return view_id; | 233 return view_id; |
| 231 } | 234 } |
| 232 | 235 |
| 233 View* ViewTreeClientImpl::GetRoot() { | 236 View* ViewTreeClientImpl::GetRoot() { |
| 234 return root_; | 237 return root_; |
| 235 } | 238 } |
| 236 | 239 |
| 237 View* ViewTreeClientImpl::GetViewById(Id id) { | 240 View* ViewTreeClientImpl::GetViewById(Id id) { |
| 238 IdToViewMap::const_iterator it = views_.find(id); | 241 IdToViewMap::const_iterator it = views_.find(id); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 254 } | 257 } |
| 255 | 258 |
| 256 ConnectionSpecificId ViewTreeClientImpl::GetConnectionId() { | 259 ConnectionSpecificId ViewTreeClientImpl::GetConnectionId() { |
| 257 return connection_id_; | 260 return connection_id_; |
| 258 } | 261 } |
| 259 | 262 |
| 260 //////////////////////////////////////////////////////////////////////////////// | 263 //////////////////////////////////////////////////////////////////////////////// |
| 261 // ViewTreeClientImpl, ViewTreeClient implementation: | 264 // ViewTreeClientImpl, ViewTreeClient implementation: |
| 262 | 265 |
| 263 void ViewTreeClientImpl::OnEmbed(ConnectionSpecificId connection_id, | 266 void ViewTreeClientImpl::OnEmbed(ConnectionSpecificId connection_id, |
| 264 ViewDataPtr root_data, | 267 mojo::ViewDataPtr root_data, |
| 265 ViewTreePtr tree, | 268 mojo::ViewTreePtr tree, |
| 266 Id focused_view_id, | 269 Id focused_view_id, |
| 267 uint32 access_policy) { | 270 uint32 access_policy) { |
| 268 if (tree) { | 271 if (tree) { |
| 269 DCHECK(!tree_); | 272 DCHECK(!tree_); |
| 270 tree_ = tree.Pass(); | 273 tree_ = tree.Pass(); |
| 271 tree_.set_connection_error_handler([this]() { delete this; }); | 274 tree_.set_connection_error_handler([this]() { delete this; }); |
| 272 } | 275 } |
| 273 connection_id_ = connection_id; | 276 connection_id_ = connection_id; |
| 274 is_embed_root_ = | 277 is_embed_root_ = |
| 275 (access_policy & mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT) != 0; | 278 (access_policy & mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT) != 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 290 } | 293 } |
| 291 } | 294 } |
| 292 | 295 |
| 293 void ViewTreeClientImpl::OnUnembed() { | 296 void ViewTreeClientImpl::OnUnembed() { |
| 294 delegate_->OnUnembed(); | 297 delegate_->OnUnembed(); |
| 295 // This will send out the various notifications. | 298 // This will send out the various notifications. |
| 296 delete this; | 299 delete this; |
| 297 } | 300 } |
| 298 | 301 |
| 299 void ViewTreeClientImpl::OnViewBoundsChanged(Id view_id, | 302 void ViewTreeClientImpl::OnViewBoundsChanged(Id view_id, |
| 300 RectPtr old_bounds, | 303 mojo::RectPtr old_bounds, |
| 301 RectPtr new_bounds) { | 304 mojo::RectPtr new_bounds) { |
| 302 View* view = GetViewById(view_id); | 305 View* view = GetViewById(view_id); |
| 303 ViewPrivate(view).LocalSetBounds(*old_bounds, *new_bounds); | 306 ViewPrivate(view).LocalSetBounds(*old_bounds, *new_bounds); |
| 304 } | 307 } |
| 305 | 308 |
| 306 namespace { | 309 namespace { |
| 307 | 310 |
| 308 void SetViewportMetricsOnDecendants(View* root, | 311 void SetViewportMetricsOnDecendants(View* root, |
| 309 const ViewportMetrics& old_metrics, | 312 const mojo::ViewportMetrics& old_metrics, |
| 310 const ViewportMetrics& new_metrics) { | 313 const mojo::ViewportMetrics& new_metrics) { |
| 311 ViewPrivate(root).LocalSetViewportMetrics(old_metrics, new_metrics); | 314 ViewPrivate(root).LocalSetViewportMetrics(old_metrics, new_metrics); |
| 312 const View::Children& children = root->children(); | 315 const View::Children& children = root->children(); |
| 313 for (size_t i = 0; i < children.size(); ++i) | 316 for (size_t i = 0; i < children.size(); ++i) |
| 314 SetViewportMetricsOnDecendants(children[i], old_metrics, new_metrics); | 317 SetViewportMetricsOnDecendants(children[i], old_metrics, new_metrics); |
| 315 } | 318 } |
| 316 } | 319 } |
| 317 | 320 |
| 318 void ViewTreeClientImpl::OnViewViewportMetricsChanged( | 321 void ViewTreeClientImpl::OnViewViewportMetricsChanged( |
| 319 ViewportMetricsPtr old_metrics, | 322 mojo::ViewportMetricsPtr old_metrics, |
| 320 ViewportMetricsPtr new_metrics) { | 323 mojo::ViewportMetricsPtr new_metrics) { |
| 321 View* view = GetRoot(); | 324 View* view = GetRoot(); |
| 322 if (view) | 325 if (view) |
| 323 SetViewportMetricsOnDecendants(view, *old_metrics, *new_metrics); | 326 SetViewportMetricsOnDecendants(view, *old_metrics, *new_metrics); |
| 324 } | 327 } |
| 325 | 328 |
| 326 void ViewTreeClientImpl::OnViewHierarchyChanged( | 329 void ViewTreeClientImpl::OnViewHierarchyChanged( |
| 327 Id view_id, | 330 Id view_id, |
| 328 Id new_parent_id, | 331 Id new_parent_id, |
| 329 Id old_parent_id, | 332 Id old_parent_id, |
| 330 mojo::Array<ViewDataPtr> views) { | 333 mojo::Array<mojo::ViewDataPtr> views) { |
| 331 View* initial_parent = views.size() ? GetViewById(views[0]->parent_id) : NULL; | 334 View* initial_parent = views.size() ? GetViewById(views[0]->parent_id) : NULL; |
| 332 | 335 |
| 333 const bool was_view_known = GetViewById(view_id) != nullptr; | 336 const bool was_view_known = GetViewById(view_id) != nullptr; |
| 334 | 337 |
| 335 BuildViewTree(this, views, initial_parent); | 338 BuildViewTree(this, views, initial_parent); |
| 336 | 339 |
| 337 // If the view was not known, then BuildViewTree() will have created it and | 340 // If the view was not known, then BuildViewTree() will have created it and |
| 338 // parented the view. | 341 // parented the view. |
| 339 if (!was_view_known) | 342 if (!was_view_known) |
| 340 return; | 343 return; |
| 341 | 344 |
| 342 View* new_parent = GetViewById(new_parent_id); | 345 View* new_parent = GetViewById(new_parent_id); |
| 343 View* old_parent = GetViewById(old_parent_id); | 346 View* old_parent = GetViewById(old_parent_id); |
| 344 View* view = GetViewById(view_id); | 347 View* view = GetViewById(view_id); |
| 345 if (new_parent) | 348 if (new_parent) |
| 346 ViewPrivate(new_parent).LocalAddChild(view); | 349 ViewPrivate(new_parent).LocalAddChild(view); |
| 347 else | 350 else |
| 348 ViewPrivate(old_parent).LocalRemoveChild(view); | 351 ViewPrivate(old_parent).LocalRemoveChild(view); |
| 349 } | 352 } |
| 350 | 353 |
| 351 void ViewTreeClientImpl::OnViewReordered(Id view_id, | 354 void ViewTreeClientImpl::OnViewReordered(Id view_id, |
| 352 Id relative_view_id, | 355 Id relative_view_id, |
| 353 OrderDirection direction) { | 356 mojo::OrderDirection direction) { |
| 354 View* view = GetViewById(view_id); | 357 View* view = GetViewById(view_id); |
| 355 View* relative_view = GetViewById(relative_view_id); | 358 View* relative_view = GetViewById(relative_view_id); |
| 356 if (view && relative_view) | 359 if (view && relative_view) |
| 357 ViewPrivate(view).LocalReorder(relative_view, direction); | 360 ViewPrivate(view).LocalReorder(relative_view, direction); |
| 358 } | 361 } |
| 359 | 362 |
| 360 void ViewTreeClientImpl::OnViewDeleted(Id view_id) { | 363 void ViewTreeClientImpl::OnViewDeleted(Id view_id) { |
| 361 View* view = GetViewById(view_id); | 364 View* view = GetViewById(view_id); |
| 362 if (view) | 365 if (view) |
| 363 ViewPrivate(view).LocalDestroy(); | 366 ViewPrivate(view).LocalDestroy(); |
| 364 } | 367 } |
| 365 | 368 |
| 366 void ViewTreeClientImpl::OnViewVisibilityChanged(Id view_id, bool visible) { | 369 void ViewTreeClientImpl::OnViewVisibilityChanged(Id view_id, bool visible) { |
| 367 // TODO(sky): there is a race condition here. If this client and another | 370 // TODO(sky): there is a race condition here. If this client and another |
| 368 // client change the visibility at the same time the wrong value may be set. | 371 // client change the visibility at the same time the wrong value may be set. |
| 369 // Deal with this some how. | 372 // Deal with this some how. |
| 370 View* view = GetViewById(view_id); | 373 View* view = GetViewById(view_id); |
| 371 if (view) | 374 if (view) |
| 372 ViewPrivate(view).LocalSetVisible(visible); | 375 ViewPrivate(view).LocalSetVisible(visible); |
| 373 } | 376 } |
| 374 | 377 |
| 375 void ViewTreeClientImpl::OnViewDrawnStateChanged(Id view_id, bool drawn) { | 378 void ViewTreeClientImpl::OnViewDrawnStateChanged(Id view_id, bool drawn) { |
| 376 View* view = GetViewById(view_id); | 379 View* view = GetViewById(view_id); |
| 377 if (view) | 380 if (view) |
| 378 ViewPrivate(view).LocalSetDrawn(drawn); | 381 ViewPrivate(view).LocalSetDrawn(drawn); |
| 379 } | 382 } |
| 380 | 383 |
| 381 void ViewTreeClientImpl::OnViewSharedPropertyChanged(Id view_id, | 384 void ViewTreeClientImpl::OnViewSharedPropertyChanged( |
| 382 const String& name, | 385 Id view_id, |
| 383 Array<uint8_t> new_data) { | 386 const mojo::String& name, |
| 387 mojo::Array<uint8_t> new_data) { |
| 384 View* view = GetViewById(view_id); | 388 View* view = GetViewById(view_id); |
| 385 if (view) { | 389 if (view) { |
| 386 std::vector<uint8_t> data; | 390 std::vector<uint8_t> data; |
| 387 std::vector<uint8_t>* data_ptr = NULL; | 391 std::vector<uint8_t>* data_ptr = NULL; |
| 388 if (!new_data.is_null()) { | 392 if (!new_data.is_null()) { |
| 389 data = new_data.To<std::vector<uint8_t>>(); | 393 data = new_data.To<std::vector<uint8_t>>(); |
| 390 data_ptr = &data; | 394 data_ptr = &data; |
| 391 } | 395 } |
| 392 | 396 |
| 393 view->SetSharedProperty(name, data_ptr); | 397 view->SetSharedProperty(name, data_ptr); |
| 394 } | 398 } |
| 395 } | 399 } |
| 396 | 400 |
| 397 void ViewTreeClientImpl::OnViewInputEvent( | 401 void ViewTreeClientImpl::OnViewInputEvent( |
| 398 Id view_id, | 402 Id view_id, |
| 399 EventPtr event, | 403 mojo::EventPtr event, |
| 400 const Callback<void()>& ack_callback) { | 404 const mojo::Callback<void()>& ack_callback) { |
| 401 View* view = GetViewById(view_id); | 405 View* view = GetViewById(view_id); |
| 402 if (view) { | 406 if (view) { |
| 403 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(), | 407 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(), |
| 404 OnViewInputEvent(view, event)); | 408 OnViewInputEvent(view, event)); |
| 405 } | 409 } |
| 406 ack_callback.Run(); | 410 ack_callback.Run(); |
| 407 } | 411 } |
| 408 | 412 |
| 409 void ViewTreeClientImpl::OnViewFocused(Id focused_view_id) { | 413 void ViewTreeClientImpl::OnViewFocused(Id focused_view_id) { |
| 410 View* focused = GetViewById(focused_view_id); | 414 View* focused = GetViewById(focused_view_id); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 424 } | 428 } |
| 425 | 429 |
| 426 //////////////////////////////////////////////////////////////////////////////// | 430 //////////////////////////////////////////////////////////////////////////////// |
| 427 // ViewTreeClientImpl, private: | 431 // ViewTreeClientImpl, private: |
| 428 | 432 |
| 429 void ViewTreeClientImpl::OnActionCompleted(bool success) { | 433 void ViewTreeClientImpl::OnActionCompleted(bool success) { |
| 430 if (!change_acked_callback_.is_null()) | 434 if (!change_acked_callback_.is_null()) |
| 431 change_acked_callback_.Run(); | 435 change_acked_callback_.Run(); |
| 432 } | 436 } |
| 433 | 437 |
| 434 Callback<void(bool)> ViewTreeClientImpl::ActionCompletedCallback() { | 438 mojo::Callback<void(bool)> ViewTreeClientImpl::ActionCompletedCallback() { |
| 435 return [this](bool success) { OnActionCompleted(success); }; | 439 return [this](bool success) { OnActionCompleted(success); }; |
| 436 } | 440 } |
| 437 | 441 |
| 438 } // namespace mojo | 442 } // namespace mus |
| OLD | NEW |