Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc

Issue 1128173003: Implements onBoundsChanged event in virtualKeyboardPrivate namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc
diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc
index d999706b58b87e73bf78a5f61c3080e8d785a4ec..0b792444a3fa4d5dc38c59a37624375362c87387 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();
« no previous file with comments | « chrome/browser/ui/ash/ash_keyboard_controller_proxy.h ('k') | extensions/common/api/virtual_keyboard_private.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698