Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "remoting/host/input_injector_chromeos.h" | 5 #include "remoting/host/input_injector_chromeos.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/location.h" | |
| 10 #include "remoting/host/clipboard.h" | |
| 8 #include "remoting/proto/internal.pb.h" | 11 #include "remoting/proto/internal.pb.h" |
| 12 #include "ui/events/keycodes/dom3/dom_code.h" | |
| 13 #include "ui/events/keycodes/dom4/keycode_converter.h" | |
| 14 #include "ui/ozone/public/ozone_platform.h" | |
| 15 #include "ui/ozone/public/system_input_injector.h" | |
| 9 | 16 |
| 10 namespace remoting { | 17 namespace remoting { |
| 11 | 18 |
| 12 using protocol::ClipboardEvent; | 19 using protocol::ClipboardEvent; |
| 13 using protocol::KeyEvent; | 20 using protocol::KeyEvent; |
| 14 using protocol::MouseEvent; | 21 using protocol::MouseEvent; |
| 15 using protocol::TextEvent; | 22 using protocol::TextEvent; |
| 16 | 23 |
| 17 // TODO(kelvinp): Implement this class (See crbug.com/426716). | 24 namespace { |
| 25 | |
| 26 ui::EventFlags MouseButtonToUIFlags(MouseEvent::MouseButton button) { | |
| 27 switch (button) { | |
| 28 case MouseEvent::BUTTON_LEFT: | |
| 29 return ui::EF_LEFT_MOUSE_BUTTON; | |
| 30 case MouseEvent::BUTTON_RIGHT: | |
| 31 return ui::EF_RIGHT_MOUSE_BUTTON; | |
| 32 case MouseEvent::BUTTON_MIDDLE: | |
| 33 return ui::EF_MIDDLE_MOUSE_BUTTON; | |
| 34 default: | |
| 35 NOTREACHED(); | |
| 36 return ui::EF_NONE; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 class InputInjectorChromeos::Core { | |
| 43 public: | |
| 44 explicit Core(scoped_ptr<ui::SystemInputInjector> delegate_); | |
| 45 | |
| 46 // Mirrors the public InputInjectorChromeos interface. | |
| 47 void InjectClipboardEvent(const ClipboardEvent& event); | |
| 48 void InjectKeyEvent(const KeyEvent& event); | |
| 49 void InjectTextEvent(const TextEvent& event); | |
| 50 void InjectMouseEvent(const MouseEvent& event); | |
| 51 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); | |
| 52 | |
| 53 private: | |
| 54 scoped_ptr<ui::SystemInputInjector> delegate_; | |
| 55 scoped_ptr<Clipboard> clipboard_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(Core); | |
| 58 }; | |
| 59 | |
| 60 InputInjectorChromeos::Core::Core(scoped_ptr<ui::SystemInputInjector> delegate) | |
| 61 : delegate_(delegate.Pass()), | |
| 62 clipboard_(Clipboard::Create()) { | |
| 63 DCHECK(delegate); | |
| 64 | |
| 65 // TODO(kelvinp): Disable AutoRepeat as long as keys are pressed on ChromeOS | |
| 66 // when the auto-repeat API is ready to avoid triggering the auto-repeat if | |
| 67 // network congestion delays the key-up event from the client | |
| 68 // (See crbug.com/425201). | |
| 69 } | |
| 70 | |
| 71 void InputInjectorChromeos::Core::InjectClipboardEvent( | |
| 72 const ClipboardEvent& event) { | |
| 73 clipboard_->InjectClipboardEvent(event); | |
| 74 } | |
| 75 | |
| 76 void InputInjectorChromeos::Core::InjectKeyEvent(const KeyEvent& event) { | |
| 77 if (!event.has_pressed() || !event.has_usb_keycode()) { | |
| 78 return; | |
| 79 } | |
| 80 | |
| 81 ui::DomCode dom_code = | |
| 82 ui::KeycodeConverter::UsbKeycodeToDomCode(event.usb_keycode()); | |
| 83 | |
| 84 // Ignore events which can't be mapped. | |
| 85 if (dom_code != ui::DomCode::NONE) { | |
| 86 delegate_->InjectKeyPress(dom_code, event.pressed()); | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 void InputInjectorChromeos::Core::InjectTextEvent(const TextEvent& event) { | |
| 91 // TextEvents are not supported on Chrome OS. | |
| 92 NOTIMPLEMENTED(); | |
| 93 } | |
| 94 | |
| 95 void InputInjectorChromeos::Core::InjectMouseEvent(const MouseEvent& event) { | |
| 96 if (event.has_button() && event.has_button_down()) { | |
| 97 delegate_->InjectMouseButton(MouseButtonToUIFlags(event.button()), | |
| 98 event.button_down()); | |
| 99 } else if (event.has_wheel_delta_y() || event.has_wheel_delta_x()) { | |
| 100 delegate_->InjectMouseWheel(event.wheel_delta_x(), event.wheel_delta_y()); | |
| 101 } else { | |
| 102 DCHECK(event.has_x() && event.has_y()); | |
|
spang
2014/11/26 17:06:42
I think just do:
aura::WindowTreeHost* host = ash
kelvinp
2014/12/02 00:12:26
We need a class to handle the rotation for a few r
spang
2014/12/02 21:00:19
Those pending changes are now landed. You should u
| |
| 103 delegate_->MoveCursorTo(gfx::PointF(event.x(), event.y())); | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 void InputInjectorChromeos::Core::Start( | |
| 108 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | |
| 109 clipboard_->Start(client_clipboard.Pass()); | |
| 110 } | |
| 111 | |
| 18 InputInjectorChromeos::InputInjectorChromeos( | 112 InputInjectorChromeos::InputInjectorChromeos( |
| 19 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 113 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 20 : input_task_runner_(task_runner) { | 114 : input_task_runner_(task_runner) { |
| 21 NOTIMPLEMENTED(); | 115 ui::OzonePlatform* ozone_platform = ui::OzonePlatform::GetInstance(); |
| 116 core_.reset(new Core(ozone_platform->CreateSystemInputInjector())); | |
| 22 } | 117 } |
| 23 | 118 |
| 24 InputInjectorChromeos::~InputInjectorChromeos() { | 119 InputInjectorChromeos::~InputInjectorChromeos() { |
| 25 NOTIMPLEMENTED(); | 120 input_task_runner_->DeleteSoon(FROM_HERE, core_.release()); |
| 26 } | 121 } |
| 27 | 122 |
| 28 void InputInjectorChromeos::InjectClipboardEvent(const ClipboardEvent& event) { | 123 void InputInjectorChromeos::InjectClipboardEvent(const ClipboardEvent& event) { |
| 29 NOTIMPLEMENTED(); | 124 input_task_runner_->PostTask( |
| 125 FROM_HERE, base::Bind(&Core::InjectClipboardEvent, | |
| 126 base::Unretained(core_.get()), event)); | |
| 30 } | 127 } |
| 31 | 128 |
| 32 void InputInjectorChromeos::InjectKeyEvent(const KeyEvent& event) { | 129 void InputInjectorChromeos::InjectKeyEvent(const KeyEvent& event) { |
| 33 NOTIMPLEMENTED(); | 130 input_task_runner_->PostTask( |
| 131 FROM_HERE, | |
| 132 base::Bind(&Core::InjectKeyEvent, base::Unretained(core_.get()), event)); | |
| 34 } | 133 } |
| 35 | 134 |
| 36 void InputInjectorChromeos::InjectTextEvent(const TextEvent& event) { | 135 void InputInjectorChromeos::InjectTextEvent(const TextEvent& event) { |
| 37 NOTIMPLEMENTED(); | 136 input_task_runner_->PostTask( |
| 137 FROM_HERE, | |
| 138 base::Bind(&Core::InjectTextEvent, base::Unretained(core_.get()), event)); | |
| 38 } | 139 } |
| 39 | 140 |
| 40 void InputInjectorChromeos::InjectMouseEvent(const MouseEvent& event) { | 141 void InputInjectorChromeos::InjectMouseEvent(const MouseEvent& event) { |
| 41 NOTIMPLEMENTED(); | 142 input_task_runner_->PostTask( |
| 143 FROM_HERE, base::Bind(&Core::InjectMouseEvent, | |
| 144 base::Unretained(core_.get()), event)); | |
| 42 } | 145 } |
| 43 | 146 |
| 44 void InputInjectorChromeos::Start( | 147 void InputInjectorChromeos::Start( |
| 45 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 148 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
| 46 NOTIMPLEMENTED(); | 149 input_task_runner_->PostTask( |
| 150 FROM_HERE, base::Bind(&Core::Start, base::Unretained(core_.get()), | |
| 151 base::Passed(&client_clipboard))); | |
| 47 } | 152 } |
| 48 | 153 |
| 49 // static | 154 // static |
| 50 scoped_ptr<InputInjector> InputInjector::Create( | 155 scoped_ptr<InputInjector> InputInjector::Create( |
| 51 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 156 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 52 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 157 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 53 scoped_ptr<InputInjectorChromeos> injector(new InputInjectorChromeos( | 158 return make_scoped_ptr(new InputInjectorChromeos(ui_task_runner)); |
| 54 ui_task_runner)); | |
| 55 return injector.Pass(); | |
| 56 } | 159 } |
| 57 | 160 |
| 58 } // namespace remoting | 161 } // namespace remoting |
| OLD | NEW |