Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/browser_actions_toolbar_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 return std::max((kButtonWidth + kButtonPadding) * icon_count - kButtonPadding, | 82 return std::max((kButtonWidth + kButtonPadding) * icon_count - kButtonPadding, |
| 83 0); | 83 0); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace | 86 } // namespace |
| 87 | 87 |
| 88 using ui::SimpleMenuModel; | 88 using ui::SimpleMenuModel; |
| 89 | 89 |
| 90 class BrowserActionButton : public content::NotificationObserver, | 90 class BrowserActionButton : public content::NotificationObserver, |
| 91 public ImageLoadingTracker::Observer, | 91 public ImageLoadingTracker::Observer, |
| 92 public ExtensionContextMenuModel::PopupDelegate, | |
| 93 public MenuGtk::Delegate { | 92 public MenuGtk::Delegate { |
| 94 public: | 93 public: |
| 95 BrowserActionButton(BrowserActionsToolbarGtk* toolbar, | 94 BrowserActionButton(BrowserActionsToolbarGtk* toolbar, |
| 96 const Extension* extension, | 95 const Extension* extension, |
| 97 ThemeServiceGtk* theme_provider) | 96 ThemeServiceGtk* theme_provider) |
| 98 : toolbar_(toolbar), | 97 : toolbar_(toolbar), |
| 99 extension_(extension), | 98 extension_(extension), |
| 100 image_(NULL), | 99 image_(NULL), |
| 101 tracker_(this), | 100 tracker_(this), |
| 102 tab_specific_icon_(NULL), | 101 tab_specific_icon_(NULL), |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } else { | 233 } else { |
| 235 return default_skbitmap_; | 234 return default_skbitmap_; |
| 236 } | 235 } |
| 237 } | 236 } |
| 238 | 237 |
| 239 MenuGtk* GetContextMenu() { | 238 MenuGtk* GetContextMenu() { |
| 240 if (!extension_->ShowConfigureContextMenus()) | 239 if (!extension_->ShowConfigureContextMenus()) |
| 241 return NULL; | 240 return NULL; |
| 242 | 241 |
| 243 context_menu_model_ = | 242 context_menu_model_ = |
| 244 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this); | 243 new ExtensionContextMenuModel(extension_, toolbar_->browser()); |
| 245 context_menu_.reset( | 244 context_menu_.reset( |
| 246 new MenuGtk(this, context_menu_model_.get())); | 245 new MenuGtk(this, context_menu_model_.get())); |
| 247 return context_menu_.get(); | 246 return context_menu_.get(); |
| 248 } | 247 } |
| 249 | 248 |
| 250 private: | 249 private: |
| 251 // MenuGtk::Delegate implementation. | 250 // MenuGtk::Delegate implementation. |
| 252 virtual void StoppedShowing() { | 251 virtual void StoppedShowing() { |
| 253 button_->UnsetPaintOverride(); | 252 button_->UnsetPaintOverride(); |
| 254 | 253 |
| 255 // If the context menu was showing for the overflow menu, re-assert the | 254 // If the context menu was showing for the overflow menu, re-assert the |
| 256 // grab that was shadowed. | 255 // grab that was shadowed. |
| 257 if (toolbar_->overflow_menu_.get()) | 256 if (toolbar_->overflow_menu_.get()) |
| 258 gtk_util::GrabAllInput(toolbar_->overflow_menu_->widget()); | 257 gtk_util::GrabAllInput(toolbar_->overflow_menu_->widget()); |
| 259 } | 258 } |
| 260 | 259 |
| 261 virtual void CommandWillBeExecuted() { | 260 virtual void CommandWillBeExecuted() { |
| 262 // If the context menu was showing for the overflow menu, and a command | 261 // If the context menu was showing for the overflow menu, and a command |
| 263 // is executed, then stop showing the overflow menu. | 262 // is executed, then stop showing the overflow menu. |
| 264 if (toolbar_->overflow_menu_.get()) | 263 if (toolbar_->overflow_menu_.get()) |
| 265 toolbar_->overflow_menu_->Cancel(); | 264 toolbar_->overflow_menu_->Cancel(); |
| 266 } | 265 } |
| 267 | 266 |
| 268 // Returns true to prevent further processing of the event that caused us to | 267 // Returns true to prevent further processing of the event that caused us to |
| 269 // show the popup, or false to continue processing. | 268 // show the popup, or false to continue processing. |
| 270 bool ShowPopup(bool devtools) { | 269 bool ShowPopup(bool devtools) { |
|
Evan Stade
2012/04/13 17:09:01
don't need the param any more
benwells
2012/04/16 02:20:32
Done.
| |
| 271 ExtensionAction* browser_action = extension_->browser_action(); | 270 ExtensionAction* browser_action = extension_->browser_action(); |
| 272 | 271 |
| 273 int tab_id = toolbar_->GetCurrentTabId(); | 272 int tab_id = toolbar_->GetCurrentTabId(); |
| 274 if (tab_id < 0) { | 273 if (tab_id < 0) { |
| 275 NOTREACHED() << "No current tab."; | 274 NOTREACHED() << "No current tab."; |
| 276 return true; | 275 return true; |
| 277 } | 276 } |
| 278 | 277 |
| 279 if (browser_action->HasPopup(tab_id)) { | 278 if (browser_action->HasPopup(tab_id)) { |
| 280 ExtensionPopupGtk::Show( | 279 ExtensionPopupGtk::Show( |
| 281 browser_action->GetPopupUrl(tab_id), toolbar_->browser(), | 280 browser_action->GetPopupUrl(tab_id), toolbar_->browser(), |
| 282 widget(), devtools); | 281 widget(), devtools); |
|
Evan Stade
2012/04/13 17:09:01
I bet the devtools param is no longer needed in Ex
benwells
2012/04/13 21:23:21
Yep that's right, and true in some way for all por
benwells
2012/04/16 02:20:32
Done.
| |
| 283 return true; | 282 return true; |
| 284 } | 283 } |
| 285 | 284 |
| 286 return false; | 285 return false; |
| 287 } | 286 } |
| 288 | 287 |
| 289 // ExtensionContextMenuModel::PopupDelegate implementation. | |
| 290 virtual void InspectPopup(ExtensionAction* action) { | |
| 291 ShowPopup(true); | |
| 292 } | |
| 293 | |
| 294 void SetImage(GdkPixbuf* image) { | 288 void SetImage(GdkPixbuf* image) { |
| 295 if (!image_) { | 289 if (!image_) { |
| 296 image_ = gtk_image_new_from_pixbuf(image); | 290 image_ = gtk_image_new_from_pixbuf(image); |
| 297 gtk_button_set_image(GTK_BUTTON(button()), image_); | 291 gtk_button_set_image(GTK_BUTTON(button()), image_); |
| 298 } else { | 292 } else { |
| 299 gtk_image_set_from_pixbuf(GTK_IMAGE(image_), image); | 293 gtk_image_set_from_pixbuf(GTK_IMAGE(image_), image); |
| 300 } | 294 } |
| 301 } | 295 } |
| 302 | 296 |
| 303 static gboolean OnButtonPress(GtkWidget* widget, | 297 static gboolean OnButtonPress(GtkWidget* widget, |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1078 | 1072 |
| 1079 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 1073 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
| 1080 event->time); | 1074 event->time); |
| 1081 return TRUE; | 1075 return TRUE; |
| 1082 } | 1076 } |
| 1083 | 1077 |
| 1084 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 1078 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
| 1085 if (!resize_animation_.is_animating()) | 1079 if (!resize_animation_.is_animating()) |
| 1086 UpdateChevronVisibility(); | 1080 UpdateChevronVisibility(); |
| 1087 } | 1081 } |
| OLD | NEW |