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

Side by Side Diff: content/renderer/render_widget.cc

Issue 2285923002: Simplify handling of text input types in RenderWidget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the glitch. Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « content/renderer/render_widget.h ('k') | third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp » ('j') | 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { 180 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
181 static TextInputModeMapSingleton* singleton = 181 static TextInputModeMapSingleton* singleton =
182 TextInputModeMapSingleton::GetInstance(); 182 TextInputModeMapSingleton::GetInstance();
183 TextInputModeMap::const_iterator it = 183 TextInputModeMap::const_iterator it =
184 singleton->map().find(input_mode.utf8()); 184 singleton->map().find(input_mode.utf8());
185 if (it == singleton->map().end()) 185 if (it == singleton->map().end())
186 return ui::TEXT_INPUT_MODE_DEFAULT; 186 return ui::TEXT_INPUT_MODE_DEFAULT;
187 return it->second; 187 return it->second;
188 } 188 }
189 189
190 bool IsDateTimeInput(ui::TextInputType type) {
191 return type == ui::TEXT_INPUT_TYPE_DATE ||
192 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
193 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
194 type == ui::TEXT_INPUT_TYPE_MONTH ||
195 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
196 }
197
198 content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate( 190 content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
199 content::RenderWidget* widget) { 191 content::RenderWidget* widget) {
200 #if defined(USE_AURA) 192 #if defined(USE_AURA)
201 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess(); 193 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
202 if (content::MojoShellConnection::GetForProcess() && 194 if (content::MojoShellConnection::GetForProcess() &&
203 cmdline.HasSwitch(switches::kUseMusInRenderer)) { 195 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
204 return content::RenderWidgetMusConnection::GetOrCreate( 196 return content::RenderWidgetMusConnection::GetOrCreate(
205 widget->routing_id()); 197 widget->routing_id());
206 } 198 }
207 #endif 199 #endif
(...skipping 26 matching lines...) Expand all
234 did_show_(false), 226 did_show_(false),
235 is_hidden_(hidden), 227 is_hidden_(hidden),
236 compositor_never_visible_(never_visible), 228 compositor_never_visible_(never_visible),
237 is_fullscreen_granted_(false), 229 is_fullscreen_granted_(false),
238 display_mode_(blink::WebDisplayModeUndefined), 230 display_mode_(blink::WebDisplayModeUndefined),
239 ime_event_guard_(nullptr), 231 ime_event_guard_(nullptr),
240 closing_(false), 232 closing_(false),
241 host_closing_(false), 233 host_closing_(false),
242 is_swapped_out_(swapped_out), 234 is_swapped_out_(swapped_out),
243 for_oopif_(false), 235 for_oopif_(false),
244 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
245 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 236 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
246 text_input_flags_(0), 237 text_input_flags_(0),
247 can_compose_inline_(true), 238 can_compose_inline_(true),
248 composition_range_(gfx::Range::InvalidRange()), 239 composition_range_(gfx::Range::InvalidRange()),
249 popup_type_(popup_type), 240 popup_type_(popup_type),
250 pending_window_rect_count_(0), 241 pending_window_rect_count_(0),
251 screen_info_(screen_info), 242 screen_info_(screen_info),
252 device_scale_factor_(screen_info_.deviceScaleFactor), 243 device_scale_factor_(screen_info_.deviceScaleFactor),
253 #if defined(OS_ANDROID) 244 #if defined(OS_ANDROID)
254 text_field_is_dirty_(false), 245 text_field_is_dirty_(false),
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); 891 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
901 if (ime_event_guard_) { 892 if (ime_event_guard_) {
902 // show_ime should still be effective even if it was set inside the IME 893 // show_ime should still be effective even if it was set inside the IME
903 // event guard. 894 // event guard.
904 if (show_ime == ShowIme::IF_NEEDED) { 895 if (show_ime == ShowIme::IF_NEEDED) {
905 ime_event_guard_->set_show_ime(true); 896 ime_event_guard_->set_show_ime(true);
906 } 897 }
907 return; 898 return;
908 } 899 }
909 900
910 ui::TextInputType new_type = GetTextInputType(); 901 if (!webwidget_)
911 if (IsDateTimeInput(new_type)) 902 return;
912 return; // Not considered as a text input field in WebKit/Chromium.
913 903
914 blink::WebTextInputInfo new_info; 904 blink::WebTextInputInfo new_info = webwidget_->textInputInfo();
915 if (webwidget_) 905
916 new_info = webwidget_->textInputInfo();
917 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 906 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
918 907
919 bool new_can_compose_inline = CanComposeInline(); 908 bool new_can_compose_inline = CanComposeInline();
920 909
921 // Only sends text input params if they are changed or if the ime should be 910 // Only sends text input params if they are changed or if the ime should be
922 // shown. 911 // shown.
923 if (show_ime == ShowIme::IF_NEEDED || 912 if (show_ime == ShowIme::IF_NEEDED ||
924 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || 913 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
925 (text_input_type_ != new_type || text_input_mode_ != new_mode || 914 (text_input_mode_ != new_mode || text_input_info_ != new_info ||
926 text_input_info_ != new_info ||
927 can_compose_inline_ != new_can_compose_inline) 915 can_compose_inline_ != new_can_compose_inline)
928 #if defined(OS_ANDROID) 916 #if defined(OS_ANDROID)
929 || text_field_is_dirty_ 917 || text_field_is_dirty_
930 #endif 918 #endif
931 ) { 919 ) {
932 TextInputState params; 920 TextInputState params;
933 params.type = new_type; 921 params.type = WebKitToUiTextInputType(new_info.type);
934 params.mode = new_mode; 922 params.mode = new_mode;
935 params.flags = new_info.flags; 923 params.flags = new_info.flags;
936 params.value = new_info.value.utf8(); 924 params.value = new_info.value.utf8();
937 params.selection_start = new_info.selectionStart; 925 params.selection_start = new_info.selectionStart;
938 params.selection_end = new_info.selectionEnd; 926 params.selection_end = new_info.selectionEnd;
939 params.composition_start = new_info.compositionStart; 927 params.composition_start = new_info.compositionStart;
940 params.composition_end = new_info.compositionEnd; 928 params.composition_end = new_info.compositionEnd;
941 params.can_compose_inline = new_can_compose_inline; 929 params.can_compose_inline = new_can_compose_inline;
942 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); 930 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
943 #if defined(USE_AURA) 931 #if defined(USE_AURA)
944 params.is_non_ime_change = true; 932 params.is_non_ime_change = true;
945 #endif 933 #endif
946 #if defined(OS_ANDROID) 934 #if defined(OS_ANDROID)
947 params.is_non_ime_change = 935 params.is_non_ime_change =
948 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_; 936 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
949 if (params.is_non_ime_change) 937 if (params.is_non_ime_change)
950 OnImeEventSentForAck(new_info); 938 OnImeEventSentForAck(new_info);
951 text_field_is_dirty_ = false; 939 text_field_is_dirty_ = false;
952 #endif 940 #endif
953 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); 941 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
954 942
955 text_input_info_ = new_info; 943 text_input_info_ = new_info;
956 text_input_type_ = new_type;
957 text_input_mode_ = new_mode; 944 text_input_mode_ = new_mode;
958 can_compose_inline_ = new_can_compose_inline; 945 can_compose_inline_ = new_can_compose_inline;
959 text_input_flags_ = new_info.flags; 946 text_input_flags_ = new_info.flags;
960 } 947 }
961 } 948 }
962 949
963 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { 950 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
964 if (owner_delegate_) 951 if (owner_delegate_)
965 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event); 952 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
966 953
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 } 1878 }
1892 1879
1893 WebScreenInfo RenderWidget::screenInfo() { 1880 WebScreenInfo RenderWidget::screenInfo() {
1894 return screen_info_; 1881 return screen_info_;
1895 } 1882 }
1896 1883
1897 void RenderWidget::resetInputMethod() { 1884 void RenderWidget::resetInputMethod() {
1898 ImeEventGuard guard(this); 1885 ImeEventGuard guard(this);
1899 // If the last text input type is not None, then we should finish any 1886 // If the last text input type is not None, then we should finish any
1900 // ongoing composition regardless of the new text input type. 1887 // ongoing composition regardless of the new text input type.
1901 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 1888 if (text_input_info_.type != blink::WebTextInputTypeNone) {
1902 // If a composition text exists, then we need to let the browser process 1889 // If a composition text exists, then we need to let the browser process
1903 // to cancel the input method's ongoing composition session. 1890 // to cancel the input method's ongoing composition session.
1904 if (webwidget_->confirmComposition()) 1891 if (webwidget_->confirmComposition())
1905 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1892 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1906 } 1893 }
1907 1894
1908 UpdateCompositionInfo(false /* not an immediate request */); 1895 UpdateCompositionInfo(false /* not an immediate request */);
1909 } 1896 }
1910 1897
1911 #if defined(OS_ANDROID) 1898 #if defined(OS_ANDROID)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 void RenderWidget::requestPointerUnlock() { 2053 void RenderWidget::requestPointerUnlock() {
2067 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); 2054 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2068 } 2055 }
2069 2056
2070 bool RenderWidget::isPointerLocked() { 2057 bool RenderWidget::isPointerLocked() {
2071 return mouse_lock_dispatcher_->IsMouseLockedTo( 2058 return mouse_lock_dispatcher_->IsMouseLockedTo(
2072 webwidget_mouse_lock_target_.get()); 2059 webwidget_mouse_lock_target_.get());
2073 } 2060 }
2074 2061
2075 } // namespace content 2062 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698