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

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

Issue 2466283002: [WIP Approach 2] Straighten up input method reactivation
Patch Set: 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
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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 889 }
889 } 890 }
890 891
891 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { 892 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
892 // Nothing to do here. RenderWidget created the |input_handler| and will take 893 // 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 894 // ownership of it. We just verify here that we don't already have an input
894 // handler. 895 // handler.
895 DCHECK(!input_handler_); 896 DCHECK(!input_handler_);
896 } 897 }
897 898
899 void RenderWidget::CancelComposition() {
900 ime_ignore_until_acked_ = true;
901 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
902 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
903 }
904
905 void RenderWidget::OnFocusedNodeChanged(bool is_editable,
906 const gfx::Rect& node_bounds) {
907 ime_ignore_until_acked_ = true;
908 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
909 Send(new ViewHostMsg_FocusedNodeChanged(
910 routing_id(), is_editable, node_bounds));
911 }
912
898 void RenderWidget::UpdateTextInputState(ShowIme show_ime, 913 void RenderWidget::UpdateTextInputState(ShowIme show_ime,
899 ChangeSource change_source) { 914 ChangeSource change_source) {
900 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); 915 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
901 if (ime_event_guard_) { 916 if (!ime_ignore_until_acked_ && ime_event_guard_) {
902 // show_ime should still be effective even if it was set inside the IME 917 // show_ime should still be effective even if it was set inside the IME
903 // event guard. 918 // event guard.
904 if (show_ime == ShowIme::IF_NEEDED) { 919 if (show_ime == ShowIme::IF_NEEDED) {
905 ime_event_guard_->set_show_ime(true); 920 ime_event_guard_->set_show_ime(true);
906 } 921 }
907 return; 922 return;
908 } 923 }
909 924
910 ui::TextInputType new_type = GetTextInputType(); 925 ui::TextInputType new_type = GetTextInputType();
911 if (IsDateTimeInput(new_type)) 926 if (IsDateTimeInput(new_type))
912 return; // Not considered as a text input field in WebKit/Chromium. 927 return; // Not considered as a text input field in WebKit/Chromium.
913 928
914 blink::WebTextInputInfo new_info; 929 blink::WebTextInputInfo new_info;
915 if (GetWebWidget()) 930 if (GetWebWidget())
916 new_info = GetWebWidget()->textInputInfo(); 931 new_info = GetWebWidget()->textInputInfo();
917 const ui::TextInputMode new_mode = 932 const ui::TextInputMode new_mode =
918 ConvertWebTextInputMode(new_info.inputMode); 933 ConvertWebTextInputMode(new_info.inputMode);
919 934
920 bool new_can_compose_inline = CanComposeInline(); 935 bool new_can_compose_inline = CanComposeInline();
921 936
922 // Only sends text input params if they are changed or if the ime should be 937 // Only sends text input params if they are changed or if the ime should be
923 // shown. 938 // shown.
924 if (show_ime == ShowIme::IF_NEEDED || 939 if (show_ime == ShowIme::IF_NEEDED ||
925 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || 940 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
926 (text_input_type_ != new_type || text_input_mode_ != new_mode || 941 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
927 text_input_info_ != new_info || 942 text_input_info_ != new_info ||
928 can_compose_inline_ != new_can_compose_inline) 943 can_compose_inline_ != new_can_compose_inline) || ime_ignore_until_acked_
929 #if defined(OS_ANDROID) 944 #if defined(OS_ANDROID)
930 || text_field_is_dirty_ 945 || text_field_is_dirty_
931 #endif 946 #endif
932 ) { 947 ) {
933 TextInputState params; 948 TextInputState params;
934 params.type = new_type; 949 params.type = new_type;
935 params.mode = new_mode; 950 params.mode = new_mode;
936 params.flags = new_info.flags; 951 params.flags = new_info.flags;
937 params.value = new_info.value.utf8(); 952 params.value = new_info.value.utf8();
938 params.selection_start = new_info.selectionStart; 953 params.selection_start = new_info.selectionStart;
939 params.selection_end = new_info.selectionEnd; 954 params.selection_end = new_info.selectionEnd;
940 params.composition_start = new_info.compositionStart; 955 params.composition_start = new_info.compositionStart;
941 params.composition_end = new_info.compositionEnd; 956 params.composition_end = new_info.compositionEnd;
942 params.can_compose_inline = new_can_compose_inline; 957 params.can_compose_inline = new_can_compose_inline;
943 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); 958 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
944 #if defined(USE_AURA) 959 #if defined(USE_AURA)
945 params.is_non_ime_change = true; 960 params.is_non_ime_change = true;
946 #endif 961 #endif
947 #if defined(OS_ANDROID) 962 #if defined(OS_ANDROID)
948 params.is_non_ime_change = 963 params.is_non_ime_change =
949 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_; 964 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
950 params.batch_edit = ime_in_batch_edit_; 965 params.batch_edit = ime_in_batch_edit_;
951 if (params.is_non_ime_change) 966 if (ime_ignore_until_acked_ ||
967 (!IsUsingImeThread() && params.is_non_ime_change)) {
968 params.requires_ack = true;
952 OnImeEventSentForAck(new_info); 969 OnImeEventSentForAck(new_info);
970 ime_ignore_until_acked_ = false;
971 }
953 text_field_is_dirty_ = false; 972 text_field_is_dirty_ = false;
954 #endif 973 #endif
955 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); 974 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
956 975
957 text_input_info_ = new_info; 976 text_input_info_ = new_info;
958 text_input_type_ = new_type; 977 text_input_type_ = new_type;
959 text_input_mode_ = new_mode; 978 text_input_mode_ = new_mode;
960 can_compose_inline_ = new_can_compose_inline; 979 can_compose_inline_ = new_can_compose_inline;
961 text_input_flags_ = new_info.flags; 980 text_input_flags_ = new_info.flags;
962 } 981 }
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 1414
1396 if (!ShouldHandleImeEvent()) 1415 if (!ShouldHandleImeEvent())
1397 return; 1416 return;
1398 ImeEventGuard guard(this); 1417 ImeEventGuard guard(this);
1399 if (!GetWebWidget()->setComposition( 1418 if (!GetWebWidget()->setComposition(
1400 text, WebVector<WebCompositionUnderline>(underlines), selection_start, 1419 text, WebVector<WebCompositionUnderline>(underlines), selection_start,
1401 selection_end)) { 1420 selection_end)) {
1402 // If we failed to set the composition text, then we need to let the browser 1421 // 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 1422 // process to cancel the input method's ongoing composition session, to make
1404 // sure we are in a consistent state. 1423 // sure we are in a consistent state.
1405 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1424 CancelComposition();
1406 } 1425 }
1407 UpdateCompositionInfo(false /* not an immediate request */); 1426 UpdateCompositionInfo(false /* not an immediate request */);
1408 } 1427 }
1409 1428
1410 void RenderWidget::OnImeCommitText(const base::string16& text, 1429 void RenderWidget::OnImeCommitText(const base::string16& text,
1411 const gfx::Range& replacement_range, 1430 const gfx::Range& replacement_range,
1412 int relative_cursor_pos) { 1431 int relative_cursor_pos) {
1413 #if defined(ENABLE_PLUGINS) 1432 #if defined(ENABLE_PLUGINS)
1414 if (focused_pepper_plugin_) { 1433 if (focused_pepper_plugin_) {
1415 focused_pepper_plugin_->render_frame()->OnImeCommitText( 1434 focused_pepper_plugin_->render_frame()->OnImeCommitText(
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 monitor_composition_info_ = monitor_request; 1647 monitor_composition_info_ = monitor_request;
1629 if (!immediate_request) 1648 if (!immediate_request)
1630 return; 1649 return;
1631 UpdateCompositionInfo(true /* immediate request */); 1650 UpdateCompositionInfo(true /* immediate request */);
1632 } 1651 }
1633 1652
1634 bool RenderWidget::ShouldHandleImeEvent() { 1653 bool RenderWidget::ShouldHandleImeEvent() {
1635 #if defined(OS_ANDROID) 1654 #if defined(OS_ANDROID)
1636 if (!GetWebWidget()) 1655 if (!GetWebWidget())
1637 return false; 1656 return false;
1638 if (IsUsingImeThread())
1639 return true;
1640 1657
1641 // We cannot handle IME events if there is any chance that the event we are 1658 // 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 1659 // receiving here from the browser is based on the state that is different
1643 // from our current one as indicated by |text_input_info_|. 1660 // from our current one as indicated by |text_input_info_|.
1644 // The states the browser might be in are: 1661 // The states the browser might be in are:
1645 // text_input_info_history_[0] - current state ack'd by browser 1662 // text_input_info_history_[0] - current state ack'd by browser
1646 // text_input_info_history_[1...N] - pending state changes 1663 // text_input_info_history_[1...N] - pending state changes
1647 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { 1664 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1648 if (text_input_info_history_[i] != text_input_info_) 1665 if (text_input_info_history_[i] != text_input_info_)
1649 return false; 1666 return false;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 ime_event_guard_->from_ime() && guard->from_ime()); 1769 ime_event_guard_->from_ime() && guard->from_ime());
1753 #endif 1770 #endif
1754 return; 1771 return;
1755 } 1772 }
1756 ime_event_guard_ = nullptr; 1773 ime_event_guard_ = nullptr;
1757 1774
1758 // While handling an ime event, text input state and selection bounds updates 1775 // While handling an ime event, text input state and selection bounds updates
1759 // are ignored. These must explicitly be updated once finished handling the 1776 // are ignored. These must explicitly be updated once finished handling the
1760 // ime event. 1777 // ime event.
1761 UpdateSelectionBounds(); 1778 UpdateSelectionBounds();
1762 #if defined(OS_ANDROID)
1763 UpdateTextInputState( 1779 UpdateTextInputState(
1764 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, 1780 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1765 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); 1781 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
1766 #endif
1767 } 1782 }
1768 1783
1769 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { 1784 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1770 #if defined(ENABLE_PLUGINS) 1785 #if defined(ENABLE_PLUGINS)
1771 if (focused_pepper_plugin_) { 1786 if (focused_pepper_plugin_) {
1772 // TODO(kinaba) http://crbug.com/101101 1787 // TODO(kinaba) http://crbug.com/101101
1773 // Current Pepper IME API does not handle selection bounds. So we simply 1788 // 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 1789 // 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. 1790 // after Pepper API equips features related to surrounding text retrieval.
1776 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds()); 1791 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 return web_screen_info; 1961 return web_screen_info;
1947 } 1962 }
1948 1963
1949 void RenderWidget::resetInputMethod() { 1964 void RenderWidget::resetInputMethod() {
1950 ImeEventGuard guard(this); 1965 ImeEventGuard guard(this);
1951 // If the last text input type is not None, then we should finish any 1966 // If the last text input type is not None, then we should finish any
1952 // ongoing composition regardless of the new text input type. 1967 // ongoing composition regardless of the new text input type.
1953 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 1968 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
1954 // If a composition text exists, then we need to let the browser process 1969 // If a composition text exists, then we need to let the browser process
1955 // to cancel the input method's ongoing composition session. 1970 // to cancel the input method's ongoing composition session.
1956 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) 1971 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) {
1957 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1972 CancelComposition();
1973 }
1958 } 1974 }
1959 1975
1960 UpdateCompositionInfo(false /* not an immediate request */); 1976 UpdateCompositionInfo(false /* not an immediate request */);
1961 } 1977 }
1962 1978
1963 #if defined(OS_ANDROID) 1979 #if defined(OS_ANDROID)
1964 void RenderWidget::showUnhandledTapUIIfNeeded( 1980 void RenderWidget::showUnhandledTapUIIfNeeded(
1965 const WebPoint& tapped_position, 1981 const WebPoint& tapped_position,
1966 const WebNode& tapped_node, 1982 const WebNode& tapped_node,
1967 bool page_changed) { 1983 bool page_changed) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 bool RenderWidget::isPointerLocked() { 2112 bool RenderWidget::isPointerLocked() {
2097 return mouse_lock_dispatcher_->IsMouseLockedTo( 2113 return mouse_lock_dispatcher_->IsMouseLockedTo(
2098 webwidget_mouse_lock_target_.get()); 2114 webwidget_mouse_lock_target_.get());
2099 } 2115 }
2100 2116
2101 blink::WebWidget* RenderWidget::GetWebWidget() const { 2117 blink::WebWidget* RenderWidget::GetWebWidget() const {
2102 return webwidget_internal_; 2118 return webwidget_internal_;
2103 } 2119 }
2104 2120
2105 } // namespace content 2121 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | third_party/WebKit/Source/core/input/MouseEventManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698