Commit 2b52cba3 authored by bshe's avatar bshe Committed by Commit bot

Implements onBoundsChanged event in virtualKeyboardPrivate namespace

BUG=484699

Review URL: https://codereview.chromium.org/1128173003

Cr-Commit-Position: refs/heads/master@{#330169}
parent 349704ce
......@@ -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();
......
......@@ -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);
};
......
......@@ -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"
}
]
}
]
}
......
......@@ -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
......
......@@ -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).
......
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