Update V8 to version 4.7.16.
[chromium-blink-merge.git] / ui / events / ozone / evdev / input_injector_evdev.cc
blobd180e615406f9390ae0d3632e830fc8f7fba01b1
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
3 // found in the LICENSE file.
5 #include "ui/events/event.h"
6 #include "ui/events/event_utils.h"
7 #include "ui/events/keycodes/dom/dom_code.h"
8 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
9 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
10 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
11 #include "ui/events/ozone/evdev/input_injector_evdev.h"
12 #include "ui/events/ozone/evdev/keyboard_evdev.h"
13 #include "ui/events/ozone/evdev/keyboard_util_evdev.h"
15 namespace ui {
17 namespace {
19 const int kDeviceIdForInjection = -1;
21 } // namespace
23 InputInjectorEvdev::InputInjectorEvdev(
24 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher,
25 CursorDelegateEvdev* cursor)
26 : cursor_(cursor), dispatcher_(dispatcher.Pass()) {
29 InputInjectorEvdev::~InputInjectorEvdev() {
32 void InputInjectorEvdev::InjectMouseButton(EventFlags button, bool down) {
33 unsigned int code;
34 switch (button) {
35 case EF_LEFT_MOUSE_BUTTON:
36 code = BTN_LEFT;
37 break;
38 case EF_RIGHT_MOUSE_BUTTON:
39 code = BTN_RIGHT;
40 break;
41 case EF_MIDDLE_MOUSE_BUTTON:
42 code = BTN_MIDDLE;
43 default:
44 LOG(WARNING) << "Invalid flag: " << button << " for the button parameter";
45 return;
48 dispatcher_->DispatchMouseButtonEvent(MouseButtonEventParams(
49 kDeviceIdForInjection, cursor_->GetLocation(), code, down,
50 false /* allow_remap */,
51 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), EventTimeForNow()));
54 void InputInjectorEvdev::InjectMouseWheel(int delta_x, int delta_y) {
55 dispatcher_->DispatchMouseWheelEvent(MouseWheelEventParams(
56 kDeviceIdForInjection, cursor_->GetLocation(),
57 gfx::Vector2d(delta_x, delta_y), EventTimeForNow()));
60 void InputInjectorEvdev::MoveCursorTo(const gfx::PointF& location) {
61 if (!cursor_)
62 return;
64 cursor_->MoveCursorTo(location);
66 dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams(
67 kDeviceIdForInjection, cursor_->GetLocation(),
68 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), EventTimeForNow()));
71 void InputInjectorEvdev::InjectKeyEvent(DomCode physical_key,
72 bool down,
73 bool suppress_auto_repeat) {
74 if (physical_key == DomCode::NONE)
75 return;
77 int native_keycode = KeycodeConverter::DomCodeToNativeKeycode(physical_key);
78 int evdev_code = NativeCodeToEvdevCode(native_keycode);
80 dispatcher_->DispatchKeyEvent(
81 KeyEventParams(kDeviceIdForInjection, evdev_code, down,
82 suppress_auto_repeat, EventTimeForNow()));
85 } // namespace ui