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 "services/view_manager/server_view.h" | 5 #include "services/view_manager/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 "services/view_manager/server_view_delegate.h" | 10 #include "services/view_manager/server_view_delegate.h" |
11 | 11 |
12 namespace view_manager { | 12 namespace view_manager { |
13 | 13 |
14 namespace { | |
15 | |
16 mojo::ViewportMetricsPtr CreateEmptyViewportMetrics() { | |
17 mojo::ViewportMetricsPtr metrics = mojo::ViewportMetrics::New(); | |
18 metrics->size = mojo::Size::New(); | |
19 return metrics; | |
20 } | |
21 } | |
22 | |
14 ServerView::ServerView(ServerViewDelegate* delegate, const ViewId& id) | 23 ServerView::ServerView(ServerViewDelegate* delegate, const ViewId& id) |
15 : delegate_(delegate), | 24 : delegate_(delegate), |
16 id_(id), | 25 id_(id), |
17 parent_(nullptr), | 26 parent_(nullptr), |
18 visible_(false), | 27 visible_(false), |
28 viewport_metrics_(CreateEmptyViewportMetrics()), | |
19 opacity_(1) { | 29 opacity_(1) { |
20 DCHECK(delegate); // Must provide a delegate. | 30 DCHECK(delegate); // Must provide a delegate. |
21 } | 31 } |
22 | 32 |
23 ServerView::~ServerView() { | 33 ServerView::~ServerView() { |
24 delegate_->OnWillDestroyView(this); | 34 delegate_->OnWillDestroyView(this); |
25 | 35 |
26 while (!children_.empty()) | 36 while (!children_.empty()) |
27 children_.front()->parent()->Remove(children_.front()); | 37 children_.front()->parent()->Remove(children_.front()); |
28 | 38 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 | 96 |
87 void ServerView::SetBounds(const gfx::Rect& bounds) { | 97 void ServerView::SetBounds(const gfx::Rect& bounds) { |
88 if (bounds_ == bounds) | 98 if (bounds_ == bounds) |
89 return; | 99 return; |
90 | 100 |
91 const gfx::Rect old_bounds = bounds_; | 101 const gfx::Rect old_bounds = bounds_; |
92 bounds_ = bounds; | 102 bounds_ = bounds; |
93 delegate_->OnViewBoundsChanged(this, old_bounds, bounds); | 103 delegate_->OnViewBoundsChanged(this, old_bounds, bounds); |
94 } | 104 } |
95 | 105 |
106 void ServerView::SetViewportMetrics(const mojo::ViewportMetrics& metrics) { | |
107 if (viewport_metrics_->Equals(metrics)) | |
108 return; | |
109 | |
110 viewport_metrics_ = metrics.Clone(); | |
111 delegate_->OnViewViewportMetricsChanged(this, *viewport_metrics_, metrics); | |
112 for (size_t i = 0; i < children_.size(); ++i) | |
eseidel
2015/01/27 22:46:58
Unknown if this is needed or not.
| |
113 children_[i]->SetViewportMetrics(metrics); | |
114 } | |
115 | |
96 const ServerView* ServerView::GetRoot() const { | 116 const ServerView* ServerView::GetRoot() const { |
97 const ServerView* view = this; | 117 const ServerView* view = this; |
98 while (view && view->parent()) | 118 while (view && view->parent()) |
99 view = view->parent(); | 119 view = view->parent(); |
100 return view; | 120 return view; |
101 } | 121 } |
102 | 122 |
103 std::vector<const ServerView*> ServerView::GetChildren() const { | 123 std::vector<const ServerView*> ServerView::GetChildren() const { |
104 std::vector<const ServerView*> children; | 124 std::vector<const ServerView*> children; |
105 children.reserve(children_.size()); | 125 children.reserve(children_.size()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 child->BuildDebugInfo(depth + " ", result); | 217 child->BuildDebugInfo(depth + " ", result); |
198 } | 218 } |
199 #endif | 219 #endif |
200 | 220 |
201 void ServerView::RemoveImpl(ServerView* view) { | 221 void ServerView::RemoveImpl(ServerView* view) { |
202 view->parent_ = NULL; | 222 view->parent_ = NULL; |
203 children_.erase(std::find(children_.begin(), children_.end(), view)); | 223 children_.erase(std::find(children_.begin(), children_.end(), view)); |
204 } | 224 } |
205 | 225 |
206 } // namespace view_manager | 226 } // namespace view_manager |
OLD | NEW |