Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #include "public/platform/WebGestureEvent.h" | |
| 2 | |
| 3 namespace blink { | |
| 4 | |
| 5 float WebGestureEvent::deltaXInRootFrame() const { | |
| 6 if (type == WebInputEvent::GestureScrollBegin) | |
| 7 return data.scrollBegin.deltaXHint / frameScale; | |
| 8 DCHECK(type == WebInputEvent::GestureScrollUpdate); | |
| 9 return data.scrollUpdate.deltaX / frameScale; | |
| 10 } | |
| 11 | |
| 12 float WebGestureEvent::deltaYInRootFrame() const { | |
| 13 if (type == WebInputEvent::GestureScrollBegin) | |
| 14 return data.scrollBegin.deltaYHint / frameScale; | |
| 15 DCHECK(type == WebInputEvent::GestureScrollUpdate); | |
| 16 return data.scrollUpdate.deltaY / frameScale; | |
| 17 } | |
| 18 | |
| 19 WebGestureEvent::ScrollUnits WebGestureEvent::deltaUnits() const { | |
| 20 if (type == WebInputEvent::GestureScrollBegin) | |
| 21 return data.scrollBegin.deltaHintUnits; | |
| 22 if (type == WebInputEvent::GestureScrollUpdate) | |
| 23 return data.scrollUpdate.deltaUnits; | |
| 24 DCHECK(type == WebInputEvent::GestureScrollEnd); | |
| 25 return data.scrollEnd.deltaUnits; | |
| 26 } | |
| 27 | |
| 28 float WebGestureEvent::pinchScale() const { | |
| 29 DCHECK(type == WebInputEvent::GesturePinchUpdate); | |
| 30 return data.pinchUpdate.scale; | |
| 31 } | |
| 32 | |
| 33 WebGestureEvent::InertialPhaseState WebGestureEvent::inertialPhase() const { | |
| 34 if (type == WebInputEvent::GestureScrollBegin) | |
| 35 return data.scrollBegin.inertialPhase; | |
| 36 if (type == WebInputEvent::GestureScrollUpdate) | |
| 37 return data.scrollUpdate.inertialPhase; | |
| 38 DCHECK(type == WebInputEvent::GestureScrollEnd); | |
| 39 return data.scrollEnd.inertialPhase; | |
| 40 } | |
| 41 | |
| 42 bool WebGestureEvent::synthetic() const { | |
| 43 if (type == WebInputEvent::GestureScrollBegin) | |
| 44 return data.scrollBegin.synthetic; | |
| 45 DCHECK(type == WebInputEvent::GestureScrollEnd); | |
| 46 return data.scrollEnd.synthetic; | |
| 47 } | |
| 48 | |
| 49 float WebGestureEvent::velocityX() const { | |
| 50 if (type == WebInputEvent::GestureScrollUpdate) | |
| 51 return data.scrollUpdate.velocityX; | |
| 52 DCHECK(type == WebInputEvent::GestureFlingStart); | |
| 53 return data.flingStart.velocityX; | |
| 54 } | |
| 55 | |
| 56 float WebGestureEvent::velocityY() const { | |
| 57 if (type == WebInputEvent::GestureScrollUpdate) | |
| 58 return data.scrollUpdate.velocityY; | |
| 59 DCHECK(type == WebInputEvent::GestureFlingStart); | |
| 60 return data.flingStart.velocityY; | |
| 61 } | |
| 62 | |
| 63 WebFloatSize WebGestureEvent::tapAreaInRootFrame() const { | |
| 64 if (type == WebInputEvent::GestureTwoFingerTap) { | |
| 65 return WebFloatSize(data.twoFingerTap.firstFingerWidth / frameScale, | |
| 66 data.twoFingerTap.firstFingerHeight / frameScale); | |
| 67 } else if (type == WebInputEvent::GestureLongPress || | |
| 68 type == WebInputEvent::GestureLongTap) { | |
| 69 return WebFloatSize(data.longPress.width / frameScale, | |
| 70 data.longPress.height / frameScale); | |
| 71 } else if (type == WebInputEvent::GestureTap || | |
| 72 type == WebInputEvent::GestureTapUnconfirmed) { | |
| 73 return WebFloatSize(data.tap.width / frameScale, | |
| 74 data.tap.height / frameScale); | |
| 75 } else if (type == WebInputEvent::GestureTapDown) { | |
| 76 return WebFloatSize(data.tapDown.width / frameScale, | |
| 77 data.tapDown.height / frameScale); | |
| 78 } else if (type == WebInputEvent::GestureShowPress) { | |
| 79 return WebFloatSize(data.showPress.width / frameScale, | |
| 80 data.showPress.height / frameScale); | |
| 81 } | |
| 82 // This function is called for all gestures and determined if the tap | |
| 83 // area is empty or not; so return an empty rect here. | |
| 84 return WebFloatSize(); | |
| 85 } | |
| 86 | |
| 87 WebFloatPoint WebGestureEvent::positionInRootFrame() const { | |
| 88 return WebFloatPoint((x / frameScale) + frameTranslate.x, | |
| 89 (y / frameScale) + frameTranslate.y); | |
| 90 } | |
| 91 | |
| 92 int WebGestureEvent::tapCount() const { | |
| 93 DCHECK(type == WebInputEvent::GestureTap); | |
| 94 return data.tap.tapCount; | |
| 95 } | |
| 96 | |
| 97 void WebGestureEvent::applyTouchAdjustment(WebFloatPoint rootFrameCoords) { | |
| 98 frameTranslate.x = rootFrameCoords.x - (x / frameScale); | |
|
majidvp
2016/12/15 17:40:46
nit: the original method had a comment which was i
dtapuska
2016/12/15 21:29:39
Done.
| |
| 99 frameTranslate.y = rootFrameCoords.y - (y / frameScale); | |
| 100 } | |
| 101 | |
| 102 void WebGestureEvent::flattenTransform() { | |
| 103 if (frameScale != 1.0) { | |
| 104 switch (type) { | |
| 105 case WebInputEvent::GestureScrollBegin: | |
| 106 data.scrollBegin.deltaXHint /= frameScale; | |
| 107 data.scrollBegin.deltaYHint /= frameScale; | |
| 108 break; | |
| 109 case WebInputEvent::GestureScrollUpdate: | |
| 110 data.scrollUpdate.deltaX /= frameScale; | |
| 111 data.scrollUpdate.deltaY /= frameScale; | |
| 112 break; | |
| 113 case WebInputEvent::GestureTwoFingerTap: | |
| 114 data.twoFingerTap.firstFingerWidth /= frameScale; | |
| 115 data.twoFingerTap.firstFingerHeight /= frameScale; | |
| 116 break; | |
| 117 case WebInputEvent::GestureLongPress: | |
| 118 case WebInputEvent::GestureLongTap: | |
| 119 data.longPress.width /= frameScale; | |
| 120 data.longPress.height /= frameScale; | |
| 121 break; | |
| 122 case WebInputEvent::GestureTap: | |
| 123 case WebInputEvent::GestureTapUnconfirmed: | |
| 124 data.tap.width /= frameScale; | |
| 125 data.tap.height /= frameScale; | |
| 126 break; | |
| 127 case WebInputEvent::GestureTapDown: | |
| 128 data.tapDown.width /= frameScale; | |
| 129 data.tapDown.height /= frameScale; | |
| 130 break; | |
| 131 case WebInputEvent::GestureShowPress: | |
| 132 data.showPress.width /= frameScale; | |
| 133 data.showPress.height /= frameScale; | |
| 134 break; | |
| 135 default: | |
| 136 break; | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 x = (x / frameScale) + frameTranslate.x; | |
|
mustaq
2016/12/15 19:25:46
Any way we can do these transforms in a common pla
dtapuska
2016/12/15 21:29:39
I think that adding inline for div operators will
mustaq
2016/12/15 22:16:13
I didn't mean operator overload, sorry for being t
| |
| 141 y = (y / frameScale) + frameTranslate.y; | |
| 142 frameTranslate.x = 0; | |
| 143 frameTranslate.y = 0; | |
| 144 frameScale = 1; | |
| 145 } | |
| 146 | |
| 147 } // namespace blink | |
| OLD | NEW |