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/pixel_rotator.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 // This class is run exclusively on the UI thread of the browser process. | |
| 44 class InputInjectorChromeos::Core { | |
| 45 public: | |
| 46 explicit Core(scoped_ptr<ui::SystemInputInjector> delegate_); | |
| 47 | |
| 48 // Mirrors the public InputInjectorChromeos interface. | |
| 49 void InjectClipboardEvent(const ClipboardEvent& event); | |
| 50 void InjectKeyEvent(const KeyEvent& event); | |
| 51 void InjectTextEvent(const TextEvent& event); | |
| 52 void InjectMouseEvent(const MouseEvent& event); | |
| 53 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard); | |
| 54 | |
| 55 private: | |
| 56 scoped_ptr<ui::SystemInputInjector> delegate_; | |
| 57 scoped_ptr<Clipboard> clipboard_; | |
| 58 | |
| 59 // Rotate the input coordinates appropriately based on the current display | |
|
Wez
2014/12/06 01:55:17
nit: "Used to rotate..."
kelvinp
2014/12/08 18:41:44
Done.
| |
| 60 // rotation settings. | |
| 61 scoped_ptr<PixelRotator> input_rotator_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(Core); | |
| 64 }; | |
| 65 | |
| 66 InputInjectorChromeos::Core::Core(scoped_ptr<ui::SystemInputInjector> delegate) | |
| 67 : delegate_(delegate.Pass()), | |
| 68 // Implemented by remoting::ClipboardAura. | |
| 69 clipboard_(Clipboard::Create()) { | |
| 70 DCHECK(delegate); | |
|
Wez
2014/12/06 01:55:17
nit: Do you need to check that |clipboard_| succee
kelvinp
2014/12/08 18:41:44
Done.
| |
| 71 } | |
| 72 | |
| 73 void InputInjectorChromeos::Core::InjectClipboardEvent( | |
| 74 const ClipboardEvent& event) { | |
| 75 clipboard_->InjectClipboardEvent(event); | |
| 76 } | |
| 77 | |
| 78 void InputInjectorChromeos::Core::InjectKeyEvent(const KeyEvent& event) { | |
| 79 DCHECK(event.has_pressed()); | |
| 80 DCHECK(event.has_usb_keycode()); | |
| 81 | |
| 82 // TODO(kelvinp): Disable AutoRepeat as long as keys are pressed on ChromeOS | |
| 83 // when the auto-repeat API is ready to avoid triggering the auto-repeat if | |
| 84 // network congestion delays the key-up event from the client | |
| 85 // (See crbug.com/425201). | |
| 86 | |
| 87 ui::DomCode dom_code = | |
| 88 ui::KeycodeConverter::UsbKeycodeToDomCode(event.usb_keycode()); | |
| 89 | |
| 90 // Ignore events which can't be mapped. | |
| 91 if (dom_code != ui::DomCode::NONE) { | |
| 92 delegate_->InjectKeyPress(dom_code, event.pressed()); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 void InputInjectorChromeos::Core::InjectTextEvent(const TextEvent& event) { | |
| 97 // Chrome OS only supports It2me, which is not supported on mobile clients, so | |
|
Wez
2014/12/06 01:55:17
nit: It2Me or IT2Me
kelvinp
2014/12/08 18:41:44
Done.
| |
| 98 // we don't need to implement text events. | |
| 99 NOTIMPLEMENTED(); | |
| 100 } | |
| 101 | |
| 102 void InputInjectorChromeos::Core::InjectMouseEvent(const MouseEvent& event) { | |
| 103 if (event.has_button() && event.has_button_down()) { | |
| 104 delegate_->InjectMouseButton(MouseButtonToUIFlags(event.button()), | |
| 105 event.button_down()); | |
| 106 } else if (event.has_wheel_delta_y() || event.has_wheel_delta_x()) { | |
| 107 delegate_->InjectMouseWheel(event.wheel_delta_x(), event.wheel_delta_y()); | |
| 108 } else { | |
| 109 DCHECK(event.has_x() && event.has_y()); | |
| 110 delegate_->MoveCursorTo( | |
| 111 input_rotator_->ToScreenPixel(gfx::PointF(event.x(), event.y()))); | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 void InputInjectorChromeos::Core::Start( | |
| 116 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | |
| 117 clipboard_->Start(client_clipboard.Pass()); | |
| 118 input_rotator_.reset(new PixelRotator()); | |
| 119 } | |
| 120 | |
| 18 InputInjectorChromeos::InputInjectorChromeos( | 121 InputInjectorChromeos::InputInjectorChromeos( |
| 19 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 122 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 20 : input_task_runner_(task_runner) { | 123 : input_task_runner_(task_runner) { |
| 21 NOTIMPLEMENTED(); | 124 ui::OzonePlatform* ozone_platform = ui::OzonePlatform::GetInstance(); |
| 125 core_.reset(new Core(ozone_platform->CreateSystemInputInjector())); | |
| 22 } | 126 } |
| 23 | 127 |
| 24 InputInjectorChromeos::~InputInjectorChromeos() { | 128 InputInjectorChromeos::~InputInjectorChromeos() { |
| 25 NOTIMPLEMENTED(); | 129 input_task_runner_->DeleteSoon(FROM_HERE, core_.release()); |
| 26 } | 130 } |
| 27 | 131 |
| 28 void InputInjectorChromeos::InjectClipboardEvent(const ClipboardEvent& event) { | 132 void InputInjectorChromeos::InjectClipboardEvent(const ClipboardEvent& event) { |
| 29 NOTIMPLEMENTED(); | 133 input_task_runner_->PostTask( |
| 134 FROM_HERE, base::Bind(&Core::InjectClipboardEvent, | |
| 135 base::Unretained(core_.get()), event)); | |
| 30 } | 136 } |
| 31 | 137 |
| 32 void InputInjectorChromeos::InjectKeyEvent(const KeyEvent& event) { | 138 void InputInjectorChromeos::InjectKeyEvent(const KeyEvent& event) { |
| 33 NOTIMPLEMENTED(); | 139 input_task_runner_->PostTask( |
| 140 FROM_HERE, | |
| 141 base::Bind(&Core::InjectKeyEvent, base::Unretained(core_.get()), event)); | |
| 34 } | 142 } |
| 35 | 143 |
| 36 void InputInjectorChromeos::InjectTextEvent(const TextEvent& event) { | 144 void InputInjectorChromeos::InjectTextEvent(const TextEvent& event) { |
| 37 NOTIMPLEMENTED(); | 145 input_task_runner_->PostTask( |
| 146 FROM_HERE, | |
| 147 base::Bind(&Core::InjectTextEvent, base::Unretained(core_.get()), event)); | |
| 38 } | 148 } |
| 39 | 149 |
| 40 void InputInjectorChromeos::InjectMouseEvent(const MouseEvent& event) { | 150 void InputInjectorChromeos::InjectMouseEvent(const MouseEvent& event) { |
| 41 NOTIMPLEMENTED(); | 151 input_task_runner_->PostTask( |
| 152 FROM_HERE, base::Bind(&Core::InjectMouseEvent, | |
| 153 base::Unretained(core_.get()), event)); | |
| 42 } | 154 } |
| 43 | 155 |
| 44 void InputInjectorChromeos::Start( | 156 void InputInjectorChromeos::Start( |
| 45 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 157 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
| 46 NOTIMPLEMENTED(); | 158 input_task_runner_->PostTask( |
| 159 FROM_HERE, base::Bind(&Core::Start, base::Unretained(core_.get()), | |
| 160 base::Passed(&client_clipboard))); | |
| 47 } | 161 } |
| 48 | 162 |
| 49 // static | 163 // static |
| 50 scoped_ptr<InputInjector> InputInjector::Create( | 164 scoped_ptr<InputInjector> InputInjector::Create( |
| 51 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 165 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 52 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 166 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 53 scoped_ptr<InputInjectorChromeos> injector(new InputInjectorChromeos( | 167 // The Ozone input injector must be called on the UI task runner of the |
| 54 ui_task_runner)); | 168 // browser process. |
| 55 return injector.Pass(); | 169 return make_scoped_ptr(new InputInjectorChromeos(ui_task_runner)); |
| 56 } | 170 } |
| 57 | 171 |
| 58 } // namespace remoting | 172 } // namespace remoting |
| OLD | NEW |