Commit 676efee9 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Move ActivateKeyboard to AshKeyboardController

This CL removes RootWindowController::ActivateKeyboard and
DeactivatteKeyboard and replaces them with calls into
AshKeyboardController, simplifying the relationship.

Bug: 843332
Change-Id: I78cde4b9b22ba1c9406cbc44dc90af41d4ce37bb
Reviewed-on: https://chromium-review.googlesource.com/c/1294691
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602080}
parent 57321ac7
......@@ -5,6 +5,7 @@
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/keyboard/virtual_keyboard_controller.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
......@@ -44,14 +45,10 @@ void AshKeyboardController::EnableKeyboard() {
if (!keyboard_controller_->IsKeyboardEnableRequested())
return;
if (keyboard_controller_->IsEnabled()) {
// Disable and re-enable the keyboard, as some callers expect the keyboard
// to be reloaded.
// TODO(https://crbug.com/731537): Add a separate function for reloading the
// keyboard.
for (auto* controller : Shell::Get()->GetAllRootWindowControllers())
controller->DeactivateKeyboard(keyboard_controller_.get());
}
// De-activate the keyboard, as some callers expect the keyboard to be
// reloaded. TODO(https://crbug.com/731537): Add a separate function for
// reloading the keyboard.
DeactivateKeyboard();
// TODO(crbug.com/646565): The keyboard UI uses a WebContents that is
// created by chrome code but parented to an ash-created container window.
......@@ -69,11 +66,7 @@ void AshKeyboardController::EnableKeyboard() {
}
void AshKeyboardController::DisableKeyboard() {
if (keyboard_controller_->IsEnabled()) {
for (auto* controller : Shell::Get()->GetAllRootWindowControllers())
controller->DeactivateKeyboard(keyboard_controller_.get());
}
DeactivateKeyboard();
keyboard_controller_->DisableKeyboard();
}
......@@ -153,10 +146,32 @@ void AshKeyboardController::OnSessionStateChanged(
}
void AshKeyboardController::ActivateKeyboard() {
ActivateKeyboardForRoot(Shell::Get()->GetPrimaryRootWindowController());
}
void AshKeyboardController::ActivateKeyboardForRoot(
RootWindowController* controller) {
DCHECK(controller);
if (!keyboard_controller_->IsEnabled())
return;
Shell::Get()->GetPrimaryRootWindowController()->ActivateKeyboard(
keyboard_controller_.get());
// If the keyboard is already activated for |controller|, do nothing.
if (controller->GetRootWindow() == keyboard_controller_->GetRootWindow())
return;
aura::Window* container =
controller->GetContainer(kShellWindowId_VirtualKeyboardContainer);
DCHECK(container);
keyboard_controller_->ActivateKeyboardInContainer(container);
keyboard_controller_->LoadKeyboardWindowInBackground();
}
void AshKeyboardController::DeactivateKeyboard() {
if (!keyboard_controller_->IsEnabled() ||
!keyboard_controller_->GetRootWindow()) {
return;
}
keyboard_controller_->DeactivateKeyboard();
}
void AshKeyboardController::UpdateEnableFlag(bool was_enabled) {
......
......@@ -25,6 +25,7 @@ class KeyboardController;
namespace ash {
class RootWindowController;
class SessionController;
class VirtualKeyboardController;
......@@ -78,10 +79,16 @@ class ASH_EXPORT AshKeyboardController
return virtual_keyboard_controller_.get();
}
private:
// Ensures that the keyboard controller is activated for the primary window.
// Activates the keyboard controller for the primary root window controller.
void ActivateKeyboard();
// Activates the keyboard controller for |controller|.
void ActivateKeyboardForRoot(RootWindowController* controller);
// Deactivates the keyboard controller.
void DeactivateKeyboard();
private:
// Called whenever the enable flags may have changed the enabled state from
// |was_enabled|. If changed, enables or disables the keyboard.
void UpdateEnableFlag(bool was_enabled);
......
......@@ -8,6 +8,7 @@
#include "ash/accessibility/accessibility_controller.h"
#include "ash/ime/ime_controller.h"
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
......@@ -50,16 +51,15 @@ void ResetVirtualKeyboard() {
void MoveKeyboardToDisplayInternal(const display::Display& display) {
// Remove the keyboard from curent root window controller
TRACE_EVENT0("vk", "MoveKeyboardToDisplayInternal");
RootWindowController::ForWindow(
keyboard::KeyboardController::Get()->GetRootWindow())
->DeactivateKeyboard(keyboard::KeyboardController::Get());
auto* ash_keyboard_controller = Shell::Get()->ash_keyboard_controller();
ash_keyboard_controller->DeactivateKeyboard();
for (RootWindowController* controller :
Shell::Get()->GetAllRootWindowControllers()) {
if (display::Screen::GetScreen()
->GetDisplayNearestWindow(controller->GetRootWindow())
.id() == display.id()) {
controller->ActivateKeyboard(keyboard::KeyboardController::Get());
ash_keyboard_controller->ActivateKeyboardForRoot(controller);
break;
}
}
......
......@@ -4,6 +4,7 @@
#include "ash/login/ui/login_keyboard_test_base.h"
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/login/login_screen_controller.h"
#include "ash/login/mock_login_screen_client.h"
#include "ash/login/ui/lock_screen.h"
......@@ -33,41 +34,41 @@ void LoginKeyboardTestBase::SetUp() {
login_controller_ = Shell::Get()->login_screen_controller();
ASSERT_NE(nullptr, login_controller_);
keyboard_controller_ = keyboard::KeyboardController::Get();
ASSERT_NE(nullptr, keyboard_controller_);
Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
keyboard_controller_);
Shell::Get()->ash_keyboard_controller()->ActivateKeyboard();
}
void LoginKeyboardTestBase::TearDown() {
Shell::GetPrimaryRootWindowController()->DeactivateKeyboard(
keyboard_controller_);
Shell::Get()->ash_keyboard_controller()->DeactivateKeyboard();
if (ash::LockScreen::HasInstance())
ash::LockScreen::Get()->Destroy();
AshTestBase::TearDown();
}
void LoginKeyboardTestBase::ShowKeyboard() {
keyboard_controller_->ShowKeyboard(false);
auto* keyboard_controller = keyboard::KeyboardController::Get();
keyboard_controller->ShowKeyboard(false);
// Set keyboard height to half of the root window - this should overlap with
// lock/login layout.
if (keyboard_controller_->GetKeyboardWindow()->bounds().height() == 0) {
if (keyboard_controller->GetKeyboardWindow()->bounds().height() == 0) {
int height = Shell::GetPrimaryRootWindow()->bounds().height() / 2;
keyboard_controller_->GetKeyboardWindow()->SetBounds(
keyboard_controller->GetKeyboardWindow()->SetBounds(
keyboard::KeyboardBoundsFromRootBounds(
Shell::GetPrimaryRootWindow()->bounds(), height));
keyboard_controller_->NotifyKeyboardWindowLoaded();
keyboard_controller->NotifyKeyboardWindowLoaded();
}
ASSERT_TRUE(keyboard_controller_->IsKeyboardVisible());
ASSERT_TRUE(keyboard_controller->IsKeyboardVisible());
}
void LoginKeyboardTestBase::HideKeyboard() {
keyboard_controller_->HideKeyboardByUser();
ASSERT_FALSE(keyboard_controller_->IsKeyboardVisible());
auto* keyboard_controller = keyboard::KeyboardController::Get();
keyboard_controller->HideKeyboardByUser();
ASSERT_FALSE(keyboard_controller->IsKeyboardVisible());
}
gfx::Rect LoginKeyboardTestBase::GetKeyboardBoundsInScreen() const {
return keyboard_controller_->GetKeyboardWindow()->GetBoundsInScreen();
return keyboard::KeyboardController::Get()
->GetKeyboardWindow()
->GetBoundsInScreen();
}
void LoginKeyboardTestBase::ShowLockScreen() {
......
......@@ -10,10 +10,6 @@
#include "ash/public/interfaces/login_user_info.mojom.h"
#include "ash/test/ash_test_base.h"
namespace keyboard {
class KeyboardController;
} // namespace keyboard
namespace ash {
class LoginScreenController;
......@@ -59,7 +55,6 @@ class LoginKeyboardTestBase : public AshTestBase {
void TearDown() override;
private:
keyboard::KeyboardController* keyboard_controller_ = nullptr;
LoginScreenController* login_controller_ = nullptr;
std::vector<mojom::LoginUserInfoPtr> users_;
......
......@@ -16,6 +16,7 @@
#include "ash/high_contrast/high_contrast_controller.h"
#include "ash/host/ash_window_tree_host.h"
#include "ash/keyboard/arc/arc_virtual_keyboard_container_layout_manager.h"
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/keyboard/virtual_keyboard_container_layout_manager.h"
#include "ash/lock_screen_action/lock_screen_action_background_controller.h"
#include "ash/login_status.h"
......@@ -470,7 +471,11 @@ void RootWindowController::CloseChildWindows() {
// Deactivate keyboard container before closing child windows and shutting
// down associated layout managers.
DeactivateKeyboard(keyboard::KeyboardController::Get());
auto* ash_keyboard_controller = Shell::Get()->ash_keyboard_controller();
if (ash_keyboard_controller->keyboard_controller()->GetRootWindow() ==
GetRootWindow()) {
ash_keyboard_controller->DeactivateKeyboard();
}
shelf_->ShutdownShelfWidget();
......@@ -533,40 +538,6 @@ aura::Window* RootWindowController::GetWindowForFullscreenMode() {
return wm::GetWindowForFullscreenMode(GetRootWindow());
}
void RootWindowController::ActivateKeyboard(
keyboard::KeyboardController* keyboard_controller) {
DCHECK(keyboard_controller);
// There is a potential edge case where IsKeyboardEnabled() returns true but
// EnableKeyboard() has not been called. In that case we still don't want to
// activate the keyboard.
if (!keyboard::IsKeyboardEnabled() || !keyboard_controller->IsEnabled())
return;
// If the keyboard is already activated, ensure that it is activated in this
// root window.
if (keyboard_controller->GetRootWindow() == GetRootWindow())
return;
aura::Window* vk_container =
GetContainer(kShellWindowId_VirtualKeyboardContainer);
DCHECK(vk_container);
keyboard_controller->ActivateKeyboardInContainer(vk_container);
keyboard_controller->LoadKeyboardWindowInBackground();
}
void RootWindowController::DeactivateKeyboard(
keyboard::KeyboardController* keyboard_controller) {
DCHECK(keyboard_controller);
if (!keyboard_controller->IsEnabled())
return;
// If the VK is under the root window of this controller.
if (keyboard_controller->GetRootWindow() == GetRootWindow())
keyboard_controller->DeactivateKeyboard();
}
void RootWindowController::SetTouchAccessibilityAnchorPoint(
const gfx::Point& anchor_point) {
if (touch_exploration_manager_)
......
......@@ -24,10 +24,6 @@ namespace gfx {
class Point;
}
namespace keyboard {
class KeyboardController;
}
namespace ui {
class SimpleMenuModel;
class WindowTreeHost;
......@@ -200,12 +196,6 @@ class ASH_EXPORT RootWindowController {
// are in fullscreen mode.
aura::Window* GetWindowForFullscreenMode();
// Activate virtual keyboard on current root window controller.
void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
// Deactivate virtual keyboard on current root window controller.
void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
// If touch exploration is enabled, update the touch exploration
// controller so that synthesized touch events are anchored at this point.
void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
......
......@@ -4,6 +4,7 @@
#include "ash/wm/always_on_top_controller.h"
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
......@@ -56,7 +57,6 @@ class TestLayoutManager : public WorkspaceLayoutManager {
// Verifies that the always on top controller is notified of keyboard bounds
// changing events.
TEST_F(VirtualKeyboardAlwaysOnTopControllerTest, NotifyKeyboardBoundsChanging) {
auto* keyboard_controller = keyboard::KeyboardController::Get();
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* always_on_top_container =
Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer);
......@@ -64,14 +64,15 @@ TEST_F(VirtualKeyboardAlwaysOnTopControllerTest, NotifyKeyboardBoundsChanging) {
TestLayoutManager* manager = new TestLayoutManager(always_on_top_container);
RootWindowController* controller = Shell::GetPrimaryRootWindowController();
// Deactivates keyboard to unregister existing listeners.
controller->DeactivateKeyboard(keyboard_controller);
Shell::Get()->ash_keyboard_controller()->DeactivateKeyboard();
AlwaysOnTopController* always_on_top_controller =
controller->always_on_top_controller();
always_on_top_controller->SetLayoutManagerForTest(base::WrapUnique(manager));
// Activate keyboard. This triggers keyboard listeners to be registered.
controller->ActivateKeyboard(keyboard_controller);
Shell::Get()->ash_keyboard_controller()->ActivateKeyboard();
// Show the keyboard.
auto* keyboard_controller = keyboard::KeyboardController::Get();
keyboard_controller->ShowKeyboard(false /* locked */);
const int kKeyboardHeight = 200;
gfx::Rect keyboard_bounds = keyboard::KeyboardBoundsFromRootBounds(
......
......@@ -7,6 +7,7 @@
#include <memory>
#include <utility>
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/lock_screen_action/lock_screen_action_background_controller.h"
#include "ash/lock_screen_action/lock_screen_action_background_controller_stub.h"
#include "ash/lock_screen_action/test_lock_screen_action_background_controller.h"
......@@ -99,8 +100,7 @@ class LockActionHandlerLayoutManagerTest : public AshTestBase {
}
void TearDown() override {
Shell::GetPrimaryRootWindowController()->DeactivateKeyboard(
keyboard::KeyboardController::Get());
Shell::Get()->ash_keyboard_controller()->DeactivateKeyboard();
lock_window_.reset();
AshTestBase::TearDown();
LockScreenActionBackgroundController::SetFactoryCallbackForTesting(nullptr);
......
......@@ -57,13 +57,9 @@ class LockLayoutManagerTest : public AshTestBase {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
keyboard::KeyboardController::Get());
}
void TearDown() override {
Shell::GetPrimaryRootWindowController()->DeactivateKeyboard(
keyboard::KeyboardController::Get());
AshTestBase::TearDown();
}
......
......@@ -6,6 +6,7 @@
#include <memory>
#include "ash/keyboard/ash_keyboard_controller.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
......@@ -153,13 +154,11 @@ class SystemModalContainerLayoutManagerTest : public AshTestBase {
}
void ActivateKeyboard() {
Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
keyboard::KeyboardController::Get());
Shell::Get()->ash_keyboard_controller()->ActivateKeyboard();
}
void DeactivateKeyboard() {
Shell::GetPrimaryRootWindowController()->DeactivateKeyboard(
keyboard::KeyboardController::Get());
Shell::Get()->ash_keyboard_controller()->DeactivateKeyboard();
}
aura::Window* OpenToplevelTestWindow(bool modal) {
......
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