summaryrefslogtreecommitdiffstats
path: root/views/view.cc
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-22 06:56:23 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-22 06:56:23 +0000
commitb13abd32f5beb25fcf5e9f6d2cce964774d05aad (patch)
tree64428ddf49f09355ffc8013ecc91f740e4b5ef1c /views/view.cc
parent1ed4f429ef2adf287791edaa3f026eba9c9ae4f6 (diff)
downloadchromium_src-b13abd32f5beb25fcf5e9f6d2cce964774d05aad.zip
chromium_src-b13abd32f5beb25fcf5e9f6d2cce964774d05aad.tar.gz
chromium_src-b13abd32f5beb25fcf5e9f6d2cce964774d05aad.tar.bz2
Get rid of Widget::ConvertPointFromAncestor.
We don't need it now that NativeWidgetViews is dead. Also simplify View::ConvertPointToView() to look (mostly) like Layer::ConvertPointToLayer(). http://crbug.com/102573 TEST=existing unittests Review URL: http://codereview.chromium.org/8620008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111108 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/view.cc')
-rw-r--r--views/view.cc77
1 files changed, 30 insertions, 47 deletions
diff --git a/views/view.cc b/views/view.cc
index fb10437..d049a42 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -75,6 +75,14 @@ class ScopedCanvas {
DISALLOW_COPY_AND_ASSIGN(ScopedCanvas);
};
+// Returns the top view in |view|'s hierarchy.
+const views::View* GetHierarchyRoot(const views::View* view) {
+ const views::View* root = view;
+ while (root && root->parent())
+ root = root->parent();
+ return root;
+}
+
} // namespace
namespace views {
@@ -581,10 +589,29 @@ View* View::GetSelectedViewForGroup(int group) {
// Coordinate conversion -------------------------------------------------------
// static
-void View::ConvertPointToView(const View* src,
- const View* dst,
+void View::ConvertPointToView(const View* source,
+ const View* target,
gfx::Point* point) {
- ConvertPointToView(src, dst, point, true);
+ if (source == target)
+ return;
+
+ // |source| can be NULL.
+ const View* root = GetHierarchyRoot(target);
+ if (source) {
+ CHECK_EQ(GetHierarchyRoot(source), root);
+
+ if (source != root)
+ source->ConvertPointForAncestor(root, point);
+ }
+
+ if (target != root)
+ target->ConvertPointFromAncestor(root, point);
+
+ // API defines NULL |source| as returning the point in screen coordinates.
+ if (!source) {
+ *point = point->Subtract(
+ root->GetWidget()->GetClientAreaScreenBounds().origin());
+ }
}
// static
@@ -1705,50 +1732,6 @@ bool View::GetTransformRelativeTo(const View* ancestor,
// Coordinate conversion -------------------------------------------------------
-// static
-void View::ConvertPointToView(const View* src,
- const View* dst,
- gfx::Point* point,
- bool try_other_direction) {
- // src can be NULL
- DCHECK(dst);
- DCHECK(point);
-
- const Widget* src_widget = src ? src->GetWidget() : NULL ;
- const Widget* dst_widget = dst->GetWidget();
- // If dest and src aren't in the same widget, try to convert the
- // point to the destination widget's coordinates first.
- // TODO(oshima|sadrul): Cleanup and consolidate conversion methods.
- if (Widget::IsPureViews() && src_widget && src_widget != dst_widget) {
- // convert to src_widget first.
- gfx::Point p = *point;
- src->ConvertPointForAncestor(src_widget->GetRootView(), &p);
- if (dst_widget->ConvertPointFromAncestor(src_widget, &p)) {
- // Convertion to destination widget's coordinates was successful.
- // Use destination's root as a source to convert the point further.
- src = dst_widget->GetRootView();
- *point = p;
- }
- }
-
- if (src == NULL || src->Contains(dst)) {
- dst->ConvertPointFromAncestor(src, point);
- if (!src) {
- if (dst_widget) {
- gfx::Rect b = dst_widget->GetClientAreaScreenBounds();
- point->SetPoint(point->x() - b.x(), point->y() - b.y());
- }
- }
- } else if (src && try_other_direction) {
- if (!src->ConvertPointForAncestor(dst, point)) {
- // |src| is not an ancestor of |dst|, and |dst| is not an ancestor of
- // |src| either. At this stage, |point| is in the widget's coordinate
- // system. So convert from the widget's to |dst|'s coordinate system now.
- ConvertPointFromWidget(dst, point);
- }
- }
-}
-
bool View::ConvertPointForAncestor(const View* ancestor,
gfx::Point* point) const {
ui::Transform trans;