summaryrefslogtreecommitdiffstats
path: root/ui/keyboard
diff options
context:
space:
mode:
authorbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-12 18:08:35 +0000
committerbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-12 18:08:35 +0000
commit96e76080d2d429aaad846dc6c44ca30267d52997 (patch)
tree476841cdf8d2206b24c1defdaadf07f1dd1eceab /ui/keyboard
parentb140c1e73ff3aaaef2233d73ea60029c4d914f91 (diff)
downloadchromium_src-96e76080d2d429aaad846dc6c44ca30267d52997.zip
chromium_src-96e76080d2d429aaad846dc6c44ca30267d52997.tar.gz
chromium_src-96e76080d2d429aaad846dc6c44ca30267d52997.tar.bz2
Control visibility of the virtual keyboard.
Add an observer to InputMethod. This makes the InputMethod the gatherer of text input state changes, which are then distributed to interested parties. The KeyboardController becomes an InputMethod::Observer, and shows/hides the keyboard as appropriate. BUG=227128 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=193662 Review URL: https://codereview.chromium.org/13207003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193965 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/keyboard')
-rw-r--r--ui/keyboard/keyboard_controller.cc28
-rw-r--r--ui/keyboard/keyboard_controller.h11
-rw-r--r--ui/keyboard/keyboard_controller_proxy.h8
-rw-r--r--ui/keyboard/keyboard_controller_unittest.cc10
4 files changed, 54 insertions, 3 deletions
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
index d4d3cec..cbfd4e2 100644
--- a/ui/keyboard/keyboard_controller.cc
+++ b/ui/keyboard/keyboard_controller.cc
@@ -8,6 +8,10 @@
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/hit_test.h"
+#include "ui/base/ime/input_method.h"
+#include "ui/base/ime/input_method_base.h"
+#include "ui/base/ime/text_input_client.h"
+#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/path.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/skia_util.h"
@@ -109,9 +113,12 @@ namespace keyboard {
KeyboardController::KeyboardController(KeyboardControllerProxy* proxy)
: proxy_(proxy), container_(NULL) {
CHECK(proxy);
+ proxy_->GetInputMethod()->AddObserver(this);
}
-KeyboardController::~KeyboardController() {}
+KeyboardController::~KeyboardController() {
+ proxy_->GetInputMethod()->RemoveObserver(this);
+}
aura::Window* KeyboardController::GetContainerWindow() {
if (!container_) {
@@ -125,8 +132,27 @@ aura::Window* KeyboardController::GetContainerWindow() {
container_->SetLayoutManager(
new KeyboardLayoutManager(container_, keyboard));
container_->AddChild(keyboard);
+
+ OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient());
}
return container_;
}
+void KeyboardController::OnTextInputStateChanged(
+ const ui::TextInputClient* client) {
+ if (!container_)
+ return;
+
+ if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
+ container_->Hide();
+ } else {
+ container_->parent()->StackChildAtTop(container_);
+ container_->Show();
+ }
+
+ // TODO(bryeung): whenever the TextInputClient changes we need to notify the
+ // keyboard (with the TextInputType) so that it can reset it's state (e.g.
+ // abandon compositions in progress)
+}
+
} // namespace keyboard
diff --git a/ui/keyboard/keyboard_controller.h b/ui/keyboard/keyboard_controller.h
index 408a71f..5d5939e9 100644
--- a/ui/keyboard/keyboard_controller.h
+++ b/ui/keyboard/keyboard_controller.h
@@ -7,19 +7,24 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "ui/base/ime/input_method_observer.h"
#include "ui/keyboard/keyboard_export.h"
namespace aura {
class Window;
}
+namespace ui {
+class TextInputClient;
+}
+
namespace keyboard {
class KeyboardControllerProxy;
// Provides control of the virtual keyboard, including providing a container,
// managing object lifetimes and controlling visibility.
-class KEYBOARD_EXPORT KeyboardController {
+class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver {
public:
// Takes ownership of |proxy|.
explicit KeyboardController(KeyboardControllerProxy* proxy);
@@ -29,6 +34,10 @@ class KEYBOARD_EXPORT KeyboardController {
// It is the responsibility of the caller to Show() the returned window.
aura::Window* GetContainerWindow();
+ // InputMethodObserver overrides
+ virtual void OnTextInputStateChanged(
+ const ui::TextInputClient* client) OVERRIDE;
+
private:
scoped_ptr<KeyboardControllerProxy> proxy_;
aura::Window* container_;
diff --git a/ui/keyboard/keyboard_controller_proxy.h b/ui/keyboard/keyboard_controller_proxy.h
index e1783a4d..a656e06 100644
--- a/ui/keyboard/keyboard_controller_proxy.h
+++ b/ui/keyboard/keyboard_controller_proxy.h
@@ -11,6 +11,10 @@ namespace aura {
class Window;
}
+namespace ui {
+class InputMethod;
+}
+
namespace keyboard {
// A proxy used by the KeyboardController to get access to the virtual
@@ -22,6 +26,10 @@ class KEYBOARD_EXPORT KeyboardControllerProxy {
// Get the virtual keyboard window. Ownership of the returned Window remains
// with the proxy.
virtual aura::Window* GetKeyboardWindow() = 0;
+
+ // Get the InputMethod that will provide notifications about changes in the
+ // text input context.
+ virtual ui::InputMethod* GetInputMethod() = 0;
};
} // namespace keyboard
diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc
index 86f81ba..dc63e29 100644
--- a/ui/keyboard/keyboard_controller_unittest.cc
+++ b/ui/keyboard/keyboard_controller_unittest.cc
@@ -11,6 +11,8 @@
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
+#include "ui/base/ime/input_method.h"
+#include "ui/base/ime/mock_input_method.h"
#include "ui/compositor/layer_type.h"
#include "ui/gfx/rect.h"
#include "ui/keyboard/keyboard_controller.h"
@@ -74,7 +76,9 @@ class KeyboardControllerTest : public testing::Test {
class TestKeyboardControllerProxy : public KeyboardControllerProxy {
public:
- TestKeyboardControllerProxy() : window_(new aura::Window(&delegate_)) {
+ TestKeyboardControllerProxy()
+ : window_(new aura::Window(&delegate_)),
+ input_method_(new ui::MockInputMethod(NULL)) {
window_->Init(ui::LAYER_NOT_DRAWN);
window_->set_owned_by_parent(false);
}
@@ -86,10 +90,14 @@ class TestKeyboardControllerProxy : public KeyboardControllerProxy {
// Overridden from KeyboardControllerProxy:
virtual aura::Window* GetKeyboardWindow() OVERRIDE { return window_.get(); }
+ virtual ui::InputMethod* GetInputMethod() OVERRIDE {
+ return input_method_.get();
+ }
private:
scoped_ptr<aura::Window> window_;
aura::test::TestWindowDelegate delegate_;
+ scoped_ptr<ui::InputMethod> input_method_;
DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy);
};