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. 4 5 #include "ash/display/virtual_keyboard_window_controller.h" 6 7 #include "ash/display/display_controller.h" 8 #include "ash/display/display_info.h" 9 #include "ash/display/display_manager.h" 10 #include "ash/display/root_window_transformers.h" 11 #include "ash/host/root_window_host_factory.h" 12 #include "ash/root_window_controller.h" 13 #include "ash/root_window_settings.h" 14 #include "ash/shell.h" 15 #include "ash/shell_window_ids.h" 16 #include "base/strings/stringprintf.h" 17 #include "base/strings/utf_string_conversions.h" 18 #include "ui/aura/env.h" 19 #include "ui/aura/root_window.h" 20 #include "ui/aura/root_window_transformer.h" 21 #include "ui/keyboard/keyboard_controller.h" 22 23 namespace ash { 24 namespace internal { 25 VirtualKeyboardWindowController()26VirtualKeyboardWindowController::VirtualKeyboardWindowController() { 27 } 28 ~VirtualKeyboardWindowController()29VirtualKeyboardWindowController::~VirtualKeyboardWindowController() { 30 // Make sure the root window gets deleted before cursor_window_delegate. 31 Close(); 32 } 33 ActivateKeyboard(keyboard::KeyboardController * keyboard_controller)34void VirtualKeyboardWindowController::ActivateKeyboard( 35 keyboard::KeyboardController* keyboard_controller) { 36 root_window_controller_->ActivateKeyboard(keyboard_controller); 37 } 38 UpdateWindow(const DisplayInfo & display_info)39void VirtualKeyboardWindowController::UpdateWindow( 40 const DisplayInfo& display_info) { 41 static int virtual_keyboard_root_window_count = 0; 42 if (!root_window_controller_.get()) { 43 const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); 44 aura::RootWindow::CreateParams params(bounds_in_native); 45 params.host = Shell::GetInstance()->root_window_host_factory()-> 46 CreateRootWindowHost(bounds_in_native); 47 aura::RootWindow* root_window = new aura::RootWindow(params); 48 49 root_window->window()->SetName( 50 base::StringPrintf("VirtualKeyboardRootWindow-%d", 51 virtual_keyboard_root_window_count++)); 52 53 // No need to remove RootWindowObserver because 54 // the DisplayController object outlives RootWindow objects. 55 root_window->AddRootWindowObserver( 56 Shell::GetInstance()->display_controller()); 57 InitRootWindowSettings(root_window->window())->display_id = 58 display_info.id(); 59 root_window->Init(); 60 RootWindowController::CreateForVirtualKeyboardDisplay(root_window); 61 root_window_controller_.reset(GetRootWindowController( 62 root_window->window())); 63 root_window_controller_->dispatcher()->host()->Show(); 64 root_window_controller_->ActivateKeyboard( 65 Shell::GetInstance()->keyboard_controller()); 66 FlipDisplay(); 67 } else { 68 aura::RootWindow* root_window = root_window_controller_->dispatcher(); 69 GetRootWindowSettings(root_window->window())->display_id = 70 display_info.id(); 71 root_window->SetHostBounds(display_info.bounds_in_native()); 72 } 73 } 74 Close()75void VirtualKeyboardWindowController::Close() { 76 if (root_window_controller_.get()) { 77 root_window_controller_->dispatcher()->RemoveRootWindowObserver( 78 Shell::GetInstance()->display_controller()); 79 root_window_controller_->Shutdown(); 80 root_window_controller_.reset(); 81 } 82 } 83 FlipDisplay()84void VirtualKeyboardWindowController::FlipDisplay() { 85 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 86 if (!display_manager->virtual_keyboard_root_window_enabled()) { 87 NOTREACHED() << "Attempting to flip virtual keyboard root window when it " 88 << "is not enabled."; 89 return; 90 } 91 display_manager->SetDisplayRotation( 92 display_manager->non_desktop_display().id(), gfx::Display::ROTATE_180); 93 94 aura::RootWindow* root_window = root_window_controller_->dispatcher(); 95 scoped_ptr<aura::RootWindowTransformer> transformer( 96 internal::CreateRootWindowTransformerForDisplay(root_window->window(), 97 display_manager->non_desktop_display())); 98 root_window->SetRootWindowTransformer(transformer.Pass()); 99 } 100 101 } // namespace internal 102 } // namespace ash 103