Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(881)

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

Issue 782693004: Update mojo sdk to rev f6c8ec07c01deebc13178d516225fd12695c3dc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack mojo_system_impl gypi for android :| Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 "mojo/services/public/cpp/view_manager/view.h" 5 #include "mojo/services/public/cpp/view_manager/view.h"
6 6
7 #include <set>
8
7 #include "mojo/public/cpp/application/service_provider_impl.h" 9 #include "mojo/public/cpp/application/service_provider_impl.h"
8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" 10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h"
9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" 11 #include "mojo/services/public/cpp/view_manager/lib/view_private.h"
10 #include "mojo/services/public/cpp/view_manager/view_observer.h" 12 #include "mojo/services/public/cpp/view_manager/view_observer.h"
13 #include "mojo/services/public/cpp/view_manager/view_tracker.h"
11 14
12 namespace mojo { 15 namespace mojo {
13 16
14 namespace { 17 namespace {
15 18
16 void NotifyViewTreeChangeAtReceiver( 19 void NotifyViewTreeChangeAtReceiver(
17 View* receiver, 20 View* receiver,
18 const ViewObserver::TreeChangeParams& params, 21 const ViewObserver::TreeChangeParams& params,
19 bool change_applied) { 22 bool change_applied) {
20 ViewObserver::TreeChangeParams local_params = params; 23 ViewObserver::TreeChangeParams local_params = params;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 221 }
219 222
220 void View::SetVisible(bool value) { 223 void View::SetVisible(bool value) {
221 if (visible_ == value) 224 if (visible_ == value)
222 return; 225 return;
223 226
224 if (manager_) 227 if (manager_)
225 static_cast<ViewManagerClientImpl*>(manager_)->SetVisible(id_, value); 228 static_cast<ViewManagerClientImpl*>(manager_)->SetVisible(id_, value);
226 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanging(this)); 229 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanging(this));
227 visible_ = value; 230 visible_ = value;
228 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanged(this)); 231 NotifyViewVisibilityChanged(this);
229 } 232 }
230 233
231 void View::SetSharedProperty(const std::string& name, 234 void View::SetSharedProperty(const std::string& name,
232 const std::vector<uint8_t>* value) { 235 const std::vector<uint8_t>* value) {
233 std::vector<uint8_t> old_value; 236 std::vector<uint8_t> old_value;
234 std::vector<uint8_t>* old_value_ptr = nullptr; 237 std::vector<uint8_t>* old_value_ptr = nullptr;
235 auto it = properties_.find(name); 238 auto it = properties_.find(name);
236 if (it != properties_.end()) { 239 if (it != properties_.end()) {
237 old_value = it->second; 240 old_value = it->second;
238 old_value_ptr = &old_value; 241 old_value_ptr = &old_value;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // notification is the value of IsDrawn() is really changing. 499 // notification is the value of IsDrawn() is really changing.
497 if (IsDrawn() == value) { 500 if (IsDrawn() == value) {
498 drawn_ = value; 501 drawn_ = value;
499 return; 502 return;
500 } 503 }
501 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanging(this)); 504 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanging(this));
502 drawn_ = value; 505 drawn_ = value;
503 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanged(this)); 506 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanged(this));
504 } 507 }
505 508
509 void View::NotifyViewVisibilityChanged(View* target) {
510 if (!NotifyViewVisibilityChangedDown(target)) {
511 return; // |this| has been deleted.
512 }
513 NotifyViewVisibilityChangedUp(target);
514 }
515
516 bool View::NotifyViewVisibilityChangedAtReceiver(View* target) {
517 // |this| may be deleted during a call to OnViewVisibilityChanged() on one
518 // of the observers. We create an local observer for that. In that case we
519 // exit without further access to any members.
520 ViewTracker tracker;
521 tracker.Add(this);
522 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanged(target));
523 return tracker.Contains(this);
524 }
525
526 bool View::NotifyViewVisibilityChangedDown(View* target) {
527 if (!NotifyViewVisibilityChangedAtReceiver(target))
528 return false; // |this| was deleted.
529 std::set<const View*> child_already_processed;
530 bool child_destroyed = false;
531 do {
532 child_destroyed = false;
533 for (View::Children::const_iterator it = children_.begin();
534 it != children_.end(); ++it) {
535 if (!child_already_processed.insert(*it).second)
536 continue;
537 if (!(*it)->NotifyViewVisibilityChangedDown(target)) {
538 // |*it| was deleted, |it| is invalid and |children_| has changed. We
539 // exit the current for-loop and enter a new one.
540 child_destroyed = true;
541 break;
542 }
543 }
544 } while (child_destroyed);
545 return true;
546 }
547
548 void View::NotifyViewVisibilityChangedUp(View* target) {
549 // Start with the parent as we already notified |this|
550 // in NotifyViewVisibilityChangedDown.
551 for (View* view = parent(); view; view = view->parent()) {
552 bool ret = view->NotifyViewVisibilityChangedAtReceiver(target);
553 DCHECK(ret);
554 }
555 }
556
506 } // namespace mojo 557 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698