Skip to content
Permalink
Browse files
[Mac] Add support for MouseEvent.buttons
https://bugs.webkit.org/show_bug.cgi?id=178214

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline test now that more checks are passing.

* web-platform-tests/dom/events/Event-subclasses-constructors-expected.txt:

Source/WebCore:

Add support for MouseEvent.buttons on Mac as per:
- https://www.w3.org/TR/uievents/#ref-for-dom-mouseevent-buttons-1

This is supported by Firefox and Chrome already.

No new tests, rebaselined existing test.

* dom/Element.cpp:
(WebCore::Element::dispatchMouseEvent):
* dom/MouseEvent.cpp:
(WebCore::MouseEvent::create):
(WebCore::MouseEvent::MouseEvent):
* dom/MouseEvent.h:
(WebCore::MouseEvent::buttons const):
* dom/MouseEvent.idl:
* dom/MouseEventInit.h:
* dom/MouseEventInit.idl:
* dom/SimulatedClick.cpp:
* dom/WheelEvent.cpp:
* page/EventHandler.cpp:
(WebCore::EventHandler::dispatchDragEvent):
* platform/PlatformMouseEvent.h:
(WebCore::PlatformMouseEvent::buttons const):
* platform/mac/PlatformEventFactoryMac.mm:
(WebCore::currentlyPressedMouseButtons):
(WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder):

Source/WebKit:

* Shared/WebEvent.h:
(WebKit::WebMouseEvent::buttons const):
* Shared/WebEventConversion.cpp:
(WebKit::WebKit2PlatformMouseEvent::WebKit2PlatformMouseEvent):
* Shared/WebMouseEvent.cpp:
(WebKit::WebMouseEvent::WebMouseEvent):
(WebKit::WebMouseEvent::encode const):
(WebKit::WebMouseEvent::decode):
* Shared/mac/WebEventFactory.mm:
(WebKit::currentlyPressedMouseButtons):
(WebKit::WebEventFactory::createWebMouseEvent):
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::showContextMenuAtPoint):
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::createWebEvent const):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::navigateToPDFLinkWithSimulatedClick):
(WebKit::WebPage::simulateMouseDown):
(WebKit::WebPage::simulateMouseUp):
(WebKit::WebPage::simulateMouseMotion):

Source/WebKitLegacy/mac:

* WebView/WebPDFView.mm:
(-[WebPDFView PDFViewWillClickOnLink:withURL:]):


Canonical link: https://commits.webkit.org/194481@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223264 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Oct 13, 2017
1 parent 9a800dc commit 7d3630ccd145e41b8f83ad834d92ddb383ed1f96
Showing 28 changed files with 167 additions and 53 deletions.
@@ -1,3 +1,14 @@
2017-10-12 Chris Dumez <cdumez@apple.com>

[Mac] Add support for MouseEvent.buttons
https://bugs.webkit.org/show_bug.cgi?id=178214

Reviewed by Ryosuke Niwa.

Rebaseline test now that more checks are passing.

* web-platform-tests/dom/events/Event-subclasses-constructors-expected.txt:

2017-10-11 Chris Dumez <cdumez@apple.com>

