Index: ui/keyboard/keyboard_controller.cc |
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc |
index 0cb975f7d949ebb54311960524adc2f8317e3918..b9ebf400cce9330faa1114757712f04bcb8fcddb 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,14 @@ namespace keyboard { |
// owner window. |
bshe
2013/12/10 21:18:08
It starts to make sense that we move the KeyboardL
Shu Chen
2013/12/11 00:48:32
Thank you!
|
class KeyboardLayoutManager : public aura::LayoutManager { |
public: |
- KeyboardLayoutManager(aura::Window* container) |
- : container_(container), keyboard_(NULL) { |
- CHECK(container_); |
+ explicit KeyboardLayoutManager(KeyboardController* controller) |
+ : controller_(controller) { |
} |
// Overridden from aura::LayoutManager |
- virtual void OnWindowResized() OVERRIDE { |
- if (!keyboard_) |
- return; |
- SetChildBoundsDirect(keyboard_, |
- KeyboardBoundsFromWindowBounds(container_->bounds())); |
- } |
+ virtual void OnWindowResized() OVERRIDE {} |
sadrul
2013/12/06 12:30:02
Did you verify that the keyboard-window gets resiz
sadrul
2013/12/09 22:47:01
You can test this trivially in a test by changing
bshe
2013/12/10 21:18:08
Looks like the keyboard-window size is now set by
sadrul
2013/12/10 21:21:19
We shouldn't depend on outside code (ash) to maint
Shu Chen
2013/12/11 00:48:32
Test added.
Shu Chen
2013/12/11 00:48:32
I've modified the code to let OnWindowResized hand
|
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
- DCHECK(!keyboard_); |
- keyboard_ = child; |
sadrul
2013/12/06 12:30:02
Why did you remove this code?
Shu Chen
2013/12/11 00:48:32
Done.
|
+ ResizeKeyboardToDefault(child); |
} |
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
@@ -114,12 +111,26 @@ 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); |
+ } else { |
+ ResizeKeyboardToDefault(child); |
+ } |
} |
private: |
- aura::Window* container_; |
- aura::Window* keyboard_; |
+ void ResizeKeyboardToDefault(aura::Window* child) { |
+ gfx::Rect keyboard_bounds = KeyboardBoundsFromWindowBounds( |
+ controller_->GetContainerWindow()->bounds()); |
+ SetChildBoundsDirect(child, keyboard_bounds); |
+ } |
+ |
+ KeyboardController* controller_; |
DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); |
}; |
@@ -135,24 +146,40 @@ KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) |
} |
KeyboardController::~KeyboardController() { |
- if (container_.get()) |
+ if (container_.get()) { |
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_ && proxy_->GetKeyboardWindow()->IsVisible()) { |
sadrul
2013/12/06 12:30:02
DCHECK(proxy_)
Shu Chen
2013/12/11 00:48:32
Done.
|
+ FOR_EACH_OBSERVER(KeyboardControllerObserver, |
+ observer_list_, |
+ OnKeyboardBoundsChanging(new_bounds)); |
+ } |
+} |
+ |
void KeyboardController::HideKeyboard(HideReason reason) { |
keyboard_visible_ = false; |
@@ -161,9 +188,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 +229,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 +249,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 |