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
  234
  235
  236

content / common / input / synthetic_pointer_action_params.h [blame]

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_
#define CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_

#include "base/check_op.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "content/common/input/synthetic_gesture_params.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/blink/public/common/input/web_touch_event.h"
#include "ui/gfx/geometry/point_f.h"

namespace content {

namespace mojom {
class SyntheticPointerActionParamsDataView;
}  // namespace mojom

// It contains all the parameters to create the synthetic events of touch,
// mouse and pen inputs in SyntheticPointerAction::ForwardInputEvents function.
struct CONTENT_EXPORT SyntheticPointerActionParams {
 public:
  // All the pointer actions that will be dispatched together will be grouped
  // in an array.
  enum class PointerActionType {
    NOT_INITIALIZED,
    PRESS,
    MOVE,
    RELEASE,
    CANCEL,
    LEAVE,
    IDLE,
    POINTER_ACTION_TYPE_MAX = IDLE
  };

  enum class Button {
    NO_BUTTON,
    LEFT,
    MIDDLE,
    RIGHT,
    BACK,
    FORWARD,
    BUTTON_MAX = FORWARD
  };

  SyntheticPointerActionParams();
  explicit SyntheticPointerActionParams(PointerActionType action_type);
  SyntheticPointerActionParams(const SyntheticPointerActionParams& other);
  ~SyntheticPointerActionParams();

  void set_pointer_action_type(PointerActionType pointer_action_type) {
    pointer_action_type_ = pointer_action_type;
  }

  void set_pointer_id(uint32_t pointer_id) { pointer_id_ = pointer_id; }

  void set_position(const gfx::PointF& position) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    position_ = position;
  }

  void set_button(Button button) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE ||
           pointer_action_type_ == PointerActionType::RELEASE ||
           pointer_action_type_ == PointerActionType::CANCEL);
    button_ = button;
  }

  void set_key_modifiers(int key_modifiers) {
    DCHECK_NE(PointerActionType::IDLE, pointer_action_type_);
    key_modifiers_ = key_modifiers;
  }

  void set_width(float width) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    width_ = width;
  }

  void set_height(float height) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    height_ = height;
  }

  void set_rotation_angle(float rotation_angle) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    rotation_angle_ = rotation_angle;
  }

  void set_force(float force) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    force_ = force;
  }

  void set_tangential_pressure(float tangential_pressure) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    tangential_pressure_ = tangential_pressure;
  }

  void set_tilt_x(int tilt_x) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    tilt_x_ = tilt_x;
  }

  void set_tilt_y(int tilt_y) {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    tilt_y_ = tilt_y;
  }

  void set_timestamp(base::TimeTicks timestamp) { timestamp_ = timestamp; }

  void set_duration(base::TimeDelta duration) {
    DCHECK_EQ(PointerActionType::IDLE, pointer_action_type_);
    duration_ = duration;
  }

  PointerActionType pointer_action_type() const { return pointer_action_type_; }

  uint32_t pointer_id() const { return pointer_id_; }

  gfx::PointF position() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    return position_;
  }

  Button button() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE ||
           pointer_action_type_ == PointerActionType::RELEASE ||
           pointer_action_type_ == PointerActionType::CANCEL);
    return button_;
  }

  int key_modifiers() const {
    DCHECK_NE(PointerActionType::IDLE, pointer_action_type_);
    return key_modifiers_;
  }

  float width() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    return width_;
  }

  float height() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    return height_;
  }

  float rotation_angle() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    return rotation_angle_;
  }

  float force() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    return force_;
  }

  float tangential_pressure() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    return tangential_pressure_;
  }

  int tilt_x() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    return tilt_x_;
  }

  int tilt_y() const {
    DCHECK(pointer_action_type_ == PointerActionType::PRESS ||
           pointer_action_type_ == PointerActionType::MOVE);
    return tilt_y_;
  }

  base::TimeTicks timestamp() const { return timestamp_; }

  base::TimeDelta duration() const {
    DCHECK_EQ(PointerActionType::IDLE, pointer_action_type_);
    return duration_;
  }

  static unsigned GetWebMouseEventModifier(
      SyntheticPointerActionParams::Button button);
  static blink::WebMouseEvent::Button GetWebMouseEventButton(
      SyntheticPointerActionParams::Button button);
  static blink::WebMouseEvent::Button GetWebMouseEventButtonFromModifier(
      unsigned modifiers);

 private:
  friend struct mojo::StructTraits<
      content::mojom::SyntheticPointerActionParamsDataView,
      content::SyntheticPointerActionParams>;

  PointerActionType pointer_action_type_ = PointerActionType::NOT_INITIALIZED;
  // The position of the pointer, where it presses or moves to.
  gfx::PointF position_;
  // The id of the pointer given by the users.
  uint32_t pointer_id_ = 0;
  Button button_ = Button::LEFT;
  // “Alt“, ”Control“, ”Meta“, ”Shift“, ”CapsLock“, ”NumLock“, ”AltGraph”
  // buttons are supported right now. It stores a matching modifiers defined
  // in WebInputEvent class.
  int key_modifiers_ = 0;
  float width_ = 40.f;
  float height_ = 40.f;
  float rotation_angle_ = 0.f;
  float force_ = 1.f;
  float tangential_pressure_ = 0.f;
  int tilt_x_ = 0;
  int tilt_y_ = 0;
  base::TimeTicks timestamp_;
  // The duration of the pause action is in milliseconds.
  base::TimeDelta duration_;
};

}  // namespace content

#endif  // CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_