Commit 0dbe34ab authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

KeyoardController: Use composition for InputMethodKeyboardController

This simplifies the public KeybardController interface and helps
prepare for supporting different InputMethodKeyboardController options
in Mash.

Bug: 845780
Change-Id: I8d857ca67c8ea57de76036ae1487abd9dbbbd91a
Reviewed-on: https://chromium-review.googlesource.com/c/1337287Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609412}
parent d258b6fb
...@@ -1393,13 +1393,17 @@ void InputMethodManagerImpl::NotifyObserversImeExtraInputStateChange() { ...@@ -1393,13 +1393,17 @@ void InputMethodManagerImpl::NotifyObserversImeExtraInputStateChange() {
ui::InputMethodKeyboardController* ui::InputMethodKeyboardController*
InputMethodManagerImpl::GetInputMethodKeyboardController() { InputMethodManagerImpl::GetInputMethodKeyboardController() {
// TODO(stevenjb/shuchen): Fix this for Mash. https://crbug.com/756059
if (features::IsMultiProcessMash())
return nullptr;
// Callers expect a nullptr when the keyboard is disabled. See // Callers expect a nullptr when the keyboard is disabled. See
// https://crbug.com/850020. TODO(stevenjb/shuchen): Fix this for Mash. // https://crbug.com/850020.
// https://crbug.com/756059 if (!keyboard::KeyboardController::HasInstance() ||
return keyboard::KeyboardController::HasInstance() && !keyboard::KeyboardController::Get()->IsEnabled()) {
keyboard::KeyboardController::Get()->IsEnabled() return nullptr;
? keyboard::KeyboardController::Get() }
: nullptr; return keyboard::KeyboardController::Get()
->input_method_keyboard_controller();
} }
void InputMethodManagerImpl::ReloadKeyboard() { void InputMethodManagerImpl::ReloadKeyboard() {
......
...@@ -149,6 +149,47 @@ void LogKeyboardControlEvent(KeyboardControlEvent event) { ...@@ -149,6 +149,47 @@ void LogKeyboardControlEvent(KeyboardControlEvent event) {
KEYBOARD_CONTROL_MAX); KEYBOARD_CONTROL_MAX);
} }
class InputMethodKeyboardController : public ui::InputMethodKeyboardController {
public:
explicit InputMethodKeyboardController(
KeyboardController* keyboard_controller)
: keyboard_controller_(keyboard_controller) {}
~InputMethodKeyboardController() override = default;
// ui::InputMethodKeyboardController
bool DisplayVirtualKeyboard() override {
// Calling |ShowKeyboardInternal| may move the keyboard to another display.
if (keyboard_controller_->IsKeyboardEnableRequested() &&
!keyboard_controller_->keyboard_locked()) {
keyboard_controller_->ShowKeyboard(false /* locked */);
return true;
}
return false;
}
void DismissVirtualKeyboard() override {
keyboard_controller_->HideKeyboardByUser();
}
void AddObserver(
ui::InputMethodKeyboardControllerObserver* observer) override {
// TODO: Implement.
}
void RemoveObserver(
ui::InputMethodKeyboardControllerObserver* observer) override {
// TODO: Implement.
}
bool IsKeyboardVisible() override {
return keyboard_controller_->IsKeyboardVisible();
}
private:
KeyboardController* keyboard_controller_;
};
} // namespace } // namespace
// Observer for both keyboard show and hide animations. It should be owned by // Observer for both keyboard show and hide animations. It should be owned by
...@@ -178,7 +219,9 @@ class CallbackAnimationObserver : public ui::ImplicitAnimationObserver { ...@@ -178,7 +219,9 @@ class CallbackAnimationObserver : public ui::ImplicitAnimationObserver {
}; };
KeyboardController::KeyboardController() KeyboardController::KeyboardController()
: ime_observer_(this), : input_method_keyboard_controller_(
std::make_unique<InputMethodKeyboardController>(this)),
ime_observer_(this),
weak_factory_report_lingering_state_(this), weak_factory_report_lingering_state_(this),
weak_factory_will_hide_(this) { weak_factory_will_hide_(this) {
DCHECK_EQ(g_keyboard_controller, nullptr); DCHECK_EQ(g_keyboard_controller, nullptr);
...@@ -577,10 +620,6 @@ void KeyboardController::HideKeyboardImplicitlyBySystem() { ...@@ -577,10 +620,6 @@ void KeyboardController::HideKeyboardImplicitlyBySystem() {
base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs));
} }
void KeyboardController::DismissVirtualKeyboard() {
HideKeyboardByUser();
}
// private // private
void KeyboardController::HideAnimationFinished() { void KeyboardController::HideAnimationFinished() {
if (state_ == KeyboardControllerState::HIDDEN) { if (state_ == KeyboardControllerState::HIDDEN) {
...@@ -1041,26 +1080,6 @@ void KeyboardController::SetDraggableArea(const gfx::Rect& rect) { ...@@ -1041,26 +1080,6 @@ void KeyboardController::SetDraggableArea(const gfx::Rect& rect) {
container_behavior_->SetDraggableArea(rect); container_behavior_->SetDraggableArea(rect);
} }
// InputMethodKeyboardController overrides:
bool KeyboardController::DisplayVirtualKeyboard() {
// Calling |ShowKeyboardInternal| may move the keyboard to another display.
if (keyboard::IsKeyboardEnabled() && !keyboard_locked_) {
ShowKeyboardInternal(display::Display());
return true;
}
return false;
}
void KeyboardController::AddObserver(
ui::InputMethodKeyboardControllerObserver* observer) {
// TODO: Implement me
}
void KeyboardController::RemoveObserver(
ui::InputMethodKeyboardControllerObserver* observer) {
// TODO: Implement me
}
bool KeyboardController::IsKeyboardVisible() { bool KeyboardController::IsKeyboardVisible() {
if (state_ == KeyboardControllerState::SHOWN) { if (state_ == KeyboardControllerState::SHOWN) {
DCHECK(IsEnabled()); DCHECK(IsEnabled());
......
...@@ -69,10 +69,8 @@ enum class KeyboardControllerState { ...@@ -69,10 +69,8 @@ enum class KeyboardControllerState {
// Provides control of the virtual keyboard, including enabling/disabling the // Provides control of the virtual keyboard, including enabling/disabling the
// keyboard and controlling its visibility. // keyboard and controlling its visibility.
class KEYBOARD_EXPORT KeyboardController class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
: public ui::InputMethodObserver,
public aura::WindowObserver, public aura::WindowObserver,
public ui::InputMethodKeyboardController,
public ContainerBehavior::Delegate { public ContainerBehavior::Delegate {
public: public:
KeyboardController(); KeyboardController();
...@@ -240,14 +238,11 @@ class KEYBOARD_EXPORT KeyboardController ...@@ -240,14 +238,11 @@ class KEYBOARD_EXPORT KeyboardController
// Sets floating keyboard draggable rect. // Sets floating keyboard draggable rect.
void SetDraggableArea(const gfx::Rect& rect); void SetDraggableArea(const gfx::Rect& rect);
// InputMethodKeyboardController overrides: bool IsKeyboardVisible();
bool DisplayVirtualKeyboard() override;
void DismissVirtualKeyboard() override; ui::InputMethodKeyboardController* input_method_keyboard_controller() {
void AddObserver( return input_method_keyboard_controller_.get();
ui::InputMethodKeyboardControllerObserver* observer) override; }
void RemoveObserver(
ui::InputMethodKeyboardControllerObserver* observer) override;
bool IsKeyboardVisible() override;
bool keyboard_locked() const { return keyboard_locked_; } bool keyboard_locked() const { return keyboard_locked_; }
void set_keyboard_locked(bool lock) { keyboard_locked_ = lock; } void set_keyboard_locked(bool lock) { keyboard_locked_ = lock; }
...@@ -385,6 +380,8 @@ class KEYBOARD_EXPORT KeyboardController ...@@ -385,6 +380,8 @@ class KEYBOARD_EXPORT KeyboardController
void MarkKeyboardLoadFinished(); void MarkKeyboardLoadFinished();
std::unique_ptr<KeyboardUI> ui_; std::unique_ptr<KeyboardUI> ui_;
std::unique_ptr<ui::InputMethodKeyboardController>
input_method_keyboard_controller_;
KeyboardLayoutDelegate* layout_delegate_ = nullptr; KeyboardLayoutDelegate* layout_delegate_ = nullptr;
ScopedObserver<ui::InputMethod, ui::InputMethodObserver> ime_observer_; ScopedObserver<ui::InputMethod, ui::InputMethodObserver> ime_observer_;
......
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