Skip to content

Commit

Permalink
Adds ozone support for ime keyboard.
Browse files Browse the repository at this point in the history
BUG=342336

Review URL: https://codereview.chromium.org/683773002

Cr-Commit-Position: refs/heads/master@{#302057}
  • Loading branch information
fengyuan authored and Commit bot committed Oct 30, 2014
1 parent 4373698 commit 8be55ca
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 153 deletions.
4 changes: 2 additions & 2 deletions chromeos/chromeos.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@
'ime/extension_ime_util.h',
'ime/fake_ime_keyboard.cc',
'ime/fake_ime_keyboard.h',
'ime/ime_keyboard.cc',
'ime/ime_keyboard.h',
'ime/ime_keyboard_ozone.cc',
'ime/ime_keyboard_x11.h',
'ime/ime_keyboard_x11.cc',
'ime/ime_keyboard_x11.h',
'ime/input_method_delegate.h',
'ime/input_method_descriptor.cc',
'ime/input_method_descriptor.h',
Expand Down
40 changes: 9 additions & 31 deletions chromeos/ime/fake_ime_keyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,37 @@ namespace input_method {

FakeImeKeyboard::FakeImeKeyboard()
: set_current_keyboard_layout_by_name_count_(0),
caps_lock_is_enabled_(false),
auto_repeat_is_enabled_(false) {
}

FakeImeKeyboard::~FakeImeKeyboard() {
}

void FakeImeKeyboard::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}

void FakeImeKeyboard::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}

bool FakeImeKeyboard::SetCurrentKeyboardLayoutByName(
const std::string& layout_name) {
++set_current_keyboard_layout_by_name_count_;
last_layout_ = layout_name;
return true;
}

