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

Side by Side Diff: components/view_manager/server_view_drawn_tracker.cc

Issue 1344573002: Mandoline: Rename components/view_manager to components/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 months 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/view_manager/server_view_drawn_tracker.h"
6
7 #include "components/view_manager/server_view.h"
8 #include "components/view_manager/server_view_drawn_tracker_observer.h"
9
10 namespace view_manager {
11
12 ServerViewDrawnTracker::ServerViewDrawnTracker(
13 ServerView* view,
14 ServerViewDrawnTrackerObserver* observer)
15 : view_(view), observer_(observer), drawn_(view->IsDrawn()) {
16 AddObservers();
17 }
18
19 ServerViewDrawnTracker::~ServerViewDrawnTracker() {
20 RemoveObservers();
21 }
22
23 void ServerViewDrawnTracker::SetDrawn(ServerView* ancestor, bool drawn) {
24 if (drawn == drawn_)
25 return;
26
27 drawn_ = drawn;
28 observer_->OnDrawnStateChanged(ancestor, view_, drawn);
29 }
30
31 void ServerViewDrawnTracker::AddObservers() {
32 if (!view_)
33 return;
34
35 for (ServerView* v = view_; v; v = v->parent()) {
36 v->AddObserver(this);
37 views_.insert(v);
38 }
39 }
40
41 void ServerViewDrawnTracker::RemoveObservers() {
42 for (ServerView* view : views_)
43 view->RemoveObserver(this);
44
45 views_.clear();
46 }
47
48 void ServerViewDrawnTracker::OnViewDestroyed(ServerView* view) {
49 // As views are removed before being destroyed, resulting in
50 // OnViewHierarchyChanged() and us removing ourself as an observer, the only
51 // view we should ever get notified of destruction on is |view_|.
52 DCHECK_EQ(view, view_);
53 RemoveObservers();
54 view_ = nullptr;
55 SetDrawn(nullptr, false);
56 }
57
58 void ServerViewDrawnTracker::OnViewHierarchyChanged(ServerView* view,
59 ServerView* new_parent,
60 ServerView* old_parent) {
61 RemoveObservers();
62 AddObservers();
63 const bool is_drawn = view_->IsDrawn();
64 SetDrawn(is_drawn ? nullptr : old_parent, is_drawn);
65 }
66
67 void ServerViewDrawnTracker::OnViewVisibilityChanged(ServerView* view) {
68 const bool is_drawn = view_->IsDrawn();
69 SetDrawn(is_drawn ? nullptr : view->parent(), is_drawn);
70 }
71
72 } // namespace view_manager
OLDNEW
« no previous file with comments | « components/view_manager/server_view_drawn_tracker.h ('k') | components/view_manager/server_view_drawn_tracker_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698