File: web_pointer_event.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (129 lines) | stat: -rw-r--r-- 4,677 bytes parent folder | download | duplicates (6)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/public/common/input/web_pointer_event.h"

#include "base/check_op.h"
#include "base/notreached.h"

namespace blink {

namespace {

WebInputEvent::Type PointerEventTypeForTouchPointState(
    WebTouchPoint::State state) {
  switch (state) {
    case WebTouchPoint::State::kStateReleased:
      return WebInputEvent::Type::kPointerUp;
    case WebTouchPoint::State::kStateCancelled:
      return WebInputEvent::Type::kPointerCancel;
    case WebTouchPoint::State::kStatePressed:
      return WebInputEvent::Type::kPointerDown;
    case WebTouchPoint::State::kStateMoved:
      return WebInputEvent::Type::kPointerMove;
    case WebTouchPoint::State::kStateStationary:
    default:
      NOTREACHED();
  }
}

}  // namespace

WebPointerEvent::WebPointerEvent(const WebTouchEvent& touch_event,
                                 const WebTouchPoint& touch_point)
    : WebInputEvent(PointerEventTypeForTouchPointState(touch_point.state),
                    touch_event.GetModifiers(),
                    touch_event.TimeStamp()),

      WebPointerProperties(touch_point),
      hovering(touch_event.hovering),
      width(touch_point.radius_x * 2.f),
      height(touch_point.radius_y * 2.f) {
  // WebInutEvent attributes
  SetFrameScale(touch_event.FrameScale());
  SetFrameTranslate(touch_event.FrameTranslate());
  // WebTouchEvent attributes
  dispatch_type = touch_event.dispatch_type;
  moved_beyond_slop_region = touch_event.moved_beyond_slop_region;
  touch_start_or_first_touch_move = touch_event.touch_start_or_first_touch_move;
  unique_touch_event_id = touch_event.unique_touch_event_id;
  // WebTouchPoint attributes
  rotation_angle = touch_point.rotation_angle;
  // TODO(crbug.com/816504): Touch point button is not set at this point yet.
  button = (GetType() == WebInputEvent::Type::kPointerDown ||
            GetType() == WebInputEvent::Type::kPointerUp)
               ? WebPointerProperties::Button::kLeft
               : WebPointerProperties::Button::kNoButton;
  if (touch_event.GetPreventCountingAsInteraction()) {
    SetPreventCountingAsInteractionTrue();
  }
}

WebPointerEvent::WebPointerEvent(WebInputEvent::Type type,
                                 const WebMouseEvent& mouse_event)
    : WebInputEvent(type, mouse_event.GetModifiers(), mouse_event.TimeStamp()),
      WebPointerProperties(mouse_event),
      hovering(true),
      width(std::numeric_limits<float>::quiet_NaN()),
      height(std::numeric_limits<float>::quiet_NaN()) {
  DCHECK_GE(type, WebInputEvent::Type::kPointerTypeFirst);
  DCHECK_LE(type, WebInputEvent::Type::kPointerTypeLast);
  SetFrameScale(mouse_event.FrameScale());
  SetFrameTranslate(mouse_event.FrameTranslate());
  if (mouse_event.GetPreventCountingAsInteraction()) {
    SetPreventCountingAsInteractionTrue();
  }
}

std::unique_ptr<WebInputEvent> WebPointerEvent::Clone() const {
  return std::make_unique<WebPointerEvent>(*this);
}

bool WebPointerEvent::CanCoalesce(const WebInputEvent& event) const {
  if (!IsPointerEventType(event.GetType()))
    return false;
  const WebPointerEvent& pointer_event =
      static_cast<const WebPointerEvent&>(event);
  return (GetType() == WebInputEvent::Type::kPointerMove ||
          GetType() == WebInputEvent::Type::kPointerRawUpdate) &&
         GetType() == event.GetType() &&
         GetModifiers() == event.GetModifiers() && id == pointer_event.id &&
         pointer_type == pointer_event.pointer_type;
}

void WebPointerEvent::Coalesce(const WebInputEvent& event) {
  DCHECK(CanCoalesce(event));
  const WebPointerEvent& pointer_event =
      static_cast<const WebPointerEvent&>(event);
  // Accumulate movement deltas.
  int x = movement_x;
  int y = movement_y;
  *this = pointer_event;
  movement_x += x;
  movement_y += y;
}

WebPointerEvent WebPointerEvent::CreatePointerCausesUaActionEvent(
    WebPointerProperties::PointerType type,
    base::TimeTicks time_stamp) {
  WebPointerEvent event;
  event.pointer_type = type;
  event.SetTimeStamp(time_stamp);
  event.SetType(WebInputEvent::Type::kPointerCausedUaAction);
  return event;
}

WebPointerEvent WebPointerEvent::WebPointerEventInRootFrame() const {
  WebPointerEvent transformed_event = *this;
  if (HasWidth())
    transformed_event.width /= frame_scale_;
  if (HasHeight())
    transformed_event.height /= frame_scale_;
  transformed_event.position_in_widget_ =
      gfx::ScalePoint(transformed_event.PositionInWidget(), 1 / frame_scale_) +
      frame_translate_;
  return transformed_event;
}

}  // namespace blink