summaryrefslogtreecommitdiffstats
path: root/ui/events/ozone/evdev/event_converter_test_util.cc
blob: f2e798c35b25e5e74b2f3d9e50e62d091d5a2757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/events/ozone/evdev/event_converter_test_util.h"

#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/platform/platform_event_dispatcher.h"

namespace ui {

namespace {

class TestDeviceManager : public ui::DeviceManager {
 public:
  TestDeviceManager() {}
  ~TestDeviceManager() override {}

  // DeviceManager:
  void ScanDevices(DeviceEventObserver* observer) override {}
  void AddObserver(DeviceEventObserver* observer) override {}
  void RemoveObserver(DeviceEventObserver* observer) override {}
};

class TestDeviceEventDispatcherEvdev : public DeviceEventDispatcherEvdev {
 public:
  TestDeviceEventDispatcherEvdev(EventFactoryEvdev* event_factory_evdev)
      : event_factory_evdev_(event_factory_evdev) {}
  ~TestDeviceEventDispatcherEvdev() override {}

  // DeviceEventDispatcher:
  void DispatchKeyEvent(const KeyEventParams& params) override {
    event_factory_evdev_->DispatchKeyEvent(params);
  }

  void DispatchMouseMoveEvent(const MouseMoveEventParams& params) override {
    event_factory_evdev_->DispatchMouseMoveEvent(params);
  }

  void DispatchMouseButtonEvent(const MouseButtonEventParams& params) override {
    event_factory_evdev_->DispatchMouseButtonEvent(params);
  }

  void DispatchMouseWheelEvent(const MouseWheelEventParams& params) override {
    event_factory_evdev_->DispatchMouseWheelEvent(params);
  }

  void DispatchScrollEvent(const ScrollEventParams& params) override {
    event_factory_evdev_->DispatchScrollEvent(params);
  }

  void DispatchTouchEvent(const TouchEventParams& params) override {
    event_factory_evdev_->DispatchTouchEvent(params);
  }

  void DispatchKeyboardDevicesUpdated(
      const std::vector<KeyboardDevice>& devices) override {
    event_factory_evdev_->DispatchKeyboardDevicesUpdated(devices);
  }
  void DispatchTouchscreenDevicesUpdated(
      const std::vector<TouchscreenDevice>& devices) override {
    event_factory_evdev_->DispatchTouchscreenDevicesUpdated(devices);
  }
  void DispatchMouseDevicesUpdated(
      const std::vector<InputDevice>& devices) override {
    event_factory_evdev_->DispatchMouseDevicesUpdated(devices);
  }
  void DispatchTouchpadDevicesUpdated(
      const std::vector<InputDevice>& devices) override {
    event_factory_evdev_->DispatchTouchpadDevicesUpdated(devices);
  }
  void DispatchDeviceListsComplete() override {
    event_factory_evdev_->DispatchDeviceListsComplete();
  }

 private:
  EventFactoryEvdev* event_factory_evdev_;
};

class TestEventFactoryEvdev : public EventFactoryEvdev {
 public:
  TestEventFactoryEvdev(CursorDelegateEvdev* cursor,
                        DeviceManager* device_manager,
                        KeyboardLayoutEngine* keyboard_layout_engine,
                        const EventDispatchCallback& callback)
      : EventFactoryEvdev(cursor, device_manager, keyboard_layout_engine),
        callback_(callback) {}
  ~TestEventFactoryEvdev() override {}

 private:
  uint32_t DispatchEvent(PlatformEvent platform_event) override {
    Event* event = static_cast<Event*>(platform_event);
    callback_.Run(event);
    return POST_DISPATCH_NONE;
  }

  EventDispatchCallback callback_;
};

}  // namespace

scoped_ptr<DeviceEventDispatcherEvdev> CreateDeviceEventDispatcherEvdevForTest(
    EventFactoryEvdev* event_factory) {
  return make_scoped_ptr(new TestDeviceEventDispatcherEvdev(event_factory));
}

scoped_ptr<DeviceManager> CreateDeviceManagerForTest() {
  return make_scoped_ptr(new TestDeviceManager());
}

scoped_ptr<EventFactoryEvdev> CreateEventFactoryEvdevForTest(
    CursorDelegateEvdev* cursor,
    DeviceManager* device_manager,
    KeyboardLayoutEngine* keyboard_layout_engine,
    const EventDispatchCallback& callback) {
  return make_scoped_ptr(new TestEventFactoryEvdev(
      cursor, device_manager, keyboard_layout_engine, callback));
}

}  // namespace ui