Chromium Code Reviews| 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..15f6d4c1304ded446dc883ca47a2a98d95e89801 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,44 @@ 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_; |
|
oshima
2015/05/14 15:37:22
nit: new line before DISALLOW...
bshe
2015/05/15 16:10:41
Done.
|
| + DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerObserver); |
| +}; |
| + |
| } // namespace |
| AshKeyboardControllerProxy::AshKeyboardControllerProxy( |
| @@ -76,7 +115,9 @@ AshKeyboardControllerProxy::AshKeyboardControllerProxy( |
| : keyboard::KeyboardControllerProxy(context) { |
| } |
| -AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {} |
| +AshKeyboardControllerProxy::~AshKeyboardControllerProxy() { |
| + keyboard_controller_->RemoveObserver(observer_.get()); |
|
oshima
2015/05/14 15:37:22
looks like the proxy is owned by controller, so th
bshe
2015/05/15 15:32:51
What do you think of letting ChromeShellDelegate o
sadrul
2015/05/15 15:37:00
How about calling proxy->SetController(nullptr) fr
bshe
2015/05/15 16:10:41
called proxy_.reset() directly. Otherwise, I need
|
| +} |
| void AshKeyboardControllerProxy::OnRequest( |
| const ExtensionHostMsg_Request_Params& params) { |
| @@ -123,6 +164,13 @@ extensions::WindowController* |
| return NULL; |
| } |
| +void AshKeyboardControllerProxy::SetController( |
| + keyboard::KeyboardController* controller) { |
| + keyboard_controller_ = controller; |
| + observer_.reset(new AshKeyboardControllerObserver(browser_context())); |
| + keyboard_controller_->AddObserver(observer_.get()); |
| +} |
| + |
| content::WebContents* |
| AshKeyboardControllerProxy::GetAssociatedWebContents() const { |
| return web_contents(); |