| OLD | NEW |
| 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 Loading... |
| 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 class TextInputModeMapSingleton { | 157 bool IsDateTimeInput(ui::TextInputType type) { |
| 158 public: | 158 return type == ui::TEXT_INPUT_TYPE_DATE || |
| 159 static TextInputModeMapSingleton* GetInstance() { | 159 type == ui::TEXT_INPUT_TYPE_DATE_TIME || |
| 160 return base::Singleton<TextInputModeMapSingleton>::get(); | 160 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || |
| 161 } | 161 type == ui::TEXT_INPUT_TYPE_MONTH || |
| 162 TextInputModeMapSingleton() { | 162 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK; |
| 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; | |
| 192 } | 163 } |
| 193 | 164 |
| 194 content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate( | 165 content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate( |
| 195 content::RenderWidget* widget) { | 166 content::RenderWidget* widget) { |
| 196 #if defined(USE_AURA) | 167 #if defined(USE_AURA) |
| 197 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess(); | 168 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess(); |
| 198 if (content::ServiceManagerConnection::GetForProcess() && | 169 if (content::ServiceManagerConnection::GetForProcess() && |
| 199 cmdline.HasSwitch(switches::kUseMusInRenderer)) { | 170 cmdline.HasSwitch(switches::kUseMusInRenderer)) { |
| 200 return content::RenderWidgetMusConnection::GetOrCreate( | 171 return content::RenderWidgetMusConnection::GetOrCreate( |
| 201 widget->routing_id()); | 172 widget->routing_id()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 is_hidden_(hidden), | 208 is_hidden_(hidden), |
| 238 compositor_never_visible_(never_visible), | 209 compositor_never_visible_(never_visible), |
| 239 is_fullscreen_granted_(false), | 210 is_fullscreen_granted_(false), |
| 240 display_mode_(blink::WebDisplayModeUndefined), | 211 display_mode_(blink::WebDisplayModeUndefined), |
| 241 ime_event_guard_(nullptr), | 212 ime_event_guard_(nullptr), |
| 242 ime_in_batch_edit_(false), | 213 ime_in_batch_edit_(false), |
| 243 closing_(false), | 214 closing_(false), |
| 244 host_closing_(false), | 215 host_closing_(false), |
| 245 is_swapped_out_(swapped_out), | 216 is_swapped_out_(swapped_out), |
| 246 for_oopif_(false), | 217 for_oopif_(false), |
| 218 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 247 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 219 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
| 248 text_input_flags_(0), | 220 text_input_flags_(0), |
| 249 can_compose_inline_(true), | 221 can_compose_inline_(true), |
| 250 composition_range_(gfx::Range::InvalidRange()), | 222 composition_range_(gfx::Range::InvalidRange()), |
| 251 popup_type_(popup_type), | 223 popup_type_(popup_type), |
| 252 pending_window_rect_count_(0), | 224 pending_window_rect_count_(0), |
| 253 screen_info_(screen_info), | 225 screen_info_(screen_info), |
| 254 device_scale_factor_(screen_info_.device_scale_factor), | 226 device_scale_factor_(screen_info_.device_scale_factor), |
| 255 #if defined(OS_ANDROID) | 227 #if defined(OS_ANDROID) |
| 256 text_field_is_dirty_(false), | 228 text_field_is_dirty_(false), |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); | 919 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); |
| 948 if (ime_event_guard_) { | 920 if (ime_event_guard_) { |
| 949 // show_ime should still be effective even if it was set inside the IME | 921 // show_ime should still be effective even if it was set inside the IME |
| 950 // event guard. | 922 // event guard. |
| 951 if (show_ime == ShowIme::IF_NEEDED) { | 923 if (show_ime == ShowIme::IF_NEEDED) { |
| 952 ime_event_guard_->set_show_ime(true); | 924 ime_event_guard_->set_show_ime(true); |
| 953 } | 925 } |
| 954 return; | 926 return; |
| 955 } | 927 } |
| 956 | 928 |
| 957 if (!GetWebWidget()) | 929 ui::TextInputType new_type = GetTextInputType(); |
| 958 return; | 930 if (IsDateTimeInput(new_type)) |
| 931 return; // Not considered as a text input field in WebKit/Chromium. |
| 959 | 932 |
| 960 blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo(); | 933 blink::WebTextInputInfo new_info; |
| 961 | 934 if (GetWebWidget()) |
| 935 new_info = GetWebWidget()->textInputInfo(); |
| 962 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); | 936 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); |
| 963 | 937 |
| 964 bool new_can_compose_inline = CanComposeInline(); | 938 bool new_can_compose_inline = CanComposeInline(); |
| 965 | 939 |
| 966 // Only sends text input params if they are changed or if the ime should be | 940 // Only sends text input params if they are changed or if the ime should be |
| 967 // shown. | 941 // shown. |
| 968 if (show_ime == ShowIme::IF_NEEDED || | 942 if (show_ime == ShowIme::IF_NEEDED || |
| 969 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || | 943 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || |
| 970 (text_input_mode_ != new_mode || text_input_info_ != new_info || | 944 (text_input_type_ != new_type || text_input_mode_ != new_mode || |
| 945 text_input_info_ != new_info || |
| 971 can_compose_inline_ != new_can_compose_inline) | 946 can_compose_inline_ != new_can_compose_inline) |
| 972 #if defined(OS_ANDROID) | 947 #if defined(OS_ANDROID) |
| 973 || text_field_is_dirty_ | 948 || text_field_is_dirty_ |
| 974 #endif | 949 #endif |
| 975 ) { | 950 ) { |
| 976 TextInputState params; | 951 TextInputState params; |
| 977 params.type = WebKitToUiTextInputType(new_info.type); | 952 params.type = new_type; |
| 978 params.mode = new_mode; | 953 params.mode = new_mode; |
| 979 params.flags = new_info.flags; | 954 params.flags = new_info.flags; |
| 980 params.value = new_info.value.utf8(); | 955 params.value = new_info.value.utf8(); |
| 981 params.selection_start = new_info.selectionStart; | 956 params.selection_start = new_info.selectionStart; |
| 982 params.selection_end = new_info.selectionEnd; | 957 params.selection_end = new_info.selectionEnd; |
| 983 params.composition_start = new_info.compositionStart; | 958 params.composition_start = new_info.compositionStart; |
| 984 params.composition_end = new_info.compositionEnd; | 959 params.composition_end = new_info.compositionEnd; |
| 985 params.can_compose_inline = new_can_compose_inline; | 960 params.can_compose_inline = new_can_compose_inline; |
| 986 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); | 961 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); |
| 987 #if defined(USE_AURA) | 962 #if defined(USE_AURA) |
| 988 params.is_non_ime_change = true; | 963 params.is_non_ime_change = true; |
| 989 #endif | 964 #endif |
| 990 #if defined(OS_ANDROID) | 965 #if defined(OS_ANDROID) |
| 991 params.is_non_ime_change = | 966 params.is_non_ime_change = |
| 992 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_; | 967 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_; |
| 993 params.batch_edit = ime_in_batch_edit_; | 968 params.batch_edit = ime_in_batch_edit_; |
| 994 if (params.is_non_ime_change) | 969 if (params.is_non_ime_change) |
| 995 OnImeEventSentForAck(new_info); | 970 OnImeEventSentForAck(new_info); |
| 996 text_field_is_dirty_ = false; | 971 text_field_is_dirty_ = false; |
| 997 #endif | 972 #endif |
| 998 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); | 973 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); |
| 999 | 974 |
| 1000 text_input_info_ = new_info; | 975 text_input_info_ = new_info; |
| 976 text_input_type_ = new_type; |
| 1001 text_input_mode_ = new_mode; | 977 text_input_mode_ = new_mode; |
| 1002 can_compose_inline_ = new_can_compose_inline; | 978 can_compose_inline_ = new_can_compose_inline; |
| 1003 text_input_flags_ = new_info.flags; | 979 text_input_flags_ = new_info.flags; |
| 1004 } | 980 } |
| 1005 } | 981 } |
| 1006 | 982 |
| 1007 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { | 983 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { |
| 1008 if (owner_delegate_) | 984 if (owner_delegate_) |
| 1009 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event); | 985 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event); |
| 1010 | 986 |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2024 break; | 2000 break; |
| 2025 } | 2001 } |
| 2026 web_screen_info.orientationAngle = screen_info_.orientation_angle; | 2002 web_screen_info.orientationAngle = screen_info_.orientation_angle; |
| 2027 return web_screen_info; | 2003 return web_screen_info; |
| 2028 } | 2004 } |
| 2029 | 2005 |
| 2030 void RenderWidget::resetInputMethod() { | 2006 void RenderWidget::resetInputMethod() { |
| 2031 ImeEventGuard guard(this); | 2007 ImeEventGuard guard(this); |
| 2032 // If the last text input type is not None, then we should finish any | 2008 // If the last text input type is not None, then we should finish any |
| 2033 // ongoing composition regardless of the new text input type. | 2009 // ongoing composition regardless of the new text input type. |
| 2034 if (text_input_info_.type != blink::WebTextInputTypeNone) { | 2010 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
| 2035 // If a composition text exists, then we need to let the browser process | 2011 // If a composition text exists, then we need to let the browser process |
| 2036 // to cancel the input method's ongoing composition session. | 2012 // to cancel the input method's ongoing composition session. |
| 2037 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) | 2013 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) |
| 2038 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 2014 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 2039 } | 2015 } |
| 2040 | 2016 |
| 2041 UpdateCompositionInfo(false /* not an immediate request */); | 2017 UpdateCompositionInfo(false /* not an immediate request */); |
| 2042 } | 2018 } |
| 2043 | 2019 |
| 2044 #if defined(OS_ANDROID) | 2020 #if defined(OS_ANDROID) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2193 bool RenderWidget::isPointerLocked() { | 2169 bool RenderWidget::isPointerLocked() { |
| 2194 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2170 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2195 webwidget_mouse_lock_target_.get()); | 2171 webwidget_mouse_lock_target_.get()); |
| 2196 } | 2172 } |
| 2197 | 2173 |
| 2198 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2174 blink::WebWidget* RenderWidget::GetWebWidget() const { |
| 2199 return webwidget_internal_; | 2175 return webwidget_internal_; |
| 2200 } | 2176 } |
| 2201 | 2177 |
| 2202 } // namespace content | 2178 } // namespace content |
| OLD | NEW |