Commit 2418e1b6 authored by changwan's avatar changwan Committed by Commit bot

Move call path for resetInputMethod

This is mostly about mechanical changes such as:

- Move InputMethodController-related logic inside InputMethodController
  and call it first - such that we can expand the logic there.
- Rename method name for better readability.

Also, there are subtle logical changes:

1) Try finishComposingText() even when the current input type is NONE.
   This should not have any effect.

2) When finishComposingText() returns false, we no longer call
   UpdateTextInputState(). This should not have any effect.

3) When finishComposingText() returns false, we no long call
   UpdateCompositionInfo(). This is used by Android and Mac.
   Previously, there was a chance that we propagate InvalidRange() all the
   way up to the keyboard app. Now ShouldUpdateCompositionInfo() returns
   false to make it clear.

This is originally found in resolving crbug.com/664317, but is also
needed for crbug.com/630137 because if we no longer cancel composition
on selection change, then WebViewTest may fail because it uses
TestWebViewClient which does not implement resetInputMethod().

BUG=664317, 630137

Review-Url: https://codereview.chromium.org/2561543003
Cr-Commit-Position: refs/heads/master@{#437854}
parent ba39ed57
...@@ -2022,6 +2022,8 @@ void RenderWidget::GetCompositionRange(gfx::Range* range) { ...@@ -2022,6 +2022,8 @@ void RenderWidget::GetCompositionRange(gfx::Range* range) {
bool RenderWidget::ShouldUpdateCompositionInfo( bool RenderWidget::ShouldUpdateCompositionInfo(
const gfx::Range& range, const gfx::Range& range,
const std::vector<gfx::Rect>& bounds) { const std::vector<gfx::Rect>& bounds) {
if (!range.IsValid())
return false;
if (composition_range_ != range) if (composition_range_ != range)
return true; return true;
if (bounds.size() != composition_character_bounds_.size()) if (bounds.size() != composition_character_bounds_.size())
...@@ -2077,17 +2079,7 @@ blink::WebScreenInfo RenderWidget::screenInfo() { ...@@ -2077,17 +2079,7 @@ blink::WebScreenInfo RenderWidget::screenInfo() {
void RenderWidget::resetInputMethod() { void RenderWidget::resetInputMethod() {
ImeEventGuard guard(this); ImeEventGuard guard(this);
// If the last text input type is not None, then we should finish any Send(new InputHostMsg_ImeCancelComposition(routing_id()));
// ongoing composition regardless of the new text input type.
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.
blink::WebInputMethodController* controller = GetInputMethodController();
if (controller &&
controller->finishComposingText(
WebInputMethodController::DoNotKeepSelection))
Send(new InputHostMsg_ImeCancelComposition(routing_id()));
}
UpdateCompositionInfo(false /* not an immediate request */); UpdateCompositionInfo(false /* not an immediate request */);
} }
......
...@@ -1193,6 +1193,12 @@ WebTextInputType InputMethodController::textInputType() const { ...@@ -1193,6 +1193,12 @@ WebTextInputType InputMethodController::textInputType() const {
return WebTextInputTypeNone; return WebTextInputTypeNone;
} }
void InputMethodController::willChangeFocus() {
if (!finishComposingText(DoNotKeepSelection))
return;
frame().chromeClient().resetInputMethod();
}
DEFINE_TRACE(InputMethodController) { DEFINE_TRACE(InputMethodController) {
visitor->trace(m_frame); visitor->trace(m_frame);
visitor->trace(m_compositionRange); visitor->trace(m_compositionRange);
......
...@@ -103,6 +103,9 @@ class CORE_EXPORT InputMethodController final ...@@ -103,6 +103,9 @@ class CORE_EXPORT InputMethodController final
WebTextInputInfo textInputInfo() const; WebTextInputInfo textInputInfo() const;
WebTextInputType textInputType() const; WebTextInputType textInputType() const;
// Call this when we will change focus.
void willChangeFocus();
private: private:
Document& document() const; Document& document() const;
bool isAvailable() const; bool isAvailable() const;
......
...@@ -303,7 +303,7 @@ class CORE_EXPORT ChromeClient : public HostWindow { ...@@ -303,7 +303,7 @@ class CORE_EXPORT ChromeClient : public HostWindow {
// Input method editor related functions. // Input method editor related functions.
virtual void didCancelCompositionOnSelectionChange() {} virtual void didCancelCompositionOnSelectionChange() {}
virtual void willSetInputMethodState() {} virtual void resetInputMethod() {}
virtual void didUpdateTextOfFocusedElementByNonUserInput(LocalFrame&) {} virtual void didUpdateTextOfFocusedElementByNonUserInput(LocalFrame&) {}
virtual void showImeIfNeeded() {} virtual void showImeIfNeeded() {}
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "core/editing/EditingUtilities.h" // For firstPositionInOrBeforeNode #include "core/editing/EditingUtilities.h" // For firstPositionInOrBeforeNode
#include "core/editing/Editor.h" #include "core/editing/Editor.h"
#include "core/editing/FrameSelection.h" #include "core/editing/FrameSelection.h"
#include "core/editing/InputMethodController.h"
#include "core/events/Event.h" #include "core/events/Event.h"
#include "core/frame/FrameClient.h" #include "core/frame/FrameClient.h"
#include "core/frame/FrameView.h" #include "core/frame/FrameView.h"
...@@ -1128,7 +1129,8 @@ bool FocusController::setFocusedElement(Element* element, ...@@ -1128,7 +1129,8 @@ bool FocusController::setFocusedElement(Element* element,
!relinquishesEditingFocus(*oldFocusedElement)) !relinquishesEditingFocus(*oldFocusedElement))
return false; return false;
m_page->chromeClient().willSetInputMethodState(); if (oldFocusedFrame)
oldFocusedFrame->inputMethodController().willChangeFocus();
Document* newDocument = nullptr; Document* newDocument = nullptr;
if (element) if (element)
......
...@@ -1012,7 +1012,7 @@ void ChromeClientImpl::didCancelCompositionOnSelectionChange() { ...@@ -1012,7 +1012,7 @@ void ChromeClientImpl::didCancelCompositionOnSelectionChange() {
m_webView->client()->didCancelCompositionOnSelectionChange(); m_webView->client()->didCancelCompositionOnSelectionChange();
} }
void ChromeClientImpl::willSetInputMethodState() { void ChromeClientImpl::resetInputMethod() {
if (m_webView->client()) if (m_webView->client())
m_webView->client()->resetInputMethod(); m_webView->client()->resetInputMethod();
} }
......
...@@ -196,7 +196,7 @@ class WEB_EXPORT ChromeClientImpl final : public ChromeClient { ...@@ -196,7 +196,7 @@ class WEB_EXPORT ChromeClientImpl final : public ChromeClient {
void ajaxSucceeded(LocalFrame*) override; void ajaxSucceeded(LocalFrame*) override;
void didCancelCompositionOnSelectionChange() override; void didCancelCompositionOnSelectionChange() override;
void willSetInputMethodState() override; void resetInputMethod() override;
void showImeIfNeeded() override; void showImeIfNeeded() override;
void registerViewportLayers() const override; void registerViewportLayers() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment