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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_widget.cc
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 57bb2085f61e3f419307f96fb827956bc7ba7206..d8509dea2ed5422c1ca2b0cc3654505fb1f38769 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -221,6 +221,7 @@ RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
display_mode_(blink::WebDisplayModeUndefined),
ime_event_guard_(nullptr),
ime_in_batch_edit_(false),
+ ime_ignore_until_acked_(false),
closing_(false),
host_closing_(false),
is_swapped_out_(swapped_out),
@@ -270,6 +271,9 @@ RenderWidget::~RenderWidget() {
// If we are swapped out, we have released already.
if (!is_swapped_out_ && RenderProcess::current())
RenderProcess::current()->ReleaseProcess();
+
+ for (size_t i = 0; i < ime_messages_to_send_after_update_.size(); ++i)
+ delete ime_messages_to_send_after_update_[i];
}
// static
@@ -895,6 +899,22 @@ void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
DCHECK(!input_handler_);
}
+void RenderWidget::CancelComposition() {
+ ImeEventGuard guard(this);
+ ime_ignore_until_acked_ = true;
+ ime_messages_to_send_after_update_.push_back(
+ new InputHostMsg_ImeCancelComposition(routing_id()));
+}
+
+void RenderWidget::OnFocusedNodeChanged(bool is_editable,
+ const gfx::Rect& node_bounds) {
+ ImeEventGuard guard(this);
+ ime_ignore_until_acked_ = true;
+ ime_messages_to_send_after_update_.push_back(
+ new ViewHostMsg_FocusedNodeChanged(
+ routing_id(), is_editable, node_bounds));
+}
+
void RenderWidget::UpdateTextInputState(ShowIme show_ime,
ChangeSource change_source) {
TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
@@ -925,7 +945,7 @@ void RenderWidget::UpdateTextInputState(ShowIme show_ime,
(IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
(text_input_type_ != new_type || text_input_mode_ != new_mode ||
text_input_info_ != new_info ||
- can_compose_inline_ != new_can_compose_inline)
+ can_compose_inline_ != new_can_compose_inline) || ime_ignore_until_acked_
#if defined(OS_ANDROID)
|| text_field_is_dirty_
#endif
@@ -948,8 +968,12 @@ void RenderWidget::UpdateTextInputState(ShowIme show_ime,
params.is_non_ime_change =
(change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
params.batch_edit = ime_in_batch_edit_;
- if (params.is_non_ime_change)
+ if (ime_ignore_until_acked_ ||
+ (!IsUsingImeThread() && params.is_non_ime_change)) {
+ params.requires_ack = true;
OnImeEventSentForAck(new_info);
+ ime_ignore_until_acked_ = false;
+ }
text_field_is_dirty_ = false;
#endif
Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
@@ -960,6 +984,11 @@ void RenderWidget::UpdateTextInputState(ShowIme show_ime,
can_compose_inline_ = new_can_compose_inline;
text_input_flags_ = new_info.flags;
}
+
+ for (size_t i = 0; i < ime_messages_to_send_after_update_.size(); ++i)
+ Send(ime_messages_to_send_after_update_[i]);
+
+ ime_messages_to_send_after_update_.clear();
}
bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
@@ -1402,7 +1431,7 @@ void RenderWidget::OnImeSetComposition(
// If we failed to set the composition text, then we need to let the browser
// process to cancel the input method's ongoing composition session, to make
// sure we are in a consistent state.
- Send(new InputHostMsg_ImeCancelComposition(routing_id()));
+ CancelComposition();
}
UpdateCompositionInfo(false /* not an immediate request */);
}
@@ -1635,8 +1664,6 @@ bool RenderWidget::ShouldHandleImeEvent() {
#if defined(OS_ANDROID)
if (!GetWebWidget())
return false;
- if (IsUsingImeThread())
- return true;
// We cannot handle IME events if there is any chance that the event we are
// receiving here from the browser is based on the state that is different
@@ -1759,11 +1786,9 @@ void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
// are ignored. These must explicitly be updated once finished handling the
// ime event.
UpdateSelectionBounds();
-#if defined(OS_ANDROID)
UpdateTextInputState(
guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
-#endif
}
void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
@@ -1953,8 +1978,9 @@ void RenderWidget::resetInputMethod() {
if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
// If a composition text exists, then we need to let the browser process
// to cancel the input method's ongoing composition session.
- if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection))
- Send(new InputHostMsg_ImeCancelComposition(routing_id()));
+ if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) {
+ CancelComposition();
+ }
}
UpdateCompositionInfo(false /* not an immediate request */);
« 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