Skip to content

Commit

Permalink
Restore window size after accessbility keyboard hides.
Browse files Browse the repository at this point in the history
BUG=366886
R=kevers@chromium.org
TEST:
    Open any non-maximized window covering at least the lower portion
    of the screen (so that normally on-screen keyboard would obscure
    part of the window).
    Turn on accessibility keyboard.
    Click on a text box, notice that keyboard shows up and window is
    resized so keyboard does not obscure any part of it.
    Click outside the text box (defocus), keyboard disappears and window
    bounds are restored to state before the keyboard showed up.

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

Cr-Commit-Position: refs/heads/master@{#291087}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291087 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
wnwen@chromium.org committed Aug 21, 2014
1 parent d338220 commit 4b04e34
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
30 changes: 21 additions & 9 deletions ash/wm/workspace/workspace_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,27 @@ void WorkspaceLayoutManager::OnKeyboardBoundsChanging(
aura::Window *window = text_input_client->GetAttachedWindow();
if (!window || !window_->Contains(window))
return;
gfx::Rect window_bounds = ScreenUtil::ConvertRectToScreen(
window_,
window->GetTargetBounds());
gfx::Rect intersect = gfx::IntersectRects(window_bounds, new_bounds);
int shift = std::min(intersect.height(),
window->bounds().y() - work_area_in_parent_.y());
if (shift > 0) {
gfx::Point origin(window->bounds().x(), window->bounds().y() - shift);
SetChildBounds(window, gfx::Rect(origin, window->bounds().size()));
aura::Window *toplevel_window = window->GetToplevelWindow();
wm::WindowState* toplevel_window_state = wm::GetWindowState(toplevel_window);
if (!new_bounds.IsEmpty()) {
// Store existing bounds to be restored before resizing for keyboard if it
// is not already stored.
if (!toplevel_window_state->HasRestoreBounds())
toplevel_window_state->SaveCurrentBoundsForRestore();

gfx::Rect window_bounds = ScreenUtil::ConvertRectToScreen(
window_,
window->GetTargetBounds());
gfx::Rect intersect = gfx::IntersectRects(window_bounds, new_bounds);
int shift = std::min(intersect.height(),
window->bounds().y() - work_area_in_parent_.y());
if (shift > 0) {
gfx::Point origin(window->bounds().x(), window->bounds().y() - shift);
SetChildBounds(window, gfx::Rect(origin, window->bounds().size()));
}
} else if (toplevel_window_state->HasRestoreBounds()) {
// Keyboard hidden, restore original bounds if they exist.
toplevel_window_state->SetAndClearRestoreBounds();
}
}

Expand Down
19 changes: 12 additions & 7 deletions ash/wm/workspace/workspace_layout_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,12 @@ class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase {
}

void ShowKeyboard() {
layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_);
restore_work_area_insets_ = Shell::GetScreen()->GetPrimaryDisplay().
GetWorkAreaInsets();
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(),
gfx::Insets(0, 0, keyboard_bounds_.height(), 0));
layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_);
}

void HideKeyboard() {
Expand Down Expand Up @@ -1043,8 +1043,10 @@ TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
work_area.height() / 2);

SetKeyboardBounds(keyboard_bounds);
scoped_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(work_area));

aura::test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
&delegate, -1, work_area));

aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
FakeTextInputClient text_input_client(window.get());
Expand All @@ -1061,20 +1063,23 @@ TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
keyboard_bounds.height();

EXPECT_EQ(gfx::Rect(work_area).ToString(),
window->bounds().ToString());
EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
ShowKeyboard();
EXPECT_EQ(gfx::Rect(work_area.origin(),
gfx::Size(work_area.width(), available_height)).ToString(),
window->bounds().ToString());
HideKeyboard();
EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());

window->SetBounds(gfx::Rect(50, 50, 100, 500));
EXPECT_EQ("50,50 100x500", window->bounds().ToString());
gfx::Rect small_window_bound(50, 50, 100, 500);
window->SetBounds(small_window_bound);
EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
ShowKeyboard();
EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
window->bounds().ToString());
HideKeyboard();
EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());

if (switches::IsTextInputFocusManagerEnabled()) {
ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
&text_input_client);
Expand Down

0 comments on commit 4b04e34

Please sign in to comment.