Skip to content

Commit

Permalink
Add a full screen virtual keyboard to virtual keyboard root window
Browse files Browse the repository at this point in the history
BUG=310331
TEST=
1. add keyboard-usability-experiment flag
2. hook up an external screen
3. boot device
expected: a full screen keyboard on one of the screen

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235502 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bshe@chromium.org committed Nov 16, 2013
1 parent 5e01b54 commit a53dcc9
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 48 deletions.
7 changes: 5 additions & 2 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@
'host/root_window_host_factory.cc',
'host/root_window_host_factory.h',
'host/root_window_host_factory_win.cc',
'keyboard_controller_proxy_stub.cc',
'keyboard_controller_proxy_stub.h',
'keyboard_overlay/keyboard_overlay_delegate.cc',
'keyboard_overlay/keyboard_overlay_delegate.h',
'keyboard_overlay/keyboard_overlay_view.cc',
Expand Down Expand Up @@ -639,6 +637,8 @@
'sources': [
'shell/toplevel_window.cc',
'shell/toplevel_window.h',
'shell/keyboard_controller_proxy_stub.cc',
'shell/keyboard_controller_proxy_stub.h',
'test/app_list_controller_test_api.cc',
'test/app_list_controller_test_api.h',
'test/ash_test_base.cc',
Expand Down Expand Up @@ -754,6 +754,7 @@
'display/display_info_unittest.cc',
'display/display_manager_unittest.cc',
'display/mirror_window_controller_unittest.cc',
'display/virtual_keyboard_window_controller_unittest.cc',
'display/mouse_cursor_event_filter_unittest.cc',
'display/resolution_notification_controller_unittest.cc',
'display/root_window_transformers_unittest.cc',
Expand Down Expand Up @@ -949,6 +950,8 @@
'shell/context_menu.cc',
'shell/context_menu.h',
'shell/example_factory.h',
'shell/keyboard_controller_proxy_stub.cc',
'shell/keyboard_controller_proxy_stub.h',
'shell/launcher_delegate_impl.cc',
'shell/launcher_delegate_impl.h',
'shell/lock_view.cc',
Expand Down
5 changes: 5 additions & 0 deletions ash/display/display_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver,
return mirror_window_controller_.get();
}

internal::VirtualKeyboardWindowController*
virtual_keyboard_window_controller() {
return virtual_keyboard_window_controller_.get();
}

// Initializes primary display.
void InitPrimaryDisplay();

Expand Down
8 changes: 8 additions & 0 deletions ash/display/virtual_keyboard_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/keyboard/keyboard_controller.h"

