⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243645 in webkit


Ignore:
Timestamp:
Mar 29, 2019, 8:54:02 AM (7 years ago)
Author:
graouts@webkit.org
Message:

All PointerEvent.isTrusted is always false.
https://bugs.webkit.org/show_bug.cgi?id=196075
<rdar://problem/49158778>

Reviewed by Chris Dumez.

Source/WebCore:

Test: pointerevents/ios/pointer-events-is-trusted.html

The constructors we were using for some PointerEvent::create() methods were using initializers which are expected to be used with JS APIs
and thus generate untrusted events. We switch to using constructors using dedicated parameters which will set isTrusted to true.

  • dom/PointerEvent.cpp:

(WebCore::PointerEvent::create):
(WebCore::PointerEvent::createPointerCancelEvent):
(WebCore::PointerEvent::PointerEvent):
(WebCore::m_isPrimary):
(WebCore::m_pointerType):

  • dom/PointerEvent.h:
  • page/PointerCaptureController.cpp:

(WebCore::PointerCaptureController::cancelPointer):

LayoutTests:

Add tests to the macOS and iOS series of tests that check that isTrusted is indeed true. This uncovered a couple of issues with how some tests were written.

  • pointerevents/ios/pointer-events-is-primary.html: Ensure we end both touches so that further tests run cleanly.
  • pointerevents/ios/pointer-events-is-trusted-expected.txt: Added.
  • pointerevents/ios/pointer-events-is-trusted.html: Added.
  • pointerevents/mouse/pointer-event-basic-properties.html: Ensure we wait for the event to be handled before finishing the test.
  • pointerevents/utils.js:

