Index: ui/views/ime/mock_input_method.cc |
diff --git a/ui/views/ime/mock_input_method.cc b/ui/views/ime/mock_input_method.cc |
index b7611dae4f413793eb20c7044d7ebc972e61afd2..ab4deed885602c2782a2724515bde016a063045c 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() && HasMockComposition(); |
ClearStates(); |
if (handled) { |
@@ -73,27 +56,17 @@ 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(); |
- } |
+ InsertMockComposition(); |
} else if (key.type() == ui::ET_KEY_PRESSED) { |
base::char16 ch = key.GetCharacter(); |
client->InsertChar(ch, key.flags()); |
} |
} |
- ClearResult(); |
+ ClearMockComposition(); |
} |
void MockInputMethod::OnTextInputTypeChanged(View* view) { |
@@ -103,27 +76,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(); |
+ ClearMockComposition(); |
} |
} |
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 { |
@@ -141,18 +111,16 @@ void MockInputMethod::OnWillChangeFocus(View* focused_before, View* focused) { |
ui::TextInputClient* client = GetTextInputClient(); |
if (client && client->HasCompositionText()) |
client->ConfirmCompositionText(); |
- focus_changed_ = true; |
- ClearResult(); |
+ ClearMockComposition(); |
} |
void MockInputMethod::Clear() { |
ClearStates(); |
- ClearResult(); |
+ ClearMockComposition(); |
} |
void MockInputMethod::SetCompositionTextForNextKey( |
const ui::CompositionText& composition) { |
- composition_changed_ = true; |
composition_ = composition; |
} |
@@ -160,33 +128,30 @@ 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::InsertMockComposition() { |
+ ui::TextInputClient* client = GetTextInputClient(); |
+ if (result_text_.length()) |
+ client->InsertText(result_text_); |
+ |
+ if (composition_.text.length()) |
+ client->SetCompositionText(composition_); |
+ else |
+ client->ClearCompositionText(); |
} |
-void MockInputMethod::SetActive(bool active) { |
- if (active_ != active) { |
- active_ = active; |
- OnInputMethodChanged(); |
- } |
+bool MockInputMethod::HasMockComposition() { |
+ return composition_.text.length() || result_text_.length(); |
+} |
+ |
+void MockInputMethod::ClearMockComposition() { |
+ composition_.Clear(); |
+ result_text_.clear(); |
} |
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() { |
- composition_.Clear(); |
- composition_changed_ = false; |
- result_text_.clear(); |
} |
} // namespace views |