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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_keybinding_registry_views.cc

Issue 64273008: [Windows] Finish global and non-global media keys support on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address some comments. Created 7 years, 1 month 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
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/views/extensions/extension_keybinding_registry_views .h" 5 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
6 6
7 #include "chrome/browser/extensions/api/commands/command_service.h" 7 #include "chrome/browser/extensions/api/commands/command_service.h"
8 #include "chrome/browser/extensions/extension_keybinding_registry.h" 8 #include "chrome/browser/extensions/extension_keybinding_registry.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 11 matching lines...) Expand all
22 views::FocusManager* focus_manager, 22 views::FocusManager* focus_manager,
23 ExtensionFilter extension_filter, 23 ExtensionFilter extension_filter,
24 Delegate* delegate) 24 Delegate* delegate)
25 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), 25 : ExtensionKeybindingRegistry(profile, extension_filter, delegate),
26 profile_(profile), 26 profile_(profile),
27 focus_manager_(focus_manager) { 27 focus_manager_(focus_manager) {
28 Init(); 28 Init();
29 } 29 }
30 30
31 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() { 31 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() {
32 EventTargets::const_iterator iter; 32 for (EventTargets::const_iterator iter = event_targets_.begin();
33 for (iter = event_targets_.begin(); iter != event_targets_.end(); ++iter) 33 iter != event_targets_.end(); ++iter)
34 focus_manager_->UnregisterAccelerator(iter->first, this);
35
36 for (MediaKeysEventTargets::const_iterator iter =
37 media_keys_event_targets_.begin();
38 iter != media_keys_event_targets_.end(); ++iter)
34 focus_manager_->UnregisterAccelerator(iter->first, this); 39 focus_manager_->UnregisterAccelerator(iter->first, this);
35 } 40 }
36 41
37 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding( 42 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding(
38 const extensions::Extension* extension, 43 const extensions::Extension* extension,
39 const std::string& command_name) { 44 const std::string& command_name) {
40 // This object only handles named commands, not browser/page actions. 45 // This object only handles named commands, not browser/page actions.
41 if (ShouldIgnoreCommand(command_name)) 46 if (ShouldIgnoreCommand(command_name))
42 return; 47 return;
43 48
44 extensions::CommandService* command_service = 49 extensions::CommandService* command_service =
45 extensions::CommandService::Get(profile_); 50 extensions::CommandService::Get(profile_);
46 // Add all the active keybindings (except page actions and browser actions, 51 // Add all the active keybindings (except page actions and browser actions,
47 // which are handled elsewhere). 52 // which are handled elsewhere).
48 extensions::CommandMap commands; 53 extensions::CommandMap commands;
49 if (!command_service->GetNamedCommands( 54 if (!command_service->GetNamedCommands(
50 extension->id(), 55 extension->id(),
51 extensions::CommandService::ACTIVE_ONLY, 56 extensions::CommandService::ACTIVE_ONLY,
52 extensions::CommandService::REGULAR, 57 extensions::CommandService::REGULAR,
53 &commands)) 58 &commands))
54 return; 59 return;
55 extensions::CommandMap::const_iterator iter = commands.begin(); 60 extensions::CommandMap::const_iterator iter = commands.begin();
56 for (; iter != commands.end(); ++iter) { 61 for (; iter != commands.end(); ++iter) {
57 if (!command_name.empty() && (iter->second.command_name() != command_name)) 62 if (!command_name.empty() && (iter->second.command_name() != command_name))
58 continue; 63 continue;
59 64
60 event_targets_[iter->second.accelerator()] = 65 if (extensions::CommandService::IsMediaKey(iter->second.accelerator())) {
61 std::make_pair(extension->id(), iter->second.command_name()); 66 std::pair<std::string, std::string> target =
67 std::make_pair(extension->id(), iter->second.command_name());
68 media_keys_event_targets_[iter->second.accelerator()].push_back(target);
69 } else {
70 event_targets_[iter->second.accelerator()] =
71 std::make_pair(extension->id(), iter->second.command_name());
72 }
62 focus_manager_->RegisterAccelerator( 73 focus_manager_->RegisterAccelerator(
63 iter->second.accelerator(), 74 iter->second.accelerator(),
64 ui::AcceleratorManager::kHighPriority, this); 75 ui::AcceleratorManager::kHighPriority, this);
65 } 76 }
66 } 77 }
67 78
68 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( 79 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl(
69 const ui::Accelerator& accelerator, 80 const ui::Accelerator& accelerator,
70 const std::string& command_name) { 81 const std::string& command_name) {
71 focus_manager_->UnregisterAccelerator(accelerator, this); 82 focus_manager_->UnregisterAccelerator(accelerator, this);
72 } 83 }
73 84
74 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( 85 bool ExtensionKeybindingRegistryViews::AcceleratorPressed(
75 const ui::Accelerator& accelerator) { 86 const ui::Accelerator& accelerator) {
76 EventTargets::iterator it = event_targets_.find(accelerator); 87 return ExtensionKeybindingRegistry::NotifyEventTargetsByAccelerator(
77 if (it == event_targets_.end()) { 88 accelerator);
78 NOTREACHED(); // Shouldn't get this event for something not registered.
79 return false;
80 }
81
82 CommandExecuted(it->second.first, it->second.second);
83
84 return true;
85 } 89 }
86 90
87 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { 91 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const {
88 return true; 92 return true;
89 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698