From f138c837cfea403df10a2fb8c7d3650b24897e2c Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sat, 24 Jan 2015 00:48:06 +0400 Subject: [PATCH] Add DOM APIs --- .../org/teavm/dom/ajax/XMLHttpRequest.java | 2 + .../java/org/teavm/dom/browser/Window.java | 4 ++ .../main/java/org/teavm/dom/core/Node.java | 3 + .../org/teavm/dom/events/KeyboardEvent.java | 64 +++++++++++++++++++ .../java/org/teavm/dom/html/HTMLDocument.java | 9 ++- .../java/org/teavm/dom/html/HTMLElement.java | 22 +++++++ .../main/java/org/teavm/dom/json/JSON.java | 28 ++++++++ 7 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 teavm-dom/src/main/java/org/teavm/dom/events/KeyboardEvent.java create mode 100644 teavm-dom/src/main/java/org/teavm/dom/json/JSON.java diff --git a/teavm-dom/src/main/java/org/teavm/dom/ajax/XMLHttpRequest.java b/teavm-dom/src/main/java/org/teavm/dom/ajax/XMLHttpRequest.java index 88e5adff9..a651390ba 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/ajax/XMLHttpRequest.java +++ b/teavm-dom/src/main/java/org/teavm/dom/ajax/XMLHttpRequest.java @@ -53,6 +53,8 @@ public interface XMLHttpRequest extends JSObject { @JSProperty("onreadystatechange") void setOnReadyStateChange(ReadyStateChangeHandler handler); + void overrideMimeType(String mimeType); + @JSProperty int getReadyState(); 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 b5bc86c4d..a877b3955 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 @@ -17,6 +17,7 @@ package org.teavm.dom.browser; import org.teavm.dom.ajax.XMLHttpRequest; import org.teavm.dom.html.HTMLDocument; +import org.teavm.dom.json.JSON; import org.teavm.dom.typedarrays.*; import org.teavm.jso.JSConstructor; import org.teavm.jso.JSGlobal; @@ -46,6 +47,9 @@ public interface Window extends JSGlobal { void clearInterval(int timeoutId); + @JSProperty("JSON") + JSON getJSON(); + @JSConstructor("XMLHttpRequest") XMLHttpRequest createXMLHttpRequest(); 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 index 12be59886..799765e6c 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/core/Node.java +++ b/teavm-dom/src/main/java/org/teavm/dom/core/Node.java @@ -100,4 +100,7 @@ public interface Node extends JSObject { String getLocalName(); boolean hasAttributes(); + + @JSProperty + Document getOwnerDocument(); } diff --git a/teavm-dom/src/main/java/org/teavm/dom/events/KeyboardEvent.java b/teavm-dom/src/main/java/org/teavm/dom/events/KeyboardEvent.java new file mode 100644 index 000000000..2b5b2e5df --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/events/KeyboardEvent.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 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.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface KeyboardEvent extends Event { + int DOM_KEY_LOCATION_STANDARD = 0x00; + + int DOM_KEY_LOCATION_LEFT = 0x01; + + int DOM_KEY_LOCATION_RIGHT = 0x02; + + int DOM_KEY_LOCATION_NUMPAD = 0x03; + + @JSProperty + String getKey(); + + @JSProperty + int getKeyCode(); + + @JSProperty + String getCode(); + + @JSProperty + int getLocation(); + + @JSProperty + boolean isCtrlKey(); + + @JSProperty + boolean isShiftKey(); + + @JSProperty + boolean isAltKey(); + + @JSProperty + boolean isMetaKey(); + + @JSProperty + boolean isRepeat(); + + @JSProperty("isComposing") + boolean isComposing(); + + boolean getModifierState(String keyArg); +} 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 index 7578cd2af..317d70842 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java @@ -16,13 +16,14 @@ package org.teavm.dom.html; import org.teavm.dom.core.Document; +import org.teavm.dom.events.EventTarget; import org.teavm.jso.JSProperty; /** * * @author Alexey Andreev */ -public interface HTMLDocument extends Document { +public interface HTMLDocument extends Document, EventTarget { @JSProperty @Override HTMLHtmlElement getDocumentElement(); @@ -38,4 +39,10 @@ public interface HTMLDocument extends Document { @JSProperty HTMLElement getHead(); + + @JSProperty + int getScrollLeft(); + + @JSProperty + int getScrollTop(); } 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 index 99b313a5a..fde105ccf 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLElement.java +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLElement.java @@ -80,4 +80,26 @@ public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget @JSProperty String getAccessKeyLabel(); + + @JSProperty + int getClientWidth(); + + @JSProperty + int getClientHeight(); + + @JSProperty + int getAbsoluteLeft(); + + @JSProperty + int getAbsoluteTop(); + + @JSProperty + int getScrollLeft(); + + @JSProperty + int getScrollTop(); + + @JSProperty + @Override + HTMLDocument getOwnerDocument(); } diff --git a/teavm-dom/src/main/java/org/teavm/dom/json/JSON.java b/teavm-dom/src/main/java/org/teavm/dom/json/JSON.java new file mode 100644 index 000000000..bcdbba54a --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/json/JSON.java @@ -0,0 +1,28 @@ +/* + * Copyright 2015 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.json; + +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface JSON extends JSObject { + String stringify(JSObject object); + + JSObject parse(String string); +}