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

Unified Diff: chrome/browser/extensions/global_shortcut_listener_chromeos.cc

Issue 350943003: Support global keyboard commands on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test updates Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
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..2dd87cd403216940fc09a4981c114735bac3fe3b 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,52 @@ 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->IsRegistered(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.
+ // This code path gets called during object destruction.
+ if (!ash::Shell::HasInstance())
+ return;
+ 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::AcceleratorProcessingRestriction restriction =
+ controller->GetCurrentAcceleratorRestriction();
+ if (restriction == ash::AcceleratorController::RESTRICTION_NONE) {
+ NotifyKeyPressed(accelerator);
+ return true;
+ }
+ return restriction == ash::AcceleratorController::
+ RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
+}
+
+bool GlobalShortcutListenerChromeOS::CanHandleAccelerators() const {
+ return is_listening_;
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698