Index: chrome/browser/ui/gtk/location_bar_view_gtk.cc |
=================================================================== |
--- chrome/browser/ui/gtk/location_bar_view_gtk.cc (revision 126791) |
+++ chrome/browser/ui/gtk/location_bar_view_gtk.cc (working copy) |
@@ -37,6 +37,7 @@ |
#include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
#include "chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h" |
#include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" |
+#include "chrome/browser/ui/gtk/browser_window_gtk.h" |
#include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h" |
#include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
#include "chrome/browser/ui/gtk/first_run_bubble.h" |
@@ -60,6 +61,7 @@ |
#include "grit/theme_resources.h" |
#include "grit/theme_resources_standard.h" |
#include "net/base/net_util.h" |
+#include "ui/base/accelerators/accelerator_gtk.h" |
#include "ui/base/dragdrop/gtk_dnd_util.h" |
#include "ui/base/gtk/gtk_hig_constants.h" |
#include "ui/base/l10n/l10n_util.h" |
@@ -671,7 +673,7 @@ |
WebContents* contents = GetWebContents(); |
if (!page_action_views_.empty() && contents) { |
- GURL url = GURL(toolbar_model_->GetText()); |
+ GURL url = browser()->GetSelectedWebContents()->GetURL(); |
for (size_t i = 0; i < page_action_views_.size(); i++) { |
page_action_views_[i]->UpdateVisibility( |
@@ -1433,6 +1435,9 @@ |
page_action_(page_action), |
last_icon_pixbuf_(NULL), |
tracker_(this), |
+ current_tab_id_(-1), |
+ window_(NULL), |
+ accel_group_(NULL), |
preview_enabled_(false) { |
event_box_.Own(gtk_event_box_new()); |
gtk_widget_set_size_request(event_box_.get(), |
@@ -1445,6 +1450,8 @@ |
G_CALLBACK(&OnButtonPressedThunk), this); |
g_signal_connect_after(event_box_.get(), "expose-event", |
G_CALLBACK(OnExposeEventThunk), this); |
+ g_signal_connect(event_box_.get(), "realize", |
+ G_CALLBACK(OnRealizeThunk), this); |
image_.Own(gtk_image_new()); |
gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
@@ -1474,6 +1481,8 @@ |
} |
LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { |
+ DisconnectPageActionAccelerator(); |
+ |
image_.Destroy(); |
event_box_.Destroy(); |
for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); |
@@ -1590,6 +1599,14 @@ |
OnButtonPressed(widget(), &event); |
} |
+void LocationBarViewGtk::PageActionViewGtk::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ DCHECK(type == chrome::NOTIFICATION_WINDOW_CLOSED); |
+ DisconnectPageActionAccelerator(); |
+} |
+ |
void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
ExtensionAction* action) { |
ShowPopup(true); |
@@ -1607,6 +1624,60 @@ |
return true; |
} |
+void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() { |
+ const Extension* extension = owner_->browser()->profile()-> |
+ GetExtensionService()->GetExtensionById(page_action_->extension_id(), |
Matt Perry
2012/03/15 19:31:24
Use extensions()->GetByID() instead. We're trying
|
+ false); |
+ window_ = owner_->browser()->window()->GetNativeHandle(); |
+ |
+ // Iterate through all the keybindings and see if one is assigned to the |
+ // pageAction. |
+ const std::vector<Extension::ExtensionKeybinding>& commands = |
+ extension->keybindings(); |
+ for (size_t i = 0; i < commands.size(); ++i) { |
+ if (commands[i].command_name() != |
+ extension_manifest_values::kPageActionKeybindingEvent) |
+ continue; |
+ |
+ // Found the browser action shortcut command, register it. |
+ keybinding_.reset(new ui::AcceleratorGtk( |
+ commands[i].accelerator().key_code(), |
+ commands[i].accelerator().IsShiftDown(), |
+ commands[i].accelerator().IsCtrlDown(), |
+ commands[i].accelerator().IsAltDown())); |
+ |
+ accel_group_ = gtk_accel_group_new(); |
+ gtk_window_add_accel_group(window_, accel_group_); |
+ |
+ gtk_accel_group_connect( |
+ accel_group_, |
+ keybinding_.get()->GetGdkKeyCode(), |
+ keybinding_.get()->gdk_modifier_type(), |
Matt Perry
2012/03/15 19:31:24
nit: can skip the .get()
|
+ GtkAccelFlags(0), |
+ g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); |
+ |
+ // Since we've added an accelerator, we'll need to unregister it before |
+ // the window is closed, so we listen for the window being closed. |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_WINDOW_CLOSED, |
+ content::Source<GtkWindow>(window_)); |
+ break; |
+ } |
+} |
+ |
+void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { |
+ if (accel_group_) { |
+ gtk_accel_group_disconnect_key( |
+ accel_group_, |
+ keybinding_.get()->GetGdkKeyCode(), |
+ static_cast<GdkModifierType>(keybinding_.get()->modifiers())); |
+ gtk_window_remove_accel_group(window_, accel_group_); |
+ g_object_unref(accel_group_); |
+ accel_group_ = NULL; |
+ keybinding_.reset(NULL); |
+ } |
+} |
+ |
gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( |
GtkWidget* sender, |
GdkEventButton* event) { |
@@ -1656,3 +1727,23 @@ |
page_action_->PaintBadge(&canvas, gfx::Rect(allocation), tab_id); |
return FALSE; |
} |
+ |
+void LocationBarViewGtk::PageActionViewGtk::OnRealize(GtkWidget* widget) { |
+ ConnectPageActionAccelerator(); |
+} |
+ |
+// static |
+gboolean LocationBarViewGtk::PageActionViewGtk::OnGtkAccelerator( |
+ GtkAccelGroup* accel_group, |
+ GObject* acceleratable, |
+ guint keyval, |
+ GdkModifierType modifier, |
+ void* user_data) { |
+ PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); |
+ if (!gtk_widget_get_visible(view->widget())) |
+ return FALSE; |
+ |
+ GdkEventButton event = {}; |
+ event.button = 1; |
+ return view->OnButtonPressed(view->widget(), &event); |
+} |