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

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

Issue 9812008: Polish the keybinding implementation a bit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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/location_bar_view_gtk.h" 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 return true; 1702 return true;
1703 } 1703 }
1704 1704
1705 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() { 1705 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() {
1706 const ExtensionSet* extensions = owner_->browser()->profile()-> 1706 const ExtensionSet* extensions = owner_->browser()->profile()->
1707 GetExtensionService()->extensions(); 1707 GetExtensionService()->extensions();
1708 const Extension* extension = 1708 const Extension* extension =
1709 extensions->GetByID(page_action_->extension_id()); 1709 extensions->GetByID(page_action_->extension_id());
1710 window_ = owner_->browser()->window()->GetNativeHandle(); 1710 window_ = owner_->browser()->window()->GetNativeHandle();
1711 1711
1712 // Iterate through all the keybindings and see if one is assigned to the 1712 const Extension::ExtensionKeybinding* command =
1713 // pageAction. 1713 extension->page_action_command();
1714 const std::vector<Extension::ExtensionKeybinding>& commands = 1714 if (command) {
1715 extension->keybindings();
1716 for (size_t i = 0; i < commands.size(); ++i) {
1717 if (commands[i].command_name() !=
1718 extension_manifest_values::kPageActionKeybindingEvent)
1719 continue;
1720
1721 // Found the browser action shortcut command, register it. 1715 // Found the browser action shortcut command, register it.
1722 keybinding_.reset(new ui::AcceleratorGtk( 1716 keybinding_.reset(new ui::AcceleratorGtk(
1723 commands[i].accelerator().key_code(), 1717 command->accelerator().key_code(),
1724 commands[i].accelerator().IsShiftDown(), 1718 command->accelerator().IsShiftDown(),
1725 commands[i].accelerator().IsCtrlDown(), 1719 command->accelerator().IsCtrlDown(),
1726 commands[i].accelerator().IsAltDown())); 1720 command->accelerator().IsAltDown()));
1727 1721
1728 accel_group_ = gtk_accel_group_new(); 1722 accel_group_ = gtk_accel_group_new();
1729 gtk_window_add_accel_group(window_, accel_group_); 1723 gtk_window_add_accel_group(window_, accel_group_);
1730 1724
1731 gtk_accel_group_connect( 1725 gtk_accel_group_connect(
1732 accel_group_, 1726 accel_group_,
1733 keybinding_->GetGdkKeyCode(), 1727 keybinding_->GetGdkKeyCode(),
1734 keybinding_->gdk_modifier_type(), 1728 keybinding_->gdk_modifier_type(),
1735 GtkAccelFlags(0), 1729 GtkAccelFlags(0),
1736 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); 1730 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL));
1737 1731
1738 // Since we've added an accelerator, we'll need to unregister it before 1732 // Since we've added an accelerator, we'll need to unregister it before
1739 // the window is closed, so we listen for the window being closed. 1733 // the window is closed, so we listen for the window being closed.
1740 registrar_.Add(this, 1734 registrar_.Add(this,
1741 chrome::NOTIFICATION_WINDOW_CLOSED, 1735 chrome::NOTIFICATION_WINDOW_CLOSED,
1742 content::Source<GtkWindow>(window_)); 1736 content::Source<GtkWindow>(window_));
1743 break;
1744 } 1737 }
1745 } 1738 }
1746 1739
1747 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { 1740 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() {
1748 if (accel_group_) { 1741 if (accel_group_) {
1749 gtk_accel_group_disconnect_key( 1742 gtk_accel_group_disconnect_key(
1750 accel_group_, 1743 accel_group_,
1751 keybinding_.get()->GetGdkKeyCode(), 1744 keybinding_.get()->GetGdkKeyCode(),
1752 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); 1745 static_cast<GdkModifierType>(keybinding_.get()->modifiers()));
1753 gtk_window_remove_accel_group(window_, accel_group_); 1746 gtk_window_remove_accel_group(window_, accel_group_);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 GdkModifierType modifier, 1812 GdkModifierType modifier,
1820 void* user_data) { 1813 void* user_data) {
1821 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); 1814 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data);
1822 if (!gtk_widget_get_visible(view->widget())) 1815 if (!gtk_widget_get_visible(view->widget()))
1823 return FALSE; 1816 return FALSE;
1824 1817
1825 GdkEventButton event = {}; 1818 GdkEventButton event = {};
1826 event.button = 1; 1819 event.button = 1;
1827 return view->OnButtonPressed(view->widget(), &event); 1820 return view->OnButtonPressed(view->widget(), &event);
1828 } 1821 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698