diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-24 00:27:52 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-24 00:27:52 +0000 |
commit | 0888e85c007b3b88167753654769a8e3129d0fbb (patch) | |
tree | 9d44790c64c762b367b8ce48f22affd5e14cac17 /chrome | |
parent | 5de6dace1d151d7929fee89e722e2d18709027d8 (diff) | |
download | chromium_src-0888e85c007b3b88167753654769a8e3129d0fbb.zip chromium_src-0888e85c007b3b88167753654769a8e3129d0fbb.tar.gz chromium_src-0888e85c007b3b88167753654769a8e3129d0fbb.tar.bz2 |
GTK: Compute infobubble target rects correctly.
I misunderstood how allocations work in the original
version and wasn't handling the case where there are
intermediate GdkWindows between the target widget and
its toplevel window correctly.
TEST=first-run, bookmark, and browser action bubbles get opened in the correct places under xmonad, metacity, and ion3
BUG=23373
Review URL: http://codereview.chromium.org/326017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29978 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/browser_actions_toolbar_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 15 | ||||
-rw-r--r-- | chrome/browser/gtk/toolbar_star_toggle_gtk.cc | 3 | ||||
-rw-r--r-- | chrome/common/gtk_util.cc | 9 | ||||
-rw-r--r-- | chrome/common/gtk_util.h | 4 |
5 files changed, 29 insertions, 10 deletions
diff --git a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc index 85ea769..74b46c2 100644 --- a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc @@ -18,6 +18,7 @@ #include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/profile.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/gtk_util.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" @@ -127,9 +128,10 @@ class BrowserActionButton : public NotificationObserver, static void OnButtonClicked(GtkWidget* widget, BrowserActionButton* action) { if (action->extension_->browser_action()->is_popup()) { - ExtensionPopupGtk::Show(action->extension_->browser_action()->popup_url(), - action->browser_, gfx::Rect(widget->allocation)); - + ExtensionPopupGtk::Show( + action->extension_->browser_action()->popup_url(), + action->browser_, + gtk_util::GetWidgetRectRelativeToToplevel(widget)); } else { ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( action->browser_->profile(), action->extension_->id(), diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 382563a..086cf97 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -649,20 +649,23 @@ void LocationBarViewGtk::ShowFirstRunBubbleInternal(bool use_OEM_bubble) { if (!location_entry_.get() || !widget()->window) return; - int x = widget()->allocation.x; - int y = widget()->allocation.y; + gfx::Rect rect = gtk_util::GetWidgetRectRelativeToToplevel(widget()); + rect.set_width(0); + rect.set_height(0); // The bubble needs to be just below the Omnibox and slightly to the right // of star button, so shift x and y co-ordinates. - y += widget()->allocation.height + kFirstRunBubbleTopMargin; + int y_offset = widget()->allocation.height + kFirstRunBubbleTopMargin; + int x_offset = 0; if (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) - x += kFirstRunBubbleLeftMargin; + x_offset = kFirstRunBubbleLeftMargin; else - x += widget()->allocation.width - kFirstRunBubbleLeftMargin; + x_offset = widget()->allocation.width - kFirstRunBubbleLeftMargin; + rect.Offset(x_offset, y_offset); FirstRunBubble::Show(profile_, GTK_WINDOW(gtk_widget_get_toplevel(widget())), - gfx::Rect(x, y, 0, 0), + rect, use_OEM_bubble); } diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc index a634618..c6ba974 100644 --- a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc +++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc @@ -14,6 +14,7 @@ #include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/theme_resources.h" @@ -67,7 +68,7 @@ void ToolbarStarToggleGtk::ShowStarBubble(const GURL& url, bool newly_bookmarked) { GtkWidget* widget = widget_.get(); BookmarkBubbleGtk::Show(GTK_WINDOW(gtk_widget_get_toplevel(widget)), - gfx::Rect(widget->allocation), + gtk_util::GetWidgetRectRelativeToToplevel(widget), host_->profile(), url, newly_bookmarked); diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index 842b99a..fac62f4 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -568,4 +568,13 @@ void StackPopupWindow(GtkWidget* popup, GtkWidget* toplevel) { } } +gfx::Rect GetWidgetRectRelativeToToplevel(GtkWidget* widget) { + gint x = 0, y = 0; + DCHECK(gtk_widget_translate_coordinates(widget, + gtk_widget_get_toplevel(widget), + 0, 0, + &x, &y)); + return gfx::Rect(x, y, widget->allocation.width, widget->allocation.height); +} + } // namespace gtk_util diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h index 749aade..4f0278a 100644 --- a/chrome/common/gtk_util.h +++ b/chrome/common/gtk_util.h @@ -184,6 +184,10 @@ GdkCursor* GetCursor(GdkCursorType type); // Stacks a |popup| window directly on top of a |toplevel| window. void StackPopupWindow(GtkWidget* popup, GtkWidget* toplevel); +// Get a rectangle corresponding to a widget's allocation relative to its +// toplevel window's origin. +gfx::Rect GetWidgetRectRelativeToToplevel(GtkWidget* widget); + } // namespace gtk_util #endif // CHROME_COMMON_GTK_UTIL_H_ |