(prototype._handlePointerEvent):

Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243643 r243645  
     12019-03-28  Antoine Quint  <graouts@apple.com>
     2
     3        All PointerEvent.isTrusted is always false.
     4        https://bugs.webkit.org/show_bug.cgi?id=196075
     5        <rdar://problem/49158778>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Add tests to the macOS and iOS series of tests that check that isTrusted is indeed true. This uncovered a couple of issues with how some tests were written.
     10
     11        * pointerevents/ios/pointer-events-is-primary.html: Ensure we end both touches so that further tests run cleanly.
     12        * pointerevents/ios/pointer-events-is-trusted-expected.txt: Added.
     13        * pointerevents/ios/pointer-events-is-trusted.html: Added.
     14        * pointerevents/mouse/pointer-event-basic-properties.html: Ensure we wait for the event to be handled before finishing the test.
     15        * pointerevents/utils.js:
     16        (prototype._handlePointerEvent):
     17
    1182019-03-29  Cathie Chen  <cathiechen@igalia.com>
    219
  • trunk/LayoutTests/pointerevents/ios/pointer-events-is-primary.html

    r240875 r243645  
    2525        one.move({ x: 30, y: 30 }),
    2626        one.end(),
    27         two.move({ x: 50, y: 50 })
     27        two.move({ x: 50, y: 50 }),
     28        two.end()
    2829    ]).then(() => {
    2930        eventTracker.assertMatchesEvents([
  • trunk/LayoutTests/pointerevents/mouse/pointer-event-basic-properties.html

    r242137 r243645  
    1313
    1414target_test((target, test) => {
    15     eventSender.mouseMoveTo(50, 50);
    16     eventSender.mouseDown();
    17 
    1815    target.addEventListener("pointerdown", event => {
    1916        assert_equals(event.pointerId, 1, "The pointer's identifier is 1.");
    2017        assert_equals(event.pointerType, "mouse", "The pointer type is 'mouse'.");
    2118        assert_true(event.isPrimary, "The pointer is the primary pointer.");
     19        assert_true(event.isTrusted, "The event is trusted.");
     20        test.done();
    2221    });
    2322
    24     test.done();
     23    eventSender.mouseMoveTo(50, 50);
     24    eventSender.mouseDown();
    2525}, `Testing the basic properties of a pointer event triggered by a mouse.`);
    2626
  • trunk/LayoutTests/pointerevents/utils.js

    r242137 r243645  
    6868            x: event.clientX,
    6969            y: event.clientY,
    70             isPrimary: event.isPrimary
     70            isPrimary: event.isPrimary,
     71            isTrusted: event.isTrusted
    7172        });
    7273    }
  • trunk/Source/WebCore/ChangeLog

    r243644 r243645  
     12019-03-28  Antoine Quint  <graouts@apple.com>
     2
     3        All PointerEvent.isTrusted is always false.
     4        https://bugs.webkit.org/show_bug.cgi?id=196075
     5        <rdar://problem/49158778>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Test: pointerevents/ios/pointer-events-is-trusted.html
     10
     11        The constructors we were using for some PointerEvent::create() methods were using initializers which are expected to be used with JS APIs
     12        and thus generate untrusted events. We switch to using constructors using dedicated parameters which will set isTrusted to true.
     13
     14        * dom/PointerEvent.cpp:
     15        (WebCore::PointerEvent::create):
     16        (WebCore::PointerEvent::createPointerCancelEvent):
     17        (WebCore::PointerEvent::PointerEvent):
     18        (WebCore::m_isPrimary):
     19        (WebCore::m_pointerType):
     20        * dom/PointerEvent.h:
     21        * page/PointerCaptureController.cpp:
     22        (WebCore::PointerCaptureController::cancelPointer):
     23
    1242019-03-29  Philippe Normand  <pnormand@igalia.com>
    225
  • trunk/Source/WebCore/dom/PointerEvent.cpp

    r242137 r243645  
    7272}
    7373
     74RefPtr<PointerEvent> PointerEvent::create(const MouseEvent& mouseEvent)
     75{
     76    auto type = pointerEventType(mouseEvent.type());
     77    if (type.isEmpty())
     78        return nullptr;
     79
     80    auto isEnterOrLeave = type == eventNames().pointerenterEvent || type == eventNames().pointerleaveEvent;
     81    auto canBubble = isEnterOrLeave ? CanBubble::No : CanBubble::Yes;
     82    auto isCancelable = isEnterOrLeave ? IsCancelable::No : IsCancelable::Yes;
     83    auto isComposed = isEnterOrLeave ? IsComposed::No : IsComposed::Yes;
     84    return adoptRef(*new PointerEvent(type, canBubble, isCancelable, isComposed, mouseEvent));
     85}
     86
     87Ref<PointerEvent> PointerEvent::createPointerCancelEvent(PointerID pointerId, const String& pointerType)
     88{
     89    return adoptRef(*new PointerEvent(eventNames().pointercancelEvent, CanBubble::Yes, IsCancelable::No, IsComposed::Yes, pointerId, pointerType));
     90}
     91
    7492PointerEvent::PointerEvent() = default;
    7593
     
    89107}
    90108
    91 RefPtr<PointerEvent> PointerEvent::create(const MouseEvent& mouseEvent)
     109PointerEvent::PointerEvent(const AtomicString& type, CanBubble canBubble, IsCancelable isCancelable, IsComposed isComposed, const MouseEvent& mouseEvent)
     110    : MouseEvent(type, canBubble, isCancelable, isComposed, mouseEvent.view(), mouseEvent.detail(), mouseEvent.screenLocation(), { mouseEvent.clientX(), mouseEvent.clientY() }, mouseEvent.modifierKeys(), mouseEvent.button(), mouseEvent.buttons(), mouseEvent.syntheticClickType(), mouseEvent.relatedTarget())
     111    , m_isPrimary(true)
    92112{
    93     auto type = pointerEventType(mouseEvent.type());
    94     if (type.isEmpty())
    95         return nullptr;
     113}
    96114
    97     auto isEnterOrLeave = type == eventNames().pointerenterEvent || type == eventNames().pointerleaveEvent;
    98 
    99     PointerEvent::Init init;
    100     init.bubbles = !isEnterOrLeave;
    101     init.cancelable = !isEnterOrLeave;
    102     init.composed = !isEnterOrLeave;
    103     init.view = mouseEvent.view();
    104     init.ctrlKey = mouseEvent.ctrlKey();
    105     init.shiftKey = mouseEvent.shiftKey();
    106     init.altKey = mouseEvent.altKey();
    107     init.metaKey = mouseEvent.metaKey();
    108     init.modifierAltGraph = mouseEvent.altGraphKey();
    109     init.modifierCapsLock = mouseEvent.capsLockKey();
    110     init.screenX = mouseEvent.screenX();
    111     init.screenY = mouseEvent.screenY();
    112     init.clientX = mouseEvent.clientX();
    113     init.clientY = mouseEvent.clientY();
    114     init.button = mouseEvent.button();
    115     init.buttons = mouseEvent.buttons();
    116     init.relatedTarget = mouseEvent.relatedTarget();
    117     init.isPrimary = true;
    118 
    119     return PointerEvent::create(type, WTFMove(init));
     115PointerEvent::PointerEvent(const AtomicString& type, CanBubble canBubble, IsCancelable isCancelable, IsComposed isComposed, PointerID pointerId, const String& pointerType)
     116    : MouseEvent(type, canBubble, isCancelable, isComposed, nullptr, 0, { }, { }, { }, 0, 0, 0, nullptr)
     117    , m_pointerId(pointerId)
     118    , m_pointerType(pointerType)
     119{
    120120}
    121121
  • trunk/Source/WebCore/dom/PointerEvent.h

    r242137 r243645  
    5858    }
    5959
    60     static Ref<PointerEvent> create(const AtomicString& type, PointerID pointerId, String pointerType)
    61     {
    62         Init initializer;
    63         initializer.bubbles = true;
    64         initializer.pointerId = pointerId;
    65         initializer.pointerType = pointerType;
    66         return adoptRef(*new PointerEvent(type, WTFMove(initializer)));
    67     }
    68 
    6960    static Ref<PointerEvent> createForPointerCapture(const AtomicString& type, const PointerEvent& pointerEvent)
    7061    {
     
    8374
    8475    static RefPtr<PointerEvent> create(const MouseEvent&);
     76    static Ref<PointerEvent> createPointerCancelEvent(PointerID, const String& pointerType);
    8577
    8678#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
     
    114106    PointerEvent();
    115107    PointerEvent(const AtomicString&, Init&&);
     108    PointerEvent(const AtomicString& type, CanBubble, IsCancelable, IsComposed, const MouseEvent&);
     109    PointerEvent(const AtomicString& type, CanBubble, IsCancelable, IsComposed, PointerID, const String& pointerType);
    116110#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
    117111    PointerEvent(const AtomicString& type, const PlatformTouchEvent&, IsCancelable isCancelable, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&);
  • trunk/Source/WebCore/page/PointerCaptureController.cpp

    r242137 r243645  
    282282        return;
    283283
    284     auto event = PointerEvent::create(eventNames().pointercancelEvent, pointerId, capturingData.pointerType);
     284    auto event = PointerEvent::createPointerCancelEvent(pointerId, capturingData.pointerType);
    285285    target->dispatchEvent(event);
    286286    processPendingPointerCapture(WTFMove(event));
Note: See TracChangeset for help on using the changeset viewer.