XMLHttpRequest: do not sniff text/html, and do not sniff XML when responseType is set to "text"
@@ -17,18 +17,18 @@ PASS FocusEvent constructor (null argument)
PASS FocusEvent constructor (empty argument)
PASS FocusEvent constructor (argument with default values)
PASS FocusEvent constructor (argument with non-default values)
FAIL MouseEvent constructor (no argument) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (undefined argument) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (null argument) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (empty argument) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (argument with default values) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (argument with non-default values) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (no argument) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (undefined argument) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (null argument) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (empty argument) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (argument with default values) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (argument with non-default values) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
PASS MouseEvent constructor (no argument)
PASS MouseEvent constructor (undefined argument)
PASS MouseEvent constructor (null argument)
PASS MouseEvent constructor (empty argument)
PASS MouseEvent constructor (argument with default values)
PASS MouseEvent constructor (argument with non-default values)
PASS WheelEvent constructor (no argument)
PASS WheelEvent constructor (undefined argument)
PASS WheelEvent constructor (null argument)
PASS WheelEvent constructor (empty argument)
PASS WheelEvent constructor (argument with default values)
PASS WheelEvent constructor (argument with non-default values)
PASS KeyboardEvent constructor (no argument)
PASS KeyboardEvent constructor (undefined argument)
PASS KeyboardEvent constructor (null argument)
@@ -17,18 +17,18 @@ PASS FocusEvent constructor (null argument)
PASS FocusEvent constructor (empty argument)
PASS FocusEvent constructor (argument with default values)
PASS FocusEvent constructor (argument with non-default values)
FAIL MouseEvent constructor (no argument) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (undefined argument) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (null argument) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (empty argument) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (argument with default values) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL MouseEvent constructor (argument with non-default values) assert_true: Event object "[object MouseEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (no argument) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (undefined argument) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (null argument) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (empty argument) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (argument with default values) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
FAIL WheelEvent constructor (argument with non-default values) assert_true: Event object "[object WheelEvent]" should have a buttons property expected true got false
PASS MouseEvent constructor (no argument)
PASS MouseEvent constructor (undefined argument)
PASS MouseEvent constructor (null argument)
PASS MouseEvent constructor (empty argument)
PASS MouseEvent constructor (argument with default values)
PASS MouseEvent constructor (argument with non-default values)
PASS WheelEvent constructor (no argument)
PASS WheelEvent constructor (undefined argument)
PASS WheelEvent constructor (null argument)
PASS WheelEvent constructor (empty argument)
PASS WheelEvent constructor (argument with default values)
PASS WheelEvent constructor (argument with non-default values)
PASS KeyboardEvent constructor (no argument)
PASS KeyboardEvent constructor (undefined argument)
PASS KeyboardEvent constructor (null argument)
@@ -1,3 +1,37 @@
2017-10-12 Chris Dumez <cdumez@apple.com>

[Mac] Add support for MouseEvent.buttons
https://bugs.webkit.org/show_bug.cgi?id=178214

Reviewed by Ryosuke Niwa.

Add support for MouseEvent.buttons on Mac as per:
- https://www.w3.org/TR/uievents/#ref-for-dom-mouseevent-buttons-1

This is supported by Firefox and Chrome already.

No new tests, rebaselined existing test.

* dom/Element.cpp:
(WebCore::Element::dispatchMouseEvent):
* dom/MouseEvent.cpp:
(WebCore::MouseEvent::create):
(WebCore::MouseEvent::MouseEvent):
* dom/MouseEvent.h:
(WebCore::MouseEvent::buttons const):
* dom/MouseEvent.idl:
* dom/MouseEventInit.h:
* dom/MouseEventInit.idl:
* dom/SimulatedClick.cpp:
* dom/WheelEvent.cpp:
* page/EventHandler.cpp:
(WebCore::EventHandler::dispatchDragEvent):
* platform/PlatformMouseEvent.h:
(WebCore::PlatformMouseEvent::buttons const):
* platform/mac/PlatformEventFactoryMac.mm:
(WebCore::currentlyPressedMouseButtons):
(WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder):

2017-10-12 David Kilzer <ddkilzer@apple.com>

[iOS] Fix -Wunused-lambda-capture warnings in WebCore/WebKit with new clang compiler
@@ -285,7 +285,7 @@ bool Element::dispatchMouseEvent(const PlatformMouseEvent& platformEvent, const
mouseEvent->bubbles(), mouseEvent->cancelable(), mouseEvent->view(), mouseEvent->detail(),
mouseEvent->screenX(), mouseEvent->screenY(), mouseEvent->clientX(), mouseEvent->clientY(),
mouseEvent->ctrlKey(), mouseEvent->altKey(), mouseEvent->shiftKey(), mouseEvent->metaKey(),
mouseEvent->button(), mouseEvent->syntheticClickType(), relatedTarget);
mouseEvent->button(), mouseEvent->buttons(), mouseEvent->syntheticClickType(), relatedTarget);

if (mouseEvent->defaultHandled())
doubleClickEvent->setDefaultHandled();
@@ -55,27 +55,27 @@ Ref<MouseEvent> MouseEvent::create(const AtomicString& eventType, DOMWindow* vie
#if ENABLE(POINTER_LOCK)
event.movementDelta().x(), event.movementDelta().y(),
#endif
event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.button(),
event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.button(), event.buttons(),
relatedTarget, event.force(), event.syntheticClickType());
}

