Chromium Code Reviews| Index: ui/keyboard/keyboard_controller.cc |
| diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc |
| index 40065d27845179576ccee19a2564195da15f69a0..6e05682dbbc53c07c4c89f866529b1ed087e1e80 100644 |
| --- a/ui/keyboard/keyboard_controller.cc |
| +++ b/ui/keyboard/keyboard_controller.cc |
| @@ -48,41 +48,13 @@ const int kHideAnimationDurationMs = 100; |
| // allowed to be shown with zero opacity, we always animate to 0.01 instead. |
| const float kAnimationStartOrAfterHideOpacity = 0.01f; |
| -// Event targeter for the keyboard container. |
| -class KeyboardContainerTargeter : public wm::MaskedWindowTargeter { |
| - public: |
| - KeyboardContainerTargeter(aura::Window* container, |
| - keyboard::KeyboardControllerProxy* proxy) |
| - : wm::MaskedWindowTargeter(container), |
| - proxy_(proxy) { |
| - } |
| - |
| - ~KeyboardContainerTargeter() override {} |
| - |
| - private: |
| - // wm::MaskedWindowTargeter: |
| - bool GetHitTestMask(aura::Window* window, gfx::Path* mask) const override { |
| - if (proxy_ && !proxy_->HasKeyboardWindow()) |
| - return true; |
| - gfx::Rect keyboard_bounds = proxy_ ? proxy_->GetKeyboardWindow()->bounds() : |
| - keyboard::DefaultKeyboardBoundsFromWindowBounds(window->bounds()); |
| - mask->addRect(RectToSkRect(keyboard_bounds)); |
| - return true; |
| - } |
| - |
| - keyboard::KeyboardControllerProxy* proxy_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(KeyboardContainerTargeter); |
| -}; |
| - |
| // The KeyboardWindowDelegate makes sure the keyboard-window does not get focus. |
| // This is necessary to make sure that the synthetic key-events reach the target |
| // window. |
| // The delegate deletes itself when the window is destroyed. |
| class KeyboardWindowDelegate : public aura::WindowDelegate { |
| public: |
| - explicit KeyboardWindowDelegate(keyboard::KeyboardControllerProxy* proxy) |
| - : proxy_(proxy) {} |
| + explicit KeyboardWindowDelegate() {} |
|
sadrul
2015/04/01 06:43:48
Don't need explicit
bshe
2015/04/01 20:41:33
Done.
|
| ~KeyboardWindowDelegate() override {} |
| private: |
| @@ -90,9 +62,7 @@ class KeyboardWindowDelegate : public aura::WindowDelegate { |
| gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
| gfx::Size GetMaximumSize() const override { return gfx::Size(); } |
| void OnBoundsChanged(const gfx::Rect& old_bounds, |
| - const gfx::Rect& new_bounds) override { |
| - bounds_ = new_bounds; |
| - } |
| + const gfx::Rect& new_bounds) override {} |
| ui::TextInputClient* GetFocusedTextInputClient() override { |
| return nullptr; |
| } |
| @@ -114,19 +84,8 @@ class KeyboardWindowDelegate : public aura::WindowDelegate { |
| void OnWindowDestroying(aura::Window* window) override {} |
| void OnWindowDestroyed(aura::Window* window) override { delete this; } |
| void OnWindowTargetVisibilityChanged(bool visible) override {} |
| - bool HasHitTestMask() const override { |
| - return !proxy_ || proxy_->HasKeyboardWindow(); |
| - } |
| - void GetHitTestMask(gfx::Path* mask) const override { |
| - if (proxy_ && !proxy_->HasKeyboardWindow()) |
| - return; |
| - gfx::Rect keyboard_bounds = proxy_ ? proxy_->GetKeyboardWindow()->bounds() : |
| - keyboard::DefaultKeyboardBoundsFromWindowBounds(bounds_); |
| - mask->addRect(RectToSkRect(keyboard_bounds)); |
| - } |
| - |
| - gfx::Rect bounds_; |
| - keyboard::KeyboardControllerProxy* proxy_; |
| + bool HasHitTestMask() const override { return false; } |
| + void GetHitTestMask(gfx::Path* mask) const override {} |
| DISALLOW_COPY_AND_ASSIGN(KeyboardWindowDelegate); |
| }; |
| @@ -275,10 +234,7 @@ KeyboardController* KeyboardController::GetInstance() { |
| aura::Window* KeyboardController::GetContainerWindow() { |
| if (!container_.get()) { |
| - container_.reset(new aura::Window( |
| - new KeyboardWindowDelegate(proxy_.get()))); |
| - container_->SetEventTargeter(scoped_ptr<ui::EventTargeter>( |
| - new KeyboardContainerTargeter(container_.get(), proxy_.get()))); |
| + container_.reset(new aura::Window(new KeyboardWindowDelegate())); |
| container_->SetName("KeyboardContainer"); |
| container_->set_owned_by_parent(false); |
| container_->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| @@ -441,15 +397,14 @@ void KeyboardController::OnShowImeIfNeeded() { |
| } |
| bool KeyboardController::ShouldEnableInsets(aura::Window* window) { |
| - aura::Window *keyboard_window = proxy_->GetKeyboardWindow(); |
| + aura::Window* keyboard_window = proxy_->GetKeyboardWindow(); |
| return (keyboard_window->GetRootWindow() == window->GetRootWindow() && |
| keyboard::IsKeyboardOverscrollEnabled() && |
| - proxy_->GetKeyboardWindow()->IsVisible() && |
| - keyboard_visible_); |
| + keyboard_window->IsVisible() && keyboard_visible_); |
| } |
| void KeyboardController::UpdateWindowInsets(aura::Window* window) { |
| - aura::Window *keyboard_window = proxy_->GetKeyboardWindow(); |
| + aura::Window* keyboard_window = proxy_->GetKeyboardWindow(); |
| if (window == keyboard_window) |
| return; |
| @@ -459,8 +414,8 @@ void KeyboardController::UpdateWindowInsets(aura::Window* window) { |
| content::RenderWidgetHostView* view = widget->GetView(); |
| if (view && window->Contains(view->GetNativeView())) { |
| gfx::Rect window_bounds = view->GetNativeView()->GetBoundsInScreen(); |
| - gfx::Rect intersect = gfx::IntersectRects(window_bounds, |
| - proxy_->GetKeyboardWindow()->bounds()); |
| + gfx::Rect intersect = |
| + gfx::IntersectRects(window_bounds, keyboard_window->bounds()); |
| int overlap = ShouldEnableInsets(window) ? intersect.height() : 0; |
| if (overlap > 0 && overlap < window_bounds.height()) |
| view->SetInsets(gfx::Insets(0, 0, overlap, 0)); |
| @@ -471,6 +426,26 @@ void KeyboardController::UpdateWindowInsets(aura::Window* window) { |
| } |
| } |
| +void KeyboardController::OnRootWindowResized(const gfx::Rect& bounds) { |
| + // Keep the same height when window resize. It gets called when screen rotate. |
| + if (!keyboard_container_initialized() || !proxy_->GetKeyboardWindow()) |
| + return; |
| + |
| + int container_height = container_->bounds().height(); |
| + if (keyboard_mode_ == FULL_WIDTH) { |
| + container_->SetBounds(gfx::Rect(bounds.x(), |
| + bounds.bottom() - container_height, |
| + bounds.width(), container_height)); |
| + } else if (keyboard_mode_ == FLOATING) { |
| + // When screen rotate, horizontally center floating virtual keyboard window |
| + // and vertically align it to the bottom. |
| + int container_width = container_->bounds().width(); |
| + container_->SetBounds(gfx::Rect( |
| + bounds.x() + (bounds.width() - container_width) / 2, |
| + bounds.bottom() - container_height, container_width, container_height)); |
| + } |
| +} |
| + |
| void KeyboardController::ShowKeyboardInternal() { |
| if (!container_.get()) |
| return; |
| @@ -564,7 +539,7 @@ bool KeyboardController::WillHideKeyboard() const { |
| void KeyboardController::ShowAnimationFinished() { |
| // Notify observers after animation finished to prevent reveal desktop |
| // background during animation. |
| - NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); |
| + NotifyKeyboardBoundsChanging(container_->bounds()); |
| proxy_->EnsureCaretInWorkArea(); |
| } |