OLD | NEW |
---|---|
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 "core/events/PointerEventFactory.h" | 5 #include "core/events/PointerEventFactory.h" |
6 | 6 |
7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
8 #include "platform/geometry/FloatSize.h" | 8 #include "platform/geometry/FloatSize.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 CASE_BUTTON_TO_BUTTONS(X2); | 68 CASE_BUTTON_TO_BUTTONS(X2); |
69 CASE_BUTTON_TO_BUTTONS(Eraser); | 69 CASE_BUTTON_TO_BUTTONS(Eraser); |
70 } | 70 } |
71 | 71 |
72 #undef CASE_BUTTON_TO_BUTTONS | 72 #undef CASE_BUTTON_TO_BUTTONS |
73 | 73 |
74 NOTREACHED(); | 74 NOTREACHED(); |
75 return 0; | 75 return 0; |
76 } | 76 } |
77 | 77 |
78 } // namespace | 78 const AtomicString& pointerEventNameForTouchPointState( |
79 | 79 PlatformTouchPoint::TouchState state) { |
80 const int PointerEventFactory::s_invalidId = 0; | 80 switch (state) { |
81 | 81 case PlatformTouchPoint::TouchReleased: |
82 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. | 82 return EventTypeNames::pointerup; |
83 const int PointerEventFactory::s_mouseId = 1; | 83 case PlatformTouchPoint::TouchCancelled: |
84 return EventTypeNames::pointercancel; | |
85 case PlatformTouchPoint::TouchPressed: | |
86 return EventTypeNames::pointerdown; | |
87 case PlatformTouchPoint::TouchMoved: | |
88 return EventTypeNames::pointermove; | |
89 case PlatformTouchPoint::TouchStationary: | |
90 // Fall through to default | |
91 default: | |
92 NOTREACHED(); | |
93 return emptyAtom; | |
94 } | |
95 } | |
84 | 96 |
85 float getPointerEventPressure(float force, int buttons) { | 97 float getPointerEventPressure(float force, int buttons) { |
86 if (std::isnan(force)) | 98 if (std::isnan(force)) |
87 return buttons ? 0.5 : 0; | 99 return buttons ? 0.5 : 0; |
88 return force; | 100 return force; |
89 } | 101 } |
90 | 102 |
103 void updateTouchPointPointerEventInit(const PlatformTouchPoint& touchPoint, | |
mustaq
2016/11/21 20:53:53
You meant "updateTouchPointerEventInit" instead?
Navid Zolghadr
2016/11/21 21:31:21
Done.
| |
104 LocalFrame* targetFrame, | |
105 PointerEventInit* pointerEventInit) { | |
106 if (targetFrame) { | |
107 FloatPoint pagePoint = | |
108 targetFrame->view()->rootFrameToContents(touchPoint.pos()); | |
109 float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); | |
110 FloatPoint scrollPosition(targetFrame->view()->scrollOffset()); | |
111 FloatPoint clientPoint = pagePoint.scaledBy(scaleFactor); | |
112 clientPoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); | |
113 | |
114 pointerEventInit->setClientX(clientPoint.x()); | |
115 pointerEventInit->setClientY(clientPoint.y()); | |
116 | |
117 FloatSize pointRadius = touchPoint.radius().scaledBy(scaleFactor); | |
mustaq
2016/11/21 20:53:53
Radius, width & height should be outside the |if|
Navid Zolghadr
2016/11/21 21:31:21
But scaleFactor comes from the targetFrame. What s
mustaq
2016/11/22 15:31:10
I thought it's a bug because when target frame is
| |
118 pointerEventInit->setWidth(pointRadius.width()); | |
119 pointerEventInit->setHeight(pointRadius.height()); | |
120 } | |
121 | |
122 pointerEventInit->setScreenX(touchPoint.screenPos().x()); | |
123 pointerEventInit->setScreenY(touchPoint.screenPos().y()); | |
124 pointerEventInit->setPressure( | |
125 getPointerEventPressure(touchPoint.force(), pointerEventInit->buttons())); | |
126 pointerEventInit->setTiltX(touchPoint.pointerProperties().tiltX); | |
127 pointerEventInit->setTiltY(touchPoint.pointerProperties().tiltY); | |
128 } | |
129 | |
130 void updateMousePointerEventInit(const PlatformMouseEvent& mouseEvent, | |
131 LocalDOMWindow* view, | |
132 PointerEventInit* pointerEventInit) { | |
133 pointerEventInit->setScreenX(mouseEvent.globalPosition().x()); | |
134 pointerEventInit->setScreenY(mouseEvent.globalPosition().y()); | |
135 | |
136 IntPoint locationInFrameZoomed; | |
137 if (view && view->frame() && view->frame()->view()) { | |
138 LocalFrame* frame = view->frame(); | |
139 FrameView* frameView = frame->view(); | |
140 IntPoint locationInContents = | |
141 frameView->rootFrameToContents(mouseEvent.position()); | |
142 locationInFrameZoomed = frameView->contentsToFrame(locationInContents); | |
143 float scaleFactor = 1 / frame->pageZoomFactor(); | |
144 locationInFrameZoomed.scale(scaleFactor, scaleFactor); | |
145 } | |
146 | |
147 // Set up initial values for coordinates. | |
mustaq
2016/11/21 20:53:53
Please get rid of this old comment line, the value
Navid Zolghadr
2016/11/21 21:31:21
Done.
| |
148 pointerEventInit->setClientX(locationInFrameZoomed.x()); | |
149 pointerEventInit->setClientY(locationInFrameZoomed.y()); | |
150 | |
151 pointerEventInit->setPressure(getPointerEventPressure( | |
152 mouseEvent.pointerProperties().force, pointerEventInit->buttons())); | |
153 pointerEventInit->setTiltX(mouseEvent.pointerProperties().tiltX); | |
154 pointerEventInit->setTiltY(mouseEvent.pointerProperties().tiltY); | |
155 } | |
156 | |
157 } // namespace | |
158 | |
159 const int PointerEventFactory::s_invalidId = 0; | |
160 | |
161 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. | |
162 const int PointerEventFactory::s_mouseId = 1; | |
163 | |
91 void PointerEventFactory::setIdTypeButtons( | 164 void PointerEventFactory::setIdTypeButtons( |
92 PointerEventInit& pointerEventInit, | 165 PointerEventInit& pointerEventInit, |
93 const WebPointerProperties& pointerProperties, | 166 const WebPointerProperties& pointerProperties, |
94 unsigned buttons) { | 167 unsigned buttons) { |
95 const WebPointerProperties::PointerType pointerType = | 168 const WebPointerProperties::PointerType pointerType = |
96 pointerProperties.pointerType; | 169 pointerProperties.pointerType; |
97 const IncomingId incomingId(pointerType, pointerProperties.id); | 170 const IncomingId incomingId(pointerType, pointerProperties.id); |
98 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); | 171 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); |
99 | 172 |
100 // Tweak the |buttons| to reflect pen eraser mode only if the pen is in | 173 // Tweak the |buttons| to reflect pen eraser mode only if the pen is in |
(...skipping 20 matching lines...) Expand all Loading... | |
121 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter && | 194 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter && |
122 type != EventTypeNames::pointerleave && | 195 type != EventTypeNames::pointerleave && |
123 type != EventTypeNames::pointercancel && | 196 type != EventTypeNames::pointercancel && |
124 type != EventTypeNames::gotpointercapture && | 197 type != EventTypeNames::gotpointercapture && |
125 type != EventTypeNames::lostpointercapture); | 198 type != EventTypeNames::lostpointercapture); |
126 | 199 |
127 pointerEventInit.setComposed(true); | 200 pointerEventInit.setComposed(true); |
128 pointerEventInit.setDetail(0); | 201 pointerEventInit.setDetail(0); |
129 } | 202 } |
130 | 203 |
131 PointerEvent* PointerEventFactory::create(const AtomicString& mouseEventName, | 204 PointerEvent* PointerEventFactory::create( |
132 const PlatformMouseEvent& mouseEvent, | 205 const AtomicString& mouseEventName, |
133 LocalDOMWindow* view) { | 206 const PlatformMouseEvent& mouseEvent, |
207 const Vector<PlatformMouseEvent>& coalescedMouseEvents, | |
208 LocalDOMWindow* view) { | |
134 DCHECK(mouseEventName == EventTypeNames::mousemove || | 209 DCHECK(mouseEventName == EventTypeNames::mousemove || |
135 mouseEventName == EventTypeNames::mousedown || | 210 mouseEventName == EventTypeNames::mousedown || |
136 mouseEventName == EventTypeNames::mouseup); | 211 mouseEventName == EventTypeNames::mouseup); |
137 | 212 |
138 AtomicString pointerEventName = | 213 AtomicString pointerEventName = |
139 pointerEventNameForMouseEventName(mouseEventName); | 214 pointerEventNameForMouseEventName(mouseEventName); |
215 DCHECK(pointerEventName == EventTypeNames::pointermove || | |
216 coalescedMouseEvents.isEmpty()); | |
217 | |
140 unsigned buttons = | 218 unsigned buttons = |
141 MouseEvent::platformModifiersToButtons(mouseEvent.getModifiers()); | 219 MouseEvent::platformModifiersToButtons(mouseEvent.getModifiers()); |
142 PointerEventInit pointerEventInit; | 220 PointerEventInit pointerEventInit; |
143 | 221 |
144 setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons); | 222 setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons); |
145 setEventSpecificFields(pointerEventInit, pointerEventName); | 223 setEventSpecificFields(pointerEventInit, pointerEventName); |
146 | 224 |
147 pointerEventInit.setScreenX(mouseEvent.globalPosition().x()); | |
148 pointerEventInit.setScreenY(mouseEvent.globalPosition().y()); | |
149 | |
150 IntPoint locationInFrameZoomed; | |
151 if (view && view->frame() && view->frame()->view()) { | |
152 LocalFrame* frame = view->frame(); | |
153 FrameView* frameView = frame->view(); | |
154 IntPoint locationInContents = | |
155 frameView->rootFrameToContents(mouseEvent.position()); | |
156 locationInFrameZoomed = frameView->contentsToFrame(locationInContents); | |
157 float scaleFactor = 1 / frame->pageZoomFactor(); | |
158 locationInFrameZoomed.scale(scaleFactor, scaleFactor); | |
159 } | |
160 | |
161 // Set up initial values for coordinates. | |
162 pointerEventInit.setClientX(locationInFrameZoomed.x()); | |
163 pointerEventInit.setClientY(locationInFrameZoomed.y()); | |
164 | |
165 if (pointerEventName == EventTypeNames::pointerdown || | 225 if (pointerEventName == EventTypeNames::pointerdown || |
166 pointerEventName == EventTypeNames::pointerup) { | 226 pointerEventName == EventTypeNames::pointerup) { |
167 WebPointerProperties::Button button = mouseEvent.pointerProperties().button; | 227 WebPointerProperties::Button button = mouseEvent.pointerProperties().button; |
168 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. | 228 // TODO(mustaq): Fix when the spec starts supporting hovering erasers. |
169 if (mouseEvent.pointerProperties().pointerType == | 229 if (mouseEvent.pointerProperties().pointerType == |
170 WebPointerProperties::PointerType::Eraser && | 230 WebPointerProperties::PointerType::Eraser && |
171 button == WebPointerProperties::Button::Left) | 231 button == WebPointerProperties::Button::Left) |
172 button = WebPointerProperties::Button::Eraser; | 232 button = WebPointerProperties::Button::Eraser; |
173 pointerEventInit.setButton(static_cast<int>(button)); | 233 pointerEventInit.setButton(static_cast<int>(button)); |
174 } else { | 234 } else { |
175 DCHECK(pointerEventName == EventTypeNames::pointermove); | 235 DCHECK(pointerEventName == EventTypeNames::pointermove); |
176 pointerEventInit.setButton( | 236 pointerEventInit.setButton( |
177 static_cast<int>(WebPointerProperties::Button::NoButton)); | 237 static_cast<int>(WebPointerProperties::Button::NoButton)); |
178 } | 238 } |
179 pointerEventInit.setPressure(getPointerEventPressure( | |
180 mouseEvent.pointerProperties().force, pointerEventInit.buttons())); | |
181 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX); | |
182 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY); | |
183 | 239 |
184 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, | 240 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, |
185 mouseEvent.getModifiers()); | 241 mouseEvent.getModifiers()); |
186 | 242 |
187 // Make sure chorded buttons fire pointermove instead of pointerup/down. | 243 // Make sure chorded buttons fire pointermove instead of pointerup/down. |
188 if ((pointerEventName == EventTypeNames::pointerdown && | 244 if ((pointerEventName == EventTypeNames::pointerdown && |
189 (buttons & | 245 (buttons & |
190 ~buttonToButtonsBitfield(mouseEvent.pointerProperties().button)) != | 246 ~buttonToButtonsBitfield(mouseEvent.pointerProperties().button)) != |
191 0) || | 247 0) || |
192 (pointerEventName == EventTypeNames::pointerup && buttons != 0)) | 248 (pointerEventName == EventTypeNames::pointerup && buttons != 0)) |
193 pointerEventName = EventTypeNames::pointermove; | 249 pointerEventName = EventTypeNames::pointermove; |
194 | 250 |
195 pointerEventInit.setView(view); | 251 pointerEventInit.setView(view); |
196 | 252 |
253 updateMousePointerEventInit(mouseEvent, view, &pointerEventInit); | |
254 | |
255 // Created coalesced events init structure | |
256 HeapVector<Member<PointerEvent>> coalescedPointerEvents; | |
257 for (const auto& coalescedMouseEvent : coalescedMouseEvents) { | |
258 PointerEventInit coalescedEventInit = pointerEventInit; | |
259 updateMousePointerEventInit(coalescedMouseEvent, view, &coalescedEventInit); | |
260 coalescedPointerEvents.append( | |
mustaq
2016/11/21 20:53:53
Add a DCHECK here for matching (with the container
Navid Zolghadr
2016/11/21 21:31:21
I'm not sure what the DCHECK would achieve here. W
mustaq
2016/11/22 15:31:10
Right but we still need to enforce the equality of
Navid Zolghadr
2016/11/22 15:59:28
I don't think that is the case either as that path
mustaq
2016/11/22 21:07:51
Instead of the raw data checks you have added, let
| |
261 PointerEvent::create(pointerEventName, coalescedEventInit)); | |
262 } | |
263 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); | |
264 | |
197 return PointerEvent::create(pointerEventName, pointerEventInit); | 265 return PointerEvent::create(pointerEventName, pointerEventInit); |
198 } | 266 } |
199 | 267 |
200 PointerEvent* PointerEventFactory::create(const AtomicString& type, | 268 PointerEvent* PointerEventFactory::create( |
201 const PlatformTouchPoint& touchPoint, | 269 const PlatformTouchPoint& touchPoint, |
202 PlatformEvent::Modifiers modifiers, | 270 const Vector<PlatformTouchPoint>& coalescedPoints, |
203 const FloatSize& pointRadius, | 271 PlatformEvent::Modifiers modifiers, |
204 const FloatPoint& clientPoint, | 272 LocalFrame* targetFrame, |
205 DOMWindow* view) { | 273 DOMWindow* view) { |
206 const PlatformTouchPoint::TouchState pointState = touchPoint.state(); | 274 const PlatformTouchPoint::TouchState pointState = touchPoint.state(); |
275 const AtomicString& type = | |
276 pointerEventNameForTouchPointState(touchPoint.state()); | |
277 DCHECK(type == EventTypeNames::pointermove || coalescedPoints.isEmpty()); | |
207 | 278 |
208 bool pointerReleasedOrCancelled = | 279 bool pointerReleasedOrCancelled = |
209 pointState == PlatformTouchPoint::TouchReleased || | 280 pointState == PlatformTouchPoint::TouchReleased || |
210 pointState == PlatformTouchPoint::TouchCancelled; | 281 pointState == PlatformTouchPoint::TouchCancelled; |
211 bool pointerPressedOrReleased = | 282 bool pointerPressedOrReleased = |
212 pointState == PlatformTouchPoint::TouchPressed || | 283 pointState == PlatformTouchPoint::TouchPressed || |
213 pointState == PlatformTouchPoint::TouchReleased; | 284 pointState == PlatformTouchPoint::TouchReleased; |
214 | 285 |
215 PointerEventInit pointerEventInit; | 286 PointerEventInit pointerEventInit; |
216 | 287 |
217 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), | 288 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), |
218 pointerReleasedOrCancelled ? 0 : 1); | 289 pointerReleasedOrCancelled ? 0 : 1); |
219 | |
220 pointerEventInit.setWidth(pointRadius.width()); | |
221 pointerEventInit.setHeight(pointRadius.height()); | |
222 pointerEventInit.setScreenX(touchPoint.screenPos().x()); | |
223 pointerEventInit.setScreenY(touchPoint.screenPos().y()); | |
224 pointerEventInit.setClientX(clientPoint.x()); | |
225 pointerEventInit.setClientY(clientPoint.y()); | |
226 pointerEventInit.setButton(static_cast<int>( | 290 pointerEventInit.setButton(static_cast<int>( |
227 pointerPressedOrReleased ? WebPointerProperties::Button::Left | 291 pointerPressedOrReleased ? WebPointerProperties::Button::Left |
228 : WebPointerProperties::Button::NoButton)); | 292 : WebPointerProperties::Button::NoButton)); |
229 pointerEventInit.setPressure( | 293 |
230 getPointerEventPressure(touchPoint.force(), pointerEventInit.buttons())); | |
231 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); | |
232 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); | |
233 pointerEventInit.setView(view); | 294 pointerEventInit.setView(view); |
295 updateTouchPointPointerEventInit(touchPoint, targetFrame, &pointerEventInit); | |
234 | 296 |
235 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); | 297 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); |
236 | 298 |
237 setEventSpecificFields(pointerEventInit, type); | 299 setEventSpecificFields(pointerEventInit, type); |
238 | 300 |
301 // Created coalesced events init structure | |
302 HeapVector<Member<PointerEvent>> coalescedPointerEvents; | |
303 for (const auto& coalescedTouchPoint : coalescedPoints) { | |
304 PointerEventInit coalescedEventInit = pointerEventInit; | |
305 updateTouchPointPointerEventInit(coalescedTouchPoint, targetFrame, | |
306 &coalescedEventInit); | |
307 coalescedPointerEvents.append( | |
mustaq
2016/11/21 20:53:53
Ditto.
| |
308 PointerEvent::create(type, coalescedEventInit)); | |
309 } | |
310 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); | |
311 | |
239 return PointerEvent::create(type, pointerEventInit); | 312 return PointerEvent::create(type, pointerEventInit); |
240 } | 313 } |
241 | 314 |
242 PointerEvent* PointerEventFactory::createPointerCancelEvent( | 315 PointerEvent* PointerEventFactory::createPointerCancelEvent( |
243 const int pointerId, | 316 const int pointerId, |
244 const WebPointerProperties::PointerType pointerType) { | 317 const WebPointerProperties::PointerType pointerType) { |
245 DCHECK(m_pointerIdMapping.contains(pointerId)); | 318 DCHECK(m_pointerIdMapping.contains(pointerId)); |
246 m_pointerIdMapping.set( | 319 m_pointerIdMapping.set( |
247 pointerId, | 320 pointerId, |
248 PointerAttributes(m_pointerIdMapping.get(pointerId).incomingId, false)); | 321 PointerAttributes(m_pointerIdMapping.get(pointerId).incomingId, false)); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 const WebPointerProperties& properties) const { | 496 const WebPointerProperties& properties) const { |
424 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) | 497 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) |
425 return PointerEventFactory::s_mouseId; | 498 return PointerEventFactory::s_mouseId; |
426 IncomingId id(properties.pointerType, properties.id); | 499 IncomingId id(properties.pointerType, properties.id); |
427 if (m_pointerIncomingIdMapping.contains(id)) | 500 if (m_pointerIncomingIdMapping.contains(id)) |
428 return m_pointerIncomingIdMapping.get(id); | 501 return m_pointerIncomingIdMapping.get(id); |
429 return PointerEventFactory::s_invalidId; | 502 return PointerEventFactory::s_invalidId; |
430 } | 503 } |
431 | 504 |
432 } // namespace blink | 505 } // namespace blink |
OLD | NEW |