Commit 5593f24a authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Commit Bot

Add RequestHideIme() mojo API to ime.mojom.

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: default avatarMattias Nissler <mnissler@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarBlake O'Hare <blakeo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551379}
parent bd4ae558
......@@ -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;
......@@ -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);
......@@ -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
......
......@@ -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.
......
......@@ -162,4 +162,8 @@ void ArcImeBridgeImpl::OnCursorRectChangedWithSurroundingText(
is_screen_coordinates);
}
void ArcImeBridgeImpl::RequestHideIme() {
delegate_->RequestHideIme();
}
} // namespace arc
......@@ -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_;
......
......@@ -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(
......
......@@ -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(
......
......@@ -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_) {
......@@ -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;
......
......@@ -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);
......
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