Skip to content

Commit

Permalink
Add RequestHideIme() mojo API to ime.mojom.
Browse files Browse the repository at this point in the history
This CL adds the new mojo API and a method of KeyboardController to
request hiding the virtual keyboard if it's shown.
The difference between HideKeyboard() and RequestHideKeyboard()
is that the request made by RequestHideKeyboard() can be
canceled by focusing another text input field.

Bug: b:72456023
Change-Id: Ief7e48da3a249825fdddd48bdcb3aa20d379eec6
Reviewed-on: https://chromium-review.googlesource.com/1004881
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: Blake O'Hare <blakeo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551379}
  • Loading branch information
Yuichiro Hanada authored and Commit Bot committed Apr 17, 2018
1 parent bd4ae55 commit 5593f24
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
10 changes: 8 additions & 2 deletions components/arc/common/ime.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Next MinVersion: 9
// Next MinVersion: 10

module arc.mojom;

Expand Down Expand Up @@ -34,7 +34,7 @@ struct CompositionSegment {
bool emphasized;
};

// Next method ID: 4
// Next method ID: 6
interface ImeHost {
// Notifies Chrome that the text input focus is changed.
OnTextInputTypeChanged@0(TextInputType type);
Expand Down Expand Up @@ -75,6 +75,12 @@ interface ImeHost {
[MinVersion=8] bool is_screen_coordinates // Whether or not the |rect|
// are in screen coordinates.
);

// Requests Chrome to hide the virtual keyboard.
// Howver, hiding can be canceled if a text field gets focus.
// TODO(yhanada): We might be able to remove this method by adding an argument
// to OnTextInputTypeChanged().
[MinVersion=9] RequestHideIme@5();
};

// Next method ID: 7
Expand Down
1 change: 1 addition & 0 deletions components/arc/ime/arc_ime_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ArcImeBridge {
const base::string16& text_in_range,
const gfx::Range& selection_range,
bool is_screen_coordinates) = 0;
virtual void RequestHideIme() = 0;
};

// Serializes and sends IME related requests through IPCs.
Expand Down
4 changes: 4 additions & 0 deletions components/arc/ime/arc_ime_bridge_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,8 @@ void ArcImeBridgeImpl::OnCursorRectChangedWithSurroundingText(
is_screen_coordinates);
}

void ArcImeBridgeImpl::RequestHideIme() {
delegate_->RequestHideIme();
}

} // namespace arc
1 change: 1 addition & 0 deletions components/arc/ime/arc_ime_bridge_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ArcImeBridgeImpl : public ArcImeBridge, public mojom::ImeHost {
const std::string& text_in_range,
const gfx::Range& selection_range,
bool screen_coordinates) override;
void RequestHideIme() override;

private:
Delegate* const delegate_;
Expand Down
5 changes: 5 additions & 0 deletions components/arc/ime/arc_ime_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ void ArcImeService::OnCursorRectChangedWithSurroundingText(
input_method->OnCaretBoundsChanged(this);
}

void ArcImeService::RequestHideIme() {
if (keyboard_controller_)
keyboard_controller_->RequestHideKeyboard();
}

////////////////////////////////////////////////////////////////////////////////
// Overridden from keyboard::KeyboardControllerObserver
void ArcImeService::OnKeyboardAppearanceChanged(
Expand Down
1 change: 1 addition & 0 deletions components/arc/ime/arc_ime_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class ArcImeService : public KeyedService,
const base::string16& text_in_range,
const gfx::Range& selection_range,
bool is_screen_coordinates) override;
void RequestHideIme() override;

// Overridden from keyboard::KeyboardControllerObserver.
void OnKeyboardAppearanceChanged(
Expand Down
23 changes: 15 additions & 8 deletions ui/keyboard/keyboard_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,20 @@ void KeyboardController::HideKeyboard(HideReason reason) {
}
}

void KeyboardController::RequestHideKeyboard() {
if (state_ != KeyboardControllerState::SHOWN)
return;

ChangeState(KeyboardControllerState::WILL_HIDE);

base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&KeyboardController::HideKeyboard,
weak_factory_will_hide_.GetWeakPtr(),
HIDE_REASON_AUTOMATIC),
base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs));
}

void KeyboardController::HideAnimationFinished() {
if (state_ == KeyboardControllerState::HIDDEN) {
if (queued_container_type_) {
Expand Down Expand Up @@ -515,14 +529,7 @@ void KeyboardController::OnTextInputStateChanged(
show_on_content_update_ = false;
return;
case KeyboardControllerState::SHOWN:
ChangeState(KeyboardControllerState::WILL_HIDE);

base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&KeyboardController::HideKeyboard,
weak_factory_will_hide_.GetWeakPtr(),
HIDE_REASON_AUTOMATIC),
base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs));
RequestHideKeyboard();
return;
default:
return;
Expand Down
6 changes: 6 additions & 0 deletions ui/keyboard/keyboard_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
// false while closing the keyboard.
void HideKeyboard(HideReason reason);

// Requests the keyboard controller to hide virtual keyboard if it's shown.
// This request can be canceled by calling ShowKeyboard() or focusing
// another text input field within certain period. This method is no-op if
// it's called when virtual keyboard is hidden.
void RequestHideKeyboard();

// Force the keyboard to show up if not showing and lock the keyboard if
// |lock| is true.
void ShowKeyboard(bool lock);
Expand Down

0 comments on commit 5593f24

Please sign in to comment.