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

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

Issue 10412052: Pull browser action click logic into ToolbarModelController, so that when I (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: views changes Created 8 years, 7 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) 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 gtk_util::GrabAllInput(toolbar_->overflow_menu_->widget()); 271 gtk_util::GrabAllInput(toolbar_->overflow_menu_->widget());
272 } 272 }
273 273
274 virtual void CommandWillBeExecuted() { 274 virtual void CommandWillBeExecuted() {
275 // If the context menu was showing for the overflow menu, and a command 275 // If the context menu was showing for the overflow menu, and a command
276 // is executed, then stop showing the overflow menu. 276 // is executed, then stop showing the overflow menu.
277 if (toolbar_->overflow_menu_.get()) 277 if (toolbar_->overflow_menu_.get())
278 toolbar_->overflow_menu_->Cancel(); 278 toolbar_->overflow_menu_->Cancel();
279 } 279 }
280 280
281 // Returns true to prevent further processing of the event that caused us to
282 // show the popup, or false to continue processing.
283 bool ShowPopup() {
284 ExtensionAction* browser_action = extension_->browser_action();
285
286 int tab_id = toolbar_->GetCurrentTabId();
287 if (tab_id < 0) {
288 NOTREACHED() << "No current tab.";
289 return true;
290 }
291
292 if (browser_action->HasPopup(tab_id)) {
293 ExtensionPopupGtk::Show(
294 browser_action->GetPopupUrl(tab_id), toolbar_->browser(), widget());
295 return true;
296 }
297
298 return false;
299 }
300
301 void SetImage(GdkPixbuf* image) { 281 void SetImage(GdkPixbuf* image) {
302 if (!image_) { 282 if (!image_) {
303 image_ = gtk_image_new_from_pixbuf(image); 283 image_ = gtk_image_new_from_pixbuf(image);
304 gtk_button_set_image(GTK_BUTTON(button()), image_); 284 gtk_button_set_image(GTK_BUTTON(button()), image_);
305 } else { 285 } else {
306 gtk_image_set_from_pixbuf(GTK_IMAGE(image_), image); 286 gtk_image_set_from_pixbuf(GTK_IMAGE(image_), image);
307 } 287 }
308 } 288 }
309 289
310 static gboolean OnButtonPress(GtkWidget* widget, 290 static gboolean OnButtonPress(GtkWidget* widget,
311 GdkEventButton* event, 291 GdkEventButton* event,
312 BrowserActionButton* action) { 292 BrowserActionButton* action) {
313 if (event->button != 3) 293 if (event->button != 3)
314 return FALSE; 294 return FALSE;
315 295
316 MenuGtk* menu = action->GetContextMenu(); 296 MenuGtk* menu = action->GetContextMenu();
317 if (!menu) 297 if (!menu)
318 return FALSE; 298 return FALSE;
319 299
320 action->button_->SetPaintOverride(GTK_STATE_ACTIVE); 300 action->button_->SetPaintOverride(GTK_STATE_ACTIVE);
321 menu->PopupForWidget(widget, event->button, event->time); 301 menu->PopupForWidget(widget, event->button, event->time);
322 302
323 return TRUE; 303 return TRUE;
324 } 304 }
325 305
326 static void OnClicked(GtkWidget* widget, BrowserActionButton* action) { 306 static void OnClicked(GtkWidget* widget, BrowserActionButton* action) {
327 if (action->ShowPopup()) 307 ExtensionToolbarModel* model = action->toolbar_->model();
328 return; 308 const Extension* extension = action->extension_;
309 Browser* browser = action->toolbar_->browser();
310 GtkWidget* chevron = action->toolbar_->chevron();
311 GURL popup_url;
329 312
330 action->toolbar_->model()->ExecuteBrowserAction( 313 switch (model->ExecuteBrowserAction(extension, browser, &popup_url)) {
331 action->extension_->id(), action->toolbar_->browser()); 314 case ExtensionToolbarModel::ACTION_NONE:
315 break;
316 case ExtensionToolbarModel::ACTION_SHOW_POPUP:
317 ExtensionPopupGtk::Show(popup_url, browser, chevron);
318 break;
319 }
332 } 320 }
333 321
334 static gboolean OnExposeEvent(GtkWidget* widget, 322 static gboolean OnExposeEvent(GtkWidget* widget,
335 GdkEventExpose* event, 323 GdkEventExpose* event,
336 BrowserActionButton* button) { 324 BrowserActionButton* button) {
337 int tab_id = button->toolbar_->GetCurrentTabId(); 325 int tab_id = button->toolbar_->GetCurrentTabId();
338 if (tab_id < 0) 326 if (tab_id < 0)
339 return FALSE; 327 return FALSE;
340 328
341 ExtensionAction* action = button->extension_->browser_action(); 329 ExtensionAction* action = button->extension_->browser_action();
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 } 775 }
788 776
789 bool BrowserActionsToolbarGtk::GetAcceleratorForCommandId( 777 bool BrowserActionsToolbarGtk::GetAcceleratorForCommandId(
790 int command_id, 778 int command_id,
791 ui::Accelerator* accelerator) { 779 ui::Accelerator* accelerator) {
792 return false; 780 return false;
793 } 781 }
794 782
795 void BrowserActionsToolbarGtk::ExecuteCommand(int command_id) { 783 void BrowserActionsToolbarGtk::ExecuteCommand(int command_id) {
796 const Extension* extension = model_->GetExtensionByIndex(command_id); 784 const Extension* extension = model_->GetExtensionByIndex(command_id);
797 ExtensionAction* browser_action = extension->browser_action(); 785 GURL popup_url;
798 786
799 int tab_id = GetCurrentTabId(); 787 switch (model_->ExecuteBrowserAction(extension, browser(), &popup_url)) {
800 if (tab_id < 0) { 788 case ExtensionToolbarModel::ACTION_NONE:
801 NOTREACHED() << "No current tab."; 789 break;
802 return; 790 case ExtensionToolbarModel::ACTION_SHOW_POPUP:
803 } 791 ExtensionPopupGtk::Show(popup_url, browser(), chevron());
804 792 break;
805 if (browser_action->HasPopup(tab_id)) {
806 ExtensionPopupGtk::Show(
807 browser_action->GetPopupUrl(tab_id), browser(), chevron());
808 } else {
809 model_->ExecuteBrowserAction(extension->id(), browser());
810 } 793 }
811 } 794 }
812 795
813 void BrowserActionsToolbarGtk::StoppedShowing() { 796 void BrowserActionsToolbarGtk::StoppedShowing() {
814 overflow_button_->UnsetPaintOverride(); 797 overflow_button_->UnsetPaintOverride();
815 } 798 }
816 799
817 bool BrowserActionsToolbarGtk::AlwaysShowIconForCmd(int command_id) const { 800 bool BrowserActionsToolbarGtk::AlwaysShowIconForCmd(int command_id) const {
818 return true; 801 return true;
819 } 802 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 1065
1083 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), 1066 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root),
1084 event->time); 1067 event->time);
1085 return TRUE; 1068 return TRUE;
1086 } 1069 }
1087 1070
1088 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { 1071 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) {
1089 if (!resize_animation_.is_animating()) 1072 if (!resize_animation_.is_animating())
1090 UpdateChevronVisibility(); 1073 UpdateChevronVisibility();
1091 } 1074 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698