blob: acddcb52ce3913cbcd8527856771db477814a8ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/caps_lock_delegate_chromeos.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/sys_info.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/ime/xkeyboard.h"
#include "content/public/browser/browser_thread.h"
CapsLockDelegate::CapsLockDelegate(chromeos::input_method::XKeyboard* xkeyboard)
: xkeyboard_(xkeyboard),
is_running_on_chromeos_(base::SysInfo::IsRunningOnChromeOS()),
caps_lock_is_on_(xkeyboard_->CapsLockIsEnabled()) {
chromeos::SystemKeyEventListener* system_event_listener =
chromeos::SystemKeyEventListener::GetInstance();
// SystemKeyEventListener should be instantiated when we're running production
// code on Chrome OS.
DCHECK(!is_running_on_chromeos_ || system_event_listener ||
CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType));
if (system_event_listener)
system_event_listener->AddCapsLockObserver(this);
}
CapsLockDelegate::~CapsLockDelegate() {
chromeos::SystemKeyEventListener* system_event_listener =
chromeos::SystemKeyEventListener::GetInstance();
if (system_event_listener)
system_event_listener->RemoveCapsLockObserver(this);
}
bool CapsLockDelegate::IsCapsLockEnabled() const {
return caps_lock_is_on_;
}
void CapsLockDelegate::SetCapsLockEnabled(bool enabled) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (is_running_on_chromeos_) {
xkeyboard_->SetCapsLockEnabled(enabled);
return;
}
}
void CapsLockDelegate::ToggleCapsLock() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (is_running_on_chromeos_) {
xkeyboard_->SetCapsLockEnabled(!caps_lock_is_on_);
return;
}
}
void CapsLockDelegate::OnCapsLockChange(bool enabled) {
caps_lock_is_on_ = enabled;
}
|