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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 const AtomicString& pointerEventNameForTouchPointState( | 78 const AtomicString& pointerEventNameForTouchPointState( |
79 PlatformTouchPoint::TouchState state) { | 79 WebTouchPoint::State state) { |
80 switch (state) { | 80 switch (state) { |
81 case PlatformTouchPoint::TouchReleased: | 81 case WebTouchPoint::StateReleased: |
82 return EventTypeNames::pointerup; | 82 return EventTypeNames::pointerup; |
83 case PlatformTouchPoint::TouchCancelled: | 83 case WebTouchPoint::StateCancelled: |
84 return EventTypeNames::pointercancel; | 84 return EventTypeNames::pointercancel; |
85 case PlatformTouchPoint::TouchPressed: | 85 case WebTouchPoint::StatePressed: |
86 return EventTypeNames::pointerdown; | 86 return EventTypeNames::pointerdown; |
87 case PlatformTouchPoint::TouchMoved: | 87 case WebTouchPoint::StateMoved: |
88 return EventTypeNames::pointermove; | 88 return EventTypeNames::pointermove; |
89 case PlatformTouchPoint::TouchStationary: | 89 case WebTouchPoint::StateStationary: |
90 // Fall through to default | 90 // Fall through to default |
91 default: | 91 default: |
92 NOTREACHED(); | 92 NOTREACHED(); |
93 return emptyAtom; | 93 return emptyAtom; |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 float getPointerEventPressure(float force, int buttons) { | 97 float getPointerEventPressure(float force, int buttons) { |
98 if (std::isnan(force)) | 98 if (std::isnan(force)) |
99 return buttons ? 0.5 : 0; | 99 return buttons ? 0.5 : 0; |
100 return force; | 100 return force; |
101 } | 101 } |
102 | 102 |
103 void updateTouchPointerEventInit(const PlatformTouchPoint& touchPoint, | 103 void updateTouchPointerEventInit(const WebTouchPoint& touchPoint, |
104 LocalFrame* targetFrame, | 104 LocalFrame* targetFrame, |
105 PointerEventInit* pointerEventInit) { | 105 PointerEventInit* pointerEventInit) { |
106 // This function should not update attributes like pointerId, isPrimary, | 106 // This function should not update attributes like pointerId, isPrimary, |
107 // and pointerType which is the same among the coalesced events and the | 107 // and pointerType which is the same among the coalesced events and the |
108 // dispatched event. | 108 // dispatched event. |
109 | 109 |
110 if (targetFrame) { | 110 if (targetFrame) { |
111 FloatPoint pagePoint = | 111 FloatPoint pagePoint = |
112 targetFrame->view()->rootFrameToContents(touchPoint.pos()); | 112 targetFrame->view()->rootFrameToContents(touchPoint.position); |
113 float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); | 113 float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); |
114 FloatPoint scrollPosition(targetFrame->view()->getScrollOffset()); | 114 FloatPoint scrollPosition(targetFrame->view()->getScrollOffset()); |
115 FloatPoint clientPoint = pagePoint.scaledBy(scaleFactor); | 115 FloatPoint clientPoint = pagePoint.scaledBy(scaleFactor); |
116 clientPoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); | 116 clientPoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); |
117 | 117 |
118 pointerEventInit->setClientX(clientPoint.x()); | 118 pointerEventInit->setClientX(clientPoint.x()); |
119 pointerEventInit->setClientY(clientPoint.y()); | 119 pointerEventInit->setClientY(clientPoint.y()); |
120 | 120 |
121 FloatSize pointRadius = touchPoint.radius().scaledBy(scaleFactor); | 121 FloatSize pointRadius = |
| 122 FloatSize(touchPoint.radiusX, touchPoint.radiusY).scaledBy(scaleFactor); |
122 pointerEventInit->setWidth(pointRadius.width()); | 123 pointerEventInit->setWidth(pointRadius.width()); |
123 pointerEventInit->setHeight(pointRadius.height()); | 124 pointerEventInit->setHeight(pointRadius.height()); |
124 } | 125 } |
125 | 126 |
126 pointerEventInit->setScreenX(touchPoint.screenPos().x()); | 127 pointerEventInit->setScreenX(touchPoint.screenPosition.x); |
127 pointerEventInit->setScreenY(touchPoint.screenPos().y()); | 128 pointerEventInit->setScreenY(touchPoint.screenPosition.y); |
128 pointerEventInit->setPressure( | 129 pointerEventInit->setPressure( |
129 getPointerEventPressure(touchPoint.force(), pointerEventInit->buttons())); | 130 getPointerEventPressure(touchPoint.force, pointerEventInit->buttons())); |
130 pointerEventInit->setTiltX(touchPoint.pointerProperties().tiltX); | 131 pointerEventInit->setTiltX(touchPoint.tiltX); |
131 pointerEventInit->setTiltY(touchPoint.pointerProperties().tiltY); | 132 pointerEventInit->setTiltY(touchPoint.tiltY); |
132 pointerEventInit->setTangentialPressure( | 133 pointerEventInit->setTangentialPressure(touchPoint.tangentialPressure); |
133 touchPoint.pointerProperties().tangentialPressure); | 134 pointerEventInit->setTwist(touchPoint.twist); |
134 pointerEventInit->setTwist(touchPoint.pointerProperties().twist); | |
135 } | 135 } |
136 | 136 |
137 void updateMousePointerEventInit(const PlatformMouseEvent& mouseEvent, | 137 void updateMousePointerEventInit(const PlatformMouseEvent& mouseEvent, |
138 LocalDOMWindow* view, | 138 LocalDOMWindow* view, |
139 PointerEventInit* pointerEventInit) { | 139 PointerEventInit* pointerEventInit) { |
140 // This function should not update attributes like pointerId, isPrimary, | 140 // This function should not update attributes like pointerId, isPrimary, |
141 // and pointerType which is the same among the coalesced events and the | 141 // and pointerType which is the same among the coalesced events and the |
142 // dispatched event. | 142 // dispatched event. |
143 | 143 |
144 pointerEventInit->setScreenX(mouseEvent.globalPosition().x()); | 144 pointerEventInit->setScreenX(mouseEvent.globalPosition().x()); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 coalescedPointerEvents.push_back( | 279 coalescedPointerEvents.push_back( |
280 PointerEvent::create(pointerEventName, coalescedEventInit)); | 280 PointerEvent::create(pointerEventName, coalescedEventInit)); |
281 } | 281 } |
282 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); | 282 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); |
283 } | 283 } |
284 | 284 |
285 return PointerEvent::create(pointerEventName, pointerEventInit); | 285 return PointerEvent::create(pointerEventName, pointerEventInit); |
286 } | 286 } |
287 | 287 |
288 PointerEvent* PointerEventFactory::create( | 288 PointerEvent* PointerEventFactory::create( |
289 const PlatformTouchPoint& touchPoint, | 289 const WebTouchPoint& touchPoint, |
290 const Vector<PlatformTouchPoint>& coalescedPoints, | 290 const Vector<WebTouchPoint>& coalescedPoints, |
291 PlatformEvent::Modifiers modifiers, | 291 WebInputEvent::Modifiers modifiers, |
292 LocalFrame* targetFrame, | 292 LocalFrame* targetFrame, |
293 DOMWindow* view) { | 293 DOMWindow* view) { |
294 const PlatformTouchPoint::TouchState pointState = touchPoint.state(); | 294 const WebTouchPoint::State pointState = touchPoint.state; |
295 const AtomicString& type = | 295 const AtomicString& type = |
296 pointerEventNameForTouchPointState(touchPoint.state()); | 296 pointerEventNameForTouchPointState(touchPoint.state); |
297 | 297 |
298 bool pointerReleasedOrCancelled = | 298 bool pointerReleasedOrCancelled = |
299 pointState == PlatformTouchPoint::TouchReleased || | 299 pointState == WebTouchPoint::State::StateReleased || |
300 pointState == PlatformTouchPoint::TouchCancelled; | 300 pointState == WebTouchPoint::State::StateCancelled; |
301 bool pointerPressedOrReleased = | 301 bool pointerPressedOrReleased = |
302 pointState == PlatformTouchPoint::TouchPressed || | 302 pointState == WebTouchPoint::State::StatePressed || |
303 pointState == PlatformTouchPoint::TouchReleased; | 303 pointState == WebTouchPoint::State::StateReleased; |
304 | 304 |
305 PointerEventInit pointerEventInit; | 305 PointerEventInit pointerEventInit; |
306 | 306 |
307 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), | 307 setIdTypeButtons(pointerEventInit, touchPoint, |
308 pointerReleasedOrCancelled ? 0 : 1); | 308 pointerReleasedOrCancelled ? 0 : 1); |
309 pointerEventInit.setButton(static_cast<int>( | 309 pointerEventInit.setButton(static_cast<int>( |
310 pointerPressedOrReleased ? WebPointerProperties::Button::Left | 310 pointerPressedOrReleased ? WebPointerProperties::Button::Left |
311 : WebPointerProperties::Button::NoButton)); | 311 : WebPointerProperties::Button::NoButton)); |
312 | 312 |
313 pointerEventInit.setView(view); | 313 pointerEventInit.setView(view); |
314 updateTouchPointerEventInit(touchPoint, targetFrame, &pointerEventInit); | 314 updateTouchPointerEventInit(touchPoint, targetFrame, &pointerEventInit); |
315 | 315 |
316 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); | 316 UIEventWithKeyState::setFromWebInputEventModifiers(pointerEventInit, |
| 317 modifiers); |
317 | 318 |
318 setEventSpecificFields(pointerEventInit, type); | 319 setEventSpecificFields(pointerEventInit, type); |
319 | 320 |
320 if (type == EventTypeNames::pointermove) { | 321 if (type == EventTypeNames::pointermove) { |
321 HeapVector<Member<PointerEvent>> coalescedPointerEvents; | 322 HeapVector<Member<PointerEvent>> coalescedPointerEvents; |
322 for (const auto& coalescedTouchPoint : coalescedPoints) { | 323 for (const auto& coalescedTouchPoint : coalescedPoints) { |
323 DCHECK_EQ(touchPoint.state(), coalescedTouchPoint.state()); | 324 DCHECK_EQ(touchPoint.state, coalescedTouchPoint.state); |
324 DCHECK_EQ(touchPoint.pointerProperties().id, | 325 DCHECK_EQ(touchPoint.id, coalescedTouchPoint.id); |
325 coalescedTouchPoint.pointerProperties().id); | 326 DCHECK_EQ(touchPoint.pointerType, coalescedTouchPoint.pointerType); |
326 DCHECK_EQ(touchPoint.pointerProperties().pointerType, | |
327 coalescedTouchPoint.pointerProperties().pointerType); | |
328 PointerEventInit coalescedEventInit = pointerEventInit; | 327 PointerEventInit coalescedEventInit = pointerEventInit; |
329 updateTouchPointerEventInit(coalescedTouchPoint, targetFrame, | 328 updateTouchPointerEventInit(coalescedTouchPoint, targetFrame, |
330 &coalescedEventInit); | 329 &coalescedEventInit); |
331 coalescedPointerEvents.push_back( | 330 coalescedPointerEvents.push_back( |
332 PointerEvent::create(type, coalescedEventInit)); | 331 PointerEvent::create(type, coalescedEventInit)); |
333 } | 332 } |
334 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); | 333 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); |
335 } | 334 } |
336 | 335 |
337 return PointerEvent::create(type, pointerEventInit); | 336 return PointerEvent::create(type, pointerEventInit); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 const WebPointerProperties& properties) const { | 522 const WebPointerProperties& properties) const { |
524 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) | 523 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) |
525 return PointerEventFactory::s_mouseId; | 524 return PointerEventFactory::s_mouseId; |
526 IncomingId id(properties.pointerType, properties.id); | 525 IncomingId id(properties.pointerType, properties.id); |
527 if (m_pointerIncomingIdMapping.contains(id)) | 526 if (m_pointerIncomingIdMapping.contains(id)) |
528 return m_pointerIncomingIdMapping.get(id); | 527 return m_pointerIncomingIdMapping.get(id); |
529 return PointerEventFactory::s_invalidId; | 528 return PointerEventFactory::s_invalidId; |
530 } | 529 } |
531 | 530 |
532 } // namespace blink | 531 } // namespace blink |
OLD | NEW |