| OLD | NEW |
| 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 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 return true; | 1627 return true; |
| 1628 } | 1628 } |
| 1629 | 1629 |
| 1630 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() { | 1630 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() { |
| 1631 const ExtensionSet* extensions = owner_->browser()->profile()-> | 1631 const ExtensionSet* extensions = owner_->browser()->profile()-> |
| 1632 GetExtensionService()->extensions(); | 1632 GetExtensionService()->extensions(); |
| 1633 const Extension* extension = | 1633 const Extension* extension = |
| 1634 extensions->GetByID(page_action_->extension_id()); | 1634 extensions->GetByID(page_action_->extension_id()); |
| 1635 window_ = owner_->browser()->window()->GetNativeHandle(); | 1635 window_ = owner_->browser()->window()->GetNativeHandle(); |
| 1636 | 1636 |
| 1637 // Iterate through all the keybindings and see if one is assigned to the | 1637 const Extension::ExtensionKeybinding* command = |
| 1638 // pageAction. | 1638 extension->page_action_command(); |
| 1639 const std::vector<Extension::ExtensionKeybinding>& commands = | 1639 if (command) { |
| 1640 extension->keybindings(); | |
| 1641 for (size_t i = 0; i < commands.size(); ++i) { | |
| 1642 if (commands[i].command_name() != | |
| 1643 extension_manifest_values::kPageActionKeybindingEvent) | |
| 1644 continue; | |
| 1645 | |
| 1646 // Found the browser action shortcut command, register it. | 1640 // Found the browser action shortcut command, register it. |
| 1647 keybinding_.reset(new ui::AcceleratorGtk( | 1641 keybinding_.reset(new ui::AcceleratorGtk( |
| 1648 commands[i].accelerator().key_code(), | 1642 command->accelerator().key_code(), |
| 1649 commands[i].accelerator().IsShiftDown(), | 1643 command->accelerator().IsShiftDown(), |
| 1650 commands[i].accelerator().IsCtrlDown(), | 1644 command->accelerator().IsCtrlDown(), |
| 1651 commands[i].accelerator().IsAltDown())); | 1645 command->accelerator().IsAltDown())); |
| 1652 | 1646 |
| 1653 accel_group_ = gtk_accel_group_new(); | 1647 accel_group_ = gtk_accel_group_new(); |
| 1654 gtk_window_add_accel_group(window_, accel_group_); | 1648 gtk_window_add_accel_group(window_, accel_group_); |
| 1655 | 1649 |
| 1656 gtk_accel_group_connect( | 1650 gtk_accel_group_connect( |
| 1657 accel_group_, | 1651 accel_group_, |
| 1658 keybinding_->GetGdkKeyCode(), | 1652 keybinding_->GetGdkKeyCode(), |
| 1659 keybinding_->gdk_modifier_type(), | 1653 keybinding_->gdk_modifier_type(), |
| 1660 GtkAccelFlags(0), | 1654 GtkAccelFlags(0), |
| 1661 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); | 1655 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); |
| 1662 | 1656 |
| 1663 // Since we've added an accelerator, we'll need to unregister it before | 1657 // Since we've added an accelerator, we'll need to unregister it before |
| 1664 // the window is closed, so we listen for the window being closed. | 1658 // the window is closed, so we listen for the window being closed. |
| 1665 registrar_.Add(this, | 1659 registrar_.Add(this, |
| 1666 chrome::NOTIFICATION_WINDOW_CLOSED, | 1660 chrome::NOTIFICATION_WINDOW_CLOSED, |
| 1667 content::Source<GtkWindow>(window_)); | 1661 content::Source<GtkWindow>(window_)); |
| 1668 break; | |
| 1669 } | 1662 } |
| 1670 } | 1663 } |
| 1671 | 1664 |
| 1672 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { | 1665 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { |
| 1673 if (accel_group_) { | 1666 if (accel_group_) { |
| 1674 gtk_accel_group_disconnect_key( | 1667 gtk_accel_group_disconnect_key( |
| 1675 accel_group_, | 1668 accel_group_, |
| 1676 keybinding_.get()->GetGdkKeyCode(), | 1669 keybinding_.get()->GetGdkKeyCode(), |
| 1677 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); | 1670 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); |
| 1678 gtk_window_remove_accel_group(window_, accel_group_); | 1671 gtk_window_remove_accel_group(window_, accel_group_); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 GdkModifierType modifier, | 1737 GdkModifierType modifier, |
| 1745 void* user_data) { | 1738 void* user_data) { |
| 1746 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); | 1739 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); |
| 1747 if (!gtk_widget_get_visible(view->widget())) | 1740 if (!gtk_widget_get_visible(view->widget())) |
| 1748 return FALSE; | 1741 return FALSE; |
| 1749 | 1742 |
| 1750 GdkEventButton event = {}; | 1743 GdkEventButton event = {}; |
| 1751 event.button = 1; | 1744 event.button = 1; |
| 1752 return view->OnButtonPressed(view->widget(), &event); | 1745 return view->OnButtonPressed(view->widget(), &event); |
| 1753 } | 1746 } |
| OLD | NEW |