OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/keyboard/keyboard_ui_handler.h" | 5 #include "ui/keyboard/keyboard_ui_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 namespace keyboard { | 22 namespace keyboard { |
23 | 23 |
24 KeyboardUIHandler::KeyboardUIHandler() { | 24 KeyboardUIHandler::KeyboardUIHandler() { |
25 } | 25 } |
26 | 26 |
27 KeyboardUIHandler::~KeyboardUIHandler() { | 27 KeyboardUIHandler::~KeyboardUIHandler() { |
28 } | 28 } |
29 | 29 |
30 void KeyboardUIHandler::RegisterMessages() { | 30 void KeyboardUIHandler::RegisterMessages() { |
31 web_ui()->RegisterMessageCallback( | 31 web_ui()->RegisterMessageCallback( |
32 "insertText", | 32 "insertText", |
sadrul
2013/09/03 22:43:43
Is 'insertText' used anymore? If both 'insertText'
kevers
2013/09/04 13:51:20
InsertText is still being used for multi-character
sadrul
2013/09/04 15:44:54
Ah, ok. Thanks for explaining.
| |
33 base::Bind(&KeyboardUIHandler::HandleInsertTextMessage, | 33 base::Bind(&KeyboardUIHandler::HandleInsertTextMessage, |
34 base::Unretained(this))); | 34 base::Unretained(this))); |
35 web_ui()->RegisterMessageCallback( | 35 web_ui()->RegisterMessageCallback( |
36 "getInputContext", | 36 "getInputContext", |
37 base::Bind(&KeyboardUIHandler::HandleGetInputContextMessage, | 37 base::Bind(&KeyboardUIHandler::HandleGetInputContextMessage, |
38 base::Unretained(this))); | 38 base::Unretained(this))); |
39 web_ui()->RegisterMessageCallback( | |
40 "sendKeyEvent", | |
41 base::Bind(&KeyboardUIHandler::HandleSendKeyEventMessage, | |
42 base::Unretained(this))); | |
43 | |
39 } | 44 } |
40 | 45 |
41 void KeyboardUIHandler::HandleInsertTextMessage(const base::ListValue* args) { | 46 void KeyboardUIHandler::HandleInsertTextMessage(const base::ListValue* args) { |
42 string16 text; | 47 string16 text; |
43 if (!args->GetString(0, &text)) { | 48 if (!args->GetString(0, &text)) { |
44 LOG(ERROR) << "insertText failed: bad argument"; | 49 LOG(ERROR) << "insertText failed: bad argument"; |
45 return; | 50 return; |
46 } | 51 } |
47 | 52 |
48 aura::RootWindow* root_window = | 53 aura::RootWindow* root_window = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 } | 85 } |
81 | 86 |
82 ui::TextInputClient* tic = input_method->GetTextInputClient(); | 87 ui::TextInputClient* tic = input_method->GetTextInputClient(); |
83 results.SetInteger("type", | 88 results.SetInteger("type", |
84 tic ? tic->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE); | 89 tic ? tic->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE); |
85 | 90 |
86 web_ui()->CallJavascriptFunction("GetInputContextCallback", | 91 web_ui()->CallJavascriptFunction("GetInputContextCallback", |
87 results); | 92 results); |
88 } | 93 } |
89 | 94 |
95 void KeyboardUIHandler::HandleSendKeyEventMessage( | |
96 const base::ListValue* args) { | |
97 const base::DictionaryValue* params = NULL; | |
98 std::string type; | |
99 int char_value; | |
100 int key_code; | |
101 bool shift_modifier; | |
102 | |
103 if (!args->GetDictionary(0, ¶ms) || | |
104 !params->GetString("type", &type) || | |
105 !params->GetInteger("charValue", &char_value) || | |
106 !params->GetInteger("keyCode", &key_code) || | |
107 !params->GetBoolean("shiftKey", &shift_modifier)) { | |
108 LOG(ERROR) << "SendKeyEvent failed: bad argument"; | |
109 return; | |
110 } | |
111 | |
112 aura::RootWindow* root_window = | |
113 web_ui()->GetWebContents()->GetView()->GetNativeView()->GetRootWindow(); | |
114 if (!root_window) { | |
115 LOG(ERROR) << "sendKeyEvent failed: no root window"; | |
116 return; | |
117 } | |
118 | |
119 if (!keyboard::SendKeyEvent(type, | |
120 char_value, | |
121 key_code, | |
122 shift_modifier, | |
123 root_window)) { | |
124 LOG(ERROR) << "sendKeyEvent failed"; | |
125 } | |
126 } | |
127 | |
90 } // namespace keyboard | 128 } // namespace keyboard |
OLD | NEW |