Changeset 205766 in webkit


Ignore:
Timestamp:
Sep 9, 2016 1:57:50 PM (8 years ago)
Author:
dino@apple.com
Message:

Expose Apple Pencil data to Touch events
https://bugs.webkit.org/show_bug.cgi?id=161783
<rdar://problem/28218898>

Reviewed by Beth Dakin.

Source/WebKit2:

  • Platform/spi/ios/UIKitSPI.h: Expose the new SPI. Since this is only used

on public builds, guard it against everything that is <= iOS 10.0.

  • Shared/WebEvent.h: New properties.

(WebKit::WebPlatformTouchPoint::setAltitudeAngle):
(WebKit::WebPlatformTouchPoint::altitudeAngle):
(WebKit::WebPlatformTouchPoint::setAzimuthAngle):
(WebKit::WebPlatformTouchPoint::azimuthAngle):
(WebKit::WebPlatformTouchPoint::setTouchType):
(WebKit::WebPlatformTouchPoint::touchType):
(WebKit::WebPlatformTouchPoint::force): Deleted.

  • Shared/WebEventConversion.cpp:

(WebKit::webPlatformTouchTypeToPlatform):
(WebKit::WebKit2PlatformTouchPoint::WebKit2PlatformTouchPoint): More
parameters sent to parent constructor.

  • Shared/ios/NativeWebTouchEventIOS.mm:

(WebKit::convertTouchType):
(WebKit::NativeWebTouchEvent::extractWebTouchPoint):

  • Shared/ios/WebPlatformTouchPointIOS.cpp:

(WebKit::WebPlatformTouchPoint::encode):
(WebKit::WebPlatformTouchPoint::decode):

Tools:

The values that IOHID expects are different from their
documentation, and from what UITouch interprets. Tweak
incoming data so it will produce the output we expect.

  • WebKitTestRunner/ios/HIDEventGenerator.mm:

(-[HIDEventGenerator stylusDownAtPoint:azimuthAngle:altitudeAngle:pressure:]):
(-[HIDEventGenerator stylusMoveToPoint:azimuthAngle:altitudeAngle:pressure:]):

LayoutTests:

Four new tests that check data coming out of an Apple Pencil.

  • fast/events/touch/ios/pencil-data-change-does-not-give-touchmove-expected.txt: Added.
  • fast/events/touch/ios/pencil-data-change-does-not-give-touchmove.html: Added.
  • fast/events/touch/ios/pencil-data-change-gives-touchforcechange-expected.txt: Added.
  • fast/events/touch/ios/pencil-data-change-gives-touchforcechange.html: Added.
  • fast/events/touch/ios/pencil-move-provides-stylus-data-expected.txt: Added.
  • fast/events/touch/ios/pencil-move-provides-stylus-data.html: Added.
  • fast/events/touch/ios/pencil-touch-registered-as-pencil-expected.txt: Added.
  • fast/events/touch/ios/pencil-touch-registered-as-pencil.html: Added.
