diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-11 23:04:23 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-11 23:04:23 +0000 |
commit | 60627a1fc425b47fd658440a9fad776237a87ec1 (patch) | |
tree | ed0b5fc3e9da3fc8b65b3036375665c6f6a2c384 /chrome | |
parent | 589df05308e0d8a014ae4f0501d63c38f1144c6f (diff) | |
download | chromium_src-60627a1fc425b47fd658440a9fad776237a87ec1.zip chromium_src-60627a1fc425b47fd658440a9fad776237a87ec1.tar.gz chromium_src-60627a1fc425b47fd658440a9fad776237a87ec1.tar.bz2 |
GTK: Set the back/forward and bookmark bar menus to always show their images.
This only works for GTK 2.16+.
BUG=21495
Review URL: http://codereview.chromium.org/199099
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/back_forward_menu_model_gtk.cc | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/back_forward_menu_model_gtk.h | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_menu_controller_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.h | 3 | ||||
-rw-r--r-- | chrome/common/gtk_util.cc | 21 | ||||
-rw-r--r-- | chrome/common/gtk_util.h | 5 |
7 files changed, 37 insertions, 0 deletions
diff --git a/chrome/browser/gtk/back_forward_menu_model_gtk.cc b/chrome/browser/gtk/back_forward_menu_model_gtk.cc index ff31cf4..a1ce91e 100644 --- a/chrome/browser/gtk/back_forward_menu_model_gtk.cc +++ b/chrome/browser/gtk/back_forward_menu_model_gtk.cc @@ -54,3 +54,7 @@ void BackForwardMenuModelGtk::StoppedShowing() { if (button_) button_->StoppedShowingMenu(); } + +bool BackForwardMenuModelGtk::AlwaysShowImages() const { + return true; +} diff --git a/chrome/browser/gtk/back_forward_menu_model_gtk.h b/chrome/browser/gtk/back_forward_menu_model_gtk.h index 0704b98..9a6058c 100644 --- a/chrome/browser/gtk/back_forward_menu_model_gtk.h +++ b/chrome/browser/gtk/back_forward_menu_model_gtk.h @@ -29,6 +29,7 @@ class BackForwardMenuModelGtk : public BackForwardMenuModel, virtual bool IsCommandEnabled(int command_id) const; virtual void ExecuteCommand(int command_id); virtual void StoppedShowing(); + virtual bool AlwaysShowImages() const; private: BackForwardButtonGtk* button_; diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc index 8334fd5..8c12c58 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc @@ -163,6 +163,7 @@ void BookmarkMenuController::BuildMenu(const BookmarkNode* parent, gtk_image_menu_item_new_with_label(WideToUTF8(elided_name).c_str()); g_object_set_data(G_OBJECT(menu_item), "bookmark-node", AsVoid(node)); SetImageMenuItem(menu_item, node, profile_->GetBookmarkModel()); + gtk_util::SetAlwaysShowImage(menu_item); if (node->is_url()) { g_signal_connect(G_OBJECT(menu_item), "activate", diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 8cfe7f8..f63f23b 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -210,6 +210,8 @@ GtkWidget* MenuGtk::BuildMenuItemWithImage(const std::string& label, gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), gtk_image_new_from_pixbuf(pixbuf)); g_object_unref(pixbuf); + if (delegate_->AlwaysShowImages()) + gtk_util::SetAlwaysShowImage(menu_item); return menu_item; } diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h index 2d47f67..f0dc661 100644 --- a/chrome/browser/gtk/menu_gtk.h +++ b/chrome/browser/gtk/menu_gtk.h @@ -43,6 +43,9 @@ class MenuGtk { virtual std::string GetLabel(int command_id) const { return std::string(); } virtual bool HasIcon(int command_id) const { return false; } virtual const SkBitmap* GetIcon(int command_id) const { return NULL; } + // Return true if we should override the "gtk-menu-images" system setting + // when showing image menu items for this menu. + virtual bool AlwaysShowImages() const { return false; } }; // Builds a MenuGtk that uses |delegate| to perform actions and |menu_data| diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index 54842eb..090d304 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -474,4 +474,25 @@ GdkColor AverageColors(GdkColor color_one, GdkColor color_two) { return average_color; } +void SetAlwaysShowImage(GtkWidget* image_menu_item) { + // Compile time check: if it's available, just use the API. + // GTK_CHECK_VERSION is TRUE if the passed version is compatible. +#if GTK_CHECK_VERSION(2, 16, 1) + gtk_image_menu_item_set_always_show_image( + GTK_IMAGE_MENU_ITEM(image_menu_item), TRUE); +#else + // Run time check: if the API is not available, set the property manually. + // This will still only work with GTK 2.16+ as the property doesn't exist + // in earlier versions. + // gtk_check_version() returns NULL if the passed version is compatible. + if (!gtk_check_version(2, 16, 1)) { + GValue true_value = { 0 }; + g_value_init(&true_value, G_TYPE_BOOLEAN); + g_value_set_boolean(&true_value, TRUE); + g_object_set_property(G_OBJECT(image_menu_item), "always-show-image", + &true_value); + } +#endif +} + } // namespace gtk_util diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h index c12fe98..07c469f 100644 --- a/chrome/common/gtk_util.h +++ b/chrome/common/gtk_util.h @@ -171,6 +171,11 @@ void DrawTextEntryBackground(GtkWidget* offscreen_entry, // Returns the two colors averaged together. GdkColor AverageColors(GdkColor color_one, GdkColor color_two); +// Show the image for the given menu item, even if the user's default is to not +// show images. Only to be used for favicons or other menus where the image is +// crucial to its functionality. +void SetAlwaysShowImage(GtkWidget* image_menu_item); + } // namespace gtk_util #endif // CHROME_COMMON_GTK_UTIL_H_ |