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

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

Issue 2422663002: Define WebTextInputMode as a enum in the public API. (Closed)
Patch Set: git cl format 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 unified diff | Download patch
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 using blink::WebPopupType; 116 using blink::WebPopupType;
117 using blink::WebRange; 117 using blink::WebRange;
118 using blink::WebRect; 118 using blink::WebRect;
119 using blink::WebSize; 119 using blink::WebSize;
120 using blink::WebTextDirection; 120 using blink::WebTextDirection;
121 using blink::WebTouchEvent; 121 using blink::WebTouchEvent;
122 using blink::WebTouchPoint; 122 using blink::WebTouchPoint;
123 using blink::WebVector; 123 using blink::WebVector;
124 using blink::WebWidget; 124 using blink::WebWidget;
125 125
126 #define STATIC_ASSERT_ENUM(a, b) \
127 static_assert(static_cast<int>(a) == static_cast<int>(b), \
128 "mismatching enums: " #a)
129
130 namespace { 126 namespace {
131 127
132 typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; 128 typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
133 129
134 class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget { 130 class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
135 public: 131 public:
136 explicit WebWidgetLockTarget(blink::WebWidget* webwidget) 132 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
137 : webwidget_(webwidget) {} 133 : webwidget_(webwidget) {}
138 134
139 void OnLockMouseACK(bool succeeded) override { 135 void OnLockMouseACK(bool succeeded) override {
140 if (succeeded) 136 if (succeeded)
141 webwidget_->didAcquirePointerLock(); 137 webwidget_->didAcquirePointerLock();
142 else 138 else
143 webwidget_->didNotAcquirePointerLock(); 139 webwidget_->didNotAcquirePointerLock();
144 } 140 }
145 141
146 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); } 142 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
147 143
148 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override { 144 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
149 // The WebWidget handles mouse lock in Blink's handleInputEvent(). 145 // The WebWidget handles mouse lock in Blink's handleInputEvent().
150 return false; 146 return false;
151 } 147 }
152 148
153 private: 149 private:
154 blink::WebWidget* webwidget_; 150 blink::WebWidget* webwidget_;
155 }; 151 };
156 152
157 class TextInputModeMapSingleton {
158 public:
159 static TextInputModeMapSingleton* GetInstance() {
160 return base::Singleton<TextInputModeMapSingleton>::get();
161 }
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;
192 }
193
194 content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate( 153 content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
195 content::RenderWidget* widget) { 154 content::RenderWidget* widget) {
196 #if defined(USE_AURA) 155 #if defined(USE_AURA)
197 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess(); 156 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
198 if (content::ServiceManagerConnection::GetForProcess() && 157 if (content::ServiceManagerConnection::GetForProcess() &&
199 cmdline.HasSwitch(switches::kUseMusInRenderer)) { 158 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
200 return content::RenderWidgetMusConnection::GetOrCreate( 159 return content::RenderWidgetMusConnection::GetOrCreate(
201 widget->routing_id()); 160 widget->routing_id());
202 } 161 }
203 #endif 162 #endif
204 // If we don't have a connection to the Service Manager, then we want to route 163 // If we don't have a connection to the Service Manager, then we want to route
205 // IPCs back to the browser process rather than Mus so we use the |widget| as 164 // IPCs back to the browser process rather than Mus so we use the |widget| as
206 // the RenderWidgetInputHandlerDelegate. 165 // the RenderWidgetInputHandlerDelegate.
207 return widget; 166 return widget;
208 } 167 }
209 168
210 content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget = 169 content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
211 nullptr; 170 nullptr;
212 171
213 content::RenderWidget::RenderWidgetInitializedCallback 172 content::RenderWidget::RenderWidgetInitializedCallback
214 g_render_widget_initialized = nullptr; 173 g_render_widget_initialized = nullptr;
215 174
175 ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
176 // Check the type is in the range representable by ui::TextInputType.
177 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
178 << "blink::WebTextInputType and ui::TextInputType not synchronized";
179 return static_cast<ui::TextInputType>(type);
180 }
181
182 ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
183 // Check the mode is in the range representable by ui::TextInputMode.
184 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
185 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
186 return static_cast<ui::TextInputMode>(mode);
187 }
188
216 } // namespace 189 } // namespace
217 190
218 namespace content { 191 namespace content {
219 192
220 // RenderWidget --------------------------------------------------------------- 193 // RenderWidget ---------------------------------------------------------------
221 194
222 RenderWidget::RenderWidget(CompositorDependencies* compositor_deps, 195 RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
223 blink::WebPopupType popup_type, 196 blink::WebPopupType popup_type,
224 const ScreenInfo& screen_info, 197 const ScreenInfo& screen_info,
225 bool swapped_out, 198 bool swapped_out,
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 ime_event_guard_->set_show_ime(true); 914 ime_event_guard_->set_show_ime(true);
942 } 915 }
943 return; 916 return;
944 } 917 }
945 918
946 if (!GetWebWidget()) 919 if (!GetWebWidget())
947 return; 920 return;
948 921
949 blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo(); 922 blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo();
950 923
951 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 924 const ui::TextInputMode new_mode =
925 ConvertWebTextInputMode(new_info.inputMode);
952 926
953 bool new_can_compose_inline = CanComposeInline(); 927 bool new_can_compose_inline = CanComposeInline();
954 928
955 // Only sends text input params if they are changed or if the ime should be 929 // Only sends text input params if they are changed or if the ime should be
956 // shown. 930 // shown.
957 if (show_ime == ShowIme::IF_NEEDED || 931 if (show_ime == ShowIme::IF_NEEDED ||
958 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || 932 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
959 (text_input_mode_ != new_mode || text_input_info_ != new_info || 933 (text_input_mode_ != new_mode || text_input_info_ != new_info ||
960 can_compose_inline_ != new_can_compose_inline) 934 can_compose_inline_ != new_can_compose_inline)
961 #if defined(OS_ANDROID) 935 #if defined(OS_ANDROID)
962 || text_field_is_dirty_ 936 || text_field_is_dirty_
963 #endif 937 #endif
964 ) { 938 ) {
965 TextInputState params; 939 TextInputState params;
966 params.type = WebKitToUiTextInputType(new_info.type); 940 params.type = ConvertWebTextInputType(new_info.type);
967 params.mode = new_mode; 941 params.mode = new_mode;
968 params.flags = new_info.flags; 942 params.flags = new_info.flags;
969 params.value = new_info.value.utf8(); 943 params.value = new_info.value.utf8();
970 params.selection_start = new_info.selectionStart; 944 params.selection_start = new_info.selectionStart;
971 params.selection_end = new_info.selectionEnd; 945 params.selection_end = new_info.selectionEnd;
972 params.composition_start = new_info.compositionStart; 946 params.composition_start = new_info.compositionStart;
973 params.composition_end = new_info.compositionEnd; 947 params.composition_end = new_info.compositionEnd;
974 params.can_compose_inline = new_can_compose_inline; 948 params.can_compose_inline = new_can_compose_inline;
975 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); 949 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
976 #if defined(USE_AURA) 950 #if defined(USE_AURA)
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 void RenderWidget::showImeIfNeeded() { 1526 void RenderWidget::showImeIfNeeded() {
1553 OnShowImeIfNeeded(); 1527 OnShowImeIfNeeded();
1554 } 1528 }
1555 1529
1556 ui::TextInputType RenderWidget::GetTextInputType() { 1530 ui::TextInputType RenderWidget::GetTextInputType() {
1557 #if defined(ENABLE_PLUGINS) 1531 #if defined(ENABLE_PLUGINS)
1558 if (focused_pepper_plugin_) 1532 if (focused_pepper_plugin_)
1559 return focused_pepper_plugin_->text_input_type(); 1533 return focused_pepper_plugin_->text_input_type();
1560 #endif 1534 #endif
1561 if (GetWebWidget()) 1535 if (GetWebWidget())
1562 return WebKitToUiTextInputType(GetWebWidget()->textInputType()); 1536 return ConvertWebTextInputType(GetWebWidget()->textInputType());
1563 return ui::TEXT_INPUT_TYPE_NONE; 1537 return ui::TEXT_INPUT_TYPE_NONE;
1564 } 1538 }
1565 1539
1566 void RenderWidget::UpdateCompositionInfo(bool immediate_request) { 1540 void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1567 if (!monitor_composition_info_ && !immediate_request) 1541 if (!monitor_composition_info_ && !immediate_request)
1568 return; // Do not calculate composition info if not requested. 1542 return; // Do not calculate composition info if not requested.
1569 1543
1570 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); 1544 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1571 gfx::Range range; 1545 gfx::Range range;
1572 std::vector<gfx::Rect> character_bounds; 1546 std::vector<gfx::Rect> character_bounds;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 window_screen_rect_ = new_pos; 1851 window_screen_rect_ = new_pos;
1878 } 1852 }
1879 1853
1880 AutoResizeCompositor(); 1854 AutoResizeCompositor();
1881 1855
1882 if (!resizing_mode_selector_->is_synchronous_mode()) 1856 if (!resizing_mode_selector_->is_synchronous_mode())
1883 need_update_rect_for_auto_resize_ = true; 1857 need_update_rect_for_auto_resize_ = true;
1884 } 1858 }
1885 } 1859 }
1886 1860
1887 // Check blink::WebTextInputType and ui::TextInputType is kept in sync.
1888 STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1889 STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1890 STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1891 ui::TEXT_INPUT_TYPE_PASSWORD);
1892 STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1893 STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1894 STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1895 STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1896 ui::TEXT_INPUT_TYPE_TELEPHONE);
1897 STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1898 STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1899 STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1900 ui::TEXT_INPUT_TYPE_DATE_TIME);
1901 STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1902 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1903 STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1904 STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1905 STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1906 STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1907 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1908 STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1909 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1910 STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1911 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
1912
1913 ui::TextInputType RenderWidget::WebKitToUiTextInputType(
1914 blink::WebTextInputType type) {
1915 // Check the type is in the range representable by ui::TextInputType.
1916 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1917 "blink::WebTextInputType and ui::TextInputType not synchronized";
1918 return static_cast<ui::TextInputType>(type);
1919 }
1920
1921 void RenderWidget::GetCompositionCharacterBounds( 1861 void RenderWidget::GetCompositionCharacterBounds(
1922 std::vector<gfx::Rect>* bounds) { 1862 std::vector<gfx::Rect>* bounds) {
1923 DCHECK(bounds); 1863 DCHECK(bounds);
1924 bounds->clear(); 1864 bounds->clear();
1925 1865
1926 #if defined(ENABLE_PLUGINS) 1866 #if defined(ENABLE_PLUGINS)
1927 if (focused_pepper_plugin_) 1867 if (focused_pepper_plugin_)
1928 return; 1868 return;
1929 #endif 1869 #endif
1930 1870
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 void RenderWidget::IgnoreAckForMouseMoveFromDebugger() { 2036 void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
2097 input_handler_->IgnoreAckForMouseMoveFromDebugger(); 2037 input_handler_->IgnoreAckForMouseMoveFromDebugger();
2098 } 2038 }
2099 2039
2100 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { 2040 void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2101 if (render_widget_scheduling_state_) 2041 if (render_widget_scheduling_state_)
2102 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers); 2042 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
2103 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); 2043 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2104 } 2044 }
2105 2045
2106 // Check blink::WebTouchAction and content::TouchAction is kept in sync.
2107 STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2108 STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2109 STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2110 STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2111 STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2112 STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2113 STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2114 STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2115 STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2116 STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2117 TOUCH_ACTION_MANIPULATION);
2118 STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2119 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2120 STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
2121
2122 void RenderWidget::setTouchAction( 2046 void RenderWidget::setTouchAction(
2123 blink::WebTouchAction web_touch_action) { 2047 blink::WebTouchAction web_touch_action) {
2124 2048
2125 // Ignore setTouchAction calls that result from synthetic touch events (eg. 2049 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2126 // when blink is emulating touch with mouse). 2050 // when blink is emulating touch with mouse).
2127 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart) 2051 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
2128 return; 2052 return;
2129 2053
2130 content::TouchAction content_touch_action = 2054 content::TouchAction content_touch_action =
2131 static_cast<content::TouchAction>(web_touch_action); 2055 static_cast<content::TouchAction>(web_touch_action);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 bool RenderWidget::isPointerLocked() { 2102 bool RenderWidget::isPointerLocked() {
2179 return mouse_lock_dispatcher_->IsMouseLockedTo( 2103 return mouse_lock_dispatcher_->IsMouseLockedTo(
2180 webwidget_mouse_lock_target_.get()); 2104 webwidget_mouse_lock_target_.get());
2181 } 2105 }
2182 2106
2183 blink::WebWidget* RenderWidget::GetWebWidget() const { 2107 blink::WebWidget* RenderWidget::GetWebWidget() const {
2184 return webwidget_internal_; 2108 return webwidget_internal_;
2185 } 2109 }
2186 2110
2187 } // namespace content 2111 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698