Chromium Code Reviews| Index: components/arc/ime/arc_ime_service.cc |
| diff --git a/components/arc/ime/arc_ime_service.cc b/components/arc/ime/arc_ime_service.cc |
| index 9259f31aad29e083415249ddb1dc897270a5f615..a52d67f1c8ae976158b64c1de6ac734f900df12c 100644 |
| --- a/components/arc/ime/arc_ime_service.cc |
| +++ b/components/arc/ime/arc_ime_service.cc |
| @@ -18,6 +18,7 @@ |
| #include "ui/events/base_event_utils.h" |
| #include "ui/events/event.h" |
| #include "ui/events/keycodes/keyboard_codes.h" |
| +#include "ui/gfx/range/range.h" |
| namespace arc { |
| @@ -209,6 +210,7 @@ void ArcImeService::OnTextInputTypeChanged(ui::TextInputType type) { |
| } |
| void ArcImeService::OnCursorRectChanged(const gfx::Rect& rect) { |
| + InvalidateSurroundingTextAndSelectionRange(); |
| if (cursor_rect_ == rect) |
| return; |
| cursor_rect_ = rect; |
| @@ -219,6 +221,7 @@ void ArcImeService::OnCursorRectChanged(const gfx::Rect& rect) { |
| } |
| void ArcImeService::OnCancelComposition() { |
| + InvalidateSurroundingTextAndSelectionRange(); |
| ui::InputMethod* const input_method = GetInputMethod(); |
| if (input_method) |
| input_method->CancelComposition(this); |
| @@ -231,6 +234,23 @@ void ArcImeService::ShowImeIfNeeded() { |
| } |
| } |
| +void ArcImeService::OnCursorRectChangedWithSurroundingText( |
| + const gfx::Rect& rect, |
| + const gfx::Range& text_range, |
| + const base::string16& text_in_range, |
| + const gfx::Range& selection_range) { |
| + if (cursor_rect_ == rect) |
| + return; |
|
kinaba
2017/05/15 07:55:18
Can't there be a case that the rects are the same
yhanada
2017/05/15 08:06:38
It is possible. I changed to save the text and the
|
| + cursor_rect_ = rect; |
| + text_range_ = text_range; |
| + text_in_range_ = text_in_range; |
| + selection_range_ = selection_range; |
| + |
| + ui::InputMethod* const input_method = GetInputMethod(); |
| + if (input_method) |
| + input_method->OnCaretBoundsChanged(this); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // Overridden from keyboard::KeyboardControllerObserver |
| void ArcImeService::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| @@ -250,16 +270,19 @@ void ArcImeService::OnKeyboardClosed() {} |
| void ArcImeService::SetCompositionText( |
| const ui::CompositionText& composition) { |
| + InvalidateSurroundingTextAndSelectionRange(); |
| has_composition_text_ = !composition.text.empty(); |
| ime_bridge_->SendSetCompositionText(composition); |
| } |
| void ArcImeService::ConfirmCompositionText() { |
| + InvalidateSurroundingTextAndSelectionRange(); |
| has_composition_text_ = false; |
| ime_bridge_->SendConfirmCompositionText(); |
| } |
| void ArcImeService::ClearCompositionText() { |
| + InvalidateSurroundingTextAndSelectionRange(); |
| if (has_composition_text_) { |
| has_composition_text_ = false; |
| ime_bridge_->SendInsertText(base::string16()); |
| @@ -267,6 +290,7 @@ void ArcImeService::ClearCompositionText() { |
| } |
| void ArcImeService::InsertText(const base::string16& text) { |
| + InvalidateSurroundingTextAndSelectionRange(); |
| has_composition_text_ = false; |
| ime_bridge_->SendInsertText(text); |
| } |
| @@ -278,6 +302,8 @@ void ArcImeService::InsertChar(const ui::KeyEvent& event) { |
| if (ime_type_ == ui::TEXT_INPUT_TYPE_NONE) |
| return; |
| + InvalidateSurroundingTextAndSelectionRange(); |
| + |
| // For apps that doesn't handle hardware keyboard events well, keys that are |
| // typically on software keyboard and lack of them are fatal, namely, |
| // unmodified enter and backspace keys are sent through IME. |
| @@ -337,6 +363,32 @@ gfx::Rect ArcImeService::GetCaretBounds() const { |
| return converted; |
| } |
| +bool ArcImeService::GetTextRange(gfx::Range* range) const { |
| + if (!text_range_.IsValid()) |
| + return false; |
| + *range = text_range_; |
| + return true; |
| +} |
| + |
| +bool ArcImeService::GetSelectionRange(gfx::Range* range) const { |
| + if (!selection_range_.IsValid()) |
| + return false; |
| + *range = selection_range_; |
| + return true; |
| +} |
| + |
| +bool ArcImeService::GetTextFromRange(const gfx::Range& range, |
| + base::string16* text) const { |
| + // It's supposed that this method is called only from |
| + // InputMethod::OnCaretBoundsChanged(). In that method, the range obtained |
| + // from GetTextRange() is used as the argument of this method. To prevent an |
| + // unexpected usage, the check, |range != text_range_|, is added. |
| + if (!text_range_.IsValid() || range != text_range_) |
| + return false; |
| + *text = text_in_range_; |
| + return true; |
| +} |
| + |
| ui::TextInputMode ArcImeService::GetTextInputMode() const { |
| return ui::TEXT_INPUT_MODE_DEFAULT; |
| } |
| @@ -366,18 +418,10 @@ bool ArcImeService::HasCompositionText() const { |
| return has_composition_text_; |
| } |
| -bool ArcImeService::GetTextRange(gfx::Range* range) const { |
| - return false; |
| -} |
| - |
| bool ArcImeService::GetCompositionTextRange(gfx::Range* range) const { |
| return false; |
| } |
| -bool ArcImeService::GetSelectionRange(gfx::Range* range) const { |
| - return false; |
| -} |
| - |
| bool ArcImeService::SetSelectionRange(const gfx::Range& range) { |
| return false; |
| } |
| @@ -386,11 +430,6 @@ bool ArcImeService::DeleteRange(const gfx::Range& range) { |
| return false; |
| } |
| -bool ArcImeService::GetTextFromRange( |
| - const gfx::Range& range, base::string16* text) const { |
| - return false; |
| -} |
| - |
| bool ArcImeService::ChangeTextDirectionAndLayoutAlignment( |
| base::i18n::TextDirection direction) { |
| return false; |
| @@ -401,4 +440,10 @@ bool ArcImeService::IsTextEditCommandEnabled( |
| return false; |
| } |
| +void ArcImeService::InvalidateSurroundingTextAndSelectionRange() { |
| + text_range_ = gfx::Range::InvalidRange(); |
| + text_in_range_ = base::string16(); |
| + selection_range_ = gfx::Range::InvalidRange(); |
| +} |
| + |
| } // namespace arc |