Chromium Code Reviews| Index: chrome/browser/extensions/global_shortcut_listener_chromeos.cc |
| diff --git a/chrome/browser/extensions/global_shortcut_listener_chromeos.cc b/chrome/browser/extensions/global_shortcut_listener_chromeos.cc |
| index 14f40c7e96052350e72f4630bc7ca65f6a1f9507..af326f26f9760046a2334d6c41573e60adb067b7 100644 |
| --- a/chrome/browser/extensions/global_shortcut_listener_chromeos.cc |
| +++ b/chrome/browser/extensions/global_shortcut_listener_chromeos.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/extensions/global_shortcut_listener_chromeos.h" |
| +#include "ash/accelerators/accelerator_controller.h" |
| +#include "ash/shell.h" |
| #include "content/public/browser/browser_thread.h" |
| using content::BrowserThread; |
| @@ -21,9 +23,6 @@ GlobalShortcutListener* GlobalShortcutListener::GetInstance() { |
| GlobalShortcutListenerChromeOS::GlobalShortcutListenerChromeOS() |
| : is_listening_(false) { |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - |
| - // TODO(implementor): Remove this. |
| - LOG(ERROR) << "GlobalShortcutListenerChromeOS object created"; |
| } |
| GlobalShortcutListenerChromeOS::~GlobalShortcutListenerChromeOS() { |
| @@ -33,32 +32,49 @@ GlobalShortcutListenerChromeOS::~GlobalShortcutListenerChromeOS() { |
| void GlobalShortcutListenerChromeOS::StartListening() { |
| DCHECK(!is_listening_); // Don't start twice. |
| - NOTIMPLEMENTED(); |
| is_listening_ = true; |
| } |
| void GlobalShortcutListenerChromeOS::StopListening() { |
| DCHECK(is_listening_); // No point if we are not already listening. |
| - NOTIMPLEMENTED(); |
| is_listening_ = false; |
| } |
| bool GlobalShortcutListenerChromeOS::RegisterAcceleratorImpl( |
| const ui::Accelerator& accelerator) { |
| - NOTIMPLEMENTED(); |
| - // To implement: |
| - // 1) Convert modifiers to platform specific modifiers. |
| - // 2) Register for the hotkey. |
| - // 3) If not successful, return false. |
| - // 4) Else, return true. |
| + ash::AcceleratorController* controller = |
| + ash::Shell::GetInstance()->accelerator_controller(); |
| + if (controller->IsReservedAccelerator(accelerator)) |
| + return false; |
| - return false; |
| + // TODO(dtseng): Support search key mapping. |
| + controller->Register(accelerator, this); |
| + return controller->IsRegistered(accelerator); |
| } |
| void GlobalShortcutListenerChromeOS::UnregisterAcceleratorImpl( |
| const ui::Accelerator& accelerator) { |
| - NOTIMPLEMENTED(); |
| - // To implement: Unregister for the hotkey. |
| + ash::Shell::GetInstance()->accelerator_controller()->Unregister(accelerator, |
| + this); |
| +} |
| + |
| +bool GlobalShortcutListenerChromeOS::AcceleratorPressed( |
| + const ui::Accelerator& accelerator) { |
| + DCHECK(is_listening_); |
| + ash::AcceleratorController* controller = |
| + ash::Shell::GetInstance()->accelerator_controller(); |
| + ash::AcceleratorController::AcceleratorProcessRestriction restriction = |
| + controller->GetAcceleratorProcessRestriction(-1, accelerator); |
| + if (restriction == ash::AcceleratorController::RESTRICTION_NONE) { |
| + NotifyKeyPressed(accelerator); |
| + return true; |
| + } |
| + return restriction == ash::AcceleratorController:: |
| + RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
|
Finnur
2014/06/26 10:37:35
What happens if code A registers accelerator foo,
David Tseng
2014/06/27 00:49:11
The latter, when target B:
- prevents propagation
Finnur
2014/06/27 11:10:57
Let me rephrase the question...
Are there scenari
David Tseng
2014/06/28 14:17:50
Are we talking about in theory or in practice?
htt
Finnur
2014/06/30 10:39:44
If it only happens in theory then there's not much
|
| +} |
| + |
| +bool GlobalShortcutListenerChromeOS::CanHandleAccelerators() const { |
| + return is_listening_; |
| } |
| } // namespace extensions |