JS Introduce SVG DOM support

This commit is contained in:
Sergey Mashkov
2015-05-08 13:27:42 +03:00
committed by Sergey Mashkov
parent 6366f966b7
commit d24bdf5ad0
15 changed files with 4828 additions and 51 deletions
@@ -11,6 +11,7 @@ import org.w3c.dom.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.notifications.* import org.w3c.notifications.*
@@ -11,6 +11,7 @@ import org.khronos.webgl.*
import org.w3c.dom.* import org.w3c.dom.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.notifications.* import org.w3c.notifications.*
@@ -11,6 +11,7 @@ import org.khronos.webgl.*
import org.w3c.dom.* import org.w3c.dom.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.notifications.* import org.w3c.notifications.*
+9 -8
View File
@@ -11,6 +11,7 @@ import org.khronos.webgl.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.notifications.* import org.w3c.notifications.*
@@ -2726,7 +2727,7 @@ native public open class CanvasRenderingContext2D {
var height: Int var height: Int
get() = noImpl get() = noImpl
set(value) = noImpl set(value) = noImpl
var currentTransform: dynamic var currentTransform: SVGMatrix
get() = noImpl get() = noImpl
set(value) = noImpl set(value) = noImpl
var globalAlpha: Double var globalAlpha: Double
@@ -2847,7 +2848,7 @@ native public trait CanvasGradient {
} }
native public trait CanvasPattern { native public trait CanvasPattern {
fun setTransform(transform: dynamic): Unit = noImpl fun setTransform(transform: SVGMatrix): Unit = noImpl
} }
native public trait TextMetrics { native public trait TextMetrics {
@@ -2945,12 +2946,12 @@ native public open class DrawingStyle(scope: Element = noImpl) {
} }
native public open class Path2D { native public open class Path2D {
fun addPath(path: Path2D, transformation: dynamic = null): Unit = noImpl fun addPath(path: Path2D, transformation: SVGMatrix? = null): Unit = noImpl
fun addPathByStrokingPath(path: Path2D, styles: dynamic, transformation: dynamic = null): Unit = noImpl fun addPathByStrokingPath(path: Path2D, styles: dynamic, transformation: SVGMatrix? = null): Unit = noImpl
fun addText(text: String, styles: dynamic, transformation: dynamic, x: Double, y: Double, maxWidth: Double = noImpl): Unit = noImpl fun addText(text: String, styles: dynamic, transformation: SVGMatrix?, x: Double, y: Double, maxWidth: Double = noImpl): Unit = noImpl
fun addPathByStrokingText(text: String, styles: dynamic, transformation: dynamic, x: Double, y: Double, maxWidth: Double = noImpl): Unit = noImpl fun addPathByStrokingText(text: String, styles: dynamic, transformation: SVGMatrix?, x: Double, y: Double, maxWidth: Double = noImpl): Unit = noImpl
fun addText(text: String, styles: dynamic, transformation: dynamic, path: Path2D, maxWidth: Double = noImpl): Unit = noImpl fun addText(text: String, styles: dynamic, transformation: SVGMatrix?, path: Path2D, maxWidth: Double = noImpl): Unit = noImpl
fun addPathByStrokingText(text: String, styles: dynamic, transformation: dynamic, path: Path2D, maxWidth: Double = noImpl): Unit = noImpl fun addPathByStrokingText(text: String, styles: dynamic, transformation: SVGMatrix?, path: Path2D, maxWidth: Double = noImpl): Unit = noImpl
fun closePath(): Unit = noImpl fun closePath(): Unit = noImpl
fun moveTo(x: Double, y: Double): Unit = noImpl fun moveTo(x: Double, y: Double): Unit = noImpl
fun lineTo(x: Double, y: Double): Unit = noImpl fun lineTo(x: Double, y: Double): Unit = noImpl
@@ -11,6 +11,7 @@ import org.khronos.webgl.*
import org.w3c.dom.* import org.w3c.dom.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.notifications.* import org.w3c.notifications.*
File diff suppressed because it is too large Load Diff
@@ -12,6 +12,7 @@ import org.w3c.dom.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.notifications.* import org.w3c.notifications.*
import org.w3c.workers.* import org.w3c.workers.*
@@ -12,6 +12,7 @@ import org.w3c.dom.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.notifications.* import org.w3c.notifications.*
import org.w3c.workers.* import org.w3c.workers.*
@@ -12,6 +12,7 @@ import org.w3c.dom.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.workers.* import org.w3c.workers.*
@@ -12,6 +12,7 @@ import org.w3c.dom.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.notifications.* import org.w3c.notifications.*
@@ -12,6 +12,7 @@ import org.w3c.dom.*
import org.w3c.dom.css.* import org.w3c.dom.css.*
import org.w3c.dom.events.* import org.w3c.dom.events.*
import org.w3c.dom.parsing.* import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.* import org.w3c.fetch.*
import org.w3c.files.* import org.w3c.files.*
import org.w3c.notifications.* import org.w3c.notifications.*
File diff suppressed because it is too large Load Diff
@@ -67,14 +67,25 @@ definition
| dictionary | dictionary
| enum_ | enum_
| typedef | typedef
| exception_
| const_
| module
| implementsStatement | implementsStatement
; ;
module
: 'module' IDENTIFIER_WEBIDL '{' definitions '}' ';'?
;
callbackOrInterface callbackOrInterface
: 'callback' callbackRestOrInterface : 'callback' callbackRestOrInterface
| interface_ | interface_
; ;
exception_
: 'exception' IDENTIFIER_WEBIDL inheritance '{' dictionaryMembers '}' ';'
;
callbackRestOrInterface callbackRestOrInterface
: callbackRest : callbackRest
| interface_ | interface_
@@ -150,7 +161,7 @@ defaultValue
; ;
inheritance inheritance
: ':' IDENTIFIER_WEBIDL : ':' IDENTIFIER_WEBIDL ( ',' IDENTIFIER_WEBIDL )*
| /* empty */ | /* empty */
; ;
@@ -271,16 +282,11 @@ readWriteAttribute
; ;
attributeRest attributeRest
: 'attribute' type (IDENTIFIER_WEBIDL | 'required') ';' : 'attribute' type (IDENTIFIER_WEBIDL | 'required') attributeAnnotations* ';'
; ;
attributeName attributeAnnotations
: attributeNameKeyword : IDENTIFIER_WEBIDL ( '(' type (',' type)* ')' )?
| IDENTIFIER_WEBIDL
;
attributeNameKeyword
: 'required'
; ;
inherit inherit
@@ -316,7 +322,7 @@ special
; ;
operationRest operationRest
: optionalIdentifier '(' argumentList ')' ';' : optionalIdentifier '(' argumentList ')' attributeAnnotations* ';'
; ;
optionalIdentifier optionalIdentifier
@@ -339,7 +345,7 @@ argument
; ;
optionalOrRequiredArgument optionalOrRequiredArgument
: 'optional'? type ellipsis argumentName default_ : 'optional'? ('in'|'out')? type ellipsis argumentName default_
; ;
argumentName argumentName
@@ -37,6 +37,7 @@ val urls = listOf(
"https://raw.githubusercontent.com/whatwg/fetch/master/Overview.src.html" to "org.w3c.fetch", "https://raw.githubusercontent.com/whatwg/fetch/master/Overview.src.html" to "org.w3c.fetch",
"http://www.w3.org/TR/vibration/" to "org.w3c.vibration", "http://www.w3.org/TR/vibration/" to "org.w3c.vibration",
"http://dev.w3.org/csswg/cssom/" to "org.w3c.dom.css", "http://dev.w3.org/csswg/cssom/" to "org.w3c.dom.css",
"http://web.archive.org/web/20150317051602/http://www.w3.org/TR/SVG11/single-page.html" to "org.w3c.dom.svg",
"https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl" to "org.khronos.webgl", "https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl" to "org.khronos.webgl",
"https://www.khronos.org/registry/typedarray/specs/latest/typedarray.idl" to "org.khronos.webgl" "https://www.khronos.org/registry/typedarray/specs/latest/typedarray.idl" to "org.khronos.webgl"
) )
+42 -32
View File
@@ -19,6 +19,7 @@ package org.jetbrains.idl2k
import org.antlr.v4.runtime.CharStream import org.antlr.v4.runtime.CharStream
import org.antlr.v4.runtime.CommonTokenStream import org.antlr.v4.runtime.CommonTokenStream
import org.antlr.v4.runtime.ParserRuleContext import org.antlr.v4.runtime.ParserRuleContext
import org.antlr.v4.runtime.tree.ParseTree
import org.antlr.v4.runtime.tree.TerminalNode import org.antlr.v4.runtime.tree.TerminalNode
import org.antlr.webidl.WebIDLBaseVisitor import org.antlr.webidl.WebIDLBaseVisitor
import org.antlr.webidl.WebIDLLexer import org.antlr.webidl.WebIDLLexer
@@ -82,7 +83,7 @@ class ExtendedAttributeParser : WebIDLBaseVisitor<ExtendedAttribute>() {
override fun defaultResult(): ExtendedAttribute = ExtendedAttribute(name, call, arguments) override fun defaultResult(): ExtendedAttribute = ExtendedAttribute(name, call, arguments)
override fun visitExtendedAttribute(ctx: WebIDLParser.ExtendedAttributeContext): ExtendedAttribute { override fun visitExtendedAttribute(ctx: WebIDLParser.ExtendedAttributeContext): ExtendedAttribute {
call = ctx.children?.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL }?.firstOrNull()?.getText() ?: "" call = ctx.children.filterIdentifiers().firstOrNull()?.getText() ?: ""
visitChildren(ctx) visitChildren(ctx)
return defaultResult() return defaultResult()
@@ -259,7 +260,7 @@ class ConstantVisitor(val attributes: List<ExtendedAttribute>) : WebIDLBaseVisit
} }
} }
class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val namespace: String) : WebIDLBaseVisitor<Definition>() { class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val namespace: String, val declarations : MutableList<Definition>) : WebIDLBaseVisitor<Definition>() {
private var type: DefinitionType = DefinitionType.INTERFACE private var type: DefinitionType = DefinitionType.INTERFACE
private var name = "" private var name = ""
private val memberAttributes = ArrayList<ExtendedAttribute>() private val memberAttributes = ArrayList<ExtendedAttribute>()
@@ -295,6 +296,15 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
return defaultResult() return defaultResult()
} }
override fun visitModule(ctx: ModuleContext): Definition {
val moduleName = getName(ctx)
val namespace = if (this.namespace.endsWith(moduleName)) this.namespace else this.namespace + "." + moduleName
ModuleVisitor(declarations, namespace).visitChildren(ctx)
return defaultResult()
}
override fun visitInterface_(ctx: Interface_Context): Definition { override fun visitInterface_(ctx: Interface_Context): Definition {
name = getName(ctx) name = getName(ctx)
visitChildren(ctx) visitChildren(ctx)
@@ -347,8 +357,8 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
override fun visitDictionaryMember(ctx: DictionaryMemberContext): Definition { override fun visitDictionaryMember(ctx: DictionaryMemberContext): Definition {
val name = ctx.children val name = ctx.children
?.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL } .filterIdentifiers()
?.first { it.getText() != "" } .firstOrNull { it.getText() != "" }
?.getText() ?.getText()
val type = TypeVisitor().visit(ctx.children.first { it is TypeContext }) val type = TypeVisitor().visit(ctx.children.first { it is TypeContext })
@@ -369,7 +379,7 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
} }
override fun visitImplementsStatement(ctx: ImplementsStatementContext): Definition { override fun visitImplementsStatement(ctx: ImplementsStatementContext): Definition {
val identifiers = ctx.children.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL }.map { it.getText() } val identifiers = ctx.children.filterIdentifiers().map { it.getText() }
if (identifiers.size() >= 2) { if (identifiers.size() >= 2) {
type = DefinitionType.EXTENSION_INTERFACE type = DefinitionType.EXTENSION_INTERFACE
@@ -390,8 +400,8 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
} }
override fun visitInheritance(ctx: WebIDLParser.InheritanceContext): Definition { override fun visitInheritance(ctx: WebIDLParser.InheritanceContext): Definition {
if (ctx.children != null && ctx.isEmpty().not()) { if (ctx.children != null) {
inherited.add(getName(ctx)) inherited.addAll(ctx.children.filterIdentifiers().map {it.getText().trim()}.filter {it != ""})
} }
return defaultResult() return defaultResult()
} }
@@ -431,38 +441,38 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
} }
private fun getName(ctx: ParserRuleContext) = ctx.children.first { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL }.getText() class ModuleVisitor(val declarations : MutableList<Definition>, var namespace : String = "") : WebIDLBaseVisitor<Unit>() {
val extendedAttributes = ArrayList<ExtendedAttribute>()
override fun visitDefinition(ctx: WebIDLParser.DefinitionContext) {
val declaration = DefinitionVisitor(extendedAttributes.toList(), namespace, declarations).visitChildren(ctx)
extendedAttributes.clear()
declarations.add(declaration)
}
override fun visitExtendedAttribute(ctx: ExtendedAttributeContext?) {
val att = with(ExtendedAttributeParser()) {
visit(ctx)
}
extendedAttributes.add(att)
}
override fun visitNamespaceRest(ctx: NamespaceRestContext) {
this.namespace = ctx.getText()
}
}
private fun List<ParseTree>?.filterIdentifiers(): List<ParseTree> = this?.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL } ?: emptyList()
private fun getName(ctx: ParserRuleContext) = ctx.children.filterIdentifiers().first().getText()
fun parseIDL(reader: CharStream): Repository { fun parseIDL(reader: CharStream): Repository {
val ll = WebIDLLexer(reader) val ll = WebIDLLexer(reader)
val pp = WebIDLParser(CommonTokenStream(ll)) val pp = WebIDLParser(CommonTokenStream(ll))
val idl = pp.webIDL() val idl = pp.webIDL()
val declarations = ArrayList<Definition>() val declarations = ArrayList<Definition>()
ModuleVisitor(declarations).visit(idl)
idl.accept(object : WebIDLBaseVisitor<Unit>() {
val extendedAttributes = ArrayList<ExtendedAttribute>()
var namespace = ""
override fun visitDefinition(ctx: WebIDLParser.DefinitionContext) {
val declaration = DefinitionVisitor(extendedAttributes.toList(), namespace).visitChildren(ctx)
extendedAttributes.clear()
declarations.add(declaration)
}
override fun visitExtendedAttribute(ctx: ExtendedAttributeContext?) {
val att = with(ExtendedAttributeParser()) {
visit(ctx)
}
extendedAttributes.add(att)
}
override fun visitNamespaceRest(ctx: NamespaceRestContext) {
this.namespace = ctx.getText()
}
})
return Repository( return Repository(
declarations.filterIsInstance<InterfaceDefinition>().filter { it.name.isEmpty().not() }.groupBy { it.name }.mapValues { it.getValue().reduce(::merge) }, declarations.filterIsInstance<InterfaceDefinition>().filter { it.name.isEmpty().not() }.groupBy { it.name }.mapValues { it.getValue().reduce(::merge) },