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/views/extensions/extension_keybinding_registry_views .h" | 5 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | |
7 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
8 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 9 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
9 #include "chrome/browser/extensions/extension_service.h" | |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/accelerator_utils.h" | |
12 #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h" | |
13 #include "extensions/browser/extension_registry.h" | |
11 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
12 #include "ui/views/focus/focus_manager.h" | 15 #include "ui/views/focus/focus_manager.h" |
13 | 16 |
14 // static | 17 // static |
15 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended( | 18 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended( |
16 bool suspended) { | 19 bool suspended) { |
17 views::FocusManager::set_shortcut_handling_suspended(suspended); | 20 views::FocusManager::set_shortcut_handling_suspended(suspended); |
18 } | 21 } |
19 | 22 |
20 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( | 23 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( |
(...skipping 27 matching lines...) Expand all Loading... | |
48 extension->id(), | 51 extension->id(), |
49 extensions::CommandService::ACTIVE_ONLY, | 52 extensions::CommandService::ACTIVE_ONLY, |
50 extensions::CommandService::REGULAR, | 53 extensions::CommandService::REGULAR, |
51 &commands)) | 54 &commands)) |
52 return; | 55 return; |
53 extensions::CommandMap::const_iterator iter = commands.begin(); | 56 extensions::CommandMap::const_iterator iter = commands.begin(); |
54 for (; iter != commands.end(); ++iter) { | 57 for (; iter != commands.end(); ++iter) { |
55 if (!command_name.empty() && (iter->second.command_name() != command_name)) | 58 if (!command_name.empty() && (iter->second.command_name() != command_name)) |
56 continue; | 59 continue; |
57 if (!IsAcceleratorRegistered(iter->second.accelerator())) { | 60 if (!IsAcceleratorRegistered(iter->second.accelerator())) { |
61 ui::AcceleratorManager::HandlerPriority priority = | |
62 ui::AcceleratorManager::kHighPriority; | |
63 // Extensions overriding the bookmark shortcut need normal priority to | |
64 // preserve the built-in processing order of the key and not override | |
65 // WebContents key handling. | |
66 if (iter->second.accelerator() == | |
67 chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE) && | |
68 extensions::UIOverrides::RemovesBookmarkShortcut(extension)) { | |
69 priority = ui::AcceleratorManager::kNormalPriority; | |
70 } | |
Finnur
2014/07/02 11:56:16
I'd rather have a utility function on the Command
Mike Wittman
2014/07/02 21:56:19
We can do the utility function, but putting it in
Finnur
2014/07/03 11:09:59
Ah, I see. That's probably fine then.
| |
58 focus_manager_->RegisterAccelerator(iter->second.accelerator(), | 71 focus_manager_->RegisterAccelerator(iter->second.accelerator(), |
59 ui::AcceleratorManager::kHighPriority, | 72 priority, |
Finnur
2014/07/02 11:56:16
Then this becomes:
Command::GetPriority(iter->se
Mike Wittman
2014/07/02 21:56:19
Done.
| |
60 this); | 73 this); |
61 } | 74 } |
62 | 75 |
63 AddEventTarget(iter->second.accelerator(), | 76 AddEventTarget(iter->second.accelerator(), |
64 extension->id(), | 77 extension->id(), |
65 iter->second.command_name()); | 78 iter->second.command_name()); |
66 } | 79 } |
67 } | 80 } |
68 | 81 |
69 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( | 82 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( |
70 const ui::Accelerator& accelerator, | 83 const ui::Accelerator& accelerator, |
71 const std::string& command_name) { | 84 const std::string& command_name) { |
72 focus_manager_->UnregisterAccelerator(accelerator, this); | 85 focus_manager_->UnregisterAccelerator(accelerator, this); |
73 } | 86 } |
74 | 87 |
75 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( | 88 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( |
76 const ui::Accelerator& accelerator) { | 89 const ui::Accelerator& accelerator) { |
90 // As a special case, if the extension removes and reassigns the bookmark | |
91 // shortcut we don't respond here but instead allow it to be handled by the | |
92 // standard browser command processing. This preserves the same shortcut key | |
93 // handling of Chrome's built-in bookmarking function, which can be overridden | |
94 // by key handling on web pages. | |
95 std::string extension_id, command_name; | |
96 GetFirstTarget(accelerator, &extension_id, &command_name); | |
97 const extensions::Extension* extension = | |
98 extensions::ExtensionRegistry::Get(browser_context())-> | |
99 enabled_extensions().GetByID(extension_id); | |
100 if (accelerator == | |
101 chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE) && | |
102 extensions::UIOverrides::RemovesBookmarkShortcut(extension)) { | |
103 return false; | |
104 } | |
Finnur
2014/07/02 11:56:16
and this becomes:
if (Command::GetPriority(acceler
Mike Wittman
2014/07/02 21:56:19
Done.
| |
105 | |
77 return ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); | 106 return ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); |
78 } | 107 } |
79 | 108 |
80 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { | 109 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { |
81 return true; | 110 return true; |
82 } | 111 } |
OLD | NEW |