1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/display/virtual_keyboard_window_controller.h"
7 #include "ash/display/display_controller.h"
8 #include "ash/display/display_info.h"
9 #include "ash/display/display_manager.h"
10 #include "ash/host/root_window_host_factory.h"
11 #include "ash/root_window_controller.h"
12 #include "ash/root_window_settings.h"
13 #include "ash/shell.h"
14 #include "ash/shell_window_ids.h"
15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/root_window.h"
19 #include "ui/keyboard/keyboard_controller.h"
24 VirtualKeyboardWindowController::VirtualKeyboardWindowController() {
27 VirtualKeyboardWindowController::~VirtualKeyboardWindowController() {
28 // Make sure the root window gets deleted before cursor_window_delegate.
32 void VirtualKeyboardWindowController::ActivateKeyboard(
33 keyboard::KeyboardController
* keyboard_controller
) {
34 root_window_controller_
->ActivateKeyboard(keyboard_controller
);
37 void VirtualKeyboardWindowController::UpdateWindow(
38 const DisplayInfo
& display_info
) {
39 static int virtual_keyboard_root_window_count
= 0;
40 if (!root_window_controller_
.get()) {
41 const gfx::Rect
& bounds_in_native
= display_info
.bounds_in_native();
42 aura::RootWindow::CreateParams
params(bounds_in_native
);
43 params
.host
= Shell::GetInstance()->root_window_host_factory()->
44 CreateRootWindowHost(bounds_in_native
);
45 aura::RootWindow
* root_window
= new aura::RootWindow(params
);
47 root_window
->window()->SetName(
48 base::StringPrintf("VirtualKeyboardRootWindow-%d",
49 virtual_keyboard_root_window_count
++));
51 // No need to remove RootWindowObserver because
52 // the DisplayController object outlives RootWindow objects.
53 root_window
->AddRootWindowObserver(
54 Shell::GetInstance()->display_controller());
55 InitRootWindowSettings(root_window
->window())->display_id
=
58 RootWindowController::CreateForVirtualKeyboardDisplay(root_window
);
59 root_window_controller_
.reset(GetRootWindowController(
60 root_window
->window()));
61 root_window_controller_
->dispatcher()->host()->Show();
62 root_window_controller_
->ActivateKeyboard(
63 Shell::GetInstance()->keyboard_controller());
65 aura::RootWindow
* root_window
= root_window_controller_
->dispatcher();
66 GetRootWindowSettings(root_window
->window())->display_id
=
68 root_window
->SetHostBounds(display_info
.bounds_in_native());
72 void VirtualKeyboardWindowController::Close() {
73 if (root_window_controller_
.get()) {
74 root_window_controller_
->dispatcher()->RemoveRootWindowObserver(
75 Shell::GetInstance()->display_controller());
76 root_window_controller_
->Shutdown();
77 root_window_controller_
.reset();
81 } // namespace internal