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 mojo::InterfaceRequest
<KeyboardUIHandlerMojo
> request
)
19 : binding_(this, request
.Pass()) {
20 GetInputMethod()->AddObserver(this);
21 OnTextInputStateChanged(GetInputMethod()->GetTextInputClient());
24 VKMojoHandler::~VKMojoHandler() {
25 GetInputMethod()->RemoveObserver(this);
28 ui::InputMethod
* VKMojoHandler::GetInputMethod() {
29 return KeyboardController::GetInstance()->proxy()->GetInputMethod();
32 void VKMojoHandler::SendKeyEvent(const mojo::String
& event_type
,
35 const mojo::String
& key_name
,
37 aura::Window
* window
=
38 KeyboardController::GetInstance()->GetContainerWindow();
39 std::string type
= event_type
.To
<std::string
>();
40 std::string name
= key_name
.To
<std::string
>();
41 keyboard::SendKeyEvent(
42 type
, char_value
, key_code
, name
, modifiers
, window
->GetHost());
45 void VKMojoHandler::HideKeyboard() {
46 KeyboardController::GetInstance()->HideKeyboard(
47 KeyboardController::HIDE_REASON_MANUAL
);
50 void VKMojoHandler::OnTextInputTypeChanged(const ui::TextInputClient
* client
) {
53 void VKMojoHandler::OnFocus() {
56 void VKMojoHandler::OnBlur() {
59 void VKMojoHandler::OnCaretBoundsChanged(const ui::TextInputClient
* client
) {
62 void VKMojoHandler::OnTextInputStateChanged(
63 const ui::TextInputClient
* text_client
) {
64 ui::TextInputType type
=
65 text_client
? text_client
->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE
;
66 std::string type_name
= "none";
68 case ui::TEXT_INPUT_TYPE_NONE
:
72 case ui::TEXT_INPUT_TYPE_PASSWORD
:
73 type_name
= "password";
76 case ui::TEXT_INPUT_TYPE_EMAIL
:
80 case ui::TEXT_INPUT_TYPE_NUMBER
:
84 case ui::TEXT_INPUT_TYPE_TELEPHONE
:
88 case ui::TEXT_INPUT_TYPE_URL
:
92 case ui::TEXT_INPUT_TYPE_DATE
:
96 case ui::TEXT_INPUT_TYPE_TEXT
:
97 case ui::TEXT_INPUT_TYPE_SEARCH
:
98 case ui::TEXT_INPUT_TYPE_DATE_TIME
:
99 case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL
:
100 case ui::TEXT_INPUT_TYPE_MONTH
:
101 case ui::TEXT_INPUT_TYPE_TIME
:
102 case ui::TEXT_INPUT_TYPE_WEEK
:
103 case ui::TEXT_INPUT_TYPE_TEXT_AREA
:
104 case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE
:
105 case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD
:
109 binding_
.client()->OnTextInputTypeChanged(type_name
);
112 void VKMojoHandler::OnInputMethodDestroyed(
113 const ui::InputMethod
* input_method
) {
116 void VKMojoHandler::OnShowImeIfNeeded() {
119 } // namespace keyboard