| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 coalescedPointerEvents.push_back( | 277 coalescedPointerEvents.push_back( |
| 278 PointerEvent::create(pointerEventName, coalescedEventInit)); | 278 PointerEvent::create(pointerEventName, coalescedEventInit)); |
| 279 } | 279 } |
| 280 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); | 280 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); |
| 281 } | 281 } |
| 282 | 282 |
| 283 return PointerEvent::create(pointerEventName, pointerEventInit); | 283 return PointerEvent::create(pointerEventName, pointerEventInit); |
| 284 } | 284 } |
| 285 | 285 |
| 286 PointerEvent* PointerEventFactory::create( | 286 PointerEvent* PointerEventFactory::create( |
| 287 const PlatformTouchPoint& touchPoint, | 287 const WebTouchPoint& touchPoint, |
| 288 const Vector<PlatformTouchPoint>& coalescedPoints, | 288 const Vector<WebTouchPoint>& coalescedPoints, |
| 289 PlatformEvent::Modifiers modifiers, | 289 WebInputEvent::Modifiers modifiers, |
| 290 LocalFrame* targetFrame, | 290 LocalFrame* targetFrame, |
| 291 DOMWindow* view) { | 291 DOMWindow* view) { |
| 292 const PlatformTouchPoint::TouchState pointState = touchPoint.state(); | 292 const WebTouchPoint::State pointState = touchPoint.state; |
| 293 const AtomicString& type = | 293 const AtomicString& type = |
| 294 pointerEventNameForTouchPointState(touchPoint.state()); | 294 pointerEventNameForTouchPointState(touchPoint.state); |
| 295 | 295 |
| 296 bool pointerReleasedOrCancelled = | 296 bool pointerReleasedOrCancelled = |
| 297 pointState == PlatformTouchPoint::TouchReleased || | 297 pointState == WebTouchPoint::State::StateReleased || |
| 298 pointState == PlatformTouchPoint::TouchCancelled; | 298 pointState == WebTouchPoint::State::StateCancelled; |
| 299 bool pointerPressedOrReleased = | 299 bool pointerPressedOrReleased = |
| 300 pointState == PlatformTouchPoint::TouchPressed || | 300 pointState == WebTouchPoint::State::StatePressed || |
| 301 pointState == PlatformTouchPoint::TouchReleased; | 301 pointState == WebTouchPoint::State::StateReleased; |
| 302 | 302 |
| 303 PointerEventInit pointerEventInit; | 303 PointerEventInit pointerEventInit; |
| 304 | 304 |
| 305 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), | 305 setIdTypeButtons(pointerEventInit, touchPoint, |
| 306 pointerReleasedOrCancelled ? 0 : 1); | 306 pointerReleasedOrCancelled ? 0 : 1); |
| 307 pointerEventInit.setButton(static_cast<int>( | 307 pointerEventInit.setButton(static_cast<int>( |
| 308 pointerPressedOrReleased ? WebPointerProperties::Button::Left | 308 pointerPressedOrReleased ? WebPointerProperties::Button::Left |
| 309 : WebPointerProperties::Button::NoButton)); | 309 : WebPointerProperties::Button::NoButton)); |
| 310 | 310 |
| 311 pointerEventInit.setView(view); | 311 pointerEventInit.setView(view); |
| 312 updateTouchPointerEventInit(touchPoint, targetFrame, &pointerEventInit); | 312 updateTouchPointerEventInit(touchPoint, targetFrame, &pointerEventInit); |
| 313 | 313 |
| 314 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); | 314 UIEventWithKeyState::setFromWebInputEventModifiers(pointerEventInit, |
| 315 modifiers); |
| 315 | 316 |
| 316 setEventSpecificFields(pointerEventInit, type); | 317 setEventSpecificFields(pointerEventInit, type); |
| 317 | 318 |
| 318 if (type == EventTypeNames::pointermove) { | 319 if (type == EventTypeNames::pointermove) { |
| 319 HeapVector<Member<PointerEvent>> coalescedPointerEvents; | 320 HeapVector<Member<PointerEvent>> coalescedPointerEvents; |
| 320 for (const auto& coalescedTouchPoint : coalescedPoints) { | 321 for (const auto& coalescedTouchPoint : coalescedPoints) { |
| 321 DCHECK_EQ(touchPoint.state(), coalescedTouchPoint.state()); | 322 DCHECK_EQ(touchPoint.state, coalescedTouchPoint.state); |
| 322 DCHECK_EQ(touchPoint.pointerProperties().id, | 323 DCHECK_EQ(touchPoint.id, coalescedTouchPoint.id); |
| 323 coalescedTouchPoint.pointerProperties().id); | 324 DCHECK_EQ(touchPoint.pointerType, coalescedTouchPoint.pointerType); |
| 324 DCHECK_EQ(touchPoint.pointerProperties().pointerType, | |
| 325 coalescedTouchPoint.pointerProperties().pointerType); | |
| 326 PointerEventInit coalescedEventInit = pointerEventInit; | 325 PointerEventInit coalescedEventInit = pointerEventInit; |
| 327 updateTouchPointerEventInit(coalescedTouchPoint, targetFrame, | 326 updateTouchPointerEventInit(coalescedTouchPoint, targetFrame, |
| 328 &coalescedEventInit); | 327 &coalescedEventInit); |
| 329 coalescedPointerEvents.push_back( | 328 coalescedPointerEvents.push_back( |
| 330 PointerEvent::create(type, coalescedEventInit)); | 329 PointerEvent::create(type, coalescedEventInit)); |
| 331 } | 330 } |
| 332 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); | 331 pointerEventInit.setCoalescedEvents(coalescedPointerEvents); |
| 333 } | 332 } |
| 334 | 333 |
| 335 return PointerEvent::create(type, pointerEventInit); | 334 return PointerEvent::create(type, pointerEventInit); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 const WebPointerProperties& properties) const { | 520 const WebPointerProperties& properties) const { |
| 522 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) | 521 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) |
| 523 return PointerEventFactory::s_mouseId; | 522 return PointerEventFactory::s_mouseId; |
| 524 IncomingId id(properties.pointerType, properties.id); | 523 IncomingId id(properties.pointerType, properties.id); |
| 525 if (m_pointerIncomingIdMapping.contains(id)) | 524 if (m_pointerIncomingIdMapping.contains(id)) |
| 526 return m_pointerIncomingIdMapping.get(id); | 525 return m_pointerIncomingIdMapping.get(id); |
| 527 return PointerEventFactory::s_invalidId; | 526 return PointerEventFactory::s_invalidId; |
| 528 } | 527 } |
| 529 | 528 |
| 530 } // namespace blink | 529 } // namespace blink |
| OLD | NEW |