Location:
trunk
Files:
8 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205765 r205766  
     12016-09-08  Dean Jackson  <dino@apple.com>
     2
     3        Expose Apple Pencil data to Touch events
     4        https://bugs.webkit.org/show_bug.cgi?id=161783
     5        <rdar://problem/28218898>
     6
     7        Reviewed by Beth Dakin.
     8
     9        Four new tests that check data coming out of an Apple Pencil.
     10
     11        * fast/events/touch/ios/pencil-data-change-does-not-give-touchmove-expected.txt: Added.
     12        * fast/events/touch/ios/pencil-data-change-does-not-give-touchmove.html: Added.
     13        * fast/events/touch/ios/pencil-data-change-gives-touchforcechange-expected.txt: Added.
     14        * fast/events/touch/ios/pencil-data-change-gives-touchforcechange.html: Added.
     15        * fast/events/touch/ios/pencil-move-provides-stylus-data-expected.txt: Added.
     16        * fast/events/touch/ios/pencil-move-provides-stylus-data.html: Added.
     17        * fast/events/touch/ios/pencil-touch-registered-as-pencil-expected.txt: Added.
     18        * fast/events/touch/ios/pencil-touch-registered-as-pencil.html: Added.
     19
    1202016-09-09  Tim Horton  <timothy_horton@apple.com>
    221
  • trunk/Source/WebKit2/ChangeLog

    r205765 r205766  
     12016-09-08  Dean Jackson  <dino@apple.com>
     2
     3        Expose Apple Pencil data to Touch events
     4        https://bugs.webkit.org/show_bug.cgi?id=161783
     5        <rdar://problem/28218898>
     6
     7        Reviewed by Beth Dakin.
     8
     9        * Platform/spi/ios/UIKitSPI.h: Expose the new SPI. Since this is only used
     10        on public builds, guard it against everything that is <= iOS 10.0.
     11        * Shared/WebEvent.h: New properties.
     12        (WebKit::WebPlatformTouchPoint::setAltitudeAngle):
     13        (WebKit::WebPlatformTouchPoint::altitudeAngle):
     14        (WebKit::WebPlatformTouchPoint::setAzimuthAngle):
     15        (WebKit::WebPlatformTouchPoint::azimuthAngle):
     16        (WebKit::WebPlatformTouchPoint::setTouchType):
     17        (WebKit::WebPlatformTouchPoint::touchType):
     18        (WebKit::WebPlatformTouchPoint::force): Deleted.
     19        * Shared/WebEventConversion.cpp:
     20        (WebKit::webPlatformTouchTypeToPlatform):
     21        (WebKit::WebKit2PlatformTouchPoint::WebKit2PlatformTouchPoint): More
     22        parameters sent to parent constructor.
     23        * Shared/ios/NativeWebTouchEventIOS.mm:
     24        (WebKit::convertTouchType):
     25        (WebKit::NativeWebTouchEvent::extractWebTouchPoint):
     26        * Shared/ios/WebPlatformTouchPointIOS.cpp:
     27        (WebKit::WebPlatformTouchPoint::encode):
     28        (WebKit::WebPlatformTouchPoint::decode):
     29
    1302016-09-09  Tim Horton  <timothy_horton@apple.com>
    231
  • trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h

    r205531 r205766  
    644644} UIWebTouchEventType;
    645645
     646typedef enum {
     647    UIWebTouchPointTypeDirect = 0,
     648    UIWebTouchPointTypeStylus
     649} UIWebTouchPointType;
     650
    646651struct _UIWebTouchPoint {
    647652    CGPoint locationInScreenCoordinates;
     
    649654    unsigned identifier;
    650655    UITouchPhase phase;
    651     CGFloat majorRadiusInScreenCoordinates;
     656#if __IPHONE_OS_VERSION_MIN_REQUIRED > 100000
     657    CGFloat force;
     658    CGFloat altitudeAngle;
     659    CGFloat azimuthAngle;
     660    UIWebTouchPointType touchType;
     661#endif
    652662};
    653663
  • trunk/Source/WebKit2/Shared/WebEvent.h

    r204668 r205766  
    307307    };
    308308
     309    enum class TouchType {
     310        Direct,
     311        Stylus
     312    };
     313
    309314    WebPlatformTouchPoint() { }
    310315    WebPlatformTouchPoint(unsigned identifier, WebCore::IntPoint location, TouchPointState phase)
     
    323328    void setForce(double force) { m_force = force; }
    324329    double force() const { return m_force; }
     330    void setAltitudeAngle(double altitudeAngle) { m_altitudeAngle = altitudeAngle; }
     331    double altitudeAngle() const { return m_altitudeAngle; }
     332    void setAzimuthAngle(double azimuthAngle) { m_azimuthAngle = azimuthAngle; }
     333    double azimuthAngle() const { return m_azimuthAngle; }
     334    void setTouchType(TouchType touchType) { m_touchType = static_cast<uint32_t>(touchType); }
     335    TouchType touchType() const { return static_cast<TouchType>(m_touchType); }
    325336#endif
    326337
     
    334345#if ENABLE(IOS_TOUCH_EVENTS)
    335346    double m_force { 0 };
     347    double m_altitudeAngle { 0 };
     348    double m_azimuthAngle { 0 };
     349    uint32_t m_touchType { static_cast<uint32_t>(TouchType::Direct) };
    336350#endif
    337351};
  • trunk/Source/WebKit2/Shared/WebEventConversion.cpp

    r191299 r205766  
    244244}
    245245
     246static WebCore::PlatformTouchPoint::TouchType webPlatformTouchTypeToPlatform(const WebPlatformTouchPoint::TouchType& webTouchType)
     247{
     248    switch (webTouchType) {
     249    case WebPlatformTouchPoint::TouchType::Direct:
     250        return WebCore::PlatformTouchPoint::TouchType::Direct;
     251    case WebPlatformTouchPoint::TouchType::Stylus:
     252        return WebCore::PlatformTouchPoint::TouchType::Stylus;
     253    }
     254}
     255
    246256class WebKit2PlatformTouchPoint : public WebCore::PlatformTouchPoint {
    247257public:
     
    249259    : PlatformTouchPoint(webTouchPoint.identifier(), webTouchPoint.location(), touchEventType(webTouchPoint)
    250260#if ENABLE(IOS_TOUCH_EVENTS)
    251     , webTouchPoint.force()
     261        , webTouchPoint.force(), webTouchPoint.altitudeAngle(), webTouchPoint.azimuthAngle(), webPlatformTouchTypeToPlatform(webTouchPoint.touchType())
    252262#endif
    253263    )
  • trunk/Source/WebKit2/Shared/ios/NativeWebTouchEventIOS.mm

    r190841 r205766  
    7171}
    7272
     73#if defined UI_WEB_TOUCH_EVENT_HAS_STYLUS_DATA && UI_WEB_TOUCH_EVENT_HAS_STYLUS_DATA
     74static WebPlatformTouchPoint::TouchType convertTouchType(UIWebTouchPointType touchType)
     75{
     76    switch (touchType) {
     77    case UIWebTouchPointTypeDirect:
     78        return WebPlatformTouchPoint::TouchType::Direct;
     79    case UIWebTouchPointTypeStylus:
     80        return WebPlatformTouchPoint::TouchType::Stylus;
     81    default:
     82        ASSERT_NOT_REACHED();
     83        return WebPlatformTouchPoint::TouchType::Direct;
     84    }
     85}
     86#endif
     87
    7388static inline WebCore::IntPoint positionForCGPoint(CGPoint position)
    7489{
     
    90105#if ENABLE(IOS_TOUCH_EVENTS)
    91106        platformTouchPoint.setForce(touchPoint.force);
     107#if defined UI_WEB_TOUCH_EVENT_HAS_STYLUS_DATA && UI_WEB_TOUCH_EVENT_HAS_STYLUS_DATA
     108        platformTouchPoint.setAltitudeAngle(touchPoint.altitudeAngle);
     109        platformTouchPoint.setAzimuthAngle(touchPoint.azimuthAngle);
     110        platformTouchPoint.setTouchType(convertTouchType(touchPoint.touchType));
     111#endif
    92112#endif
    93113        touchPointList.uncheckedAppend(platformTouchPoint);
  • trunk/Source/WebKit2/Shared/ios/WebPlatformTouchPointIOS.cpp

    r204743 r205766  
    4242#if ENABLE(IOS_TOUCH_EVENTS)
    4343    encoder << m_force;
     44    encoder << m_altitudeAngle;
     45    encoder << m_azimuthAngle;
     46    encoder << m_touchType;
    4447#endif
    4548}
     
    5659    if (!decoder.decode(result.m_force))
    5760        return false;
     61    if (!decoder.decode(result.m_altitudeAngle))
     62        return false;
     63    if (!decoder.decode(result.m_azimuthAngle))
     64        return false;
     65    if (!decoder.decode(result.m_touchType))
     66        return false;
    5867#endif
    5968    return true;
  • trunk/Tools/ChangeLog

    r205764 r205766  
     12016-09-08  Dean Jackson  <dino@apple.com>
     2
     3        Expose Apple Pencil data to Touch events
     4        https://bugs.webkit.org/show_bug.cgi?id=161783
     5        <rdar://problem/28218898>
     6
     7        Reviewed by Beth Dakin.
     8
     9        The values that IOHID expects are different from their
     10        documentation, and from what UITouch interprets. Tweak
     11        incoming data so it will produce the output we expect.
     12
     13        * WebKitTestRunner/ios/HIDEventGenerator.mm:
     14        (-[HIDEventGenerator stylusDownAtPoint:azimuthAngle:altitudeAngle:pressure:]):
     15        (-[HIDEventGenerator stylusMoveToPoint:azimuthAngle:altitudeAngle:pressure:]):
     16
    1172016-09-09  JF Bastien  <jfbastien@apple.com>
    218
  • trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm

    r205585 r205766  
    435435    _activePoints[0].point = location;
    436436    _activePoints[0].isStylus = YES;
    437     _activePoints[0].pathPressure = pressure;
    438     _activePoints[0].azimuthAngle = azimuthAngle;
    439     _activePoints[0].altitudeAngle = altitudeAngle;
     437
     438    // At the time of writing, the IOKit documentation isn't always correct. For example
     439    // it says that pressure is a value [0,1], but in practice it is [0,500] for stylus
     440    // data. It does not mention that the azimuth angle is offset from a full rotation.
     441    // Also, UIKit and IOHID interpret the altitude as different adjacent angles.
     442    _activePoints[0].pathPressure = pressure * 500;
     443    _activePoints[0].azimuthAngle = M_PI * 2 - azimuthAngle;
     444    _activePoints[0].altitudeAngle = M_PI_2 - altitudeAngle;
    440445
    441446    RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:StylusEventTouched]);
     
    448453    _activePoints[0].point = location;
    449454    _activePoints[0].isStylus = YES;
    450     _activePoints[0].pathPressure = pressure;
    451     _activePoints[0].azimuthAngle = azimuthAngle;
    452     _activePoints[0].altitudeAngle = altitudeAngle;
     455    // See notes above for details on these calculations.
     456    _activePoints[0].pathPressure = pressure * 500;
     457    _activePoints[0].azimuthAngle = M_PI * 2 - azimuthAngle;
     458    _activePoints[0].altitudeAngle = M_PI_2 - altitudeAngle;
    453459
    454460    RetainPtr<IOHIDEventRef> eventRef = adoptCF([self _createIOHIDEventType:StylusEventMoved]);
Note: See TracChangeset for help on using the changeset viewer.