summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/views/ime/input_method.h3
-rw-r--r--ui/views/ime/input_method_base.cc4
-rw-r--r--ui/views/ime/input_method_base.h1
-rw-r--r--ui/views/ime/mock_input_method.cc85
-rw-r--r--ui/views/ime/mock_input_method.h21
-rw-r--r--ui/views/ime/null_input_method.cc4
-rw-r--r--ui/views/ime/null_input_method.h1
7 files changed, 24 insertions, 95 deletions
diff --git a/ui/views/ime/input_method.h b/ui/views/ime/input_method.h
index ffb5ae9..268c9f1 100644
--- a/ui/views/ime/input_method.h
+++ b/ui/views/ime/input_method.h
@@ -117,9 +117,6 @@ class VIEWS_EXPORT InputMethod {
// Displays an on screen keyboard if enabled.
virtual void ShowImeIfNeeded() = 0;
- // Returns true if the input method is a mock instance used for testing.
- virtual bool IsMock() const = 0;
-
// TODO(suzhe): Support mouse/touch event.
};
diff --git a/ui/views/ime/input_method_base.cc b/ui/views/ime/input_method_base.cc
index 784746b..6eb5179 100644
--- a/ui/views/ime/input_method_base.cc
+++ b/ui/views/ime/input_method_base.cc
@@ -52,10 +52,6 @@ ui::TextInputType InputMethodBase::GetTextInputType() const {
return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
}
-bool InputMethodBase::IsMock() const {
- return false;
-}
-
void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) {}
void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) {}
diff --git a/ui/views/ime/input_method_base.h b/ui/views/ime/input_method_base.h
index c95966c..75fd6fc 100644
--- a/ui/views/ime/input_method_base.h
+++ b/ui/views/ime/input_method_base.h
@@ -34,7 +34,6 @@ class VIEWS_EXPORT InputMethodBase : public InputMethod,
void OnTextInputTypeChanged(View* view) override;
ui::TextInputClient* GetTextInputClient() const override;
ui::TextInputType GetTextInputType() const override;
- bool IsMock() const override;
// Overridden from FocusChangeListener.
void OnWillChangeFocus(View* focused_before, View* focused) override;
diff --git a/ui/views/ime/mock_input_method.cc b/ui/views/ime/mock_input_method.cc
index b7611da..a56c96a 100644
--- a/ui/views/ime/mock_input_method.cc
+++ b/ui/views/ime/mock_input_method.cc
@@ -14,37 +14,21 @@
namespace views {
MockInputMethod::MockInputMethod()
- : composition_changed_(false),
- focus_changed_(false),
- untranslated_ime_message_called_(false),
+ : untranslated_ime_message_called_(false),
text_input_type_changed_(false),
- caret_bounds_changed_(false),
- cancel_composition_called_(false),
- input_locale_changed_(false),
- locale_("en-US"),
- active_(true) {
+ cancel_composition_called_(false) {
}
MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
- : composition_changed_(false),
- focus_changed_(false),
- untranslated_ime_message_called_(false),
+ : untranslated_ime_message_called_(false),
text_input_type_changed_(false),
- caret_bounds_changed_(false),
- cancel_composition_called_(false),
- input_locale_changed_(false),
- locale_("en-US"),
- active_(true) {
+ cancel_composition_called_(false) {
SetDelegate(delegate);
}
MockInputMethod::~MockInputMethod() {
}
-void MockInputMethod::Init(Widget* widget) {
- InputMethodBase::Init(widget);
-}
-
void MockInputMethod::OnFocus() {}
void MockInputMethod::OnBlur() {}
@@ -59,8 +43,7 @@ bool MockInputMethod::OnUntranslatedIMEMessage(
}
void MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& key) {
- bool handled = (composition_changed_ || result_text_.length()) &&
- !IsTextInputTypeNone();
+ bool handled = !IsTextInputTypeNone() && HasComposition();
ClearStates();
if (handled) {
@@ -73,27 +56,22 @@ void MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& key) {
DispatchKeyEventPostIME(key);
}
- if (focus_changed_)
- return;
-
ui::TextInputClient* client = GetTextInputClient();
if (client) {
if (handled) {
if (result_text_.length())
client->InsertText(result_text_);
- if (composition_changed_) {
- if (composition_.text.length())
- client->SetCompositionText(composition_);
- else
- client->ClearCompositionText();
- }
+ if (composition_.text.length())
+ client->SetCompositionText(composition_);
+ else
+ client->ClearCompositionText();
} else if (key.type() == ui::ET_KEY_PRESSED) {
base::char16 ch = key.GetCharacter();
client->InsertChar(ch, key.flags());
}
}
- ClearResult();
+ ClearComposition();
}
void MockInputMethod::OnTextInputTypeChanged(View* view) {
@@ -103,27 +81,24 @@ void MockInputMethod::OnTextInputTypeChanged(View* view) {
}
void MockInputMethod::OnCaretBoundsChanged(View* view) {
- if (IsViewFocused(view))
- caret_bounds_changed_ = true;
}
void MockInputMethod::CancelComposition(View* view) {
if (IsViewFocused(view)) {
cancel_composition_called_ = true;
- ClearResult();
+ ClearComposition();
}
}
void MockInputMethod::OnInputLocaleChanged() {
- input_locale_changed_ = true;
}
std::string MockInputMethod::GetInputLocale() {
- return locale_;
+ return "en-US";
}
bool MockInputMethod::IsActive() {
- return active_;
+ return true;
}
bool MockInputMethod::IsCandidatePopupOpen() const {
@@ -133,26 +108,20 @@ bool MockInputMethod::IsCandidatePopupOpen() const {
void MockInputMethod::ShowImeIfNeeded() {
}
-bool MockInputMethod::IsMock() const {
- return true;
-}
-
void MockInputMethod::OnWillChangeFocus(View* focused_before, View* focused) {
ui::TextInputClient* client = GetTextInputClient();
if (client && client->HasCompositionText())
client->ConfirmCompositionText();
- focus_changed_ = true;
- ClearResult();
+ ClearComposition();
}
void MockInputMethod::Clear() {
ClearStates();
- ClearResult();
+ ClearComposition();
}
void MockInputMethod::SetCompositionTextForNextKey(
const ui::CompositionText& composition) {
- composition_changed_ = true;
composition_ = composition;
}
@@ -160,32 +129,18 @@ void MockInputMethod::SetResultTextForNextKey(const base::string16& result) {
result_text_ = result;
}
-void MockInputMethod::SetInputLocale(const std::string& locale) {
- if (locale_ != locale) {
- locale_ = locale;
- OnInputMethodChanged();
- }
-}
-
-void MockInputMethod::SetActive(bool active) {
- if (active_ != active) {
- active_ = active;
- OnInputMethodChanged();
- }
-}
-
void MockInputMethod::ClearStates() {
- focus_changed_ = false;
untranslated_ime_message_called_ = false;
text_input_type_changed_ = false;
- caret_bounds_changed_ = false;
cancel_composition_called_ = false;
- input_locale_changed_ = false;
}
-void MockInputMethod::ClearResult() {
+bool MockInputMethod::HasComposition() {
+ return composition_.text.length() || result_text_.length();
+}
+
+void MockInputMethod::ClearComposition() {
composition_.Clear();
- composition_changed_ = false;
result_text_.clear();
}
diff --git a/ui/views/ime/mock_input_method.h b/ui/views/ime/mock_input_method.h
index 19d8dc5..ddee3c2 100644
--- a/ui/views/ime/mock_input_method.h
+++ b/ui/views/ime/mock_input_method.h
@@ -23,7 +23,6 @@ class VIEWS_EXPORT MockInputMethod : public InputMethodBase {
~MockInputMethod() override;
// Overridden from InputMethod:
- void Init(Widget* widget) override;
void OnFocus() override;
void OnBlur() override;
bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
@@ -37,16 +36,12 @@ class VIEWS_EXPORT MockInputMethod : public InputMethodBase {
bool IsActive() override;
bool IsCandidatePopupOpen() const override;
void ShowImeIfNeeded() override;
- bool IsMock() const override;
- bool focus_changed() const { return focus_changed_; }
bool untranslated_ime_message_called() const {
return untranslated_ime_message_called_;
}
bool text_input_type_changed() const { return text_input_type_changed_; }
- bool caret_bounds_changed() const { return caret_bounds_changed_; }
bool cancel_composition_called() const { return cancel_composition_called_; }
- bool input_locale_changed() const { return input_locale_changed_; }
// Clears all internal states and result.
void Clear();
@@ -54,9 +49,6 @@ class VIEWS_EXPORT MockInputMethod : public InputMethodBase {
void SetCompositionTextForNextKey(const ui::CompositionText& composition);
void SetResultTextForNextKey(const base::string16& result);
- void SetInputLocale(const std::string& locale);
- void SetActive(bool active);
-
private:
// Overridden from InputMethodBase.
void OnWillChangeFocus(View* focused_before, View* focused) override;
@@ -64,13 +56,15 @@ class VIEWS_EXPORT MockInputMethod : public InputMethodBase {
// Clears boolean states defined below.
void ClearStates();
+ // Whether a mock composition or result is scheduled for the next key event.
+ bool HasComposition();
+
// Clears only composition information and result text.
- void ClearResult();
+ void ClearComposition();
// Composition information for the next key event. It'll be cleared
// automatically after dispatching the next key event.
ui::CompositionText composition_;
- bool composition_changed_;
// Result text for the next key event. It'll be cleared automatically after
// dispatching the next key event.
@@ -78,16 +72,9 @@ class VIEWS_EXPORT MockInputMethod : public InputMethodBase {
// Record call state of corresponding methods. They will be set to false
// automatically before dispatching a key event.
- bool focus_changed_;
bool untranslated_ime_message_called_;
bool text_input_type_changed_;
- bool caret_bounds_changed_;
bool cancel_composition_called_;
- bool input_locale_changed_;
-
- // To mock corresponding input method prooperties.
- std::string locale_;
- bool active_;
DISALLOW_COPY_AND_ASSIGN(MockInputMethod);
};
diff --git a/ui/views/ime/null_input_method.cc b/ui/views/ime/null_input_method.cc
index 666d6cf..d98988c 100644
--- a/ui/views/ime/null_input_method.cc
+++ b/ui/views/ime/null_input_method.cc
@@ -55,8 +55,4 @@ bool NullInputMethod::IsCandidatePopupOpen() const {
void NullInputMethod::ShowImeIfNeeded() {}
-bool NullInputMethod::IsMock() const {
- return false;
-}
-
} // namespace views
diff --git a/ui/views/ime/null_input_method.h b/ui/views/ime/null_input_method.h
index 1ee1308..83980c3 100644
--- a/ui/views/ime/null_input_method.h
+++ b/ui/views/ime/null_input_method.h
@@ -39,7 +39,6 @@ class NullInputMethod : public InputMethod {
ui::TextInputType GetTextInputType() const override;
bool IsCandidatePopupOpen() const override;
void ShowImeIfNeeded() override;
- bool IsMock() const override;
private:
DISALLOW_COPY_AND_ASSIGN(NullInputMethod);