Introduce TrackEvent, MediaStreamTrackEvent-related IDL definitions

This commit is contained in:
Shagen Ogandzhanian
2018-12-18 12:19:12 +01:00
parent 3b16fa6af9
commit 44af5b783f
20 changed files with 1056 additions and 68 deletions
@@ -38,7 +38,7 @@ class BuildWebIdl(val mdnCacheFile: File, val srcDir: File) {
val repository =
repositoryPre.copy(typeDefs = repositoryPre.typeDefs.mapValues { it.value.copy(mapType(repositoryPre, it.value.types)) })
val definitions = mapDefinitions(repository, repository.interfaces.values).map {
val definitions = implementInterfaces(mapDefinitions(repository, repository.interfaces.values).map {
if (it.name in relocations) {
// we need this to get interfaces listed in the relocations in valid package
// to keep compatibility with DOM Java API
@@ -46,12 +46,9 @@ class BuildWebIdl(val mdnCacheFile: File, val srcDir: File) {
} else {
it
}
}
val unions = generateUnions(definitions, repository.typeDefs.values)
})
init {
implementInterfaces(definitions)
}
val unions = generateUnions(definitions, repository.typeDefs.values)
val allPackages = (definitions.asSequence().map { it.namespace } + repository.enums.values.map { it.namespace }).distinct().sorted()
+65 -49
View File
@@ -29,6 +29,7 @@ val urls = listOf(
"https://drafts.csswg.org/cssom/" to "org.w3c.dom.css",
"https://www.w3.org/TR/css-masking-1/" to "org.w3c.css.masking",
"https://w3c.github.io/mediacapture-main/" to "org.w3c.dom.mediacapture",
"http://www.w3.org/TR/DOM-Parsing/" to "org.w3c.dom.parsing",
"https://raw.githubusercontent.com/whatwg/url/master/url.html" to "org.w3c.dom.url",
@@ -95,69 +96,84 @@ val kotlinBuiltinInterfaces = mapOf(
)
)
val specifyEventMapper = mapOf<String, String>(
"onbeforeunload" to "BeforeUnloadEvent",
val eventSpecifierMapper = mapOf<String, String>(
"onbeforeunload" to "BeforeUnloadEvent",
"ondrag" to "DragEvent",
"ondragend" to "DragEvent",
"ondragenter" to "DragEvent",
"ondragexit" to "DragEvent",
"ondragleave" to "DragEvent",
"ondragover" to "DragEvent",
"ondragstart" to "DragEvent",
"ondrop" to "DragEvent",
"ondrag" to "DragEvent",
"ondragend" to "DragEvent",
"ondragenter" to "DragEvent",
"ondragexit" to "DragEvent",
"ondragleave" to "DragEvent",
"ondragover" to "DragEvent",
"ondragstart" to "DragEvent",
"ondrop" to "DragEvent",
"onfetch" to "FetchEvent",
"onfetch" to "FetchEvent",
"onblur" to "FocusEvent",
"onfocus" to "FocusEvent",
"onblur" to "FocusEvent",
"onfocus" to "FocusEvent",
"onhashchange" to "HashChangeEvent",
"onhashchange" to "HashChangeEvent",
"oninput" to "InputEvent",
"oninput" to "InputEvent",
"onkeydown" to "KeyboardEvent",
"onkeypress" to "KeyboardEvent",
"onkeyup" to "KeyboardEvent",
"onkeydown" to "KeyboardEvent",
"onkeypress" to "KeyboardEvent",
"onkeyup" to "KeyboardEvent",
"onmessage" to "MessageEvent",
"onmessage" to "MessageEvent",
"onclick" to "MouseEvent",
"oncontextmenu" to "MouseEvent",
"ondblclick" to "MouseEvent",
"onmousedown" to "MouseEvent",
"onmouseenter" to "MouseEvent",
"onmouseleave" to "MouseEvent",
"onmousemove" to "MouseEvent",
"onmouseout" to "MouseEvent",
"onmouseover" to "MouseEvent",
"onmouseup" to "MouseEvent",
"onclick" to "MouseEvent",
"oncontextmenu" to "MouseEvent",
"ondblclick" to "MouseEvent",
"onmousedown" to "MouseEvent",
"onmouseenter" to "MouseEvent",
"onmouseleave" to "MouseEvent",
"onmousemove" to "MouseEvent",
"onmouseout" to "MouseEvent",
"onmouseover" to "MouseEvent",
"onmouseup" to "MouseEvent",
"onnotificationclick" to "NotificationEvent",
"onnotificationclose" to "NotificationEvent",
"onnotificationclick" to "NotificationEvent",
"onnotificationclose" to "NotificationEvent",
"onpagehide" to "PageTransitionEvent",
"onpageshow" to "PageTransitionEvent",
"onpagehide" to "PageTransitionEvent",
"onpageshow" to "PageTransitionEvent",
"ongotpointercapture" to "PointerEvent",
"onlostpointercapture" to "PointerEvent",
"onpointercancel" to "PointerEvent",
"onpointerdown" to "PointerEvent",
"onpointerenter" to "PointerEvent",
"onpointerleave" to "PointerEvent",
"onpointermove" to "PointerEvent",
"onpointerout" to "PointerEvent",
"onpointerover" to "PointerEvent",
"onpointerup" to "PointerEvent",
"ongotpointercapture" to "PointerEvent",
"onlostpointercapture" to "PointerEvent",
"onpointercancel" to "PointerEvent",
"onpointerdown" to "PointerEvent",
"onpointerenter" to "PointerEvent",
"onpointerleave" to "PointerEvent",
"onpointermove" to "PointerEvent",
"onpointerout" to "PointerEvent",
"onpointerover" to "PointerEvent",
"onpointerup" to "PointerEvent",
"onpopstate" to "PopStateEvent",
"onpopstate" to "PopStateEvent",
"onloadstart" to "ProgressEvent",
"onprogress" to "ProgressEvent",
"onloadstart" to "ProgressEvent",
"onprogress" to "ProgressEvent",
"onunhandledrejection" to "PromiseRejectionEvent",
"onunhandledrejection" to "PromiseRejectionEvent",
"onstorage" to "StorageEvent",
"onstorage" to "StorageEvent",
"onwheel" to "WheelEvent"
"onwheel" to "WheelEvent"
)
data class EventMapKey(val name: String, val context: String)
val eventSpecifierMapperWithContext = mapOf<EventMapKey, String>(
EventMapKey("onaddtrack", "MediaStream") to "MediaStreamTrackEvent",
EventMapKey("onremovetrack", "MediaStream") to "MediaStreamTrackEvent",
EventMapKey("onaddtrack", "AudioTrackList") to "TrackEvent",
EventMapKey("onaddtrack", "TextTrackList") to "TrackEvent",
EventMapKey("onaddtrack", "VideoTrackList") to "TrackEvent",
EventMapKey("onremovetrack", "AudioTrackList") to "TrackEvent",
EventMapKey("onremovetrack", "TextTrackList") to "TrackEvent",
EventMapKey("onremovetrack", "VideoTrackList") to "TrackEvent"
)
+15 -7
View File
@@ -89,7 +89,7 @@ fun generateFunctions(repository: Repository, function: Operation): List<Generat
fun generateAttribute(putNoImpl: Boolean, repository: Repository, attribute: Attribute, nullableAttributes: Boolean): GenerateAttribute {
val mappedType = mapType(repository, attribute.type).let { if (nullableAttributes) it.toNullable() else it }
return GenerateAttribute(attribute.name,
type = generalizeType(attribute.name, mappedType),
type = mappedType,
initializer =
if (putNoImpl && !attribute.static) {
mapLiteral(attribute.defaultValue, mapType(repository, attribute.type), repository.enums)
@@ -260,9 +260,10 @@ private fun mapLiteral(literal: String?, expectedType: Type = DynamicType, enums
}
private fun specifyType(name: String, type: Type): Type {
private fun specifyType(name: String, type: Type, context: String): Type {
if ((type is SimpleType) && (type.type == "Event")) {
specifyEventMapper[name]?.let {
(eventSpecifierMapper[name] ?: eventSpecifierMapperWithContext[EventMapKey(name, context)])?.let {
return type.copy(type = it)
}
}
@@ -270,27 +271,34 @@ private fun specifyType(name: String, type: Type): Type {
return type
}
private fun generalizeType(name: String, type: Type): Type {
private fun generalizeType(name: String, type: Type, context: String): Type {
if ((type is FunctionType) && (type.parameterTypes.size == 1)) {
val paramAttribute = type.parameterTypes[0]
return type.copy(parameterTypes = listOf(paramAttribute.copy(type = specifyType(name, paramAttribute.type))))
return type.copy(parameterTypes = listOf(paramAttribute.copy(type = specifyType(name, paramAttribute.type, context))))
}
return type
}
fun implementInterfaces(declarations: List<GenerateTraitOrClass>) {
fun implementInterfaces(declarations: List<GenerateTraitOrClass>) : List<GenerateTraitOrClass> {
val unimplementedMemberMap = getUnimplementedMembers(declarations)
val nonAbstractDeclarations = declarations.filter { it.kind == GenerateDefinitionKind.CLASS }
for (declaration in nonAbstractDeclarations) {
val unimplementedMembers = unimplementedMemberMap[declaration.name] ?: continue
for (attribute in unimplementedMembers.attributes) {
declaration.memberAttributes += attribute.copy(override = true, type = generalizeType(attribute.name, attribute.type))
declaration.memberAttributes += attribute.copy(override = true)
}
for (function in unimplementedMembers.functions) {
declaration.memberFunctions += function.copy(override = true)
}
}
return declarations.map { declaration ->
declaration.copy(
memberAttributes = declaration
.memberAttributes.map { attribute -> attribute.copy(type = generalizeType(attribute.name, attribute.type, declaration.name)) }.toMutableList()
)
}
}
private fun getUnimplementedMembers(declarations: List<GenerateTraitOrClass>): Map<String, UnimplementedMembers> {