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

Side by Side 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, 1 month 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 unified diff | Download patch
« no previous file with comments | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/render_widget.h" 5 #include "content/renderer/render_widget.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override { 148 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
149 // The WebWidget handles mouse lock in Blink's handleInputEvent(). 149 // The WebWidget handles mouse lock in Blink's handleInputEvent().
150 return false; 150 return false;
151 } 151 }
152 152
153 private: 153 private:
154 blink::WebWidget* webwidget_; 154 blink::WebWidget* webwidget_;
155 }; 155 };
156 156
157 bool IsDateTimeInput(ui::TextInputType type) { 157 class TextInputModeMapSingleton {
158 return type == ui::TEXT_INPUT_TYPE_DATE || 158 public:
159 type == ui::TEXT_INPUT_TYPE_DATE_TIME || 159 static TextInputModeMapSingleton* GetInstance() {
160 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || 160 return base::Singleton<TextInputModeMapSingleton>::get();
161 type == ui::TEXT_INPUT_TYPE_MONTH || 161 }
162 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK; 162 TextInputModeMapSingleton() {
163 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
164 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
165 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
166 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
167 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
168 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
169 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
170 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
171 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
172 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
173 map_["url"] = ui::TEXT_INPUT_MODE_URL;
174 }
175 const TextInputModeMap& map() const { return map_; }
176 private:
177 TextInputModeMap map_;
178
179 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
180
181 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
182 };
183
184 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
185 static TextInputModeMapSingleton* singleton =
186 TextInputModeMapSingleton::GetInstance();
187 TextInputModeMap::const_iterator it =
188 singleton->map().find(input_mode.utf8());
189 if (it == singleton->map().end())
190 return ui::TEXT_INPUT_MODE_DEFAULT;
191 return it->second;
163 } 192 }
164 193
165 content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate( 194 content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
166 content::RenderWidget* widget) { 195 content::RenderWidget* widget) {
167 #if defined(USE_AURA) 196 #if defined(USE_AURA)
168 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess(); 197 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
169 if (content::ServiceManagerConnection::GetForProcess() && 198 if (content::ServiceManagerConnection::GetForProcess() &&
170 cmdline.HasSwitch(switches::kUseMusInRenderer)) { 199 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
171 return content::RenderWidgetMusConnection::GetOrCreate( 200 return content::RenderWidgetMusConnection::GetOrCreate(
172 widget->routing_id()); 201 widget->routing_id());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 is_hidden_(hidden), 237 is_hidden_(hidden),
209 compositor_never_visible_(never_visible), 238 compositor_never_visible_(never_visible),
210 is_fullscreen_granted_(false), 239 is_fullscreen_granted_(false),
211 display_mode_(blink::WebDisplayModeUndefined), 240 display_mode_(blink::WebDisplayModeUndefined),
212 ime_event_guard_(nullptr), 241 ime_event_guard_(nullptr),
213 ime_in_batch_edit_(false), 242 ime_in_batch_edit_(false),
214 closing_(false), 243 closing_(false),
215 host_closing_(false), 244 host_closing_(false),
216 is_swapped_out_(swapped_out), 245 is_swapped_out_(swapped_out),
217 for_oopif_(false), 246 for_oopif_(false),
218 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
219 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 247 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
220 text_input_flags_(0), 248 text_input_flags_(0),
221 can_compose_inline_(true), 249 can_compose_inline_(true),
222 composition_range_(gfx::Range::InvalidRange()), 250 composition_range_(gfx::Range::InvalidRange()),
223 popup_type_(popup_type), 251 popup_type_(popup_type),
224 pending_window_rect_count_(0), 252 pending_window_rect_count_(0),
225 screen_info_(screen_info), 253 screen_info_(screen_info),
226 device_scale_factor_(screen_info_.device_scale_factor), 254 device_scale_factor_(screen_info_.device_scale_factor),
227 #if defined(OS_ANDROID) 255 #if defined(OS_ANDROID)
228 text_field_is_dirty_(false), 256 text_field_is_dirty_(false),
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); 947 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
920 if (ime_event_guard_) { 948 if (ime_event_guard_) {
921 // show_ime should still be effective even if it was set inside the IME 949 // show_ime should still be effective even if it was set inside the IME
922 // event guard. 950 // event guard.
923 if (show_ime == ShowIme::IF_NEEDED) { 951 if (show_ime == ShowIme::IF_NEEDED) {
924 ime_event_guard_->set_show_ime(true); 952 ime_event_guard_->set_show_ime(true);
925 } 953 }
926 return; 954 return;
927 } 955 }
928 956
929 ui::TextInputType new_type = GetTextInputType(); 957 if (!GetWebWidget())
930 if (IsDateTimeInput(new_type)) 958 return;
931 return; // Not considered as a text input field in WebKit/Chromium.
932 959
933 blink::WebTextInputInfo new_info; 960 blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo();
934 if (GetWebWidget()) 961
935 new_info = GetWebWidget()->textInputInfo();
936 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 962 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
937 963
938 bool new_can_compose_inline = CanComposeInline(); 964 bool new_can_compose_inline = CanComposeInline();
939 965
940 // Only sends text input params if they are changed or if the ime should be 966 // Only sends text input params if they are changed or if the ime should be
941 // shown. 967 // shown.
942 if (show_ime == ShowIme::IF_NEEDED || 968 if (show_ime == ShowIme::IF_NEEDED ||
943 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || 969 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
944 (text_input_type_ != new_type || text_input_mode_ != new_mode || 970 (text_input_mode_ != new_mode || text_input_info_ != new_info ||
945 text_input_info_ != new_info ||
946 can_compose_inline_ != new_can_compose_inline) 971 can_compose_inline_ != new_can_compose_inline)
947 #if defined(OS_ANDROID) 972 #if defined(OS_ANDROID)
948 || text_field_is_dirty_ 973 || text_field_is_dirty_
949 #endif 974 #endif
950 ) { 975 ) {
951 TextInputState params; 976 TextInputState params;
952 params.type = new_type; 977 params.type = WebKitToUiTextInputType(new_info.type);
953 params.mode = new_mode; 978 params.mode = new_mode;
954 params.flags = new_info.flags; 979 params.flags = new_info.flags;
955 params.value = new_info.value.utf8(); 980 params.value = new_info.value.utf8();
956 params.selection_start = new_info.selectionStart; 981 params.selection_start = new_info.selectionStart;
957 params.selection_end = new_info.selectionEnd; 982 params.selection_end = new_info.selectionEnd;
958 params.composition_start = new_info.compositionStart; 983 params.composition_start = new_info.compositionStart;
959 params.composition_end = new_info.compositionEnd; 984 params.composition_end = new_info.compositionEnd;
960 params.can_compose_inline = new_can_compose_inline; 985 params.can_compose_inline = new_can_compose_inline;
961 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); 986 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
962 #if defined(USE_AURA) 987 #if defined(USE_AURA)
963 params.is_non_ime_change = true; 988 params.is_non_ime_change = true;
964 #endif 989 #endif
965 #if defined(OS_ANDROID) 990 #if defined(OS_ANDROID)
966 params.is_non_ime_change = 991 params.is_non_ime_change =
967 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_; 992 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
968 params.batch_edit = ime_in_batch_edit_; 993 params.batch_edit = ime_in_batch_edit_;
969 if (params.is_non_ime_change) 994 if (params.is_non_ime_change)
970 OnImeEventSentForAck(new_info); 995 OnImeEventSentForAck(new_info);
971 text_field_is_dirty_ = false; 996 text_field_is_dirty_ = false;
972 #endif 997 #endif
973 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); 998 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
974 999
975 text_input_info_ = new_info; 1000 text_input_info_ = new_info;
976 text_input_type_ = new_type;
977 text_input_mode_ = new_mode; 1001 text_input_mode_ = new_mode;
978 can_compose_inline_ = new_can_compose_inline; 1002 can_compose_inline_ = new_can_compose_inline;
979 text_input_flags_ = new_info.flags; 1003 text_input_flags_ = new_info.flags;
980 } 1004 }
981 } 1005 }
982 1006
983 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { 1007 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
984 if (owner_delegate_) 1008 if (owner_delegate_)
985 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event); 1009 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
986 1010
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 break; 2024 break;
2001 } 2025 }
2002 web_screen_info.orientationAngle = screen_info_.orientation_angle; 2026 web_screen_info.orientationAngle = screen_info_.orientation_angle;
2003 return web_screen_info; 2027 return web_screen_info;
2004 } 2028 }
2005 2029
2006 void RenderWidget::resetInputMethod() { 2030 void RenderWidget::resetInputMethod() {
2007 ImeEventGuard guard(this); 2031 ImeEventGuard guard(this);
2008 // If the last text input type is not None, then we should finish any 2032 // If the last text input type is not None, then we should finish any
2009 // ongoing composition regardless of the new text input type. 2033 // ongoing composition regardless of the new text input type.
2010 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 2034 if (text_input_info_.type != blink::WebTextInputTypeNone) {
2011 // If a composition text exists, then we need to let the browser process 2035 // If a composition text exists, then we need to let the browser process
2012 // to cancel the input method's ongoing composition session. 2036 // to cancel the input method's ongoing composition session.
2013 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) 2037 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection))
2014 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 2038 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
2015 } 2039 }
2016 2040
2017 UpdateCompositionInfo(false /* not an immediate request */); 2041 UpdateCompositionInfo(false /* not an immediate request */);
2018 } 2042 }
2019 2043
2020 #if defined(OS_ANDROID) 2044 #if defined(OS_ANDROID)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 bool RenderWidget::isPointerLocked() { 2193 bool RenderWidget::isPointerLocked() {
2170 return mouse_lock_dispatcher_->IsMouseLockedTo( 2194 return mouse_lock_dispatcher_->IsMouseLockedTo(
2171 webwidget_mouse_lock_target_.get()); 2195 webwidget_mouse_lock_target_.get());
2172 } 2196 }
2173 2197
2174 blink::WebWidget* RenderWidget::GetWebWidget() const { 2198 blink::WebWidget* RenderWidget::GetWebWidget() const {
2175 return webwidget_internal_; 2199 return webwidget_internal_;
2176 } 2200 }
2177 2201
2178 } // namespace content 2202 } // namespace content
OLDNEW
« 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