From b621b0524be6c2423b976acaed9a811df327164a Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Thu, 6 Feb 2014 13:00:46 +0400 Subject: [PATCH] Adds a skeleton of a new native interface to JavaScript --- pom.xml | 1 + .../javascript/JavascriptNativeProcessor.java | 72 ++++++++++++ .../java/org/teavm/javascript/ni/JSArray.java | 30 +++++ .../teavm/javascript/ni/JSConstructor.java | 40 +++++++ .../org/teavm/javascript/ni/JSFunction.java | 53 +++++++++ .../org/teavm/javascript/ni/JSFunctor.java | 30 +++++ .../org/teavm/javascript/ni/JSGlobal.java | 28 +++++ .../org/teavm/javascript/ni/JSMethod.java | 31 ++++++ .../org/teavm/javascript/ni/JSNumber.java | 23 ++++ .../org/teavm/javascript/ni/JSObject.java | 97 +++++++++++++++++ .../org/teavm/javascript/ni/JSProperty.java | 31 ++++++ .../java/org/teavm/javascript/ni/JSRoot.java | 61 +++++++++++ .../javascript/ni/JSRootNativeGenerator.java | 58 ++++++++++ .../org/teavm/javascript/ni/JSString.java | 24 ++++ .../java/org/teavm/javascript/ni/JSType.java | 29 +++++ teavm-dom/.gitignore | 4 + teavm-dom/pom.xml | 35 ++++++ .../main/java/org/teavm/dom/core/Attr.java | 39 +++++++ .../java/org/teavm/dom/core/CDATASection.java | 24 ++++ .../org/teavm/dom/core/CharacterData.java | 43 ++++++++ .../main/java/org/teavm/dom/core/Comment.java | 24 ++++ .../org/teavm/dom/core/DOMImplementation.java | 25 +++++ .../java/org/teavm/dom/core/Document.java | 61 +++++++++++ .../org/teavm/dom/core/DocumentFragment.java | 24 ++++ .../java/org/teavm/dom/core/DocumentType.java | 24 ++++ .../main/java/org/teavm/dom/core/Element.java | 54 +++++++++ .../org/teavm/dom/core/EntityReference.java | 23 ++++ .../java/org/teavm/dom/core/NamedNodeMap.java | 44 ++++++++ .../main/java/org/teavm/dom/core/Node.java | 103 ++++++++++++++++++ .../java/org/teavm/dom/core/NodeList.java | 31 ++++++ .../teavm/dom/core/ProcessingInstruction.java | 24 ++++ .../main/java/org/teavm/dom/core/Text.java | 24 ++++ .../main/java/org/teavm/dom/core/Window.java | 36 ++++++ .../main/java/org/teavm/dom/events/Event.java | 56 ++++++++++ .../org/teavm/dom/events/EventListener.java | 27 +++++ .../org/teavm/dom/events/EventTarget.java | 30 +++++ 36 files changed, 1363 insertions(+) create mode 100644 teavm-core/src/main/java/org/teavm/javascript/JavascriptNativeProcessor.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSArray.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSConstructor.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSFunction.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSFunctor.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSGlobal.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSMethod.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSNumber.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSObject.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSProperty.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSRoot.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSRootNativeGenerator.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSString.java create mode 100644 teavm-core/src/main/java/org/teavm/javascript/ni/JSType.java create mode 100644 teavm-dom/.gitignore create mode 100644 teavm-dom/pom.xml create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/Attr.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/CDATASection.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/CharacterData.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/Comment.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/DOMImplementation.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/Document.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/DocumentFragment.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/DocumentType.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/Element.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/EntityReference.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/NamedNodeMap.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/Node.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/NodeList.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/ProcessingInstruction.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/Text.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/core/Window.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/events/Event.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/events/EventListener.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/events/EventTarget.java diff --git a/pom.xml b/pom.xml index 6008b055e..0f64cffcb 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ teavm-classlib teavm-maven-plugin teavm-samples + teavm-dom diff --git a/teavm-core/src/main/java/org/teavm/javascript/JavascriptNativeProcessor.java b/teavm-core/src/main/java/org/teavm/javascript/JavascriptNativeProcessor.java new file mode 100644 index 000000000..68de6d51b --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/JavascriptNativeProcessor.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.teavm.javascript.ni.JSObject; +import org.teavm.model.*; +import org.teavm.model.instructions.InvokeInstruction; + +/** + * + * @author Alexey Andreev + */ +class JavascriptNativeProcessor { + private ClassHolderSource classSource; + private Map knownJavaScriptClasses = new HashMap<>(); + + public JavascriptNativeProcessor(ClassHolderSource classSource) { + this.classSource = classSource; + knownJavaScriptClasses.put(JSObject.class.getName(), true); + } + + public void processProgram(Program program) { + for (int i = 0; i < program.basicBlockCount(); ++i) { + BasicBlock block = program.basicBlockAt(i); + List instructions = block.getInstructions(); + for (int j = 0; j < instructions.size(); ++j) { + Instruction insn = instructions.get(j); + if (!(insn instanceof InvokeInstruction)) { + continue; + } + } + } + } + + private boolean isJavaScriptClass(String className) { + Boolean known = knownJavaScriptClasses.get(className); + if (known == null) { + known = exploreIfJavaScriptClass(className); + knownJavaScriptClasses.put(className, known); + } + return known; + } + + private boolean exploreIfJavaScriptClass(String className) { + ClassHolder cls = classSource.getClassHolder(className); + if (cls == null || !cls.getModifiers().contains(ElementModifier.INTERFACE)) { + return false; + } + for (String iface : cls.getInterfaces()) { + if (isJavaScriptClass(iface)) { + return true; + } + } + return false; + } +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSArray.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSArray.java new file mode 100644 index 000000000..66621b08b --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSArray.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public interface JSArray extends JSObject, Iterable { + @JSProperty + int getLength(); + + @Override + T get(int index); + + JSArray cast(); +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSConstructor.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSConstructor.java new file mode 100644 index 000000000..0668788e4 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSConstructor.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public interface JSConstructor extends JSFunction { + T construct(); + + T construct(JSObject a); + + T construct(JSObject a, JSObject b); + + T construct(JSObject a, JSObject b, JSObject c); + + T construct(JSObject a, JSObject b, JSObject c, JSObject d); + + T construct(JSObject a, JSObject b, JSObject c, JSObject d, JSObject e); + + T construct(JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f); + + T construct(JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, JSObject g); + + T construct(JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, JSObject g, JSObject h); +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSFunction.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSFunction.java new file mode 100644 index 000000000..5ae2343cb --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSFunction.java @@ -0,0 +1,53 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public interface JSFunction extends JSObject { + @JSProperty + int getLength(); + + @JSProperty + JSString getName(); + + JSObject call(JSObject thisArg); + + JSObject call(JSObject thisArg, JSObject a); + + JSObject call(JSObject thisArg, JSObject a, JSObject b); + + JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c); + + JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c, + JSObject d); + + JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e); + + JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e, JSObject f); + + JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e, JSObject f, JSObject g); + + JSObject call(JSObject thisArg, JSObject a, JSObject b, JSObject c, + JSObject d, JSObject e, JSObject f, JSObject g, JSObject h); + + JSObject apply(JSObject thisArg, JSObject[] arguments); +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSFunctor.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSFunctor.java new file mode 100644 index 000000000..531751f31 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSFunctor.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author Alexey Andreev + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface JSFunctor { +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSGlobal.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSGlobal.java new file mode 100644 index 000000000..e7dc3de87 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSGlobal.java @@ -0,0 +1,28 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public interface JSGlobal extends JSObject { + @JSProperty + JSConstructor> getArray(); + + @JSProperty + JSConstructor getObject(); +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSMethod.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSMethod.java new file mode 100644 index 000000000..6925983e4 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSMethod.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author Alexey Andreev + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface JSMethod { + String value() default ""; +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSNumber.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSNumber.java new file mode 100644 index 000000000..60862b353 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSNumber.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public interface JSNumber extends JSObject { +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSObject.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSObject.java new file mode 100644 index 000000000..3ba0b3144 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSObject.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public interface JSObject { + @JSProperty + JSObject getPrototype(); + + JSObject get(String name); + + void set(String name, JSObject obj); + + JSObject get(JSString name); + + void set(JSString name, JSObject obj); + + JSObject get(int index); + + void set(int index, JSObject obj); + + JSObject invoke(String method); + + JSObject invoke(String method, JSObject a); + + JSObject invoke(String method, JSObject a, JSObject b); + + JSObject invoke(String method, JSObject a, JSObject b, JSObject c); + + JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d); + + JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e); + + JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f); + + JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, JSObject g); + + JSObject invoke(String method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, + JSObject g, JSObject h); + + JSObject invoke(JSString method); + + JSObject invoke(JSString method, JSObject a); + + JSObject invoke(JSString method, JSObject a, JSObject b); + + JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c); + + JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d); + + JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e); + + JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f); + + JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, + JSObject g); + + JSObject invoke(JSString method, JSObject a, JSObject b, JSObject c, JSObject d, JSObject e, JSObject f, + JSObject g, JSObject h); + + @JSProperty + boolean hasOwnProperty(String property); + + @JSProperty + boolean hasOwnProperty(JSString property); + + boolean asBoolean(); + + int asInteger(); + + double asNumber(); + + String asString(); + + boolean isNull(); + + boolean isUndefined(); + + @JSMethod("toString") + JSString toJSString(); +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSProperty.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSProperty.java new file mode 100644 index 000000000..df49ea071 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSProperty.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author Alexey Andreev + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface JSProperty { + String value() default ""; +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSRoot.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSRoot.java new file mode 100644 index 000000000..0700a55d8 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSRoot.java @@ -0,0 +1,61 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public final class JSRoot { + private JSRoot() { + } + + public static JSType getType(JSObject obj) { + switch (getTypeName(obj).asString()) { + case "boolean": + return JSType.OBJECT; + case "number": + return JSType.NUMBER; + case "string": + return JSType.STRING; + case "function": + return JSType.FUNCTION; + case "object": + return JSType.OBJECT; + case "undefined": + return JSType.UNDEFINED; + } + throw new AssertionError("Unexpected type"); + } + + @GeneratedBy(JSRootNativeGenerator.class) + public static native JSString getTypeName(JSObject obj); + + @GeneratedBy(JSRootNativeGenerator.class) + public static native JSObject getGlobal(); + + @GeneratedBy(JSRootNativeGenerator.class) + public static native JSString wrap(String str); + + @GeneratedBy(JSRootNativeGenerator.class) + public static native JSNumber wrap(int num); + + @GeneratedBy(JSRootNativeGenerator.class) + public static native JSNumber wrap(float num); + + @GeneratedBy(JSRootNativeGenerator.class) + public static native JSNumber wrap(double num); +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSRootNativeGenerator.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSRootNativeGenerator.java new file mode 100644 index 000000000..64deedf66 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSRootNativeGenerator.java @@ -0,0 +1,58 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +import java.io.IOException; +import org.teavm.codegen.SourceWriter; +import org.teavm.model.FieldReference; +import org.teavm.model.MethodReference; + +/** + * + * @author Alexey Andreev + */ +public class JSRootNativeGenerator implements Generator { + @Override + public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) + throws IOException { + switch (methodRef.getName()) { + case "getTypeName": + writer.append("return typeof ").append(context.getParameterName(1)).append(";").softNewLine(); + break; + case "getGlobal": + writer.append("return window;").softNewLine(); + break; + case "wrap": + if (methodRef.getParameterTypes()[0].isObject("java.lang.String")) { + generateWrapString(context, writer); + } else { + writer.append("return ").append(context.getParameterName(1)).append(";").softNewLine(); + } + break; + } + } + + private void generateWrapString(GeneratorContext context, SourceWriter writer) throws IOException { + FieldReference charsField = new FieldReference("java.lang.String", "characters"); + writer.append("var result = \"\";").softNewLine(); + writer.append("var data = ").append(context.getParameterName(1)) + .appendField(charsField).append(".data;").softNewLine(); + writer.append("for (var i = 0; i < data.length; i = (i + 1) | 0) {").indent().softNewLine(); + writer.append("result += String.fromCharCode(data[i]);").softNewLine(); + writer.outdent().append("}").softNewLine(); + writer.append("return result;").softNewLine(); + } +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSString.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSString.java new file mode 100644 index 000000000..a69a0a94d --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSString.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public interface JSString extends JSObject { + +} diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSType.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSType.java new file mode 100644 index 000000000..c056d1557 --- /dev/null +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSType.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.javascript.ni; + +/** + * + * @author Alexey Andreev + */ +public enum JSType { + UNDEFINED, + BOOLEAN, + NUMBER, + STRING, + FUNCTION, + OBJECT +} diff --git a/teavm-dom/.gitignore b/teavm-dom/.gitignore new file mode 100644 index 000000000..968391422 --- /dev/null +++ b/teavm-dom/.gitignore @@ -0,0 +1,4 @@ +/target +.classpath +.project +.settings \ No newline at end of file diff --git a/teavm-dom/pom.xml b/teavm-dom/pom.xml new file mode 100644 index 000000000..4784672b0 --- /dev/null +++ b/teavm-dom/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + + org.teavm + teavm + 0.0.1-SNAPSHOT + + teavm-dom + + + + org.teavm + teavm-core + 0.0.1-SNAPSHOT + true + + + \ No newline at end of file diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/Attr.java b/teavm-dom/src/main/java/org/teavm/dom/core/Attr.java new file mode 100644 index 000000000..50d898b31 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Attr.java @@ -0,0 +1,39 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +import org.teavm.javascript.ni.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface Attr extends Node { + @JSProperty + String getName(); + + @JSProperty + boolean isSpecified(); + + @JSProperty + String getValue(); + + @JSProperty + void setValue(String value); + + @JSProperty + Element getOwnerElement(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/CDATASection.java b/teavm-dom/src/main/java/org/teavm/dom/core/CDATASection.java new file mode 100644 index 000000000..be999f2f3 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/CDATASection.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +/** + * + * @author Alexey Andreev + */ +public interface CDATASection extends Node { + +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/CharacterData.java b/teavm-dom/src/main/java/org/teavm/dom/core/CharacterData.java new file mode 100644 index 000000000..b38cd64be --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/CharacterData.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +import org.teavm.javascript.ni.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface CharacterData extends Node { + @JSProperty + String getData(); + + @JSProperty + void setData(String data); + + @JSProperty + int getLength(); + + String substringData(int offset, int count); + + void appendData(String arg); + + void insertData(int offset, String arg); + + void deleteData(int offset, int count); + + void replaceData(int offset, int count, String arg); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/Comment.java b/teavm-dom/src/main/java/org/teavm/dom/core/Comment.java new file mode 100644 index 000000000..1750f7d77 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Comment.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +/** + * + * @author Alexey Andreev + */ +public interface Comment extends Node { + +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/DOMImplementation.java b/teavm-dom/src/main/java/org/teavm/dom/core/DOMImplementation.java new file mode 100644 index 000000000..36488a5de --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/DOMImplementation.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +import org.teavm.javascript.ni.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface DOMImplementation extends JSObject { +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/Document.java b/teavm-dom/src/main/java/org/teavm/dom/core/Document.java new file mode 100644 index 000000000..ce4ad539b --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Document.java @@ -0,0 +1,61 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +import org.teavm.javascript.ni.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface Document extends Node { + @JSProperty + DocumentType getDoctype(); + + @JSProperty + DOMImplementation getImplementation(); + + @JSProperty + Element getDocumentElement(); + + Element createElement(String tagName); + + DocumentFragment createDocumentFragment(); + + Text createTextNode(String data); + + Comment createComment(String data); + + CDATASection createCDATASection(String data); + + ProcessingInstruction createProcessingInstruction(String target, String data); + + Attr createAttribute(String name); + + EntityReference createEntityReference(String name); + + NodeList getElementsByTagName(); + + T importNode(T importedNode, boolean deep); + + Element createElementNS(String namespaceURI, String qualifiedName); + + Attr createAttributeNS(String namespaceURI, String qualifiedName); + + NodeList getElementsByTagNameNS(String namespaceURI, String localName); + + Element getElementById(String elementId); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/DocumentFragment.java b/teavm-dom/src/main/java/org/teavm/dom/core/DocumentFragment.java new file mode 100644 index 000000000..79841e067 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/DocumentFragment.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +/** + * + * @author Alexey Andreev + */ +public interface DocumentFragment extends Node { + +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/DocumentType.java b/teavm-dom/src/main/java/org/teavm/dom/core/DocumentType.java new file mode 100644 index 000000000..86342b1f5 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/DocumentType.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +/** + * + * @author Alexey Andreev + */ +public interface DocumentType extends Node { + +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/Element.java b/teavm-dom/src/main/java/org/teavm/dom/core/Element.java new file mode 100644 index 000000000..f07a04ef6 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Element.java @@ -0,0 +1,54 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +/** + * + * @author Alexey Andreev + */ +public interface Element extends Node { + String getTagName(); + + String getAttribute(String name); + + void setAttribute(String name, String value); + + void removeAttribute(String name); + + Attr getAttributeNode(String name); + + Attr setAttributeNode(Attr newAttr); + + Attr removeAttributeNode(Attr oldAttr); + + NodeList getElementsByTagName(String name); + + String getAttributeNS(String namespaceURI, String localName); + + void setAttributeNS(String namespaceURI, String qualifiedName, String value); + + void removeAttributeNS(String namespaceURI, String localName); + + Attr getAttributeNodeNS(String namespaceURI, String localName); + + Attr setAttributeNodeNS(Attr newAttr); + + NodeList getElementsByTagNameNS(String namespaceURI, String localName); + + boolean hasAttribute(String name); + + boolean hasAttributeNS(String namespaceURI, String localName); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/EntityReference.java b/teavm-dom/src/main/java/org/teavm/dom/core/EntityReference.java new file mode 100644 index 000000000..c98cf518d --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/EntityReference.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +/** + * + * @author Alexey Andreev + */ +public interface EntityReference extends Node { +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/NamedNodeMap.java b/teavm-dom/src/main/java/org/teavm/dom/core/NamedNodeMap.java new file mode 100644 index 000000000..b15c815a2 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/NamedNodeMap.java @@ -0,0 +1,44 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +import org.teavm.javascript.ni.JSArray; +import org.teavm.javascript.ni.JSObject; +import org.teavm.javascript.ni.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface NamedNodeMap extends JSObject, JSArray { + T getNamedItem(String name); + + T setNamedItem(T arg); + + T removeNamedItem(String name); + + T item(int index); + + @Override + @JSProperty + int getLength(); + + T getNamedItemNS(String namespaceURI, String localName); + + T setNamedItemNS(T arg); + + T removeNamedItemNS(String namespaceURI, String localName); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/Node.java b/teavm-dom/src/main/java/org/teavm/dom/core/Node.java new file mode 100644 index 000000000..947aa1a44 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Node.java @@ -0,0 +1,103 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +import org.teavm.javascript.ni.JSObject; +import org.teavm.javascript.ni.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface Node extends JSObject { + short ELEMENT_NODE = 1; + short ATTRIBUTE_NODE = 2; + short TEXT_NODE = 3; + short CDATA_SECTION_NODE = 4; + short ENTITY_REFERENCE_NODE = 5; + short ENTITY_NODE = 6; + short PROCESSING_INSTRUCTION_NODE = 7; + short COMMENT_NODE = 8; + short DOCUMENT_NODE = 9; + short DOCUMENT_TYPE_NODE = 10; + short DOCUMENT_FRAGMENT_NODE = 11; + short NOTATION_NODE = 12; + + @JSProperty + String getNodeName(); + + @JSProperty + String getNodeValue(); + + @JSProperty + void setNodeValue(String value); + + @JSProperty + short getNodeType(); + + @JSProperty + Node getParentNode(); + + @JSProperty + NodeList getChildNodes(); + + @JSProperty + Node getFirstChild(); + + @JSProperty + Node getLastChild(); + + @JSProperty + Node getPreviousSibling(); + + @JSProperty + Node getNextSibling(); + + @JSProperty + NamedNodeMap getAttributes(); + + Node insertBefore(Node newChild, Node refChild); + + Node replaceChild(Node newChild, Node oldChild); + + Node removeChild(Node oldChild); + + Node appendChild(Node newChild); + + boolean hasChildNodes(); + + boolean hasChildNodesJS(); + + Node cloneNode(boolean deep); + + void normalize(); + + boolean isSupported(String feature, String version); + + @JSProperty + String getNamespaceURI(); + + @JSProperty + String getPrefix(); + + @JSProperty + void setPrefix(String prefix); + + @JSProperty + String getLocalName(); + + boolean hasAttributes(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/NodeList.java b/teavm-dom/src/main/java/org/teavm/dom/core/NodeList.java new file mode 100644 index 000000000..f1246cb76 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/NodeList.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +import org.teavm.javascript.ni.JSArray; +import org.teavm.javascript.ni.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface NodeList extends JSArray { + T item(int index); + + @Override + @JSProperty + int getLength(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/ProcessingInstruction.java b/teavm-dom/src/main/java/org/teavm/dom/core/ProcessingInstruction.java new file mode 100644 index 000000000..728aaa487 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/ProcessingInstruction.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +/** + * + * @author Alexey Andreev + */ +public interface ProcessingInstruction extends Node { + +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/Text.java b/teavm-dom/src/main/java/org/teavm/dom/core/Text.java new file mode 100644 index 000000000..266e230e5 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Text.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +/** + * + * @author Alexey Andreev + */ +public interface Text extends Node { + Text splitText(int offset); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/core/Window.java b/teavm-dom/src/main/java/org/teavm/dom/core/Window.java new file mode 100644 index 000000000..886ad94a8 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Window.java @@ -0,0 +1,36 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.core; + +import org.teavm.javascript.ni.JSGlobal; +import org.teavm.javascript.ni.JSObject; +import org.teavm.javascript.ni.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface Window extends JSGlobal { + @JSProperty + Document getDocument(); + + @JSProperty + Element getBody(); + + void alert(JSObject message); + + void alert(String message); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/events/Event.java b/teavm-dom/src/main/java/org/teavm/dom/events/Event.java new file mode 100644 index 000000000..923e9c71e --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/events/Event.java @@ -0,0 +1,56 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.events; + +import org.teavm.javascript.ni.JSObject; +import org.teavm.javascript.ni.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface Event extends JSObject { + short CAPTURING_PHASE = 1; + short AT_TARGET = 2; + short BUBBLING_PHASE = 3; + + @JSProperty + String getType(); + + @JSProperty + EventTarget getTarget(); + + @JSProperty + EventTarget getCurrentTarget(); + + @JSProperty + short getEventPhase(); + + @JSProperty + boolean isBubbles(); + + @JSProperty + boolean isCancelable(); + + @JSProperty + JSObject getTimeStamp(); + + void stopPropagation(); + + void preventDefault(); + + void initEvent(String eventTypeArg, boolean canBubbleArg, boolean cancelableArg); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/events/EventListener.java b/teavm-dom/src/main/java/org/teavm/dom/events/EventListener.java new file mode 100644 index 000000000..1d633f515 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/events/EventListener.java @@ -0,0 +1,27 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.events; + +import org.teavm.javascript.ni.JSFunctor; + +/** + * + * @author Alexey Andreev + */ +@JSFunctor +public interface EventListener { + void handleEvent(Event evt); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/events/EventTarget.java b/teavm-dom/src/main/java/org/teavm/dom/events/EventTarget.java new file mode 100644 index 000000000..3db94bd7d --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/events/EventTarget.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.events; + +import org.teavm.javascript.ni.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface EventTarget extends JSObject { + void addEventListener(String type, EventListener listener, boolean useCapture); + + void removeEventListener(String type, EventListener listener, boolean useCapture); + + boolean dispatchEvent(Event evt); +}