Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / ash / caps_lock_delegate_chromeos.cc
blobacddcb52ce3913cbcd8527856771db477814a8ac
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.
5 #include "chrome/browser/ui/ash/caps_lock_delegate_chromeos.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/sys_info.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chromeos/ime/xkeyboard.h"
12 #include "content/public/browser/browser_thread.h"
14 CapsLockDelegate::CapsLockDelegate(chromeos::input_method::XKeyboard* xkeyboard)
15 : xkeyboard_(xkeyboard),
16 is_running_on_chromeos_(base::SysInfo::IsRunningOnChromeOS()),
17 caps_lock_is_on_(xkeyboard_->CapsLockIsEnabled()) {
18 chromeos::SystemKeyEventListener* system_event_listener =
19 chromeos::SystemKeyEventListener::GetInstance();
20 // SystemKeyEventListener should be instantiated when we're running production
21 // code on Chrome OS.
22 DCHECK(!is_running_on_chromeos_ || system_event_listener ||
23 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType));
24 if (system_event_listener)
25 system_event_listener->AddCapsLockObserver(this);
28 CapsLockDelegate::~CapsLockDelegate() {
29 chromeos::SystemKeyEventListener* system_event_listener =
30 chromeos::SystemKeyEventListener::GetInstance();
31 if (system_event_listener)
32 system_event_listener->RemoveCapsLockObserver(this);
35 bool CapsLockDelegate::IsCapsLockEnabled() const {
36 return caps_lock_is_on_;
39 void CapsLockDelegate::SetCapsLockEnabled(bool enabled) {
40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
41 if (is_running_on_chromeos_) {
42 xkeyboard_->SetCapsLockEnabled(enabled);
43 return;
47 void CapsLockDelegate::ToggleCapsLock() {
48 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
49 if (is_running_on_chromeos_) {
50 xkeyboard_->SetCapsLockEnabled(!caps_lock_is_on_);
51 return;
55 void CapsLockDelegate::OnCapsLockChange(bool enabled) {
56 caps_lock_is_on_ = enabled;