diff options
author | chocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-22 17:34:16 +0000 |
---|---|---|
committer | chocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-22 17:34:16 +0000 |
commit | 840d06673585d905c5091ebd18b72401fae92cff (patch) | |
tree | 2100fe14308c15ac2581b344c1667a7aff1fc8f2 /views/widget | |
parent | 6b64b0265e7d066fdb3426643cbc0ed739747695 (diff) | |
download | chromium_src-840d06673585d905c5091ebd18b72401fae92cff.zip chromium_src-840d06673585d905c5091ebd18b72401fae92cff.tar.gz chromium_src-840d06673585d905c5091ebd18b72401fae92cff.tar.bz2 |
Fix code to get widget position on screen.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/215053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26829 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/widget_gtk.cc | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 75bcc33..be3c102 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -51,19 +51,19 @@ class WidgetGtk::DropObserver : public MessageLoopForUI::Observer { // Returns the position of a widget on screen. static void GetWidgetPositionOnScreen(GtkWidget* widget, int* x, int *y) { - while (widget) { - if (GTK_IS_WINDOW(widget)) { - int window_x, window_y; - gtk_window_get_position(GTK_WINDOW(widget), &window_x, &window_y); - *x += window_x; - *y += window_y; - return; - } - // Not a window. - *x += widget->allocation.x; - *y += widget->allocation.y; - widget = gtk_widget_get_parent(widget); + // First get the root window. + GtkWidget* root = widget; + while (root && !GTK_IS_WINDOW(root)) { + root = gtk_widget_get_parent(root); } + DCHECK(root); + // Translate the coordinate from widget to root window. + gtk_widget_translate_coordinates(widget, root, 0, 0, x, y); + // Then adjust the position with the position of the root window. + int window_x, window_y; + gtk_window_get_position(GTK_WINDOW(root), &window_x, &window_y); + *x += window_x; + *y += window_y; } // Returns the view::Event::flags for a GdkEventButton. |