Commit 7975dd82 authored by wnwen's avatar wnwen Committed by Commit bot

Overscroll for keyboard disabled while keyboard is hiding.

While the keyboard is in the process of hiding, the proxy's visibility
flag may not be updated yet. Use the private keyboard_visible_ flag
instead as it stores the future visibility of the keyboard window after
animation is completed.

BUG=401670
TEST=Updated:
        KeyboardControllerTest.CheckOverscrollInsetDuringVisibilityChange
     On device:
         As the inset update must be initiated after the animation is
         started and before it is finished. Tested on clapper with the
         same method as in the bug, i.e. switch tab after hiding
         keyboard to trigger fast inset update.

Review URL: https://codereview.chromium.org/578653004

Cr-Commit-Position: refs/heads/master@{#295530}
parent 66f40ead
......@@ -445,15 +445,19 @@ void KeyboardController::OnShowImeIfNeeded() {
ShowKeyboardInternal();
}
bool KeyboardController::ShouldEnableInsets(aura::Window* window) {
aura::Window *keyboard_window = proxy_->GetKeyboardWindow();
return (keyboard_window->GetRootWindow() == window->GetRootWindow() &&
keyboard::IsKeyboardOverscrollEnabled() &&
proxy_->GetKeyboardWindow()->IsVisible() &&
keyboard_visible_);
}
void KeyboardController::UpdateWindowInsets(aura::Window* window) {
aura::Window *keyboard_window = proxy_->GetKeyboardWindow();
if (window == keyboard_window)
return;
bool enableInsets = (keyboard_window->GetRootWindow() ==
window->GetRootWindow()) && keyboard::IsKeyboardOverscrollEnabled() &&
proxy_->GetKeyboardWindow()->IsVisible();
scoped_ptr<content::RenderWidgetHostIterator> widgets(
content::RenderWidgetHost::GetRenderWidgetHosts());
while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
......@@ -462,7 +466,7 @@ void KeyboardController::UpdateWindowInsets(aura::Window* window) {
gfx::Rect window_bounds = view->GetNativeView()->GetBoundsInScreen();
gfx::Rect intersect = gfx::IntersectRects(window_bounds,
proxy_->GetKeyboardWindow()->bounds());
int overlap = enableInsets ? intersect.height() : 0;
int overlap = ShouldEnableInsets(window) ? intersect.height() : 0;
if (overlap > 0 && overlap < window_bounds.height())
view->SetInsets(gfx::Insets(0, 0, overlap, 0));
else
......
......@@ -104,6 +104,9 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
return current_keyboard_bounds_;
}
// Determines whether a particular window should have insets for overscroll.
bool ShouldEnableInsets(aura::Window* window);
// Updates insets on web content window
void UpdateWindowInsets(aura::Window* window);
......
......@@ -228,6 +228,10 @@ class KeyboardControllerTest : public testing::Test {
return controller_->WillHideKeyboard();
}
bool ShouldEnableInsets(aura::Window* window) {
return controller_->ShouldEnableInsets(window);
}
base::MessageLoopForUI message_loop_;
scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
scoped_ptr<TestFocusController> focus_controller_;
......@@ -421,6 +425,33 @@ TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
EXPECT_TRUE(keyboard_container->IsVisible());
}
// Test to prevent spurious overscroll boxes when changing tabs during keyboard
// hide. Refer to crbug.com/401670 for more context.
TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) {
const gfx::Rect& root_bounds = root_window()->bounds();
ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
aura::Window* keyboard_container(controller()->GetContainerWindow());
keyboard_container->SetBounds(root_bounds);
root_window()->AddChild(keyboard_container);
// Enable touch keyboard / overscroll mode to test insets.
keyboard::SetTouchKeyboardEnabled(true);
EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled());
SetFocus(&input_client);
SetFocus(&no_input_client);
// Insets should not be enabled for new windows while keyboard is in the
// process of hiding when overscroll is enabled.
EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
// Cancel keyboard hide.
SetFocus(&input_client);
// Insets should be enabled for new windows as hide was cancelled.
EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow()));
}
TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
const gfx::Rect& root_bounds = root_window()->bounds();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment