Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/keyboard/keyboard_ui_handler.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "content/public/browser/web_ui.h" | |
| 13 #include "ui/aura/root_window.h" | |
| 14 #include "ui/base/events/event.h" | |
| 15 #include "ui/keyboard/keyboard_util.h" | |
| 16 | |
| 17 namespace keyboard { | |
| 18 | |
| 19 KeyboardUIHandler::KeyboardUIHandler(aura::RootWindow* root_window) | |
| 20 : root_window_(root_window) { | |
| 21 } | |
| 22 | |
| 23 KeyboardUIHandler::~KeyboardUIHandler() { | |
| 24 } | |
| 25 | |
| 26 void KeyboardUIHandler::RegisterMessages() { | |
| 27 web_ui()->RegisterMessageCallback( | |
| 28 "sendKeyEvent", | |
| 29 base::Bind(&KeyboardUIHandler::HandleSendKeyEventMessage, | |
| 30 base::Unretained(this))); | |
| 31 } | |
| 32 | |
| 33 void KeyboardUIHandler::HandleSendKeyEventMessage(const base::ListValue* args) { | |
| 34 std::string error; | |
| 35 scoped_ptr<ui::KeyEvent> event(keyboard::KeyEventFromArgs(args, &error)); | |
| 36 if (!event) { | |
| 37 LOG(ERROR) << "sendKeyEvent failed: " << error; | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 if (root_window_) { | |
| 42 root_window_->AsRootWindowHostDelegate()->OnHostKeyEvent(event.get()); | |
|
sadrul
2013/04/18 02:58:28
Does it make sense to use web_ui()->GetWebContents
bryeung
2013/04/18 14:42:36
Clever! This is a great simplification. Done.
| |
| 43 } else { | |
| 44 DLOG(INFO) << "KeyboardUIHandler handling sendKeyEvent: key_code=" | |
| 45 << event->key_code(); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 } // namespace keyboard | |
| OLD | NEW |