| Index: chromeos/ime/keyboard_controller_x11.cc
|
| diff --git a/chromeos/ime/xkeyboard.cc b/chromeos/ime/keyboard_controller_x11.cc
|
| similarity index 84%
|
| rename from chromeos/ime/xkeyboard.cc
|
| rename to chromeos/ime/keyboard_controller_x11.cc
|
| index b2f55f14443e77a403ce47d27889b11c3a7fc658..e930cde1f0353f92d872202732c931e6df21900d 100644
|
| --- a/chromeos/ime/xkeyboard.cc
|
| +++ b/chromeos/ime/keyboard_controller_x11.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chromeos/ime/xkeyboard.h"
|
| +#include "chromeos/ime/keyboard_controller.h"
|
|
|
| #include <cstdlib>
|
| #include <cstring>
|
| @@ -112,12 +112,12 @@ bool CheckLayoutName(const std::string& layout_name) {
|
| return true;
|
| }
|
|
|
| -class XKeyboardImpl : public XKeyboard {
|
| +class KeyboardControllerX11 : public KeyboardController {
|
| public:
|
| - XKeyboardImpl();
|
| - virtual ~XKeyboardImpl() {}
|
| + KeyboardControllerX11();
|
| + virtual ~KeyboardControllerX11() {}
|
|
|
| - // Overridden from XKeyboard:
|
| + // Overridden from KeyboardController:
|
| virtual bool SetCurrentKeyboardLayoutByName(
|
| const std::string& layout_name) OVERRIDE;
|
| virtual bool ReapplyCurrentKeyboardLayout() OVERRIDE;
|
| @@ -167,12 +167,12 @@ class XKeyboardImpl : public XKeyboard {
|
|
|
| base::ThreadChecker thread_checker_;
|
|
|
| - base::WeakPtrFactory<XKeyboardImpl> weak_factory_;
|
| + base::WeakPtrFactory<KeyboardControllerX11> weak_factory_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(XKeyboardImpl);
|
| + DISALLOW_COPY_AND_ASSIGN(KeyboardControllerX11);
|
| };
|
|
|
| -XKeyboardImpl::XKeyboardImpl()
|
| +KeyboardControllerX11::KeyboardControllerX11()
|
| : is_running_on_chrome_os_(base::SysInfo::IsRunningOnChromeOS()),
|
| weak_factory_(this) {
|
| // X must be already initialized.
|
| @@ -193,7 +193,7 @@ XKeyboardImpl::XKeyboardImpl()
|
| current_caps_lock_status_ = CapsLockIsEnabled();
|
| }
|
|
|
| -unsigned int XKeyboardImpl::GetNumLockMask() {
|
| +unsigned int KeyboardControllerX11::GetNumLockMask() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| static const unsigned int kBadMask = 0;
|
|
|
| @@ -227,7 +227,7 @@ unsigned int XKeyboardImpl::GetNumLockMask() {
|
| return real_mask;
|
| }
|
|
|
| -void XKeyboardImpl::SetLockedModifiers(bool caps_lock_enabled) {
|
| +void KeyboardControllerX11::SetLockedModifiers(bool caps_lock_enabled) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| // Always turn off num lock.
|
| @@ -241,8 +241,8 @@ void XKeyboardImpl::SetLockedModifiers(bool caps_lock_enabled) {
|
| XkbLockModifiers(GetXDisplay(), XkbUseCoreKbd, affect_mask, value_mask);
|
| }
|
|
|
| -bool XKeyboardImpl::SetLayoutInternal(const std::string& layout_name,
|
| - bool force) {
|
| +bool KeyboardControllerX11::SetLayoutInternal(const std::string& layout_name,
|
| + bool force) {
|
| if (!is_running_on_chrome_os_) {
|
| // We should not try to change a layout on Linux or inside ui_tests. Just
|
| // return true.
|
| @@ -275,7 +275,7 @@ bool XKeyboardImpl::SetLayoutInternal(const std::string& layout_name,
|
| // Executes 'setxkbmap -layout ...' command asynchronously using a layout name
|
| // in the |execute_queue_|. Do nothing if the queue is empty.
|
| // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105)
|
| -void XKeyboardImpl::MaybeExecuteSetLayoutCommand() {
|
| +void KeyboardControllerX11::MaybeExecuteSetLayoutCommand() {
|
| if (execute_queue_.empty())
|
| return;
|
| const std::string layout_to_set = execute_queue_.front();
|
| @@ -296,12 +296,13 @@ void XKeyboardImpl::MaybeExecuteSetLayoutCommand() {
|
|
|
| PollUntilChildFinish(handle);
|
|
|
| - DVLOG(1) << "ExecuteSetLayoutCommand: "
|
| - << layout_to_set << ": pid=" << base::GetProcId(handle);
|
| + DVLOG(1) << "ExecuteSetLayoutCommand: " << layout_to_set
|
| + << ": pid=" << base::GetProcId(handle);
|
| }
|
|
|
| // Delay and loop until child process finishes and call the callback.
|
| -void XKeyboardImpl::PollUntilChildFinish(const base::ProcessHandle handle) {
|
| +void KeyboardControllerX11::PollUntilChildFinish(
|
| + const base::ProcessHandle handle) {
|
| int exit_code;
|
| DVLOG(1) << "PollUntilChildFinish: poll for pid=" << base::GetProcId(handle);
|
| switch (base::GetTerminationStatus(handle, &exit_code)) {
|
| @@ -309,8 +310,9 @@ void XKeyboardImpl::PollUntilChildFinish(const base::ProcessHandle handle) {
|
| DVLOG(1) << "PollUntilChildFinish: Try waiting again";
|
| base::MessageLoop::current()->PostDelayedTask(
|
| FROM_HERE,
|
| - base::Bind(&XKeyboardImpl::PollUntilChildFinish,
|
| - weak_factory_.GetWeakPtr(), handle),
|
| + base::Bind(&KeyboardControllerX11::PollUntilChildFinish,
|
| + weak_factory_.GetWeakPtr(),
|
| + handle),
|
| base::TimeDelta::FromMilliseconds(kSetLayoutCommandCheckDelayMs));
|
| return;
|
|
|
| @@ -331,14 +333,14 @@ void XKeyboardImpl::PollUntilChildFinish(const base::ProcessHandle handle) {
|
| }
|
| }
|
|
|
| -bool XKeyboardImpl::CapsLockIsEnabled() {
|
| +bool KeyboardControllerX11::CapsLockIsEnabled() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| XkbStateRec status;
|
| XkbGetState(GetXDisplay(), XkbUseCoreKbd, &status);
|
| return (status.locked_mods & LockMask);
|
| }
|
|
|
| -bool XKeyboardImpl::IsISOLevel5ShiftAvailable() const {
|
| +bool KeyboardControllerX11::IsISOLevel5ShiftAvailable() const {
|
| for (size_t i = 0; i < arraysize(kISOLevel5ShiftLayoutIds); ++i) {
|
| if (current_layout_name_ == kISOLevel5ShiftLayoutIds[i])
|
| return true;
|
| @@ -346,7 +348,7 @@ bool XKeyboardImpl::IsISOLevel5ShiftAvailable() const {
|
| return false;
|
| }
|
|
|
| -bool XKeyboardImpl::IsAltGrAvailable() const {
|
| +bool KeyboardControllerX11::IsAltGrAvailable() const {
|
| for (size_t i = 0; i < arraysize(kAltGrLayoutIds); ++i) {
|
| if (current_layout_name_ == kAltGrLayoutIds[i])
|
| return true;
|
| @@ -354,8 +356,7 @@ bool XKeyboardImpl::IsAltGrAvailable() const {
|
| return false;
|
| }
|
|
|
| -
|
| -bool XKeyboardImpl::SetAutoRepeatEnabled(bool enabled) {
|
| +bool KeyboardControllerX11::SetAutoRepeatEnabled(bool enabled) {
|
| if (enabled)
|
| XAutoRepeatOn(GetXDisplay());
|
| else
|
| @@ -364,7 +365,7 @@ bool XKeyboardImpl::SetAutoRepeatEnabled(bool enabled) {
|
| return true;
|
| }
|
|
|
| -bool XKeyboardImpl::SetAutoRepeatRate(const AutoRepeatRate& rate) {
|
| +bool KeyboardControllerX11::SetAutoRepeatRate(const AutoRepeatRate& rate) {
|
| DVLOG(1) << "Set auto-repeat rate to: "
|
| << rate.initial_delay_in_ms << " ms delay, "
|
| << rate.repeat_interval_in_ms << " ms interval";
|
| @@ -377,11 +378,11 @@ bool XKeyboardImpl::SetAutoRepeatRate(const AutoRepeatRate& rate) {
|
| return true;
|
| }
|
|
|
| -void XKeyboardImpl::SetCapsLockEnabled(bool enable_caps_lock) {
|
| +void KeyboardControllerX11::SetCapsLockEnabled(bool enable_caps_lock) {
|
| SetLockedModifiers(enable_caps_lock);
|
| }
|
|
|
| -bool XKeyboardImpl::SetCurrentKeyboardLayoutByName(
|
| +bool KeyboardControllerX11::SetCurrentKeyboardLayoutByName(
|
| const std::string& layout_name) {
|
| if (SetLayoutInternal(layout_name, false)) {
|
| current_layout_name_ = layout_name;
|
| @@ -390,7 +391,7 @@ bool XKeyboardImpl::SetCurrentKeyboardLayoutByName(
|
| return false;
|
| }
|
|
|
| -bool XKeyboardImpl::ReapplyCurrentKeyboardLayout() {
|
| +bool KeyboardControllerX11::ReapplyCurrentKeyboardLayout() {
|
| if (current_layout_name_.empty()) {
|
| DVLOG(1) << "Can't reapply XKB layout: layout unknown";
|
| return false;
|
| @@ -398,15 +399,15 @@ bool XKeyboardImpl::ReapplyCurrentKeyboardLayout() {
|
| return SetLayoutInternal(current_layout_name_, true /* force */);
|
| }
|
|
|
| -void XKeyboardImpl::ReapplyCurrentModifierLockStatus() {
|
| +void KeyboardControllerX11::ReapplyCurrentModifierLockStatus() {
|
| SetLockedModifiers(current_caps_lock_status_);
|
| }
|
|
|
| -void XKeyboardImpl::DisableNumLock() {
|
| +void KeyboardControllerX11::DisableNumLock() {
|
| SetCapsLockEnabled(current_caps_lock_status_);
|
| }
|
|
|
| -void XKeyboardImpl::OnSetLayoutFinish() {
|
| +void KeyboardControllerX11::OnSetLayoutFinish() {
|
| if (execute_queue_.empty()) {
|
| DVLOG(1) << "OnSetLayoutFinish: execute_queue_ is empty. "
|
| << "base::LaunchProcess failed?";
|
| @@ -419,27 +420,29 @@ void XKeyboardImpl::OnSetLayoutFinish() {
|
| } // namespace
|
|
|
| // static
|
| -bool XKeyboard::GetAutoRepeatEnabledForTesting() {
|
| +bool KeyboardController::GetAutoRepeatEnabledForTesting() {
|
| XKeyboardState state = {};
|
| XGetKeyboardControl(GetXDisplay(), &state);
|
| return state.global_auto_repeat != AutoRepeatModeOff;
|
| }
|
|
|
| // static
|
| -bool XKeyboard::GetAutoRepeatRateForTesting(AutoRepeatRate* out_rate) {
|
| - return XkbGetAutoRepeatRate(GetXDisplay(), XkbUseCoreKbd,
|
| +bool KeyboardController::GetAutoRepeatRateForTesting(AutoRepeatRate* out_rate) {
|
| + return XkbGetAutoRepeatRate(GetXDisplay(),
|
| + XkbUseCoreKbd,
|
| &(out_rate->initial_delay_in_ms),
|
| &(out_rate->repeat_interval_in_ms)) == True;
|
| }
|
|
|
| // static
|
| -bool XKeyboard::CheckLayoutNameForTesting(const std::string& layout_name) {
|
| +bool KeyboardController::CheckLayoutNameForTesting(
|
| + const std::string& layout_name) {
|
| return CheckLayoutName(layout_name);
|
| }
|
|
|
| // static
|
| -XKeyboard* XKeyboard::Create() {
|
| - return new XKeyboardImpl();
|
| +KeyboardController* KeyboardController::Create() {
|
| + return new KeyboardControllerX11();
|
| }
|
|
|
| } // namespace input_method
|
|
|