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

Side by Side Diff: ui/gfx/compositor/layer.cc

Issue 7769001: Adds support for point conversions to ui::Layer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/layer.h ('k') | ui/gfx/compositor/layer_unittest.cc » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/gfx/compositor/layer.h" 5 #include "ui/gfx/compositor/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/gfx/point3.h"
10 11
11 namespace ui { 12 namespace ui {
12 13
13 Layer::Layer(Compositor* compositor) 14 Layer::Layer(Compositor* compositor)
14 : compositor_(compositor), 15 : compositor_(compositor),
15 texture_(compositor->CreateTexture()), 16 texture_(compositor->CreateTexture()),
16 parent_(NULL), 17 parent_(NULL),
17 fills_bounds_opaquely_(false) { 18 fills_bounds_opaquely_(false) {
18 } 19 }
19 20
(...skipping 18 matching lines...) Expand all
38 std::vector<Layer*>::iterator i = 39 std::vector<Layer*>::iterator i =
39 std::find(children_.begin(), children_.end(), child); 40 std::find(children_.begin(), children_.end(), child);
40 DCHECK(i != children_.end()); 41 DCHECK(i != children_.end());
41 children_.erase(i); 42 children_.erase(i);
42 child->parent_ = NULL; 43 child->parent_ = NULL;
43 44
44 if (child->fills_bounds_opaquely()) 45 if (child->fills_bounds_opaquely())
45 RecomputeHole(); 46 RecomputeHole();
46 } 47 }
47 48
49 bool Layer::Contains(const Layer* other) const {
50 for (const Layer* parent = other; parent; parent = parent->parent()) {
51 if (parent == this)
52 return true;
53 }
54 return false;
55 }
56
48 void Layer::SetTransform(const ui::Transform& transform) { 57 void Layer::SetTransform(const ui::Transform& transform) {
49 transform_ = transform; 58 transform_ = transform;
50 59
51 if (parent() && fills_bounds_opaquely_) 60 if (parent() && fills_bounds_opaquely_)
52 parent()->RecomputeHole(); 61 parent()->RecomputeHole();
53 } 62 }
54 63
55 void Layer::SetBounds(const gfx::Rect& bounds) { 64 void Layer::SetBounds(const gfx::Rect& bounds) {
56 bounds_ = bounds; 65 bounds_ = bounds;
57 66
58 if (parent() && fills_bounds_opaquely_) 67 if (parent() && fills_bounds_opaquely_)
59 parent()->RecomputeHole(); 68 parent()->RecomputeHole();
60 } 69 }
61 70
71 // static
72 void Layer::ConvertPointToLayer(const Layer* source,
73 const Layer* target,
74 gfx::Point* point) {
75 const Layer* inner = NULL;
76 const Layer* outer = NULL;
77 if (source->Contains(target)) {
78 inner = target;
79 outer = source;
80 inner->ConvertPointFromAncestor(outer, point);
81 } else if (target->Contains(source)) {
82 inner = source;
83 outer = target;
84 inner->ConvertPointForAncestor(outer, point);
85 } else {
86 NOTREACHED(); // |source| and |target| are in unrelated hierarchies.
87 }
88 }
89
62 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { 90 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
63 if (fills_bounds_opaquely_ == fills_bounds_opaquely) 91 if (fills_bounds_opaquely_ == fills_bounds_opaquely)
64 return; 92 return;
65 93
66 fills_bounds_opaquely_ = fills_bounds_opaquely; 94 fills_bounds_opaquely_ = fills_bounds_opaquely;
67 95
68 if (parent()) 96 if (parent())
69 parent()->RecomputeHole(); 97 parent()->RecomputeHole();
70 } 98 }
71 99
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (children_[i]->fills_bounds_opaquely() && 165 if (children_[i]->fills_bounds_opaquely() &&
138 !children_[i]->transform().HasChange()) { 166 !children_[i]->transform().HasChange()) {
139 hole_rect_ = children_[i]->bounds(); 167 hole_rect_ = children_[i]->bounds();
140 return; 168 return;
141 } 169 }
142 } 170 }
143 // no opaque child layers, set hole_rect_ to empty 171 // no opaque child layers, set hole_rect_ to empty
144 hole_rect_ = gfx::Rect(); 172 hole_rect_ = gfx::Rect();
145 } 173 }
146 174
175 bool Layer::ConvertPointForAncestor(const Layer* ancestor,
176 gfx::Point* point) const {
177 ui::Transform transform;
178 bool result = GetTransformRelativeTo(ancestor, &transform);
179 gfx::Point3f p(*point);
180 transform.TransformPoint(p);
181 *point = p.AsPoint();
182 return result;
183 }
184
185 bool Layer::ConvertPointFromAncestor(const Layer* ancestor,
186 gfx::Point* point) const {
187 ui::Transform transform;
188 bool result = GetTransformRelativeTo(ancestor, &transform);
189 gfx::Point3f p(*point);
190 transform.TransformPointReverse(p);
191 *point = p.AsPoint();
192 return result;
193 }
194
195 bool Layer::GetTransformRelativeTo(const Layer* ancestor,
196 ui::Transform* transform) const {
197 const Layer* p = this;
198 for (; p && p != ancestor; p = p->parent()) {
199 if (p->transform().HasChange())
200 transform->ConcatTransform(p->transform());
201 transform->ConcatTranslate(static_cast<float>(p->bounds().x()),
202 static_cast<float>(p->bounds().y()));
203 }
204 return p == ancestor;
205 }
206
147 } // namespace ui 207 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer.h ('k') | ui/gfx/compositor/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698