diff --git a/jso/apis/src/main/java/org/teavm/jso/ajax/ProgressEvent.java b/jso/apis/src/main/java/org/teavm/jso/ajax/ProgressEvent.java new file mode 100644 index 000000000..db550953c --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/ajax/ProgressEvent.java @@ -0,0 +1,30 @@ +/* + * Copyright 2023 ihromant. + * + * 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.jso.ajax; + +import org.teavm.jso.JSProperty; +import org.teavm.jso.dom.events.Event; + +public interface ProgressEvent extends Event { + @JSProperty + boolean isLengthComputable(); + + @JSProperty + int getLoaded(); + + @JSProperty + int getTotal(); +} diff --git a/jso/apis/src/main/java/org/teavm/jso/ajax/XMLHttpRequest.java b/jso/apis/src/main/java/org/teavm/jso/ajax/XMLHttpRequest.java index 3edc20e97..bcecfa1b9 100644 --- a/jso/apis/src/main/java/org/teavm/jso/ajax/XMLHttpRequest.java +++ b/jso/apis/src/main/java/org/teavm/jso/ajax/XMLHttpRequest.java @@ -18,9 +18,12 @@ package org.teavm.jso.ajax; import org.teavm.jso.JSBody; import org.teavm.jso.JSObject; import org.teavm.jso.JSProperty; +import org.teavm.jso.dom.events.Event; +import org.teavm.jso.dom.events.EventListener; +import org.teavm.jso.dom.events.EventTarget; import org.teavm.jso.dom.xml.Document; -public abstract class XMLHttpRequest implements JSObject { +public abstract class XMLHttpRequest implements JSObject, EventTarget { public static final int UNSET = 0; public static final int OPENED = 1; @@ -54,6 +57,30 @@ public abstract class XMLHttpRequest implements JSObject { @JSProperty("onreadystatechange") public abstract void setOnReadyStateChange(ReadyStateChangeHandler handler); + @JSProperty("onreadystatechange") + public abstract void setOnReadyStateChange(EventListener handler); + + @JSProperty("onabort") + public abstract void onAbort(EventListener eventListener); + + @JSProperty("onerror") + public abstract void onError(EventListener eventListener); + + @JSProperty("onload") + public abstract void onLoad(EventListener eventListener); + + @JSProperty("onloadstart") + public abstract void onLoadStart(EventListener eventListener); + + @JSProperty("onloadend") + public abstract void onLoadEnd(EventListener eventListener); + + @JSProperty("onprogress") + public abstract void onProgress(EventListener eventListener); + + @JSProperty("ontimeout") + public abstract void onTimeout(EventListener eventListener); + public final void onComplete(Runnable runnable) { setOnReadyStateChange(() -> { if (getReadyState() == DONE) { diff --git a/jso/apis/src/main/java/org/teavm/jso/websocket/WebSocket.java b/jso/apis/src/main/java/org/teavm/jso/websocket/WebSocket.java index 48079f199..b58b6c632 100644 --- a/jso/apis/src/main/java/org/teavm/jso/websocket/WebSocket.java +++ b/jso/apis/src/main/java/org/teavm/jso/websocket/WebSocket.java @@ -35,7 +35,7 @@ public abstract class WebSocket implements JSObject { public abstract void onMessage(EventListener eventListener); @JSProperty("onopen") - public abstract void onOpen(EventListener eventListener); + public abstract void onOpen(EventListener eventListener); @JSBody(params = "url", script = "return new WebSocket(url);") public static native WebSocket create(String url);