summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/input/synthetic_pointer_action.cc
blob: 2577e3f5497fed988c2804978f6d7073954514ab (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
// 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 "content/browser/renderer_host/input/synthetic_pointer_action.h"

#include "base/logging.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/events/latency_info.h"

namespace content {

SyntheticPointerAction::SyntheticPointerAction(
    SyntheticGestureParams::GestureSourceType gesture_source_type,
    PointerActionType pointer_action_type,
    SyntheticPointer* synthetic_pointer,
    gfx::PointF position,
    int index)
    : gesture_source_type_(gesture_source_type),
      pointer_action_type_(pointer_action_type),
      position_(position),
      index_(index),
      synthetic_pointer_(synthetic_pointer) {}

SyntheticPointerAction::~SyntheticPointerAction() {}

SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents(
    const base::TimeTicks& timestamp,
    SyntheticGestureTarget* target) {
  if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT)
    gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType();

  DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT);

  ForwardTouchOrMouseInputEvents(timestamp, target);
  return SyntheticGesture::GESTURE_FINISHED;
}

void SyntheticPointerAction::ForwardTouchOrMouseInputEvents(
    const base::TimeTicks& timestamp,
    SyntheticGestureTarget* target) {
  switch (pointer_action_type_) {
    case SyntheticGesture::PRESS:
      synthetic_pointer_->Press(position_.x(), position_.y(), target,
                                timestamp);
      break;
    case SyntheticGesture::MOVE:
      synthetic_pointer_->Move(index_, position_.x(), position_.y(), target,
                               timestamp);
      break;
    case SyntheticGesture::RELEASE:
      synthetic_pointer_->Release(index_, target, timestamp);
      break;
  }
  synthetic_pointer_->DispatchEvent(target, timestamp);
}

}  // namespace content