Commit 051ec2f1 authored by My Nguyen's avatar My Nguyen Committed by Commit Bot

[Autocorrect] Add ClearAutocorrectRange to InputMethodEngine

Bug: b/171924347
Change-Id: Ia4deca20e2d79fda81eb1a0fcadedf38b887b093
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533057Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Commit-Queue: My Nguyen <myy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828444}
parent 46318321
...@@ -66,10 +66,7 @@ bool AutocorrectManager::OnKeyEvent( ...@@ -66,10 +66,7 @@ bool AutocorrectManager::OnKeyEvent(
} }
void AutocorrectManager::ClearUnderline() { void AutocorrectManager::ClearUnderline() {
engine_->SetAutocorrectRange(/*autocorrect text=*/base::string16(), engine_->ClearAutocorrectRange();
/*start=*/0,
/*end=*/std::numeric_limits<uint32_t>::max());
// TODO(b/171924347): expose engine->clearAutocorrectRange() and use it here.
} }
void AutocorrectManager::OnSurroundingTextChanged(const base::string16& text, void AutocorrectManager::OnSurroundingTextChanged(const base::string16& text,
......
...@@ -490,6 +490,14 @@ bool InputMethodEngine::SetAutocorrectRange( ...@@ -490,6 +490,14 @@ bool InputMethodEngine::SetAutocorrectRange(
return input_context->SetAutocorrectRange(autocorrect_text, start, end); return input_context->SetAutocorrectRange(autocorrect_text, start, end);
} }
void InputMethodEngine::ClearAutocorrectRange() {
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
if (!input_context)
return;
return input_context->ClearAutocorrectRange();
}
bool InputMethodEngine::SetSelectionRange(uint32_t start, uint32_t end) { bool InputMethodEngine::SetSelectionRange(uint32_t start, uint32_t end) {
ui::IMEInputContextHandlerInterface* input_context = ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler(); ui::IMEBridge::Get()->GetInputContextHandler();
......
...@@ -186,6 +186,7 @@ class InputMethodEngine : public InputMethodEngineBase, ...@@ -186,6 +186,7 @@ class InputMethodEngine : public InputMethodEngineBase,
uint32_t end) override; uint32_t end) override;
gfx::Range GetAutocorrectRange() override; gfx::Range GetAutocorrectRange() override;
void ClearAutocorrectRange() override;
private: private:
// InputMethodEngineBase: // InputMethodEngineBase:
......
...@@ -231,6 +231,8 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface, ...@@ -231,6 +231,8 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface,
int end, int end,
std::string* error); std::string* error);
virtual void ClearAutocorrectRange() = 0;
// Set the current selection range. // Set the current selection range.
bool SetSelectionRange(int context_id, bool SetSelectionRange(int context_id,
int start, int start,
......
...@@ -41,6 +41,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) IMEInputContextHandlerInterface { ...@@ -41,6 +41,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) IMEInputContextHandlerInterface {
virtual bool SetAutocorrectRange(const base::string16& autocorrect_text, virtual bool SetAutocorrectRange(const base::string16& autocorrect_text,
uint32_t start, uint32_t start,
uint32_t end) = 0; uint32_t end) = 0;
virtual void ClearAutocorrectRange() = 0;
// Called when the engine changes the selection range. // Called when the engine changes the selection range.
// Returns true if the operation was successful. // Returns true if the operation was successful.
......
...@@ -318,7 +318,7 @@ void InputMethodChromeOS::OnWillChangeFocusedClient( ...@@ -318,7 +318,7 @@ void InputMethodChromeOS::OnWillChangeFocusedClient(
gfx::Range text_range; gfx::Range text_range;
if (focused_before && focused_before->GetTextRange(&text_range)) { if (focused_before && focused_before->GetTextRange(&text_range)) {
// This is currently only implemented in RenderWidgetHostViewAura. // This is currently only implemented in RenderWidgetHostViewAura.
focused_before->SetAutocorrectRange(base::EmptyString16(), text_range); focused_before->ClearAutocorrectRange();
} }
if (GetEngine()) if (GetEngine())
...@@ -417,6 +417,13 @@ bool InputMethodChromeOS::SetAutocorrectRange( ...@@ -417,6 +417,13 @@ bool InputMethodChromeOS::SetAutocorrectRange(
gfx::Range(start, end)); gfx::Range(start, end));
} }
void InputMethodChromeOS::ClearAutocorrectRange() {
if (IsTextInputTypeNone())
return;
// This is currently only implemented in RenderWidgetHostViewAura.
return GetTextInputClient()->ClearAutocorrectRange();
}
bool InputMethodChromeOS::SetSelectionRange(uint32_t start, uint32_t end) { bool InputMethodChromeOS::SetSelectionRange(uint32_t start, uint32_t end) {
if (IsTextInputTypeNone()) if (IsTextInputTypeNone())
return false; return false;
......
...@@ -67,6 +67,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodChromeOS ...@@ -67,6 +67,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodChromeOS
bool SetAutocorrectRange(const base::string16& autocorrect_text, bool SetAutocorrectRange(const base::string16& autocorrect_text,
uint32_t start, uint32_t start,
uint32_t end) override; uint32_t end) override;
void ClearAutocorrectRange() override;
bool SetSelectionRange(uint32_t start, uint32_t end) override; bool SetSelectionRange(uint32_t start, uint32_t end) override;
void UpdateCompositionText(const CompositionText& text, void UpdateCompositionText(const CompositionText& text,
uint32_t cursor_pos, uint32_t cursor_pos,
......
...@@ -72,6 +72,8 @@ bool MockIMEInputContextHandler::SetAutocorrectRange( ...@@ -72,6 +72,8 @@ bool MockIMEInputContextHandler::SetAutocorrectRange(
return false; return false;
} }
void MockIMEInputContextHandler::ClearAutocorrectRange() {}
bool MockIMEInputContextHandler::SetSelectionRange(uint32_t start, bool MockIMEInputContextHandler::SetSelectionRange(uint32_t start,
uint32_t end) { uint32_t end) {
++set_selection_range_call_count_; ++set_selection_range_call_count_;
......
...@@ -51,6 +51,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) MockIMEInputContextHandler ...@@ -51,6 +51,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) MockIMEInputContextHandler
bool SetAutocorrectRange(const base::string16& autocorrect_text, bool SetAutocorrectRange(const base::string16& autocorrect_text,
uint32_t start, uint32_t start,
uint32_t end) override; uint32_t end) override;
void ClearAutocorrectRange() override;
bool SetSelectionRange(uint32_t start, uint32_t end) override; bool SetSelectionRange(uint32_t start, uint32_t end) override;
void DeleteSurroundingText(int32_t offset, uint32_t length) override; void DeleteSurroundingText(int32_t offset, uint32_t length) override;
SurroundingTextInfo GetSurroundingTextInfo() override; SurroundingTextInfo GetSurroundingTextInfo() override;
......
...@@ -175,7 +175,9 @@ bool DummyTextInputClient::SetAutocorrectRange( ...@@ -175,7 +175,9 @@ bool DummyTextInputClient::SetAutocorrectRange(
return true; return true;
} }
void DummyTextInputClient::ClearAutocorrectRange() {} void DummyTextInputClient::ClearAutocorrectRange() {
autocorrect_range_ = gfx::Range();
}
#endif #endif
......
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