OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/ash/caps_lock_handler.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 |
| 10 // TODO(yusukes): Support Ash on Windows. |
| 11 #if defined(OS_CHROMEOS) |
| 12 #include "base/chromeos/chromeos_version.h" |
| 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/common/pref_names.h" |
| 17 #endif |
| 18 |
| 19 #if defined(OS_CHROMEOS) |
| 20 CapsLockHandler::CapsLockHandler(chromeos::input_method::XKeyboard* xkeyboard) |
| 21 : xkeyboard_(xkeyboard), |
| 22 is_running_on_chromeos_(base::chromeos::IsRunningOnChromeOS()), |
| 23 caps_lock_is_on_(xkeyboard_->CapsLockIsEnabled()) { |
| 24 chromeos::SystemKeyEventListener* system_event_listener = |
| 25 chromeos::SystemKeyEventListener::GetInstance(); |
| 26 // SystemKeyEventListener should be instantiated when we're running on Chrome |
| 27 // OS. |
| 28 DCHECK(!is_running_on_chromeos_ || system_event_listener); |
| 29 if (system_event_listener) |
| 30 system_event_listener->AddCapsLockObserver(this); |
| 31 } |
| 32 #endif |
| 33 |
| 34 CapsLockHandler::~CapsLockHandler() { |
| 35 #if defined(OS_CHROMEOS) |
| 36 chromeos::SystemKeyEventListener* system_event_listener = |
| 37 chromeos::SystemKeyEventListener::GetInstance(); |
| 38 if (system_event_listener) |
| 39 system_event_listener->RemoveCapsLockObserver(this); |
| 40 #endif |
| 41 } |
| 42 |
| 43 bool CapsLockHandler::HandleToggleCapsLock() { |
| 44 #if defined(OS_CHROMEOS) |
| 45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 46 if (is_running_on_chromeos_ && |
| 47 // When spoken feedback is enabled, the Search key is used as an |
| 48 // accessibility modifier key. |
| 49 !g_browser_process->local_state()->GetBoolean( |
| 50 prefs::kSpokenFeedbackEnabled)) { |
| 51 xkeyboard_->SetCapsLockEnabled(!caps_lock_is_on_); |
| 52 return true; // consume the shortcut key. |
| 53 } |
| 54 #else |
| 55 NOTIMPLEMENTED(); |
| 56 #endif |
| 57 return false; |
| 58 } |
| 59 |
| 60 #if defined(OS_CHROMEOS) |
| 61 void CapsLockHandler::OnCapsLockChange(bool enabled) { |
| 62 caps_lock_is_on_ = enabled; |
| 63 } |
| 64 #endif |
OLD | NEW |