mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 00:04:10 -08:00
jso apis: new convention for event registration
This commit is contained in:
parent
272f55b383
commit
97aa42d87b
|
@ -22,6 +22,7 @@ import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.Event;
|
import org.teavm.jso.dom.events.Event;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
import org.teavm.jso.dom.events.EventTarget;
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
import org.teavm.jso.dom.xml.Document;
|
import org.teavm.jso.dom.xml.Document;
|
||||||
|
|
||||||
@JSClass
|
@JSClass
|
||||||
|
@ -65,29 +66,40 @@ public class XMLHttpRequest implements JSObject, EventTarget {
|
||||||
@JSProperty("onreadystatechange")
|
@JSProperty("onreadystatechange")
|
||||||
public native void setOnReadyStateChange(EventListener<Event> handler);
|
public native void setOnReadyStateChange(EventListener<Event> handler);
|
||||||
|
|
||||||
@JSProperty("onabort")
|
public final Registration onReadyStateChange(EventListener<Event> handler) {
|
||||||
public native void onAbort(EventListener<ProgressEvent> eventListener);
|
return onEvent("readystatechange", handler);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onerror")
|
public final Registration onAbort(EventListener<ProgressEvent> eventListener) {
|
||||||
public native void onError(EventListener<ProgressEvent> eventListener);
|
return onEvent("abort", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onload")
|
public final Registration onError(EventListener<ProgressEvent> eventListener) {
|
||||||
public native void onLoad(EventListener<ProgressEvent> eventListener);
|
return onEvent("error", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onloadstart")
|
public final Registration onLoad(EventListener<ProgressEvent> eventListener) {
|
||||||
public native void onLoadStart(EventListener<ProgressEvent> eventListener);
|
return onEvent("load", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onloadend")
|
public final Registration onLoadStart(EventListener<ProgressEvent> eventListener) {
|
||||||
public native void onLoadEnd(EventListener<ProgressEvent> eventListener);
|
return onEvent("loadstart", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onprogress")
|
public final Registration onLoadEnd(EventListener<ProgressEvent> eventListener) {
|
||||||
public native void onProgress(EventListener<ProgressEvent> eventListener);
|
return onEvent("loadend", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("ontimeout")
|
public final Registration onProgress(EventListener<ProgressEvent> eventListener) {
|
||||||
public native void onTimeout(EventListener<ProgressEvent> eventListener);
|
return onEvent("progress", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
public final void onComplete(Runnable runnable) {
|
public final Registration onTimeout(EventListener<ProgressEvent> eventListener) {
|
||||||
setOnReadyStateChange(() -> {
|
return onEvent("timeout", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Registration onComplete(Runnable runnable) {
|
||||||
|
return onReadyStateChange(event -> {
|
||||||
if (getReadyState() == DONE) {
|
if (getReadyState() == DONE) {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,30 +25,54 @@ import org.teavm.jso.dom.events.KeyboardEventTarget;
|
||||||
import org.teavm.jso.dom.events.LoadEventTarget;
|
import org.teavm.jso.dom.events.LoadEventTarget;
|
||||||
import org.teavm.jso.dom.events.MessageEvent;
|
import org.teavm.jso.dom.events.MessageEvent;
|
||||||
import org.teavm.jso.dom.events.MouseEventTarget;
|
import org.teavm.jso.dom.events.MouseEventTarget;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
import org.teavm.jso.dom.events.StorageEvent;
|
||||||
|
|
||||||
public interface WindowEventTarget extends EventTarget, FocusEventTarget, MouseEventTarget, KeyboardEventTarget,
|
public interface WindowEventTarget extends EventTarget, FocusEventTarget, MouseEventTarget, KeyboardEventTarget,
|
||||||
LoadEventTarget, GamepadEventTarget {
|
LoadEventTarget, GamepadEventTarget {
|
||||||
|
@Deprecated
|
||||||
default void listenBeforeOnload(EventListener<Event> listener) {
|
default void listenBeforeOnload(EventListener<Event> listener) {
|
||||||
addEventListener("beforeunload", listener);
|
addEventListener("beforeunload", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectBeforeOnload(EventListener<Event> listener) {
|
default void neglectBeforeOnload(EventListener<Event> listener) {
|
||||||
removeEventListener("beforeunload", listener);
|
removeEventListener("beforeunload", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenMessage(EventListener<MessageEvent> listener) {
|
default void listenMessage(EventListener<MessageEvent> listener) {
|
||||||
addEventListener("message", listener);
|
addEventListener("message", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectMessage(EventListener<MessageEvent> listener) {
|
default void neglectMessage(EventListener<MessageEvent> listener) {
|
||||||
removeEventListener("message", listener);
|
removeEventListener("message", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenHashChange(EventListener<HashChangeEvent> listener) {
|
default void listenHashChange(EventListener<HashChangeEvent> listener) {
|
||||||
addEventListener("hashchange", listener);
|
addEventListener("hashchange", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectHashChange(EventListener<HashChangeEvent> listener) {
|
default void neglectHashChange(EventListener<HashChangeEvent> listener) {
|
||||||
removeEventListener("hashchange", listener);
|
removeEventListener("hashchange", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Registration onBeforeUnload(EventListener<Event> listener) {
|
||||||
|
return onEvent("beforeunload", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onMessage(EventListener<MessageEvent> listener) {
|
||||||
|
return onEvent("message", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onHashChange(EventListener<HashChangeEvent> listener) {
|
||||||
|
return onEvent("hashchange", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onStorage(EventListener<StorageEvent> listener) {
|
||||||
|
return onEvent("storage", listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,14 @@ public interface EventTarget extends JSObject {
|
||||||
void removeEventListener(String type, EventListener<?> listener);
|
void removeEventListener(String type, EventListener<?> listener);
|
||||||
|
|
||||||
boolean dispatchEvent(Event evt);
|
boolean dispatchEvent(Event evt);
|
||||||
|
|
||||||
|
default Registration onEvent(String type, boolean useCapture, EventListener<?> listener) {
|
||||||
|
addEventListener(type, listener, useCapture);
|
||||||
|
return new Registration(this, type, listener, useCapture);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onEvent(String type, EventListener<?> listener) {
|
||||||
|
addEventListener(type, listener);
|
||||||
|
return new Registration(this, type, listener, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,31 @@
|
||||||
package org.teavm.jso.dom.events;
|
package org.teavm.jso.dom.events;
|
||||||
|
|
||||||
public interface FocusEventTarget extends EventTarget {
|
public interface FocusEventTarget extends EventTarget {
|
||||||
|
@Deprecated
|
||||||
default void listenFocus(EventListener<Event> listener) {
|
default void listenFocus(EventListener<Event> listener) {
|
||||||
addEventListener("focus", listener);
|
addEventListener("focus", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectFocus(EventListener<Event> listener) {
|
default void neglectFocus(EventListener<Event> listener) {
|
||||||
removeEventListener("focus", listener);
|
removeEventListener("focus", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenBlur(EventListener<Event> listener) {
|
default void listenBlur(EventListener<Event> listener) {
|
||||||
addEventListener("blur", listener);
|
addEventListener("blur", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectBlur(EventListener<Event> listener) {
|
default void neglectBlur(EventListener<Event> listener) {
|
||||||
removeEventListener("blur", listener);
|
removeEventListener("blur", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Registration onFocus(EventListener<? super Event> listener) {
|
||||||
|
return onEvent("focus", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onBlur(EventListener<? super Event> listener) {
|
||||||
|
return onEvent("blur", listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,20 +18,31 @@ package org.teavm.jso.dom.events;
|
||||||
import org.teavm.jso.gamepad.GamepadEvent;
|
import org.teavm.jso.gamepad.GamepadEvent;
|
||||||
|
|
||||||
public interface GamepadEventTarget extends EventTarget {
|
public interface GamepadEventTarget extends EventTarget {
|
||||||
|
@Deprecated
|
||||||
default void listenGamepadConnected(EventListener<GamepadEvent> listener) {
|
default void listenGamepadConnected(EventListener<GamepadEvent> listener) {
|
||||||
addEventListener("gamepadconnected", listener);
|
addEventListener("gamepadconnected", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectGamepadConnected(EventListener<GamepadEvent> listener) {
|
default void neglectGamepadConnected(EventListener<GamepadEvent> listener) {
|
||||||
removeEventListener("gamepadconnected", listener);
|
removeEventListener("gamepadconnected", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenGamepadDisconnected(EventListener<GamepadEvent> listener) {
|
default void listenGamepadDisconnected(EventListener<GamepadEvent> listener) {
|
||||||
addEventListener("gamepaddisconnected", listener);
|
addEventListener("gamepaddisconnected", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectGamepadDisconnected(EventListener<GamepadEvent> listener) {
|
default void neglectGamepadDisconnected(EventListener<GamepadEvent> listener) {
|
||||||
removeEventListener("gamepaddisconnected", listener);
|
removeEventListener("gamepaddisconnected", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Registration onGamepadConnected(EventListener<? super Event> listener) {
|
||||||
|
return onEvent("gamepadconnected", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onGamepadDisconnected(EventListener<? super Event> listener) {
|
||||||
|
return onEvent("gamepaddisconnected", listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,27 +16,45 @@
|
||||||
package org.teavm.jso.dom.events;
|
package org.teavm.jso.dom.events;
|
||||||
|
|
||||||
public interface KeyboardEventTarget extends EventTarget {
|
public interface KeyboardEventTarget extends EventTarget {
|
||||||
|
@Deprecated
|
||||||
default void listenKeyDown(EventListener<KeyboardEvent> listener) {
|
default void listenKeyDown(EventListener<KeyboardEvent> listener) {
|
||||||
addEventListener("keydown", listener);
|
addEventListener("keydown", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectKeyDown(EventListener<KeyboardEvent> listener) {
|
default void neglectKeyDown(EventListener<KeyboardEvent> listener) {
|
||||||
removeEventListener("keydown", listener);
|
removeEventListener("keydown", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenKeyUp(EventListener<KeyboardEvent> listener) {
|
default void listenKeyUp(EventListener<KeyboardEvent> listener) {
|
||||||
addEventListener("keyup", listener);
|
addEventListener("keyup", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectKeyUp(EventListener<KeyboardEvent> listener) {
|
default void neglectKeyUp(EventListener<KeyboardEvent> listener) {
|
||||||
removeEventListener("keyup", listener);
|
removeEventListener("keyup", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenKeyPress(EventListener<KeyboardEvent> listener) {
|
default void listenKeyPress(EventListener<KeyboardEvent> listener) {
|
||||||
addEventListener("keypress", listener);
|
addEventListener("keypress", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectKeyPress(EventListener<KeyboardEvent> listener) {
|
default void neglectKeyPress(EventListener<KeyboardEvent> listener) {
|
||||||
removeEventListener("keypress", listener);
|
removeEventListener("keypress", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Registration onKeyDown(EventListener<KeyboardEvent> listener) {
|
||||||
|
return onEvent("keydown", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onKeyUp(EventListener<KeyboardEvent> listener) {
|
||||||
|
return onEvent("keyup", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onKeyPress(EventListener<KeyboardEvent> listener) {
|
||||||
|
return onEvent("keypress", listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,17 @@
|
||||||
package org.teavm.jso.dom.events;
|
package org.teavm.jso.dom.events;
|
||||||
|
|
||||||
public interface LoadEventTarget extends EventTarget {
|
public interface LoadEventTarget extends EventTarget {
|
||||||
|
@Deprecated
|
||||||
default void listenLoad(EventListener<Event> listener) {
|
default void listenLoad(EventListener<Event> listener) {
|
||||||
addEventListener("load", listener);
|
addEventListener("load", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectLoad(EventListener<Event> listener) {
|
default void neglectLoad(EventListener<Event> listener) {
|
||||||
addEventListener("load", listener);
|
addEventListener("load", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Registration onLoad(EventListener<Event> listener) {
|
||||||
|
return onEvent("load", listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,75 +16,129 @@
|
||||||
package org.teavm.jso.dom.events;
|
package org.teavm.jso.dom.events;
|
||||||
|
|
||||||
public interface MouseEventTarget extends EventTarget {
|
public interface MouseEventTarget extends EventTarget {
|
||||||
|
@Deprecated
|
||||||
default void listenClick(EventListener<MouseEvent> listener) {
|
default void listenClick(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("click", listener);
|
addEventListener("click", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectClick(EventListener<MouseEvent> listener) {
|
default void neglectClick(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("click", listener);
|
removeEventListener("click", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenDoubleClick(EventListener<MouseEvent> listener) {
|
default void listenDoubleClick(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("dblclick", listener);
|
addEventListener("dblclick", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectDoubleClick(EventListener<MouseEvent> listener) {
|
default void neglectDoubleClick(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("dblclick", listener);
|
removeEventListener("dblclick", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenMouseDown(EventListener<MouseEvent> listener) {
|
default void listenMouseDown(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("mousedown", listener);
|
addEventListener("mousedown", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectMouseDown(EventListener<MouseEvent> listener) {
|
default void neglectMouseDown(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("mousedown", listener);
|
removeEventListener("mousedown", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenMouseUp(EventListener<MouseEvent> listener) {
|
default void listenMouseUp(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("mouseup", listener);
|
addEventListener("mouseup", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectMouseUp(EventListener<MouseEvent> listener) {
|
default void neglectMouseUp(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("mouseup", listener);
|
removeEventListener("mouseup", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenMouseMove(EventListener<MouseEvent> listener) {
|
default void listenMouseMove(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("mousemove", listener);
|
addEventListener("mousemove", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectMouseMove(EventListener<MouseEvent> listener) {
|
default void neglectMouseMove(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("mousemove", listener);
|
removeEventListener("mousemove", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenMouseOver(EventListener<MouseEvent> listener) {
|
default void listenMouseOver(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("mouseover", listener);
|
addEventListener("mouseover", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectMouseOver(EventListener<MouseEvent> listener) {
|
default void neglectMouseOver(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("mouseover", listener);
|
removeEventListener("mouseover", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenMouseEnter(EventListener<MouseEvent> listener) {
|
default void listenMouseEnter(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("mouseenter", listener);
|
addEventListener("mouseenter", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectMouseEnter(EventListener<MouseEvent> listener) {
|
default void neglectMouseEnter(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("mouseenter", listener);
|
removeEventListener("mouseenter", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenMouseLeave(EventListener<MouseEvent> listener) {
|
default void listenMouseLeave(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("mouseleave", listener);
|
addEventListener("mouseleave", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectMouseLeave(EventListener<MouseEvent> listener) {
|
default void neglectMouseLeave(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("mouseleave", listener);
|
removeEventListener("mouseleave", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void listenMouseOut(EventListener<MouseEvent> listener) {
|
default void listenMouseOut(EventListener<MouseEvent> listener) {
|
||||||
addEventListener("mouseout", listener);
|
addEventListener("mouseout", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectMouseOut(EventListener<MouseEvent> listener) {
|
default void neglectMouseOut(EventListener<MouseEvent> listener) {
|
||||||
removeEventListener("mouseout", listener);
|
removeEventListener("mouseout", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Registration onClick(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("click", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onDoubleClick(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("dblclick", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onMouseDown(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("mousedown", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onMouseUp(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("mouseup", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onMouseMove(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("mousemove", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onMouseOver(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("mouseover", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onMouseEnter(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("mouseenter", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onMouseLeave(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("mouseleave", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Registration onMouseOut(EventListener<MouseEvent> listener) {
|
||||||
|
return onEvent("mouseout", listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 konsoletyper.
|
||||||
|
*
|
||||||
|
* 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.dom.events;
|
||||||
|
|
||||||
|
public class Registration {
|
||||||
|
private EventTarget target;
|
||||||
|
private String type;
|
||||||
|
private EventListener<?> listener;
|
||||||
|
private Boolean useCapture;
|
||||||
|
|
||||||
|
Registration(EventTarget target, String type, EventListener<?> listener, Boolean useCapture) {
|
||||||
|
this.target = target;
|
||||||
|
this.type = type;
|
||||||
|
this.listener = listener;
|
||||||
|
this.useCapture = useCapture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
if (target != null) {
|
||||||
|
if (useCapture != null) {
|
||||||
|
target.removeEventListener(type, listener, useCapture);
|
||||||
|
} else {
|
||||||
|
target.removeEventListener(type, listener);
|
||||||
|
}
|
||||||
|
target = null;
|
||||||
|
type = null;
|
||||||
|
listener = null;
|
||||||
|
useCapture = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,10 +18,6 @@ package org.teavm.jso.dom.events;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.browser.Storage;
|
import org.teavm.jso.browser.Storage;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Junji Takakura
|
|
||||||
*/
|
|
||||||
public interface StorageEvent extends Event {
|
public interface StorageEvent extends Event {
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
|
|
|
@ -16,11 +16,17 @@
|
||||||
package org.teavm.jso.dom.events;
|
package org.teavm.jso.dom.events;
|
||||||
|
|
||||||
public interface WheelEventTarget extends EventTarget {
|
public interface WheelEventTarget extends EventTarget {
|
||||||
|
@Deprecated
|
||||||
default void listenWheel(EventListener<WheelEvent> listener) {
|
default void listenWheel(EventListener<WheelEvent> listener) {
|
||||||
addEventListener("wheel", listener);
|
addEventListener("wheel", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default void neglectWheel(EventListener<WheelEvent> listener) {
|
default void neglectWheel(EventListener<WheelEvent> listener) {
|
||||||
removeEventListener("wheel", listener);
|
removeEventListener("wheel", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Registration onWheel(EventListener<WheelEvent> listener) {
|
||||||
|
return onEvent("wheel", listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,6 @@ package org.teavm.jso.geolocation;
|
||||||
import org.teavm.jso.JSFunctor;
|
import org.teavm.jso.JSFunctor;
|
||||||
import org.teavm.jso.JSObject;
|
import org.teavm.jso.JSObject;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@JSFunctor
|
@JSFunctor
|
||||||
public interface PositionHandler extends JSObject {
|
public interface PositionHandler extends JSObject {
|
||||||
void handlePosition(Position position);
|
void handlePosition(Position position);
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.jso.webaudio;
|
||||||
|
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface AudioBufferSourceNode extends AudioNode {
|
public interface AudioBufferSourceNode extends AudioNode {
|
||||||
@JSProperty
|
@JSProperty
|
||||||
|
@ -55,6 +56,10 @@ public interface AudioBufferSourceNode extends AudioNode {
|
||||||
@JSProperty("onended")
|
@JSProperty("onended")
|
||||||
EventListener<MediaEvent> getOnEnded();
|
EventListener<MediaEvent> getOnEnded();
|
||||||
|
|
||||||
|
default Registration onEnded(EventListener<MediaEvent> eventListener) {
|
||||||
|
return onEvent("ended", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
void start(double when, double offset, double duration);
|
void start(double when, double offset, double duration);
|
||||||
|
|
||||||
void start(double when, double offset);
|
void start(double when, double offset);
|
||||||
|
|
|
@ -20,13 +20,16 @@ import org.teavm.jso.JSByRef;
|
||||||
import org.teavm.jso.JSClass;
|
import org.teavm.jso.JSClass;
|
||||||
import org.teavm.jso.JSObject;
|
import org.teavm.jso.JSObject;
|
||||||
import org.teavm.jso.JSProperty;
|
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.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
import org.teavm.jso.dom.html.HTMLMediaElement;
|
import org.teavm.jso.dom.html.HTMLMediaElement;
|
||||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||||
import org.teavm.jso.typedarrays.Float32Array;
|
import org.teavm.jso.typedarrays.Float32Array;
|
||||||
|
|
||||||
@JSClass
|
@JSClass
|
||||||
public class AudioContext implements JSObject {
|
public class AudioContext implements JSObject, EventTarget {
|
||||||
public static final String STATE_SUSPENDED = "suspended";
|
public static final String STATE_SUSPENDED = "suspended";
|
||||||
public static final String STATE_RUNNING = "running";
|
public static final String STATE_RUNNING = "running";
|
||||||
public static final String STATE_CLOSE = "close";
|
public static final String STATE_CLOSE = "close";
|
||||||
|
@ -52,6 +55,10 @@ public class AudioContext implements JSObject {
|
||||||
@JSProperty("onstatechange")
|
@JSProperty("onstatechange")
|
||||||
public native EventListener<MediaEvent> getOnStateChange();
|
public native EventListener<MediaEvent> getOnStateChange();
|
||||||
|
|
||||||
|
public final Registration onStateChange(EventListener<MediaEvent> listener) {
|
||||||
|
return onEvent("statechange", listener);
|
||||||
|
}
|
||||||
|
|
||||||
public native void suspend();
|
public native void suspend();
|
||||||
|
|
||||||
public native void resume();
|
public native void resume();
|
||||||
|
@ -131,4 +138,19 @@ public class AudioContext implements JSObject {
|
||||||
@JSBody(script = "return new Context();")
|
@JSBody(script = "return new Context();")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static native AudioContext create();
|
public static native AudioContext create();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native void addEventListener(String type, EventListener<?> listener, boolean useCapture);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native void addEventListener(String type, EventListener<?> listener);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native void removeEventListener(String type, EventListener<?> listener, boolean useCapture);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native void removeEventListener(String type, EventListener<?> listener);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native boolean dispatchEvent(Event evt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,9 @@ package org.teavm.jso.webaudio;
|
||||||
|
|
||||||
import org.teavm.jso.JSObject;
|
import org.teavm.jso.JSObject;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
|
|
||||||
public interface AudioNode extends JSObject {
|
public interface AudioNode extends JSObject, EventTarget {
|
||||||
String CHANNEL_COUNT_MODE_MAX = "max";
|
String CHANNEL_COUNT_MODE_MAX = "max";
|
||||||
String CHANNEL_COUNT_MODE_CLAMPED_MAX = "clamped-max";
|
String CHANNEL_COUNT_MODE_CLAMPED_MAX = "clamped-max";
|
||||||
String CHANNEL_COUNT_MODE_EXPLICIT = "explicit";
|
String CHANNEL_COUNT_MODE_EXPLICIT = "explicit";
|
||||||
|
|
|
@ -19,8 +19,10 @@ import org.teavm.jso.JSByRef;
|
||||||
import org.teavm.jso.JSObject;
|
import org.teavm.jso.JSObject;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface AudioWorker extends JSObject {
|
public interface AudioWorker extends EventTarget {
|
||||||
@JSProperty
|
@JSProperty
|
||||||
AudioWorkerParamDescriptor[] getParameters();
|
AudioWorkerParamDescriptor[] getParameters();
|
||||||
|
|
||||||
|
@ -30,12 +32,20 @@ public interface AudioWorker extends JSObject {
|
||||||
@JSProperty(value = "onmessage")
|
@JSProperty(value = "onmessage")
|
||||||
EventListener<MediaEvent> getOnMessage();
|
EventListener<MediaEvent> getOnMessage();
|
||||||
|
|
||||||
|
default Registration onMessage(EventListener<MediaEvent> listener) {
|
||||||
|
return onEvent("message", listener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty(value = "onloaded")
|
@JSProperty(value = "onloaded")
|
||||||
void setOnLoaded(EventListener<MediaEvent> event);
|
void setOnLoaded(EventListener<MediaEvent> event);
|
||||||
|
|
||||||
@JSProperty(value = "onloaded")
|
@JSProperty(value = "onloaded")
|
||||||
EventListener<MediaEvent> getOnLoaded();
|
EventListener<MediaEvent> getOnLoaded();
|
||||||
|
|
||||||
|
default Registration onLoaded(EventListener<MediaEvent> listener) {
|
||||||
|
return onEvent("loaded", listener);
|
||||||
|
}
|
||||||
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
void postMessage(JSObject message, @JSByRef JSObject[] transfer);
|
void postMessage(JSObject message, @JSByRef JSObject[] transfer);
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.jso.webaudio;
|
package org.teavm.jso.webaudio;
|
||||||
|
|
||||||
import org.teavm.jso.JSObject;
|
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface AudioWorkerGlobalScope extends JSObject {
|
public interface AudioWorkerGlobalScope extends EventTarget {
|
||||||
@JSProperty
|
@JSProperty
|
||||||
float getSampleRate();
|
float getSampleRate();
|
||||||
|
|
||||||
|
@ -29,12 +30,20 @@ public interface AudioWorkerGlobalScope extends JSObject {
|
||||||
@JSProperty("onaudioprocess")
|
@JSProperty("onaudioprocess")
|
||||||
EventListener<MediaEvent> getOnAudioProcess();
|
EventListener<MediaEvent> getOnAudioProcess();
|
||||||
|
|
||||||
|
default Registration onAudioProcess(EventListener<MediaEvent> listener) {
|
||||||
|
return onEvent("audioprocess", listener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onnodecreate")
|
@JSProperty("onnodecreate")
|
||||||
void setOnNodeCreate(EventListener<MediaEvent> event);
|
void setOnNodeCreate(EventListener<MediaEvent> event);
|
||||||
|
|
||||||
@JSProperty("onnodecreate")
|
@JSProperty("onnodecreate")
|
||||||
EventListener<MediaEvent> getOnNodeCreate();
|
EventListener<MediaEvent> getOnNodeCreate();
|
||||||
|
|
||||||
|
default Registration onNodeCreate(EventListener<MediaEvent> listener) {
|
||||||
|
return onEvent("nodecreate", listener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
AudioWorkerParamDescriptor[] getParameters();
|
AudioWorkerParamDescriptor[] getParameters();
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.teavm.jso.JSByRef;
|
||||||
import org.teavm.jso.JSObject;
|
import org.teavm.jso.JSObject;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface AudioWorkerNode extends AudioNode {
|
public interface AudioWorkerNode extends AudioNode {
|
||||||
@JSProperty("onmessage")
|
@JSProperty("onmessage")
|
||||||
|
@ -27,6 +28,10 @@ public interface AudioWorkerNode extends AudioNode {
|
||||||
@JSProperty("onmessage")
|
@JSProperty("onmessage")
|
||||||
EventListener<MediaEvent> getOnMessage();
|
EventListener<MediaEvent> getOnMessage();
|
||||||
|
|
||||||
|
default Registration onMessage(EventListener<MediaEvent> listener) {
|
||||||
|
return onEvent("message", listener);
|
||||||
|
}
|
||||||
|
|
||||||
void postMessage(JSObject message, @JSByRef JSObject[] transfer);
|
void postMessage(JSObject message, @JSByRef JSObject[] transfer);
|
||||||
|
|
||||||
void postMessage(JSObject message, JSObject transfer);
|
void postMessage(JSObject message, JSObject transfer);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.jso.webaudio;
|
package org.teavm.jso.webaudio;
|
||||||
|
|
||||||
|
import org.teavm.jso.JSObject;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.core.JSArray;
|
import org.teavm.jso.core.JSArray;
|
||||||
|
|
||||||
|
@ -23,9 +24,9 @@ public interface AudioWorkerNodeCreationEvent extends MediaEvent {
|
||||||
AudioWorkerNodeProcessor getNode();
|
AudioWorkerNodeProcessor getNode();
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
JSArray getInputs();
|
JSArray<JSObject> getInputs();
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
JSArray getOutputs();
|
JSArray<JSObject> getOutputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.teavm.jso.JSObject;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
import org.teavm.jso.dom.events.EventTarget;
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface AudioWorkerNodeProcessor extends EventTarget {
|
public interface AudioWorkerNodeProcessor extends EventTarget {
|
||||||
@JSProperty("onmessage")
|
@JSProperty("onmessage")
|
||||||
|
@ -27,6 +28,10 @@ public interface AudioWorkerNodeProcessor extends EventTarget {
|
||||||
@JSProperty("onmessage")
|
@JSProperty("onmessage")
|
||||||
EventListener<MediaEvent> getOnMessage();
|
EventListener<MediaEvent> getOnMessage();
|
||||||
|
|
||||||
|
default Registration onMessage(EventListener<MediaEvent> listener) {
|
||||||
|
return onEvent("message", listener);
|
||||||
|
}
|
||||||
|
|
||||||
void postMessage(JSObject message, JSObject[] transfer);
|
void postMessage(JSObject message, JSObject[] transfer);
|
||||||
|
|
||||||
void postMessage(JSObject message, JSObject transfer);
|
void postMessage(JSObject message, JSObject transfer);
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.teavm.jso.webaudio;
|
||||||
import org.teavm.jso.JSClass;
|
import org.teavm.jso.JSClass;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
@JSClass
|
@JSClass
|
||||||
public class OfflineAudioContext extends AudioContext {
|
public class OfflineAudioContext extends AudioContext {
|
||||||
|
@ -27,6 +28,10 @@ public class OfflineAudioContext extends AudioContext {
|
||||||
@JSProperty("oncomplete")
|
@JSProperty("oncomplete")
|
||||||
public native EventListener<OfflineAudioCompletionEvent> getOnComplete();
|
public native EventListener<OfflineAudioCompletionEvent> getOnComplete();
|
||||||
|
|
||||||
|
public final Registration onComplete(EventListener<OfflineAudioCompletionEvent> listener) {
|
||||||
|
return onEvent("complete", listener);
|
||||||
|
}
|
||||||
|
|
||||||
public native AudioBuffer startRendering();
|
public native AudioBuffer startRendering();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.jso.webaudio;
|
||||||
|
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface OscillatorNode extends AudioNode {
|
public interface OscillatorNode extends AudioNode {
|
||||||
String TYPE_SINE = "sine";
|
String TYPE_SINE = "sine";
|
||||||
|
@ -43,6 +44,10 @@ public interface OscillatorNode extends AudioNode {
|
||||||
@JSProperty("onended")
|
@JSProperty("onended")
|
||||||
EventListener<MediaEvent> getOnEnded();
|
EventListener<MediaEvent> getOnEnded();
|
||||||
|
|
||||||
|
default Registration onEnded(EventListener<MediaEvent> listener) {
|
||||||
|
return onEvent("ended", listener);
|
||||||
|
}
|
||||||
|
|
||||||
void start(double when);
|
void start(double when);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.jso.webaudio;
|
||||||
|
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface ScriptProcessorNode extends AudioNode {
|
public interface ScriptProcessorNode extends AudioNode {
|
||||||
@JSProperty("onaudioprocess")
|
@JSProperty("onaudioprocess")
|
||||||
|
@ -25,6 +26,10 @@ public interface ScriptProcessorNode extends AudioNode {
|
||||||
@JSProperty("onaudioprocess")
|
@JSProperty("onaudioprocess")
|
||||||
void setOnAudioProcess(EventListener<AudioProcessingEvent> event);
|
void setOnAudioProcess(EventListener<AudioProcessingEvent> event);
|
||||||
|
|
||||||
|
default Registration onAudioProcess(EventListener<AudioProcessingEvent> listener) {
|
||||||
|
return onEvent("audioprocess", listener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
int getBufferSize();
|
int getBufferSize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,14 @@ import org.teavm.jso.JSObject;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.Event;
|
import org.teavm.jso.dom.events.Event;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
import org.teavm.jso.dom.events.MessageEvent;
|
import org.teavm.jso.dom.events.MessageEvent;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||||
import org.teavm.jso.typedarrays.ArrayBufferView;
|
import org.teavm.jso.typedarrays.ArrayBufferView;
|
||||||
|
|
||||||
@JSClass
|
@JSClass
|
||||||
public class WebSocket implements JSObject {
|
public class WebSocket implements JSObject, EventTarget {
|
||||||
public WebSocket(String url) {
|
public WebSocket(String url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,17 +38,21 @@ public class WebSocket implements JSObject {
|
||||||
public WebSocket(String url, String[] protocols) {
|
public WebSocket(String url, String[] protocols) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JSProperty("onclose")
|
public final Registration onClose(EventListener<CloseEvent> eventListener) {
|
||||||
public native void onClose(EventListener<CloseEvent> eventListener);
|
return onEvent("close", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onerror")
|
public final Registration onError(EventListener<Event> eventListener) {
|
||||||
public native void onError(EventListener<Event> eventListener);
|
return onEvent("error", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onmessage")
|
public final Registration onMessage(EventListener<MessageEvent> eventListener) {
|
||||||
public native void onMessage(EventListener<MessageEvent> eventListener);
|
return onEvent("message", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onopen")
|
public final Registration onOpen(EventListener<Event> eventListener) {
|
||||||
public native void onOpen(EventListener<Event> eventListener);
|
return onEvent("open", eventListener);
|
||||||
|
}
|
||||||
|
|
||||||
@JSBody(params = "url", script = "return new WebSocket(url);")
|
@JSBody(params = "url", script = "return new WebSocket(url);")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -95,4 +101,19 @@ public class WebSocket implements JSObject {
|
||||||
|
|
||||||
@JSBody(script = "return typeof WebSocket !== 'undefined';")
|
@JSBody(script = "return typeof WebSocket !== 'undefined';")
|
||||||
public static native boolean isSupported();
|
public static native boolean isSupported();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native void addEventListener(String type, EventListener<?> listener, boolean useCapture);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native void addEventListener(String type, EventListener<?> listener);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native void removeEventListener(String type, EventListener<?> listener, boolean useCapture);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native void removeEventListener(String type, EventListener<?> listener);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native boolean dispatchEvent(Event evt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,13 @@
|
||||||
package org.teavm.jso.workers;
|
package org.teavm.jso.workers;
|
||||||
|
|
||||||
import org.teavm.jso.JSObject;
|
import org.teavm.jso.JSObject;
|
||||||
import org.teavm.jso.JSProperty;
|
|
||||||
import org.teavm.jso.dom.events.ErrorEvent;
|
import org.teavm.jso.dom.events.ErrorEvent;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
import org.teavm.jso.dom.events.EventTarget;
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface AbstractWorker extends JSObject, EventTarget {
|
public interface AbstractWorker extends JSObject, EventTarget {
|
||||||
@JSProperty("onerror")
|
default Registration onError(EventListener<ErrorEvent> listener) {
|
||||||
void onError(EventListener<ErrorEvent> listener);
|
return onEvent("error", listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.jso.workers;
|
package org.teavm.jso.workers;
|
||||||
|
|
||||||
import org.teavm.jso.JSProperty;
|
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
import org.teavm.jso.dom.events.EventTarget;
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
import org.teavm.jso.dom.events.MessageEvent;
|
import org.teavm.jso.dom.events.MessageEvent;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
public interface MessagePort extends EventTarget {
|
public interface MessagePort extends EventTarget {
|
||||||
void postMessage(Object message);
|
void postMessage(Object message);
|
||||||
|
@ -27,9 +27,11 @@ public interface MessagePort extends EventTarget {
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
@JSProperty("onmessage")
|
default Registration onMessage(EventListener<MessageEvent> message) {
|
||||||
void onMessage(EventListener<MessageEvent> message);
|
return onEvent("message", message);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty("onmessageerror")
|
default Registration onMessageError(EventListener<MessageEvent> message) {
|
||||||
void onMessageError(EventListener<MessageEvent> message);
|
return onEvent("messageerror", message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,14 @@
|
||||||
package org.teavm.jso.workers;
|
package org.teavm.jso.workers;
|
||||||
|
|
||||||
import org.teavm.jso.JSBody;
|
import org.teavm.jso.JSBody;
|
||||||
|
import org.teavm.jso.JSClass;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.events.ErrorEvent;
|
import org.teavm.jso.dom.events.ErrorEvent;
|
||||||
import org.teavm.jso.dom.events.Event;
|
import org.teavm.jso.dom.events.Event;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
|
@JSClass
|
||||||
public class SharedWorker implements AbstractWorker {
|
public class SharedWorker implements AbstractWorker {
|
||||||
public SharedWorker(String url) {
|
public SharedWorker(String url) {
|
||||||
}
|
}
|
||||||
|
@ -32,9 +35,6 @@ public class SharedWorker implements AbstractWorker {
|
||||||
@JSProperty
|
@JSProperty
|
||||||
public native MessagePort getPort();
|
public native MessagePort getPort();
|
||||||
|
|
||||||
@Override
|
|
||||||
public native void onError(EventListener<ErrorEvent> listener);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public native void addEventListener(String type, EventListener<?> listener, boolean useCapture);
|
public native void addEventListener(String type, EventListener<?> listener, boolean useCapture);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.teavm.jso.dom.events.ErrorEvent;
|
||||||
import org.teavm.jso.dom.events.Event;
|
import org.teavm.jso.dom.events.Event;
|
||||||
import org.teavm.jso.dom.events.EventListener;
|
import org.teavm.jso.dom.events.EventListener;
|
||||||
import org.teavm.jso.dom.events.MessageEvent;
|
import org.teavm.jso.dom.events.MessageEvent;
|
||||||
|
import org.teavm.jso.dom.events.Registration;
|
||||||
|
|
||||||
@JSClass
|
@JSClass
|
||||||
public class Worker implements AbstractWorker {
|
public class Worker implements AbstractWorker {
|
||||||
|
@ -32,16 +33,14 @@ public class Worker implements AbstractWorker {
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static native Worker create(String url);
|
public static native Worker create(String url);
|
||||||
|
|
||||||
@JSProperty("onmessage")
|
public Registration onMessage(EventListener<MessageEvent> listener) {
|
||||||
public native void onMessage(EventListener<MessageEvent> listener);
|
return onEvent("message", listener);
|
||||||
|
}
|
||||||
|
|
||||||
public native void postMessage(Object message);
|
public native void postMessage(Object message);
|
||||||
|
|
||||||
public native void terminate();
|
public native void terminate();
|
||||||
|
|
||||||
@Override
|
|
||||||
public native void onError(EventListener<ErrorEvent> listener);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public native void addEventListener(String type, EventListener<?> listener, boolean useCapture);
|
public native void addEventListener(String type, EventListener<?> listener, boolean useCapture);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ public final class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
helloButton.listenClick(evt -> sayHello());
|
helloButton.onClick(evt -> sayHello());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sayHello() {
|
private static void sayHello() {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform") version "1.9.20"
|
kotlin("jvm") version "1.9.20"
|
||||||
war
|
war
|
||||||
id("org.teavm")
|
id("org.teavm")
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,4 @@ teavm.js {
|
||||||
mainClass = "org.teavm.samples.kotlin.HelloKt"
|
mainClass = "org.teavm.samples.kotlin.HelloKt"
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin.jvmToolchain(17)
|
||||||
jvm()
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,5 +20,5 @@ import org.teavm.jso.browser.*
|
||||||
fun main() {
|
fun main() {
|
||||||
val document = Window.current().document
|
val document = Window.current().document
|
||||||
|
|
||||||
document.getElementById("hello-kotlin").addEventListener("click") { Window.alert("Hello, developer!") }
|
document.getElementById("hello-kotlin").onClick { Window.alert("Hello, developer!") }
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ object Client {
|
||||||
val exprElem = doc.getElementById("expr").asInstanceOf[HTMLInputElement]
|
val exprElem = doc.getElementById("expr").asInstanceOf[HTMLInputElement]
|
||||||
val calcElem = doc.getElementById("calculate")
|
val calcElem = doc.getElementById("calculate")
|
||||||
val resultList = doc.getElementById("result-list")
|
val resultList = doc.getElementById("result-list")
|
||||||
calcElem.listenClick((e: MouseEvent) => {
|
calcElem.onClick((e: MouseEvent) => {
|
||||||
parse(exprElem.getValue.toSeq) match {
|
parse(exprElem.getValue.toSeq) match {
|
||||||
case (None, _) => Window.alert("Error parsing expression");
|
case (None, _) => Window.alert("Error parsing expression");
|
||||||
case (Some(x), Nil) =>
|
case (Some(x), Nil) =>
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.teavm.samples.software3d.scenes.geometry
|
||||||
|
|
||||||
fun worker() {
|
fun worker() {
|
||||||
val worker = RenderWorker()
|
val worker = RenderWorker()
|
||||||
Window.worker().listenMessage {
|
Window.worker().onMessage {
|
||||||
val dataJson = it.data as JSMapLike<*>
|
val dataJson = it.data as JSMapLike<*>
|
||||||
when ((dataJson["type"] as JSString).stringValue()) {
|
when ((dataJson["type"] as JSString).stringValue()) {
|
||||||
"init" -> worker.init(dataJson)
|
"init" -> worker.init(dataJson)
|
||||||
|
|
|
@ -37,7 +37,7 @@ public final class Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLButtonElement saveButton = document.getElementById("save-button").cast();
|
HTMLButtonElement saveButton = document.getElementById("save-button").cast();
|
||||||
saveButton.listenClick(e -> {
|
saveButton.onClick(e -> {
|
||||||
var key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
var key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
||||||
var value = document.getElementById("value").<HTMLInputElement>cast().getValue();
|
var value = document.getElementById("value").<HTMLInputElement>cast().getValue();
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public final class Storage {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
HTMLButtonElement deleteButton = document.getElementById("delete-button").cast();
|
HTMLButtonElement deleteButton = document.getElementById("delete-button").cast();
|
||||||
deleteButton.listenClick(e -> {
|
deleteButton.onClick(e -> {
|
||||||
String key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
String key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
||||||
if (key != null && !key.isEmpty()) {
|
if (key != null && !key.isEmpty()) {
|
||||||
storage.removeItem(key);
|
storage.removeItem(key);
|
||||||
|
@ -55,7 +55,7 @@ public final class Storage {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
HTMLButtonElement deleteAllButton = document.getElementById("delete-all-button").cast();
|
HTMLButtonElement deleteAllButton = document.getElementById("delete-all-button").cast();
|
||||||
deleteAllButton.listenClick(e -> {
|
deleteAllButton.onClick(e -> {
|
||||||
storage.clear();
|
storage.clear();
|
||||||
draw();
|
draw();
|
||||||
});
|
});
|
||||||
|
|
|
@ -57,30 +57,30 @@ public final class Video {
|
||||||
|
|
||||||
var divButtons = document.createElement("div")
|
var divButtons = document.createElement("div")
|
||||||
.withAttr("id", "button")
|
.withAttr("id", "button")
|
||||||
.withChild("button", elem -> elem.withText("load()").listenClick(evt -> video.load()))
|
.withChild("button", elem -> elem.withText("load()").onClick(evt -> video.load()))
|
||||||
.withChild("button", elem -> elem.withText("play()").listenClick(evt -> video.play()))
|
.withChild("button", elem -> elem.withText("play()").onClick(evt -> video.play()))
|
||||||
.withChild("button", elem -> elem.withText("pause()").listenClick(evt -> video.pause()))
|
.withChild("button", elem -> elem.withText("pause()").onClick(evt -> video.pause()))
|
||||||
.withChild("br")
|
.withChild("br")
|
||||||
.withChild("button", elem -> elem.withText("currentTime+=10")
|
.withChild("button", elem -> elem.withText("currentTime+=10")
|
||||||
.listenClick(evt -> video.addCurrentTime(10)))
|
.onClick(evt -> video.addCurrentTime(10)))
|
||||||
.withChild("button", elem -> elem.withText("currentTime-=10")
|
.withChild("button", elem -> elem.withText("currentTime-=10")
|
||||||
.listenClick(evt -> video.addCurrentTime(-10)))
|
.onClick(evt -> video.addCurrentTime(-10)))
|
||||||
.withChild("button", elem -> elem.withText("currentTime-=50")
|
.withChild("button", elem -> elem.withText("currentTime-=50")
|
||||||
.listenClick(evt -> video.setCurrentTime(50)))
|
.onClick(evt -> video.setCurrentTime(50)))
|
||||||
.withChild("br")
|
.withChild("br")
|
||||||
.withChild("button", elem -> elem.withText("playbackRate++")
|
.withChild("button", elem -> elem.withText("playbackRate++")
|
||||||
.listenClick(evt -> video.addPlaybackRate(1)))
|
.onClick(evt -> video.addPlaybackRate(1)))
|
||||||
.withChild("button", elem -> elem.withText("playbackRate--")
|
.withChild("button", elem -> elem.withText("playbackRate--")
|
||||||
.listenClick(evt -> video.addPlaybackRate(-1)))
|
.onClick(evt -> video.addPlaybackRate(-1)))
|
||||||
.withChild("button", elem -> elem.withText("playbackRate+=0.1")
|
.withChild("button", elem -> elem.withText("playbackRate+=0.1")
|
||||||
.listenClick(evt -> video.addPlaybackRate(0.1)))
|
.onClick(evt -> video.addPlaybackRate(0.1)))
|
||||||
.withChild("button", elem -> elem.withText("playbackRate-=0.1")
|
.withChild("button", elem -> elem.withText("playbackRate-=0.1")
|
||||||
.listenClick(evt -> video.addPlaybackRate(-0.1)))
|
.onClick(evt -> video.addPlaybackRate(-0.1)))
|
||||||
.withChild("br")
|
.withChild("br")
|
||||||
.withChild("button", elem -> elem.withText("volume+=1").listenClick(evt -> video.addVolume(0.1F)))
|
.withChild("button", elem -> elem.withText("volume+=1").onClick(evt -> video.addVolume(0.1F)))
|
||||||
.withChild("button", elem -> elem.withText("volume-=1").listenClick(evt -> video.addVolume(-0.1F)))
|
.withChild("button", elem -> elem.withText("volume-=1").onClick(evt -> video.addVolume(-0.1F)))
|
||||||
.withChild("button", elem -> elem.withText("mute").listenClick(evt -> video.setMuted(true)))
|
.withChild("button", elem -> elem.withText("mute").onClick(evt -> video.setMuted(true)))
|
||||||
.withChild("button", elem -> elem.withText("unmute").listenClick(evt -> video.setMuted(false)));
|
.withChild("button", elem -> elem.withText("unmute").onClick(evt -> video.setMuted(false)));
|
||||||
|
|
||||||
var body = document.getBody();
|
var body = document.getBody();
|
||||||
body.appendChild(divVideo);
|
body.appendChild(divVideo);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user