Chromium Code Reviews| Index: ui/keyboard/keyboard_controller.cc |
| diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc |
| index 0cb975f7d949ebb54311960524adc2f8317e3918..02f5a94dd201e9c3a4c38764b2153b251e8fbc92 100644 |
| --- a/ui/keyboard/keyboard_controller.cc |
| +++ b/ui/keyboard/keyboard_controller.cc |
| @@ -42,7 +42,8 @@ gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds) { |
| // The delegate deletes itself when the window is destroyed. |
| class KeyboardWindowDelegate : public aura::WindowDelegate { |
| public: |
| - KeyboardWindowDelegate() {} |
| + KeyboardWindowDelegate(keyboard::KeyboardControllerProxy* proxy) |
|
sadrul
2013/12/04 17:35:20
explicit
Shu Chen
2013/12/05 05:01:39
Done.
|
| + : proxy_(proxy) {} |
| virtual ~KeyboardWindowDelegate() {} |
| private: |
| @@ -73,13 +74,16 @@ class KeyboardWindowDelegate : public aura::WindowDelegate { |
| virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} |
| virtual bool HasHitTestMask() const OVERRIDE { return true; } |
| virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE { |
| - gfx::Rect keyboard_bounds = KeyboardBoundsFromWindowBounds(bounds_); |
| + gfx::Rect keyboard_bounds = proxy_ ? proxy_->GetKeyboardWindow()->bounds() |
| + : KeyboardBoundsFromWindowBounds(bounds_); |
| mask->addRect(RectToSkRect(keyboard_bounds)); |
| } |
| virtual void DidRecreateLayer(ui::Layer* old_layer, |
| ui::Layer* new_layer) OVERRIDE {} |
| gfx::Rect bounds_; |
| + keyboard::KeyboardControllerProxy* proxy_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(KeyboardWindowDelegate); |
| }; |
| @@ -92,17 +96,19 @@ namespace keyboard { |
| // owner window. |
| class KeyboardLayoutManager : public aura::LayoutManager { |
| public: |
| - KeyboardLayoutManager(aura::Window* container) |
| - : container_(container), keyboard_(NULL) { |
| - CHECK(container_); |
| + KeyboardLayoutManager(KeyboardController* controller) |
|
sadrul
2013/12/04 17:35:20
explicit here too
Shu Chen
2013/12/05 05:01:39
Done.
|
| + : controller_(controller), keyboard_(NULL) { |
| } |
| // Overridden from aura::LayoutManager |
| virtual void OnWindowResized() OVERRIDE { |
| if (!keyboard_) |
| return; |
| - SetChildBoundsDirect(keyboard_, |
| - KeyboardBoundsFromWindowBounds(container_->bounds())); |
| + gfx::Rect keyboard_bounds = KeyboardBoundsFromWindowBounds( |
| + controller_->GetContainerWindow()->bounds()); |
| + // Don't notify keyboard bounds changing, because the bounds has been |
| + // changed here. |
|
kevers
2013/12/04 15:18:28
Nit: Find this comment more confusing than helpful
sadrul
2013/12/04 17:35:20
+1
Shu Chen
2013/12/05 05:01:39
Done.
Shu Chen
2013/12/05 05:01:39
Done.
|
| + SetChildBoundsDirect(keyboard_, keyboard_bounds); |
|
sadrul
2013/12/04 17:35:20
We should not be doing this when proxy::resizing_f
Shu Chen
2013/12/05 05:01:39
I think it won't happen because the flag resizing_
|
| } |
| virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
| DCHECK(!keyboard_); |
| @@ -114,11 +120,19 @@ class KeyboardLayoutManager : public aura::LayoutManager { |
| bool visible) OVERRIDE {} |
| virtual void SetChildBounds(aura::Window* child, |
| const gfx::Rect& requested_bounds) OVERRIDE { |
| - // Drop these: the size should only be set in OnWindowResized. |
| + // SetChildBounds can be invoked by resizing from the container or by |
| + // resizing from the contents (through window.resizeTo call in JS). |
| + // OnWindowResized() can take care of resizing from the container. |
| + // While here should only take care of resizing from the contents. |
| + if (controller_->proxy()->resizing_from_contents()) { |
| + controller_->NotifyKeyboardBoundsChanging(requested_bounds); |
| + SetChildBoundsDirect(child, requested_bounds); |
| + controller_->proxy()->set_resizing_from_contents(false); |
|
sadrul
2013/12/04 17:35:20
Why reset here?
Shu Chen
2013/12/05 05:01:39
After finishing resizing the web content window, w
|
| + } |
|
sadrul
2013/12/04 17:35:20
I think you should just do keyboard_->SetBounds()
Shu Chen
2013/12/05 05:01:39
When resizing from contents, the code flow is WebC
|
| } |
| private: |
| - aura::Window* container_; |
| + KeyboardController* controller_; |
| aura::Window* keyboard_; |
| DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); |
| @@ -143,16 +157,26 @@ KeyboardController::~KeyboardController() { |
| aura::Window* KeyboardController::GetContainerWindow() { |
| if (!container_.get()) { |
| - container_.reset(new aura::Window(new KeyboardWindowDelegate())); |
| + container_.reset(new aura::Window( |
| + new KeyboardWindowDelegate(proxy_.get()))); |
| container_->SetName("KeyboardContainer"); |
| container_->set_owned_by_parent(false); |
| container_->Init(ui::LAYER_NOT_DRAWN); |
| container_->AddObserver(this); |
| - container_->SetLayoutManager(new KeyboardLayoutManager(container_.get())); |
| + container_->SetLayoutManager(new KeyboardLayoutManager(this)); |
| } |
| return container_.get(); |
| } |
| +void KeyboardController::NotifyKeyboardBoundsChanging( |
| + const gfx::Rect& new_bounds) { |
| + if (proxy_ && proxy_->GetKeyboardWindow()->IsVisible()) { |
| + FOR_EACH_OBSERVER(KeyboardControllerObserver, |
| + observer_list_, |
| + OnKeyboardBoundsChanging(new_bounds)); |
| + } |
| +} |
| + |
| void KeyboardController::HideKeyboard(HideReason reason) { |
| keyboard_visible_ = false; |
| @@ -161,9 +185,7 @@ void KeyboardController::HideKeyboard(HideReason reason) { |
| keyboard::KEYBOARD_CONTROL_HIDE_AUTO : |
| keyboard::KEYBOARD_CONTROL_HIDE_USER); |
| - FOR_EACH_OBSERVER(KeyboardControllerObserver, |
| - observer_list_, |
| - OnKeyboardBoundsChanging(gfx::Rect())); |
| + NotifyKeyboardBoundsChanging(gfx::Rect()); |
| proxy_->HideKeyboardContainer(container_.get()); |
| } |
| @@ -225,10 +247,8 @@ void KeyboardController::OnTextInputStateChanged( |
| if (container_->IsVisible()) |
| return; |
| - FOR_EACH_OBSERVER( |
| - KeyboardControllerObserver, |
| - observer_list_, |
| - OnKeyboardBoundsChanging(container_->children()[0]->bounds())); |
| + NotifyKeyboardBoundsChanging(container_->children()[0]->bounds()); |
| + |
| proxy_->ShowKeyboardContainer(container_.get()); |
| } else { |
| // Set the visibility state here so that any queries for visibility |