diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-24 05:12:51 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-24 05:12:51 +0000 |
commit | d75d871e362c774d1f221f9e878ac508989789cf (patch) | |
tree | 86c3f3283f8cc0fc3fef6a1bf266b26c36d73bf0 | |
parent | c5419ba7b78b4ff4c00658586b240e076496a3d2 (diff) | |
download | chromium_src-d75d871e362c774d1f221f9e878ac508989789cf.zip chromium_src-d75d871e362c774d1f221f9e878ac508989789cf.tar.gz chromium_src-d75d871e362c774d1f221f9e878ac508989789cf.tar.bz2 |
Add support for status icon context menus for gtk.
Rename ResetContextIcon()->UpdatePlatformContextIcon().
BUG=37375
TEST=CreateIcon updated
Review URL: http://codereview.chromium.org/3127028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57142 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/status_icons/status_icon_mac.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/status_icons/status_icon_mac.mm | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/status_icons/status_icon_gtk.cc | 21 | ||||
-rw-r--r-- | chrome/browser/gtk/status_icons/status_icon_gtk.h | 10 | ||||
-rw-r--r-- | chrome/browser/gtk/status_icons/status_tray_gtk_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/status_icons/status_icon.cc | 2 | ||||
-rw-r--r-- | chrome/browser/status_icons/status_icon.h | 2 | ||||
-rw-r--r-- | chrome/browser/status_icons/status_icon_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/status_icons/status_tray_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/status_icons/status_icon_win.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/status_icons/status_icon_win.h | 3 |
13 files changed, 50 insertions, 16 deletions
diff --git a/chrome/browser/cocoa/status_icons/status_icon_mac.h b/chrome/browser/cocoa/status_icons/status_icon_mac.h index 3f4fbe2..78a2283 100644 --- a/chrome/browser/cocoa/status_icons/status_icon_mac.h +++ b/chrome/browser/cocoa/status_icons/status_icon_mac.h @@ -27,7 +27,8 @@ class StatusIconMac : public StatusIcon { virtual void SetToolTip(const string16& tool_tip); protected: - virtual void ResetContextMenu(menus::MenuModel* menu); + // Overridden from StatusIcon. + virtual void UpdatePlatformContextMenu(menus::MenuModel* menu); private: // Getter for item_ that allows lazy initialization. diff --git a/chrome/browser/cocoa/status_icons/status_icon_mac.mm b/chrome/browser/cocoa/status_icons/status_icon_mac.mm index 0d50c76..6b79b45 100644 --- a/chrome/browser/cocoa/status_icons/status_icon_mac.mm +++ b/chrome/browser/cocoa/status_icons/status_icon_mac.mm @@ -76,7 +76,7 @@ void StatusIconMac::SetToolTip(const string16& tool_tip) { [item() setToolTip:base::SysUTF16ToNSString(tool_tip)]; } -void StatusIconMac::ResetContextMenu(menus::MenuModel* menu) { +void StatusIconMac::UpdatePlatformContextMenu(menus::MenuModel* menu) { // TODO(atwilson): Add support for context menus for Mac when actually needed // (not yet used by anything) - http://crbug.com/37375. } diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 08cf95f..80c20c4 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -259,6 +259,12 @@ void MenuGtk::PopupAsContextAt(guint32 event_time, gfx::Point point) { PointMenuPositionFunc, &point, 3, event_time); } +void MenuGtk::PopupAsContextForStatusIcon(guint32 event_time, guint32 button, + GtkStatusIcon* icon) { + gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, gtk_status_icon_position_menu, + icon, button, event_time); +} + void MenuGtk::PopupAsFromKeyEvent(GtkWidget* widget) { Popup(widget, 0, gtk_get_current_event_time()); gtk_menu_shell_select_first(GTK_MENU_SHELL(menu_), FALSE); diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h index ee0114e..7f8e7ec 100644 --- a/chrome/browser/gtk/menu_gtk.h +++ b/chrome/browser/gtk/menu_gtk.h @@ -83,6 +83,10 @@ class MenuGtk { // Displays the menu at the given coords. |point| is intentionally not const. void PopupAsContextAt(guint32 event_time, gfx::Point point); + // Displays the menu as a context menu for the passed status icon. + void PopupAsContextForStatusIcon(guint32 event_time, guint32 button, + GtkStatusIcon* icon); + // Displays the menu following a keyboard event (such as selecting |widget| // and pressing "enter"). void PopupAsFromKeyEvent(GtkWidget* widget); diff --git a/chrome/browser/gtk/status_icons/status_icon_gtk.cc b/chrome/browser/gtk/status_icons/status_icon_gtk.cc index d6af0a7..7268b00 100644 --- a/chrome/browser/gtk/status_icons/status_icon_gtk.cc +++ b/chrome/browser/gtk/status_icons/status_icon_gtk.cc @@ -7,6 +7,7 @@ #include "base/string16.h" #include "base/logging.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/gtk/menu_gtk.h" #include "gfx/gtk_util.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -16,6 +17,8 @@ StatusIconGtk::StatusIconGtk() { g_signal_connect(icon_, "activate", G_CALLBACK(OnClickThunk), this); + g_signal_connect(icon_, "popup-menu", + G_CALLBACK(OnPopupMenuThunk), this); } StatusIconGtk::~StatusIconGtk() { @@ -40,11 +43,19 @@ void StatusIconGtk::SetToolTip(const string16& tool_tip) { gtk_status_icon_set_tooltip(icon_, UTF16ToUTF8(tool_tip).c_str()); } -void StatusIconGtk::ResetContextMenu(menus::MenuModel* menu) { - // TODO(atwilson): Add support for context menus for GTK - // (http://crbug.com.37375). -} - void StatusIconGtk::OnClick(GtkWidget* widget) { DispatchClickEvent(); } + +void StatusIconGtk::UpdatePlatformContextMenu(menus::MenuModel* model) { + if (!model) + menu_.reset(); + else + menu_.reset(new MenuGtk(NULL, model)); +} + +void StatusIconGtk::OnPopupMenu(GtkWidget* widget, guint button, guint time) { + // If we have a menu - display it. + if (menu_.get()) + menu_->PopupAsContextForStatusIcon(time, button, icon_); +} diff --git a/chrome/browser/gtk/status_icons/status_icon_gtk.h b/chrome/browser/gtk/status_icons/status_icon_gtk.h index 4aa6c93..7053ed5 100644 --- a/chrome/browser/gtk/status_icons/status_icon_gtk.h +++ b/chrome/browser/gtk/status_icons/status_icon_gtk.h @@ -11,6 +11,7 @@ #include "app/gtk_signal.h" #include "chrome/browser/status_icons/status_icon.h" +class MenuGtk; class SkBitmap; class StatusIconGtk : public StatusIcon { @@ -27,12 +28,19 @@ class StatusIconGtk : public StatusIcon { CHROMEGTK_CALLBACK_0(StatusIconGtk, void, OnClick); protected: - virtual void ResetContextMenu(menus::MenuModel* menu); + // Overridden from StatusIcon. + virtual void UpdatePlatformContextMenu(menus::MenuModel* menu); private: + // Callback invoked when user right-clicks on the status icon. + CHROMEGTK_CALLBACK_2(StatusIconGtk, void, OnPopupMenu, guint, guint); + // The currently-displayed icon for the window. GtkStatusIcon* icon_; + // The context menu for this icon (if any). + scoped_ptr<MenuGtk> menu_; + DISALLOW_COPY_AND_ASSIGN(StatusIconGtk); }; diff --git a/chrome/browser/gtk/status_icons/status_tray_gtk_unittest.cc b/chrome/browser/gtk/status_icons/status_tray_gtk_unittest.cc index 89f9524..0e28e9e 100644 --- a/chrome/browser/gtk/status_icons/status_tray_gtk_unittest.cc +++ b/chrome/browser/gtk/status_icons/status_tray_gtk_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/menus/simple_menu_model.h" #include "app/resource_bundle.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -33,6 +34,9 @@ TEST(StatusTrayGtkTest, CreateIcon) { icon->SetImage(*bitmap); icon->SetPressedImage(*bitmap); icon->SetToolTip(ASCIIToUTF16("tool tip")); + menus::SimpleMenuModel* menu = new menus::SimpleMenuModel(NULL); + menu->AddItem(0, ASCIIToUTF16("foo")); + icon->SetContextMenu(menu); } TEST(StatusTrayGtkTest, ClickOnIcon) { diff --git a/chrome/browser/status_icons/status_icon.cc b/chrome/browser/status_icons/status_icon.cc index 066419f..baaa6cc 100644 --- a/chrome/browser/status_icons/status_icon.cc +++ b/chrome/browser/status_icons/status_icon.cc @@ -31,5 +31,5 @@ void StatusIcon::DispatchClickEvent() { void StatusIcon::SetContextMenu(menus::MenuModel* menu) { context_menu_contents_.reset(menu); - ResetContextMenu(menu); + UpdatePlatformContextMenu(menu); } diff --git a/chrome/browser/status_icons/status_icon.h b/chrome/browser/status_icons/status_icon.h index 8f868b5..5398eb3 100644 --- a/chrome/browser/status_icons/status_icon.h +++ b/chrome/browser/status_icons/status_icon.h @@ -63,7 +63,7 @@ class StatusIcon { // Invoked after a call to SetContextMenu() to let the platform-specific // subclass update the native context menu based on the new model. If NULL is // passed, subclass should destroy the native context menu. - virtual void ResetContextMenu(menus::MenuModel* model) = 0; + virtual void UpdatePlatformContextMenu(menus::MenuModel* model) = 0; private: ObserverList<Observer> observers_; diff --git a/chrome/browser/status_icons/status_icon_unittest.cc b/chrome/browser/status_icons/status_icon_unittest.cc index 1738ff7..48fbc20 100644 --- a/chrome/browser/status_icons/status_icon_unittest.cc +++ b/chrome/browser/status_icons/status_icon_unittest.cc @@ -18,7 +18,7 @@ class TestStatusIcon : public StatusIcon { virtual void SetImage(const SkBitmap& image) {} virtual void SetPressedImage(const SkBitmap& image) {} virtual void SetToolTip(const string16& tool_tip) {} - virtual void ResetContextMenu(menus::MenuModel* menu) {} + virtual void UpdatePlatformContextMenu(menus::MenuModel* menu) {} }; TEST(StatusIconTest, ObserverAdd) { @@ -45,4 +45,3 @@ TEST(StatusIconTest, ObserverRemove) { icon.RemoveObserver(&observer); icon.DispatchClickEvent(); } - diff --git a/chrome/browser/status_icons/status_tray_unittest.cc b/chrome/browser/status_icons/status_tray_unittest.cc index 1d43cdc..a047689 100644 --- a/chrome/browser/status_icons/status_tray_unittest.cc +++ b/chrome/browser/status_icons/status_tray_unittest.cc @@ -15,7 +15,7 @@ class MockStatusIcon : public StatusIcon { virtual void SetImage(const SkBitmap& image) {} virtual void SetPressedImage(const SkBitmap& image) {} virtual void SetToolTip(const string16& tool_tip) {} - virtual void ResetContextMenu(menus::MenuModel* menu) {} + virtual void UpdatePlatformContextMenu(menus::MenuModel* menu) {} virtual void AddObserver(StatusIcon::Observer* observer) {} virtual void RemoveObserver(StatusIcon::Observer* observer) {} }; @@ -23,7 +23,7 @@ class MockStatusIcon : public StatusIcon { class TestStatusTray : public StatusTray { public: MOCK_METHOD0(CreatePlatformStatusIcon, StatusIcon*()); - MOCK_METHOD1(ResetContextMenu, void(menus::MenuModel*)); + MOCK_METHOD1(UpdatePlatformContextMenu, void(menus::MenuModel*)); }; TEST(StatusTrayTest, Create) { diff --git a/chrome/browser/views/status_icons/status_icon_win.cc b/chrome/browser/views/status_icons/status_icon_win.cc index 524829e..5545560 100644 --- a/chrome/browser/views/status_icons/status_icon_win.cc +++ b/chrome/browser/views/status_icons/status_icon_win.cc @@ -61,7 +61,7 @@ void StatusIconWin::InitIconData(NOTIFYICONDATA* icon_data) { icon_data->uID = icon_id_; } -void StatusIconWin::ResetContextMenu(menus::MenuModel* menu) { +void StatusIconWin::UpdatePlatformContextMenu(menus::MenuModel* menu) { // If no items are passed, blow away our context menu. if (!menu) { context_menu_.reset(); diff --git a/chrome/browser/views/status_icons/status_icon_win.h b/chrome/browser/views/status_icons/status_icon_win.h index f698fc4..08545ac 100644 --- a/chrome/browser/views/status_icons/status_icon_win.h +++ b/chrome/browser/views/status_icons/status_icon_win.h @@ -38,7 +38,8 @@ class StatusIconWin : public StatusIcon { void HandleClickEvent(int x, int y, bool left_button_click); protected: - virtual void ResetContextMenu(menus::MenuModel* menu); + // Overridden from StatusIcon. + virtual void UpdatePlatformContextMenu(menus::MenuModel* menu); private: void InitIconData(NOTIFYICONDATA* icon_data); |