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/default_access_policy.h" | 10 #include "mojo/services/view_manager/default_access_policy.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 135 |
136 if (originated_change) | 136 if (originated_change) |
137 return; | 137 return; |
138 | 138 |
139 if (in_known) { | 139 if (in_known) { |
140 client()->OnViewDeleted(NodeIdToTransportId(node)); | 140 client()->OnViewDeleted(NodeIdToTransportId(node)); |
141 root_node_manager_->OnConnectionMessagedClient(id_); | 141 root_node_manager_->OnConnectionMessagedClient(id_); |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 void ViewManagerServiceImpl::ProcessFocusChanged(const Node* focused_node, | |
146 const Node* blurred_node, | |
147 bool originated_change) { | |
148 if (originated_change) | |
149 return; | |
150 | |
151 // TODO(sky): this should not notify all clients. | |
152 Id focused_id = 0; | |
153 Id blurred_id = 0; | |
154 if (focused_node && IsNodeKnown(focused_node)) | |
155 focused_id = NodeIdToTransportId(focused_node->id()); | |
156 if (blurred_node && IsNodeKnown(blurred_node)) | |
157 blurred_id = NodeIdToTransportId(blurred_node->id()); | |
158 | |
159 if (focused_id != 0 || blurred_id != 0) | |
160 client()->OnFocusChanged(focused_id, blurred_id); | |
161 } | |
162 | |
163 void ViewManagerServiceImpl::OnConnectionError() { | 145 void ViewManagerServiceImpl::OnConnectionError() { |
164 if (delete_on_connection_error_) | 146 if (delete_on_connection_error_) |
165 delete this; | 147 delete this; |
166 } | 148 } |
167 | 149 |
168 bool ViewManagerServiceImpl::IsNodeKnown(const Node* node) const { | 150 bool ViewManagerServiceImpl::IsNodeKnown(const Node* node) const { |
169 return known_nodes_.count(NodeIdToTransportId(node->id())) > 0; | 151 return known_nodes_.count(NodeIdToTransportId(node->id())) > 0; |
170 } | 152 } |
171 | 153 |
172 bool ViewManagerServiceImpl::CanReorderNode(const Node* node, | 154 bool ViewManagerServiceImpl::CanReorderNode(const Node* node, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 return; | 414 return; |
433 } | 415 } |
434 SkBitmap bitmap; | 416 SkBitmap bitmap; |
435 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(handle_data), | 417 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(handle_data), |
436 buffer_size, &bitmap); | 418 buffer_size, &bitmap); |
437 node->SetBitmap(bitmap); | 419 node->SetBitmap(bitmap); |
438 UnmapBuffer(handle_data); | 420 UnmapBuffer(handle_data); |
439 callback.Run(true); | 421 callback.Run(true); |
440 } | 422 } |
441 | 423 |
442 void ViewManagerServiceImpl::SetFocus(Id view_id, | |
443 const Callback<void(bool)> & callback) { | |
444 bool success = false; | |
445 Node* node = GetNode(NodeIdFromTransportId(view_id)); | |
446 if (node && access_policy_->CanSetFocus(node)) { | |
447 success = true; | |
448 node->window()->Focus(); | |
449 } | |
450 callback.Run(success); | |
451 } | |
452 | |
453 void ViewManagerServiceImpl::SetViewBounds( | 424 void ViewManagerServiceImpl::SetViewBounds( |
454 Id view_id, | 425 Id view_id, |
455 RectPtr bounds, | 426 RectPtr bounds, |
456 const Callback<void(bool)>& callback) { | 427 const Callback<void(bool)>& callback) { |
457 Node* node = GetNode(NodeIdFromTransportId(view_id)); | 428 Node* node = GetNode(NodeIdFromTransportId(view_id)); |
458 const bool success = node && access_policy_->CanSetNodeBounds(node); | 429 const bool success = node && access_policy_->CanSetNodeBounds(node); |
459 if (success) { | 430 if (success) { |
460 RootNodeManager::ScopedChange change(this, root_node_manager_, false); | 431 RootNodeManager::ScopedChange change(this, root_node_manager_, false); |
461 gfx::Rect old_bounds = node->window()->bounds(); | 432 gfx::Rect old_bounds = node->window()->bounds(); |
462 node->window()->SetBounds(bounds.To<gfx::Rect>()); | 433 node->window()->SetBounds(bounds.To<gfx::Rect>()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 539 |
569 bool ViewManagerServiceImpl::IsNodeRootOfAnotherConnectionForAccessPolicy( | 540 bool ViewManagerServiceImpl::IsNodeRootOfAnotherConnectionForAccessPolicy( |
570 const Node* node) const { | 541 const Node* node) const { |
571 ViewManagerServiceImpl* connection = | 542 ViewManagerServiceImpl* connection = |
572 root_node_manager_->GetConnectionWithRoot(node->id()); | 543 root_node_manager_->GetConnectionWithRoot(node->id()); |
573 return connection && connection != this; | 544 return connection && connection != this; |
574 } | 545 } |
575 | 546 |
576 } // namespace service | 547 } // namespace service |
577 } // namespace mojo | 548 } // namespace mojo |
OLD | NEW |