Chromium Code Reviews

Side by Side Diff: mojo/services/view_manager/cpp/lib/view_manager_client_impl.cc

Issue 1391243003: Move //mojo/services/X/public/... to //mojo/services/X/... (part 4). (Closed) Base URL: https://github.com/domokit/mojo.git@no_public_3-x-no_public_2-x-no_public_1
Patch Set: copyright header Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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 "view_manager/public/cpp/lib/view_manager_client_impl.h" 5 #include "view_manager/cpp/lib/view_manager_client_impl.h"
6 6
7 #include "mojo/public/cpp/application/application_impl.h" 7 #include "mojo/public/cpp/application/application_impl.h"
8 #include "mojo/public/cpp/application/connect.h" 8 #include "mojo/public/cpp/application/connect.h"
9 #include "mojo/public/cpp/application/service_provider_impl.h" 9 #include "mojo/public/cpp/application/service_provider_impl.h"
10 #include "mojo/public/interfaces/application/service_provider.mojom.h" 10 #include "mojo/public/interfaces/application/service_provider.mojom.h"
11 #include "mojo/public/interfaces/application/shell.mojom.h" 11 #include "mojo/public/interfaces/application/shell.mojom.h"
12 #include "view_manager/public/cpp/lib/view_private.h" 12 #include "view_manager/cpp/lib/view_private.h"
13 #include "view_manager/public/cpp/util.h" 13 #include "view_manager/cpp/util.h"
14 #include "view_manager/public/cpp/view_manager_delegate.h" 14 #include "view_manager/cpp/view_manager_delegate.h"
15 #include "view_manager/public/cpp/view_observer.h" 15 #include "view_manager/cpp/view_observer.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;
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* AddViewToViewManager(ViewManagerClientImpl* client, 25 View* AddViewToViewManager(ViewManagerClientImpl* client,
(...skipping 111 matching lines...)
137 void ViewManagerClientImpl::AddChild(Id child_id, Id parent_id) { 137 void ViewManagerClientImpl::AddChild(Id child_id, Id parent_id) {
138 DCHECK(service_); 138 DCHECK(service_);
139 service_->AddView(parent_id, child_id, ActionCompletedCallback()); 139 service_->AddView(parent_id, child_id, ActionCompletedCallback());
140 } 140 }
141 141
142 void ViewManagerClientImpl::RemoveChild(Id child_id, Id parent_id) { 142 void ViewManagerClientImpl::RemoveChild(Id child_id, Id parent_id) {
143 DCHECK(service_); 143 DCHECK(service_);
144 service_->RemoveViewFromParent(child_id, ActionCompletedCallback()); 144 service_->RemoveViewFromParent(child_id, ActionCompletedCallback());
145 } 145 }
146 146
147 void ViewManagerClientImpl::Reorder( 147 void ViewManagerClientImpl::Reorder(Id view_id,
148 Id view_id, 148 Id relative_view_id,
149 Id relative_view_id, 149 OrderDirection direction) {
150 OrderDirection direction) {
151 DCHECK(service_); 150 DCHECK(service_);
152 service_->ReorderView(view_id, relative_view_id, direction, 151 service_->ReorderView(view_id, relative_view_id, direction,
153 ActionCompletedCallback()); 152 ActionCompletedCallback());
154 } 153 }
155 154
156 bool ViewManagerClientImpl::OwnsView(Id id) const { 155 bool ViewManagerClientImpl::OwnsView(Id id) const {
157 return HiWord(id) == connection_id_; 156 return HiWord(id) == connection_id_;
158 } 157 }
159 158
160 void ViewManagerClientImpl::SetBounds(Id view_id, const Rect& bounds) { 159 void ViewManagerClientImpl::SetBounds(Id view_id, const Rect& bounds) {
161 DCHECK(service_); 160 DCHECK(service_);
162 service_->SetViewBounds(view_id, bounds.Clone(), ActionCompletedCallback()); 161 service_->SetViewBounds(view_id, bounds.Clone(), ActionCompletedCallback());
163 } 162 }
164 163
165 void ViewManagerClientImpl::SetSurfaceId(Id view_id, SurfaceIdPtr surface_id) { 164 void ViewManagerClientImpl::SetSurfaceId(Id view_id, SurfaceIdPtr surface_id) {
166 DCHECK(service_); 165 DCHECK(service_);
167 if (surface_id.is_null()) 166 if (surface_id.is_null())
168 return; 167 return;
169 service_->SetViewSurfaceId( 168 service_->SetViewSurfaceId(view_id, surface_id.Pass(),
170 view_id, surface_id.Pass(), ActionCompletedCallback()); 169 ActionCompletedCallback());
171 } 170 }
172 171
173 void ViewManagerClientImpl::SetFocus(Id view_id) { 172 void ViewManagerClientImpl::SetFocus(Id view_id) {
174 // In order for us to get here we had to have exposed a view, which implies we 173 // In order for us to get here we had to have exposed a view, which implies we
175 // got a connection. 174 // got a connection.
176 DCHECK(service_); 175 DCHECK(service_);
177 service_->PerformAction(view_id, "focus", ActionCompletedCallback()); 176 service_->PerformAction(view_id, "focus", ActionCompletedCallback());
178 } 177 }
179 178
180 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { 179 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) {
181 DCHECK(service_); 180 DCHECK(service_);
182 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); 181 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback());
183 } 182 }
184 183
185 void ViewManagerClientImpl::SetProperty( 184 void ViewManagerClientImpl::SetProperty(Id view_id,
186 Id view_id, 185 const std::string& name,
187 const std::string& name, 186 const std::vector<uint8_t>& data) {
188 const std::vector<uint8_t>& data) {
189 DCHECK(service_); 187 DCHECK(service_);
190 service_->SetViewProperty(view_id, 188 service_->SetViewProperty(view_id, String(name), Array<uint8_t>::From(data),
191 String(name),
192 Array<uint8_t>::From(data),
193 ActionCompletedCallback()); 189 ActionCompletedCallback());
194 } 190 }
195 191
196 void ViewManagerClientImpl::Embed(const String& url, Id view_id) { 192 void ViewManagerClientImpl::Embed(const String& url, Id view_id) {
197 Embed(url, view_id, nullptr, nullptr); 193 Embed(url, view_id, nullptr, nullptr);
198 } 194 }
199 195
200 void ViewManagerClientImpl::Embed(const String& url, 196 void ViewManagerClientImpl::Embed(const String& url,
201 Id view_id, 197 Id view_id,
202 InterfaceRequest<ServiceProvider> services, 198 InterfaceRequest<ServiceProvider> services,
(...skipping 143 matching lines...)
346 View* view = GetRoot(); 342 View* view = GetRoot();
347 if (view) 343 if (view)
348 SetViewportMetricsOnDecendants(view, *old_metrics, *new_metrics); 344 SetViewportMetricsOnDecendants(view, *old_metrics, *new_metrics);
349 } 345 }
350 346
351 void ViewManagerClientImpl::OnViewHierarchyChanged( 347 void ViewManagerClientImpl::OnViewHierarchyChanged(
352 Id view_id, 348 Id view_id,
353 Id new_parent_id, 349 Id new_parent_id,
354 Id old_parent_id, 350 Id old_parent_id,
355 mojo::Array<ViewDataPtr> views) { 351 mojo::Array<ViewDataPtr> views) {
356 View* initial_parent = views.size() ? 352 View* initial_parent = views.size() ? GetViewById(views[0]->parent_id) : NULL;
357 GetViewById(views[0]->parent_id) : NULL;
358 353
359 BuildViewTree(this, views, initial_parent); 354 BuildViewTree(this, views, initial_parent);
360 355
361 View* new_parent = GetViewById(new_parent_id); 356 View* new_parent = GetViewById(new_parent_id);
362 View* old_parent = GetViewById(old_parent_id); 357 View* old_parent = GetViewById(old_parent_id);
363 View* view = GetViewById(view_id); 358 View* view = GetViewById(view_id);
364 if (new_parent) 359 if (new_parent)
365 ViewPrivate(new_parent).LocalAddChild(view); 360 ViewPrivate(new_parent).LocalAddChild(view);
366 else 361 else
367 ViewPrivate(old_parent).LocalRemoveChild(view); 362 ViewPrivate(old_parent).LocalRemoveChild(view);
(...skipping 45 matching lines...)
413 view->SetSharedProperty(name, data_ptr); 408 view->SetSharedProperty(name, data_ptr);
414 } 409 }
415 } 410 }
416 411
417 void ViewManagerClientImpl::OnViewInputEvent( 412 void ViewManagerClientImpl::OnViewInputEvent(
418 Id view_id, 413 Id view_id,
419 EventPtr event, 414 EventPtr event,
420 const Callback<void()>& ack_callback) { 415 const Callback<void()>& ack_callback) {
421 View* view = GetViewById(view_id); 416 View* view = GetViewById(view_id);
422 if (view) { 417 if (view) {
423 FOR_EACH_OBSERVER(ViewObserver, 418 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(),
424 *ViewPrivate(view).observers(),
425 OnViewInputEvent(view, event)); 419 OnViewInputEvent(view, event));
426 } 420 }
427 ack_callback.Run(); 421 ack_callback.Run();
428 } 422 }
429 423
430 void ViewManagerClientImpl::OnPerformAction( 424 void ViewManagerClientImpl::OnPerformAction(
431 Id view_id, 425 Id view_id,
432 const String& name, 426 const String& name,
433 const Callback<void(bool)>& callback) { 427 const Callback<void(bool)>& callback) {
434 View* view = GetViewById(view_id); 428 View* view = GetViewById(view_id);
435 callback.Run(delegate_->OnPerformAction(view, name)); 429 callback.Run(delegate_->OnPerformAction(view, name));
436 } 430 }
437 431
438 //////////////////////////////////////////////////////////////////////////////// 432 ////////////////////////////////////////////////////////////////////////////////
439 // ViewManagerClientImpl, WindowManagerObserver implementation: 433 // ViewManagerClientImpl, WindowManagerObserver implementation:
440 434
441 void ViewManagerClientImpl::OnCaptureChanged(Id capture_view_id) { 435 void ViewManagerClientImpl::OnCaptureChanged(Id capture_view_id) {
442 View* gained_capture = GetViewById(capture_view_id); 436 View* gained_capture = GetViewById(capture_view_id);
443 View* lost_capture = capture_view_; 437 View* lost_capture = capture_view_;
444 if (lost_capture) { 438 if (lost_capture) {
445 FOR_EACH_OBSERVER(ViewObserver, 439 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(lost_capture).observers(),
446 *ViewPrivate(lost_capture).observers(),
447 OnViewFocusChanged(gained_capture, lost_capture)); 440 OnViewFocusChanged(gained_capture, lost_capture));
448 } 441 }
449 capture_view_ = gained_capture; 442 capture_view_ = gained_capture;
450 if (gained_capture) { 443 if (gained_capture) {
451 FOR_EACH_OBSERVER(ViewObserver, 444 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(gained_capture).observers(),
452 *ViewPrivate(gained_capture).observers(),
453 OnViewFocusChanged(gained_capture, lost_capture)); 445 OnViewFocusChanged(gained_capture, lost_capture));
454 } 446 }
455 } 447 }
456 448
457 void ViewManagerClientImpl::OnFocusChanged(Id focused_view_id) { 449 void ViewManagerClientImpl::OnFocusChanged(Id focused_view_id) {
458 View* focused = GetViewById(focused_view_id); 450 View* focused = GetViewById(focused_view_id);
459 View* blurred = focused_view_; 451 View* blurred = focused_view_;
460 if (blurred) { 452 if (blurred) {
461 FOR_EACH_OBSERVER(ViewObserver, 453 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(blurred).observers(),
462 *ViewPrivate(blurred).observers(),
463 OnViewFocusChanged(focused, blurred)); 454 OnViewFocusChanged(focused, blurred));
464 } 455 }
465 focused_view_ = focused; 456 focused_view_ = focused;
466 if (focused) { 457 if (focused) {
467 FOR_EACH_OBSERVER(ViewObserver, 458 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(focused).observers(),
468 *ViewPrivate(focused).observers(),
469 OnViewFocusChanged(focused, blurred)); 459 OnViewFocusChanged(focused, blurred));
470 } 460 }
471 } 461 }
472 462
473 void ViewManagerClientImpl::OnActiveWindowChanged(Id active_view_id) { 463 void ViewManagerClientImpl::OnActiveWindowChanged(Id active_view_id) {
474 View* activated = GetViewById(active_view_id); 464 View* activated = GetViewById(active_view_id);
475 View* deactivated = activated_view_; 465 View* deactivated = activated_view_;
476 if (deactivated) { 466 if (deactivated) {
477 FOR_EACH_OBSERVER(ViewObserver, 467 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(deactivated).observers(),
478 *ViewPrivate(deactivated).observers(),
479 OnViewActivationChanged(activated, deactivated)); 468 OnViewActivationChanged(activated, deactivated));
480 } 469 }
481 activated_view_ = activated; 470 activated_view_ = activated;
482 if (activated) { 471 if (activated) {
483 FOR_EACH_OBSERVER(ViewObserver, 472 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(activated).observers(),
484 *ViewPrivate(activated).observers(),
485 OnViewActivationChanged(activated, deactivated)); 473 OnViewActivationChanged(activated, deactivated));
486 } 474 }
487 } 475 }
488 476
489 //////////////////////////////////////////////////////////////////////////////// 477 ////////////////////////////////////////////////////////////////////////////////
490 // ViewManagerClientImpl, private: 478 // ViewManagerClientImpl, private:
491 479
492 void ViewManagerClientImpl::RootDestroyed(View* root) { 480 void ViewManagerClientImpl::RootDestroyed(View* root) {
493 DCHECK_EQ(root, root_); 481 DCHECK_EQ(root, root_);
494 root_ = nullptr; 482 root_ = nullptr;
495 } 483 }
496 484
497 void ViewManagerClientImpl::OnActionCompleted(bool success) { 485 void ViewManagerClientImpl::OnActionCompleted(bool success) {
498 if (!change_acked_callback_.is_null()) 486 if (!change_acked_callback_.is_null())
499 change_acked_callback_.Run(); 487 change_acked_callback_.Run();
500 } 488 }
501 489
502 Callback<void(bool)> ViewManagerClientImpl::ActionCompletedCallback() { 490 Callback<void(bool)> ViewManagerClientImpl::ActionCompletedCallback() {
503 return [this](bool success) { OnActionCompleted(success); }; 491 return [this](bool success) { OnActionCompleted(success); };
504 } 492 }
505 493
506 } // namespace mojo 494 } // namespace mojo
OLDNEW

Powered by Google App Engine