summaryrefslogtreecommitdiffstats
path: root/ui/views/view.cc
diff options
context:
space:
mode:
authortdanderson@chromium.org <tdanderson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-21 00:02:43 +0000
committertdanderson@chromium.org <tdanderson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-21 00:02:43 +0000
commit5350df75f7a44b8f78231d38412331f2f96f132f (patch)
tree78125ed52a63e35a70e646f3979cb375abbbf9bc /ui/views/view.cc
parent940d498aa7b90c629324a89c355df41e505d8bf6 (diff)
downloadchromium_src-5350df75f7a44b8f78231d38412331f2f96f132f.zip
chromium_src-5350df75f7a44b8f78231d38412331f2f96f132f.tar.gz
chromium_src-5350df75f7a44b8f78231d38412331f2f96f132f.tar.bz2
Implement rect conversion utility functions in View
Add the following utility functions (similar to their point-based counterparts): View::ConvertRectToTarget() View::ConvertRectToAncestor() View::ConvertRectFromAncestor() BUG=306182 Review URL: https://codereview.chromium.org/26884003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/view.cc')
-rw-r--r--ui/views/view.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/ui/views/view.cc b/ui/views/view.cc
index ac3c471..3e0d55a 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -681,6 +681,32 @@ void View::ConvertPointToTarget(const View* source,
}
// static
+void View::ConvertRectToTarget(const View* source,
+ const View* target,
+ gfx::RectF* rect) {
+ if (source == target)
+ return;
+
+ // |source| can be NULL.
+ const View* root = GetHierarchyRoot(target);
+ if (source) {
+ CHECK_EQ(GetHierarchyRoot(source), root);
+
+ if (source != root)
+ source->ConvertRectForAncestor(root, rect);
+ }
+
+ if (target != root)
+ target->ConvertRectFromAncestor(root, rect);
+
+ // API defines NULL |source| as returning the point in screen coordinates.
+ if (!source) {
+ rect->set_origin(rect->origin() -
+ root->GetWidget()->GetClientAreaBoundsInScreen().OffsetFromOrigin());
+ }
+}
+
+// static
void View::ConvertPointToWidget(const View* src, gfx::Point* p) {
DCHECK(src);
DCHECK(p);
@@ -1978,6 +2004,23 @@ bool View::ConvertPointFromAncestor(const View* ancestor,
return result;
}
+bool View::ConvertRectForAncestor(const View* ancestor,
+ gfx::RectF* rect) const {
+ gfx::Transform trans;
+ // TODO(sad): Have some way of caching the transformation results.
+ bool result = GetTransformRelativeTo(ancestor, &trans);
+ trans.TransformRect(rect);
+ return result;
+}
+
+bool View::ConvertRectFromAncestor(const View* ancestor,
+ gfx::RectF* rect) const {
+ gfx::Transform trans;
+ bool result = GetTransformRelativeTo(ancestor, &trans);
+ trans.TransformRectReverse(rect);
+ return result;
+}
+
// Accelerated painting --------------------------------------------------------
void View::CreateLayer() {