| OLD | NEW |
| 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 Loading... |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 if (children_[i]->fills_bounds_opaquely() && | 164 if (children_[i]->fills_bounds_opaquely() && |
| 137 !children_[i]->transform().HasChange()) { | 165 !children_[i]->transform().HasChange()) { |
| 138 hole_rect_ = children_[i]->bounds(); | 166 hole_rect_ = children_[i]->bounds(); |
| 139 return; | 167 return; |
| 140 } | 168 } |
| 141 } | 169 } |
| 142 // no opaque child layers, set hole_rect_ to empty | 170 // no opaque child layers, set hole_rect_ to empty |
| 143 hole_rect_ = gfx::Rect(); | 171 hole_rect_ = gfx::Rect(); |
| 144 } | 172 } |
| 145 | 173 |
| 174 bool Layer::ConvertPointForAncestor(const Layer* ancestor, |
| 175 gfx::Point* point) const { |
| 176 ui::Transform transform; |
| 177 bool result = GetTransformRelativeTo(ancestor, &transform); |
| 178 gfx::Point3f p(*point); |
| 179 transform.TransformPoint(p); |
| 180 *point = p.AsPoint(); |
| 181 return result; |
| 182 } |
| 183 |
| 184 bool Layer::ConvertPointFromAncestor(const Layer* ancestor, |
| 185 gfx::Point* point) const { |
| 186 ui::Transform transform; |
| 187 bool result = GetTransformRelativeTo(ancestor, &transform); |
| 188 gfx::Point3f p(*point); |
| 189 transform.TransformPointReverse(p); |
| 190 *point = p.AsPoint(); |
| 191 return result; |
| 192 } |
| 193 |
| 194 bool Layer::GetTransformRelativeTo(const Layer* ancestor, |
| 195 ui::Transform* transform) const { |
| 196 const Layer* p = this; |
| 197 for (; p && p != ancestor; p = p->parent()) { |
| 198 if (p->transform().HasChange()) |
| 199 transform->ConcatTransform(p->transform()); |
| 200 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), |
| 201 static_cast<float>(p->bounds().y())); |
| 202 } |
| 203 return p == ancestor; |
| 204 } |
| 205 |
| 146 } // namespace ui | 206 } // namespace ui |
| OLD | NEW |