1 // Copyright 2014 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 "ui/keyboard/webui/vk_mojo_handler.h"
7 #include "ui/aura/window.h"
8 #include "ui/base/ime/input_method.h"
9 #include "ui/base/ime/text_input_client.h"
10 #include "ui/keyboard/keyboard_controller.h"
11 #include "ui/keyboard/keyboard_controller_proxy.h"
12 #include "ui/keyboard/keyboard_util.h"
13 #include "ui/keyboard/webui/keyboard.mojom.h"
17 VKMojoHandler::VKMojoHandler() {
18 GetInputMethod()->AddObserver(this);
21 VKMojoHandler::~VKMojoHandler() {
22 GetInputMethod()->RemoveObserver(this);
25 ui::InputMethod
* VKMojoHandler::GetInputMethod() {
26 return KeyboardController::GetInstance()->proxy()->GetInputMethod();
29 void VKMojoHandler::OnConnectionEstablished() {
30 OnTextInputStateChanged(GetInputMethod()->GetTextInputClient());
33 void VKMojoHandler::SendKeyEvent(const mojo::String
& event_type
,
36 const mojo::String
& key_name
,
38 aura::Window
* window
=
39 KeyboardController::GetInstance()->GetContainerWindow();
40 std::string type
= event_type
.To
<std::string
>();
41 std::string name
= key_name
.To
<std::string
>();
42 keyboard::SendKeyEvent(
43 type
, char_value
, key_code
, name
, modifiers
, window
->GetHost());
46 void VKMojoHandler::HideKeyboard() {
47 KeyboardController::GetInstance()->HideKeyboard(
48 KeyboardController::HIDE_REASON_MANUAL
);
51 void VKMojoHandler::OnTextInputTypeChanged(const ui::TextInputClient
* client
) {
54 void VKMojoHandler::OnFocus() {
57 void VKMojoHandler::OnBlur() {
60 void VKMojoHandler::OnCaretBoundsChanged(const ui::TextInputClient
* client
) {
63 void VKMojoHandler::OnTextInputStateChanged(
64 const ui::TextInputClient
* text_client
) {
65 ui::TextInputType type
=
66 text_client
? text_client
->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE
;
67 std::string type_name
= "none";
69 case ui::TEXT_INPUT_TYPE_NONE
:
73 case ui::TEXT_INPUT_TYPE_PASSWORD
:
74 type_name
= "password";
77 case ui::TEXT_INPUT_TYPE_EMAIL
:
81 case ui::TEXT_INPUT_TYPE_NUMBER
:
85 case ui::TEXT_INPUT_TYPE_TELEPHONE
:
89 case ui::TEXT_INPUT_TYPE_URL
:
93 case ui::TEXT_INPUT_TYPE_DATE
:
97 case ui::TEXT_INPUT_TYPE_TEXT
:
98 case ui::TEXT_INPUT_TYPE_SEARCH
:
99 case ui::TEXT_INPUT_TYPE_DATE_TIME
:
100 case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL
:
101 case ui::TEXT_INPUT_TYPE_MONTH
:
102 case ui::TEXT_INPUT_TYPE_TIME
:
103 case ui::TEXT_INPUT_TYPE_WEEK
:
104 case ui::TEXT_INPUT_TYPE_TEXT_AREA
:
105 case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE
:
106 case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD
:
110 client()->OnTextInputTypeChanged(type_name
);
113 void VKMojoHandler::OnInputMethodDestroyed(
114 const ui::InputMethod
* input_method
) {
117 void VKMojoHandler::OnShowImeIfNeeded() {
120 } // namespace keyboard