| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "remoting/host/input_injector.h" |
| 6 | 6 |
| 7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
| 8 #include <X11/extensions/XTest.h> | 8 #include <X11/extensions/XTest.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Pixel-to-wheel-ticks conversion ratio used by GTK. | 86 // Pixel-to-wheel-ticks conversion ratio used by GTK. |
| 87 // From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp . | 87 // From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp . |
| 88 const float kWheelTicksPerPixel = 3.0f / 160.0f; | 88 const float kWheelTicksPerPixel = 3.0f / 160.0f; |
| 89 | 89 |
| 90 // A class to generate events on X11. | 90 // A class to generate events on Linux. |
| 91 class InputInjectorX11 : public InputInjector { | 91 class InputInjectorLinux : public InputInjector { |
| 92 public: | 92 public: |
| 93 explicit InputInjectorX11( | 93 explicit InputInjectorLinux( |
| 94 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 94 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 95 ~InputInjectorX11() override; | 95 ~InputInjectorLinux() override; |
| 96 | 96 |
| 97 bool Init(); | 97 bool Init(); |
| 98 | 98 |
| 99 // Clipboard stub interface. | 99 // Clipboard stub interface. |
| 100 void InjectClipboardEvent(const ClipboardEvent& event) override; | 100 void InjectClipboardEvent(const ClipboardEvent& event) override; |
| 101 | 101 |
| 102 // InputStub interface. | 102 // InputStub interface. |
| 103 void InjectKeyEvent(const KeyEvent& event) override; | 103 void InjectKeyEvent(const KeyEvent& event) override; |
| 104 void InjectTextEvent(const TextEvent& event) override; | 104 void InjectTextEvent(const TextEvent& event) override; |
| 105 void InjectMouseEvent(const MouseEvent& event) override; | 105 void InjectMouseEvent(const MouseEvent& event) override; |
| 106 | 106 |
| 107 // InputInjector interface. | 107 // InputInjector interface. |
| 108 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard) override; | 108 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard) override; |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 // The actual implementation resides in InputInjectorX11::Core class. | 111 // The actual implementation resides in InputInjectorLinux::Core class. |
| 112 class Core : public base::RefCountedThreadSafe<Core> { | 112 class Core : public base::RefCountedThreadSafe<Core> { |
| 113 public: | 113 public: |
| 114 explicit Core(scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 114 explicit Core(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 115 | 115 |
| 116 bool Init(); | 116 bool Init(); |
| 117 | 117 |
| 118 // Mirrors the ClipboardStub interface. | 118 // Mirrors the ClipboardStub interface. |
| 119 void InjectClipboardEvent(const ClipboardEvent& event); | 119 void InjectClipboardEvent(const ClipboardEvent& event); |
| 120 | 120 |
| 121 // Mirrors the InputStub interface. | 121 // Mirrors the InputStub interface. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 scoped_ptr<Clipboard> clipboard_; | 174 scoped_ptr<Clipboard> clipboard_; |
| 175 | 175 |
| 176 bool saved_auto_repeat_enabled_; | 176 bool saved_auto_repeat_enabled_; |
| 177 | 177 |
| 178 DISALLOW_COPY_AND_ASSIGN(Core); | 178 DISALLOW_COPY_AND_ASSIGN(Core); |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 scoped_refptr<Core> core_; | 181 scoped_refptr<Core> core_; |
| 182 | 182 |
| 183 DISALLOW_COPY_AND_ASSIGN(InputInjectorX11); | 183 DISALLOW_COPY_AND_ASSIGN(InputInjectorLinux); |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 InputInjectorX11::InputInjectorX11( | 186 InputInjectorLinux::InputInjectorLinux( |
| 187 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 187 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 188 core_ = new Core(task_runner); | 188 core_ = new Core(task_runner); |
| 189 } | 189 } |
| 190 | 190 |
| 191 InputInjectorX11::~InputInjectorX11() { | 191 InputInjectorLinux::~InputInjectorLinux() { |
| 192 core_->Stop(); | 192 core_->Stop(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 bool InputInjectorX11::Init() { | 195 bool InputInjectorLinux::Init() { |
| 196 return core_->Init(); | 196 return core_->Init(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void InputInjectorX11::InjectClipboardEvent(const ClipboardEvent& event) { | 199 void InputInjectorLinux::InjectClipboardEvent(const ClipboardEvent& event) { |
| 200 core_->InjectClipboardEvent(event); | 200 core_->InjectClipboardEvent(event); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void InputInjectorX11::InjectKeyEvent(const KeyEvent& event) { | 203 void InputInjectorLinux::InjectKeyEvent(const KeyEvent& event) { |
| 204 core_->InjectKeyEvent(event); | 204 core_->InjectKeyEvent(event); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void InputInjectorX11::InjectTextEvent(const TextEvent& event) { | 207 void InputInjectorLinux::InjectTextEvent(const TextEvent& event) { |
| 208 core_->InjectTextEvent(event); | 208 core_->InjectTextEvent(event); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void InputInjectorX11::InjectMouseEvent(const MouseEvent& event) { | 211 void InputInjectorLinux::InjectMouseEvent(const MouseEvent& event) { |
| 212 core_->InjectMouseEvent(event); | 212 core_->InjectMouseEvent(event); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void InputInjectorX11::Start( | 215 void InputInjectorLinux::Start( |
| 216 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 216 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
| 217 core_->Start(client_clipboard.Pass()); | 217 core_->Start(client_clipboard.Pass()); |
| 218 } | 218 } |
| 219 | 219 |
| 220 InputInjectorX11::Core::Core( | 220 InputInjectorLinux::Core::Core( |
| 221 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 221 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 222 : task_runner_(task_runner), | 222 : task_runner_(task_runner), |
| 223 latest_mouse_position_(-1, -1), | 223 latest_mouse_position_(-1, -1), |
| 224 wheel_ticks_x_(0.0f), | 224 wheel_ticks_x_(0.0f), |
| 225 wheel_ticks_y_(0.0f), | 225 wheel_ticks_y_(0.0f), |
| 226 display_(XOpenDisplay(NULL)), | 226 display_(XOpenDisplay(NULL)), |
| 227 root_window_(BadValue), | 227 root_window_(BadValue), |
| 228 saved_auto_repeat_enabled_(false) { | 228 saved_auto_repeat_enabled_(false) { |
| 229 } | 229 } |
| 230 | 230 |
| 231 bool InputInjectorX11::Core::Init() { | 231 bool InputInjectorLinux::Core::Init() { |
| 232 CHECK(display_); | 232 CHECK(display_); |
| 233 | 233 |
| 234 if (!task_runner_->BelongsToCurrentThread()) | 234 if (!task_runner_->BelongsToCurrentThread()) |
| 235 task_runner_->PostTask(FROM_HERE, base::Bind(&Core::InitClipboard, this)); | 235 task_runner_->PostTask(FROM_HERE, base::Bind(&Core::InitClipboard, this)); |
| 236 | 236 |
| 237 root_window_ = RootWindow(display_, DefaultScreen(display_)); | 237 root_window_ = RootWindow(display_, DefaultScreen(display_)); |
| 238 if (root_window_ == BadValue) { | 238 if (root_window_ == BadValue) { |
| 239 LOG(ERROR) << "Unable to get the root window"; | 239 LOG(ERROR) << "Unable to get the root window"; |
| 240 return false; | 240 return false; |
| 241 } | 241 } |
| 242 | 242 |
| 243 // TODO(ajwong): Do we want to check the major/minor version at all for XTest? | 243 // TODO(ajwong): Do we want to check the major/minor version at all for XTest? |
| 244 int major = 0; | 244 int major = 0; |
| 245 int minor = 0; | 245 int minor = 0; |
| 246 if (!XTestQueryExtension(display_, &test_event_base_, &test_error_base_, | 246 if (!XTestQueryExtension(display_, &test_event_base_, &test_error_base_, |
| 247 &major, &minor)) { | 247 &major, &minor)) { |
| 248 LOG(ERROR) << "Server does not support XTest."; | 248 LOG(ERROR) << "Server does not support XTest."; |
| 249 return false; | 249 return false; |
| 250 } | 250 } |
| 251 InitMouseButtonMap(); | 251 InitMouseButtonMap(); |
| 252 return true; | 252 return true; |
| 253 } | 253 } |
| 254 | 254 |
| 255 void InputInjectorX11::Core::InjectClipboardEvent( | 255 void InputInjectorLinux::Core::InjectClipboardEvent( |
| 256 const ClipboardEvent& event) { | 256 const ClipboardEvent& event) { |
| 257 if (!task_runner_->BelongsToCurrentThread()) { | 257 if (!task_runner_->BelongsToCurrentThread()) { |
| 258 task_runner_->PostTask( | 258 task_runner_->PostTask( |
| 259 FROM_HERE, base::Bind(&Core::InjectClipboardEvent, this, event)); | 259 FROM_HERE, base::Bind(&Core::InjectClipboardEvent, this, event)); |
| 260 return; | 260 return; |
| 261 } | 261 } |
| 262 | 262 |
| 263 // |clipboard_| will ignore unknown MIME-types, and verify the data's format. | 263 // |clipboard_| will ignore unknown MIME-types, and verify the data's format. |
| 264 clipboard_->InjectClipboardEvent(event); | 264 clipboard_->InjectClipboardEvent(event); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void InputInjectorX11::Core::InjectKeyEvent(const KeyEvent& event) { | 267 void InputInjectorLinux::Core::InjectKeyEvent(const KeyEvent& event) { |
| 268 // HostEventDispatcher should filter events missing the pressed field. | 268 // HostEventDispatcher should filter events missing the pressed field. |
| 269 if (!event.has_pressed() || !event.has_usb_keycode()) | 269 if (!event.has_pressed() || !event.has_usb_keycode()) |
| 270 return; | 270 return; |
| 271 | 271 |
| 272 if (!task_runner_->BelongsToCurrentThread()) { | 272 if (!task_runner_->BelongsToCurrentThread()) { |
| 273 task_runner_->PostTask(FROM_HERE, | 273 task_runner_->PostTask(FROM_HERE, |
| 274 base::Bind(&Core::InjectKeyEvent, this, event)); | 274 base::Bind(&Core::InjectKeyEvent, this, event)); |
| 275 return; | 275 return; |
| 276 } | 276 } |
| 277 | 277 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 306 // Re-enable auto-repeat, if necessary, when all keys are released. | 306 // Re-enable auto-repeat, if necessary, when all keys are released. |
| 307 if (saved_auto_repeat_enabled_) | 307 if (saved_auto_repeat_enabled_) |
| 308 SetAutoRepeatEnabled(true); | 308 SetAutoRepeatEnabled(true); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 XTestFakeKeyEvent(display_, keycode, event.pressed(), CurrentTime); | 312 XTestFakeKeyEvent(display_, keycode, event.pressed(), CurrentTime); |
| 313 XFlush(display_); | 313 XFlush(display_); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void InputInjectorX11::Core::InjectTextEvent(const TextEvent& event) { | 316 void InputInjectorLinux::Core::InjectTextEvent(const TextEvent& event) { |
| 317 if (!task_runner_->BelongsToCurrentThread()) { | 317 if (!task_runner_->BelongsToCurrentThread()) { |
| 318 task_runner_->PostTask(FROM_HERE, | 318 task_runner_->PostTask(FROM_HERE, |
| 319 base::Bind(&Core::InjectTextEvent, this, event)); | 319 base::Bind(&Core::InjectTextEvent, this, event)); |
| 320 return; | 320 return; |
| 321 } | 321 } |
| 322 | 322 |
| 323 const std::string text = event.text(); | 323 const std::string text = event.text(); |
| 324 for (int32 index = 0; index < static_cast<int32>(text.size()); ++index) { | 324 for (int32 index = 0; index < static_cast<int32>(text.size()); ++index) { |
| 325 uint32_t code_point; | 325 uint32_t code_point; |
| 326 if (!base::ReadUnicodeCharacter( | 326 if (!base::ReadUnicodeCharacter( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 337 | 337 |
| 338 XTestFakeKeyEvent(display_, keycode, True, CurrentTime); | 338 XTestFakeKeyEvent(display_, keycode, True, CurrentTime); |
| 339 XTestFakeKeyEvent(display_, keycode, False, CurrentTime); | 339 XTestFakeKeyEvent(display_, keycode, False, CurrentTime); |
| 340 | 340 |
| 341 XkbLockModifiers(display_, XkbUseCoreKbd, modifiers, 0); | 341 XkbLockModifiers(display_, XkbUseCoreKbd, modifiers, 0); |
| 342 } | 342 } |
| 343 | 343 |
| 344 XFlush(display_); | 344 XFlush(display_); |
| 345 } | 345 } |
| 346 | 346 |
| 347 InputInjectorX11::Core::~Core() { | 347 InputInjectorLinux::Core::~Core() { |
| 348 CHECK(pressed_keys_.empty()); | 348 CHECK(pressed_keys_.empty()); |
| 349 } | 349 } |
| 350 | 350 |
| 351 void InputInjectorX11::Core::InitClipboard() { | 351 void InputInjectorLinux::Core::InitClipboard() { |
| 352 DCHECK(task_runner_->BelongsToCurrentThread()); | 352 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 353 clipboard_ = Clipboard::Create(); | 353 clipboard_ = Clipboard::Create(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 bool InputInjectorX11::Core::IsAutoRepeatEnabled() { | 356 bool InputInjectorLinux::Core::IsAutoRepeatEnabled() { |
| 357 XKeyboardState state; | 357 XKeyboardState state; |
| 358 if (!XGetKeyboardControl(display_, &state)) { | 358 if (!XGetKeyboardControl(display_, &state)) { |
| 359 LOG(ERROR) << "Failed to get keyboard auto-repeat status, assuming ON."; | 359 LOG(ERROR) << "Failed to get keyboard auto-repeat status, assuming ON."; |
| 360 return true; | 360 return true; |
| 361 } | 361 } |
| 362 return state.global_auto_repeat == AutoRepeatModeOn; | 362 return state.global_auto_repeat == AutoRepeatModeOn; |
| 363 } | 363 } |
| 364 | 364 |
| 365 void InputInjectorX11::Core::SetAutoRepeatEnabled(bool mode) { | 365 void InputInjectorLinux::Core::SetAutoRepeatEnabled(bool mode) { |
| 366 XKeyboardControl control; | 366 XKeyboardControl control; |
| 367 control.auto_repeat_mode = mode ? AutoRepeatModeOn : AutoRepeatModeOff; | 367 control.auto_repeat_mode = mode ? AutoRepeatModeOn : AutoRepeatModeOff; |
| 368 XChangeKeyboardControl(display_, KBAutoRepeatMode, &control); | 368 XChangeKeyboardControl(display_, KBAutoRepeatMode, &control); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void InputInjectorX11::Core::InjectScrollWheelClicks(int button, int count) { | 371 void InputInjectorLinux::Core::InjectScrollWheelClicks(int button, int count) { |
| 372 if (button < 0) { | 372 if (button < 0) { |
| 373 LOG(WARNING) << "Ignoring unmapped scroll wheel button"; | 373 LOG(WARNING) << "Ignoring unmapped scroll wheel button"; |
| 374 return; | 374 return; |
| 375 } | 375 } |
| 376 for (int i = 0; i < count; i++) { | 376 for (int i = 0; i < count; i++) { |
| 377 // Generate a button-down and a button-up to simulate a wheel click. | 377 // Generate a button-down and a button-up to simulate a wheel click. |
| 378 XTestFakeButtonEvent(display_, button, true, CurrentTime); | 378 XTestFakeButtonEvent(display_, button, true, CurrentTime); |
| 379 XTestFakeButtonEvent(display_, button, false, CurrentTime); | 379 XTestFakeButtonEvent(display_, button, false, CurrentTime); |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 | 382 |
| 383 void InputInjectorX11::Core::InjectMouseEvent(const MouseEvent& event) { | 383 void InputInjectorLinux::Core::InjectMouseEvent(const MouseEvent& event) { |
| 384 if (!task_runner_->BelongsToCurrentThread()) { | 384 if (!task_runner_->BelongsToCurrentThread()) { |
| 385 task_runner_->PostTask(FROM_HERE, | 385 task_runner_->PostTask(FROM_HERE, |
| 386 base::Bind(&Core::InjectMouseEvent, this, event)); | 386 base::Bind(&Core::InjectMouseEvent, this, event)); |
| 387 return; | 387 return; |
| 388 } | 388 } |
| 389 | 389 |
| 390 if (event.has_delta_x() && | 390 if (event.has_delta_x() && |
| 391 event.has_delta_y() && | 391 event.has_delta_y() && |
| 392 (event.delta_x() != 0 || event.delta_y() != 0)) { | 392 (event.delta_x() != 0 || event.delta_y() != 0)) { |
| 393 latest_mouse_position_.set(-1, -1); | 393 latest_mouse_position_.set(-1, -1); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 wheel_ticks_x_ -= ticks_x; | 464 wheel_ticks_x_ -= ticks_x; |
| 465 } | 465 } |
| 466 if (ticks_x != 0) { | 466 if (ticks_x != 0) { |
| 467 InjectScrollWheelClicks(HorizontalScrollWheelToX11ButtonNumber(ticks_x), | 467 InjectScrollWheelClicks(HorizontalScrollWheelToX11ButtonNumber(ticks_x), |
| 468 abs(ticks_x)); | 468 abs(ticks_x)); |
| 469 } | 469 } |
| 470 | 470 |
| 471 XFlush(display_); | 471 XFlush(display_); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void InputInjectorX11::Core::InitMouseButtonMap() { | 474 void InputInjectorLinux::Core::InitMouseButtonMap() { |
| 475 // TODO(rmsousa): Run this on global/device mapping change events. | 475 // TODO(rmsousa): Run this on global/device mapping change events. |
| 476 | 476 |
| 477 // Do not touch global pointer mapping, since this may affect the local user. | 477 // Do not touch global pointer mapping, since this may affect the local user. |
| 478 // Instead, try to work around it by reversing the mapping. | 478 // Instead, try to work around it by reversing the mapping. |
| 479 // Note that if a user has a global mapping that completely disables a button | 479 // Note that if a user has a global mapping that completely disables a button |
| 480 // (by assigning 0 to it), we won't be able to inject it. | 480 // (by assigning 0 to it), we won't be able to inject it. |
| 481 int num_buttons = XGetPointerMapping(display_, NULL, 0); | 481 int num_buttons = XGetPointerMapping(display_, NULL, 0); |
| 482 scoped_ptr<unsigned char[]> pointer_mapping(new unsigned char[num_buttons]); | 482 scoped_ptr<unsigned char[]> pointer_mapping(new unsigned char[num_buttons]); |
| 483 num_buttons = XGetPointerMapping(display_, pointer_mapping.get(), | 483 num_buttons = XGetPointerMapping(display_, pointer_mapping.get(), |
| 484 num_buttons); | 484 num_buttons); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 button_mapping[i] = i + 1; | 540 button_mapping[i] = i + 1; |
| 541 } | 541 } |
| 542 error = XSetDeviceButtonMapping(display_, device, button_mapping.get(), | 542 error = XSetDeviceButtonMapping(display_, device, button_mapping.get(), |
| 543 num_device_buttons); | 543 num_device_buttons); |
| 544 if (error != Success) | 544 if (error != Success) |
| 545 LOG(ERROR) << "Failed to set XTest device button mapping: " << error; | 545 LOG(ERROR) << "Failed to set XTest device button mapping: " << error; |
| 546 | 546 |
| 547 XCloseDevice(display_, device); | 547 XCloseDevice(display_, device); |
| 548 } | 548 } |
| 549 | 549 |
| 550 int InputInjectorX11::Core::MouseButtonToX11ButtonNumber( | 550 int InputInjectorLinux::Core::MouseButtonToX11ButtonNumber( |
| 551 MouseEvent::MouseButton button) { | 551 MouseEvent::MouseButton button) { |
| 552 switch (button) { | 552 switch (button) { |
| 553 case MouseEvent::BUTTON_LEFT: | 553 case MouseEvent::BUTTON_LEFT: |
| 554 return pointer_button_map_[0]; | 554 return pointer_button_map_[0]; |
| 555 | 555 |
| 556 case MouseEvent::BUTTON_RIGHT: | 556 case MouseEvent::BUTTON_RIGHT: |
| 557 return pointer_button_map_[2]; | 557 return pointer_button_map_[2]; |
| 558 | 558 |
| 559 case MouseEvent::BUTTON_MIDDLE: | 559 case MouseEvent::BUTTON_MIDDLE: |
| 560 return pointer_button_map_[1]; | 560 return pointer_button_map_[1]; |
| 561 | 561 |
| 562 case MouseEvent::BUTTON_UNDEFINED: | 562 case MouseEvent::BUTTON_UNDEFINED: |
| 563 default: | 563 default: |
| 564 return -1; | 564 return -1; |
| 565 } | 565 } |
| 566 } | 566 } |
| 567 | 567 |
| 568 int InputInjectorX11::Core::HorizontalScrollWheelToX11ButtonNumber(int dx) { | 568 int InputInjectorLinux::Core::HorizontalScrollWheelToX11ButtonNumber(int dx) { |
| 569 return (dx > 0 ? pointer_button_map_[5] : pointer_button_map_[6]); | 569 return (dx > 0 ? pointer_button_map_[5] : pointer_button_map_[6]); |
| 570 } | 570 } |
| 571 | 571 |
| 572 int InputInjectorX11::Core::VerticalScrollWheelToX11ButtonNumber(int dy) { | 572 int InputInjectorLinux::Core::VerticalScrollWheelToX11ButtonNumber(int dy) { |
| 573 // Positive y-values are wheel scroll-up events (button 4), negative y-values | 573 // Positive y-values are wheel scroll-up events (button 4), negative y-values |
| 574 // are wheel scroll-down events (button 5). | 574 // are wheel scroll-down events (button 5). |
| 575 return (dy > 0 ? pointer_button_map_[3] : pointer_button_map_[4]); | 575 return (dy > 0 ? pointer_button_map_[3] : pointer_button_map_[4]); |
| 576 } | 576 } |
| 577 | 577 |
| 578 void InputInjectorX11::Core::Start( | 578 void InputInjectorLinux::Core::Start( |
| 579 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 579 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
| 580 if (!task_runner_->BelongsToCurrentThread()) { | 580 if (!task_runner_->BelongsToCurrentThread()) { |
| 581 task_runner_->PostTask( | 581 task_runner_->PostTask( |
| 582 FROM_HERE, | 582 FROM_HERE, |
| 583 base::Bind(&Core::Start, this, base::Passed(&client_clipboard))); | 583 base::Bind(&Core::Start, this, base::Passed(&client_clipboard))); |
| 584 return; | 584 return; |
| 585 } | 585 } |
| 586 | 586 |
| 587 InitMouseButtonMap(); | 587 InitMouseButtonMap(); |
| 588 | 588 |
| 589 clipboard_->Start(client_clipboard.Pass()); | 589 clipboard_->Start(client_clipboard.Pass()); |
| 590 } | 590 } |
| 591 | 591 |
| 592 void InputInjectorX11::Core::Stop() { | 592 void InputInjectorLinux::Core::Stop() { |
| 593 if (!task_runner_->BelongsToCurrentThread()) { | 593 if (!task_runner_->BelongsToCurrentThread()) { |
| 594 task_runner_->PostTask(FROM_HERE, base::Bind(&Core::Stop, this)); | 594 task_runner_->PostTask(FROM_HERE, base::Bind(&Core::Stop, this)); |
| 595 return; | 595 return; |
| 596 } | 596 } |
| 597 | 597 |
| 598 clipboard_->Stop(); | 598 clipboard_->Stop(); |
| 599 } | 599 } |
| 600 | 600 |
| 601 } // namespace | 601 } // namespace |
| 602 | 602 |
| 603 scoped_ptr<InputInjector> InputInjector::Create( | 603 scoped_ptr<InputInjector> InputInjector::Create( |
| 604 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 604 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 605 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 605 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 606 scoped_ptr<InputInjectorX11> injector( | 606 scoped_ptr<InputInjectorLinux> injector( |
| 607 new InputInjectorX11(main_task_runner)); | 607 new InputInjectorLinux(main_task_runner)); |
| 608 if (!injector->Init()) | 608 if (!injector->Init()) |
| 609 return nullptr; | 609 return nullptr; |
| 610 return injector.Pass(); | 610 return injector.Pass(); |
| 611 } | 611 } |
| 612 | 612 |
| 613 } // namespace remoting | 613 } // namespace remoting |
| OLD | NEW |