| 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 "platform/geometry/FloatSize.h" |
| 8 |
| 7 namespace blink { | 9 namespace blink { |
| 8 | 10 |
| 9 namespace { | 11 namespace { |
| 10 | 12 |
| 11 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>(
t); } | 13 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>(
t); } |
| 12 | 14 |
| 13 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT
ype type) | 15 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT
ype type) |
| 14 { | 16 { |
| 15 switch (type) { | 17 switch (type) { |
| 16 case WebPointerProperties::PointerType::Unknown: | 18 case WebPointerProperties::PointerType::Unknown: |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 125 |
| 124 pointerEventInit.setView(view); | 126 pointerEventInit.setView(view); |
| 125 if (relatedTarget) | 127 if (relatedTarget) |
| 126 pointerEventInit.setRelatedTarget(relatedTarget); | 128 pointerEventInit.setRelatedTarget(relatedTarget); |
| 127 | 129 |
| 128 return PointerEvent::create(pointerEventName, pointerEventInit); | 130 return PointerEvent::create(pointerEventName, pointerEventInit); |
| 129 } | 131 } |
| 130 | 132 |
| 131 PointerEvent* PointerEventFactory::create(const AtomicString& type, | 133 PointerEvent* PointerEventFactory::create(const AtomicString& type, |
| 132 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers, | 134 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers, |
| 133 const double width, const double height, | 135 const FloatSize& pointRadius, |
| 134 const double clientX, const double clientY) | 136 const FloatPoint& pagePoint) |
| 135 { | 137 { |
| 136 const PlatformTouchPoint::TouchState pointState = touchPoint.state(); | 138 const PlatformTouchPoint::TouchState pointState = touchPoint.state(); |
| 137 | 139 |
| 138 bool pointerReleasedOrCancelled = | 140 bool pointerReleasedOrCancelled = |
| 139 pointState == PlatformTouchPoint::TouchReleased | 141 pointState == PlatformTouchPoint::TouchReleased |
| 140 || pointState == PlatformTouchPoint::TouchCancelled; | 142 || pointState == PlatformTouchPoint::TouchCancelled; |
| 141 bool pointerPressedOrReleased = | 143 bool pointerPressedOrReleased = |
| 142 pointState == PlatformTouchPoint::TouchPressed | 144 pointState == PlatformTouchPoint::TouchPressed |
| 143 || pointState == PlatformTouchPoint::TouchReleased; | 145 || pointState == PlatformTouchPoint::TouchReleased; |
| 144 | 146 |
| 145 bool isEnterOrLeave = false; | 147 bool isEnterOrLeave = false; |
| 146 | 148 |
| 147 PointerEventInit pointerEventInit; | 149 PointerEventInit pointerEventInit; |
| 148 | 150 |
| 149 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), | 151 setIdTypeButtons(pointerEventInit, touchPoint.pointerProperties(), |
| 150 pointerReleasedOrCancelled ? 0 : 1); | 152 pointerReleasedOrCancelled ? 0 : 1); |
| 151 | 153 |
| 152 pointerEventInit.setWidth(width); | 154 pointerEventInit.setWidth(pointRadius.width()); |
| 153 pointerEventInit.setHeight(height); | 155 pointerEventInit.setHeight(pointRadius.height()); |
| 154 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); | 156 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX); |
| 155 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); | 157 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY); |
| 156 pointerEventInit.setScreenX(touchPoint.screenPos().x()); | 158 pointerEventInit.setScreenX(touchPoint.screenPos().x()); |
| 157 pointerEventInit.setScreenY(touchPoint.screenPos().y()); | 159 pointerEventInit.setScreenY(touchPoint.screenPos().y()); |
| 158 pointerEventInit.setClientX(clientX); | 160 pointerEventInit.setClientX(pagePoint.x()); |
| 159 pointerEventInit.setClientY(clientY); | 161 pointerEventInit.setClientY(pagePoint.y()); |
| 160 pointerEventInit.setButton(pointerPressedOrReleased ? LeftButton: NoButton); | 162 pointerEventInit.setButton(pointerPressedOrReleased ? LeftButton: NoButton); |
| 161 pointerEventInit.setPressure(getPointerEventPressure( | 163 pointerEventInit.setPressure(getPointerEventPressure( |
| 162 touchPoint.force(), pointerEventInit.buttons())); | 164 touchPoint.force(), pointerEventInit.buttons())); |
| 163 | 165 |
| 164 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); | 166 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers); |
| 165 | 167 |
| 166 pointerEventInit.setBubbles(!isEnterOrLeave); | 168 pointerEventInit.setBubbles(!isEnterOrLeave); |
| 167 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc
hPoint::TouchCancelled); | 169 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc
hPoint::TouchCancelled); |
| 168 | 170 |
| 169 return PointerEvent::create(type, pointerEventInit); | 171 return PointerEvent::create(type, pointerEventInit); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 { | 349 { |
| 348 return m_pointerIdMapping.contains(pointerId); | 350 return m_pointerIdMapping.contains(pointerId); |
| 349 } | 351 } |
| 350 | 352 |
| 351 bool PointerEventFactory::isActiveButtonsState(const int pointerId) | 353 bool PointerEventFactory::isActiveButtonsState(const int pointerId) |
| 352 { | 354 { |
| 353 return m_pointerIdMapping.contains(pointerId) | 355 return m_pointerIdMapping.contains(pointerId) |
| 354 && m_pointerIdMapping.get(pointerId).isActiveButtons; | 356 && m_pointerIdMapping.get(pointerId).isActiveButtons; |
| 355 } | 357 } |
| 356 | 358 |
| 359 int PointerEventFactory::getPointerEventId( |
| 360 const WebPointerProperties& properties) |
| 361 { |
| 362 if (properties.pointerType |
| 363 == WebPointerProperties::PointerType::Mouse) |
| 364 return PointerEventFactory::s_mouseId; |
| 365 IncomingId id(properties.pointerType, properties.id); |
| 366 if (m_pointerIncomingIdMapping.contains(id)) |
| 367 return m_pointerIncomingIdMapping.get(id); |
| 368 return PointerEventFactory::s_invalidId; |
| 369 } |
| 370 |
| 357 } // namespace blink | 371 } // namespace blink |
| OLD | NEW |