| 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 namespace blink { | 7 namespace blink { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. | 55 // Mouse id is 1 to behave the same as MS Edge for compatibility reasons. |
| 56 const int PointerEventFactory::s_mouseId = 1; | 56 const int PointerEventFactory::s_mouseId = 1; |
| 57 | 57 |
| 58 float getPointerEventPressure(float force, int buttons) | 58 float getPointerEventPressure(float force, int buttons) |
| 59 { | 59 { |
| 60 if (std::isnan(force)) | 60 if (std::isnan(force)) |
| 61 return buttons ? 0.5 : 0; | 61 return buttons ? 0.5 : 0; |
| 62 return force; | 62 return force; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void PointerEventFactory::setIdTypeButtons(PointerEventInit &pointerEventInit, | 65 bool PointerEventFactory::setIdTypeButtons(PointerEventInit &pointerEventInit, |
| 66 const WebPointerProperties &pointerProperties, unsigned buttons) | 66 const WebPointerProperties &pointerProperties, unsigned buttons) |
| 67 { | 67 { |
| 68 const WebPointerProperties::PointerType pointerType = pointerProperties.poin
terType; | 68 const WebPointerProperties::PointerType pointerType = pointerProperties.poin
terType; |
| 69 const IncomingId incomingId(pointerType, pointerProperties.id); | 69 const IncomingId incomingId(pointerType, pointerProperties.id); |
| 70 int previousCurrentId = m_currentId; |
| 70 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); | 71 int pointerId = addIdAndActiveButtons(incomingId, buttons != 0); |
| 71 | 72 |
| 72 pointerEventInit.setButtons(buttons); | 73 pointerEventInit.setButtons(buttons); |
| 73 pointerEventInit.setPointerId(pointerId); | 74 pointerEventInit.setPointerId(pointerId); |
| 74 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe
rType)); | 75 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe
rType)); |
| 75 pointerEventInit.setIsPrimary(isPrimary(pointerId)); | 76 pointerEventInit.setIsPrimary(isPrimary(pointerId)); |
| 77 |
| 78 return previousCurrentId != m_currentId; |
| 76 } | 79 } |
| 77 | 80 |
| 78 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactory::create( | 81 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactory::create( |
| 79 const AtomicString& mouseEventName, const PlatformMouseEvent& mouseEvent, | 82 const AtomicString& mouseEventName, const PlatformMouseEvent& mouseEvent, |
| 80 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, | 83 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, |
| 81 PassRefPtrWillBeRawPtr<AbstractView> view) | 84 PassRefPtrWillBeRawPtr<AbstractView> view) |
| 82 { | 85 { |
| 83 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent
Name); | 86 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent
Name); |
| 84 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi
fiers()); | 87 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi
fiers()); |
| 85 PointerEventInit pointerEventInit; | 88 PointerEventInit pointerEventInit; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 pointerEventInit.setView(view); | 124 pointerEventInit.setView(view); |
| 122 if (relatedTarget) | 125 if (relatedTarget) |
| 123 pointerEventInit.setRelatedTarget(relatedTarget); | 126 pointerEventInit.setRelatedTarget(relatedTarget); |
| 124 | 127 |
| 125 return PointerEvent::create(pointerEventName, pointerEventInit); | 128 return PointerEvent::create(pointerEventName, pointerEventInit); |
| 126 } | 129 } |
| 127 | 130 |
| 128 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactory::create(const AtomicStr
ing& type, | 131 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactory::create(const AtomicStr
ing& type, |
| 129 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers, | 132 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers, |
| 130 const double width, const double height, | 133 const double width, const double height, |
| 131 const double clientX, const double clientY) | 134 const double clientX, const double clientY, bool &isNew) |
| 132 { | 135 { |
| 133 const PlatformTouchPoint::TouchState pointState = touchPoint.state(); | 136 const PlatformTouchPoint::TouchState pointState = touchPoint.state(); |
| 134 | 137 |
| 135 bool pointerReleasedOrCancelled = | 138 bool pointerReleasedOrCancelled = |
| 136 pointState == PlatformTouchPoint::TouchReleased | 139 pointState == PlatformTouchPoint::TouchReleased |
| 137 || pointState == PlatformTouchPoint::TouchCancelled; | 140 || pointState == PlatformTouchPoint::TouchCancelled; |
| 138 bool pointerPressedOrReleased = | 141 bool pointerPressedOrReleased = |
| 139 pointState == PlatformTouchPoint::TouchPressed | 142 pointState == PlatformTouchPoint::TouchPressed |
| 140 || pointState == PlatformTouchPoint::TouchReleased; | 143 || pointState == PlatformTouchPoint::TouchReleased; |
| 141 | 144 |
| 142 bool isEnterOrLeave = false; | 145 bool isEnterOrLeave = false; |
| 143 | 146 |
| 144 PointerEventInit pointerEventInit; | 147 PointerEventInit pointerEventInit; |
| 145 | 148 |
| 146 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), | 149 isNew = setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), |
| 147 pointerReleasedOrCancelled ? 0 : 1); | 150 pointerReleasedOrCancelled ? 0 : 1); |
| 148 | 151 |
| 149 pointerEventInit.setWidth(width); | 152 pointerEventInit.setWidth(width); |
| 150 pointerEventInit.setHeight(height); | 153 pointerEventInit.setHeight(height); |
| 151 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); | 154 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); |
| 152 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); | 155 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); |
| 153 pointerEventInit.setScreenX(touchPoint.screenPos().x()); | 156 pointerEventInit.setScreenX(touchPoint.screenPos().x()); |
| 154 pointerEventInit.setScreenY(touchPoint.screenPos().y()); | 157 pointerEventInit.setScreenY(touchPoint.screenPos().y()); |
| 155 pointerEventInit.setClientX(clientX); | 158 pointerEventInit.setClientX(clientX); |
| 156 pointerEventInit.setClientY(clientY); | 159 pointerEventInit.setClientY(clientY); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 return m_pointerIdMapping.contains(pointerId); | 324 return m_pointerIdMapping.contains(pointerId); |
| 322 } | 325 } |
| 323 | 326 |
| 324 bool PointerEventFactory::isActiveButtonsState(const int pointerId) | 327 bool PointerEventFactory::isActiveButtonsState(const int pointerId) |
| 325 { | 328 { |
| 326 return m_pointerIdMapping.contains(pointerId) | 329 return m_pointerIdMapping.contains(pointerId) |
| 327 && m_pointerIdMapping.get(pointerId).isActiveButtons; | 330 && m_pointerIdMapping.get(pointerId).isActiveButtons; |
| 328 } | 331 } |
| 329 | 332 |
| 330 } // namespace blink | 333 } // namespace blink |
| OLD | NEW |