diff options
author | bshe <bshe@chromium.org> | 2015-05-15 12:38:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-15 19:39:04 +0000 |
commit | 2b52cba3b5a831c466311faba812d51ddd532ba5 (patch) | |
tree | 0dd3cb98471d86af81dcd609a9d272687a414887 | |
parent | 349704cec73c9b5a377827313860d178b062fb8c (diff) | |
download | chromium_src-2b52cba3b5a831c466311faba812d51ddd532ba5.zip chromium_src-2b52cba3b5a831c466311faba812d51ddd532ba5.tar.gz chromium_src-2b52cba3b5a831c466311faba812d51ddd532ba5.tar.bz2 |
Implements onBoundsChanged event in virtualKeyboardPrivate namespace
BUG=484699
Review URL: https://codereview.chromium.org/1128173003
Cr-Commit-Position: refs/heads/master@{#330169}
-rw-r--r-- | chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc | 56 | ||||
-rw-r--r-- | chrome/browser/ui/ash/ash_keyboard_controller_proxy.h | 8 | ||||
-rw-r--r-- | extensions/common/api/virtual_keyboard_private.json | 24 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller.cc | 2 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_proxy.h | 7 |
5 files changed, 95 insertions, 2 deletions
diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc index d999706..0b79244 100644 --- a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc +++ b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc @@ -26,6 +26,7 @@ #include "ui/aura/window_event_dispatcher.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/keyboard/keyboard_controller.h" +#include "ui/keyboard/keyboard_controller_observer.h" namespace virtual_keyboard_private = extensions::core_api::virtual_keyboard_private; @@ -69,6 +70,43 @@ TextInputTypeToGeneratedInputTypeEnum(ui::TextInputType type) { return virtual_keyboard_private::ON_TEXT_INPUT_BOX_FOCUSED_TYPE_NONE; } +class AshKeyboardControllerObserver + : public keyboard::KeyboardControllerObserver { + public: + explicit AshKeyboardControllerObserver(content::BrowserContext* context) + : context_(context) {} + ~AshKeyboardControllerObserver() override {} + + // KeyboardControllerObserver overrides: + void OnKeyboardBoundsChanging(const gfx::Rect& bounds) override { + extensions::EventRouter* router = extensions::EventRouter::Get(context_); + + if (!router->HasEventListener( + virtual_keyboard_private::OnBoundsChanged::kEventName)) { + return; + } + + scoped_ptr<base::ListValue> event_args(new base::ListValue()); + scoped_ptr<base::DictionaryValue> new_bounds(new base::DictionaryValue()); + new_bounds->SetInteger("left", bounds.x()); + new_bounds->SetInteger("top", bounds.y()); + new_bounds->SetInteger("width", bounds.width()); + new_bounds->SetInteger("height", bounds.height()); + event_args->Append(new_bounds.release()); + + scoped_ptr<extensions::Event> event(new extensions::Event( + virtual_keyboard_private::OnBoundsChanged::kEventName, + event_args.Pass())); + event->restrict_to_browser_context = context_; + router->BroadcastEvent(event.Pass()); + } + + private: + content::BrowserContext* context_; + + DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerObserver); +}; + } // namespace AshKeyboardControllerProxy::AshKeyboardControllerProxy( @@ -76,7 +114,9 @@ AshKeyboardControllerProxy::AshKeyboardControllerProxy( : keyboard::KeyboardControllerProxy(context) { } -AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {} +AshKeyboardControllerProxy::~AshKeyboardControllerProxy() { + DCHECK(!keyboard_controller_); +} void AshKeyboardControllerProxy::OnRequest( const ExtensionHostMsg_Request_Params& params) { @@ -123,6 +163,20 @@ extensions::WindowController* return NULL; } +void AshKeyboardControllerProxy::SetController( + keyboard::KeyboardController* controller) { + // During KeyboardController destruction, controller can be set to null. + if (!controller) { + DCHECK(keyboard_controller_); + keyboard_controller_->RemoveObserver(observer_.get()); + keyboard_controller_ = nullptr; + return; + } + keyboard_controller_ = controller; + observer_.reset(new AshKeyboardControllerObserver(browser_context())); + keyboard_controller_->AddObserver(observer_.get()); +} + content::WebContents* AshKeyboardControllerProxy::GetAssociatedWebContents() const { return web_contents(); diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h index 40b4777..64c042c 100644 --- a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h +++ b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h @@ -22,6 +22,10 @@ class WindowController; namespace gfx { class Rect; } +namespace keyboard { +class KeyboardController; +class KeyboardControllerObserver; +} namespace ui { class InputMethod; } @@ -46,6 +50,7 @@ class AshKeyboardControllerProxy const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) override; void SetupWebContents(content::WebContents* contents) override; + void SetController(keyboard::KeyboardController* controller) override; void ShowKeyboardContainer(aura::Window* container) override; // The overridden implementation dispatches @@ -65,8 +70,11 @@ class AshKeyboardControllerProxy bool OnMessageReceived(const IPC::Message& message) override; void RenderViewCreated(content::RenderViewHost* render_view_host) override; + keyboard::KeyboardController* keyboard_controller_; + scoped_ptr<extensions::ExtensionFunctionDispatcher> extension_function_dispatcher_; + scoped_ptr<keyboard::KeyboardControllerObserver> observer_; DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerProxy); }; diff --git a/extensions/common/api/virtual_keyboard_private.json b/extensions/common/api/virtual_keyboard_private.json index 71bdd0e..f8dd826 100644 --- a/extensions/common/api/virtual_keyboard_private.json +++ b/extensions/common/api/virtual_keyboard_private.json @@ -39,7 +39,17 @@ "type": "string", "description": "The value of type attribute of the focused text input box.", "enum": ["text", "number", "password", "date", "url", "tel", "email"] - } + }, + { + "id": "Bounds", + "type": "object", + "properties": { + "left": {"type": "integer", "description": "The position of the virtual keyboard window's left edge."}, + "top": {"type": "integer", "description": "The position of the virtual keyboard window's top edge."}, + "width": {"type": "integer", "description": "The width of the virtual keyboard window."}, + "height": {"type": "integer", "description": "The height of the virtual keyboard window."} + } + } ], "functions": [ { @@ -208,6 +218,18 @@ } } ] + }, + { + "name": "onBoundsChanged", + "type": "function", + "description": "This event is sent when virtual keyboard bounds changed and overscroll/resize is enabled.", + "parameters": [ + { + "name": "bounds", + "description": "The virtual keyboard bounds", + "$ref": "Bounds" + } + ] } ] } diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc index a085c53..351cf57 100644 --- a/ui/keyboard/keyboard_controller.cc +++ b/ui/keyboard/keyboard_controller.cc @@ -211,6 +211,7 @@ KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) input_method_ = proxy_->GetInputMethod(); input_method_->AddObserver(this); window_bounds_observer_.reset(new WindowBoundsChangeObserver()); + proxy_->SetController(this); } KeyboardController::~KeyboardController() { @@ -222,6 +223,7 @@ KeyboardController::~KeyboardController() { if (input_method_) input_method_->RemoveObserver(this); ResetWindowInsets(); + proxy_->SetController(nullptr); } // static diff --git a/ui/keyboard/keyboard_controller_proxy.h b/ui/keyboard/keyboard_controller_proxy.h index 2c91446..f927849 100644 --- a/ui/keyboard/keyboard_controller_proxy.h +++ b/ui/keyboard/keyboard_controller_proxy.h @@ -31,6 +31,8 @@ class Shadow; namespace keyboard { +class KeyboardController; + // A proxy used by the KeyboardController to get access to the virtual // keyboard window. class KEYBOARD_EXPORT KeyboardControllerProxy : public aura::WindowObserver { @@ -101,6 +103,11 @@ class KEYBOARD_EXPORT KeyboardControllerProxy : public aura::WindowObserver { // provide one. virtual void ReloadKeyboardIfNeeded(); + // KeyboardController owns KeyboardControllerProxy so KeyboardControllerProxy + // or its subclasses should not take ownership of the |controller|. + // |controller| can be null when KeyboardController is destroying. + virtual void SetController(KeyboardController* controller) {} + protected: // The implementation can choose to setup the WebContents before the virtual // keyboard page is loaded (e.g. install a WebContentsObserver). |