OLD | NEW |
(Empty) | |
| 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 "athena/virtual_keyboard/vk_message_handler.h" |
| 6 |
| 7 #include "athena/screen/public/screen_manager.h" |
| 8 #include "base/bind.h" |
| 9 #include "base/values.h" |
| 10 #include "content/public/browser/web_ui.h" |
| 11 #include "ui/keyboard/keyboard_controller.h" |
| 12 #include "ui/keyboard/keyboard_util.h" |
| 13 |
| 14 namespace athena { |
| 15 |
| 16 VKMessageHandler::VKMessageHandler() { |
| 17 } |
| 18 VKMessageHandler::~VKMessageHandler() { |
| 19 } |
| 20 |
| 21 void VKMessageHandler::RegisterMessages() { |
| 22 web_ui()->RegisterMessageCallback( |
| 23 "sendKeyEvent", |
| 24 base::Bind(&VKMessageHandler::SendKeyEvent, base::Unretained(this))); |
| 25 web_ui()->RegisterMessageCallback( |
| 26 "hideKeyboard", |
| 27 base::Bind(&VKMessageHandler::HideKeyboard, base::Unretained(this))); |
| 28 } |
| 29 |
| 30 void VKMessageHandler::SendKeyEvent(const base::ListValue* params) { |
| 31 std::string type; |
| 32 int char_value; |
| 33 int key_code; |
| 34 std::string key_name; |
| 35 int modifiers; |
| 36 if (!params->GetString(0, &type)) |
| 37 return; |
| 38 if (!params->GetInteger(1, &char_value)) |
| 39 return; |
| 40 if (!params->GetInteger(2, &key_code)) |
| 41 return; |
| 42 if (!params->GetString(3, &key_name)) |
| 43 return; |
| 44 if (!params->GetInteger(4, &modifiers)) |
| 45 return; |
| 46 |
| 47 aura::Window* window = ScreenManager::Get()->GetContext(); |
| 48 keyboard::SendKeyEvent( |
| 49 type, char_value, key_code, key_name, modifiers, window->GetHost()); |
| 50 } |
| 51 |
| 52 void VKMessageHandler::HideKeyboard(const base::ListValue* params) { |
| 53 keyboard::KeyboardController::GetInstance()->HideKeyboard( |
| 54 keyboard::KeyboardController::HIDE_REASON_MANUAL); |
| 55 } |
| 56 |
| 57 } // namespace athena |
OLD | NEW |