Ref<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, MonotonicTime timestamp, DOMWindow* view, int detail, int screenX, int screenY, int pageX, int pageY,
#if ENABLE(POINTER_LOCK)
int movementX, int movementY,
#endif
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* dataTransfer, bool isSimulated)
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short buttons, EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* dataTransfer, bool isSimulated)
{
return adoptRef(*new MouseEvent(type, canBubble, cancelable, timestamp, view,
detail, { screenX, screenY }, { pageX, pageY },
#if ENABLE(POINTER_LOCK)
{ movementX, movementY },
#endif
ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, force, syntheticClickType, dataTransfer, isSimulated));
ctrlKey, altKey, shiftKey, metaKey, button, buttons, relatedTarget, force, syntheticClickType, dataTransfer, isSimulated));
}

Ref<MouseEvent> MouseEvent::create(const AtomicString& eventType, bool canBubble, bool cancelable, DOMWindow* view, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short syntheticClickType, EventTarget* relatedTarget)
Ref<MouseEvent> MouseEvent::create(const AtomicString& eventType, bool canBubble, bool cancelable, DOMWindow* view, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short buttons, unsigned short syntheticClickType, EventTarget* relatedTarget)
{
return adoptRef(*new MouseEvent(eventType, canBubble, cancelable, view, detail, { screenX, screenY }, { clientX, clientY }, ctrlKey, altKey, shiftKey, metaKey, button, syntheticClickType, relatedTarget));
return adoptRef(*new MouseEvent(eventType, canBubble, cancelable, view, detail, { screenX, screenY }, { clientX, clientY }, ctrlKey, altKey, shiftKey, metaKey, button, buttons, syntheticClickType, relatedTarget));
}

MouseEvent::MouseEvent()
@@ -86,13 +86,14 @@ MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
#if ENABLE(POINTER_LOCK)
const IntPoint& movementDelta,
#endif
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* dataTransfer, bool isSimulated)
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short buttons, EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* dataTransfer, bool isSimulated)
: MouseRelatedEvent(eventType, canBubble, cancelable, timestamp, view, detail, screenLocation, windowLocation,
#if ENABLE(POINTER_LOCK)
movementDelta,
#endif
ctrlKey, altKey, shiftKey, metaKey, isSimulated)
, m_button(button == (unsigned short)-1 ? 0 : button)
, m_buttons(buttons)
, m_syntheticClickType(button == (unsigned short)-1 ? 0 : syntheticClickType)
, m_buttonDown(button != (unsigned short)-1)
, m_relatedTarget(relatedTarget)
@@ -101,13 +102,14 @@ MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
{
}

MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, DOMWindow* view, int detail, const IntPoint& screenLocation, const IntPoint& clientLocation, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short syntheticClickType, EventTarget* relatedTarget)
MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, DOMWindow* view, int detail, const IntPoint& screenLocation, const IntPoint& clientLocation, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short buttons, unsigned short syntheticClickType, EventTarget* relatedTarget)
: MouseRelatedEvent(eventType, canBubble, cancelable, MonotonicTime::now(), view, detail, screenLocation, { },
#if ENABLE(POINTER_LOCK)
{ },
#endif
ctrlKey, altKey, shiftKey, metaKey, false)
, m_button(button == (unsigned short)-1 ? 0 : button)
, m_buttons(buttons)
, m_syntheticClickType(button == (unsigned short)-1 ? 0 : syntheticClickType)
, m_buttonDown(button != (unsigned short)-1)
, m_relatedTarget(relatedTarget)
@@ -118,6 +120,7 @@ MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& initializer, IsTrusted isTrusted)
: MouseRelatedEvent(eventType, initializer, isTrusted)
, m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button)
, m_buttons(initializer.buttons)
, m_buttonDown(initializer.button != (unsigned short)-1)
, m_relatedTarget(initializer.relatedTarget)
{
@@ -37,11 +37,11 @@ class MouseEvent : public MouseRelatedEvent {
#if ENABLE(POINTER_LOCK)
int movementX, int movementY,
#endif
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* = nullptr, bool isSimulated = false);
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short buttons, EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* = nullptr, bool isSimulated = false);

WEBCORE_EXPORT static Ref<MouseEvent> create(const AtomicString& eventType, DOMWindow*, const PlatformMouseEvent&, int detail, Node* relatedTarget);

static Ref<MouseEvent> create(const AtomicString& eventType, bool canBubble, bool cancelable, DOMWindow*, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short syntheticClickType, EventTarget* relatedTarget);
static Ref<MouseEvent> create(const AtomicString& eventType, bool canBubble, bool cancelable, DOMWindow*, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short buttons, unsigned short syntheticClickType, EventTarget* relatedTarget);

static Ref<MouseEvent> createForBindings() { return adoptRef(*new MouseEvent); }

