Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: chrome/browser/gtk/browser_actions_toolbar_gtk.cc

Issue 1107007: Extension context menu refactor (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h" 5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/gfx/canvas_paint.h" 9 #include "app/gfx/canvas_paint.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/extensions/extension_action_context_menu_model.h"
12 #include "chrome/browser/extensions/extension_browser_event_router.h" 11 #include "chrome/browser/extensions/extension_browser_event_router.h"
12 #include "chrome/browser/extensions/extension_context_menu_model.h"
13 #include "chrome/browser/extensions/extensions_service.h" 13 #include "chrome/browser/extensions/extensions_service.h"
14 #include "chrome/browser/extensions/image_loading_tracker.h" 14 #include "chrome/browser/extensions/image_loading_tracker.h"
15 #include "chrome/browser/gtk/cairo_cached_surface.h" 15 #include "chrome/browser/gtk/cairo_cached_surface.h"
16 #include "chrome/browser/gtk/extension_popup_gtk.h" 16 #include "chrome/browser/gtk/extension_popup_gtk.h"
17 #include "chrome/browser/gtk/gtk_chrome_button.h" 17 #include "chrome/browser/gtk/gtk_chrome_button.h"
18 #include "chrome/browser/gtk/gtk_chrome_shrinkable_hbox.h" 18 #include "chrome/browser/gtk/gtk_chrome_shrinkable_hbox.h"
19 #include "chrome/browser/gtk/gtk_theme_provider.h" 19 #include "chrome/browser/gtk/gtk_theme_provider.h"
20 #include "chrome/browser/gtk/gtk_util.h" 20 #include "chrome/browser/gtk/gtk_util.h"
21 #include "chrome/browser/gtk/menu_gtk.h" 21 #include "chrome/browser/gtk/menu_gtk.h"
22 #include "chrome/browser/gtk/view_id_util.h" 22 #include "chrome/browser/gtk/view_id_util.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // The minimum width in pixels of the button hbox if |icon_count| icons are 55 // The minimum width in pixels of the button hbox if |icon_count| icons are
56 // showing. 56 // showing.
57 gint WidthForIconCount(gint icon_count) { 57 gint WidthForIconCount(gint icon_count) {
58 return std::max((kButtonSize + kButtonPadding) * icon_count - kButtonPadding, 58 return std::max((kButtonSize + kButtonPadding) * icon_count - kButtonPadding,
59 0); 59 0);
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 class BrowserActionButton : public NotificationObserver, 64 class BrowserActionButton : public NotificationObserver,
65 public ImageLoadingTracker::Observer { 65 public ImageLoadingTracker::Observer,
66 public ExtensionContextMenuModel::PopupDelegate {
66 public: 67 public:
67 BrowserActionButton(BrowserActionsToolbarGtk* toolbar, 68 BrowserActionButton(BrowserActionsToolbarGtk* toolbar,
68 Extension* extension) 69 Extension* extension)
69 : toolbar_(toolbar), 70 : toolbar_(toolbar),
70 extension_(extension), 71 extension_(extension),
71 tracker_(NULL), 72 tracker_(NULL),
72 tab_specific_icon_(NULL), 73 tab_specific_icon_(NULL),
73 default_icon_(NULL) { 74 default_icon_(NULL) {
74 button_.Own( 75 button_.Own(
75 GtkThemeProvider::GetFrom(toolbar->profile_)->BuildChromeButton()); 76 GtkThemeProvider::GetFrom(toolbar->profile_)->BuildChromeButton());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 const SkBitmap& image = extension_->browser_action()->GetIcon( 171 const SkBitmap& image = extension_->browser_action()->GetIcon(
171 toolbar_->GetCurrentTabId()); 172 toolbar_->GetCurrentTabId());
172 if (!image.isNull()) { 173 if (!image.isNull()) {
173 return image; 174 return image;
174 } else { 175 } else {
175 return default_skbitmap_; 176 return default_skbitmap_;
176 } 177 }
177 } 178 }
178 179
179 private: 180 private:
181 // ExtensionContextMenuModel::PopupDelegate implementation.
182 virtual void InspectPopup(ExtensionAction* action) {
183 // TODO(estade): http://crbug.com/24477
184 NOTIMPLEMENTED();
185 }
186
180 void SetImage(GdkPixbuf* image) { 187 void SetImage(GdkPixbuf* image) {
181 gtk_button_set_image(GTK_BUTTON(button_.get()), 188 gtk_button_set_image(GTK_BUTTON(button_.get()),
182 gtk_image_new_from_pixbuf(image)); 189 gtk_image_new_from_pixbuf(image));
183 } 190 }
184 191
185 static gboolean OnButtonPress(GtkWidget* widget, 192 static gboolean OnButtonPress(GtkWidget* widget,
186 GdkEvent* event, 193 GdkEvent* event,
187 BrowserActionButton* action) { 194 BrowserActionButton* action) {
188 if (event->button.button != 3) 195 if (event->button.button != 3)
189 return FALSE; 196 return FALSE;
190 197
191 // TODO(rafaelw): support inspecting popups. 198 action->context_menu_model_.reset(
192 if (!action->context_menu_model_.get()) { 199 new ExtensionContextMenuModel(
193 action->context_menu_model_.reset( 200 action->extension_,
194 new ExtensionActionContextMenuModel(action->extension_, 201 action->toolbar_->browser(),
195 action->extension_->browser_action(), 202 action));
196 action->toolbar_->browser()->profile()->GetPrefs(), NULL));
197 }
198
199 action->context_menu_.reset( 203 action->context_menu_.reset(
200 new MenuGtk(NULL, action->context_menu_model_.get())); 204 new MenuGtk(NULL, action->context_menu_model_.get()));
205 action->context_menu_->Popup(widget, event);
201 206
202 action->context_menu_->Popup(widget, event);
203 return TRUE; 207 return TRUE;
204 } 208 }
205 209
206 static void OnClicked(GtkWidget* widget, BrowserActionButton* action) { 210 static void OnClicked(GtkWidget* widget, BrowserActionButton* action) {
207 ExtensionAction* browser_action = action->extension_->browser_action(); 211 ExtensionAction* browser_action = action->extension_->browser_action();
208 212
209 int tab_id = action->toolbar_->GetCurrentTabId(); 213 int tab_id = action->toolbar_->GetCurrentTabId();
210 if (tab_id < 0) { 214 if (tab_id < 0) {
211 NOTREACHED() << "No current tab."; 215 NOTREACHED() << "No current tab.";
212 return; 216 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // If the browser action has a default icon, it will be here. 272 // If the browser action has a default icon, it will be here.
269 GdkPixbuf* default_icon_; 273 GdkPixbuf* default_icon_;
270 274
271 // Same as |default_icon_|, but stored as SkBitmap. 275 // Same as |default_icon_|, but stored as SkBitmap.
272 SkBitmap default_skbitmap_; 276 SkBitmap default_skbitmap_;
273 277
274 NotificationRegistrar registrar_; 278 NotificationRegistrar registrar_;
275 279
276 // The context menu view and model for this extension action. 280 // The context menu view and model for this extension action.
277 scoped_ptr<MenuGtk> context_menu_; 281 scoped_ptr<MenuGtk> context_menu_;
278 scoped_ptr<ExtensionActionContextMenuModel> context_menu_model_; 282 scoped_ptr<ExtensionContextMenuModel> context_menu_model_;
279 283
280 friend class BrowserActionsToolbarGtk; 284 friend class BrowserActionsToolbarGtk;
281 }; 285 };
282 286
283 // BrowserActionsToolbarGtk ---------------------------------------------------- 287 // BrowserActionsToolbarGtk ----------------------------------------------------
284 288
285 BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser) 289 BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser)
286 : browser_(browser), 290 : browser_(browser),
287 profile_(browser->profile()), 291 profile_(browser->profile()),
288 theme_provider_(GtkThemeProvider::GetFrom(browser->profile())), 292 theme_provider_(GtkThemeProvider::GetFrom(browser->profile())),
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 745
742 // TODO(estade): set the menu item's tooltip. 746 // TODO(estade): set the menu item's tooltip.
743 } 747 }
744 748
745 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(overflow), 749 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(overflow),
746 GTK_STATE_ACTIVE); 750 GTK_STATE_ACTIVE);
747 overflow_menu_->PopupAsFromKeyEvent(overflow); 751 overflow_menu_->PopupAsFromKeyEvent(overflow);
748 752
749 return FALSE; 753 return FALSE;
750 } 754 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698