namespace ash {
namespace internal {
Expand All @@ -28,6 +29,11 @@ VirtualKeyboardWindowController::~VirtualKeyboardWindowController() {
Close();
}

void VirtualKeyboardWindowController::ActivateKeyboard(
keyboard::KeyboardController* keyboard_controller) {
root_window_controller_->ActivateKeyboard(keyboard_controller);
}

void VirtualKeyboardWindowController::UpdateWindow(
const DisplayInfo& display_info) {
static int virtual_keyboard_root_window_count = 0;
Expand All @@ -53,6 +59,8 @@ void VirtualKeyboardWindowController::UpdateWindow(
root_window_controller_.reset(GetRootWindowController(
root_window->window()));
root_window_controller_->dispatcher()->host()->Show();
root_window_controller_->ActivateKeyboard(
Shell::GetInstance()->keyboard_controller());
} else {
aura::RootWindow* root_window = root_window_controller_->dispatcher();
GetRootWindowSettings(root_window->window())->display_id =
Expand Down
16 changes: 16 additions & 0 deletions ash/display/virtual_keyboard_window_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"

namespace keyboard {
class KeyboardController;
}

namespace ash {

namespace test {
class VirtualKeyboardWindowControllerTest;
} // namespace test

namespace internal {
class DisplayInfo;
class RootWindowController;
Expand All @@ -22,6 +30,8 @@ class ASH_EXPORT VirtualKeyboardWindowController {
VirtualKeyboardWindowController();
virtual ~VirtualKeyboardWindowController();

void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);

// Updates the root window's bounds using |display_info|.
// Creates the new root window if one doesn't exist.
void UpdateWindow(const DisplayInfo& display_info);
Expand All @@ -30,6 +40,12 @@ class ASH_EXPORT VirtualKeyboardWindowController {
void Close();

private:
friend class test::VirtualKeyboardWindowControllerTest;

RootWindowController* root_window_controller_for_test() {
return root_window_controller_.get();
}

scoped_ptr<RootWindowController> root_window_controller_;

DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardWindowController);
Expand Down
64 changes: 64 additions & 0 deletions ash/display/virtual_keyboard_window_controller_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/display/virtual_keyboard_window_controller.h"

#include "ash/ash_switches.h"
#include "ash/display/display_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "base/command_line.h"
#include "ui/keyboard/keyboard_switches.h"

namespace ash {
namespace test {

class VirtualKeyboardWindowControllerTest : public AshTestBase {
public:
VirtualKeyboardWindowControllerTest()
: virtual_keyboard_window_controller_(NULL) {}
virtual ~VirtualKeyboardWindowControllerTest() {}

virtual void SetUp() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kAshHostWindowBounds, "1+1-300x300,1+301-300x300");
CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kKeyboardUsabilityExperiment);
test::AshTestBase::SetUp();
}

void set_virtual_keyboard_window_controller(
internal::VirtualKeyboardWindowController* controller) {
virtual_keyboard_window_controller_ = controller;
}

internal::RootWindowController* root_window_controller() {
return virtual_keyboard_window_controller_->
root_window_controller_for_test();
}

private:
internal::VirtualKeyboardWindowController*
virtual_keyboard_window_controller_;
DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardWindowControllerTest);
};


TEST_F(VirtualKeyboardWindowControllerTest, VirtualKeyboardWindowTest) {
if (!SupportsMultipleDisplays())
return;
RunAllPendingInMessageLoop();
set_virtual_keyboard_window_controller(
Shell::GetInstance()->display_controller()->
virtual_keyboard_window_controller());
EXPECT_TRUE(root_window_controller());
// Keyboard container is added to virtual keyboard window.
EXPECT_TRUE(root_window_controller()->GetContainer(
internal::kShellWindowId_VirtualKeyboardContainer));
}

} // namespace test
} // namespace ash
27 changes: 17 additions & 10 deletions ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,11 @@ void RootWindowController::ActivateKeyboard(
return;
}
DCHECK(keyboard_controller);
keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
keyboard_controller->AddObserver(panel_layout_manager_);
keyboard_controller->AddObserver(docked_layout_manager_);
if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
keyboard_controller->AddObserver(panel_layout_manager_);
keyboard_controller->AddObserver(docked_layout_manager_);
}
aura::Window* parent = root_window();
aura::Window* keyboard_container =
keyboard_controller->GetContainerWindow();
Expand All @@ -565,9 +567,11 @@ void RootWindowController::DeactivateKeyboard(
keyboard_controller->GetContainerWindow();
if (keyboard_container->GetRootWindow() == root_window()) {
root_window()->RemoveChild(keyboard_container);
keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
keyboard_controller->RemoveObserver(panel_layout_manager_);
keyboard_controller->RemoveObserver(docked_layout_manager_);
if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
keyboard_controller->RemoveObserver(panel_layout_manager_);
keyboard_controller->RemoveObserver(docked_layout_manager_);
}
}
}

Expand All @@ -593,13 +597,16 @@ RootWindowController::RootWindowController(aura::RootWindow* root_window)

void RootWindowController::Init(RootWindowType root_window_type,
bool first_run_after_boot) {
Shell::GetInstance()->InitRootWindow(root_window());
Shell* shell = Shell::GetInstance();
shell->InitRootWindow(root_window());

root_window_->SetCursor(ui::kCursorPointer);
CreateContainersInRootWindow(root_window_->window());

if (root_window_type == VIRTUAL_KEYBOARD)
if (root_window_type == VIRTUAL_KEYBOARD) {
shell->InitKeyboard();
return;
}

CreateSystemBackground(first_run_after_boot);

Expand All @@ -611,12 +618,12 @@ void RootWindowController::Init(RootWindowType root_window_type,
GetSystemModalLayoutManager(NULL)->CreateModalBackground();
}

Shell* shell = Shell::GetInstance();
shell->AddShellObserver(this);

if (root_window_type == PRIMARY) {
root_window_layout()->OnWindowResized();
shell->InitKeyboard(this);
if (!keyboard::IsKeyboardUsabilityExperimentEnabled())
shell->InitKeyboard();
} else {
root_window_layout()->OnWindowResized();
shell->desktop_background_controller()->OnRootWindowAdded(root_window());
Expand Down
4 changes: 2 additions & 2 deletions ash/root_window_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ TEST_F(VirtualKeyboardRootWindowControllerTest,
// Track the keyboard container window.
aura::WindowTracker tracker;
tracker.Add(keyboard_container);
// Mock a login state change to reinitialize the keyboard.
ash::Shell::GetInstance()->OnLoginStateChanged(user::LOGGED_IN_OWNER);
// Mock a login user profile change to reinitialize the keyboard.
ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
// keyboard_container should no longer be present.
EXPECT_FALSE(tracker.Contains(keyboard_container));
}
Expand Down
31 changes: 22 additions & 9 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ash/display/mouse_cursor_event_filter.h"
#include "ash/display/resolution_notification_controller.h"
#include "ash/display/screen_position_controller.h"
#include "ash/display/virtual_keyboard_window_controller.h"
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/first_run/first_run_helper_impl.h"
#include "ash/focus_cycler.h"
Expand Down Expand Up @@ -337,16 +338,14 @@ void Shell::SetDisplayWorkAreaInsets(Window* contains,
}

void Shell::OnLoginStateChanged(user::LoginStatus status) {
if (status != user::LOGGED_IN_NONE) {
// TODO(bshe): Primary root window controller may not be the controller to
// attach virtual keyboard. See http://crbug.com/303429
InitKeyboard(GetPrimaryRootWindowController());
GetPrimaryRootWindowController()->ActivateKeyboard(
keyboard_controller_.get());
}
FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status));
}

