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

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

Issue 2470713002: [WIP Approach 1] Straighten up input method reactivation
Patch Set: fix some tests 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') | no next file » | 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 next_paint_flags_(0), 214 next_paint_flags_(0),
215 auto_resize_mode_(false), 215 auto_resize_mode_(false),
216 need_update_rect_for_auto_resize_(false), 216 need_update_rect_for_auto_resize_(false),
217 did_show_(false), 217 did_show_(false),
218 is_hidden_(hidden), 218 is_hidden_(hidden),
219 compositor_never_visible_(never_visible), 219 compositor_never_visible_(never_visible),
220 is_fullscreen_granted_(false), 220 is_fullscreen_granted_(false),
221 display_mode_(blink::WebDisplayModeUndefined), 221 display_mode_(blink::WebDisplayModeUndefined),
222 ime_event_guard_(nullptr), 222 ime_event_guard_(nullptr),
223 ime_in_batch_edit_(false), 223 ime_in_batch_edit_(false),
224 ime_ignore_until_acked_(false),
224 closing_(false), 225 closing_(false),
225 host_closing_(false), 226 host_closing_(false),
226 is_swapped_out_(swapped_out), 227 is_swapped_out_(swapped_out),
227 for_oopif_(false), 228 for_oopif_(false),
228 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 229 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
229 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 230 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
230 text_input_flags_(0), 231 text_input_flags_(0),
231 can_compose_inline_(true), 232 can_compose_inline_(true),
232 composition_range_(gfx::Range::InvalidRange()), 233 composition_range_(gfx::Range::InvalidRange()),
233 popup_type_(popup_type), 234 popup_type_(popup_type),
(...skipping 29 matching lines...) Expand all
263 render_widget_scheduling_state_->SetHidden(is_hidden_); 264 render_widget_scheduling_state_->SetHidden(is_hidden_);
264 } 265 }
265 } 266 }
266 267
267 RenderWidget::~RenderWidget() { 268 RenderWidget::~RenderWidget() {
268 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!"; 269 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
269 270
270 // If we are swapped out, we have released already. 271 // If we are swapped out, we have released already.
271 if (!is_swapped_out_ && RenderProcess::current()) 272 if (!is_swapped_out_ && RenderProcess::current())
272 RenderProcess::current()->ReleaseProcess(); 273 RenderProcess::current()->ReleaseProcess();
274
275 for (size_t i = 0; i < ime_messages_to_send_after_update_.size(); ++i)
276 delete ime_messages_to_send_after_update_[i];
273 } 277 }
274 278
275 // static 279 // static
276 void RenderWidget::InstallCreateHook( 280 void RenderWidget::InstallCreateHook(
277 CreateRenderWidgetFunction create_render_widget, 281 CreateRenderWidgetFunction create_render_widget,
278 RenderWidgetInitializedCallback render_widget_initialized) { 282 RenderWidgetInitializedCallback render_widget_initialized) {
279 CHECK(!g_create_render_widget && !g_render_widget_initialized); 283 CHECK(!g_create_render_widget && !g_render_widget_initialized);
280 g_create_render_widget = create_render_widget; 284 g_create_render_widget = create_render_widget;
281 g_render_widget_initialized = render_widget_initialized; 285 g_render_widget_initialized = render_widget_initialized;
282 } 286 }
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 892 }
889 } 893 }
890 894
891 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { 895 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
892 // Nothing to do here. RenderWidget created the |input_handler| and will take 896 // Nothing to do here. RenderWidget created the |input_handler| and will take
893 // ownership of it. We just verify here that we don't already have an input 897 // ownership of it. We just verify here that we don't already have an input
894 // handler. 898 // handler.
895 DCHECK(!input_handler_); 899 DCHECK(!input_handler_);
896 } 900 }
897 901
902 void RenderWidget::CancelComposition() {
903 ImeEventGuard guard(this);
904 ime_ignore_until_acked_ = true;
905 ime_messages_to_send_after_update_.push_back(
906 new InputHostMsg_ImeCancelComposition(routing_id()));
907 }
908
909 void RenderWidget::OnFocusedNodeChanged(bool is_editable,
910 const gfx::Rect& node_bounds) {
911 ImeEventGuard guard(this);
912 ime_ignore_until_acked_ = true;
913 ime_messages_to_send_after_update_.push_back(
914 new ViewHostMsg_FocusedNodeChanged(
915 routing_id(), is_editable, node_bounds));
916 }
917
898 void RenderWidget::UpdateTextInputState(ShowIme show_ime, 918 void RenderWidget::UpdateTextInputState(ShowIme show_ime,
899 ChangeSource change_source) { 919 ChangeSource change_source) {
900 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); 920 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
901 if (ime_event_guard_) { 921 if (ime_event_guard_) {
902 // show_ime should still be effective even if it was set inside the IME 922 // show_ime should still be effective even if it was set inside the IME
903 // event guard. 923 // event guard.
904 if (show_ime == ShowIme::IF_NEEDED) { 924 if (show_ime == ShowIme::IF_NEEDED) {
905 ime_event_guard_->set_show_ime(true); 925 ime_event_guard_->set_show_ime(true);
906 } 926 }
907 return; 927 return;
(...skipping 10 matching lines...) Expand all
918 ConvertWebTextInputMode(new_info.inputMode); 938 ConvertWebTextInputMode(new_info.inputMode);
919 939
920 bool new_can_compose_inline = CanComposeInline(); 940 bool new_can_compose_inline = CanComposeInline();
921 941
922 // Only sends text input params if they are changed or if the ime should be 942 // Only sends text input params if they are changed or if the ime should be
923 // shown. 943 // shown.
924 if (show_ime == ShowIme::IF_NEEDED || 944 if (show_ime == ShowIme::IF_NEEDED ||
925 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || 945 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
926 (text_input_type_ != new_type || text_input_mode_ != new_mode || 946 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
927 text_input_info_ != new_info || 947 text_input_info_ != new_info ||
928 can_compose_inline_ != new_can_compose_inline) 948 can_compose_inline_ != new_can_compose_inline) || ime_ignore_until_acked_
929 #if defined(OS_ANDROID) 949 #if defined(OS_ANDROID)
930 || text_field_is_dirty_ 950 || text_field_is_dirty_
931 #endif 951 #endif
932 ) { 952 ) {
933 TextInputState params; 953 TextInputState params;
934 params.type = new_type; 954 params.type = new_type;
935 params.mode = new_mode; 955 params.mode = new_mode;
936 params.flags = new_info.flags; 956 params.flags = new_info.flags;
937 params.value = new_info.value.utf8(); 957 params.value = new_info.value.utf8();
938 params.selection_start = new_info.selectionStart; 958 params.selection_start = new_info.selectionStart;
939 params.selection_end = new_info.selectionEnd; 959 params.selection_end = new_info.selectionEnd;
940 params.composition_start = new_info.compositionStart; 960 params.composition_start = new_info.compositionStart;
941 params.composition_end = new_info.compositionEnd; 961 params.composition_end = new_info.compositionEnd;
942 params.can_compose_inline = new_can_compose_inline; 962 params.can_compose_inline = new_can_compose_inline;
943 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); 963 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
944 #if defined(USE_AURA) 964 #if defined(USE_AURA)
945 params.is_non_ime_change = true; 965 params.is_non_ime_change = true;
946 #endif 966 #endif
947 #if defined(OS_ANDROID) 967 #if defined(OS_ANDROID)
948 params.is_non_ime_change = 968 params.is_non_ime_change =
949 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_; 969 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
950 params.batch_edit = ime_in_batch_edit_; 970 params.batch_edit = ime_in_batch_edit_;
951 if (params.is_non_ime_change) 971 if (ime_ignore_until_acked_ ||
972 (!IsUsingImeThread() && params.is_non_ime_change)) {
973 params.requires_ack = true;
952 OnImeEventSentForAck(new_info); 974 OnImeEventSentForAck(new_info);
975 ime_ignore_until_acked_ = false;
976 }
953 text_field_is_dirty_ = false; 977 text_field_is_dirty_ = false;
954 #endif 978 #endif
955 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); 979 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
956 980
957 text_input_info_ = new_info; 981 text_input_info_ = new_info;
958 text_input_type_ = new_type; 982 text_input_type_ = new_type;
959 text_input_mode_ = new_mode; 983 text_input_mode_ = new_mode;
960 can_compose_inline_ = new_can_compose_inline; 984 can_compose_inline_ = new_can_compose_inline;
961 text_input_flags_ = new_info.flags; 985 text_input_flags_ = new_info.flags;
962 } 986 }
987
988 for (size_t i = 0; i < ime_messages_to_send_after_update_.size(); ++i)
989 Send(ime_messages_to_send_after_update_[i]);
990
991 ime_messages_to_send_after_update_.clear();
963 } 992 }
964 993
965 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { 994 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
966 if (owner_delegate_) 995 if (owner_delegate_)
967 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event); 996 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
968 997
969 return false; 998 return false;
970 } 999 }
971 1000
972 bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) { 1001 bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 1424
1396 if (!ShouldHandleImeEvent()) 1425 if (!ShouldHandleImeEvent())
1397 return; 1426 return;
1398 ImeEventGuard guard(this); 1427 ImeEventGuard guard(this);
1399 if (!GetWebWidget()->setComposition( 1428 if (!GetWebWidget()->setComposition(
1400 text, WebVector<WebCompositionUnderline>(underlines), selection_start, 1429 text, WebVector<WebCompositionUnderline>(underlines), selection_start,
1401 selection_end)) { 1430 selection_end)) {
1402 // If we failed to set the composition text, then we need to let the browser 1431 // If we failed to set the composition text, then we need to let the browser
1403 // process to cancel the input method's ongoing composition session, to make 1432 // process to cancel the input method's ongoing composition session, to make
1404 // sure we are in a consistent state. 1433 // sure we are in a consistent state.
1405 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1434 CancelComposition();
1406 } 1435 }
1407 UpdateCompositionInfo(false /* not an immediate request */); 1436 UpdateCompositionInfo(false /* not an immediate request */);
1408 } 1437 }
1409 1438
1410 void RenderWidget::OnImeCommitText(const base::string16& text, 1439 void RenderWidget::OnImeCommitText(const base::string16& text,
1411 const gfx::Range& replacement_range, 1440 const gfx::Range& replacement_range,
1412 int relative_cursor_pos) { 1441 int relative_cursor_pos) {
1413 #if defined(ENABLE_PLUGINS) 1442 #if defined(ENABLE_PLUGINS)
1414 if (focused_pepper_plugin_) { 1443 if (focused_pepper_plugin_) {
1415 focused_pepper_plugin_->render_frame()->OnImeCommitText( 1444 focused_pepper_plugin_->render_frame()->OnImeCommitText(
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 monitor_composition_info_ = monitor_request; 1657 monitor_composition_info_ = monitor_request;
1629 if (!immediate_request) 1658 if (!immediate_request)
1630 return; 1659 return;
1631 UpdateCompositionInfo(true /* immediate request */); 1660 UpdateCompositionInfo(true /* immediate request */);
1632 } 1661 }
1633 1662
1634 bool RenderWidget::ShouldHandleImeEvent() { 1663 bool RenderWidget::ShouldHandleImeEvent() {
1635 #if defined(OS_ANDROID) 1664 #if defined(OS_ANDROID)
1636 if (!GetWebWidget()) 1665 if (!GetWebWidget())
1637 return false; 1666 return false;
1638 if (IsUsingImeThread())
1639 return true;
1640 1667
1641 // We cannot handle IME events if there is any chance that the event we are 1668 // We cannot handle IME events if there is any chance that the event we are
1642 // receiving here from the browser is based on the state that is different 1669 // receiving here from the browser is based on the state that is different
1643 // from our current one as indicated by |text_input_info_|. 1670 // from our current one as indicated by |text_input_info_|.
1644 // The states the browser might be in are: 1671 // The states the browser might be in are:
1645 // text_input_info_history_[0] - current state ack'd by browser 1672 // text_input_info_history_[0] - current state ack'd by browser
1646 // text_input_info_history_[1...N] - pending state changes 1673 // text_input_info_history_[1...N] - pending state changes
1647 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { 1674 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1648 if (text_input_info_history_[i] != text_input_info_) 1675 if (text_input_info_history_[i] != text_input_info_)
1649 return false; 1676 return false;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 ime_event_guard_->from_ime() && guard->from_ime()); 1779 ime_event_guard_->from_ime() && guard->from_ime());
1753 #endif 1780 #endif
1754 return; 1781 return;
1755 } 1782 }
1756 ime_event_guard_ = nullptr; 1783 ime_event_guard_ = nullptr;
1757 1784
1758 // While handling an ime event, text input state and selection bounds updates 1785 // While handling an ime event, text input state and selection bounds updates
1759 // are ignored. These must explicitly be updated once finished handling the 1786 // are ignored. These must explicitly be updated once finished handling the
1760 // ime event. 1787 // ime event.
1761 UpdateSelectionBounds(); 1788 UpdateSelectionBounds();
1762 #if defined(OS_ANDROID)
1763 UpdateTextInputState( 1789 UpdateTextInputState(
1764 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, 1790 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1765 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); 1791 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
1766 #endif
1767 } 1792 }
1768 1793
1769 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { 1794 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1770 #if defined(ENABLE_PLUGINS) 1795 #if defined(ENABLE_PLUGINS)
1771 if (focused_pepper_plugin_) { 1796 if (focused_pepper_plugin_) {
1772 // TODO(kinaba) http://crbug.com/101101 1797 // TODO(kinaba) http://crbug.com/101101
1773 // Current Pepper IME API does not handle selection bounds. So we simply 1798 // Current Pepper IME API does not handle selection bounds. So we simply
1774 // use the caret position as an empty range for now. It will be updated 1799 // use the caret position as an empty range for now. It will be updated
1775 // after Pepper API equips features related to surrounding text retrieval. 1800 // after Pepper API equips features related to surrounding text retrieval.
1776 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds()); 1801 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 return web_screen_info; 1971 return web_screen_info;
1947 } 1972 }
1948 1973
1949 void RenderWidget::resetInputMethod() { 1974 void RenderWidget::resetInputMethod() {
1950 ImeEventGuard guard(this); 1975 ImeEventGuard guard(this);
1951 // If the last text input type is not None, then we should finish any 1976 // If the last text input type is not None, then we should finish any
1952 // ongoing composition regardless of the new text input type. 1977 // ongoing composition regardless of the new text input type.
1953 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 1978 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
1954 // If a composition text exists, then we need to let the browser process 1979 // If a composition text exists, then we need to let the browser process
1955 // to cancel the input method's ongoing composition session. 1980 // to cancel the input method's ongoing composition session.
1956 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) 1981 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) {
1957 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1982 CancelComposition();
1983 }
1958 } 1984 }
1959 1985
1960 UpdateCompositionInfo(false /* not an immediate request */); 1986 UpdateCompositionInfo(false /* not an immediate request */);
1961 } 1987 }
1962 1988
1963 #if defined(OS_ANDROID) 1989 #if defined(OS_ANDROID)
1964 void RenderWidget::showUnhandledTapUIIfNeeded( 1990 void RenderWidget::showUnhandledTapUIIfNeeded(
1965 const WebPoint& tapped_position, 1991 const WebPoint& tapped_position,
1966 const WebNode& tapped_node, 1992 const WebNode& tapped_node,
1967 bool page_changed) { 1993 bool page_changed) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 bool RenderWidget::isPointerLocked() { 2114 bool RenderWidget::isPointerLocked() {
2089 return mouse_lock_dispatcher_->IsMouseLockedTo( 2115 return mouse_lock_dispatcher_->IsMouseLockedTo(
2090 webwidget_mouse_lock_target_.get()); 2116 webwidget_mouse_lock_target_.get());
2091 } 2117 }
2092 2118
2093 blink::WebWidget* RenderWidget::GetWebWidget() const { 2119 blink::WebWidget* RenderWidget::GetWebWidget() const {
2094 return webwidget_internal_; 2120 return webwidget_internal_;
2095 } 2121 }
2096 2122
2097 } // namespace content 2123 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698