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

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

Issue 2422663002: Define WebTextInputMode as a enum in the public API. (Closed)
Patch Set: Rebase 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') | third_party/WebKit/Source/core/BUILD.gn » ('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 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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 ime_event_guard_->set_show_ime(true); 897 ime_event_guard_->set_show_ime(true);
925 } 898 }
926 return; 899 return;
927 } 900 }
928 901
929 if (!GetWebWidget()) 902 if (!GetWebWidget())
930 return; 903 return;
931 904
932 blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo(); 905 blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo();
933 906
934 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 907 const ui::TextInputMode new_mode =
908 ConvertWebTextInputMode(new_info.inputMode);
935 909
936 bool new_can_compose_inline = CanComposeInline(); 910 bool new_can_compose_inline = CanComposeInline();
937 911
938 // Only sends text input params if they are changed or if the ime should be 912 // Only sends text input params if they are changed or if the ime should be
939 // shown. 913 // shown.
940 if (show_ime == ShowIme::IF_NEEDED || 914 if (show_ime == ShowIme::IF_NEEDED ||
941 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || 915 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
942 (text_input_mode_ != new_mode || text_input_info_ != new_info || 916 (text_input_mode_ != new_mode || text_input_info_ != new_info ||
943 can_compose_inline_ != new_can_compose_inline) 917 can_compose_inline_ != new_can_compose_inline)
944 #if defined(OS_ANDROID) 918 #if defined(OS_ANDROID)
945 || text_field_is_dirty_ 919 || text_field_is_dirty_
946 #endif 920 #endif
947 ) { 921 ) {
948 TextInputState params; 922 TextInputState params;
949 params.type = WebKitToUiTextInputType(new_info.type); 923 params.type = ConvertWebTextInputType(new_info.type);
950 params.mode = new_mode; 924 params.mode = new_mode;
951 params.flags = new_info.flags; 925 params.flags = new_info.flags;
952 params.value = new_info.value.utf8(); 926 params.value = new_info.value.utf8();
953 params.selection_start = new_info.selectionStart; 927 params.selection_start = new_info.selectionStart;
954 params.selection_end = new_info.selectionEnd; 928 params.selection_end = new_info.selectionEnd;
955 params.composition_start = new_info.compositionStart; 929 params.composition_start = new_info.compositionStart;
956 params.composition_end = new_info.compositionEnd; 930 params.composition_end = new_info.compositionEnd;
957 params.can_compose_inline = new_can_compose_inline; 931 params.can_compose_inline = new_can_compose_inline;
958 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); 932 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
959 #if defined(USE_AURA) 933 #if defined(USE_AURA)
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 void RenderWidget::showImeIfNeeded() { 1509 void RenderWidget::showImeIfNeeded() {
1536 OnShowImeIfNeeded(); 1510 OnShowImeIfNeeded();
1537 } 1511 }
1538 1512
1539 ui::TextInputType RenderWidget::GetTextInputType() { 1513 ui::TextInputType RenderWidget::GetTextInputType() {
1540 #if defined(ENABLE_PLUGINS) 1514 #if defined(ENABLE_PLUGINS)
1541 if (focused_pepper_plugin_) 1515 if (focused_pepper_plugin_)
1542 return focused_pepper_plugin_->text_input_type(); 1516 return focused_pepper_plugin_->text_input_type();
1543 #endif 1517 #endif
1544 if (GetWebWidget()) 1518 if (GetWebWidget())
1545 return WebKitToUiTextInputType(GetWebWidget()->textInputType()); 1519 return ConvertWebTextInputType(GetWebWidget()->textInputType());
1546 return ui::TEXT_INPUT_TYPE_NONE; 1520 return ui::TEXT_INPUT_TYPE_NONE;
1547 } 1521 }
1548 1522
1549 void RenderWidget::UpdateCompositionInfo(bool immediate_request) { 1523 void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1550 if (!monitor_composition_info_ && !immediate_request) 1524 if (!monitor_composition_info_ && !immediate_request)
1551 return; // Do not calculate composition info if not requested. 1525 return; // Do not calculate composition info if not requested.
1552 1526
1553 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); 1527 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1554 gfx::Range range; 1528 gfx::Range range;
1555 std::vector<gfx::Rect> character_bounds; 1529 std::vector<gfx::Rect> character_bounds;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 window_screen_rect_ = new_pos; 1834 window_screen_rect_ = new_pos;
1861 } 1835 }
1862 1836
1863 AutoResizeCompositor(); 1837 AutoResizeCompositor();
1864 1838
1865 if (!resizing_mode_selector_->is_synchronous_mode()) 1839 if (!resizing_mode_selector_->is_synchronous_mode())
1866 need_update_rect_for_auto_resize_ = true; 1840 need_update_rect_for_auto_resize_ = true;
1867 } 1841 }
1868 } 1842 }
1869 1843
1870 // Check blink::WebTextInputType and ui::TextInputType is kept in sync.
1871 STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1872 STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1873 STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1874 ui::TEXT_INPUT_TYPE_PASSWORD);
1875 STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1876 STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1877 STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1878 STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1879 ui::TEXT_INPUT_TYPE_TELEPHONE);
1880 STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1881 STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1882 STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1883 ui::TEXT_INPUT_TYPE_DATE_TIME);
1884 STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1885 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1886 STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1887 STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1888 STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1889 STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1890 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1891 STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1892 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1893 STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1894 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
1895
1896 ui::TextInputType RenderWidget::WebKitToUiTextInputType(
1897 blink::WebTextInputType type) {
1898 // Check the type is in the range representable by ui::TextInputType.
1899 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1900 "blink::WebTextInputType and ui::TextInputType not synchronized";
1901 return static_cast<ui::TextInputType>(type);
1902 }
1903
1904 void RenderWidget::GetCompositionCharacterBounds( 1844 void RenderWidget::GetCompositionCharacterBounds(
1905 std::vector<gfx::Rect>* bounds) { 1845 std::vector<gfx::Rect>* bounds) {
1906 DCHECK(bounds); 1846 DCHECK(bounds);
1907 bounds->clear(); 1847 bounds->clear();
1908 1848
1909 #if defined(ENABLE_PLUGINS) 1849 #if defined(ENABLE_PLUGINS)
1910 if (focused_pepper_plugin_) 1850 if (focused_pepper_plugin_)
1911 return; 1851 return;
1912 #endif 1852 #endif
1913 1853
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 void RenderWidget::IgnoreAckForMouseMoveFromDebugger() { 2019 void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
2080 input_handler_->IgnoreAckForMouseMoveFromDebugger(); 2020 input_handler_->IgnoreAckForMouseMoveFromDebugger();
2081 } 2021 }
2082 2022
2083 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { 2023 void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2084 if (render_widget_scheduling_state_) 2024 if (render_widget_scheduling_state_)
2085 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers); 2025 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
2086 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); 2026 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2087 } 2027 }
2088 2028
2089 // Check blink::WebTouchAction and content::TouchAction is kept in sync.
2090 STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2091 STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2092 STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2093 STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2094 STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2095 STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2096 STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2097 STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2098 STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2099 STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2100 TOUCH_ACTION_MANIPULATION);
2101 STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2102 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2103 STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
2104
2105 void RenderWidget::setTouchAction( 2029 void RenderWidget::setTouchAction(
2106 blink::WebTouchAction web_touch_action) { 2030 blink::WebTouchAction web_touch_action) {
2107 2031
2108 // Ignore setTouchAction calls that result from synthetic touch events (eg. 2032 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2109 // when blink is emulating touch with mouse). 2033 // when blink is emulating touch with mouse).
2110 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart) 2034 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
2111 return; 2035 return;
2112 2036
2113 content::TouchAction content_touch_action = 2037 content::TouchAction content_touch_action =
2114 static_cast<content::TouchAction>(web_touch_action); 2038 static_cast<content::TouchAction>(web_touch_action);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 bool RenderWidget::isPointerLocked() { 2085 bool RenderWidget::isPointerLocked() {
2162 return mouse_lock_dispatcher_->IsMouseLockedTo( 2086 return mouse_lock_dispatcher_->IsMouseLockedTo(
2163 webwidget_mouse_lock_target_.get()); 2087 webwidget_mouse_lock_target_.get());
2164 } 2088 }
2165 2089
2166 blink::WebWidget* RenderWidget::GetWebWidget() const { 2090 blink::WebWidget* RenderWidget::GetWebWidget() const {
2167 return webwidget_internal_; 2091 return webwidget_internal_;
2168 } 2092 }
2169 2093
2170 } // namespace content 2094 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | third_party/WebKit/Source/core/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698