PointerEventIOS.cpp [plain text]
#import "config.h"
#import "PointerEvent.h"
#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
#import "EventNames.h"
namespace WebCore {
static const AtomString& pointerEventType(PlatformTouchPoint::TouchPhaseType phase)
{
switch (phase) {
case PlatformTouchPoint::TouchPhaseBegan:
return eventNames().pointerdownEvent;
case PlatformTouchPoint::TouchPhaseMoved:
return eventNames().pointermoveEvent;
case PlatformTouchPoint::TouchPhaseStationary:
return eventNames().pointermoveEvent;
case PlatformTouchPoint::TouchPhaseEnded:
return eventNames().pointerupEvent;
case PlatformTouchPoint::TouchPhaseCancelled:
return eventNames().pointercancelEvent;
}
ASSERT_NOT_REACHED();
return nullAtom();
}
static short buttonForType(const AtomString& type)
{
return type == eventNames().pointermoveEvent ? -1 : 0;
}
static unsigned short buttonsForType(const AtomString& type)
{
return (type == eventNames().pointerupEvent || type == eventNames().pointeroutEvent || type == eventNames().pointerleaveEvent || type == eventNames().pointercancelEvent) ? 0 : 1;
}
Ref<PointerEvent> PointerEvent::create(const PlatformTouchEvent& event, unsigned index, bool isPrimary, Ref<WindowProxy>&& view)
{
const auto& type = pointerEventType(event.touchPhaseAtIndex(index));
return adoptRef(*new PointerEvent(type, event, typeIsCancelable(type), index, isPrimary, WTFMove(view)));
}
Ref<PointerEvent> PointerEvent::create(const String& type, const PlatformTouchEvent& event, unsigned index, bool isPrimary, Ref<WindowProxy>&& view)
{
return adoptRef(*new PointerEvent(type, event, typeIsCancelable(type), index, isPrimary, WTFMove(view)));
}
PointerEvent::PointerEvent(const AtomString& type, const PlatformTouchEvent& event, IsCancelable isCancelable, unsigned index, bool isPrimary, Ref<WindowProxy>&& view)
: MouseEvent(type, typeCanBubble(type), isCancelable, typeIsComposed(type), event.timestamp().approximateMonotonicTime(), WTFMove(view), 0, event.touchLocationAtIndex(index), event.touchLocationAtIndex(index), { }, event.modifiers(), buttonForType(type), buttonsForType(type), nullptr, 0, 0, IsSimulated::No, IsTrusted::Yes)
, m_pointerId(event.touchIdentifierAtIndex(index))
, m_width(2 * event.radiusXAtIndex(index))
, m_height(2 * event.radiusYAtIndex(index))
, m_pressure(event.forceAtIndex(index))
, m_pointerType(event.touchTypeAtIndex(index) == PlatformTouchPoint::TouchType::Stylus ? PointerEvent::penPointerType() : PointerEvent::touchPointerType())
, m_isPrimary(isPrimary)
{
double azimuthAngle = event.azimuthAngleAtIndex(index);
double altitudeAngle = event.altitudeAngleAtIndex(index);
m_tiltX = round(cos(azimuthAngle) * cos(altitudeAngle) * 90);
m_tiltY = round(sin(azimuthAngle) * cos(altitudeAngle) * 90);
}
}
#endif // ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)