summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/views/widget/native_widget_aura.cc7
-rw-r--r--ui/views/widget/native_widget_aura.h2
-rw-r--r--ui/views/widget/native_widget_gtk.cc6
-rw-r--r--ui/views/widget/native_widget_gtk.h2
-rw-r--r--ui/views/widget/native_widget_private.h2
-rw-r--r--ui/views/widget/native_widget_win.cc6
-rw-r--r--ui/views/widget/native_widget_win.h2
-rw-r--r--ui/views/widget/widget.cc5
-rw-r--r--ui/views/widget/widget.h7
-rw-r--r--views/view.cc77
-rw-r--r--views/view.h33
11 files changed, 40 insertions, 109 deletions
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index 87a1573..c60ab07 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -514,13 +514,6 @@ void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) {
NOTIMPLEMENTED();
}
-bool NativeWidgetAura::ConvertPointFromAncestor(const Widget* ancestor,
- gfx::Point* point) const {
- // http://crbug.com/102573
- NOTIMPLEMENTED();
- return false;
-}
-
gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const {
return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
}
diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h
index f5abd78..57c2405 100644
--- a/ui/views/widget/native_widget_aura.h
+++ b/ui/views/widget/native_widget_aura.h
@@ -114,8 +114,6 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
- virtual bool ConvertPointFromAncestor(
- const Widget* ancestor, gfx::Point* point) const OVERRIDE;
virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE;
diff --git a/ui/views/widget/native_widget_gtk.cc b/ui/views/widget/native_widget_gtk.cc
index 4bf288a..5209be8 100644
--- a/ui/views/widget/native_widget_gtk.cc
+++ b/ui/views/widget/native_widget_gtk.cc
@@ -1343,12 +1343,6 @@ void NativeWidgetGtk::FocusNativeView(gfx::NativeView native_view) {
gtk_widget_grab_focus(native_view);
}
-bool NativeWidgetGtk::ConvertPointFromAncestor(
- const Widget* ancestor, gfx::Point* point) const {
- NOTREACHED();
- return false;
-}
-
gfx::Rect NativeWidgetGtk::GetWorkAreaBoundsInScreen() const {
return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
}
diff --git a/ui/views/widget/native_widget_gtk.h b/ui/views/widget/native_widget_gtk.h
index 51184ee..f216e66 100644
--- a/ui/views/widget/native_widget_gtk.h
+++ b/ui/views/widget/native_widget_gtk.h
@@ -217,8 +217,6 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
- virtual bool ConvertPointFromAncestor(
- const Widget* ancestor, gfx::Point* point) const OVERRIDE;
virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE;
diff --git a/ui/views/widget/native_widget_private.h b/ui/views/widget/native_widget_private.h
index 3f1b474..702cf8b 100644
--- a/ui/views/widget/native_widget_private.h
+++ b/ui/views/widget/native_widget_private.h
@@ -200,8 +200,6 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget,
virtual void SetCursor(gfx::NativeCursor cursor) = 0;
virtual void ClearNativeFocus() = 0;
virtual void FocusNativeView(gfx::NativeView native_view) = 0;
- virtual bool ConvertPointFromAncestor(
- const Widget* ancestor, gfx::Point* point) const = 0;
virtual gfx::Rect GetWorkAreaBoundsInScreen() const = 0;
virtual void SetInactiveRenderingDisabled(bool value) = 0;
diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc
index a8022c8..f969932 100644
--- a/ui/views/widget/native_widget_win.cc
+++ b/ui/views/widget/native_widget_win.cc
@@ -991,12 +991,6 @@ void NativeWidgetWin::FocusNativeView(gfx::NativeView native_view) {
::SetFocus(native_view);
}
-bool NativeWidgetWin::ConvertPointFromAncestor(
- const Widget* ancestor, gfx::Point* point) const {
- NOTREACHED();
- return false;
-}
-
gfx::Rect NativeWidgetWin::GetWorkAreaBoundsInScreen() const {
return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
}
diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h
index 9618811..3e77310 100644
--- a/ui/views/widget/native_widget_win.h
+++ b/ui/views/widget/native_widget_win.h
@@ -252,8 +252,6 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
- virtual bool ConvertPointFromAncestor(
- const Widget* ancestor, gfx::Point* point) const OVERRIDE;
virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE;
diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc
index 53c1577..92801e5 100644
--- a/ui/views/widget/widget.cc
+++ b/ui/views/widget/widget.cc
@@ -816,11 +816,6 @@ bool Widget::SetInitialFocus() {
return !!v;
}
-bool Widget::ConvertPointFromAncestor(
- const Widget* ancestor, gfx::Point* point) const {
- return native_widget_->ConvertPointFromAncestor(ancestor, point);
-}
-
View* Widget::GetChildViewParent() {
return GetContentsView() ? GetContentsView() : GetRootView();
}
diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h
index ad0a7bf..128a0aa 100644
--- a/ui/views/widget/widget.h
+++ b/ui/views/widget/widget.h
@@ -550,13 +550,6 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
focus_on_creation_ = focus_on_creation;
}
- // Converts the |point| in ancestor's coordinate to this widget's coordinates.
- // Returns false if |ancestor| is not an ancestor of this widget.
- // The receiver has to be pure views widget (NativeWidgetViews) and
- // ancestor can be of any type.
- bool ConvertPointFromAncestor(
- const Widget* ancestor, gfx::Point* point) const;
-
// Returns a View* that any child Widgets backed by NativeWidgetViews
// are added to. The default implementation returns the contents view
// if it exists and the root view otherwise.
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.