Skip to content

Add PointerEvent and related event handlers. #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 13, 2018
Merged

Add PointerEvent and related event handlers. #317

merged 10 commits into from
Mar 13, 2018

Conversation

busti
Copy link
Contributor

@busti busti commented Mar 11, 2018

Pointer events are now available across all major browsers, since they provide several advantages over traditional mouse and touch events, it would be handy to be able to use them in scalajs.

@busti
Copy link
Contributor Author

busti commented Mar 11, 2018

It seems like everything is now correctly formatted. Unfortunately I am unable to check this since the sbt task does not fail on my own system.

@sjrd
Copy link
Member

sjrd commented Mar 12, 2018

Can't you run sbt scalafmt to automatically fix all the formatting?

@busti
Copy link
Contributor Author

busti commented Mar 12, 2018

Sorry, I did not know scalafmt was a thing.

* in addition to new properties for other forms of input: pressure, contact geometry, tilt, etc.
* In fact, the PointerEvent interface inherits all of the MouseEvent's properties thus facilitating
* migrating content from mouse events to pointer events.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you confirm that you are the original author of this documentation text?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the documentation found on MDN. I added credit below (that must have slipped through).
MDN documents are licensed under the Creative Commons license found here: https://github.com/mdn/mdn/blob/master/LICENSE

*/
@js.native
@JSGlobal
class PointerEvent extends MouseEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor should take a type: String, and optionally a init: PointerEventInit, according to https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent.

PointerEventInit should be modeled as a non-native JS trait, with = js.undefined for all members.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the necessary Init trait and constructor parameters.
Please note that this also applies to MouseEvent, which is currently not implemented.

*
* MDN
*/
def pointerId: Int = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.w3.org/TR/pointerevents/#pointerevent-interface says that pointerId is a long in the IDL, so it should be a Double in Scala.js, not an Int (and not a Long either).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it accordingly.

@busti
Copy link
Contributor Author

busti commented Mar 13, 2018

In the last 2 commits I also added the additional tangentialPressure and twist properties specified here: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent

/**
* Sets value of MouseEvent.pointerId. Defaults to 0.
*/
var pointerId: js.undefOr[Double] = js.undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefOr -> UndefOr to fix the compile error.

Otherwise good to go.

@sjrd sjrd changed the title Pointer Events Add PointerEvent and related event handlers. Mar 13, 2018
@sjrd sjrd merged commit 6c88d85 into scala-js:master Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants