summaryrefslogtreecommitdiffstats
path: root/views
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
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')
-rw-r--r--views/view.cc77
-rw-r--r--views/view.h33
2 files changed, 40 insertions, 70 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;
diff --git a/views/view.h b/views/view.h
index c4e286f..bbb10a8 100644
--- a/views/view.h
+++ b/views/view.h
@@ -415,27 +415,23 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// the mirrored position of the child Views if the parent View uses a
// right-to-left UI layout.
- // Convert a point from source coordinate system to dst coordinate system.
+ // Convert a point from the coordinate system of one View to another.
//
- // |src| and |dst| needs to be in the same widget, but doesn't need to be in
+ // |source| and |target| must be in the same widget, but doesn't need to be in
// the same view hierarchy.
- // If |src| and |dst| are not in the same widget, the result is undefined.
- // Source can be NULL in which case it means the screen coordinate system
- static void ConvertPointToView(const View* src,
- const View* dst,
+ // |source| can be NULL in which case it means the screen coordinate system.
+ static void ConvertPointToView(const View* source,
+ const View* target,
gfx::Point* point);
- // Convert a point from the coordinate system of a View to that of the
- // Widget. This is useful for example when sizing HWND children of the
- // Widget that don't know about the View hierarchy and need to be placed
- // relative to the Widget that is their parent.
+ // Convert a point from a View's coordinate system to that of its Widget.
static void ConvertPointToWidget(const View* src, gfx::Point* point);
- // Convert a point from a view Widget to a View dest
+ // Convert a point from the coordinate system of a View's Widget to that
+ // View's coordinate system.
static void ConvertPointFromWidget(const View* dest, gfx::Point* p);
- // Convert a point from the coordinate system of a View to that of the
- // screen. This is useful for example when placing popup windows.
+ // Convert a point from a View's coordinate system to that of the screen.
static void ConvertPointToScreen(const View* src, gfx::Point* point);
// Applies transformation on the rectangle, which is in the view's coordinate
@@ -443,7 +439,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
gfx::Rect ConvertRectToParent(const gfx::Rect& rect) const;
// Converts a rectangle from this views coordinate system to its widget
- // cooridnate system.
+ // coordinate system.
gfx::Rect ConvertRectToWidget(const gfx::Rect& rect) const;
// Painting ------------------------------------------------------------------
@@ -1202,15 +1198,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// Coordinate conversion -----------------------------------------------------
- // This is the actual implementation for ConvertPointToView()
- // Attempts a parent -> child conversion and then a
- // child -> parent conversion if try_other_direction is true
- // Applies necessary transformations during the conversion.
- static void ConvertPointToView(const View* src,
- const View* dst,
- gfx::Point* point,
- bool try_other_direction);
-
// Convert a point in the view's coordinate to an ancestor view's coordinate
// system using necessary transformations. Returns whether the point was
// successfully converted to the ancestor's coordinate system.