diff options
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 67 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 27 |
2 files changed, 59 insertions, 35 deletions
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index c3468b8..186b575 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -19,9 +19,10 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/command_updater.h" -#include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/extensions/extension_action_context_menu_model.h" #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/gtk/cairo_cached_surface.h" #include "chrome/browser/gtk/extension_popup_gtk.h" #include "chrome/browser/gtk/first_run_bubble.h" @@ -714,9 +715,9 @@ LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( // Make the event box not visible so it does not paint a background. gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); g_signal_connect(event_box_.get(), "button-press-event", - G_CALLBACK(&OnButtonPressed), this); + G_CALLBACK(&OnButtonPressedThunk), this); g_signal_connect_after(event_box_.get(), "expose-event", - G_CALLBACK(OnExposeEvent), this); + G_CALLBACK(OnExposeEventThunk), this); image_.Own(gtk_image_new()); gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); @@ -855,39 +856,47 @@ void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded(SkBitmap* image, } void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { - GdkEventButton event; - event.button = 1; - OnButtonPressed(widget(), &event, this); + GdkEvent event; + event.button.button = 1; + OnButtonPressed(widget(), &event); } -// static gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( GtkWidget* sender, - GdkEventButton* event, - LocationBarViewGtk::PageActionViewGtk* page_action_view) { - ExtensionAction* page_action = page_action_view->page_action_; - if (page_action->has_popup()) { - ExtensionPopupGtk::Show( - page_action->popup_url(), - page_action_view->owner_->browser_, - gtk_util::GetWidgetRectRelativeToToplevel( - page_action_view->event_box_.get())); + GdkEvent* event) { + if (event->button.button != 3) { + if (page_action_->has_popup()) { + ExtensionPopupGtk::Show( + page_action_->popup_url(), + owner_->browser_, + gtk_util::GetWidgetRectRelativeToToplevel(event_box_.get())); + } else { + ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( + profile_, + page_action_->extension_id(), + page_action_->id(), + current_tab_id_, + current_url_.spec(), + event->button.button); + } } else { - ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( - page_action_view->profile_, - page_action->extension_id(), - page_action->id(), - page_action_view->current_tab_id_, - page_action_view->current_url_.spec(), - event->button); + Extension* extension = profile_->GetExtensionsService()->GetExtensionById( + page_action()->extension_id(), false); + + if (!context_menu_model_.get()) + context_menu_model_.reset(new ExtensionActionContextMenuModel(extension)); + + context_menu_.reset( + new MenuGtk(this, context_menu_model_.get())); + context_menu_->Popup(sender, event); } - return true; + + return TRUE; } -// static gboolean LocationBarViewGtk::PageActionViewGtk::OnExposeEvent( - GtkWidget* widget, GdkEventExpose* event, PageActionViewGtk* view) { - TabContents* contents = view->owner_->browser_->GetSelectedTabContents(); + GtkWidget* widget, GdkEventExpose* event) { + TabContents* contents = owner_->browser_->GetSelectedTabContents(); if (!contents) return FALSE; @@ -895,12 +904,12 @@ gboolean LocationBarViewGtk::PageActionViewGtk::OnExposeEvent( if (tab_id < 0) return FALSE; - std::string badge_text = view->page_action_->GetBadgeText(tab_id); + std::string badge_text = page_action_->GetBadgeText(tab_id); if (badge_text.empty()) return FALSE; gfx::CanvasPaint canvas(event, false); gfx::Rect bounding_rect(widget->allocation); - view->page_action_->PaintBadge(&canvas, bounding_rect, tab_id); + page_action_->PaintBadge(&canvas, bounding_rect, tab_id); return FALSE; } diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index 7f40709..078ebd60 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -16,6 +16,7 @@ #include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" #include "chrome/browser/extensions/image_loading_tracker.h" +#include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/location_bar.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" @@ -29,6 +30,7 @@ class BubblePositioner; class Browser; class CommandUpdater; class ExtensionAction; +class ExtensionActionContextMenuModel; class GtkThemeProvider; class Profile; class SkBitmap; @@ -105,7 +107,8 @@ class LocationBarViewGtk : public AutocompleteEditController, static const GdkColor kBackgroundColorByLevel[3]; private: - class PageActionViewGtk : public ImageLoadingTracker::Observer { + class PageActionViewGtk : public ImageLoadingTracker::Observer, + public MenuGtk::Delegate { public: PageActionViewGtk( LocationBarViewGtk* owner, Profile* profile, @@ -130,11 +133,19 @@ class LocationBarViewGtk : public AutocompleteEditController, void TestActivatePageAction(); private: - static gboolean OnButtonPressed(GtkWidget* sender, GdkEventButton* event, - PageActionViewGtk* page_action_view); - static gboolean OnExposeEvent(GtkWidget* widget, - GdkEventExpose* event, - PageActionViewGtk* page_action_view); + static gboolean OnButtonPressedThunk(GtkWidget* sender, + GdkEvent* event, + PageActionViewGtk* page_action_view) { + return page_action_view->OnButtonPressed(sender, event); + } + gboolean OnButtonPressed(GtkWidget* sender, GdkEvent* event); + + static gboolean OnExposeEventThunk(GtkWidget* widget, + GdkEventExpose* event, + PageActionViewGtk* page_action_view) { + return page_action_view->OnExposeEvent(widget, event); + } + gboolean OnExposeEvent(GtkWidget* widget, GdkEventExpose* event); // The location bar view that owns us. LocationBarViewGtk* owner_; @@ -170,6 +181,10 @@ class LocationBarViewGtk : public AutocompleteEditController, // The URL we are currently showing the icon for. GURL current_url_; + // The context menu view and model for this extension action. + scoped_ptr<MenuGtk> context_menu_; + scoped_ptr<ExtensionActionContextMenuModel> context_menu_model_; + DISALLOW_COPY_AND_ASSIGN(PageActionViewGtk); }; friend class PageActionViewGtk; |