Commit 00bff42f authored by rsadam's avatar rsadam Committed by Commit bot

Resize BrowserFrameAsh and not RenderWidgetHostViewAura when keyboard bounds change.

TextInputClient returns a BrowserFrameAsh is the omnibar is clicked, and RenderWidgetHostViewAura if a textfield on the page is clicked. We always want to resize BrowserFrameAsh.

TEST=WorkspaceLayoutManagerKeyboardTest.ChildWindowFocused
BUG=407094

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

Cr-Commit-Position: refs/heads/master@{#292004}
parent a4e40580
...@@ -134,22 +134,21 @@ void WorkspaceLayoutManager::SetChildBounds( ...@@ -134,22 +134,21 @@ void WorkspaceLayoutManager::SetChildBounds(
void WorkspaceLayoutManager::OnKeyboardBoundsChanging( void WorkspaceLayoutManager::OnKeyboardBoundsChanging(
const gfx::Rect& new_bounds) { const gfx::Rect& new_bounds) {
aura::Window* root_window = window_->GetRootWindow();
ui::InputMethod* input_method = ui::InputMethod* input_method =
root_window->GetProperty(aura::client::kRootWindowInputMethodKey); root_window_->GetProperty(aura::client::kRootWindowInputMethodKey);
ui::TextInputClient* text_input_client = input_method->GetTextInputClient(); ui::TextInputClient* text_input_client = input_method->GetTextInputClient();
if (!text_input_client) if (!text_input_client)
return; return;
aura::Window *window = text_input_client->GetAttachedWindow(); aura::Window *window =
text_input_client->GetAttachedWindow()->GetToplevelWindow();
if (!window || !window_->Contains(window)) if (!window || !window_->Contains(window))
return; return;
aura::Window *toplevel_window = window->GetToplevelWindow(); wm::WindowState* window_state = wm::GetWindowState(window);
wm::WindowState* toplevel_window_state = wm::GetWindowState(toplevel_window);
if (!new_bounds.IsEmpty()) { if (!new_bounds.IsEmpty()) {
// Store existing bounds to be restored before resizing for keyboard if it // Store existing bounds to be restored before resizing for keyboard if it
// is not already stored. // is not already stored.
if (!toplevel_window_state->HasRestoreBounds()) if (!window_state->HasRestoreBounds())
toplevel_window_state->SaveCurrentBoundsForRestore(); window_state->SaveCurrentBoundsForRestore();
gfx::Rect window_bounds = ScreenUtil::ConvertRectToScreen( gfx::Rect window_bounds = ScreenUtil::ConvertRectToScreen(
window_, window_,
...@@ -161,9 +160,9 @@ void WorkspaceLayoutManager::OnKeyboardBoundsChanging( ...@@ -161,9 +160,9 @@ void WorkspaceLayoutManager::OnKeyboardBoundsChanging(
gfx::Point origin(window->bounds().x(), window->bounds().y() - shift); gfx::Point origin(window->bounds().x(), window->bounds().y() - shift);
SetChildBounds(window, gfx::Rect(origin, window->bounds().size())); SetChildBounds(window, gfx::Rect(origin, window->bounds().size()));
} }
} else if (toplevel_window_state->HasRestoreBounds()) { } else if (window_state->HasRestoreBounds()) {
// Keyboard hidden, restore original bounds if they exist. // Keyboard hidden, restore original bounds if they exist.
toplevel_window_state->SetAndClearRestoreBounds(); window_state->SetAndClearRestoreBounds();
} }
} }
......
...@@ -1011,6 +1011,32 @@ class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase { ...@@ -1011,6 +1011,32 @@ class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase {
keyboard_bounds_ = bounds; keyboard_bounds_ = bounds;
} }
void Focus(ui::TextInputClient* text_input_client) {
if (switches::IsTextInputFocusManagerEnabled()) {
ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
text_input_client);
} else {
aura::Window* root_window =
ash::Shell::GetInstance()->GetPrimaryRootWindow();
ui::InputMethod* input_method =
root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
input_method->SetFocusedTextInputClient(text_input_client);
}
}
void Blur(ui::TextInputClient* text_input_client) {
if (switches::IsTextInputFocusManagerEnabled()) {
ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
text_input_client);
} else {
aura::Window* root_window =
ash::Shell::GetInstance()->GetPrimaryRootWindow();
ui::InputMethod* input_method =
root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
input_method->SetFocusedTextInputClient(NULL);
}
}
private: private:
gfx::Insets restore_work_area_insets_; gfx::Insets restore_work_area_insets_;
gfx::Rect keyboard_bounds_; gfx::Rect keyboard_bounds_;
...@@ -1034,6 +1060,47 @@ class FakeTextInputClient : public ui::DummyTextInputClient { ...@@ -1034,6 +1060,47 @@ class FakeTextInputClient : public ui::DummyTextInputClient {
DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient); DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient);
}; };
// Tests that when a child window gains focus the top level window containing it
// is resized to fit the remaining workspace area.
TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) {
gfx::Rect work_area(
Shell::GetScreen()->GetPrimaryDisplay().work_area());
gfx::Rect keyboard_bounds(work_area.x(),
work_area.y() + work_area.height() / 2,
work_area.width(),
work_area.height() / 2);
SetKeyboardBounds(keyboard_bounds);
aura::test::TestWindowDelegate delegate1;
scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate(
&delegate1, -1, work_area));
aura::test::TestWindowDelegate delegate2;
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
&delegate2, -1, work_area));
parent_window->AddChild(window.get());
FakeTextInputClient text_input_client(window.get());
Focus(&text_input_client);
int available_height =
Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
keyboard_bounds.height();
gfx::Rect initial_window_bounds(50, 50, 100, 500);
parent_window->SetBounds(initial_window_bounds);
EXPECT_EQ(initial_window_bounds.ToString(),
parent_window->bounds().ToString());
ShowKeyboard();
EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
parent_window->bounds().ToString());
HideKeyboard();
EXPECT_EQ(initial_window_bounds.ToString(),
parent_window->bounds().ToString());
Blur(&text_input_client);
}
TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
gfx::Rect work_area( gfx::Rect work_area(
Shell::GetScreen()->GetPrimaryDisplay().work_area()); Shell::GetScreen()->GetPrimaryDisplay().work_area());
...@@ -1048,16 +1115,8 @@ TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { ...@@ -1048,16 +1115,8 @@ TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
&delegate, -1, work_area)); &delegate, -1, work_area));
aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
FakeTextInputClient text_input_client(window.get()); FakeTextInputClient text_input_client(window.get());
ui::InputMethod* input_method = Focus(&text_input_client);
root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
if (switches::IsTextInputFocusManagerEnabled()) {
ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
&text_input_client);
} else {
input_method->SetFocusedTextInputClient(&text_input_client);
}
int available_height = int available_height =
Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
...@@ -1080,12 +1139,7 @@ TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { ...@@ -1080,12 +1139,7 @@ TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
HideKeyboard(); HideKeyboard();
EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString()); EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
if (switches::IsTextInputFocusManagerEnabled()) { Blur(&text_input_client);
ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
&text_input_client);
} else {
input_method->SetFocusedTextInputClient(NULL);
}
} }
} // namespace ash } // namespace ash
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