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

Unified Diff: ui/keyboard/keyboard_controller.cc

Issue 97013002: [Input View] Makes the input view window support window.resizeTo() and w3c visibility API its web c… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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: ui/keyboard/keyboard_controller.cc
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
index 0cb975f7d949ebb54311960524adc2f8317e3918..5420a2d621058854df85cb82ba676e3c6ae90daf 100644
--- a/ui/keyboard/keyboard_controller.cc
+++ b/ui/keyboard/keyboard_controller.cc
@@ -74,6 +74,12 @@ class KeyboardWindowDelegate : public aura::WindowDelegate {
virtual bool HasHitTestMask() const OVERRIDE { return true; }
virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {
gfx::Rect keyboard_bounds = KeyboardBoundsFromWindowBounds(bounds_);
kevers 2013/12/03 00:08:12 Won't bounds_ be properly updated by OnBoundsChang
Shu Chen 2013/12/03 01:54:42 Actually with proxy_, bounds_ is not needed.
+ if (keyboard::KeyboardControllerProxy::keyboard_height >= 0) {
+ // The keyboard height is variable, use the recorded keyboard height to be
+ // the hit test mask.
+ keyboard_bounds.set_height(
+ keyboard::KeyboardControllerProxy::keyboard_height);
+ }
mask->addRect(RectToSkRect(keyboard_bounds));
}
virtual void DidRecreateLayer(ui::Layer* old_layer,
@@ -92,17 +98,21 @@ namespace keyboard {
// owner window.
class KeyboardLayoutManager : public aura::LayoutManager {
public:
- KeyboardLayoutManager(aura::Window* container)
- : container_(container), keyboard_(NULL) {
- CHECK(container_);
+ KeyboardLayoutManager(KeyboardController* controller)
+ : 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());
+ // Records the keyboard new height. So that GetHitTestMask() can set the
+ // same keyboard bounds as the hit test mask.
+ KeyboardControllerProxy::keyboard_height = keyboard_bounds.height();
+ SetChildBoundsDirect(keyboard_, keyboard_bounds);
+ controller_->NotifyKeyboardBoundsChanged(keyboard_bounds);
}
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
DCHECK(!keyboard_);
@@ -114,11 +124,18 @@ class KeyboardLayoutManager : public aura::LayoutManager {
bool visible) OVERRIDE {}
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE {
kevers 2013/12/03 00:08:12 Chatted with Sadrul, and the main reason we had th
Shu Chen 2013/12/03 01:54:42 Done. I've changed it to non-static. What do you m
- // 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 (KeyboardControllerProxy::keyboard_resizing_from_contents) {
+ SetChildBoundsDirect(child, requested_bounds);
+ controller_->NotifyKeyboardBoundsChanged(requested_bounds);
+ }
}
private:
- aura::Window* container_;
+ KeyboardController* controller_;
aura::Window* keyboard_;
DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager);
@@ -148,11 +165,20 @@ aura::Window* KeyboardController::GetContainerWindow() {
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::NotifyKeyboardBoundsChanged(
+ const gfx::Rect& new_bounds, bool force) {
+ if (keyboard_visible_ || force) {
+ FOR_EACH_OBSERVER(KeyboardControllerObserver,
+ observer_list_,
+ OnKeyboardBoundsChanging(new_bounds));
+ }
+}
+
void KeyboardController::HideKeyboard(HideReason reason) {
keyboard_visible_ = false;
@@ -161,9 +187,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()));
+ NotifyKeyboardBoundsChanged(gfx::Rect(), true);
proxy_->HideKeyboardContainer(container_.get());
}
@@ -225,10 +249,8 @@ void KeyboardController::OnTextInputStateChanged(
if (container_->IsVisible())
return;
- FOR_EACH_OBSERVER(
- KeyboardControllerObserver,
- observer_list_,
- OnKeyboardBoundsChanging(container_->children()[0]->bounds()));
+ NotifyKeyboardBoundsChanged(container_->children()[0]->bounds());
+
proxy_->ShowKeyboardContainer(container_.get());
} else {
// Set the visibility state here so that any queries for visibility

Powered by Google App Engine
This is Rietveld 408576698