@@ -54,6 +54,7 @@ class MouseEvent : public MouseRelatedEvent {
// WinIE uses 1,4,2 for left/middle/right but not for click (just for mousedown/up, maybe others),
// but we will match the standard DOM.
unsigned short button() const { return m_button; }
unsigned short buttons() const { return m_buttons; }
unsigned short syntheticClickType() const { return m_syntheticClickType; }
bool buttonDown() const { return m_buttonDown; }
EventTarget* relatedTarget() const final { return m_relatedTarget.get(); }
@@ -75,13 +76,13 @@ class MouseEvent : public MouseRelatedEvent {
#if ENABLE(POINTER_LOCK)
const IntPoint& movementDelta,
#endif
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short buttons,
EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer*, bool isSimulated);

MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, DOMWindow*,
int detail, const IntPoint& screenLocation, const IntPoint& clientLocation,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
unsigned short button, unsigned short syntheticClickType, EventTarget* relatedTarget);
unsigned short button, unsigned short buttons, unsigned short syntheticClickType, EventTarget* relatedTarget);

MouseEvent(const AtomicString& type, const MouseEventInit&, IsTrusted);

@@ -96,6 +97,7 @@ class MouseEvent : public MouseRelatedEvent {
void setRelatedTarget(EventTarget& relatedTarget) final { m_relatedTarget = &relatedTarget; }

unsigned short m_button { 0 };
unsigned short m_buttons { 0 };
unsigned short m_syntheticClickType { 0 };
bool m_buttonDown { false };
RefPtr<EventTarget> m_relatedTarget;
@@ -33,6 +33,7 @@
readonly attribute boolean altKey;
readonly attribute boolean metaKey;
readonly attribute unsigned short button;
readonly attribute unsigned short buttons;
readonly attribute EventTarget? relatedTarget;
[Conditional=POINTER_LOCK] readonly attribute long movementX;
[Conditional=POINTER_LOCK] readonly attribute long movementY;
@@ -33,6 +33,7 @@ struct MouseEventInit : MouseRelatedEventInit {
int clientX { 0 };
int clientY { 0 };
unsigned short button { 0 };
unsigned short buttons { 0 };
RefPtr<EventTarget> relatedTarget;
};

@@ -29,6 +29,7 @@ dictionary MouseEventInit : EventModifierInit {
long clientX = 0;
long clientY = 0;
unsigned short button = 0;
unsigned short buttons = 0;

// FIXME: We need to support the following member.
// unsigned short buttons = 0;
@@ -50,7 +50,7 @@ class SimulatedMouseEvent final : public MouseEvent {
#if ENABLE(POINTER_LOCK)
{ },
#endif
false, false, false, false, 0, 0, 0, 0, 0, true)
false, false, false, false, 0, 0, nullptr, 0, 0, nullptr, true)
{
if (source == SimulatedClickSource::Bindings)
setUntrusted();
@@ -54,7 +54,7 @@ WheelEvent::WheelEvent(const PlatformWheelEvent& event, DOMWindow* view)
#if ENABLE(POINTER_LOCK)
, { }
#endif
, event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), 0, 0, 0, 0, 0, false)
, event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), 0, 0, nullptr, 0, 0, nullptr, false)
, m_wheelDelta(event.wheelTicksX() * TickMultiplier, event.wheelTicksY() * TickMultiplier)
, m_deltaX(-event.deltaX())
, m_deltaY(-event.deltaY())
@@ -2197,7 +2197,7 @@ bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Element& dra
event.movementDelta().x(), event.movementDelta().y(),
#endif
event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(),
0, 0, event.force(), NoTap, &dataTransfer);
0, 0, nullptr, event.force(), NoTap, &dataTransfer);

dragTarget.dispatchEvent(me);
return me->defaultPrevented();
@@ -86,6 +86,7 @@ const double ForceAtForceClick = 2;
#endif

MouseButton button() const { return m_button; }
unsigned short buttons() const { return m_buttons; }
int clickCount() const { return m_clickCount; }
unsigned modifierFlags() const { return m_modifierFlags; }
double force() const { return m_force; }
@@ -115,6 +116,7 @@ const double ForceAtForceClick = 2;
IntPoint m_movementDelta;
#endif
MouseButton m_button;
unsigned short m_buttons { 0 };
int m_clickCount;
unsigned m_modifierFlags;
double m_force { 0 };

0 comments on commit 7d3630c

Please sign in to comment.