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

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

Issue 1278593004: Introduce ThreadedInputConnection behind a switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix selection update to be accurate and fix tests Created 4 years, 10 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 <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) 713 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
714 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) 714 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
715 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) 715 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
716 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) 716 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
717 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) 717 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
718 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace) 718 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
719 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, 719 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
720 OnWaitNextFrameForTests) 720 OnWaitNextFrameForTests)
721 #if defined(OS_ANDROID) 721 #if defined(OS_ANDROID)
722 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) 722 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
723 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
724 OnRequestTextInputStateUpdate)
723 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) 725 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
724 #endif 726 #endif
725 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) 727 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
726 IPC_MESSAGE_UNHANDLED(handled = false) 728 IPC_MESSAGE_UNHANDLED(handled = false)
727 IPC_END_MESSAGE_MAP() 729 IPC_END_MESSAGE_MAP()
728 return handled; 730 return handled;
729 } 731 }
730 732
731 bool RenderWidget::Send(IPC::Message* message) { 733 bool RenderWidget::Send(IPC::Message* message) {
732 // Don't send any messages after the browser has told us to close, and filter 734 // Don't send any messages after the browser has told us to close, and filter
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 if (IsDateTimeInput(new_type)) 1299 if (IsDateTimeInput(new_type))
1298 return; // Not considered as a text input field in WebKit/Chromium. 1300 return; // Not considered as a text input field in WebKit/Chromium.
1299 1301
1300 blink::WebTextInputInfo new_info; 1302 blink::WebTextInputInfo new_info;
1301 if (webwidget_) 1303 if (webwidget_)
1302 new_info = webwidget_->textInputInfo(); 1304 new_info = webwidget_->textInputInfo();
1303 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 1305 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1304 1306
1305 bool new_can_compose_inline = CanComposeInline(); 1307 bool new_can_compose_inline = CanComposeInline();
1306 1308
1309 bool use_ime_thread = true;
1310 #if defined(OS_ANDROID)
1311 use_ime_thread = base::CommandLine::ForCurrentProcess()->HasSwitch(
1312 switches::kUseImeThread);
1313 #endif
1314
1307 // Only sends text input params if they are changed or if the ime should be 1315 // Only sends text input params if they are changed or if the ime should be
1308 // shown. 1316 // shown.
1309 if (show_ime == ShowIme::IF_NEEDED || 1317 if (show_ime == ShowIme::IF_NEEDED ||
1318 (use_ime_thread && change_source == ChangeSource::FROM_IME) ||
1310 (text_input_type_ != new_type || text_input_mode_ != new_mode || 1319 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1311 text_input_info_ != new_info || 1320 text_input_info_ != new_info ||
1312 can_compose_inline_ != new_can_compose_inline) 1321 can_compose_inline_ != new_can_compose_inline)
1313 #if defined(OS_ANDROID) 1322 #if defined(OS_ANDROID)
1314 || text_field_is_dirty_ 1323 || text_field_is_dirty_
1315 #endif 1324 #endif
1316 ) { 1325 ) {
1317 ViewHostMsg_TextInputState_Params params; 1326 ViewHostMsg_TextInputState_Params params;
1318 params.type = new_type; 1327 params.type = new_type;
1319 params.mode = new_mode; 1328 params.mode = new_mode;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 1816
1808 #if defined(OS_ANDROID) 1817 #if defined(OS_ANDROID)
1809 void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) { 1818 void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1810 text_input_info_history_.push_back(info); 1819 text_input_info_history_.push_back(info);
1811 } 1820 }
1812 1821
1813 void RenderWidget::OnImeEventAck() { 1822 void RenderWidget::OnImeEventAck() {
1814 DCHECK_GE(text_input_info_history_.size(), 1u); 1823 DCHECK_GE(text_input_info_history_.size(), 1u);
1815 text_input_info_history_.pop_front(); 1824 text_input_info_history_.pop_front();
1816 } 1825 }
1826
1827 void RenderWidget::OnRequestTextInputStateUpdate() {
1828 DCHECK(!ime_event_guard_);
1829 UpdateSelectionBounds();
1830 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1831 }
1817 #endif 1832 #endif
1818 1833
1819 bool RenderWidget::ShouldHandleImeEvent() { 1834 bool RenderWidget::ShouldHandleImeEvent() {
1820 #if defined(OS_ANDROID) 1835 #if defined(OS_ANDROID)
1821 if (!webwidget_) 1836 if (!webwidget_)
1822 return false; 1837 return false;
1838 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1839 switches::kUseImeThread))
1840 return true;
1823 1841
1824 // We cannot handle IME events if there is any chance that the event we are 1842 // We cannot handle IME events if there is any chance that the event we are
1825 // receiving here from the browser is based on the state that is different 1843 // receiving here from the browser is based on the state that is different
1826 // from our current one as indicated by |text_input_info_|. 1844 // from our current one as indicated by |text_input_info_|.
1827 // The states the browser might be in are: 1845 // The states the browser might be in are:
1828 // text_input_info_history_[0] - current state ack'd by browser 1846 // text_input_info_history_[0] - current state ack'd by browser
1829 // text_input_info_history_[1...N] - pending state changes 1847 // text_input_info_history_[1...N] - pending state changes
1830 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { 1848 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1831 if (text_input_info_history_[i] != text_input_info_) 1849 if (text_input_info_history_[i] != text_input_info_)
1832 return false; 1850 return false;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 } 1923 }
1906 1924
1907 void RenderWidget::set_next_paint_is_resize_ack() { 1925 void RenderWidget::set_next_paint_is_resize_ack() {
1908 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; 1926 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
1909 } 1927 }
1910 1928
1911 void RenderWidget::set_next_paint_is_repaint_ack() { 1929 void RenderWidget::set_next_paint_is_repaint_ack() {
1912 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; 1930 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
1913 } 1931 }
1914 1932
1933 bool RenderWidget::IsFromImeDefault() {
1934 #if defined(OS_ANDROID)
1935 // When ChromiumInputConnection is used, we want to make sure that FROM_IME
1936 // is set only for OnRequestTextInputStateUpdate() so that we can distinguish
1937 // it from other updates so that we can wait for it safely.
1938 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
1939 switches::kUseImeThread);
1940 #else
1941 return false;
1942 #endif
1943 }
1944
1915 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { 1945 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1916 if (!ime_event_guard_) 1946 if (!ime_event_guard_)
1917 ime_event_guard_ = guard; 1947 ime_event_guard_ = guard;
1918 } 1948 }
1919 1949
1920 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { 1950 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1921 if (ime_event_guard_ != guard) { 1951 if (ime_event_guard_ != guard) {
1922 #if defined(OS_ANDROID) 1952 #if defined(OS_ANDROID)
1923 // In case a from-IME event (e.g. touch) ends up in not-from-IME event 1953 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1924 // (e.g. long press gesture), we want to treat it as not-from-IME event 1954 // (e.g. long press gesture), we want to treat it as not-from-IME event
1925 // so that AdapterInputConnection can make changes to its Editable model. 1955 // so that ReplicaInputConnection can make changes to its Editable model.
1926 // Therefore, we want to mark this text state update as 'from IME' only 1956 // Therefore, we want to mark this text state update as 'from IME' only
1927 // when all the nested events are all originating from IME. 1957 // when all the nested events are all originating from IME.
1928 ime_event_guard_->set_from_ime( 1958 ime_event_guard_->set_from_ime(
1929 ime_event_guard_->from_ime() && guard->from_ime()); 1959 ime_event_guard_->from_ime() && guard->from_ime());
1930 #endif 1960 #endif
1931 return; 1961 return;
1932 } 1962 }
1933 ime_event_guard_ = nullptr; 1963 ime_event_guard_ = nullptr;
1934 1964
1935 // While handling an ime event, text input state and selection bounds updates 1965 // While handling an ime event, text input state and selection bounds updates
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart) 2230 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
2201 return; 2231 return;
2202 2232
2203 content::TouchAction content_touch_action = 2233 content::TouchAction content_touch_action =
2204 static_cast<content::TouchAction>(web_touch_action); 2234 static_cast<content::TouchAction>(web_touch_action);
2205 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); 2235 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2206 } 2236 }
2207 2237
2208 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { 2238 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2209 #if defined(OS_ANDROID) 2239 #if defined(OS_ANDROID)
2210 text_field_is_dirty_ = true; 2240 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
2241 switches::kUseImeThread))
2242 text_field_is_dirty_ = true;
2211 #endif 2243 #endif
2212 } 2244 }
2213 2245
2214 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 2246 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
2215 RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) { 2247 RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) {
2216 // Explicitly disable antialiasing for the compositor. As of the time of 2248 // Explicitly disable antialiasing for the compositor. As of the time of
2217 // this writing, the only platform that supported antialiasing for the 2249 // this writing, the only platform that supported antialiasing for the
2218 // compositor was Mac OS X, because the on-screen OpenGL context creation 2250 // compositor was Mac OS X, because the on-screen OpenGL context creation
2219 // code paths on Windows and Linux didn't yet have multisampling support. 2251 // code paths on Windows and Linux didn't yet have multisampling support.
2220 // Mac OS X essentially always behaves as though it's rendering offscreen. 2252 // Mac OS X essentially always behaves as though it's rendering offscreen.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 video_hole_frames_.RemoveObserver(frame); 2326 video_hole_frames_.RemoveObserver(frame);
2295 } 2327 }
2296 #endif // defined(VIDEO_HOLE) 2328 #endif // defined(VIDEO_HOLE)
2297 2329
2298 void RenderWidget::OnWaitNextFrameForTests(int routing_id) { 2330 void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2299 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id), 2331 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2300 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); 2332 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2301 } 2333 }
2302 2334
2303 } // namespace content 2335 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698