void Shell::OnLoginUserProfilePrepared() {
CreateLauncher();
CreateKeyboard();
}

void Shell::UpdateAfterLoginStatusChange(user::LoginStatus status) {
RootWindowControllerList controllers = GetAllRootWindowControllers();
for (RootWindowControllerList::iterator iter = controllers.begin();
Expand Down Expand Up @@ -381,6 +380,19 @@ void Shell::CreateLauncher() {
(*iter)->shelf()->CreateLauncher();
}

void Shell::CreateKeyboard() {
// TODO(bshe): Primary root window controller may not be the controller to
// attach virtual keyboard. See http://crbug.com/303429
InitKeyboard();
if (keyboard::IsKeyboardUsabilityExperimentEnabled()) {
display_controller()->virtual_keyboard_window_controller()->
ActivateKeyboard(keyboard_controller_.get());
} else {
GetPrimaryRootWindowController()->
ActivateKeyboard(keyboard_controller_.get());
}
}

void Shell::ShowLauncher() {
RootWindowControllerList controllers = GetAllRootWindowControllers();
for (RootWindowControllerList::iterator iter = controllers.begin();
Expand Down Expand Up @@ -619,6 +631,7 @@ Shell::~Shell() {

// Destroy all child windows including widgets.
display_controller_->CloseChildWindows();
display_controller_->CloseNonDesktopDisplay();

// Destroy SystemTrayNotifier after destroying SystemTray as TrayItems
// needs to remove observers from it.
Expand Down Expand Up @@ -693,7 +706,7 @@ void Shell::Init() {
CommandLine* command_line = CommandLine::ForCurrentProcess();

delegate_->PreInit();
if (command_line->HasSwitch(keyboard::switches::kKeyboardUsabilityTest)) {
if (keyboard::IsKeyboardUsabilityExperimentEnabled()) {
display_manager_->SetSecondDisplayMode(
internal::DisplayManager::VIRTUAL_KEYBOARD);
}
Expand Down Expand Up @@ -916,7 +929,7 @@ void Shell::Init() {
weak_display_manager_factory_->GetWeakPtr()));
}

void Shell::InitKeyboard(internal::RootWindowController* root) {
void Shell::InitKeyboard() {
if (keyboard::IsKeyboardEnabled()) {
if (keyboard_controller_.get()) {
RootWindowControllerList controllers = GetAllRootWindowControllers();
Expand Down
11 changes: 9 additions & 2 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ class ASH_EXPORT Shell
// Called when the user logs in.
void OnLoginStateChanged(user::LoginStatus status);

// Called after the logged-in user's profile is ready.
void OnLoginUserProfilePrepared();

// Called when the login status changes.
// TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
void UpdateAfterLoginStatusChange(user::LoginStatus status);
Expand All @@ -283,6 +286,10 @@ class ASH_EXPORT Shell
// Initializes |launcher_|. Does nothing if it's already initialized.
void CreateLauncher();

// Creates virtual keyboard. Deletes the old virtual keyboard if it's already
// exist.
void CreateKeyboard();

// Show shelf view if it was created hidden (before session has started).
void ShowLauncher();

Expand Down Expand Up @@ -539,8 +546,8 @@ class ASH_EXPORT Shell

void Init();

// Initializes virtual keyboard controller and attaches it to |root|.
void InitKeyboard(internal::RootWindowController* root);
// Initializes virtual keyboard controller.
void InitKeyboard();

// Initializes the root window so that it can host browser windows.
void InitRootWindow(aura::Window* root_window);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/keyboard_controller_proxy_stub.h"
#include "ash/shell/keyboard_controller_proxy_stub.h"

#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ui/aura/window.h"
#include "ui/views/corewm/input_method_event_filter.h"

using namespace content;
Expand All @@ -18,6 +19,12 @@ KeyboardControllerProxyStub::KeyboardControllerProxyStub() {
KeyboardControllerProxyStub::~KeyboardControllerProxyStub() {
}

aura::Window* KeyboardControllerProxyStub::GetKeyboardWindow() {
aura::Window* window = new aura::Window(&delegate_);
window->Init(ui::LAYER_NOT_DRAWN);
return window;
}

BrowserContext* KeyboardControllerProxyStub::GetBrowserContext() {
return Shell::GetInstance()->delegate()->GetCurrentBrowserContext();
}
Expand Down
Loading

0 comments on commit a53dcc9

Please sign in to comment.