Diff
Modified: trunk/LayoutTests/ChangeLog (207543 => 207544)
--- trunk/LayoutTests/ChangeLog 2016-10-19 17:40:27 UTC (rev 207543)
+++ trunk/LayoutTests/ChangeLog 2016-10-19 17:46:42 UTC (rev 207544)
@@ -1,3 +1,16 @@
+2016-10-19 Chris Dumez <cdu...@apple.com>
+
+ MouseEvent's coordinates should be 0 for simulated clicks
+ https://bugs.webkit.org/show_bug.cgi?id=163648
+
+ Reviewed by Darin Adler.
+
+ 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.
+
2016-10-19 Nan Wang <n_w...@apple.com>
AX: [Mac] Meter element should use AXValueDescription to descrbe the status of the value
Added: trunk/LayoutTests/fast/events/element-click-no-coords-expected.txt (0 => 207544)
--- trunk/LayoutTests/fast/events/element-click-no-coords-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/events/element-click-no-coords-expected.txt 2016-10-19 17:46:42 UTC (rev 207544)
@@ -0,0 +1,15 @@
+Tests that the MouseEvent's coordinates are 0 for a simulated click.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.screenX is 0
+PASS event.screenY is 0
+PASS event.clientX is 0
+PASS event.clientY is 0
+PASS event.pageX is 0
+PASS event.pageY is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Test Div
Added: trunk/LayoutTests/fast/events/element-click-no-coords.html (0 => 207544)
--- trunk/LayoutTests/fast/events/element-click-no-coords.html (rev 0)
+++ trunk/LayoutTests/fast/events/element-click-no-coords.html 2016-10-19 17:46:42 UTC (rev 207544)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<div id="testDiv">Test Div</div>
+<script>
+description("Tests that the MouseEvent's coordinates are 0 for a simulated click.");
+jsTestIsAsync = true;
+
+var testDiv = document.getElementById("testDiv");
+
+testDiv._onclick_ = function(e) {
+ event = e;
+ shouldBe("event.screenX", "0");
+ shouldBe("event.screenY", "0");
+ shouldBe("event.clientX", "0");
+ shouldBe("event.clientY", "0");
+ shouldBe("event.pageX", "0");
+ shouldBe("event.pageY", "0");
+
+ finishJSTest();
+};
+
+testDiv.click();
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (207543 => 207544)
--- trunk/Source/WebCore/ChangeLog 2016-10-19 17:40:27 UTC (rev 207543)
+++ trunk/Source/WebCore/ChangeLog 2016-10-19 17:46:42 UTC (rev 207544)
@@ -1,3 +1,29 @@
+2016-10-19 Chris Dumez <cdu...@apple.com>
+
+ MouseEvent's coordinates should be 0 for simulated clicks
+ https://bugs.webkit.org/show_bug.cgi?id=163648
+
+ Reviewed by Darin Adler.
+
+ 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):
+
2016-10-19 Dave Hyatt <hy...@apple.com>
[CSS Parser] Fix transform parsing
Modified: trunk/Source/WebCore/dom/Element.cpp (207543 => 207544)
--- trunk/Source/WebCore/dom/Element.cpp 2016-10-19 17:40:27 UTC (rev 207543)
+++ trunk/Source/WebCore/dom/Element.cpp 2016-10-19 17:46:42 UTC (rev 207544)
@@ -335,7 +335,7 @@
void Element::dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions eventOptions, SimulatedClickVisualOptions visualOptions)
{
- simulateClick(*this, underlyingEvent, eventOptions, visualOptions, SimulatedClickCreationOptions::FromUserAgent);
+ simulateClick(*this, underlyingEvent, eventOptions, visualOptions, SimulatedClickSource::UserAgent);
}
Ref<Node> Element::cloneNodeInternal(Document& targetDocument, CloningOperation type)
Modified: trunk/Source/WebCore/dom/SimulatedClick.cpp (207543 => 207544)
--- trunk/Source/WebCore/dom/SimulatedClick.cpp 2016-10-19 17:40:27 UTC (rev 207543)
+++ trunk/Source/WebCore/dom/SimulatedClick.cpp 2016-10-19 17:46:42 UTC (rev 207544)
@@ -38,13 +38,13 @@
class SimulatedMouseEvent final : public MouseEvent {
public:
- static Ref<SimulatedMouseEvent> create(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target)
+ static Ref<SimulatedMouseEvent> create(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target, SimulatedClickSource source)
{
- return adoptRef(*new SimulatedMouseEvent(eventType, view, WTFMove(underlyingEvent), target));
+ return adoptRef(*new SimulatedMouseEvent(eventType, view, WTFMove(underlyingEvent), target, source));
}
private:
- SimulatedMouseEvent(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target)
+ SimulatedMouseEvent(const AtomicString& eventType, DOMWindow* view, RefPtr<Event>&& underlyingEvent, Element& target, SimulatedClickSource source)
: MouseEvent(eventType, true, true, underlyingEvent ? underlyingEvent->timeStamp() : currentTime(), view, 0, 0, 0, 0, 0,
#if ENABLE(POINTER_LOCK)
0, 0,
@@ -51,6 +51,9 @@
#endif
false, false, false, false, 0, 0, 0, 0, 0, true)
{
+ if (source == SimulatedClickSource::Bindings)
+ setUntrusted();
+
if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent.get())) {
m_ctrlKey = keyStateEvent->ctrlKey();
m_altKey = keyStateEvent->altKey();
@@ -63,7 +66,11 @@
MouseEvent& mouseEvent = downcast<MouseEvent>(*this->underlyingEvent());
m_screenLocation = mouseEvent.screenLocation();
initCoordinates(mouseEvent.clientLocation());
- } else {
+ } else if (source == SimulatedClickSource::UserAgent) {
+ // If there is no underlying event, we only populate the coordinates for events coming
+ // from the user agent (e.g. accessibility). For those coming from _javascript_ (e.g.
+ // (element.click()), the coordinates will be 0, similarly to Firefox and Chrome.
+ // Note that the call to screenRect() causes a synchronous IPC with the UI process.
m_screenLocation = target.screenRect().center();
initCoordinates(LayoutPoint(target.clientRect().center()));
}
@@ -71,15 +78,13 @@
};
-static void simulateMouseEvent(const AtomicString& eventType, Element& element, Event* underlyingEvent, SimulatedClickCreationOptions creationOptions)
+static void simulateMouseEvent(const AtomicString& eventType, Element& element, Event* underlyingEvent, SimulatedClickSource source)
{
- auto event = SimulatedMouseEvent::create(eventType, element.document().defaultView(), underlyingEvent, element);
- if (creationOptions == SimulatedClickCreationOptions::FromBindings)
- event.get().setUntrusted();
- EventDispatcher::dispatchEvent(&element, event.get());
+ auto event = SimulatedMouseEvent::create(eventType, element.document().defaultView(), underlyingEvent, element, source);
+ EventDispatcher::dispatchEvent(&element, event);
}
-void simulateClick(Element& element, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions, SimulatedClickCreationOptions creationOptions)
+void simulateClick(Element& element, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions, SimulatedClickSource creationOptions)
{
if (element.isDisabledFormControl())
return;
Modified: trunk/Source/WebCore/dom/SimulatedClick.h (207543 => 207544)
--- trunk/Source/WebCore/dom/SimulatedClick.h 2016-10-19 17:40:27 UTC (rev 207543)
+++ trunk/Source/WebCore/dom/SimulatedClick.h 2016-10-19 17:46:42 UTC (rev 207544)
@@ -33,12 +33,12 @@
class Element;
class Event;
-enum class SimulatedClickCreationOptions {
- FromBindings,
- FromUserAgent
+enum class SimulatedClickSource {
+ Bindings,
+ UserAgent
};
-void simulateClick(Element&, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions, SimulatedClickCreationOptions);
+void simulateClick(Element&, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions, SimulatedClickSource);
} // namespace WebCore
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (207543 => 207544)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2016-10-19 17:40:27 UTC (rev 207543)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2016-10-19 17:46:42 UTC (rev 207544)
@@ -701,7 +701,7 @@
void HTMLElement::click()
{
- simulateClick(*this, nullptr, SendNoEvents, DoNotShowPressedLook, SimulatedClickCreationOptions::FromBindings);
+ simulateClick(*this, nullptr, SendNoEvents, DoNotShowPressedLook, SimulatedClickSource::Bindings);
}
void HTMLElement::accessKeyAction(bool sendMouseEvents)