Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: third_party/WebKit/Source/platform/WebGestureEvent.cpp

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "public/platform/WebGestureEvent.h" 5 #include "public/platform/WebGestureEvent.h"
6 6
7 namespace blink { 7 namespace blink {
8 8
9 float WebGestureEvent::deltaXInRootFrame() const { 9 float WebGestureEvent::deltaXInRootFrame() const {
10 if (type == WebInputEvent::GestureScrollBegin) 10 if (m_type == WebInputEvent::GestureScrollBegin)
11 return data.scrollBegin.deltaXHint / m_frameScale; 11 return data.scrollBegin.deltaXHint / m_frameScale;
12 DCHECK(type == WebInputEvent::GestureScrollUpdate); 12 DCHECK(m_type == WebInputEvent::GestureScrollUpdate);
13 return data.scrollUpdate.deltaX / m_frameScale; 13 return data.scrollUpdate.deltaX / m_frameScale;
14 } 14 }
15 15
16 float WebGestureEvent::deltaYInRootFrame() const { 16 float WebGestureEvent::deltaYInRootFrame() const {
17 if (type == WebInputEvent::GestureScrollBegin) 17 if (m_type == WebInputEvent::GestureScrollBegin)
18 return data.scrollBegin.deltaYHint / m_frameScale; 18 return data.scrollBegin.deltaYHint / m_frameScale;
19 DCHECK(type == WebInputEvent::GestureScrollUpdate); 19 DCHECK(m_type == WebInputEvent::GestureScrollUpdate);
20 return data.scrollUpdate.deltaY / m_frameScale; 20 return data.scrollUpdate.deltaY / m_frameScale;
21 } 21 }
22 22
23 WebGestureEvent::ScrollUnits WebGestureEvent::deltaUnits() const { 23 WebGestureEvent::ScrollUnits WebGestureEvent::deltaUnits() const {
24 if (type == WebInputEvent::GestureScrollBegin) 24 if (m_type == WebInputEvent::GestureScrollBegin)
25 return data.scrollBegin.deltaHintUnits; 25 return data.scrollBegin.deltaHintUnits;
26 if (type == WebInputEvent::GestureScrollUpdate) 26 if (m_type == WebInputEvent::GestureScrollUpdate)
27 return data.scrollUpdate.deltaUnits; 27 return data.scrollUpdate.deltaUnits;
28 DCHECK(type == WebInputEvent::GestureScrollEnd); 28 DCHECK(m_type == WebInputEvent::GestureScrollEnd);
29 return data.scrollEnd.deltaUnits; 29 return data.scrollEnd.deltaUnits;
30 } 30 }
31 31
32 float WebGestureEvent::pinchScale() const { 32 float WebGestureEvent::pinchScale() const {
33 DCHECK(type == WebInputEvent::GesturePinchUpdate); 33 DCHECK(m_type == WebInputEvent::GesturePinchUpdate);
34 return data.pinchUpdate.scale; 34 return data.pinchUpdate.scale;
35 } 35 }
36 36
37 WebGestureEvent::InertialPhaseState WebGestureEvent::inertialPhase() const { 37 WebGestureEvent::InertialPhaseState WebGestureEvent::inertialPhase() const {
38 if (type == WebInputEvent::GestureScrollBegin) 38 if (m_type == WebInputEvent::GestureScrollBegin)
39 return data.scrollBegin.inertialPhase; 39 return data.scrollBegin.inertialPhase;
40 if (type == WebInputEvent::GestureScrollUpdate) 40 if (m_type == WebInputEvent::GestureScrollUpdate)
41 return data.scrollUpdate.inertialPhase; 41 return data.scrollUpdate.inertialPhase;
42 DCHECK(type == WebInputEvent::GestureScrollEnd); 42 DCHECK(m_type == WebInputEvent::GestureScrollEnd);
43 return data.scrollEnd.inertialPhase; 43 return data.scrollEnd.inertialPhase;
44 } 44 }
45 45
46 bool WebGestureEvent::synthetic() const { 46 bool WebGestureEvent::synthetic() const {
47 if (type == WebInputEvent::GestureScrollBegin) 47 if (m_type == WebInputEvent::GestureScrollBegin)
48 return data.scrollBegin.synthetic; 48 return data.scrollBegin.synthetic;
49 DCHECK(type == WebInputEvent::GestureScrollEnd); 49 DCHECK(m_type == WebInputEvent::GestureScrollEnd);
50 return data.scrollEnd.synthetic; 50 return data.scrollEnd.synthetic;
51 } 51 }
52 52
53 float WebGestureEvent::velocityX() const { 53 float WebGestureEvent::velocityX() const {
54 if (type == WebInputEvent::GestureScrollUpdate) 54 if (m_type == WebInputEvent::GestureScrollUpdate)
55 return data.scrollUpdate.velocityX; 55 return data.scrollUpdate.velocityX;
56 DCHECK(type == WebInputEvent::GestureFlingStart); 56 DCHECK(m_type == WebInputEvent::GestureFlingStart);
57 return data.flingStart.velocityX; 57 return data.flingStart.velocityX;
58 } 58 }
59 59
60 float WebGestureEvent::velocityY() const { 60 float WebGestureEvent::velocityY() const {
61 if (type == WebInputEvent::GestureScrollUpdate) 61 if (m_type == WebInputEvent::GestureScrollUpdate)
62 return data.scrollUpdate.velocityY; 62 return data.scrollUpdate.velocityY;
63 DCHECK(type == WebInputEvent::GestureFlingStart); 63 DCHECK(m_type == WebInputEvent::GestureFlingStart);
64 return data.flingStart.velocityY; 64 return data.flingStart.velocityY;
65 } 65 }
66 66
67 WebFloatSize WebGestureEvent::tapAreaInRootFrame() const { 67 WebFloatSize WebGestureEvent::tapAreaInRootFrame() const {
68 if (type == WebInputEvent::GestureTwoFingerTap) { 68 if (m_type == WebInputEvent::GestureTwoFingerTap) {
69 return WebFloatSize(data.twoFingerTap.firstFingerWidth / m_frameScale, 69 return WebFloatSize(data.twoFingerTap.firstFingerWidth / m_frameScale,
70 data.twoFingerTap.firstFingerHeight / m_frameScale); 70 data.twoFingerTap.firstFingerHeight / m_frameScale);
71 } else if (type == WebInputEvent::GestureLongPress || 71 } else if (m_type == WebInputEvent::GestureLongPress ||
72 type == WebInputEvent::GestureLongTap) { 72 m_type == WebInputEvent::GestureLongTap) {
73 return WebFloatSize(data.longPress.width / m_frameScale, 73 return WebFloatSize(data.longPress.width / m_frameScale,
74 data.longPress.height / m_frameScale); 74 data.longPress.height / m_frameScale);
75 } else if (type == WebInputEvent::GestureTap || 75 } else if (m_type == WebInputEvent::GestureTap ||
76 type == WebInputEvent::GestureTapUnconfirmed) { 76 m_type == WebInputEvent::GestureTapUnconfirmed) {
77 return WebFloatSize(data.tap.width / m_frameScale, 77 return WebFloatSize(data.tap.width / m_frameScale,
78 data.tap.height / m_frameScale); 78 data.tap.height / m_frameScale);
79 } else if (type == WebInputEvent::GestureTapDown) { 79 } else if (m_type == WebInputEvent::GestureTapDown) {
80 return WebFloatSize(data.tapDown.width / m_frameScale, 80 return WebFloatSize(data.tapDown.width / m_frameScale,
81 data.tapDown.height / m_frameScale); 81 data.tapDown.height / m_frameScale);
82 } else if (type == WebInputEvent::GestureShowPress) { 82 } else if (m_type == WebInputEvent::GestureShowPress) {
83 return WebFloatSize(data.showPress.width / m_frameScale, 83 return WebFloatSize(data.showPress.width / m_frameScale,
84 data.showPress.height / m_frameScale); 84 data.showPress.height / m_frameScale);
85 } 85 }
86 // This function is called for all gestures and determined if the tap 86 // This function is called for all gestures and determined if the tap
87 // area is empty or not; so return an empty rect here. 87 // area is empty or not; so return an empty rect here.
88 return WebFloatSize(); 88 return WebFloatSize();
89 } 89 }
90 90
91 WebFloatPoint WebGestureEvent::positionInRootFrame() const { 91 WebFloatPoint WebGestureEvent::positionInRootFrame() const {
92 return WebFloatPoint((x / m_frameScale) + m_frameTranslate.x, 92 return WebFloatPoint((x / m_frameScale) + m_frameTranslate.x,
93 (y / m_frameScale) + m_frameTranslate.y); 93 (y / m_frameScale) + m_frameTranslate.y);
94 } 94 }
95 95
96 int WebGestureEvent::tapCount() const { 96 int WebGestureEvent::tapCount() const {
97 DCHECK(type == WebInputEvent::GestureTap); 97 DCHECK(m_type == WebInputEvent::GestureTap);
98 return data.tap.tapCount; 98 return data.tap.tapCount;
99 } 99 }
100 100
101 void WebGestureEvent::applyTouchAdjustment(WebFloatPoint rootFrameCoords) { 101 void WebGestureEvent::applyTouchAdjustment(WebFloatPoint rootFrameCoords) {
102 // Update the window-relative position of the event so that the node that 102 // Update the window-relative position of the event so that the node that
103 // was ultimately hit is under this point (i.e. elementFromPoint for the 103 // was ultimately hit is under this point (i.e. elementFromPoint for the
104 // client co-ordinates in a 'click' event should yield the target). The 104 // client co-ordinates in a 'click' event should yield the target). The
105 // global position is intentionally left unmodified because it's intended to 105 // global position is intentionally left unmodified because it's intended to
106 // reflect raw co-ordinates unrelated to any content. 106 // reflect raw co-ordinates unrelated to any content.
107 m_frameTranslate.x = rootFrameCoords.x - (x / m_frameScale); 107 m_frameTranslate.x = rootFrameCoords.x - (x / m_frameScale);
108 m_frameTranslate.y = rootFrameCoords.y - (y / m_frameScale); 108 m_frameTranslate.y = rootFrameCoords.y - (y / m_frameScale);
109 } 109 }
110 110
111 void WebGestureEvent::flattenTransform() { 111 void WebGestureEvent::flattenTransform() {
112 if (m_frameScale != 1) { 112 if (m_frameScale != 1) {
113 switch (type) { 113 switch (m_type) {
114 case WebInputEvent::GestureScrollBegin: 114 case WebInputEvent::GestureScrollBegin:
115 data.scrollBegin.deltaXHint /= m_frameScale; 115 data.scrollBegin.deltaXHint /= m_frameScale;
116 data.scrollBegin.deltaYHint /= m_frameScale; 116 data.scrollBegin.deltaYHint /= m_frameScale;
117 break; 117 break;
118 case WebInputEvent::GestureScrollUpdate: 118 case WebInputEvent::GestureScrollUpdate:
119 data.scrollUpdate.deltaX /= m_frameScale; 119 data.scrollUpdate.deltaX /= m_frameScale;
120 data.scrollUpdate.deltaY /= m_frameScale; 120 data.scrollUpdate.deltaY /= m_frameScale;
121 break; 121 break;
122 case WebInputEvent::GestureTwoFingerTap: 122 case WebInputEvent::GestureTwoFingerTap:
123 data.twoFingerTap.firstFingerWidth /= m_frameScale; 123 data.twoFingerTap.firstFingerWidth /= m_frameScale;
(...skipping 23 matching lines...) Expand all
147 } 147 }
148 148
149 x = (x / m_frameScale) + m_frameTranslate.x; 149 x = (x / m_frameScale) + m_frameTranslate.x;
150 y = (y / m_frameScale) + m_frameTranslate.y; 150 y = (y / m_frameScale) + m_frameTranslate.y;
151 m_frameTranslate.x = 0; 151 m_frameTranslate.x = 0;
152 m_frameTranslate.y = 0; 152 m_frameTranslate.y = 0;
153 m_frameScale = 1; 153 m_frameScale = 1;
154 } 154 }
155 155
156 } // namespace blink 156 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698