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/views/aura/caps_lock_handler.h" |
| 6 |
| 7 #include "content/public/browser/browser_thread.h" |
| 8 |
| 9 // TODO(yusukes): Support Ash on Windows. |
| 10 #if defined(OS_CHROMEOS) |
| 11 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
| 12 #include "chrome/browser/chromeos/system/runtime_environment.h" |
| 13 #endif |
| 14 |
| 15 #if defined(OS_CHROMEOS) |
| 16 CapsLockHandler::CapsLockHandler(chromeos::input_method::XKeyboard* xkeyboard) |
| 17 : xkeyboard_(xkeyboard), |
| 18 is_running_on_chromeos_( |
| 19 chromeos::system::runtime_environment::IsRunningOnChromeOS()), |
| 20 caps_lock_is_on_(xkeyboard_->CapsLockIsEnabled()) { |
| 21 chromeos::SystemKeyEventListener* system_event_listener = |
| 22 chromeos::SystemKeyEventListener::GetInstance(); |
| 23 // SystemKeyEventListener should be instantiated when we're running on Chrome |
| 24 // OS. |
| 25 DCHECK(!is_running_on_chromeos_ || system_event_listener); |
| 26 if (system_event_listener) |
| 27 system_event_listener->AddCapsLockObserver(this); |
| 28 } |
| 29 #endif |
| 30 |
| 31 CapsLockHandler::~CapsLockHandler() { |
| 32 #if defined(OS_CHROMEOS) |
| 33 chromeos::SystemKeyEventListener* system_event_listener = |
| 34 chromeos::SystemKeyEventListener::GetInstance(); |
| 35 if (system_event_listener) |
| 36 system_event_listener->RemoveCapsLockObserver(this); |
| 37 #endif |
| 38 } |
| 39 |
| 40 bool CapsLockHandler::HandleToggleCapsLock() { |
| 41 #if defined(OS_CHROMEOS) |
| 42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 43 if (is_running_on_chromeos_) { |
| 44 // TODO(yusukes): Do not change Caps Lock status and just return false if |
| 45 // spoken feedback is enabled (crosbug.com/110127). |
| 46 xkeyboard_->SetCapsLockEnabled(!caps_lock_is_on_); |
| 47 return true; // consume the shortcut key. |
| 48 } |
| 49 #else |
| 50 NOTIMPLEMENTED(); |
| 51 #endif |
| 52 return false; |
| 53 } |
| 54 |
| 55 #if defined(OS_CHROMEOS) |
| 56 void CapsLockHandler::OnCapsLockChange(bool enabled) { |
| 57 caps_lock_is_on_ = enabled; |
| 58 } |
| 59 #endif |
OLD | NEW |