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

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
« no previous file with comments | « ui/keyboard/keyboard_controller.h ('k') | ui/keyboard/keyboard_controller_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/keyboard/keyboard_controller.cc
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
index 0cb975f7d949ebb54311960524adc2f8317e3918..d653102805fa3252c84524ed9b7e5f125c4244b1 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)
+ : proxy_(proxy) {}
virtual ~KeyboardWindowDelegate() {}
private:
@@ -50,9 +51,7 @@ class KeyboardWindowDelegate : public aura::WindowDelegate {
virtual gfx::Size GetMinimumSize() const OVERRIDE { return gfx::Size(); }
virtual gfx::Size GetMaximumSize() const OVERRIDE { return gfx::Size(); }
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) OVERRIDE {
- bounds_ = new_bounds;
- }
+ const gfx::Rect& new_bounds) OVERRIDE {}
virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
return gfx::kNullCursor;
}
@@ -73,13 +72,15 @@ 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()
+ : gfx::Rect();
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 +93,20 @@ 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.
+ SetChildBoundsDirect(keyboard_, keyboard_bounds);
+ controller_->NotifyKeyboardBoundsChanged(keyboard_bounds);
kevers 2013/12/03 02:53:07 Is NotifyKeyboardBoundsChanged going to fire twice
Shu Chen 2013/12/03 04:12:25 Done. I've removed this line and add comments.
}
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
DCHECK(!keyboard_);
@@ -114,11 +118,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()) {
+ SetChildBoundsDirect(child, requested_bounds);
+ controller_->NotifyKeyboardBoundsChanged(requested_bounds);
+ controller_->proxy()->set_resizing_from_contents(false);
+ }
}
private:
- aura::Window* container_;
+ KeyboardController* controller_;
aura::Window* keyboard_;
DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager);
@@ -143,16 +155,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::NotifyKeyboardBoundsChanged(
+ 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 +183,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());
kevers 2013/12/03 02:53:07 Will we now get extra notifications: here and when
Shu Chen 2013/12/03 04:12:25 Done. I've renamed the method to NotifyKeyboardBou
proxy_->HideKeyboardContainer(container_.get());
}
@@ -225,10 +245,8 @@ void KeyboardController::OnTextInputStateChanged(
if (container_->IsVisible())
return;
- FOR_EACH_OBSERVER(
- KeyboardControllerObserver,
- observer_list_,
- OnKeyboardBoundsChanging(container_->children()[0]->bounds()));
+ NotifyKeyboardBoundsChanged(container_->children()[0]->bounds());
kevers 2013/12/03 02:53:07 See previous comment.
Shu Chen 2013/12/03 04:12:25 Done.
+
proxy_->ShowKeyboardContainer(container_.get());
} else {
// Set the visibility state here so that any queries for visibility
« no previous file with comments | « ui/keyboard/keyboard_controller.h ('k') | ui/keyboard/keyboard_controller_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698