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/view_manager_service_impl.h" | 5 #include "mojo/services/view_manager/view_manager_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
10 #include "mojo/services/view_manager/connection_manager.h" | 10 #include "mojo/services/view_manager/connection_manager.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const gfx::Rect& old_bounds, | 74 const gfx::Rect& old_bounds, |
75 const gfx::Rect& new_bounds, | 75 const gfx::Rect& new_bounds, |
76 bool originated_change) { | 76 bool originated_change) { |
77 if (originated_change || !IsViewKnown(view)) | 77 if (originated_change || !IsViewKnown(view)) |
78 return; | 78 return; |
79 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()), | 79 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()), |
80 Rect::From(old_bounds), | 80 Rect::From(old_bounds), |
81 Rect::From(new_bounds)); | 81 Rect::From(new_bounds)); |
82 } | 82 } |
83 | 83 |
| 84 void ViewManagerServiceImpl::ProcessWillChangeViewHierarchy( |
| 85 const ServerView* view, |
| 86 const ServerView* new_parent, |
| 87 const ServerView* old_parent, |
| 88 bool originated_change) { |
| 89 if (originated_change) |
| 90 return; |
| 91 |
| 92 const bool old_drawn = view->IsDrawn(connection_manager_->root()); |
| 93 const bool new_drawn = view->visible() && new_parent && |
| 94 new_parent->IsDrawn(connection_manager_->root()); |
| 95 if (old_drawn == new_drawn) |
| 96 return; |
| 97 |
| 98 NotifyDrawnStateChanged(view, new_drawn); |
| 99 } |
| 100 |
84 void ViewManagerServiceImpl::ProcessViewHierarchyChanged( | 101 void ViewManagerServiceImpl::ProcessViewHierarchyChanged( |
85 const ServerView* view, | 102 const ServerView* view, |
86 const ServerView* new_parent, | 103 const ServerView* new_parent, |
87 const ServerView* old_parent, | 104 const ServerView* old_parent, |
88 bool originated_change) { | 105 bool originated_change) { |
89 if (originated_change && !IsViewKnown(view) && new_parent && | 106 if (originated_change && !IsViewKnown(view) && new_parent && |
90 IsViewKnown(new_parent)) { | 107 IsViewKnown(new_parent)) { |
91 std::vector<const ServerView*> unused; | 108 std::vector<const ServerView*> unused; |
92 GetUnknownViewsFrom(view, &unused); | 109 GetUnknownViewsFrom(view, &unused); |
93 } | 110 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 152 |
136 if (originated_change) | 153 if (originated_change) |
137 return; | 154 return; |
138 | 155 |
139 if (in_known) { | 156 if (in_known) { |
140 client()->OnViewDeleted(ViewIdToTransportId(view)); | 157 client()->OnViewDeleted(ViewIdToTransportId(view)); |
141 connection_manager_->OnConnectionMessagedClient(id_); | 158 connection_manager_->OnConnectionMessagedClient(id_); |
142 } | 159 } |
143 } | 160 } |
144 | 161 |
| 162 void ViewManagerServiceImpl::ProcessWillChangeViewVisibility( |
| 163 const ServerView* view, |
| 164 bool originated_change) { |
| 165 if (originated_change) |
| 166 return; |
| 167 |
| 168 if (IsViewKnown(view)) { |
| 169 client()->OnViewVisibilityChanged(ViewIdToTransportId(view->id()), |
| 170 !view->visible()); |
| 171 return; |
| 172 } |
| 173 |
| 174 bool view_target_drawn_state; |
| 175 if (view->visible()) { |
| 176 // View is being hidden, won't be drawn. |
| 177 view_target_drawn_state = false; |
| 178 } else { |
| 179 // View is being shown. View will be drawn if its parent is drawn. |
| 180 view_target_drawn_state = |
| 181 view->parent() && view->parent()->IsDrawn(connection_manager_->root()); |
| 182 } |
| 183 |
| 184 NotifyDrawnStateChanged(view, view_target_drawn_state); |
| 185 } |
| 186 |
145 void ViewManagerServiceImpl::OnConnectionError() { | 187 void ViewManagerServiceImpl::OnConnectionError() { |
146 if (delete_on_connection_error_) | 188 if (delete_on_connection_error_) |
147 delete this; | 189 delete this; |
148 } | 190 } |
149 | 191 |
150 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const { | 192 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const { |
151 return known_views_.count(ViewIdToTransportId(view->id())) > 0; | 193 return known_views_.count(ViewIdToTransportId(view->id())) > 0; |
152 } | 194 } |
153 | 195 |
154 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view, | 196 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 DCHECK(IsViewKnown(view)); | 299 DCHECK(IsViewKnown(view)); |
258 const ServerView* parent = view->parent(); | 300 const ServerView* parent = view->parent(); |
259 // If the parent isn't known, it means the parent is not visible to us (not | 301 // If the parent isn't known, it means the parent is not visible to us (not |
260 // in roots), and should not be sent over. | 302 // in roots), and should not be sent over. |
261 if (parent && !IsViewKnown(parent)) | 303 if (parent && !IsViewKnown(parent)) |
262 parent = NULL; | 304 parent = NULL; |
263 ViewDataPtr view_data(ViewData::New()); | 305 ViewDataPtr view_data(ViewData::New()); |
264 view_data->parent_id = ViewIdToTransportId(parent ? parent->id() : ViewId()); | 306 view_data->parent_id = ViewIdToTransportId(parent ? parent->id() : ViewId()); |
265 view_data->view_id = ViewIdToTransportId(view->id()); | 307 view_data->view_id = ViewIdToTransportId(view->id()); |
266 view_data->bounds = Rect::From(view->bounds()); | 308 view_data->bounds = Rect::From(view->bounds()); |
| 309 view_data->visible = view->visible(); |
| 310 view_data->drawn = view->IsDrawn(connection_manager_->root()); |
267 return view_data.Pass(); | 311 return view_data.Pass(); |
268 } | 312 } |
269 | 313 |
270 void ViewManagerServiceImpl::GetViewTreeImpl( | 314 void ViewManagerServiceImpl::GetViewTreeImpl( |
271 const ServerView* view, | 315 const ServerView* view, |
272 std::vector<const ServerView*>* views) const { | 316 std::vector<const ServerView*>* views) const { |
273 DCHECK(view); | 317 DCHECK(view); |
274 | 318 |
275 if (!access_policy_->CanGetViewTree(view)) | 319 if (!access_policy_->CanGetViewTree(view)) |
276 return; | 320 return; |
277 | 321 |
278 views->push_back(view); | 322 views->push_back(view); |
279 | 323 |
280 if (!access_policy_->CanDescendIntoViewForViewTree(view)) | 324 if (!access_policy_->CanDescendIntoViewForViewTree(view)) |
281 return; | 325 return; |
282 | 326 |
283 std::vector<const ServerView*> children(view->GetChildren()); | 327 std::vector<const ServerView*> children(view->GetChildren()); |
284 for (size_t i = 0 ; i < children.size(); ++i) | 328 for (size_t i = 0 ; i < children.size(); ++i) |
285 GetViewTreeImpl(children[i], views); | 329 GetViewTreeImpl(children[i], views); |
286 } | 330 } |
287 | 331 |
| 332 void ViewManagerServiceImpl::NotifyDrawnStateChanged(const ServerView* view, |
| 333 bool new_drawn_value) { |
| 334 // Even though we don't know about view, it may be an ancestor of one of our |
| 335 // roots, in which case the change may effect our roots drawn state. |
| 336 for (ViewIdSet::iterator i = roots_.begin(); i != roots_.end(); ++i) { |
| 337 const ServerView* root = GetView(ViewIdFromTransportId(*i)); |
| 338 DCHECK(root); |
| 339 if (view->Contains(root) && |
| 340 (new_drawn_value != root->IsDrawn(connection_manager_->root()))) { |
| 341 client()->OnViewDrawnStateChanged(ViewIdToTransportId(root->id()), |
| 342 new_drawn_value); |
| 343 } |
| 344 } |
| 345 } |
| 346 |
288 void ViewManagerServiceImpl::CreateView( | 347 void ViewManagerServiceImpl::CreateView( |
289 Id transport_view_id, | 348 Id transport_view_id, |
290 const Callback<void(ErrorCode)>& callback) { | 349 const Callback<void(ErrorCode)>& callback) { |
291 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | 350 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
292 ErrorCode error_code = ERROR_CODE_NONE; | 351 ErrorCode error_code = ERROR_CODE_NONE; |
293 if (view_id.connection_id != id_) { | 352 if (view_id.connection_id != id_) { |
294 error_code = ERROR_CODE_ILLEGAL_ARGUMENT; | 353 error_code = ERROR_CODE_ILLEGAL_ARGUMENT; |
295 } else if (view_map_.find(view_id.view_id) != view_map_.end()) { | 354 } else if (view_map_.find(view_id.view_id) != view_map_.end()) { |
296 error_code = ERROR_CODE_VALUE_IN_USE; | 355 error_code = ERROR_CODE_VALUE_IN_USE; |
297 } else { | 356 } else { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 view->SetBounds(bounds.To<gfx::Rect>()); | 466 view->SetBounds(bounds.To<gfx::Rect>()); |
408 } | 467 } |
409 callback.Run(success); | 468 callback.Run(success); |
410 } | 469 } |
411 | 470 |
412 void ViewManagerServiceImpl::SetViewVisibility( | 471 void ViewManagerServiceImpl::SetViewVisibility( |
413 Id transport_view_id, | 472 Id transport_view_id, |
414 bool visible, | 473 bool visible, |
415 const Callback<void(bool)>& callback) { | 474 const Callback<void(bool)>& callback) { |
416 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); | 475 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); |
417 const bool success = view && view->visible() != visible && | 476 if (!view || view->visible() == visible || |
418 access_policy_->CanChangeViewVisibility(view); | 477 !access_policy_->CanChangeViewVisibility(view)) { |
419 if (success) { | 478 callback.Run(false); |
420 DCHECK(view); | 479 return; |
| 480 } |
| 481 { |
| 482 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
421 view->SetVisible(visible); | 483 view->SetVisible(visible); |
422 } | 484 } |
423 // TODO(sky): need to notify of visibility changes. | 485 callback.Run(true); |
424 callback.Run(success); | |
425 } | 486 } |
426 | 487 |
427 void ViewManagerServiceImpl::Embed( | 488 void ViewManagerServiceImpl::Embed( |
428 const String& url, | 489 const String& url, |
429 Id transport_view_id, | 490 Id transport_view_id, |
430 ServiceProviderPtr service_provider, | 491 ServiceProviderPtr service_provider, |
431 const Callback<void(bool)>& callback) { | 492 const Callback<void(bool)>& callback) { |
432 InterfaceRequest<ServiceProvider> spir; | 493 InterfaceRequest<ServiceProvider> spir; |
433 spir.Bind(service_provider.PassMessagePipe()); | 494 spir.Bind(service_provider.PassMessagePipe()); |
434 | 495 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 568 |
508 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( | 569 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( |
509 const ServerView* view) const { | 570 const ServerView* view) const { |
510 ViewManagerServiceImpl* connection = | 571 ViewManagerServiceImpl* connection = |
511 connection_manager_->GetConnectionWithRoot(view->id()); | 572 connection_manager_->GetConnectionWithRoot(view->id()); |
512 return connection && connection != this; | 573 return connection && connection != this; |
513 } | 574 } |
514 | 575 |
515 } // namespace service | 576 } // namespace service |
516 } // namespace mojo | 577 } // namespace mojo |
OLD | NEW |