1 // Copyright 2015 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/keyboard/test_keyboard_ui.h"
6 
7 #include "ash/keyboard/ui/test/keyboard_test_util.h"
8 #include "ash/shell.h"
9 #include "ash/window_factory.h"
10 #include "ash/wm/window_util.h"
11 #include "base/threading/sequenced_task_runner_handle.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_tree_host.h"
14 #include "ui/base/ime/mock_input_method.h"
15 
16 namespace ash {
17 
18 TestKeyboardUI::TestKeyboardUI() = default;
19 
20 TestKeyboardUI::~TestKeyboardUI() = default;
21 
LoadKeyboardWindow(LoadCallback callback)22 aura::Window* TestKeyboardUI::LoadKeyboardWindow(LoadCallback callback) {
23   DCHECK(!keyboard_window_);
24   keyboard_window_ = window_factory::NewWindow(&delegate_);
25   keyboard_window_->Init(ui::LAYER_NOT_DRAWN);
26 
27   // Set a default size for the keyboard.
28   display::Screen* screen = display::Screen::GetScreen();
29   keyboard_window_->SetBounds(keyboard::KeyboardBoundsFromRootBounds(
30       screen->GetPrimaryDisplay().bounds()));
31 
32   // Simulate an asynchronous load.
33   base::SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE,
34                                                    std::move(callback));
35 
36   return keyboard_window_.get();
37 }
38 
GetKeyboardWindow() const39 aura::Window* TestKeyboardUI::GetKeyboardWindow() const {
40   return keyboard_window_.get();
41 }
42 
GetGestureConsumer() const43 ui::GestureConsumer* TestKeyboardUI::GetGestureConsumer() const {
44   return GetKeyboardWindow();
45 }
46 
GetInputMethod()47 ui::InputMethod* TestKeyboardUI::GetInputMethod() {
48   aura::Window* active_window = window_util::GetActiveWindow();
49   aura::Window* root_window = active_window ? active_window->GetRootWindow()
50                                             : Shell::GetPrimaryRootWindow();
51   return root_window->GetHost()->GetInputMethod();
52 }
53 
ReloadKeyboardIfNeeded()54 void TestKeyboardUI::ReloadKeyboardIfNeeded() {}
55 
56 TestKeyboardUIFactory::TestKeyboardUIFactory() = default;
57 TestKeyboardUIFactory::~TestKeyboardUIFactory() = default;
58 
59 std::unique_ptr<keyboard::KeyboardUI>
CreateKeyboardUI()60 TestKeyboardUIFactory::CreateKeyboardUI() {
61   return std::make_unique<TestKeyboardUI>();
62 }
63 
64 }  // namespace ash
65