Skip to content

Instantly share code, notes, and snippets.

@npryce
Created December 12, 2017 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npryce/2ba5e9bec206ea54f5b1908f12d07171 to your computer and use it in GitHub Desktop.
Save npryce/2ba5e9bec206ea54f5b1908f12d07171 to your computer and use it in GitHub Desktop.
Kotlin definitions for browser touch API
package browser
import org.w3c.dom.Element
import org.w3c.dom.events.UIEvent
typealias TouchId = Int
external interface Touch {
val identifier: TouchId
val target: Element
val screenX: Double
val screenY: Double
val clientX: Double
val clientY: Double
val pageX: Double
val pageY: Double
}
external open class TouchList {
val length: Int
fun item(index: Int): Touch?
}
operator fun TouchList.get(n: Int) =
item(n) ?: throw IndexOutOfBoundsException("index out of bounds: $n, length: $length")
external open class TouchEvent : UIEvent {
val shiftKey: Boolean;
val ctrlKey: Boolean;
val altKey: Boolean;
val metaKey: Boolean;
/**
* See [DOM Level 3 Events spec](https://www.w3.org/TR/uievents-key/#keys-modifier). for a list of valid (case-sensitive) arguments to this method.
*/
fun getModifierState(key: String): Boolean;
val touches: TouchList;
val changedTouches: TouchList;
val targetTouches: TouchList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment