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 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 | 22 |
23 KeyboardUIHandler::~KeyboardUIHandler() { | 23 KeyboardUIHandler::~KeyboardUIHandler() { |
24 } | 24 } |
25 | 25 |
26 void KeyboardUIHandler::RegisterMessages() { | 26 void KeyboardUIHandler::RegisterMessages() { |
27 web_ui()->RegisterMessageCallback( | 27 web_ui()->RegisterMessageCallback( |
28 "insertText", | 28 "insertText", |
29 base::Bind(&KeyboardUIHandler::HandleInsertTextMessage, | 29 base::Bind(&KeyboardUIHandler::HandleInsertTextMessage, |
30 base::Unretained(this))); | 30 base::Unretained(this))); |
| 31 web_ui()->RegisterMessageCallback( |
| 32 "dispatchKeyEvent", |
| 33 base::Bind(&KeyboardUIHandler::HandleDispatchKeyEventMessage, |
| 34 base::Unretained(this))); |
31 } | 35 } |
32 | 36 |
33 void KeyboardUIHandler::HandleInsertTextMessage(const base::ListValue* args) { | 37 void KeyboardUIHandler::HandleInsertTextMessage(const base::ListValue* args) { |
34 string16 text; | 38 string16 text; |
35 if (!args->GetString(0, &text)) { | 39 if (!args->GetString(0, &text)) { |
36 LOG(ERROR) << "insertText failed: bad argument"; | 40 LOG(ERROR) << "insertText failed: bad argument"; |
37 return; | 41 return; |
38 } | 42 } |
39 | 43 |
40 aura::RootWindow* root_window = | 44 aura::RootWindow* root_window = |
41 web_ui()->GetWebContents()->GetView()->GetNativeView()->GetRootWindow(); | 45 web_ui()->GetWebContents()->GetView()->GetNativeView()->GetRootWindow(); |
42 if (!root_window) { | 46 if (!root_window) { |
43 LOG(ERROR) << "insertText failed: no root window"; | 47 LOG(ERROR) << "insertText failed: no root window"; |
44 return; | 48 return; |
45 } | 49 } |
46 | 50 |
47 if (!keyboard::InsertText(text, root_window)) | 51 if (!keyboard::InsertText(text, root_window)) |
48 LOG(ERROR) << "insertText failed"; | 52 LOG(ERROR) << "insertText failed"; |
49 } | 53 } |
50 | 54 |
| 55 void KeyboardUIHandler::HandleDispatchKeyEventMessage( |
| 56 const base::ListValue* args) { |
| 57 std::string type; |
| 58 if (!args->GetString(0, &type)) { |
| 59 LOG(ERROR) << "dispatchKeyEvent failed: bad argument"; |
| 60 return; |
| 61 } |
| 62 |
| 63 int char_code; |
| 64 if (!args->GetInteger(1, &char_code)) { |
| 65 LOG(ERROR) << "dispatchKeyEvent failed: bad argument"; |
| 66 return; |
| 67 } |
| 68 |
| 69 aura::RootWindow* root_window = |
| 70 web_ui()->GetWebContents()->GetView()->GetNativeView()->GetRootWindow(); |
| 71 if (!root_window) { |
| 72 LOG(ERROR) << "dispatchKeyEvent failed: no root window"; |
| 73 return; |
| 74 } |
| 75 |
| 76 if (!keyboard::DispatchKeyEvent(type, char_code, root_window)) |
| 77 LOG(ERROR) << "dispatchKeyEvent failed"; |
| 78 } |
| 79 |
51 } // namespace keyboard | 80 } // namespace keyboard |
OLD | NEW |