bool FakeImeKeyboard::ReapplyCurrentKeyboardLayout() {
bool FakeImeKeyboard::SetAutoRepeatRate(const AutoRepeatRate& rate) {
last_auto_repeat_rate_ = rate;
return true;
}

void FakeImeKeyboard::ReapplyCurrentModifierLockStatus() {
bool FakeImeKeyboard::SetAutoRepeatEnabled(bool enabled) {
auto_repeat_is_enabled_ = enabled;
return true;
}

void FakeImeKeyboard::DisableNumLock() {
bool FakeImeKeyboard::ReapplyCurrentKeyboardLayout() {
return true;
}

void FakeImeKeyboard::SetCapsLockEnabled(bool enable_caps_lock) {
bool old_state = caps_lock_is_enabled_;
caps_lock_is_enabled_ = enable_caps_lock;
if (old_state != enable_caps_lock) {
FOR_EACH_OBSERVER(ImeKeyboard::Observer, observers_,
OnCapsLockChanged(enable_caps_lock));
}
void FakeImeKeyboard::ReapplyCurrentModifierLockStatus() {
}

bool FakeImeKeyboard::CapsLockIsEnabled() {
return caps_lock_is_enabled_;
void FakeImeKeyboard::DisableNumLock() {
}

bool FakeImeKeyboard::IsISOLevel5ShiftAvailable() const {
Expand All @@ -62,15 +50,5 @@ bool FakeImeKeyboard::IsAltGrAvailable() const {
return false;
}

bool FakeImeKeyboard::SetAutoRepeatEnabled(bool enabled) {
auto_repeat_is_enabled_ = enabled;
return true;
}

bool FakeImeKeyboard::SetAutoRepeatRate(const AutoRepeatRate& rate) {
last_auto_repeat_rate_ = rate;
return true;
}

} // namespace input_method
} // namespace chromeos
15 changes: 3 additions & 12 deletions chromeos/ime/fake_ime_keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <string>

#include "base/compiler_specific.h"
#include "base/observer_list.h"
#include "chromeos/chromeos_export.h"

namespace chromeos {
Expand All @@ -21,30 +20,22 @@ class CHROMEOS_EXPORT FakeImeKeyboard : public ImeKeyboard {
FakeImeKeyboard();
virtual ~FakeImeKeyboard();

virtual void AddObserver(Observer* observer) override;
virtual void RemoveObserver(Observer* observer) override;
virtual bool SetCurrentKeyboardLayoutByName(const std::string& layout_name)
override;
virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) override;
virtual bool SetAutoRepeatEnabled(bool enabled) override;
virtual bool ReapplyCurrentKeyboardLayout() override;
virtual void ReapplyCurrentModifierLockStatus() override;
virtual void DisableNumLock() override;
virtual void SetCapsLockEnabled(bool enable_caps_lock) override;
virtual bool CapsLockIsEnabled() override;
virtual bool IsISOLevel5ShiftAvailable() const override;
virtual bool IsAltGrAvailable() const override;
virtual bool SetAutoRepeatEnabled(bool enabled) override;
virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) override;

int set_current_keyboard_layout_by_name_count_;
std::string last_layout_;
bool caps_lock_is_enabled_;
bool auto_repeat_is_enabled_;
AutoRepeatRate last_auto_repeat_rate_;
// TODO(yusukes): Add more variables for counting the numbers of the API calls
bool auto_repeat_is_enabled_;

private:
ObserverList<Observer> observers_;

DISALLOW_COPY_AND_ASSIGN(FakeImeKeyboard);
};

Expand Down
105 changes: 105 additions & 0 deletions chromeos/ime/ime_keyboard.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2014 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 "chromeos/ime/ime_keyboard.h"

namespace chromeos {
namespace input_method {
namespace {

const char *kISOLevel5ShiftLayoutIds[] = {
"ca(multix)",
"de(neo)",
};

const char *kAltGrLayoutIds[] = {
"be",
"be",
"be",
"bg",
"bg(phonetic)",
"br",
"ca",
"ca(eng)",
"ca(multix)",
"ch",
"ch(fr)",
"cz",
"de",
"de(neo)",
"dk",
"ee",
"es",
"es(cat)",
"fi",
"fr",
"gb(dvorak)",
"gb(extd)",
"gr",
"hr",
"il",
"it",
"latam",
"lt",
"no",
"pl",
"pt",
"ro",
"se",
"si",
"sk",
"tr",
"ua",
"us(altgr-intl)",
"us(intl)",
};

} // namespace

ImeKeyboard::ImeKeyboard()
: caps_lock_is_enabled_(false) {
}

ImeKeyboard::~ImeKeyboard() {
}

void ImeKeyboard::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}

void ImeKeyboard::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}

void ImeKeyboard::SetCapsLockEnabled(bool enable_caps_lock) {
bool old_state = caps_lock_is_enabled_;
caps_lock_is_enabled_ = enable_caps_lock;
if (old_state != enable_caps_lock) {
FOR_EACH_OBSERVER(ImeKeyboard::Observer, observers_,
OnCapsLockChanged(enable_caps_lock));
}
}

bool ImeKeyboard::CapsLockIsEnabled() {
return caps_lock_is_enabled_;
}

bool ImeKeyboard::IsISOLevel5ShiftAvailable() const {
for (size_t i = 0; i < arraysize(kISOLevel5ShiftLayoutIds); ++i) {
if (last_layout_ == kISOLevel5ShiftLayoutIds[i])
return true;
}
return false;
}

bool ImeKeyboard::IsAltGrAvailable() const {
for (size_t i = 0; i < arraysize(kAltGrLayoutIds); ++i) {
if (last_layout_ == kAltGrLayoutIds[i])
return true;
}
return false;
}

} // namespace input_method
} // namespace chromeos
23 changes: 15 additions & 8 deletions chromeos/ime/ime_keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vector>

#include "base/basictypes.h"
#include "base/observer_list.h"
#include "chromeos/chromeos_export.h"

namespace chromeos {
Expand Down Expand Up @@ -42,11 +43,11 @@ class CHROMEOS_EXPORT ImeKeyboard {
virtual void OnCapsLockChanged(bool enabled) = 0;
};

virtual ~ImeKeyboard() {}

ImeKeyboard();
virtual ~ImeKeyboard();
// Adds/removes observer.
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
virtual void AddObserver(Observer* observer);
virtual void RemoveObserver(Observer* observer);

// Sets the current keyboard layout to |layout_name|. This function does not
// change the current mapping of the modifier keys. Returns true on success.
Expand Down Expand Up @@ -74,17 +75,17 @@ class CHROMEOS_EXPORT ImeKeyboard {

// Sets the caps lock status to |enable_caps_lock|. Do not call the function
// from non-UI threads.
virtual void SetCapsLockEnabled(bool enable_caps_lock) = 0;
virtual void SetCapsLockEnabled(bool enable_caps_lock);

// Returns true if caps lock is enabled. Do not call the function from non-UI
// threads.
virtual bool CapsLockIsEnabled() = 0;
virtual bool CapsLockIsEnabled();

// Returns true if the current layout supports ISO Level 5 shift.
virtual bool IsISOLevel5ShiftAvailable() const = 0;
virtual bool IsISOLevel5ShiftAvailable() const;

// Returns true if the current layout supports alt gr.
virtual bool IsAltGrAvailable() const = 0;
virtual bool IsAltGrAvailable() const;

// Turns on and off the auto-repeat of the keyboard. Returns true on success.
// Do not call the function from non-UI threads.
Expand All @@ -111,6 +112,12 @@ class CHROMEOS_EXPORT ImeKeyboard {
// Note: At this moment, classes other than InputMethodManager should not
// instantiate the ImeKeyboard class.
static ImeKeyboard* Create();

bool caps_lock_is_enabled_;
std::string last_layout_;

protected:
ObserverList<Observer> observers_;
};

} // namespace input_method
Expand Down
54 changes: 51 additions & 3 deletions chromeos/ime/ime_keyboard_ozone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,63 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ime/fake_ime_keyboard.h"
#include "chromeos/ime/ime_keyboard.h"
#include "chromeos/ime/ime_keyboard_ozone.h"

namespace chromeos {
namespace input_method {


ImeKeyboardOzone::ImeKeyboardOzone()
: set_current_keyboard_layout_by_name_count_(0),
caps_lock_is_enabled_(false),
auto_repeat_is_enabled_(false) {
}


ImeKeyboardOzone::~ImeKeyboardOzone() {
}

bool ImeKeyboardOzone::SetCurrentKeyboardLayoutByName(
const std::string& layout_name) {
// Call SetKeyMapping here.
// TODO: parse out layout name and variation.
last_layout_ = layout_name;
return true;
}

void ImeKeyboardOzone::ReapplyCurrentKeyboardLayout() {
SetCurrentKeyboardLayoutByName(last_layout_);
}

void ImeKeyboardOzone::SetCapsLockEnabled(bool enable_caps_lock) {
// Call SetModifierStates here.
ImeKeyboard::SetCapsLockEnabled(enable_caps_lock);
}

bool ImeKeyboardOzone::CapsLockIsEnabled() {
// Call getModifierStates here.
return false;
}

void ImeKeyboardOzone::ReapplyCurrentModifierLockStatus() {
// call SetModifierStates here.
}

void ImeKeyboardOzone::DisableNumLock() {
SetCapsLockEnabled(caps_lock_is_enabled_);
}

bool ImeKeyboardOzone::SetAutoRepeatRate(const AutoRepeatRate& rate) {
return true;
}

bool ImeKeyboardOzone::SetAutoRepeatEnabled(bool enabled) {
return true;
}

// static
ImeKeyboard* ImeKeyboard::Create() {
return new FakeImeKeyboard;
return new ImeKeyboardOzone();
}

} // namespace input_method
Expand Down
Loading

0 comments on commit 8be55ca

Please sign in to comment.