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
|
// Copyright 2016 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 "public/platform/WebGestureEvent.h"
namespace blink {
float WebGestureEvent::deltaXInRootFrame() const {
if (m_type == WebInputEvent::GestureScrollBegin)
return data.scrollBegin.deltaXHint / m_frameScale;
DCHECK(m_type == WebInputEvent::GestureScrollUpdate);
return data.scrollUpdate.deltaX / m_frameScale;
}
float WebGestureEvent::deltaYInRootFrame() const {
if (m_type == WebInputEvent::GestureScrollBegin)
return data.scrollBegin.deltaYHint / m_frameScale;
DCHECK(m_type == WebInputEvent::GestureScrollUpdate);
return data.scrollUpdate.deltaY / m_frameScale;
}
WebGestureEvent::ScrollUnits WebGestureEvent::deltaUnits() const {
if (m_type == WebInputEvent::GestureScrollBegin)
return data.scrollBegin.deltaHintUnits;
if (m_type == WebInputEvent::GestureScrollUpdate)
return data.scrollUpdate.deltaUnits;
DCHECK(m_type == WebInputEvent::GestureScrollEnd);
return data.scrollEnd.deltaUnits;
}
float WebGestureEvent::pinchScale() const {
DCHECK(m_type == WebInputEvent::GesturePinchUpdate);
return data.pinchUpdate.scale;
}
WebGestureEvent::InertialPhaseState WebGestureEvent::inertialPhase() const {
if (m_type == WebInputEvent::GestureScrollBegin)
return data.scrollBegin.inertialPhase;
if (m_type == WebInputEvent::GestureScrollUpdate)
return data.scrollUpdate.inertialPhase;
DCHECK(m_type == WebInputEvent::GestureScrollEnd);
return data.scrollEnd.inertialPhase;
}
bool WebGestureEvent::synthetic() const {
if (m_type == WebInputEvent::GestureScrollBegin)
return data.scrollBegin.synthetic;
DCHECK(m_type == WebInputEvent::GestureScrollEnd);
return data.scrollEnd.synthetic;
}
float WebGestureEvent::velocityX() const {
if (m_type == WebInputEvent::GestureScrollUpdate)
return data.scrollUpdate.velocityX;
DCHECK(m_type == WebInputEvent::GestureFlingStart);
return data.flingStart.velocityX;
}
float WebGestureEvent::velocityY() const {
if (m_type == WebInputEvent::GestureScrollUpdate)
return data.scrollUpdate.velocityY;
DCHECK(m_type == WebInputEvent::GestureFlingStart);
return data.flingStart.velocityY;
}
WebFloatSize WebGestureEvent::tapAreaInRootFrame() const {
if (m_type == WebInputEvent::GestureTwoFingerTap) {
return WebFloatSize(data.twoFingerTap.firstFingerWidth / m_frameScale,
data.twoFingerTap.firstFingerHeight / m_frameScale);
} else if (m_type == WebInputEvent::GestureLongPress ||
m_type == WebInputEvent::GestureLongTap) {
return WebFloatSize(data.longPress.width / m_frameScale,
data.longPress.height / m_frameScale);
} else if (m_type == WebInputEvent::GestureTap ||
m_type == WebInputEvent::GestureTapUnconfirmed) {
return WebFloatSize(data.tap.width / m_frameScale,
data.tap.height / m_frameScale);
} else if (m_type == WebInputEvent::GestureTapDown) {
return WebFloatSize(data.tapDown.width / m_frameScale,
data.tapDown.height / m_frameScale);
} else if (m_type == WebInputEvent::GestureShowPress) {
return WebFloatSize(data.showPress.width / m_frameScale,
data.showPress.height / m_frameScale);
}
// This function is called for all gestures and determined if the tap
// area is empty or not; so return an empty rect here.
return WebFloatSize();
}
WebFloatPoint WebGestureEvent::positionInRootFrame() const {
return WebFloatPoint((x / m_frameScale) + m_frameTranslate.x,
(y / m_frameScale) + m_frameTranslate.y);
}
int WebGestureEvent::tapCount() const {
DCHECK(m_type == WebInputEvent::GestureTap);
return data.tap.tapCount;
}
void WebGestureEvent::applyTouchAdjustment(WebFloatPoint rootFrameCoords) {
// Update the window-relative position of the event so that the node that
// was ultimately hit is under this point (i.e. elementFromPoint for the
// client co-ordinates in a 'click' event should yield the target). The
// global position is intentionally left unmodified because it's intended to
// reflect raw co-ordinates unrelated to any content.
m_frameTranslate.x = rootFrameCoords.x - (x / m_frameScale);
m_frameTranslate.y = rootFrameCoords.y - (y / m_frameScale);
}
void WebGestureEvent::flattenTransform() {
if (m_frameScale != 1) {
switch (m_type) {
case WebInputEvent::GestureScrollBegin:
data.scrollBegin.deltaXHint /= m_frameScale;
data.scrollBegin.deltaYHint /= m_frameScale;
break;
case WebInputEvent::GestureScrollUpdate:
data.scrollUpdate.deltaX /= m_frameScale;
data.scrollUpdate.deltaY /= m_frameScale;
break;
case WebInputEvent::GestureTwoFingerTap:
data.twoFingerTap.firstFingerWidth /= m_frameScale;
data.twoFingerTap.firstFingerHeight /= m_frameScale;
break;
case WebInputEvent::GestureLongPress:
case WebInputEvent::GestureLongTap:
data.longPress.width /= m_frameScale;
data.longPress.height /= m_frameScale;
break;
case WebInputEvent::GestureTap:
case WebInputEvent::GestureTapUnconfirmed:
data.tap.width /= m_frameScale;
data.tap.height /= m_frameScale;
break;
case WebInputEvent::GestureTapDown:
data.tapDown.width /= m_frameScale;
data.tapDown.height /= m_frameScale;
break;
case WebInputEvent::GestureShowPress:
data.showPress.width /= m_frameScale;
data.showPress.height /= m_frameScale;
break;
default:
break;
}
}
x = (x / m_frameScale) + m_frameTranslate.x;
y = (y / m_frameScale) + m_frameTranslate.y;
m_frameTranslate.x = 0;
m_frameTranslate.y = 0;
m_frameScale = 1;
}
} // namespace blink
|