Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: ui/keyboard/keyboard_ui_handler.cc

Issue 16972006: Insert text directly from the virtual keyboard. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix include Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/keyboard/keyboard_ui_handler.h ('k') | ui/keyboard/keyboard_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/values.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_view.h" 13 #include "content/public/browser/web_contents_view.h"
14 #include "content/public/browser/web_ui.h" 14 #include "content/public/browser/web_ui.h"
15 #include "ui/aura/root_window.h" 15 #include "ui/aura/window.h"
16 #include "ui/base/events/event.h"
17 #include "ui/keyboard/keyboard_util.h" 16 #include "ui/keyboard/keyboard_util.h"
18 17
19 namespace keyboard { 18 namespace keyboard {
20 19
21 KeyboardUIHandler::KeyboardUIHandler() { 20 KeyboardUIHandler::KeyboardUIHandler() {
22 } 21 }
23 22
24 KeyboardUIHandler::~KeyboardUIHandler() { 23 KeyboardUIHandler::~KeyboardUIHandler() {
25 } 24 }
26 25
27 void KeyboardUIHandler::RegisterMessages() { 26 void KeyboardUIHandler::RegisterMessages() {
28 web_ui()->RegisterMessageCallback( 27 web_ui()->RegisterMessageCallback(
29 "sendKeyEvent", 28 "insertText",
30 base::Bind(&KeyboardUIHandler::HandleSendKeyEventMessage, 29 base::Bind(&KeyboardUIHandler::HandleInsertTextMessage,
31 base::Unretained(this))); 30 base::Unretained(this)));
32 } 31 }
33 32
34 void KeyboardUIHandler::HandleSendKeyEventMessage(const base::ListValue* args) { 33 void KeyboardUIHandler::HandleInsertTextMessage(const base::ListValue* args) {
35 std::string error; 34 string16 text;
36 scoped_ptr<ui::KeyEvent> event(keyboard::KeyEventFromArgs(args, &error)); 35 if (!args->GetString(0, &text)) {
37 if (!event) { 36 LOG(ERROR) << "insertText failed: bad argument";
38 LOG(ERROR) << "sendKeyEvent failed: " << error;
39 return; 37 return;
40 } 38 }
41 39
42 aura::RootWindow* root_window = 40 aura::RootWindow* root_window =
43 web_ui()->GetWebContents()->GetView()->GetNativeView()->GetRootWindow(); 41 web_ui()->GetWebContents()->GetView()->GetNativeView()->GetRootWindow();
44 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(event.get()); 42 if (!root_window) {
43 LOG(ERROR) << "insertText failed: no root window";
44 return;
45 }
46
47 if (!keyboard::InsertText(text, root_window))
48 LOG(ERROR) << "insertText failed";
45 } 49 }
46 50
47 } // namespace keyboard 51 } // namespace keyboard
OLDNEW
« no previous file with comments | « ui/keyboard/keyboard_ui_handler.h ('k') | ui/keyboard/keyboard_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698