Index: ui/keyboard/keyboard_controller.cc |
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc |
index 0cb975f7d949ebb54311960524adc2f8317e3918..4ff2cf5a3a1afb9e6b057c323e992b59d4dd8627 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() {} |
+ explicit KeyboardWindowDelegate(keyboard::KeyboardControllerProxy* proxy) |
+ : 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,21 +96,19 @@ namespace keyboard { |
// owner window. |
class KeyboardLayoutManager : public aura::LayoutManager { |
public: |
- KeyboardLayoutManager(aura::Window* container) |
- : container_(container), keyboard_(NULL) { |
- CHECK(container_); |
+ explicit KeyboardLayoutManager(KeyboardController* controller) |
+ : controller_(controller), keyboard_(NULL) { |
} |
// Overridden from aura::LayoutManager |
virtual void OnWindowResized() OVERRIDE { |
- if (!keyboard_) |
- return; |
- SetChildBoundsDirect(keyboard_, |
- KeyboardBoundsFromWindowBounds(container_->bounds())); |
+ if (keyboard_ && !controller_->proxy()->resizing_from_contents()) |
+ ResizeKeyboardToDefault(keyboard_); |
} |
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
DCHECK(!keyboard_); |
keyboard_ = child; |
+ ResizeKeyboardToDefault(keyboard_); |
} |
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
@@ -114,11 +116,24 @@ 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). |
+ // The flag resizing_from_contents() is used to determine the keyboard is |
+ // resizing from which. |
+ if (controller_->proxy()->resizing_from_contents()) { |
+ controller_->NotifyKeyboardBoundsChanging(requested_bounds); |
+ SetChildBoundsDirect(child, requested_bounds); |
+ } |
} |
private: |
- aura::Window* container_; |
+ void ResizeKeyboardToDefault(aura::Window* child) { |
+ gfx::Rect keyboard_bounds = KeyboardBoundsFromWindowBounds( |
+ controller_->GetContainerWindow()->bounds()); |
+ SetChildBoundsDirect(child, keyboard_bounds); |
+ } |
+ |
+ KeyboardController* controller_; |
aura::Window* keyboard_; |
DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); |
@@ -135,24 +150,39 @@ KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) |
} |
KeyboardController::~KeyboardController() { |
- if (container_.get()) |
+ if (container_) { |
container_->RemoveObserver(this); |
+ // Remove the keyboard window from the children because the keyboard window |
+ // is owned by proxy and it should be destroyed by proxy. |
+ if (container_->Contains(proxy_->GetKeyboardWindow())) |
+ container_->RemoveChild(proxy_->GetKeyboardWindow()); |
+ } |
if (input_method_) |
input_method_->RemoveObserver(this); |
} |
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_->GetKeyboardWindow()->IsVisible()) { |
+ FOR_EACH_OBSERVER(KeyboardControllerObserver, |
+ observer_list_, |
+ OnKeyboardBoundsChanging(new_bounds)); |
+ } |
+} |
+ |
void KeyboardController::HideKeyboard(HideReason reason) { |
keyboard_visible_ = false; |
@@ -161,9 +191,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()); |
} |
@@ -204,7 +232,6 @@ void KeyboardController::OnTextInputStateChanged( |
aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
keyboard->Show(); |
container_->AddChild(keyboard); |
- container_->layout_manager()->OnWindowResized(); |
} |
if (type != ui::TEXT_INPUT_TYPE_NONE) |
proxy_->SetUpdateInputType(type); |
@@ -225,10 +252,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 |