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

Side by Side Diff: components/mus/ws/server_view.cc

Issue 1406153004: components/mus/public/interfaces View => Window (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Yet another rebase Created 5 years, 2 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
« no previous file with comments | « components/mus/ws/server_view.h ('k') | components/mus/ws/server_view_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/mus/ws/server_view.h" 5 #include "components/mus/ws/server_view.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "components/mus/ws/server_view_delegate.h" 10 #include "components/mus/ws/server_view_delegate.h"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 void ServerView::AddObserver(ServerViewObserver* observer) { 41 void ServerView::AddObserver(ServerViewObserver* observer) {
42 observers_.AddObserver(observer); 42 observers_.AddObserver(observer);
43 } 43 }
44 44
45 void ServerView::RemoveObserver(ServerViewObserver* observer) { 45 void ServerView::RemoveObserver(ServerViewObserver* observer) {
46 observers_.RemoveObserver(observer); 46 observers_.RemoveObserver(observer);
47 } 47 }
48 48
49 void ServerView::Bind(mojo::InterfaceRequest<mojo::Surface> request, 49 void ServerView::Bind(mojo::InterfaceRequest<mojom::Surface> request,
50 mojo::SurfaceClientPtr client) { 50 mojom::SurfaceClientPtr client) {
51 GetOrCreateSurface()->Bind(request.Pass(), client.Pass()); 51 GetOrCreateSurface()->Bind(request.Pass(), client.Pass());
52 } 52 }
53 53
54 void ServerView::Add(ServerView* child) { 54 void ServerView::Add(ServerView* child) {
55 // We assume validation checks happened already. 55 // We assume validation checks happened already.
56 DCHECK(child); 56 DCHECK(child);
57 DCHECK(child != this); 57 DCHECK(child != this);
58 DCHECK(!child->Contains(this)); 58 DCHECK(!child->Contains(this));
59 if (child->parent() == this) { 59 if (child->parent() == this) {
60 if (children_.size() == 1) 60 if (children_.size() == 1)
61 return; // Already in the right position. 61 return; // Already in the right position.
62 Reorder(child, children_.back(), mojo::ORDER_DIRECTION_ABOVE); 62 Reorder(child, children_.back(), mojom::ORDER_DIRECTION_ABOVE);
63 return; 63 return;
64 } 64 }
65 65
66 ServerView* old_parent = child->parent(); 66 ServerView* old_parent = child->parent();
67 FOR_EACH_OBSERVER(ServerViewObserver, child->observers_, 67 FOR_EACH_OBSERVER(ServerViewObserver, child->observers_,
68 OnWillChangeViewHierarchy(child, this, old_parent)); 68 OnWillChangeViewHierarchy(child, this, old_parent));
69 69
70 if (child->parent()) 70 if (child->parent())
71 child->parent()->RemoveImpl(child); 71 child->parent()->RemoveImpl(child);
72 72
(...skipping 11 matching lines...) Expand all
84 84
85 FOR_EACH_OBSERVER(ServerViewObserver, child->observers_, 85 FOR_EACH_OBSERVER(ServerViewObserver, child->observers_,
86 OnWillChangeViewHierarchy(child, nullptr, this)); 86 OnWillChangeViewHierarchy(child, nullptr, this));
87 RemoveImpl(child); 87 RemoveImpl(child);
88 FOR_EACH_OBSERVER(ServerViewObserver, child->observers_, 88 FOR_EACH_OBSERVER(ServerViewObserver, child->observers_,
89 OnViewHierarchyChanged(child, nullptr, this)); 89 OnViewHierarchyChanged(child, nullptr, this));
90 } 90 }
91 91
92 void ServerView::Reorder(ServerView* child, 92 void ServerView::Reorder(ServerView* child,
93 ServerView* relative, 93 ServerView* relative,
94 mojo::OrderDirection direction) { 94 mojom::OrderDirection direction) {
95 // We assume validation checks happened else where. 95 // We assume validation checks happened else where.
96 DCHECK(child); 96 DCHECK(child);
97 DCHECK(child->parent() == this); 97 DCHECK(child->parent() == this);
98 DCHECK_GT(children_.size(), 1u); 98 DCHECK_GT(children_.size(), 1u);
99 children_.erase(std::find(children_.begin(), children_.end(), child)); 99 children_.erase(std::find(children_.begin(), children_.end(), child));
100 Views::iterator i = std::find(children_.begin(), children_.end(), relative); 100 Views::iterator i = std::find(children_.begin(), children_.end(), relative);
101 if (direction == mojo::ORDER_DIRECTION_ABOVE) { 101 if (direction == mojom::ORDER_DIRECTION_ABOVE) {
102 DCHECK(i != children_.end()); 102 DCHECK(i != children_.end());
103 children_.insert(++i, child); 103 children_.insert(++i, child);
104 } else if (direction == mojo::ORDER_DIRECTION_BELOW) { 104 } else if (direction == mojom::ORDER_DIRECTION_BELOW) {
105 DCHECK(i != children_.end()); 105 DCHECK(i != children_.end());
106 children_.insert(i, child); 106 children_.insert(i, child);
107 } 107 }
108 FOR_EACH_OBSERVER(ServerViewObserver, observers_, 108 FOR_EACH_OBSERVER(ServerViewObserver, observers_,
109 OnViewReordered(this, relative, direction)); 109 OnViewReordered(this, relative, direction));
110 } 110 }
111 111
112 void ServerView::SetBounds(const gfx::Rect& bounds) { 112 void ServerView::SetBounds(const gfx::Rect& bounds) {
113 if (bounds_ == bounds) 113 if (bounds_ == bounds)
114 return; 114 return;
(...skipping 30 matching lines...) Expand all
145 for (size_t i = 0; i < children_.size(); ++i) 145 for (size_t i = 0; i < children_.size(); ++i)
146 children.push_back(children_[i]); 146 children.push_back(children_[i]);
147 return children; 147 return children;
148 } 148 }
149 149
150 std::vector<ServerView*> ServerView::GetChildren() { 150 std::vector<ServerView*> ServerView::GetChildren() {
151 // TODO(sky): rename to children() and fix return type. 151 // TODO(sky): rename to children() and fix return type.
152 return children_; 152 return children_;
153 } 153 }
154 154
155 ServerView* ServerView::GetChildView(const ViewId& view_id) { 155 ServerView* ServerView::GetChildView(const ViewId& window_id) {
156 if (id_ == view_id) 156 if (id_ == window_id)
157 return this; 157 return this;
158 158
159 for (ServerView* child : children_) { 159 for (ServerView* child : children_) {
160 ServerView* view = child->GetChildView(view_id); 160 ServerView* view = child->GetChildView(window_id);
161 if (view) 161 if (view)
162 return view; 162 return view;
163 } 163 }
164 164
165 return nullptr; 165 return nullptr;
166 } 166 }
167 167
168 bool ServerView::Contains(const ServerView* view) const { 168 bool ServerView::Contains(const ServerView* view) const {
169 for (const ServerView* parent = view; parent; parent = parent->parent_) { 169 for (const ServerView* parent = view; parent; parent = parent->parent_) {
170 if (parent == this) 170 if (parent == this)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 std::string ServerView::GetDebugWindowHierarchy() const { 252 std::string ServerView::GetDebugWindowHierarchy() const {
253 std::string result; 253 std::string result;
254 BuildDebugInfo(std::string(), &result); 254 BuildDebugInfo(std::string(), &result);
255 return result; 255 return result;
256 } 256 }
257 257
258 void ServerView::BuildDebugInfo(const std::string& depth, 258 void ServerView::BuildDebugInfo(const std::string& depth,
259 std::string* result) const { 259 std::string* result) const {
260 *result += base::StringPrintf( 260 *result += base::StringPrintf(
261 "%sid=%d,%d visible=%s bounds=%d,%d %dx%d" PRIu64 "\n", depth.c_str(), 261 "%sid=%d,%d visible=%s bounds=%d,%d %dx%d" PRIu64 "\n", depth.c_str(),
262 static_cast<int>(id_.connection_id), static_cast<int>(id_.view_id), 262 static_cast<int>(id_.connection_id), static_cast<int>(id_.window_id),
263 visible_ ? "true" : "false", bounds_.x(), bounds_.y(), bounds_.width(), 263 visible_ ? "true" : "false", bounds_.x(), bounds_.y(), bounds_.width(),
264 bounds_.height()); 264 bounds_.height());
265 for (const ServerView* child : children_) 265 for (const ServerView* child : children_)
266 child->BuildDebugInfo(depth + " ", result); 266 child->BuildDebugInfo(depth + " ", result);
267 } 267 }
268 #endif 268 #endif
269 269
270 void ServerView::RemoveImpl(ServerView* view) { 270 void ServerView::RemoveImpl(ServerView* view) {
271 view->parent_ = NULL; 271 view->parent_ = NULL;
272 children_.erase(std::find(children_.begin(), children_.end(), view)); 272 children_.erase(std::find(children_.begin(), children_.end(), view));
273 } 273 }
274 274
275 } // namespace mus 275 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/server_view.h ('k') | components/mus/ws/server_view_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698