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 "mojo/services/view_manager/server_view.h" | 5 #include "mojo/services/view_manager/server_view.h" |
6 | 6 |
7 #include "mojo/services/view_manager/server_view_delegate.h" | 7 #include "mojo/services/view_manager/server_view_delegate.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 namespace service { | 10 namespace service { |
11 | 11 |
12 ServerView::ServerView(ServerViewDelegate* delegate, const ViewId& id) | 12 ServerView::ServerView(ServerViewDelegate* delegate, const ViewId& id) |
13 : delegate_(delegate), id_(id), parent_(NULL), visible_(true) { | 13 : delegate_(delegate), id_(id), parent_(NULL), visible_(true), opacity_(1) { |
14 DCHECK(delegate); // Must provide a delegate. | 14 DCHECK(delegate); // Must provide a delegate. |
15 } | 15 } |
16 | 16 |
17 ServerView::~ServerView() { | 17 ServerView::~ServerView() { |
| 18 delegate_->OnWillDestroyView(this); |
| 19 |
18 while (!children_.empty()) | 20 while (!children_.empty()) |
19 children_.front()->parent()->Remove(children_.front()); | 21 children_.front()->parent()->Remove(children_.front()); |
20 | 22 |
21 if (parent_) | 23 if (parent_) |
22 parent_->Remove(this); | 24 parent_->Remove(this); |
23 | 25 |
24 delegate_->OnViewDestroyed(this); | 26 delegate_->OnViewDestroyed(this); |
25 } | 27 } |
26 | 28 |
27 void ServerView::Add(ServerView* child) { | 29 void ServerView::Add(ServerView* child) { |
28 // We assume validation checks happened already. | 30 // We assume validation checks happened already. |
29 DCHECK(child); | 31 DCHECK(child); |
30 DCHECK(child != this); | 32 DCHECK(child != this); |
31 DCHECK(!child->Contains(this)); | 33 DCHECK(!child->Contains(this)); |
32 if (child->parent() == this) { | 34 if (child->parent() == this) { |
33 if (children_.size() == 1) | 35 if (children_.size() == 1) |
34 return; // Already in the right position. | 36 return; // Already in the right position. |
35 Reorder(child, children_.back(), ORDER_DIRECTION_ABOVE); | 37 Reorder(child, children_.back(), ORDER_DIRECTION_ABOVE); |
36 return; | 38 return; |
37 } | 39 } |
38 | 40 |
39 const ServerView* old_parent = child->parent(); | 41 ServerView* old_parent = child->parent(); |
40 child->delegate_->OnWillChangeViewHierarchy(child, this, old_parent); | 42 child->delegate_->OnWillChangeViewHierarchy(child, this, old_parent); |
41 if (child->parent()) | 43 if (child->parent()) |
42 child->parent()->RemoveImpl(child); | 44 child->parent()->RemoveImpl(child); |
43 | 45 |
44 child->parent_ = this; | 46 child->parent_ = this; |
45 children_.push_back(child); | 47 children_.push_back(child); |
46 child->delegate_->OnViewHierarchyChanged(child, this, old_parent); | 48 child->delegate_->OnViewHierarchyChanged(child, this, old_parent); |
47 } | 49 } |
48 | 50 |
49 void ServerView::Remove(ServerView* child) { | 51 void ServerView::Remove(ServerView* child) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 116 } |
115 | 117 |
116 void ServerView::SetVisible(bool value) { | 118 void ServerView::SetVisible(bool value) { |
117 if (visible_ == value) | 119 if (visible_ == value) |
118 return; | 120 return; |
119 | 121 |
120 delegate_->OnWillChangeViewVisibility(this); | 122 delegate_->OnWillChangeViewVisibility(this); |
121 visible_ = value; | 123 visible_ = value; |
122 } | 124 } |
123 | 125 |
| 126 void ServerView::SetOpacity(float value) { |
| 127 if (value == opacity_) |
| 128 return; |
| 129 opacity_ = value; |
| 130 delegate_->OnScheduleViewPaint(this); |
| 131 } |
| 132 |
124 void ServerView::SetProperty(const std::string& name, | 133 void ServerView::SetProperty(const std::string& name, |
125 const std::vector<uint8_t>* value) { | 134 const std::vector<uint8_t>* value) { |
126 auto it = properties_.find(name); | 135 auto it = properties_.find(name); |
127 if (it != properties_.end()) { | 136 if (it != properties_.end()) { |
128 if (value && it->second == *value) | 137 if (value && it->second == *value) |
129 return; | 138 return; |
130 } else if (!value) { | 139 } else if (!value) { |
131 // This property isn't set in |properties_| and |value| is NULL, so there's | 140 // This property isn't set in |properties_| and |value| is NULL, so there's |
132 // no change. | 141 // no change. |
133 return; | 142 return; |
(...skipping 22 matching lines...) Expand all Loading... |
156 delegate_->OnViewSurfaceIdChanged(this); | 165 delegate_->OnViewSurfaceIdChanged(this); |
157 } | 166 } |
158 | 167 |
159 void ServerView::RemoveImpl(ServerView* view) { | 168 void ServerView::RemoveImpl(ServerView* view) { |
160 view->parent_ = NULL; | 169 view->parent_ = NULL; |
161 children_.erase(std::find(children_.begin(), children_.end(), view)); | 170 children_.erase(std::find(children_.begin(), children_.end(), view)); |
162 } | 171 } |
163 | 172 |
164 } // namespace service | 173 } // namespace service |
165 } // namespace mojo | 174 } // namespace mojo |
OLD | NEW |