Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: ui/views/ime/mock_input_method.cc

Issue 782673002: MacViews: tryjobs for toolkit_views=1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: latest crrev/901823002 Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/ime/mock_input_method.h ('k') | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ui/views/ime/mock_input_method.h ('k') | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698