| OLD | NEW |
| 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" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 const SkBitmap& image = extension_->browser_action()->GetIcon( | 171 const SkBitmap& image = extension_->browser_action()->GetIcon( |
| 172 toolbar_->GetCurrentTabId()); | 172 toolbar_->GetCurrentTabId()); |
| 173 if (!image.isNull()) { | 173 if (!image.isNull()) { |
| 174 return image; | 174 return image; |
| 175 } else { | 175 } else { |
| 176 return default_skbitmap_; | 176 return default_skbitmap_; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 private: | 180 private: |
| 181 // Returns true to prevent further processing of the event that caused us to |
| 182 // show the popup, or false to continue processing. |
| 183 bool ShowPopup(bool devtools) { |
| 184 ExtensionAction* browser_action = extension_->browser_action(); |
| 185 |
| 186 int tab_id = toolbar_->GetCurrentTabId(); |
| 187 if (tab_id < 0) { |
| 188 NOTREACHED() << "No current tab."; |
| 189 return true; |
| 190 } |
| 191 |
| 192 if (browser_action->HasPopup(tab_id)) { |
| 193 ExtensionPopupGtk::Show( |
| 194 browser_action->GetPopupUrl(tab_id), |
| 195 toolbar_->browser(), |
| 196 gtk_util::GetWidgetRectRelativeToToplevel(widget()), |
| 197 devtools); |
| 198 return true; |
| 199 } |
| 200 |
| 201 return false; |
| 202 } |
| 203 |
| 181 // ExtensionContextMenuModel::PopupDelegate implementation. | 204 // ExtensionContextMenuModel::PopupDelegate implementation. |
| 182 virtual void InspectPopup(ExtensionAction* action) { | 205 virtual void InspectPopup(ExtensionAction* action) { |
| 183 // TODO(estade): http://crbug.com/24477 | 206 ShowPopup(true); |
| 184 NOTIMPLEMENTED(); | |
| 185 } | 207 } |
| 186 | 208 |
| 187 void SetImage(GdkPixbuf* image) { | 209 void SetImage(GdkPixbuf* image) { |
| 188 gtk_button_set_image(GTK_BUTTON(button_.get()), | 210 gtk_button_set_image(GTK_BUTTON(button_.get()), |
| 189 gtk_image_new_from_pixbuf(image)); | 211 gtk_image_new_from_pixbuf(image)); |
| 190 } | 212 } |
| 191 | 213 |
| 192 static gboolean OnButtonPress(GtkWidget* widget, | 214 static gboolean OnButtonPress(GtkWidget* widget, |
| 193 GdkEvent* event, | 215 GdkEvent* event, |
| 194 BrowserActionButton* action) { | 216 BrowserActionButton* action) { |
| 195 if (event->button.button != 3) | 217 if (event->button.button != 3) |
| 196 return FALSE; | 218 return FALSE; |
| 197 | 219 |
| 198 action->context_menu_model_.reset( | 220 action->context_menu_model_.reset( |
| 199 new ExtensionContextMenuModel( | 221 new ExtensionContextMenuModel( |
| 200 action->extension_, | 222 action->extension_, |
| 201 action->toolbar_->browser(), | 223 action->toolbar_->browser(), |
| 202 action)); | 224 action)); |
| 203 action->context_menu_.reset( | 225 action->context_menu_.reset( |
| 204 new MenuGtk(NULL, action->context_menu_model_.get())); | 226 new MenuGtk(NULL, action->context_menu_model_.get())); |
| 205 action->context_menu_->Popup(widget, event); | 227 action->context_menu_->Popup(widget, event); |
| 206 | 228 |
| 207 return TRUE; | 229 return TRUE; |
| 208 } | 230 } |
| 209 | 231 |
| 210 static void OnClicked(GtkWidget* widget, BrowserActionButton* action) { | 232 static void OnClicked(GtkWidget* widget, BrowserActionButton* action) { |
| 211 ExtensionAction* browser_action = action->extension_->browser_action(); | 233 if (action->ShowPopup(false)) |
| 234 return; |
| 212 | 235 |
| 213 int tab_id = action->toolbar_->GetCurrentTabId(); | 236 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( |
| 214 if (tab_id < 0) { | 237 action->toolbar_->browser()->profile(), action->extension_->id(), |
| 215 NOTREACHED() << "No current tab."; | 238 action->toolbar_->browser()); |
| 216 return; | |
| 217 } | |
| 218 | |
| 219 if (browser_action->HasPopup(tab_id)) { | |
| 220 ExtensionPopupGtk::Show( | |
| 221 browser_action->GetPopupUrl(tab_id), | |
| 222 action->toolbar_->browser(), | |
| 223 gtk_util::GetWidgetRectRelativeToToplevel(widget)); | |
| 224 } else { | |
| 225 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( | |
| 226 action->toolbar_->browser()->profile(), action->extension_->id(), | |
| 227 action->toolbar_->browser()); | |
| 228 } | |
| 229 } | 239 } |
| 230 | 240 |
| 231 static gboolean OnExposeEvent(GtkWidget* widget, | 241 static gboolean OnExposeEvent(GtkWidget* widget, |
| 232 GdkEventExpose* event, | 242 GdkEventExpose* event, |
| 233 BrowserActionButton* button) { | 243 BrowserActionButton* button) { |
| 234 int tab_id = button->toolbar_->GetCurrentTabId(); | 244 int tab_id = button->toolbar_->GetCurrentTabId(); |
| 235 if (tab_id < 0) | 245 if (tab_id < 0) |
| 236 return FALSE; | 246 return FALSE; |
| 237 | 247 |
| 238 ExtensionAction* action = button->extension_->browser_action(); | 248 ExtensionAction* action = button->extension_->browser_action(); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 | 544 |
| 535 int tab_id = GetCurrentTabId(); | 545 int tab_id = GetCurrentTabId(); |
| 536 if (tab_id < 0) { | 546 if (tab_id < 0) { |
| 537 NOTREACHED() << "No current tab."; | 547 NOTREACHED() << "No current tab."; |
| 538 return; | 548 return; |
| 539 } | 549 } |
| 540 | 550 |
| 541 if (browser_action->HasPopup(tab_id)) { | 551 if (browser_action->HasPopup(tab_id)) { |
| 542 ExtensionPopupGtk::Show( | 552 ExtensionPopupGtk::Show( |
| 543 browser_action->GetPopupUrl(tab_id), browser(), | 553 browser_action->GetPopupUrl(tab_id), browser(), |
| 544 gtk_util::GetWidgetRectRelativeToToplevel(overflow_button_.widget())); | 554 gtk_util::GetWidgetRectRelativeToToplevel(overflow_button_.widget()), |
| 555 false); |
| 545 } else { | 556 } else { |
| 546 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( | 557 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( |
| 547 browser()->profile(), extension->id(), browser()); | 558 browser()->profile(), extension->id(), browser()); |
| 548 } | 559 } |
| 549 } | 560 } |
| 550 | 561 |
| 551 void BrowserActionsToolbarGtk::StoppedShowing() { | 562 void BrowserActionsToolbarGtk::StoppedShowing() { |
| 552 gtk_chrome_button_unset_paint_state( | 563 gtk_chrome_button_unset_paint_state( |
| 553 GTK_CHROME_BUTTON(overflow_button_.widget())); | 564 GTK_CHROME_BUTTON(overflow_button_.widget())); |
| 554 } | 565 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 GtkWidget* previous_toplevel)
{ | 648 GtkWidget* previous_toplevel)
{ |
| 638 GtkWidget* toplevel = gtk_widget_get_toplevel(widget); | 649 GtkWidget* toplevel = gtk_widget_get_toplevel(widget); |
| 639 if (!GTK_WIDGET_TOPLEVEL(toplevel)) | 650 if (!GTK_WIDGET_TOPLEVEL(toplevel)) |
| 640 return; | 651 return; |
| 641 | 652 |
| 642 g_signal_connect(toplevel, "set-focus", G_CALLBACK(OnSetFocusThunk), this); | 653 g_signal_connect(toplevel, "set-focus", G_CALLBACK(OnSetFocusThunk), this); |
| 643 } | 654 } |
| 644 | 655 |
| 645 void BrowserActionsToolbarGtk::OnSetFocus(GtkWidget* widget, | 656 void BrowserActionsToolbarGtk::OnSetFocus(GtkWidget* widget, |
| 646 GtkWidget* focus_widget) { | 657 GtkWidget* focus_widget) { |
| 658 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); |
| 647 // The focus of the parent window has changed. Close the popup. Delay the hide | 659 // The focus of the parent window has changed. Close the popup. Delay the hide |
| 648 // because it will destroy the RenderViewHost, which may still be on the | 660 // because it will destroy the RenderViewHost, which may still be on the |
| 649 // call stack. | 661 // call stack. |
| 650 if (!ExtensionPopupGtk::get_current_extension_popup()) | 662 if (!popup || popup->being_inspected()) |
| 651 return; | 663 return; |
| 652 MessageLoop::current()->PostTask(FROM_HERE, | 664 MessageLoop::current()->PostTask(FROM_HERE, |
| 653 method_factory_.NewRunnableMethod(&BrowserActionsToolbarGtk::HidePopup)); | 665 method_factory_.NewRunnableMethod(&BrowserActionsToolbarGtk::HidePopup)); |
| 654 } | 666 } |
| 655 | 667 |
| 656 gboolean BrowserActionsToolbarGtk::OnGripperMotionNotify( | 668 gboolean BrowserActionsToolbarGtk::OnGripperMotionNotify( |
| 657 GtkWidget* widget, GdkEventMotion* event) { | 669 GtkWidget* widget, GdkEventMotion* event) { |
| 658 if (!(event->state & GDK_BUTTON1_MASK)) | 670 if (!(event->state & GDK_BUTTON1_MASK)) |
| 659 return FALSE; | 671 return FALSE; |
| 660 | 672 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 | 757 |
| 746 // TODO(estade): set the menu item's tooltip. | 758 // TODO(estade): set the menu item's tooltip. |
| 747 } | 759 } |
| 748 | 760 |
| 749 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(overflow), | 761 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(overflow), |
| 750 GTK_STATE_ACTIVE); | 762 GTK_STATE_ACTIVE); |
| 751 overflow_menu_->PopupAsFromKeyEvent(overflow); | 763 overflow_menu_->PopupAsFromKeyEvent(overflow); |
| 752 | 764 |
| 753 return FALSE; | 765 return FALSE; |
| 754 } | 766 } |
| OLD | NEW |