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/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/view_manager/public/cpp/lib/view_private.h" | 7 #include "components/mus/public/cpp/lib/view_private.h" |
8 #include "components/view_manager/public/cpp/util.h" | 8 #include "components/mus/public/cpp/util.h" |
9 #include "components/view_manager/public/cpp/view_observer.h" | 9 #include "components/mus/public/cpp/view_observer.h" |
10 #include "components/view_manager/public/cpp/view_tree_connection.h" | 10 #include "components/mus/public/cpp/view_tree_connection.h" |
11 #include "components/view_manager/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 mojo { |
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; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 InterfaceRequest<ViewTreeClient> request) { |
74 return new ViewTreeClientImpl(delegate, request.Pass()); | 74 return new ViewTreeClientImpl(delegate, request.Pass()); |
75 } | 75 } |
76 | 76 |
77 ViewTreeClientImpl::ViewTreeClientImpl( | 77 ViewTreeClientImpl::ViewTreeClientImpl(ViewTreeDelegate* delegate, |
78 ViewTreeDelegate* delegate, | 78 InterfaceRequest<ViewTreeClient> request) |
79 InterfaceRequest<ViewTreeClient> request) | |
80 : connection_id_(0), | 79 : connection_id_(0), |
81 next_id_(1), | 80 next_id_(1), |
82 delegate_(delegate), | 81 delegate_(delegate), |
83 root_(nullptr), | 82 root_(nullptr), |
84 capture_view_(nullptr), | 83 capture_view_(nullptr), |
85 focused_view_(nullptr), | 84 focused_view_(nullptr), |
86 activated_view_(nullptr), | 85 activated_view_(nullptr), |
87 binding_(this, request.Pass()), | 86 binding_(this, request.Pass()), |
88 is_embed_root_(false), | 87 is_embed_root_(false), |
89 in_destructor_(false) { | 88 in_destructor_(false) {} |
90 } | |
91 | 89 |
92 ViewTreeClientImpl::~ViewTreeClientImpl() { | 90 ViewTreeClientImpl::~ViewTreeClientImpl() { |
93 in_destructor_ = true; | 91 in_destructor_ = true; |
94 | 92 |
95 std::vector<View*> non_owned; | 93 std::vector<View*> non_owned; |
96 while (!views_.empty()) { | 94 while (!views_.empty()) { |
97 IdToViewMap::iterator it = views_.begin(); | 95 IdToViewMap::iterator it = views_.begin(); |
98 if (OwnsView(it->second->id())) { | 96 if (OwnsView(it->second->id())) { |
99 it->second->Destroy(); | 97 it->second->Destroy(); |
100 } else { | 98 } else { |
(...skipping 20 matching lines...) Expand all Loading... |
121 void ViewTreeClientImpl::AddChild(Id child_id, Id parent_id) { | 119 void ViewTreeClientImpl::AddChild(Id child_id, Id parent_id) { |
122 DCHECK(tree_); | 120 DCHECK(tree_); |
123 tree_->AddView(parent_id, child_id, ActionCompletedCallback()); | 121 tree_->AddView(parent_id, child_id, ActionCompletedCallback()); |
124 } | 122 } |
125 | 123 |
126 void ViewTreeClientImpl::RemoveChild(Id child_id, Id parent_id) { | 124 void ViewTreeClientImpl::RemoveChild(Id child_id, Id parent_id) { |
127 DCHECK(tree_); | 125 DCHECK(tree_); |
128 tree_->RemoveViewFromParent(child_id, ActionCompletedCallback()); | 126 tree_->RemoveViewFromParent(child_id, ActionCompletedCallback()); |
129 } | 127 } |
130 | 128 |
131 void ViewTreeClientImpl::Reorder( | 129 void ViewTreeClientImpl::Reorder(Id view_id, |
132 Id view_id, | 130 Id relative_view_id, |
133 Id relative_view_id, | 131 OrderDirection direction) { |
134 OrderDirection direction) { | |
135 DCHECK(tree_); | 132 DCHECK(tree_); |
136 tree_->ReorderView(view_id, relative_view_id, direction, | 133 tree_->ReorderView(view_id, relative_view_id, direction, |
137 ActionCompletedCallback()); | 134 ActionCompletedCallback()); |
138 } | 135 } |
139 | 136 |
140 bool ViewTreeClientImpl::OwnsView(Id id) const { | 137 bool ViewTreeClientImpl::OwnsView(Id id) const { |
141 return HiWord(id) == connection_id_; | 138 return HiWord(id) == connection_id_; |
142 } | 139 } |
143 | 140 |
144 void ViewTreeClientImpl::SetBounds(Id view_id, const Rect& bounds) { | 141 void ViewTreeClientImpl::SetBounds(Id view_id, const Rect& bounds) { |
145 DCHECK(tree_); | 142 DCHECK(tree_); |
146 tree_->SetViewBounds(view_id, bounds.Clone(), ActionCompletedCallback()); | 143 tree_->SetViewBounds(view_id, bounds.Clone(), ActionCompletedCallback()); |
147 } | 144 } |
148 | 145 |
149 void ViewTreeClientImpl::SetFocus(Id view_id) { | 146 void ViewTreeClientImpl::SetFocus(Id view_id) { |
150 // In order for us to get here we had to have exposed a view, which implies we | 147 // In order for us to get here we had to have exposed a view, which implies we |
151 // got a connection. | 148 // got a connection. |
152 DCHECK(tree_); | 149 DCHECK(tree_); |
153 tree_->SetFocus(view_id); | 150 tree_->SetFocus(view_id); |
154 } | 151 } |
155 | 152 |
156 void ViewTreeClientImpl::SetVisible(Id view_id, bool visible) { | 153 void ViewTreeClientImpl::SetVisible(Id view_id, bool visible) { |
157 DCHECK(tree_); | 154 DCHECK(tree_); |
158 tree_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); | 155 tree_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); |
159 } | 156 } |
160 | 157 |
161 void ViewTreeClientImpl::SetProperty( | 158 void ViewTreeClientImpl::SetProperty(Id view_id, |
162 Id view_id, | 159 const std::string& name, |
163 const std::string& name, | 160 const std::vector<uint8_t>& data) { |
164 const std::vector<uint8_t>& data) { | |
165 DCHECK(tree_); | 161 DCHECK(tree_); |
166 tree_->SetViewProperty(view_id, | 162 tree_->SetViewProperty(view_id, String(name), Array<uint8_t>::From(data), |
167 String(name), | |
168 Array<uint8_t>::From(data), | |
169 ActionCompletedCallback()); | 163 ActionCompletedCallback()); |
170 } | 164 } |
171 | 165 |
172 void ViewTreeClientImpl::SetViewTextInputState(Id view_id, | 166 void ViewTreeClientImpl::SetViewTextInputState(Id view_id, |
173 TextInputStatePtr state) { | 167 TextInputStatePtr state) { |
174 DCHECK(tree_); | 168 DCHECK(tree_); |
175 tree_->SetViewTextInputState(view_id, state.Pass()); | 169 tree_->SetViewTextInputState(view_id, state.Pass()); |
176 } | 170 } |
177 | 171 |
178 void ViewTreeClientImpl::SetImeVisibility(Id view_id, | 172 void ViewTreeClientImpl::SetImeVisibility(Id view_id, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 View* view = GetRoot(); | 321 View* view = GetRoot(); |
328 if (view) | 322 if (view) |
329 SetViewportMetricsOnDecendants(view, *old_metrics, *new_metrics); | 323 SetViewportMetricsOnDecendants(view, *old_metrics, *new_metrics); |
330 } | 324 } |
331 | 325 |
332 void ViewTreeClientImpl::OnViewHierarchyChanged( | 326 void ViewTreeClientImpl::OnViewHierarchyChanged( |
333 Id view_id, | 327 Id view_id, |
334 Id new_parent_id, | 328 Id new_parent_id, |
335 Id old_parent_id, | 329 Id old_parent_id, |
336 mojo::Array<ViewDataPtr> views) { | 330 mojo::Array<ViewDataPtr> views) { |
337 View* initial_parent = views.size() ? | 331 View* initial_parent = views.size() ? GetViewById(views[0]->parent_id) : NULL; |
338 GetViewById(views[0]->parent_id) : NULL; | |
339 | 332 |
340 const bool was_view_known = GetViewById(view_id) != nullptr; | 333 const bool was_view_known = GetViewById(view_id) != nullptr; |
341 | 334 |
342 BuildViewTree(this, views, initial_parent); | 335 BuildViewTree(this, views, initial_parent); |
343 | 336 |
344 // If the view was not known, then BuildViewTree() will have created it and | 337 // If the view was not known, then BuildViewTree() will have created it and |
345 // parented the view. | 338 // parented the view. |
346 if (!was_view_known) | 339 if (!was_view_known) |
347 return; | 340 return; |
348 | 341 |
(...skipping 29 matching lines...) Expand all Loading... |
378 if (view) | 371 if (view) |
379 ViewPrivate(view).LocalSetVisible(visible); | 372 ViewPrivate(view).LocalSetVisible(visible); |
380 } | 373 } |
381 | 374 |
382 void ViewTreeClientImpl::OnViewDrawnStateChanged(Id view_id, bool drawn) { | 375 void ViewTreeClientImpl::OnViewDrawnStateChanged(Id view_id, bool drawn) { |
383 View* view = GetViewById(view_id); | 376 View* view = GetViewById(view_id); |
384 if (view) | 377 if (view) |
385 ViewPrivate(view).LocalSetDrawn(drawn); | 378 ViewPrivate(view).LocalSetDrawn(drawn); |
386 } | 379 } |
387 | 380 |
388 void ViewTreeClientImpl::OnViewSharedPropertyChanged( | 381 void ViewTreeClientImpl::OnViewSharedPropertyChanged(Id view_id, |
389 Id view_id, | 382 const String& name, |
390 const String& name, | 383 Array<uint8_t> new_data) { |
391 Array<uint8_t> new_data) { | |
392 View* view = GetViewById(view_id); | 384 View* view = GetViewById(view_id); |
393 if (view) { | 385 if (view) { |
394 std::vector<uint8_t> data; | 386 std::vector<uint8_t> data; |
395 std::vector<uint8_t>* data_ptr = NULL; | 387 std::vector<uint8_t>* data_ptr = NULL; |
396 if (!new_data.is_null()) { | 388 if (!new_data.is_null()) { |
397 data = new_data.To<std::vector<uint8_t>>(); | 389 data = new_data.To<std::vector<uint8_t>>(); |
398 data_ptr = &data; | 390 data_ptr = &data; |
399 } | 391 } |
400 | 392 |
401 view->SetSharedProperty(name, data_ptr); | 393 view->SetSharedProperty(name, data_ptr); |
402 } | 394 } |
403 } | 395 } |
404 | 396 |
405 void ViewTreeClientImpl::OnViewInputEvent( | 397 void ViewTreeClientImpl::OnViewInputEvent( |
406 Id view_id, | 398 Id view_id, |
407 EventPtr event, | 399 EventPtr event, |
408 const Callback<void()>& ack_callback) { | 400 const Callback<void()>& ack_callback) { |
409 View* view = GetViewById(view_id); | 401 View* view = GetViewById(view_id); |
410 if (view) { | 402 if (view) { |
411 FOR_EACH_OBSERVER(ViewObserver, | 403 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(), |
412 *ViewPrivate(view).observers(), | |
413 OnViewInputEvent(view, event)); | 404 OnViewInputEvent(view, event)); |
414 } | 405 } |
415 ack_callback.Run(); | 406 ack_callback.Run(); |
416 } | 407 } |
417 | 408 |
418 void ViewTreeClientImpl::OnViewFocused(Id focused_view_id) { | 409 void ViewTreeClientImpl::OnViewFocused(Id focused_view_id) { |
419 View* focused = GetViewById(focused_view_id); | 410 View* focused = GetViewById(focused_view_id); |
420 View* blurred = focused_view_; | 411 View* blurred = focused_view_; |
421 // Update |focused_view_| before calling any of the observers, so that the | 412 // Update |focused_view_| before calling any of the observers, so that the |
422 // observers get the correct result from calling |View::HasFocus()|, | 413 // observers get the correct result from calling |View::HasFocus()|, |
(...skipping 15 matching lines...) Expand all Loading... |
438 void ViewTreeClientImpl::OnActionCompleted(bool success) { | 429 void ViewTreeClientImpl::OnActionCompleted(bool success) { |
439 if (!change_acked_callback_.is_null()) | 430 if (!change_acked_callback_.is_null()) |
440 change_acked_callback_.Run(); | 431 change_acked_callback_.Run(); |
441 } | 432 } |
442 | 433 |
443 Callback<void(bool)> ViewTreeClientImpl::ActionCompletedCallback() { | 434 Callback<void(bool)> ViewTreeClientImpl::ActionCompletedCallback() { |
444 return [this](bool success) { OnActionCompleted(success); }; | 435 return [this](bool success) { OnActionCompleted(success); }; |
445 } | 436 } |
446 | 437 |
447 } // namespace mojo | 438 } // namespace mojo |
OLD | NEW |