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