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. 4 5 #include "ui/keyboard/webui/vk_mojo_handler.h" 6 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" 14 15 namespace keyboard { 16 17 VKMojoHandler::VKMojoHandler() { 18 GetInputMethod()->AddObserver(this); 19 } 20 21 VKMojoHandler::~VKMojoHandler() { 22 GetInputMethod()->RemoveObserver(this); 23 } 24 25 ui::InputMethod* VKMojoHandler::GetInputMethod() { 26 return KeyboardController::GetInstance()->proxy()->GetInputMethod(); 27 } 28 29 void VKMojoHandler::OnConnectionEstablished() { 30 OnTextInputStateChanged(GetInputMethod()->GetTextInputClient()); 31 } 32 33 void VKMojoHandler::SendKeyEvent(const mojo::String& event_type, 34 int32_t char_value, 35 int32_t key_code, 36 const mojo::String& key_name, 37 int32_t modifiers) { 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()); 44 } 45 46 void VKMojoHandler::HideKeyboard() { 47 KeyboardController::GetInstance()->HideKeyboard( 48 KeyboardController::HIDE_REASON_MANUAL); 49 } 50 51 void VKMojoHandler::OnTextInputTypeChanged(const ui::TextInputClient* client) { 52 } 53 54 void VKMojoHandler::OnFocus() { 55 } 56 57 void VKMojoHandler::OnBlur() { 58 } 59 60 void VKMojoHandler::OnCaretBoundsChanged(const ui::TextInputClient* client) { 61 } 62 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"; 68 switch (type) { 69 case ui::TEXT_INPUT_TYPE_NONE: 70 type_name = "none"; 71 break; 72 73 case ui::TEXT_INPUT_TYPE_PASSWORD: 74 type_name = "password"; 75 break; 76 77 case ui::TEXT_INPUT_TYPE_EMAIL: 78 type_name = "email"; 79 break; 80 81 case ui::TEXT_INPUT_TYPE_NUMBER: 82 type_name = "number"; 83 break; 84 85 case ui::TEXT_INPUT_TYPE_TELEPHONE: 86 type_name = "tel"; 87 break; 88 89 case ui::TEXT_INPUT_TYPE_URL: 90 type_name = "url"; 91 break; 92 93 case ui::TEXT_INPUT_TYPE_DATE: 94 type_name = "date"; 95 break; 96 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: 107 type_name = "text"; 108 break; 109 } 110 client()->OnTextInputTypeChanged(type_name); 111 } 112 113 void VKMojoHandler::OnInputMethodDestroyed( 114 const ui::InputMethod* input_method) { 115 } 116 117 void VKMojoHandler::OnShowImeIfNeeded() { 118 } 119 120 } // namespace keyboard 121