diff options
author | wnwen@chromium.org <wnwen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-21 16:23:14 +0000 |
---|---|---|
committer | wnwen@chromium.org <wnwen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-21 16:25:12 +0000 |
commit | 4b04e3424d3a266d33d5f613cbfbbecd1bd5388a (patch) | |
tree | 8f890459c17dc8910fa362819d414d53ee626cbe /ash | |
parent | d3382204f0301433e45331a507646662e28e283b (diff) | |
download | chromium_src-4b04e3424d3a266d33d5f613cbfbbecd1bd5388a.zip chromium_src-4b04e3424d3a266d33d5f613cbfbbecd1bd5388a.tar.gz chromium_src-4b04e3424d3a266d33d5f613cbfbbecd1bd5388a.tar.bz2 |
Restore window size after accessbility keyboard hides.
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
Diffstat (limited to 'ash')
-rw-r--r-- | ash/wm/workspace/workspace_layout_manager.cc | 30 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_layout_manager_unittest.cc | 19 |
2 files changed, 33 insertions, 16 deletions
diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc index 71f4b96..68fabb5 100644 --- a/ash/wm/workspace/workspace_layout_manager.cc +++ b/ash/wm/workspace/workspace_layout_manager.cc @@ -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(); } } diff --git a/ash/wm/workspace/workspace_layout_manager_unittest.cc b/ash/wm/workspace/workspace_layout_manager_unittest.cc index 76c7b24..a5fa688 100644 --- a/ash/wm/workspace/workspace_layout_manager_unittest.cc +++ b/ash/wm/workspace/workspace_layout_manager_unittest.cc @@ -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() { @@ -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()); @@ -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); |