From e206229db4af5779bff6c892b8ea3d87168f4766 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Tue, 6 May 2014 22:55:35 +0400 Subject: [PATCH] Adds several DOM wrappers --- .../classlib/java/util/HashtableTest.java | 4 +- .../java/org/teavm/dom/browser/Window.java | 4 +- .../main/java/org/teavm/dom/core/Element.java | 4 +- .../teavm/dom/css/CSSStyleDeclaration.java | 52 ++++++++++++ .../teavm/dom/css/ElementCSSInlineStyle.java | 28 +++++++ .../java/org/teavm/dom/html/HTMLDocument.java | 35 ++++++++ .../java/org/teavm/dom/html/HTMLElement.java | 83 +++++++++++++++++++ 7 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 teavm-dom/src/main/java/org/teavm/dom/css/CSSStyleDeclaration.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/css/ElementCSSInlineStyle.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/html/HTMLElement.java diff --git a/teavm-classlib/src/test/java/org/teavm/classlib/java/util/HashtableTest.java b/teavm-classlib/src/test/java/org/teavm/classlib/java/util/HashtableTest.java index 95a5581bb..569df25cd 100644 --- a/teavm-classlib/src/test/java/org/teavm/classlib/java/util/HashtableTest.java +++ b/teavm-classlib/src/test/java/org/teavm/classlib/java/util/HashtableTest.java @@ -157,7 +157,9 @@ public class HashtableTest { String okey, ckey; while (org.hasMoreElements()) { - assertTrue("Key comparison failed", (okey = org.nextElement()).equals(ckey = cpy.nextElement())); + okey = org.nextElement(); + ckey = cpy.nextElement(); + assertTrue("Key comparison failed", okey.equals(ckey)); assertTrue("Value comparison failed", (htfull.get(okey)).equals(h.get(ckey))); } assertTrue("Copy has more keys than original", !cpy.hasMoreElements()); diff --git a/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java b/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java index 3ee4f5a48..7793a0dc5 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java +++ b/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java @@ -15,7 +15,7 @@ */ package org.teavm.dom.browser; -import org.teavm.dom.core.Document; +import org.teavm.dom.html.HTMLDocument; import org.teavm.jso.JSGlobal; import org.teavm.jso.JSObject; import org.teavm.jso.JSProperty; @@ -26,7 +26,7 @@ import org.teavm.jso.JSProperty; */ public interface Window extends JSGlobal { @JSProperty - Document getDocument(); + HTMLDocument getDocument(); void alert(JSObject message); 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 index f07a04ef6..d21f91f38 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/core/Element.java +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Element.java @@ -34,7 +34,7 @@ public interface Element extends Node { Attr removeAttributeNode(Attr oldAttr); - NodeList getElementsByTagName(String name); + NodeList getElementsByTagName(String name); String getAttributeNS(String namespaceURI, String localName); @@ -46,7 +46,7 @@ public interface Element extends Node { Attr setAttributeNodeNS(Attr newAttr); - NodeList getElementsByTagNameNS(String namespaceURI, String localName); + NodeList getElementsByTagNameNS(String namespaceURI, String localName); boolean hasAttribute(String name); diff --git a/teavm-dom/src/main/java/org/teavm/dom/css/CSSStyleDeclaration.java b/teavm-dom/src/main/java/org/teavm/dom/css/CSSStyleDeclaration.java new file mode 100644 index 000000000..a96a1b257 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/css/CSSStyleDeclaration.java @@ -0,0 +1,52 @@ +/* + * 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.css; + +import org.teavm.jso.JSIndexer; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface CSSStyleDeclaration extends JSObject { + @JSProperty + String getCssText(); + + @JSProperty + void setCssText(String cssText); + + @JSProperty + int getLength(); + + @JSIndexer + String item(int index); + + String getPropertyValue(String property); + + String getPropertyPriority(String property); + + void setProperty(String property, String value); + + void setProperty(String property, String value, String priority); + + void setPropertyValue(String property, String value); + + void setPropertyPriority(String property, String priority); + + String removeProperty(String property); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/css/ElementCSSInlineStyle.java b/teavm-dom/src/main/java/org/teavm/dom/css/ElementCSSInlineStyle.java new file mode 100644 index 000000000..67ad3387a --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/css/ElementCSSInlineStyle.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.dom.css; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface ElementCSSInlineStyle extends JSObject { + @JSProperty + CSSStyleDeclaration getStyle(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java new file mode 100644 index 000000000..c7e411654 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java @@ -0,0 +1,35 @@ +/* + * 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.html; + +import org.teavm.dom.core.Document; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface HTMLDocument extends Document { + @JSProperty + @Override + HTMLElement getDocumentElement(); + + @Override + HTMLElement createElement(String tagName); + + @Override + HTMLElement getElementById(String elementId); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLElement.java b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLElement.java new file mode 100644 index 000000000..99b313a5a --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLElement.java @@ -0,0 +1,83 @@ +/* + * 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.html; + +import org.teavm.dom.core.Element; +import org.teavm.dom.core.NodeList; +import org.teavm.dom.css.ElementCSSInlineStyle; +import org.teavm.dom.events.EventTarget; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget { + @Override + @JSProperty + NodeList getElementsByTagName(String name); + + @JSProperty + String getTitle(); + + @JSProperty + void setTitle(String title); + + @JSProperty + String getLang(); + + @JSProperty + void setLang(String lang); + + @JSProperty + boolean isTranslate(); + + @JSProperty + void setTranslate(boolean translate); + + @JSProperty + String getDir(); + + @JSProperty + void setDir(String dir); + + @JSProperty + boolean isHidden(); + + @JSProperty + void setHidden(boolean hidden); + + void click(); + + @JSProperty + int getTabIndex(); + + @JSProperty + void setTabIndex(int tabIndex); + + void focus(); + + void blur(); + + @JSProperty + String getAccessKey(); + + @JSProperty + void setAccessKey(String accessKey); + + @JSProperty + String getAccessKeyLabel(); +}