Changeset 207544 in webkit


Ignore:
Timestamp:
Oct 19, 2016 10:46:42 AM (8 years ago)
Author:
Chris Dumez
Message:

MouseEvent's coordinates should be 0 for simulated clicks
https://bugs.webkit.org/show_bug.cgi?id=163648

Reviewed by Darin Adler.

Source/WebCore:

MouseEvent's coordinates should be 0 / 0 for simulated clicks triggered
by JavaScript (i.e. via element.click()). This behavior matches Chrome
and Firefox.

WebKit was computing actual coordinates for the element which was
expensive, especially because computing screenX / screenY required
a synchronous IPC with the UI process.

Test: fast/events/element-click-no-coords.html

  • dom/Element.cpp:

(WebCore::Element::dispatchSimulatedClick):

  • dom/SimulatedClick.cpp:

(WebCore::simulateMouseEvent):
(WebCore::simulateClick):

  • dom/SimulatedClick.h:
  • html/HTMLElement.cpp:

(WebCore::HTMLElement::click):

LayoutTests:

Add layout test coverage. I verified that this test is passing in
Firefox and Chrome as well.

  • fast/events/element-click-no-coords-expected.txt: Added.
  • fast/events/element-click-no-coords.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r207540 r207544  
     12016-10-19  Chris Dumez  <cdumez@apple.com>
     2
     3        MouseEvent's coordinates should be 0 for simulated clicks
     4        https://bugs.webkit.org/show_bug.cgi?id=163648
     5
     6        Reviewed by Darin Adler.
     7
     8        Add layout test coverage. I verified that this test is passing in
     9        Firefox and Chrome as well.
     10
     11        * fast/events/element-click-no-coords-expected.txt: Added.
     12        * fast/events/element-click-no-coords.html: Added.
     13
    1142016-10-19  Nan Wang  <n_wang@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r207543 r207544  
     12016-10-19  Chris Dumez  <cdumez@apple.com>
     2
     3        MouseEvent's coordinates should be 0 for simulated clicks
     4        https://bugs.webkit.org/show_bug.cgi?id=163648
     5
     6        Reviewed by Darin Adler.
     7
     8        MouseEvent's coordinates should be 0 / 0 for simulated clicks triggered
     9        by JavaScript (i.e. via element.click()). This behavior matches Chrome
     10        and Firefox.
     11
     12        WebKit was computing actual coordinates for the element which was
     13        expensive, especially because computing  screenX / screenY required
     14        a synchronous IPC with the UI process.
     15
     16        Test: fast/events/element-click-no-coords.html
     17
     18        * dom/Element.cpp:
     19        (WebCore::Element::dispatchSimulatedClick):
     20        * dom/SimulatedClick.cpp:
     21        (WebCore::simulateMouseEvent):
     22        (WebCore::simulateClick):
     23        * dom/SimulatedClick.h:
     24        * html/HTMLElement.cpp:
     25        (WebCore::HTMLElement::click):
     26
    1272016-10-19  Dave Hyatt  <hyatt@apple.com>
    228
  • trunk/Source/WebCore/dom/Element.cpp

    r207521 r207544  
    336336void Element::dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions eventOptions, SimulatedClickVisualOptions visualOptions)
    337337{
    338     simulateClick(*this, underlyingEvent, eventOptions, visualOptions, SimulatedClickCreationOptions::FromUserAgent);
     338    simulateClick(*this, underlyingEvent, eventOptions, visualOptions, SimulatedClickSource::UserAgent);
    339339}
    340340
  • trunk/Source/WebCore/dom/SimulatedClick.cpp

    r204681 r207544  
    3939class SimulatedMouseEvent final : public MouseEvent {
    4040public:
    41     static Ref<SimulatedMouseEvent> create(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target)
     41    static Ref<SimulatedMouseEvent> create(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target, SimulatedClickSource source)
    4242    {
    43         return adoptRef(*new SimulatedMouseEvent(eventType, view, WTFMove(underlyingEvent), target));
     43        return adoptRef(*new SimulatedMouseEvent(eventType, view, WTFMove(underlyingEvent), target, source));
    4444    }
    4545
    4646private:
    47     SimulatedMouseEvent(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target)
     47    SimulatedMouseEvent(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target, SimulatedClickSource source)
    4848        : MouseEvent(eventType, true, true, underlyingEvent ? underlyingEvent->timeStamp() : currentTime(), view, 0, 0, 0, 0, 0,
    4949#if ENABLE(POINTER_LOCK)
     
    5252                     false, false, false, false, 0, 0, 0, 0, 0, true)
    5353    {
     54        if (source == SimulatedClickSource::Bindings)
     55            setUntrusted();
     56
    5457        if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent.get())) {
    5558            m_ctrlKey = keyStateEvent->ctrlKey();
     
    6467            m_screenLocation = mouseEvent.screenLocation();
    6568            initCoordinates(mouseEvent.clientLocation());
    66         } else {
     69        } else if (source == SimulatedClickSource::UserAgent) {
     70            // If there is no underlying event, we only populate the coordinates for events coming
     71            // from the user agent (e.g. accessibility). For those coming from JavaScript (e.g.
     72            // (element.click()), the coordinates will be 0, similarly to Firefox and Chrome.
     73            // Note that the call to screenRect() causes a synchronous IPC with the UI process.
    6774            m_screenLocation = target.screenRect().center();
    6875            initCoordinates(LayoutPoint(target.clientRect().center()));
     
    7279};
    7380
    74 static void simulateMouseEvent(const AtomicString& eventType, Element& element, Event* underlyingEvent, SimulatedClickCreationOptions creationOptions)
     81static void simulateMouseEvent(const AtomicString& eventType, Element& element, Event* underlyingEvent, SimulatedClickSource source)
    7582{
    76     auto event = SimulatedMouseEvent::create(eventType, element.document().defaultView(), underlyingEvent, element);
    77     if (creationOptions == SimulatedClickCreationOptions::FromBindings)
    78         event.get().setUntrusted();
    79     EventDispatcher::dispatchEvent(&element, event.get());
     83    auto event = SimulatedMouseEvent::create(eventType, element.document().defaultView(), underlyingEvent, element, source);
     84    EventDispatcher::dispatchEvent(&element, event);
    8085}
    8186
    82 void simulateClick(Element& element, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions, SimulatedClickCreationOptions creationOptions)
     87void simulateClick(Element& element, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions, SimulatedClickSource creationOptions)
    8388{
    8489    if (element.isDisabledFormControl())
  • trunk/Source/WebCore/dom/SimulatedClick.h

    r196598 r207544  
    3434class Event;
    3535
    36 enum class SimulatedClickCreationOptions {
    37     FromBindings,
    38     FromUserAgent
     36enum class SimulatedClickSource {
     37    Bindings,
     38    UserAgent
    3939};
    4040
    41 void simulateClick(Element&, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions, SimulatedClickCreationOptions);
     41void simulateClick(Element&, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions, SimulatedClickSource);
    4242
    4343} // namespace WebCore
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r207514 r207544  
    702702void HTMLElement::click()
    703703{
    704     simulateClick(*this, nullptr, SendNoEvents, DoNotShowPressedLook, SimulatedClickCreationOptions::FromBindings);
     704    simulateClick(*this, nullptr, SendNoEvents, DoNotShowPressedLook, SimulatedClickSource::Bindings);
    705705}
    706706
Note: See TracChangeset for help on using the changeset viewer.