Commit b18b5235 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[VK] Automatically load keyboard window in background when enabled.

In the future, we want KeyboardController to automatically
enable/disable itself when flags change. This means that we no longer
need to go through AshKeyboardController to enable/disable. However,
AshKeyboardController currently is responsible for pre-loading the
VK window when the VK gets enabled.

Hence, we'll move preloading code from AshKeyboardController to
KeyboardController. This doesn't affect real world execution, but
does affect some tests.

TBR=jamescook@chromium.org

Bug: 845780
Change-Id: Ib3cf897261497c7ff8a0c7b58739e4f0e9498b35
Reviewed-on: https://chromium-review.googlesource.com/c/1419597Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626869}
parent fb858216
......@@ -53,10 +53,6 @@ void AshKeyboardController::EnableKeyboard() {
keyboard_ui_factory_ ? keyboard_ui_factory_->CreateKeyboardUI()
: std::make_unique<AshKeyboardUI>(this),
virtual_keyboard_controller_.get());
// Start preloading the virtual keyboard UI in the background, so that it
// shows up faster when needed.
keyboard_controller_->LoadKeyboardWindowInBackground();
}
void AshKeyboardController::DisableKeyboard() {
......
......@@ -593,11 +593,6 @@ TEST_F(VirtualKeyboardControllerAlwaysEnabledTest,
ShowKeyboardInSecondaryDisplay) {
UpdateDisplay("500x500,500x500");
// Load in the primary display.
keyboard_controller_->LoadKeyboardWindowInBackground();
// Wait for the keyboard window to load.
base::RunLoop().RunUntilIdle();
// Show in secondary display.
keyboard_controller_->ShowKeyboardInDisplay(GetSecondaryDisplay());
EXPECT_EQ(GetSecondaryRootWindow(), keyboard_controller_->GetRootWindow());
......
......@@ -521,10 +521,7 @@ class ShelfWidgetVirtualKeyboardTest : public AshTestBase {
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
ASSERT_TRUE(keyboard::IsKeyboardEnabled());
keyboard_controller()->LoadKeyboardWindowInBackground();
// Wait for the keyboard window to load.
base::RunLoop().RunUntilIdle();
keyboard::test::WaitUntilLoaded();
// These tests only apply to the floating virtual keyboard, as it is the
// only case where both the virtual keyboard and the shelf are visible.
......
......@@ -250,10 +250,7 @@ class StatusAreaWidgetVirtualKeyboardTest : public AshTestBase {
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
ASSERT_TRUE(keyboard::IsKeyboardEnabled());
keyboard_controller()->LoadKeyboardWindowInBackground();
// Wait for the keyboard window to load.
base::RunLoop().RunUntilIdle();
keyboard::test::WaitUntilLoaded();
// These tests only apply to the floating virtual keyboard, as it is the
// only case where both the virtual keyboard and the shelf are visible.
......
......@@ -23,12 +23,10 @@ class VirtualKeyboardTrayTest : public AshTestBase {
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
ASSERT_TRUE(keyboard::IsKeyboardEnabled());
keyboard::test::WaitUntilLoaded();
// These tests only apply to the floating virtual keyboard, as it is the
// only case where both the virtual keyboard and the shelf are visible.
keyboard_controller()->LoadKeyboardWindowInBackground();
// Wait for the keyboard window to load.
base::RunLoop().RunUntilIdle();
keyboard_controller()->SetContainerType(
keyboard::mojom::ContainerType::kFloating, base::nullopt,
base::DoNothing());
......
......@@ -378,8 +378,8 @@ class OverviewVirtualKeyboardTest : public OverviewControllerTest {
TabletModeControllerTestApi().EnterTabletMode();
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(keyboard::IsKeyboardEnabled());
keyboard::test::WaitUntilLoaded();
keyboard_controller()->LoadKeyboardWindowInBackground();
keyboard_controller()->GetKeyboardWindow()->SetBounds(
keyboard::KeyboardBoundsFromRootBounds(
Shell::GetPrimaryRootWindow()->bounds(), 100));
......
......@@ -423,7 +423,6 @@ IN_PROC_BROWSER_TEST_F(KeyboardControllerStateTest,
auto* controller = keyboard::KeyboardController::Get();
controller->LoadKeyboardWindowInBackground();
EXPECT_EQ(controller->GetStateForTest(),
keyboard::KeyboardControllerState::LOADING_EXTENSION);
......
......@@ -274,6 +274,10 @@ void KeyboardController::EnableKeyboard(std::unique_ptr<KeyboardUI> ui,
ActivateKeyboardInContainer(
layout_delegate_->GetContainerForDefaultDisplay());
// Start preloading the virtual keyboard UI in the background, so that it
// shows up faster when needed.
LoadKeyboardWindowInBackground();
}
void KeyboardController::DisableKeyboard() {
......
......@@ -87,6 +87,7 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
static bool HasInstance();
// Enables the virtual keyboard with a specified |ui| and |delegate|.
// Immediately starts pre-loading the keyboard window in the background.
// Disables and re-enables the keyboard if it is already enabled.
void EnableKeyboard(std::unique_ptr<KeyboardUI> ui,
KeyboardLayoutDelegate* delegate);
......@@ -177,10 +178,6 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
// lock the keyboard
void ShowKeyboardInDisplay(const display::Display& display);
// Loads the keyboard window in the background, but does not display
// the keyboard.
void LoadKeyboardWindowInBackground();
// Returns the bounds in screen for the visible portion of the keyboard. An
// empty rectangle will get returned when the keyboard is hidden.
const gfx::Rect& visual_bounds_in_screen() const {
......@@ -322,6 +319,10 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
// keyboard if it is currently visible.
void DeactivateKeyboard();
// Loads the keyboard window in the background, but does not display
// the keyboard.
void LoadKeyboardWindowInBackground();
// Show virtual keyboard immediately with animation.
void ShowKeyboardInternal(aura::Window* target_container);
void PopulateKeyboardContent(aura::Window* target_container,
......
......@@ -282,8 +282,6 @@ class KeyboardControllerTest : public aura::test::AuraTestBase,
TEST_F(KeyboardControllerTest, KeyboardSize) {
root_window()->SetLayoutManager(new KeyboardLayoutManager(&controller()));
controller().LoadKeyboardWindowInBackground();
// The keyboard window should not be visible.
aura::Window* keyboard_window = controller().GetKeyboardWindow();
EXPECT_FALSE(keyboard_window->IsVisible());
......@@ -317,7 +315,6 @@ TEST_F(KeyboardControllerTest, TransientBlurShortDelay) {
ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
base::RunLoop run_loop;
controller().LoadKeyboardWindowInBackground();
aura::Window* keyboard_window = controller().GetKeyboardWindow();
auto keyboard_container_observer =
std::make_unique<KeyboardContainerObserver>(keyboard_window, &run_loop);
......@@ -360,7 +357,6 @@ TEST_F(KeyboardControllerTest, TransientBlurLongDelay) {
ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
base::RunLoop run_loop;
controller().LoadKeyboardWindowInBackground();
aura::Window* keyboard_window = controller().GetKeyboardWindow();
auto keyboard_container_observer =
std::make_unique<KeyboardContainerObserver>(keyboard_window, &run_loop);
......@@ -398,7 +394,6 @@ TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
base::RunLoop run_loop;
controller().LoadKeyboardWindowInBackground();
aura::Window* keyboard_window = controller().GetKeyboardWindow();
auto keyboard_container_observer =
std::make_unique<KeyboardContainerObserver>(keyboard_window, &run_loop);
......@@ -457,7 +452,6 @@ TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE);
base::RunLoop run_loop;
controller().LoadKeyboardWindowInBackground();
aura::Window* keyboard_window = controller().GetKeyboardWindow();
auto keyboard_container_observer =
std::make_unique<KeyboardContainerObserver>(keyboard_window, &run_loop);
......@@ -496,7 +490,6 @@ TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
// Tests that disabling the keyboard will get a corresponding event.
TEST_F(KeyboardControllerTest, DisableKeyboard) {
controller().LoadKeyboardWindowInBackground();
aura::Window* keyboard_window = controller().GetKeyboardWindow();
ShowKeyboard();
......@@ -508,7 +501,6 @@ TEST_F(KeyboardControllerTest, DisableKeyboard) {
}
TEST_F(KeyboardControllerTest, SetOccludedBoundsChangesFullscreenBounds) {
controller().LoadKeyboardWindowInBackground();
// Keyboard is hidden, so SetContainerType should be synchronous.
controller().SetContainerType(mojom::ContainerType::kFullscreen,
......@@ -547,8 +539,6 @@ class KeyboardControllerAnimationTest : public KeyboardControllerTest {
KeyboardControllerTest::SetUp();
// Preload the keyboard contents so that we can set its bounds.
controller().LoadKeyboardWindowInBackground();
// Wait for the keyboard contents to load.
base::RunLoop().RunUntilIdle();
keyboard_window()->SetBounds(root_window()->bounds());
......@@ -711,7 +701,6 @@ TEST_F(KeyboardControllerTest, TextInputMode) {
ui::TEXT_INPUT_MODE_NONE);
base::RunLoop run_loop;
controller().LoadKeyboardWindowInBackground();
aura::Window* keyboard_window = controller().GetKeyboardWindow();
auto keyboard_container_observer =
std::make_unique<KeyboardContainerObserver>(keyboard_window, &run_loop);
......
......@@ -48,6 +48,21 @@ bool WaitVisibilityChangesTo(bool wait_until) {
} // namespace
namespace test {
bool WaitUntilLoaded() {
// In tests, the keyboard window is mocked out so it usually "loads" within a
// single RunUntilIdle call.
base::RunLoop run_loop;
while (KeyboardController::Get()->GetStateForTest() ==
KeyboardControllerState::LOADING_EXTENSION) {
run_loop.RunUntilIdle();
}
return true;
}
} // namespace test
bool WaitUntilShown() {
// KeyboardController send a visibility update once the show animation
// finishes.
......
......@@ -13,6 +13,14 @@ class Rect;
namespace keyboard {
// TODO(shend): Move other methods into test namespace.
namespace test {
// Waits until the keyboard window finishes loading.
bool WaitUntilLoaded();
} // namespace test
// Waits until the keyboard is fully shown, with no pending animations.
bool WaitUntilShown();
......
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