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

Unified Diff: content/renderer/render_widget.cc

Issue 2447213002: Revert of Revert "Simplify handling of text input types in RenderWidget." (Closed)
Patch Set: Created 4 years, 2 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 | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_widget.cc
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index bd10e264a79e8889ce9d4afc6e5cf0bb9dead09f..b4be9c3755e6ea17824202a93bbb7134de90eaea 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -154,12 +154,41 @@
blink::WebWidget* webwidget_;
};
-bool IsDateTimeInput(ui::TextInputType type) {
- return type == ui::TEXT_INPUT_TYPE_DATE ||
- type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
- type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
- type == ui::TEXT_INPUT_TYPE_MONTH ||
- type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
+class TextInputModeMapSingleton {
+ public:
+ static TextInputModeMapSingleton* GetInstance() {
+ return base::Singleton<TextInputModeMapSingleton>::get();
+ }
+ TextInputModeMapSingleton() {
+ map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
+ map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
+ map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
+ map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
+ map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
+ map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
+ map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
+ map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
+ map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
+ map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
+ map_["url"] = ui::TEXT_INPUT_MODE_URL;
+ }
+ const TextInputModeMap& map() const { return map_; }
+ private:
+ TextInputModeMap map_;
+
+ friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
+
+ DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
+};
+
+ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
+ static TextInputModeMapSingleton* singleton =
+ TextInputModeMapSingleton::GetInstance();
+ TextInputModeMap::const_iterator it =
+ singleton->map().find(input_mode.utf8());
+ if (it == singleton->map().end())
+ return ui::TEXT_INPUT_MODE_DEFAULT;
+ return it->second;
}
content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
@@ -215,7 +244,6 @@
host_closing_(false),
is_swapped_out_(swapped_out),
for_oopif_(false),
- text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
text_input_flags_(0),
can_compose_inline_(true),
@@ -926,13 +954,11 @@
return;
}
- ui::TextInputType new_type = GetTextInputType();
- if (IsDateTimeInput(new_type))
- return; // Not considered as a text input field in WebKit/Chromium.
-
- blink::WebTextInputInfo new_info;
- if (GetWebWidget())
- new_info = GetWebWidget()->textInputInfo();
+ if (!GetWebWidget())
+ return;
+
+ blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo();
+
const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
bool new_can_compose_inline = CanComposeInline();
@@ -941,15 +967,14 @@
// shown.
if (show_ime == ShowIme::IF_NEEDED ||
(IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
- (text_input_type_ != new_type || text_input_mode_ != new_mode ||
- text_input_info_ != new_info ||
+ (text_input_mode_ != new_mode || text_input_info_ != new_info ||
can_compose_inline_ != new_can_compose_inline)
#if defined(OS_ANDROID)
|| text_field_is_dirty_
#endif
) {
TextInputState params;
- params.type = new_type;
+ params.type = WebKitToUiTextInputType(new_info.type);
params.mode = new_mode;
params.flags = new_info.flags;
params.value = new_info.value.utf8();
@@ -973,7 +998,6 @@
Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
text_input_info_ = new_info;
- text_input_type_ = new_type;
text_input_mode_ = new_mode;
can_compose_inline_ = new_can_compose_inline;
text_input_flags_ = new_info.flags;
@@ -2007,7 +2031,7 @@
ImeEventGuard guard(this);
// If the last text input type is not None, then we should finish any
// ongoing composition regardless of the new text input type.
- if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
+ if (text_input_info_.type != blink::WebTextInputTypeNone) {
// If a composition text exists, then we need to let the browser process
// to cancel the input method's ongoing composition session.
if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection))
« no previous file with comments | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698