summaryrefslogtreecommitdiff
path: root/chromium/pdf/ppapi_migration/input_event_conversions.h
blob: a8b9065fe323427235e9e69bc2a372dcf3fcf612 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Copyright 2020 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.

#ifndef PDF_PPAPI_MIGRATION_INPUT_EVENT_CONVERSIONS_H_
#define PDF_PPAPI_MIGRATION_INPUT_EVENT_CONVERSIONS_H_

#include <stdint.h>
#include <string>

#include "ppapi/c/dev/pp_cursor_type_dev.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"

namespace pp {
class KeyboardInputEvent;
class MouseInputEvent;
class TouchInputEvent;
}  // namespace pp

namespace chrome_pdf {

enum InputEventModifier : uint32_t {
  // None represents no modifier key specified.
  kInputEventModifierNone = 0,
  kInputEventModifierShiftKey = 1 << 0,
  kInputEventModifierControlKey = 1 << 1,
  kInputEventModifierAltKey = 1 << 2,
  kInputEventModifierMetaKey = 1 << 3,
  kInputEventModifierIsKeyPad = 1 << 4,
  kInputEventModifierIsAutoRepeat = 1 << 5,
  kInputEventModifierLeftButtonDown = 1 << 6,
  kInputEventModifierMiddleButtonDown = 1 << 7,
  kInputEventModifierRightButtonDown = 1 << 8,
  kInputEventModifierCapsLockKey = 1 << 9,
  kInputEventModifierNumLockKey = 1 << 10,
  kInputEventModifierIsLeft = 1 << 11,
  kInputEventModifierIsRight = 1 << 12,
  kInputEventModifierIsPen = 1 << 13,
  kInputEventModifierIsEraser = 1 << 14
};

enum class InputEventType {
  kNone,

  // Notification that a mouse button was pressed.
  kMouseDown,

  // Notification that a mouse button was released.
  kMouseUp,

  // Notification that a mouse button was moved when it is over the instance
  // or dragged out of it.
  kMouseMove,

  // Notification that the mouse entered the pdf view's bounds.
  kMouseEnter,

  // Notification that a mouse left the pdf view's bounds.
  kMouseLeave,

  // Notification that the scroll wheel was used.
  kWheel,

  // Notification that a key transitioned from "up" to "down".
  kRawKeyDown,

  // Notification that a key was pressed. This does not necessarily correspond
  // to a character depending on the key and language. Use the
  // kChar for character input.
  kKeyDown,

  // Notification that a key was released.
  kKeyUp,

  // Notification that a character was typed. Use this for text input. Key
  // down events may generate 0, 1, or more than one character event depending
  // on the key, locale, and operating system.
  kChar,

  kContextMenu,

  // Notification that an input method composition process has just started.
  kImeCompositionStart,

  // Notification that the input method composition string is updated.
  kImeCompositionUpdate,

  // Notification that an input method composition process has completed.
  kImeCompositionEnd,

  // Notification that an input method committed a string.
  kImeText,

  // Notification that a finger was placed on a touch-enabled device.
  kTouchStart,

  // Notification that a finger was moved on a touch-enabled device.
  kTouchMove,

  // Notification that a finger was released on a touch-enabled device.
  kTouchEnd,

  // Notification that a touch event was canceled.
  kTouchCancel
};

enum class InputEventMouseButtonType {
  kNone = 0,
  kLeft,
  kMiddle,
  kRight,
};

class InputEvent {
 public:
  InputEventType GetEventType() const { return event_type_; }

  double GetTimeStamp() const { return time_stamp_; }

  uint32_t GetModifiers() const { return modifiers_; }

 protected:
  // Base class is not intended to be instantiated directly. Use
  // `NoneInputEvent` to get an event of type `InputEventType::kNone`.
  InputEvent(InputEventType event_type, double time_stamp, uint32_t modifiers);
  InputEvent(const InputEvent& other);
  InputEvent& operator=(const InputEvent& other);
  ~InputEvent();

 private:
  InputEventType event_type_;
  // The units are in seconds, but are not measured relative to any particular
  // epoch, so the most you can do is compare two values.
  double time_stamp_;
  uint32_t modifiers_;
};

class KeyboardInputEvent : public InputEvent {
 public:
  KeyboardInputEvent(InputEventType event_type,
                     double time_stamp,
                     uint32_t modifiers,
                     uint32_t keyboard_code,
                     const std::string& key_char);
  KeyboardInputEvent(const KeyboardInputEvent& other);
  KeyboardInputEvent& operator=(const KeyboardInputEvent& other);
  ~KeyboardInputEvent();

  uint32_t GetKeyCode() const { return keyboard_code_; }

  const std::string& GetKeyChar() const { return key_char_; }

 private:
  uint32_t keyboard_code_;
  std::string key_char_;
};

class MouseInputEvent : public InputEvent {
 public:
  MouseInputEvent(InputEventType event_type,
                  double time_stamp,
                  uint32_t modifier,
                  InputEventMouseButtonType mouse_button_type,
                  const gfx::Point& point,
                  int32_t click_count,
                  const gfx::Point& movement);
  MouseInputEvent(const MouseInputEvent& other);
  MouseInputEvent& operator=(const MouseInputEvent& other);
  ~MouseInputEvent();

  const InputEventMouseButtonType& GetButton() const {
    return mouse_button_type_;
  }

  const gfx::Point& GetPosition() const { return point_; }

  int32_t GetClickCount() const { return click_count_; }

  const gfx::Point& GetMovement() const { return movement_; }

 private:
  InputEventMouseButtonType mouse_button_type_;
  gfx::Point point_;
  int32_t click_count_ = 0;
  gfx::Point movement_;
};

class TouchInputEvent : public InputEvent {
 public:
  TouchInputEvent(InputEventType event_type,
                  double time_stamp,
                  uint32_t modifiers,
                  const gfx::PointF& target_touch_point,
                  int32_t touch_count);
  TouchInputEvent(const TouchInputEvent& other);
  TouchInputEvent& operator=(const TouchInputEvent& other);
  ~TouchInputEvent();

  // `pp::TouchInputEvent` exposes a collection of target touch points. We can
  // get all the points by passing the index of the point in the collection.
  // However, with `chrome_pdf::TouchEvent` the number of target touch points
  // are restricted to the first point. This is because PDFiumeEngine at present
  // is dependent on only the first target touch point.
  const gfx::PointF& GetTargetTouchPoint() const { return target_touch_point_; }

  int32_t GetTouchCount() const { return touch_count_; }

 private:
  gfx::PointF target_touch_point_;
  int32_t touch_count_ = 0;
};

class NoneInputEvent : public InputEvent {
 public:
  NoneInputEvent();
  NoneInputEvent(const NoneInputEvent& other);
  NoneInputEvent& operator=(const NoneInputEvent& other);
  ~NoneInputEvent();
};

KeyboardInputEvent GetKeyboardInputEvent(const pp::KeyboardInputEvent& event);

MouseInputEvent GetMouseInputEvent(const pp::MouseInputEvent& event);

TouchInputEvent GetTouchInputEvent(const pp::TouchInputEvent& event);

PP_CursorType_Dev PPCursorTypeFromCursorType(ui::mojom::CursorType cursor_type);

}  // namespace chrome_pdf

#endif  // PDF_PPAPI_MIGRATION_INPUT_EVENT_CONVERSIONS_H_