| 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/view_manager/view_tree_impl.h" | 5 #include "components/mus/view_tree_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "components/view_manager/connection_manager.h" | 9 #include "components/mus/connection_manager.h" |
| 10 #include "components/view_manager/default_access_policy.h" | 10 #include "components/mus/default_access_policy.h" |
| 11 #include "components/view_manager/display_manager.h" | 11 #include "components/mus/display_manager.h" |
| 12 #include "components/view_manager/server_view.h" | 12 #include "components/mus/server_view.h" |
| 13 #include "components/view_manager/view_tree_host_impl.h" | 13 #include "components/mus/view_tree_host_impl.h" |
| 14 #include "components/view_manager/window_manager_access_policy.h" | 14 #include "components/mus/window_manager_access_policy.h" |
| 15 #include "mojo/converters/geometry/geometry_type_converters.h" | 15 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 16 #include "mojo/converters/ime/ime_type_converters.h" | 16 #include "mojo/converters/ime/ime_type_converters.h" |
| 17 #include "mojo/converters/input_events/input_events_type_converters.h" | 17 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 18 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 18 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 19 #include "ui/platform_window/text_input_state.h" | 19 #include "ui/platform_window/text_input_state.h" |
| 20 | 20 |
| 21 using mojo::Array; | 21 using mojo::Array; |
| 22 using mojo::Callback; | 22 using mojo::Callback; |
| 23 using mojo::Id; | 23 using mojo::Id; |
| 24 using mojo::InterfaceRequest; | 24 using mojo::InterfaceRequest; |
| 25 using mojo::OrderDirection; | 25 using mojo::OrderDirection; |
| 26 using mojo::Rect; | 26 using mojo::Rect; |
| 27 using mojo::ServiceProvider; | 27 using mojo::ServiceProvider; |
| 28 using mojo::ServiceProviderPtr; | 28 using mojo::ServiceProviderPtr; |
| 29 using mojo::String; | 29 using mojo::String; |
| 30 using mojo::ViewDataPtr; | 30 using mojo::ViewDataPtr; |
| 31 | 31 |
| 32 namespace view_manager { | 32 namespace view_manager { |
| 33 | 33 |
| 34 ViewTreeImpl::ViewTreeImpl( | 34 ViewTreeImpl::ViewTreeImpl(ConnectionManager* connection_manager, |
| 35 ConnectionManager* connection_manager, | 35 mojo::ConnectionSpecificId creator_id, |
| 36 mojo::ConnectionSpecificId creator_id, | 36 const ViewId& root_id) |
| 37 const ViewId& root_id) | |
| 38 : connection_manager_(connection_manager), | 37 : connection_manager_(connection_manager), |
| 39 id_(connection_manager_->GetAndAdvanceNextConnectionId()), | 38 id_(connection_manager_->GetAndAdvanceNextConnectionId()), |
| 40 creator_id_(creator_id), | 39 creator_id_(creator_id), |
| 41 client_(nullptr), | 40 client_(nullptr), |
| 42 is_embed_root_(false) { | 41 is_embed_root_(false) { |
| 43 ServerView* view = GetView(root_id); | 42 ServerView* view = GetView(root_id); |
| 44 CHECK(view); | 43 CHECK(view); |
| 45 root_.reset(new ViewId(root_id)); | 44 root_.reset(new ViewId(root_id)); |
| 46 if (view->GetRoot() == view) { | 45 if (view->GetRoot() == view) { |
| 47 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); | 46 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return i == view_map_.end() ? NULL : i->second; | 83 return i == view_map_.end() ? NULL : i->second; |
| 85 } | 84 } |
| 86 return connection_manager_->GetView(id); | 85 return connection_manager_->GetView(id); |
| 87 } | 86 } |
| 88 | 87 |
| 89 bool ViewTreeImpl::IsRoot(const ViewId& id) const { | 88 bool ViewTreeImpl::IsRoot(const ViewId& id) const { |
| 90 return root_.get() && *root_ == id; | 89 return root_.get() && *root_ == id; |
| 91 } | 90 } |
| 92 | 91 |
| 93 ViewTreeHostImpl* ViewTreeImpl::GetHost() { | 92 ViewTreeHostImpl* ViewTreeImpl::GetHost() { |
| 94 return root_.get() ? | 93 return root_.get() |
| 95 connection_manager_->GetViewTreeHostByView(GetView(*root_)) : nullptr; | 94 ? connection_manager_->GetViewTreeHostByView(GetView(*root_)) |
| 95 : nullptr; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void ViewTreeImpl::OnWillDestroyViewTreeImpl( | 98 void ViewTreeImpl::OnWillDestroyViewTreeImpl(ViewTreeImpl* connection) { |
| 99 ViewTreeImpl* connection) { | |
| 100 if (creator_id_ == connection->id()) | 99 if (creator_id_ == connection->id()) |
| 101 creator_id_ = kInvalidConnectionId; | 100 creator_id_ = kInvalidConnectionId; |
| 102 const ServerView* connection_root = | 101 const ServerView* connection_root = |
| 103 connection->root_ ? connection->GetView(*connection->root_) : nullptr; | 102 connection->root_ ? connection->GetView(*connection->root_) : nullptr; |
| 104 if (connection_root && | 103 if (connection_root && |
| 105 ((connection_root->id().connection_id == id_ && | 104 ((connection_root->id().connection_id == id_ && |
| 106 view_map_.count(connection_root->id().view_id) > 0) || | 105 view_map_.count(connection_root->id().view_id) > 0) || |
| 107 (is_embed_root_ && IsViewKnown(connection_root)))) { | 106 (is_embed_root_ && IsViewKnown(connection_root)))) { |
| 108 client()->OnEmbeddedAppDisconnected( | 107 client()->OnEmbeddedAppDisconnected( |
| 109 ViewIdToTransportId(*connection->root_)); | 108 ViewIdToTransportId(*connection->root_)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 return true; | 167 return true; |
| 169 } | 168 } |
| 170 | 169 |
| 171 void ViewTreeImpl::Embed(const ViewId& view_id, mojo::URLRequestPtr request) { | 170 void ViewTreeImpl::Embed(const ViewId& view_id, mojo::URLRequestPtr request) { |
| 172 if (!CanEmbed(view_id)) | 171 if (!CanEmbed(view_id)) |
| 173 return; | 172 return; |
| 174 PrepareForEmbed(view_id); | 173 PrepareForEmbed(view_id); |
| 175 connection_manager_->EmbedAtView(id_, view_id, request.Pass()); | 174 connection_manager_->EmbedAtView(id_, view_id, request.Pass()); |
| 176 } | 175 } |
| 177 | 176 |
| 178 void ViewTreeImpl::ProcessViewBoundsChanged( | 177 void ViewTreeImpl::ProcessViewBoundsChanged(const ServerView* view, |
| 179 const ServerView* view, | 178 const gfx::Rect& old_bounds, |
| 180 const gfx::Rect& old_bounds, | 179 const gfx::Rect& new_bounds, |
| 181 const gfx::Rect& new_bounds, | 180 bool originated_change) { |
| 182 bool originated_change) { | |
| 183 if (originated_change || !IsViewKnown(view)) | 181 if (originated_change || !IsViewKnown(view)) |
| 184 return; | 182 return; |
| 185 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()), | 183 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()), |
| 186 Rect::From(old_bounds), | 184 Rect::From(old_bounds), Rect::From(new_bounds)); |
| 187 Rect::From(new_bounds)); | |
| 188 } | 185 } |
| 189 | 186 |
| 190 void ViewTreeImpl::ProcessViewportMetricsChanged( | 187 void ViewTreeImpl::ProcessViewportMetricsChanged( |
| 191 const mojo::ViewportMetrics& old_metrics, | 188 const mojo::ViewportMetrics& old_metrics, |
| 192 const mojo::ViewportMetrics& new_metrics, | 189 const mojo::ViewportMetrics& new_metrics, |
| 193 bool originated_change) { | 190 bool originated_change) { |
| 194 client()->OnViewViewportMetricsChanged(old_metrics.Clone(), | 191 client()->OnViewViewportMetricsChanged(old_metrics.Clone(), |
| 195 new_metrics.Clone()); | 192 new_metrics.Clone()); |
| 196 } | 193 } |
| 197 | 194 |
| 198 void ViewTreeImpl::ProcessWillChangeViewHierarchy( | 195 void ViewTreeImpl::ProcessWillChangeViewHierarchy(const ServerView* view, |
| 199 const ServerView* view, | 196 const ServerView* new_parent, |
| 200 const ServerView* new_parent, | 197 const ServerView* old_parent, |
| 201 const ServerView* old_parent, | 198 bool originated_change) { |
| 202 bool originated_change) { | |
| 203 if (originated_change) | 199 if (originated_change) |
| 204 return; | 200 return; |
| 205 | 201 |
| 206 const bool old_drawn = view->IsDrawn(); | 202 const bool old_drawn = view->IsDrawn(); |
| 207 const bool new_drawn = view->visible() && new_parent && new_parent->IsDrawn(); | 203 const bool new_drawn = view->visible() && new_parent && new_parent->IsDrawn(); |
| 208 if (old_drawn == new_drawn) | 204 if (old_drawn == new_drawn) |
| 209 return; | 205 return; |
| 210 | 206 |
| 211 NotifyDrawnStateChanged(view, new_drawn); | 207 NotifyDrawnStateChanged(view, new_drawn); |
| 212 } | 208 } |
| 213 | 209 |
| 214 void ViewTreeImpl::ProcessViewPropertyChanged( | 210 void ViewTreeImpl::ProcessViewPropertyChanged( |
| 215 const ServerView* view, | 211 const ServerView* view, |
| 216 const std::string& name, | 212 const std::string& name, |
| 217 const std::vector<uint8_t>* new_data, | 213 const std::vector<uint8_t>* new_data, |
| 218 bool originated_change) { | 214 bool originated_change) { |
| 219 if (originated_change) | 215 if (originated_change) |
| 220 return; | 216 return; |
| 221 | 217 |
| 222 Array<uint8_t> data; | 218 Array<uint8_t> data; |
| 223 if (new_data) | 219 if (new_data) |
| 224 data = Array<uint8_t>::From(*new_data); | 220 data = Array<uint8_t>::From(*new_data); |
| 225 | 221 |
| 226 client()->OnViewSharedPropertyChanged(ViewIdToTransportId(view->id()), | 222 client()->OnViewSharedPropertyChanged(ViewIdToTransportId(view->id()), |
| 227 String(name), data.Pass()); | 223 String(name), data.Pass()); |
| 228 } | 224 } |
| 229 | 225 |
| 230 void ViewTreeImpl::ProcessViewHierarchyChanged( | 226 void ViewTreeImpl::ProcessViewHierarchyChanged(const ServerView* view, |
| 231 const ServerView* view, | 227 const ServerView* new_parent, |
| 232 const ServerView* new_parent, | 228 const ServerView* old_parent, |
| 233 const ServerView* old_parent, | 229 bool originated_change) { |
| 234 bool originated_change) { | |
| 235 if (originated_change && !IsViewKnown(view) && new_parent && | 230 if (originated_change && !IsViewKnown(view) && new_parent && |
| 236 IsViewKnown(new_parent)) { | 231 IsViewKnown(new_parent)) { |
| 237 std::vector<const ServerView*> unused; | 232 std::vector<const ServerView*> unused; |
| 238 GetUnknownViewsFrom(view, &unused); | 233 GetUnknownViewsFrom(view, &unused); |
| 239 } | 234 } |
| 240 if (originated_change || connection_manager_->is_processing_delete_view() || | 235 if (originated_change || connection_manager_->is_processing_delete_view() || |
| 241 connection_manager_->DidConnectionMessageClient(id_)) { | 236 connection_manager_->DidConnectionMessageClient(id_)) { |
| 242 return; | 237 return; |
| 243 } | 238 } |
| 244 | 239 |
| 245 if (!access_policy_->ShouldNotifyOnHierarchyChange( | 240 if (!access_policy_->ShouldNotifyOnHierarchyChange(view, &new_parent, |
| 246 view, &new_parent, &old_parent)) { | 241 &old_parent)) { |
| 247 return; | 242 return; |
| 248 } | 243 } |
| 249 // Inform the client of any new views and update the set of views we know | 244 // Inform the client of any new views and update the set of views we know |
| 250 // about. | 245 // about. |
| 251 std::vector<const ServerView*> to_send; | 246 std::vector<const ServerView*> to_send; |
| 252 if (!IsViewKnown(view)) | 247 if (!IsViewKnown(view)) |
| 253 GetUnknownViewsFrom(view, &to_send); | 248 GetUnknownViewsFrom(view, &to_send); |
| 254 const ViewId new_parent_id(new_parent ? new_parent->id() : ViewId()); | 249 const ViewId new_parent_id(new_parent ? new_parent->id() : ViewId()); |
| 255 const ViewId old_parent_id(old_parent ? old_parent->id() : ViewId()); | 250 const ViewId old_parent_id(old_parent ? old_parent->id() : ViewId()); |
| 256 client()->OnViewHierarchyChanged(ViewIdToTransportId(view->id()), | 251 client()->OnViewHierarchyChanged( |
| 257 ViewIdToTransportId(new_parent_id), | 252 ViewIdToTransportId(view->id()), ViewIdToTransportId(new_parent_id), |
| 258 ViewIdToTransportId(old_parent_id), | 253 ViewIdToTransportId(old_parent_id), ViewsToViewDatas(to_send)); |
| 259 ViewsToViewDatas(to_send)); | |
| 260 connection_manager_->OnConnectionMessagedClient(id_); | 254 connection_manager_->OnConnectionMessagedClient(id_); |
| 261 } | 255 } |
| 262 | 256 |
| 263 void ViewTreeImpl::ProcessViewReorder(const ServerView* view, | 257 void ViewTreeImpl::ProcessViewReorder(const ServerView* view, |
| 264 const ServerView* relative_view, | 258 const ServerView* relative_view, |
| 265 OrderDirection direction, | 259 OrderDirection direction, |
| 266 bool originated_change) { | 260 bool originated_change) { |
| 267 if (originated_change || !IsViewKnown(view) || !IsViewKnown(relative_view)) | 261 if (originated_change || !IsViewKnown(view) || !IsViewKnown(relative_view)) |
| 268 return; | 262 return; |
| 269 | 263 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 284 | 278 |
| 285 if (originated_change) | 279 if (originated_change) |
| 286 return; | 280 return; |
| 287 | 281 |
| 288 if (in_known) { | 282 if (in_known) { |
| 289 client()->OnViewDeleted(ViewIdToTransportId(view)); | 283 client()->OnViewDeleted(ViewIdToTransportId(view)); |
| 290 connection_manager_->OnConnectionMessagedClient(id_); | 284 connection_manager_->OnConnectionMessagedClient(id_); |
| 291 } | 285 } |
| 292 } | 286 } |
| 293 | 287 |
| 294 void ViewTreeImpl::ProcessWillChangeViewVisibility( | 288 void ViewTreeImpl::ProcessWillChangeViewVisibility(const ServerView* view, |
| 295 const ServerView* view, | 289 bool originated_change) { |
| 296 bool originated_change) { | |
| 297 if (originated_change) | 290 if (originated_change) |
| 298 return; | 291 return; |
| 299 | 292 |
| 300 if (IsViewKnown(view)) { | 293 if (IsViewKnown(view)) { |
| 301 client()->OnViewVisibilityChanged(ViewIdToTransportId(view->id()), | 294 client()->OnViewVisibilityChanged(ViewIdToTransportId(view->id()), |
| 302 !view->visible()); | 295 !view->visible()); |
| 303 return; | 296 return; |
| 304 } | 297 } |
| 305 | 298 |
| 306 bool view_target_drawn_state; | 299 bool view_target_drawn_state; |
| 307 if (view->visible()) { | 300 if (view->visible()) { |
| 308 // View is being hidden, won't be drawn. | 301 // View is being hidden, won't be drawn. |
| 309 view_target_drawn_state = false; | 302 view_target_drawn_state = false; |
| 310 } else { | 303 } else { |
| 311 // View is being shown. View will be drawn if its parent is drawn. | 304 // View is being shown. View will be drawn if its parent is drawn. |
| 312 view_target_drawn_state = view->parent() && view->parent()->IsDrawn(); | 305 view_target_drawn_state = view->parent() && view->parent()->IsDrawn(); |
| 313 } | 306 } |
| 314 | 307 |
| 315 NotifyDrawnStateChanged(view, view_target_drawn_state); | 308 NotifyDrawnStateChanged(view, view_target_drawn_state); |
| 316 } | 309 } |
| 317 | 310 |
| 318 void ViewTreeImpl::ProcessFocusChanged( | 311 void ViewTreeImpl::ProcessFocusChanged(const ServerView* old_focused_view, |
| 319 const ServerView* old_focused_view, | 312 const ServerView* new_focused_view) { |
| 320 const ServerView* new_focused_view) { | |
| 321 const ServerView* view = | 313 const ServerView* view = |
| 322 new_focused_view ? access_policy_->GetViewForFocusChange(new_focused_view) | 314 new_focused_view ? access_policy_->GetViewForFocusChange(new_focused_view) |
| 323 : nullptr; | 315 : nullptr; |
| 324 client()->OnViewFocused(view ? ViewIdToTransportId(view->id()) | 316 client()->OnViewFocused(view ? ViewIdToTransportId(view->id()) |
| 325 : ViewIdToTransportId(ViewId())); | 317 : ViewIdToTransportId(ViewId())); |
| 326 } | 318 } |
| 327 | 319 |
| 328 bool ViewTreeImpl::IsViewKnown(const ServerView* view) const { | 320 bool ViewTreeImpl::IsViewKnown(const ServerView* view) const { |
| 329 return known_views_.count(ViewIdToTransportId(view->id())) > 0; | 321 return known_views_.count(ViewIdToTransportId(view->id())) > 0; |
| 330 } | 322 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 356 } | 348 } |
| 357 | 349 |
| 358 bool ViewTreeImpl::DeleteViewImpl(ViewTreeImpl* source, ServerView* view) { | 350 bool ViewTreeImpl::DeleteViewImpl(ViewTreeImpl* source, ServerView* view) { |
| 359 DCHECK(view); | 351 DCHECK(view); |
| 360 DCHECK_EQ(view->id().connection_id, id_); | 352 DCHECK_EQ(view->id().connection_id, id_); |
| 361 ConnectionManager::ScopedChange change(source, connection_manager_, true); | 353 ConnectionManager::ScopedChange change(source, connection_manager_, true); |
| 362 delete view; | 354 delete view; |
| 363 return true; | 355 return true; |
| 364 } | 356 } |
| 365 | 357 |
| 366 void ViewTreeImpl::GetUnknownViewsFrom( | 358 void ViewTreeImpl::GetUnknownViewsFrom(const ServerView* view, |
| 367 const ServerView* view, | 359 std::vector<const ServerView*>* views) { |
| 368 std::vector<const ServerView*>* views) { | |
| 369 if (IsViewKnown(view) || !access_policy_->CanGetViewTree(view)) | 360 if (IsViewKnown(view) || !access_policy_->CanGetViewTree(view)) |
| 370 return; | 361 return; |
| 371 views->push_back(view); | 362 views->push_back(view); |
| 372 known_views_.insert(ViewIdToTransportId(view->id())); | 363 known_views_.insert(ViewIdToTransportId(view->id())); |
| 373 if (!access_policy_->CanDescendIntoViewForViewTree(view)) | 364 if (!access_policy_->CanDescendIntoViewForViewTree(view)) |
| 374 return; | 365 return; |
| 375 std::vector<const ServerView*> children(view->GetChildren()); | 366 std::vector<const ServerView*> children(view->GetChildren()); |
| 376 for (size_t i = 0 ; i < children.size(); ++i) | 367 for (size_t i = 0; i < children.size(); ++i) |
| 377 GetUnknownViewsFrom(children[i], views); | 368 GetUnknownViewsFrom(children[i], views); |
| 378 } | 369 } |
| 379 | 370 |
| 380 void ViewTreeImpl::RemoveFromKnown( | 371 void ViewTreeImpl::RemoveFromKnown(const ServerView* view, |
| 381 const ServerView* view, | 372 std::vector<ServerView*>* local_views) { |
| 382 std::vector<ServerView*>* local_views) { | |
| 383 if (view->id().connection_id == id_) { | 373 if (view->id().connection_id == id_) { |
| 384 if (local_views) | 374 if (local_views) |
| 385 local_views->push_back(GetView(view->id())); | 375 local_views->push_back(GetView(view->id())); |
| 386 return; | 376 return; |
| 387 } | 377 } |
| 388 known_views_.erase(ViewIdToTransportId(view->id())); | 378 known_views_.erase(ViewIdToTransportId(view->id())); |
| 389 std::vector<const ServerView*> children = view->GetChildren(); | 379 std::vector<const ServerView*> children = view->GetChildren(); |
| 390 for (size_t i = 0; i < children.size(); ++i) | 380 for (size_t i = 0; i < children.size(); ++i) |
| 391 RemoveFromKnown(children[i], local_views); | 381 RemoveFromKnown(children[i], local_views); |
| 392 } | 382 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 436 |
| 447 if (!access_policy_->CanGetViewTree(view)) | 437 if (!access_policy_->CanGetViewTree(view)) |
| 448 return; | 438 return; |
| 449 | 439 |
| 450 views->push_back(view); | 440 views->push_back(view); |
| 451 | 441 |
| 452 if (!access_policy_->CanDescendIntoViewForViewTree(view)) | 442 if (!access_policy_->CanDescendIntoViewForViewTree(view)) |
| 453 return; | 443 return; |
| 454 | 444 |
| 455 std::vector<const ServerView*> children(view->GetChildren()); | 445 std::vector<const ServerView*> children(view->GetChildren()); |
| 456 for (size_t i = 0 ; i < children.size(); ++i) | 446 for (size_t i = 0; i < children.size(); ++i) |
| 457 GetViewTreeImpl(children[i], views); | 447 GetViewTreeImpl(children[i], views); |
| 458 } | 448 } |
| 459 | 449 |
| 460 void ViewTreeImpl::NotifyDrawnStateChanged(const ServerView* view, | 450 void ViewTreeImpl::NotifyDrawnStateChanged(const ServerView* view, |
| 461 bool new_drawn_value) { | 451 bool new_drawn_value) { |
| 462 // Even though we don't know about view, it may be an ancestor of our root, in | 452 // Even though we don't know about view, it may be an ancestor of our root, in |
| 463 // which case the change may effect our roots drawn state. | 453 // which case the change may effect our roots drawn state. |
| 464 if (!root_.get()) | 454 if (!root_.get()) |
| 465 return; | 455 return; |
| 466 | 456 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 498 |
| 509 void ViewTreeImpl::RemoveChildrenAsPartOfEmbed(const ViewId& view_id) { | 499 void ViewTreeImpl::RemoveChildrenAsPartOfEmbed(const ViewId& view_id) { |
| 510 ServerView* view = GetView(view_id); | 500 ServerView* view = GetView(view_id); |
| 511 CHECK(view); | 501 CHECK(view); |
| 512 CHECK(view->id().connection_id == view_id.connection_id); | 502 CHECK(view->id().connection_id == view_id.connection_id); |
| 513 std::vector<ServerView*> children = view->GetChildren(); | 503 std::vector<ServerView*> children = view->GetChildren(); |
| 514 for (size_t i = 0; i < children.size(); ++i) | 504 for (size_t i = 0; i < children.size(); ++i) |
| 515 view->Remove(children[i]); | 505 view->Remove(children[i]); |
| 516 } | 506 } |
| 517 | 507 |
| 518 void ViewTreeImpl::CreateView( | 508 void ViewTreeImpl::CreateView(Id transport_view_id, |
| 519 Id transport_view_id, | 509 const Callback<void(mojo::ErrorCode)>& callback) { |
| 520 const Callback<void(mojo::ErrorCode)>& callback) { | |
| 521 callback.Run(CreateView(ViewIdFromTransportId(transport_view_id))); | 510 callback.Run(CreateView(ViewIdFromTransportId(transport_view_id))); |
| 522 } | 511 } |
| 523 | 512 |
| 524 void ViewTreeImpl::DeleteView( | 513 void ViewTreeImpl::DeleteView(Id transport_view_id, |
| 525 Id transport_view_id, | 514 const Callback<void(bool)>& callback) { |
| 526 const Callback<void(bool)>& callback) { | |
| 527 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); | 515 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); |
| 528 bool success = false; | 516 bool success = false; |
| 529 if (view && access_policy_->CanDeleteView(view)) { | 517 if (view && access_policy_->CanDeleteView(view)) { |
| 530 ViewTreeImpl* connection = | 518 ViewTreeImpl* connection = |
| 531 connection_manager_->GetConnection(view->id().connection_id); | 519 connection_manager_->GetConnection(view->id().connection_id); |
| 532 success = connection && connection->DeleteViewImpl(this, view); | 520 success = connection && connection->DeleteViewImpl(this, view); |
| 533 } | 521 } |
| 534 callback.Run(success); | 522 callback.Run(success); |
| 535 } | 523 } |
| 536 | 524 |
| 537 void ViewTreeImpl::AddView( | 525 void ViewTreeImpl::AddView(Id parent_id, |
| 538 Id parent_id, | 526 Id child_id, |
| 539 Id child_id, | 527 const Callback<void(bool)>& callback) { |
| 540 const Callback<void(bool)>& callback) { | |
| 541 callback.Run(AddView(ViewIdFromTransportId(parent_id), | 528 callback.Run(AddView(ViewIdFromTransportId(parent_id), |
| 542 ViewIdFromTransportId(child_id))); | 529 ViewIdFromTransportId(child_id))); |
| 543 } | 530 } |
| 544 | 531 |
| 545 void ViewTreeImpl::RemoveViewFromParent( | 532 void ViewTreeImpl::RemoveViewFromParent(Id view_id, |
| 546 Id view_id, | 533 const Callback<void(bool)>& callback) { |
| 547 const Callback<void(bool)>& callback) { | |
| 548 bool success = false; | 534 bool success = false; |
| 549 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 535 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 550 if (view && view->parent() && access_policy_->CanRemoveViewFromParent(view)) { | 536 if (view && view->parent() && access_policy_->CanRemoveViewFromParent(view)) { |
| 551 success = true; | 537 success = true; |
| 552 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 538 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 553 view->parent()->Remove(view); | 539 view->parent()->Remove(view); |
| 554 } | 540 } |
| 555 callback.Run(success); | 541 callback.Run(success); |
| 556 } | 542 } |
| 557 | 543 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 572 } | 558 } |
| 573 | 559 |
| 574 void ViewTreeImpl::GetViewTree( | 560 void ViewTreeImpl::GetViewTree( |
| 575 Id view_id, | 561 Id view_id, |
| 576 const Callback<void(Array<ViewDataPtr>)>& callback) { | 562 const Callback<void(Array<ViewDataPtr>)>& callback) { |
| 577 std::vector<const ServerView*> views( | 563 std::vector<const ServerView*> views( |
| 578 GetViewTree(ViewIdFromTransportId(view_id))); | 564 GetViewTree(ViewIdFromTransportId(view_id))); |
| 579 callback.Run(ViewsToViewDatas(views)); | 565 callback.Run(ViewsToViewDatas(views)); |
| 580 } | 566 } |
| 581 | 567 |
| 582 void ViewTreeImpl::SetViewBounds( | 568 void ViewTreeImpl::SetViewBounds(Id view_id, |
| 583 Id view_id, | 569 mojo::RectPtr bounds, |
| 584 mojo::RectPtr bounds, | 570 const Callback<void(bool)>& callback) { |
| 585 const Callback<void(bool)>& callback) { | |
| 586 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 571 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 587 const bool success = view && access_policy_->CanSetViewBounds(view); | 572 const bool success = view && access_policy_->CanSetViewBounds(view); |
| 588 if (success) { | 573 if (success) { |
| 589 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 574 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 590 view->SetBounds(bounds.To<gfx::Rect>()); | 575 view->SetBounds(bounds.To<gfx::Rect>()); |
| 591 } | 576 } |
| 592 callback.Run(success); | 577 callback.Run(success); |
| 593 } | 578 } |
| 594 | 579 |
| 595 void ViewTreeImpl::SetViewVisibility( | 580 void ViewTreeImpl::SetViewVisibility(Id transport_view_id, |
| 596 Id transport_view_id, | 581 bool visible, |
| 597 bool visible, | 582 const Callback<void(bool)>& callback) { |
| 598 const Callback<void(bool)>& callback) { | |
| 599 callback.Run( | 583 callback.Run( |
| 600 SetViewVisibility(ViewIdFromTransportId(transport_view_id), visible)); | 584 SetViewVisibility(ViewIdFromTransportId(transport_view_id), visible)); |
| 601 } | 585 } |
| 602 | 586 |
| 603 void ViewTreeImpl::SetViewProperty( | 587 void ViewTreeImpl::SetViewProperty(uint32_t view_id, |
| 604 uint32_t view_id, | 588 const mojo::String& name, |
| 605 const mojo::String& name, | 589 mojo::Array<uint8_t> value, |
| 606 mojo::Array<uint8_t> value, | 590 const mojo::Callback<void(bool)>& callback) { |
| 607 const mojo::Callback<void(bool)>& callback) { | |
| 608 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 591 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 609 const bool success = view && access_policy_->CanSetViewProperties(view); | 592 const bool success = view && access_policy_->CanSetViewProperties(view); |
| 610 if (success) { | 593 if (success) { |
| 611 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 594 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 612 | 595 |
| 613 if (value.is_null()) { | 596 if (value.is_null()) { |
| 614 view->SetProperty(name, nullptr); | 597 view->SetProperty(name, nullptr); |
| 615 } else { | 598 } else { |
| 616 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); | 599 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); |
| 617 view->SetProperty(name, &data); | 600 view->SetProperty(name, &data); |
| 618 } | 601 } |
| 619 } | 602 } |
| 620 callback.Run(success); | 603 callback.Run(success); |
| 621 } | 604 } |
| 622 | 605 |
| 623 void ViewTreeImpl::RequestSurface( | 606 void ViewTreeImpl::RequestSurface(mojo::Id view_id, |
| 624 mojo::Id view_id, | 607 mojo::InterfaceRequest<mojo::Surface> surface, |
| 625 mojo::InterfaceRequest<mojo::Surface> surface, | 608 mojo::SurfaceClientPtr client) { |
| 626 mojo::SurfaceClientPtr client) { | |
| 627 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 609 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 628 const bool success = view && access_policy_->CanSetViewSurfaceId(view); | 610 const bool success = view && access_policy_->CanSetViewSurfaceId(view); |
| 629 if (!success) | 611 if (!success) |
| 630 return; | 612 return; |
| 631 view->Bind(surface.Pass(), client.Pass()); | 613 view->Bind(surface.Pass(), client.Pass()); |
| 632 } | 614 } |
| 633 | 615 |
| 634 void ViewTreeImpl::SetViewTextInputState( | 616 void ViewTreeImpl::SetViewTextInputState(uint32_t view_id, |
| 635 uint32_t view_id, | 617 mojo::TextInputStatePtr state) { |
| 636 mojo::TextInputStatePtr state) { | |
| 637 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 618 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
| 638 bool success = view && access_policy_->CanSetViewTextInputState(view); | 619 bool success = view && access_policy_->CanSetViewTextInputState(view); |
| 639 if (success) | 620 if (success) |
| 640 view->SetTextInputState(state.To<ui::TextInputState>()); | 621 view->SetTextInputState(state.To<ui::TextInputState>()); |
| 641 } | 622 } |
| 642 | 623 |
| 643 void ViewTreeImpl::SetImeVisibility(Id transport_view_id, | 624 void ViewTreeImpl::SetImeVisibility(Id transport_view_id, |
| 644 bool visible, | 625 bool visible, |
| 645 mojo::TextInputStatePtr state) { | 626 mojo::TextInputStatePtr state) { |
| 646 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); | 627 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 ViewTreeImpl* connection = | 686 ViewTreeImpl* connection = |
| 706 connection_manager_->GetConnectionWithRoot(view->id()); | 687 connection_manager_->GetConnectionWithRoot(view->id()); |
| 707 return connection && connection != this; | 688 return connection && connection != this; |
| 708 } | 689 } |
| 709 | 690 |
| 710 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView* view) { | 691 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView* view) { |
| 711 return is_embed_root_ && root_ && GetView(*root_)->Contains(view); | 692 return is_embed_root_ && root_ && GetView(*root_)->Contains(view); |
| 712 } | 693 } |
| 713 | 694 |
| 714 } // namespace view_manager | 695 } // namespace view_manager |
| OLD | NEW |