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

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: Created 5 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
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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect) 736 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
737 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) 737 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
738 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) 738 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
739 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) 739 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
740 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) 740 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
741 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) 741 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
742 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) 742 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
743 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace) 743 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
744 #if defined(OS_ANDROID) 744 #if defined(OS_ANDROID)
745 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) 745 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
746 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
747 OnRequestTextInputStateUpdate)
746 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) 748 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
747 #endif 749 #endif
748 IPC_MESSAGE_UNHANDLED(handled = false) 750 IPC_MESSAGE_UNHANDLED(handled = false)
749 IPC_END_MESSAGE_MAP() 751 IPC_END_MESSAGE_MAP()
750 return handled; 752 return handled;
751 } 753 }
752 754
753 bool RenderWidget::Send(IPC::Message* message) { 755 bool RenderWidget::Send(IPC::Message* message) {
754 // Don't send any messages after the browser has told us to close, and filter 756 // Don't send any messages after the browser has told us to close, and filter
755 // most outgoing messages while swapped out. 757 // most outgoing messages while swapped out.
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 scoped_ptr<ImeEventGuard> ime_event_guard_maybe; 1109 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1108 if (WebInputEvent::isKeyboardEventType(input_event->type)) { 1110 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1109 const WebKeyboardEvent& key_event = 1111 const WebKeyboardEvent& key_event =
1110 *static_cast<const WebKeyboardEvent*>(input_event); 1112 *static_cast<const WebKeyboardEvent*>(input_event);
1111 // Some keys are special and it's essential that no events get blocked. 1113 // Some keys are special and it's essential that no events get blocked.
1112 if (key_event.nativeKeyCode != AKEYCODE_TAB && 1114 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
1113 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER && 1115 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1114 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT && 1116 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1115 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT && 1117 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1116 key_event.nativeKeyCode != AKEYCODE_DPAD_UP && 1118 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1117 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN) 1119 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN &&
1120 // We do not need to block additionally for composition key code.
1121 key_event.nativeKeyCode != 229) {
1122 LOG(ERROR) << "XXX OnHandleInputEvent: " << key_event.nativeKeyCode;
1118 ime_event_guard_maybe.reset(new ImeEventGuard(this)); 1123 ime_event_guard_maybe.reset(new ImeEventGuard(this));
1124 }
1119 } 1125 }
1120 #endif 1126 #endif
1121 1127
1122 base::TimeTicks start_time; 1128 base::TimeTicks start_time;
1123 if (base::TimeTicks::IsHighResolution()) 1129 if (base::TimeTicks::IsHighResolution())
1124 start_time = base::TimeTicks::Now(); 1130 start_time = base::TimeTicks::Now();
1125 1131
1126 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent", 1132 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
1127 "event", WebInputEventTraits::GetName(input_event->type)); 1133 "event", WebInputEventTraits::GetName(input_event->type));
1128 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); 1134 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 WebRect RenderWidget::windowResizerRect() { 1687 WebRect RenderWidget::windowResizerRect() {
1682 return resizer_rect_; 1688 return resizer_rect_;
1683 } 1689 }
1684 1690
1685 void RenderWidget::OnImeSetComposition( 1691 void RenderWidget::OnImeSetComposition(
1686 const base::string16& text, 1692 const base::string16& text,
1687 const std::vector<WebCompositionUnderline>& underlines, 1693 const std::vector<WebCompositionUnderline>& underlines,
1688 int selection_start, int selection_end) { 1694 int selection_start, int selection_end) {
1689 if (!ShouldHandleImeEvent()) 1695 if (!ShouldHandleImeEvent())
1690 return; 1696 return;
1697 LOG(ERROR) << "XXX OnImeSetComposition";
1691 ImeEventGuard guard(this); 1698 ImeEventGuard guard(this);
1692 if (!webwidget_->setComposition( 1699 if (!webwidget_->setComposition(
1693 text, WebVector<WebCompositionUnderline>(underlines), 1700 text, WebVector<WebCompositionUnderline>(underlines),
1694 selection_start, selection_end)) { 1701 selection_start, selection_end)) {
1695 // If we failed to set the composition text, then we need to let the browser 1702 // If we failed to set the composition text, then we need to let the browser
1696 // process to cancel the input method's ongoing composition session, to make 1703 // process to cancel the input method's ongoing composition session, to make
1697 // sure we are in a consistent state. 1704 // sure we are in a consistent state.
1698 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1705 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1699 } 1706 }
1700 UpdateCompositionInfo(true); 1707 UpdateCompositionInfo(true);
1701 } 1708 }
1702 1709
1703 void RenderWidget::OnImeConfirmComposition(const base::string16& text, 1710 void RenderWidget::OnImeConfirmComposition(const base::string16& text,
1704 const gfx::Range& replacement_range, 1711 const gfx::Range& replacement_range,
1705 bool keep_selection) { 1712 bool keep_selection) {
1706 if (!ShouldHandleImeEvent()) 1713 if (!ShouldHandleImeEvent())
1707 return; 1714 return;
1715 LOG(ERROR) << "XXX OnImeConfirmComposition";
1708 ImeEventGuard guard(this); 1716 ImeEventGuard guard(this);
1709 handling_input_event_ = true; 1717 handling_input_event_ = true;
1710 if (text.length()) 1718 if (text.length())
1711 webwidget_->confirmComposition(text); 1719 webwidget_->confirmComposition(text);
1712 else if (keep_selection) 1720 else if (keep_selection)
1713 webwidget_->confirmComposition(WebWidget::KeepSelection); 1721 webwidget_->confirmComposition(WebWidget::KeepSelection);
1714 else 1722 else
1715 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); 1723 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
1716 handling_input_event_ = false; 1724 handling_input_event_ = false;
1717 UpdateCompositionInfo(true); 1725 UpdateCompositionInfo(true);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 1789
1782 #if defined(OS_ANDROID) 1790 #if defined(OS_ANDROID)
1783 void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) { 1791 void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1784 text_input_info_history_.push_back(info); 1792 text_input_info_history_.push_back(info);
1785 } 1793 }
1786 1794
1787 void RenderWidget::OnImeEventAck() { 1795 void RenderWidget::OnImeEventAck() {
1788 DCHECK_GE(text_input_info_history_.size(), 1u); 1796 DCHECK_GE(text_input_info_history_.size(), 1u);
1789 text_input_info_history_.pop_front(); 1797 text_input_info_history_.pop_front();
1790 } 1798 }
1799
1800 void RenderWidget::OnRequestTextInputStateUpdate() {
1801 LOG(ERROR) << "XXX OnRequestTextInputStateUpdate";
1802 ImeEventGuard guard(this);
1803 }
1791 #endif 1804 #endif
1792 1805
1793 bool RenderWidget::ShouldHandleImeEvent() { 1806 bool RenderWidget::ShouldHandleImeEvent() {
1794 #if defined(OS_ANDROID) 1807 #if defined(OS_ANDROID)
1795 if (!webwidget_) 1808 if (!webwidget_)
1796 return false; 1809 return false;
1810 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1811 switches::kUseImeThread))
1812 return true;
1797 1813
1798 // We cannot handle IME events if there is any chance that the event we are 1814 // We cannot handle IME events if there is any chance that the event we are
1799 // receiving here from the browser is based on the state that is different 1815 // receiving here from the browser is based on the state that is different
1800 // from our current one as indicated by |text_input_info_|. 1816 // from our current one as indicated by |text_input_info_|.
1801 // The states the browser might be in are: 1817 // The states the browser might be in are:
1802 // text_input_info_history_[0] - current state ack'd by browser 1818 // text_input_info_history_[0] - current state ack'd by browser
1803 // text_input_info_history_[1...N] - pending state changes 1819 // text_input_info_history_[1...N] - pending state changes
1804 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { 1820 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1805 if (text_input_info_history_[i] != text_input_info_) 1821 if (text_input_info_history_[i] != text_input_info_)
1806 return false; 1822 return false;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 1915
1900 static bool IsDateTimeInput(ui::TextInputType type) { 1916 static bool IsDateTimeInput(ui::TextInputType type) {
1901 return type == ui::TEXT_INPUT_TYPE_DATE || 1917 return type == ui::TEXT_INPUT_TYPE_DATE ||
1902 type == ui::TEXT_INPUT_TYPE_DATE_TIME || 1918 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1903 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || 1919 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1904 type == ui::TEXT_INPUT_TYPE_MONTH || 1920 type == ui::TEXT_INPUT_TYPE_MONTH ||
1905 type == ui::TEXT_INPUT_TYPE_TIME || 1921 type == ui::TEXT_INPUT_TYPE_TIME ||
1906 type == ui::TEXT_INPUT_TYPE_WEEK; 1922 type == ui::TEXT_INPUT_TYPE_WEEK;
1907 } 1923 }
1908 1924
1909
1910 void RenderWidget::StartHandlingImeEvent() { 1925 void RenderWidget::StartHandlingImeEvent() {
1911 DCHECK(!handling_ime_event_); 1926 DCHECK(!handling_ime_event_);
1912 handling_ime_event_ = true; 1927 handling_ime_event_ = true;
1913 } 1928 }
1914 1929
1915 void RenderWidget::FinishHandlingImeEvent() { 1930 void RenderWidget::FinishHandlingImeEvent() {
1916 DCHECK(handling_ime_event_); 1931 DCHECK(handling_ime_event_);
1917 handling_ime_event_ = false; 1932 handling_ime_event_ = false;
1918 // While handling an ime event, text input state and selection bounds updates 1933 // While handling an ime event, text input state and selection bounds updates
1919 // are ignored. These must explicitly be updated once finished handling the 1934 // are ignored. These must explicitly be updated once finished handling the
(...skipping 13 matching lines...) Expand all
1933 if (IsDateTimeInput(new_type)) 1948 if (IsDateTimeInput(new_type))
1934 return; // Not considered as a text input field in WebKit/Chromium. 1949 return; // Not considered as a text input field in WebKit/Chromium.
1935 1950
1936 blink::WebTextInputInfo new_info; 1951 blink::WebTextInputInfo new_info;
1937 if (webwidget_) 1952 if (webwidget_)
1938 new_info = webwidget_->textInputInfo(); 1953 new_info = webwidget_->textInputInfo();
1939 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 1954 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1940 1955
1941 bool new_can_compose_inline = CanComposeInline(); 1956 bool new_can_compose_inline = CanComposeInline();
1942 1957
1958 bool use_ime_thread = false;
1959 #if defined(OS_ANDROID)
1960 use_ime_thread = base::CommandLine::ForCurrentProcess()->HasSwitch(
1961 switches::kUseImeThread);
1962 #endif
1963
1943 // Only sends text input params if they are changed or if the ime should be 1964 // Only sends text input params if they are changed or if the ime should be
1944 // shown. 1965 // shown.
1945 if (show_ime == SHOW_IME_IF_NEEDED || 1966 if (show_ime == SHOW_IME_IF_NEEDED ||
1946 (text_input_type_ != new_type || 1967 (use_ime_thread && change_source == FROM_IME) ||
1947 text_input_mode_ != new_mode || 1968 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1948 text_input_info_ != new_info || 1969 text_input_info_ != new_info ||
1949 can_compose_inline_ != new_can_compose_inline) 1970 can_compose_inline_ != new_can_compose_inline)
1950 #if defined(OS_ANDROID) 1971 #if defined(OS_ANDROID)
1951 || text_field_is_dirty_ 1972 || text_field_is_dirty_
1952 #endif 1973 #endif
1953 ) { 1974 ) {
1975 if (change_source == FROM_IME) {
1976 LOG(ERROR) << "cr.Ime UpdateTextInputState FROM_IME";
1977 }
1954 ViewHostMsg_TextInputState_Params params; 1978 ViewHostMsg_TextInputState_Params params;
1955 params.type = new_type; 1979 params.type = new_type;
1956 params.mode = new_mode; 1980 params.mode = new_mode;
1957 params.flags = new_info.flags; 1981 params.flags = new_info.flags;
1958 params.value = new_info.value.utf8(); 1982 params.value = new_info.value.utf8();
1959 params.selection_start = new_info.selectionStart; 1983 params.selection_start = new_info.selectionStart;
1960 params.selection_end = new_info.selectionEnd; 1984 params.selection_end = new_info.selectionEnd;
1961 params.composition_start = new_info.compositionStart; 1985 params.composition_start = new_info.compositionStart;
1962 params.composition_end = new_info.compositionEnd; 1986 params.composition_end = new_info.compositionEnd;
1963 params.can_compose_inline = new_can_compose_inline; 1987 params.can_compose_inline = new_can_compose_inline;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2133 2157
2134 WebScreenInfo RenderWidget::screenInfo() { 2158 WebScreenInfo RenderWidget::screenInfo() {
2135 return screen_info_; 2159 return screen_info_;
2136 } 2160 }
2137 2161
2138 float RenderWidget::deviceScaleFactor() { 2162 float RenderWidget::deviceScaleFactor() {
2139 return device_scale_factor_; 2163 return device_scale_factor_;
2140 } 2164 }
2141 2165
2142 void RenderWidget::resetInputMethod() { 2166 void RenderWidget::resetInputMethod() {
2167 LOG(ERROR) << "XXX resetInputMethod";
2143 ImeEventGuard guard(this); 2168 ImeEventGuard guard(this);
2144 // If the last text input type is not None, then we should finish any 2169 // If the last text input type is not None, then we should finish any
2145 // ongoing composition regardless of the new text input type. 2170 // ongoing composition regardless of the new text input type.
2146 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 2171 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
2147 // If a composition text exists, then we need to let the browser process 2172 // If a composition text exists, then we need to let the browser process
2148 // to cancel the input method's ongoing composition session. 2173 // to cancel the input method's ongoing composition session.
2149 if (webwidget_->confirmComposition()) 2174 if (webwidget_->confirmComposition())
2150 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 2175 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
2151 } 2176 }
2152 2177
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y); 2347 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2323 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM); 2348 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
2324 2349
2325 content::TouchAction content_touch_action = 2350 content::TouchAction content_touch_action =
2326 static_cast<content::TouchAction>(web_touch_action); 2351 static_cast<content::TouchAction>(web_touch_action);
2327 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); 2352 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2328 } 2353 }
2329 2354
2330 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { 2355 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2331 #if defined(OS_ANDROID) 2356 #if defined(OS_ANDROID)
2332 text_field_is_dirty_ = true; 2357 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
2358 switches::kUseImeThread))
2359 text_field_is_dirty_ = true;
2333 #endif 2360 #endif
2334 } 2361 }
2335 2362
2336 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { 2363 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2337 return true; 2364 return true;
2338 } 2365 }
2339 2366
2340 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 2367 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
2341 RenderWidget::CreateGraphicsContext3D(bool compositor) { 2368 RenderWidget::CreateGraphicsContext3D(bool compositor) {
2342 if (!webwidget_) 2369 if (!webwidget_)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { 2457 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2431 video_hole_frames_.AddObserver(frame); 2458 video_hole_frames_.AddObserver(frame);
2432 } 2459 }
2433 2460
2434 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { 2461 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2435 video_hole_frames_.RemoveObserver(frame); 2462 video_hole_frames_.RemoveObserver(frame);
2436 } 2463 }
2437 #endif // defined(VIDEO_HOLE) 2464 #endif // defined(VIDEO_HOLE)
2438 2465
2439 } // namespace content 2466 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698