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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/compositor/layer.h ('k') | ui/gfx/compositor/layer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/compositor/layer.cc
===================================================================
--- ui/gfx/compositor/layer.cc (revision 98650)
+++ ui/gfx/compositor/layer.cc (working copy)
@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/logging.h"
+#include "ui/gfx/point3.h"
namespace ui {
@@ -45,6 +46,14 @@
RecomputeHole();
}
+bool Layer::Contains(const Layer* other) const {
+ for (const Layer* parent = other; parent; parent = parent->parent()) {
+ if (parent == this)
+ return true;
+ }
+ return false;
+}
+
void Layer::SetTransform(const ui::Transform& transform) {
transform_ = transform;
@@ -59,6 +68,25 @@
parent()->RecomputeHole();
}
+// static
+void Layer::ConvertPointToLayer(const Layer* source,
+ const Layer* target,
+ gfx::Point* point) {
+ const Layer* inner = NULL;
+ const Layer* outer = NULL;
+ if (source->Contains(target)) {
+ inner = target;
+ outer = source;
+ inner->ConvertPointFromAncestor(outer, point);
+ } else if (target->Contains(source)) {
+ inner = source;
+ outer = target;
+ inner->ConvertPointForAncestor(outer, point);
+ } else {
+ NOTREACHED(); // |source| and |target| are in unrelated hierarchies.
+ }
+}
+
void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
if (fills_bounds_opaquely_ == fills_bounds_opaquely)
return;
@@ -144,4 +172,36 @@
hole_rect_ = gfx::Rect();
}
+bool Layer::ConvertPointForAncestor(const Layer* ancestor,
+ gfx::Point* point) const {
+ ui::Transform transform;
+ bool result = GetTransformRelativeTo(ancestor, &transform);
+ gfx::Point3f p(*point);
+ transform.TransformPoint(p);
+ *point = p.AsPoint();
+ return result;
+}
+
+bool Layer::ConvertPointFromAncestor(const Layer* ancestor,
+ gfx::Point* point) const {
+ ui::Transform transform;
+ bool result = GetTransformRelativeTo(ancestor, &transform);
+ gfx::Point3f p(*point);
+ transform.TransformPointReverse(p);
+ *point = p.AsPoint();
+ return result;
+}
+
+bool Layer::GetTransformRelativeTo(const Layer* ancestor,
+ ui::Transform* transform) const {
+ const Layer* p = this;
+ for (; p && p != ancestor; p = p->parent()) {
+ if (p->transform().HasChange())
+ transform->ConcatTransform(p->transform());
+ transform->ConcatTranslate(static_cast<float>(p->bounds().x()),
+ static_cast<float>(p->bounds().y()));
+ }
+ return p == ancestor;
+}
+
} // namespace ui
« 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