mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add JS API wrappers
This commit is contained in:
parent
24952e5b86
commit
53cd861563
|
@ -56,6 +56,14 @@ public abstract class XMLHttpRequest implements JSObject {
|
||||||
@JSProperty("onreadystatechange")
|
@JSProperty("onreadystatechange")
|
||||||
public abstract void setOnReadyStateChange(ReadyStateChangeHandler handler);
|
public abstract void setOnReadyStateChange(ReadyStateChangeHandler handler);
|
||||||
|
|
||||||
|
public final void onComplete(Runnable runnable) {
|
||||||
|
setOnReadyStateChange(() -> {
|
||||||
|
if (getReadyState() == DONE) {
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void overrideMimeType(String mimeType);
|
public abstract void overrideMimeType(String mimeType);
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
|
|
45
jso/apis/src/main/java/org/teavm/jso/browser/History.java
Normal file
45
jso/apis/src/main/java/org/teavm/jso/browser/History.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.browser;
|
||||||
|
|
||||||
|
import org.teavm.jso.JSObject;
|
||||||
|
import org.teavm.jso.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface History extends JSObject {
|
||||||
|
@JSProperty
|
||||||
|
int getLength();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
JSObject getState();
|
||||||
|
|
||||||
|
void back();
|
||||||
|
|
||||||
|
void forward();
|
||||||
|
|
||||||
|
void go(int delta);
|
||||||
|
|
||||||
|
void pushState(JSObject data, String title);
|
||||||
|
|
||||||
|
void pushState(JSObject data, String title, String url);
|
||||||
|
|
||||||
|
void replaceState(JSObject data, String title);
|
||||||
|
|
||||||
|
void replaceState(JSObject data, String title, String url);
|
||||||
|
}
|
84
jso/apis/src/main/java/org/teavm/jso/browser/Location.java
Normal file
84
jso/apis/src/main/java/org/teavm/jso/browser/Location.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.browser;
|
||||||
|
|
||||||
|
import org.teavm.jso.JSObject;
|
||||||
|
import org.teavm.jso.JSProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface Location extends JSObject {
|
||||||
|
@JSProperty("href")
|
||||||
|
String getFullURL();
|
||||||
|
|
||||||
|
@JSProperty("href")
|
||||||
|
void setFullURL(String url);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getProtocol();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setProtocol(String protocol);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getHost();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setHost(String host);
|
||||||
|
|
||||||
|
@JSProperty("hostname")
|
||||||
|
String getHostName();
|
||||||
|
|
||||||
|
@JSProperty("hostname")
|
||||||
|
void setHostName(String hostName);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getPort();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setPort(String port);
|
||||||
|
|
||||||
|
@JSProperty("pathname")
|
||||||
|
String getPathName();
|
||||||
|
|
||||||
|
@JSProperty("pathname")
|
||||||
|
void setPathName(String pathName);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getSearch();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setSearch(String search);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getHash();
|
||||||
|
|
||||||
|
void setHash(String hash);
|
||||||
|
|
||||||
|
void assign(String url);
|
||||||
|
|
||||||
|
void reload();
|
||||||
|
|
||||||
|
void reload(boolean force);
|
||||||
|
|
||||||
|
void replace(String url);
|
||||||
|
|
||||||
|
static Location current() {
|
||||||
|
return Window.current().getLocation();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2014 Alexey Andreev.
|
* Copyright 2015 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,14 +13,18 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.jso.dom.events;
|
package org.teavm.jso.browser;
|
||||||
|
|
||||||
import org.teavm.jso.JSObject;
|
import org.teavm.jso.JSBody;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public interface DocumentEvent extends JSObject {
|
public final class Navigator {
|
||||||
Event createEvent(String eventType);
|
private Navigator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@JSBody(params = "", script = "return window.navigator.onLine;")
|
||||||
|
public static native boolean isOnline();
|
||||||
}
|
}
|
|
@ -18,14 +18,17 @@ package org.teavm.jso.browser;
|
||||||
import org.teavm.jso.JSBody;
|
import org.teavm.jso.JSBody;
|
||||||
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;
|
import org.teavm.jso.core.JSArray;
|
||||||
|
import org.teavm.jso.core.JSArrayReader;
|
||||||
import org.teavm.jso.dom.html.HTMLDocument;
|
import org.teavm.jso.dom.html.HTMLDocument;
|
||||||
|
import org.teavm.jso.dom.html.HTMLElement;
|
||||||
|
import org.teavm.jso.dom.html.HTMLIFrameElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public abstract class Window implements JSObject, EventTarget, StorageProvider {
|
public abstract class Window implements JSObject, WindowEventTarget, StorageProvider, JSArrayReader<HTMLIFrameElement> {
|
||||||
private Window() {
|
private Window() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,12 +38,64 @@ public abstract class Window implements JSObject, EventTarget, StorageProvider {
|
||||||
@JSProperty
|
@JSProperty
|
||||||
public abstract Screen getScreen();
|
public abstract Screen getScreen();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract int getScreenX();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract int getScreenY();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract Location getLocation();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract HTMLElement getFrameElement();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract JSArrayReader<HTMLIFrameElement> getFrames();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract int getInnerWidth();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract int getInnerHeight();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract int getOuterWidth();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract int getOuterHeight();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract void setName(String name);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract Window getParent();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
public abstract Window getTop();
|
||||||
|
|
||||||
@JSBody(params = "message", script = "alert(message);")
|
@JSBody(params = "message", script = "alert(message);")
|
||||||
public static native void alert(JSObject message);
|
public static native void alert(JSObject message);
|
||||||
|
|
||||||
@JSBody(params = "message", script = "alert(message);")
|
@JSBody(params = "message", script = "alert(message);")
|
||||||
public static native void alert(String message);
|
public static native void alert(String message);
|
||||||
|
|
||||||
|
@JSBody(params = "message", script = "confirm(message);")
|
||||||
|
public static native boolean confirm(JSObject message);
|
||||||
|
|
||||||
|
@JSBody(params = "message", script = "confirm(message);")
|
||||||
|
public static native boolean confirm(String message);
|
||||||
|
|
||||||
|
public static String prompt(String message) {
|
||||||
|
return prompt(message, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@JSBody(params = { "message", "default" }, script = "prompt(message, default);")
|
||||||
|
public static native String prompt(String message, String defaultValue);
|
||||||
|
|
||||||
@JSBody(params = { "handler", "delay" }, script = "return setTimeout(handler, delay);")
|
@JSBody(params = { "handler", "delay" }, script = "return setTimeout(handler, delay);")
|
||||||
public static native int setTimeout(TimerHandler handler, int delay);
|
public static native int setTimeout(TimerHandler handler, int delay);
|
||||||
|
|
||||||
|
@ -59,6 +114,44 @@ public abstract class Window implements JSObject, EventTarget, StorageProvider {
|
||||||
@JSBody(params = { "timeoutId" }, script = "clearInterval(timeoutId);")
|
@JSBody(params = { "timeoutId" }, script = "clearInterval(timeoutId);")
|
||||||
public static native void clearInterval(int timeoutId);
|
public static native void clearInterval(int timeoutId);
|
||||||
|
|
||||||
|
public abstract void blur();
|
||||||
|
|
||||||
|
public abstract void focus();
|
||||||
|
|
||||||
|
public abstract void close();
|
||||||
|
|
||||||
|
public abstract void moveBy(int deltaX, int deltaY);
|
||||||
|
|
||||||
|
public abstract void moveTo(int x, int y);
|
||||||
|
|
||||||
|
public abstract void resizeBy(int deltaX, int deltaY);
|
||||||
|
|
||||||
|
public abstract void resizeTo(int x, int y);
|
||||||
|
|
||||||
|
public abstract void scrollBy(int deltaX, int deltaY);
|
||||||
|
|
||||||
|
public abstract void scrollTo(int x, int y);
|
||||||
|
|
||||||
|
public abstract Window open(String url, String name);
|
||||||
|
|
||||||
|
public final Window open(String url, String name, WindowFeatures features) {
|
||||||
|
return open(url, name, features.sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Window open(String url, String name, String features);
|
||||||
|
|
||||||
|
public abstract void print();
|
||||||
|
|
||||||
|
public abstract void stop();
|
||||||
|
|
||||||
|
public abstract void postMessage(JSObject message, String targetOrigin);
|
||||||
|
|
||||||
|
public abstract void postMessage(JSObject message, String targetOrigin, JSArrayReader<JSObject> transfer);
|
||||||
|
|
||||||
|
public final void postMessage(JSObject message, String targetOrigin, JSObject... transfer) {
|
||||||
|
postMessage(message, targetOrigin, JSArray.of(transfer));
|
||||||
|
}
|
||||||
|
|
||||||
@JSBody(params = {}, script = "return window;")
|
@JSBody(params = {}, script = "return window;")
|
||||||
public static native Window current();
|
public static native Window current();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.browser;
|
||||||
|
|
||||||
|
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.events.FocusEventTarget;
|
||||||
|
import org.teavm.jso.dom.events.KeyboardEventTarget;
|
||||||
|
import org.teavm.jso.dom.events.LoadEventTarget;
|
||||||
|
import org.teavm.jso.dom.events.MessageEvent;
|
||||||
|
import org.teavm.jso.dom.events.MouseEventTarget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface WindowEventTarget extends EventTarget, FocusEventTarget, MouseEventTarget, KeyboardEventTarget,
|
||||||
|
LoadEventTarget {
|
||||||
|
default void listenBeforeOnload(EventListener<Event> listener) {
|
||||||
|
addEventListener("beforeunload", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectBeforeOnload(EventListener<Event> listener) {
|
||||||
|
removeEventListener("beforeunload", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenMessage(EventListener<MessageEvent> listener) {
|
||||||
|
addEventListener("message", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectMessage(EventListener<MessageEvent> listener) {
|
||||||
|
removeEventListener("message", listener);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.browser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public class WindowFeatures {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
public WindowFeatures() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures left(int left) {
|
||||||
|
return add("left=" + left);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures top(int top) {
|
||||||
|
return add("top=" + top);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures width(int width) {
|
||||||
|
return add("width=" + width);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures height(int height) {
|
||||||
|
return add("height=" + height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures menubar() {
|
||||||
|
return add("menubar");
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures toolbar() {
|
||||||
|
return add("toolbar");
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures location() {
|
||||||
|
return add("location");
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures status() {
|
||||||
|
return add("status");
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures resizable() {
|
||||||
|
return add("resizable");
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowFeatures scrollbars() {
|
||||||
|
return add("resizable");
|
||||||
|
}
|
||||||
|
|
||||||
|
private WindowFeatures add(String feature) {
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.append(',');
|
||||||
|
}
|
||||||
|
sb.append(feature);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -88,4 +88,13 @@ public abstract class JSArray<T extends JSObject> implements JSArrayReader<T> {
|
||||||
|
|
||||||
@JSBody(params = "size", script = "return new Array(size);")
|
@JSBody(params = "size", script = "return new Array(size);")
|
||||||
public static native <T extends JSObject> JSArray<T> create(int size);
|
public static native <T extends JSObject> JSArray<T> create(int size);
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public static <S extends JSObject> JSArray<S> of(S... items) {
|
||||||
|
JSArray<S> array = create(items.length);
|
||||||
|
for (int i = 0; i < items.length; ++i) {
|
||||||
|
array.set(i, items[i]);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.dom.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface FocusEventTarget extends EventTarget {
|
||||||
|
default void listenFocus(EventListener<Event> listener) {
|
||||||
|
addEventListener("focus", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectFocus(EventListener<Event> listener) {
|
||||||
|
removeEventListener("focus", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenBlur(EventListener<Event> listener) {
|
||||||
|
addEventListener("blur", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectBlur(EventListener<Event> listener) {
|
||||||
|
removeEventListener("blur", listener);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.dom.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface KeyboardEventTarget extends EventTarget {
|
||||||
|
default void listenKeyDown(EventListener<KeyboardEvent> listener) {
|
||||||
|
addEventListener("keydown", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectKeyDown(EventListener<KeyboardEvent> listener) {
|
||||||
|
removeEventListener("keydown", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenKeyUp(EventListener<KeyboardEvent> listener) {
|
||||||
|
addEventListener("keyup", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectKeyUp(EventListener<KeyboardEvent> listener) {
|
||||||
|
removeEventListener("keyup", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenKeyPress(EventListener<KeyboardEvent> listener) {
|
||||||
|
addEventListener("keypress", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectKeyPress(EventListener<KeyboardEvent> listener) {
|
||||||
|
removeEventListener("keypress", listener);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.dom.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface LoadEventTarget extends EventTarget {
|
||||||
|
default void listenLoad(EventListener<Event> listener) {
|
||||||
|
addEventListener("load", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectLoad(EventListener<Event> listener) {
|
||||||
|
addEventListener("load", listener);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.dom.events;
|
||||||
|
|
||||||
|
import org.teavm.jso.JSObject;
|
||||||
|
import org.teavm.jso.JSProperty;
|
||||||
|
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface MessageEvent extends Event {
|
||||||
|
@JSProperty
|
||||||
|
JSObject getData();
|
||||||
|
|
||||||
|
@JSProperty("data")
|
||||||
|
String getDataAsString();
|
||||||
|
|
||||||
|
@JSProperty("data")
|
||||||
|
ArrayBuffer getDataAsArray();
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.dom.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface MouseEventTarget extends EventTarget {
|
||||||
|
default void listenClick(EventListener<MouseEvent> listener) {
|
||||||
|
addEventListener("click", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectClick(EventListener<MouseEvent> listener) {
|
||||||
|
removeEventListener("click", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenDoubleClick(EventListener<MouseEvent> listener) {
|
||||||
|
addEventListener("dblclick", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectDoubleClick(EventListener<MouseEvent> listener) {
|
||||||
|
removeEventListener("dblclick", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenMouseDown(EventListener<MouseEvent> listener) {
|
||||||
|
addEventListener("mousedown", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectMouseDown(EventListener<MouseEvent> listener) {
|
||||||
|
removeEventListener("mousedown", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenMouseUp(EventListener<MouseEvent> listener) {
|
||||||
|
addEventListener("mouseup", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectMouseUp(EventListener<MouseEvent> listener) {
|
||||||
|
removeEventListener("mouseup", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenMouseOver(EventListener<MouseEvent> listener) {
|
||||||
|
addEventListener("mouseover", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectMouseOver(EventListener<MouseEvent> listener) {
|
||||||
|
removeEventListener("mouseover", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenMouseEnter(EventListener<MouseEvent> listener) {
|
||||||
|
addEventListener("mouseenter", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectMouseEnter(EventListener<MouseEvent> listener) {
|
||||||
|
removeEventListener("mouseenter", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenMouseLeaeve(EventListener<MouseEvent> listener) {
|
||||||
|
addEventListener("mouseleave", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectMouseLeave(EventListener<MouseEvent> listener) {
|
||||||
|
removeEventListener("mouseleave", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void listenMouseOut(EventListener<MouseEvent> listener) {
|
||||||
|
addEventListener("mouseout", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void neglectMouseOut(EventListener<MouseEvent> listener) {
|
||||||
|
removeEventListener("mouseout", listener);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,14 +19,20 @@ import java.util.function.Consumer;
|
||||||
import org.teavm.jso.JSProperty;
|
import org.teavm.jso.JSProperty;
|
||||||
import org.teavm.jso.dom.css.ElementCSSInlineStyle;
|
import org.teavm.jso.dom.css.ElementCSSInlineStyle;
|
||||||
import org.teavm.jso.dom.events.EventTarget;
|
import org.teavm.jso.dom.events.EventTarget;
|
||||||
|
import org.teavm.jso.dom.events.FocusEventTarget;
|
||||||
|
import org.teavm.jso.dom.events.KeyboardEventTarget;
|
||||||
|
import org.teavm.jso.dom.events.LoadEventTarget;
|
||||||
|
import org.teavm.jso.dom.events.MouseEventTarget;
|
||||||
import org.teavm.jso.dom.xml.Element;
|
import org.teavm.jso.dom.xml.Element;
|
||||||
|
import org.teavm.jso.dom.xml.Node;
|
||||||
import org.teavm.jso.dom.xml.NodeList;
|
import org.teavm.jso.dom.xml.NodeList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget {
|
public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget, FocusEventTarget, MouseEventTarget,
|
||||||
|
KeyboardEventTarget, LoadEventTarget {
|
||||||
@Override
|
@Override
|
||||||
@JSProperty
|
@JSProperty
|
||||||
NodeList<? extends HTMLElement> getElementsByTagName(String name);
|
NodeList<? extends HTMLElement> getElementsByTagName(String name);
|
||||||
|
@ -120,14 +126,19 @@ public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget
|
||||||
default HTMLElement withChild(String tagName) {
|
default HTMLElement withChild(String tagName) {
|
||||||
HTMLElement result = getOwnerDocument().createElement(tagName);
|
HTMLElement result = getOwnerDocument().createElement(tagName);
|
||||||
appendChild(result);
|
appendChild(result);
|
||||||
return result;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
default HTMLElement withChild(Node node) {
|
||||||
|
appendChild(node);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
default HTMLElement withChild(String tagName, Consumer<HTMLElement> consumer) {
|
default HTMLElement withChild(String tagName, Consumer<HTMLElement> consumer) {
|
||||||
HTMLElement result = getOwnerDocument().createElement(tagName);
|
HTMLElement result = getOwnerDocument().createElement(tagName);
|
||||||
appendChild(result);
|
appendChild(result);
|
||||||
consumer.accept(result);
|
consumer.accept(result);
|
||||||
return result;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
default HTMLElement clear() {
|
default HTMLElement clear() {
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* 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.jso.dom.html;
|
||||||
|
|
||||||
|
import org.teavm.jso.JSProperty;
|
||||||
|
import org.teavm.jso.browser.Window;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
public interface HTMLIFrameElement extends HTMLElement {
|
||||||
|
@JSProperty
|
||||||
|
HTMLDocument getContentDocument();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
Window getContentWindow();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getWidth();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setWidth(String width);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getHeight();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setHeight(String height);
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
@JSProperty
|
||||||
|
void setName(String name);
|
||||||
|
|
||||||
|
@JSProperty("src")
|
||||||
|
String getSourceAddress();
|
||||||
|
|
||||||
|
@JSProperty("src")
|
||||||
|
void setSourceAddress(String src);
|
||||||
|
|
||||||
|
@JSProperty("srcdoc")
|
||||||
|
String getSourceDocument();
|
||||||
|
|
||||||
|
@JSProperty("srcdoc")
|
||||||
|
void setSourceDocument(String srcdoc);
|
||||||
|
}
|
|
@ -83,6 +83,10 @@ public interface HTMLMediaElement extends HTMLElement {
|
||||||
@JSProperty
|
@JSProperty
|
||||||
void setCurrentTime(double currentTime);
|
void setCurrentTime(double currentTime);
|
||||||
|
|
||||||
|
default void addCurrentTime(double delta) {
|
||||||
|
setCurrentTime(getCurrentTime() + delta);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
double getDuration();
|
double getDuration();
|
||||||
|
|
||||||
|
@ -104,6 +108,10 @@ public interface HTMLMediaElement extends HTMLElement {
|
||||||
@JSProperty
|
@JSProperty
|
||||||
void setPlaybackRate(double playbackRate);
|
void setPlaybackRate(double playbackRate);
|
||||||
|
|
||||||
|
default void addPlaybackRate(double delta) {
|
||||||
|
setPlaybackRate(getPlaybackRate() + delta);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
TimeRanges getPlayed();
|
TimeRanges getPlayed();
|
||||||
|
|
||||||
|
@ -149,6 +157,10 @@ public interface HTMLMediaElement extends HTMLElement {
|
||||||
@JSProperty
|
@JSProperty
|
||||||
void setVolume(float volume);
|
void setVolume(float volume);
|
||||||
|
|
||||||
|
default void addVolume(float delta) {
|
||||||
|
setVolume(getVolume() + delta);
|
||||||
|
}
|
||||||
|
|
||||||
@JSProperty
|
@JSProperty
|
||||||
boolean isMuted();
|
boolean isMuted();
|
||||||
|
|
||||||
|
|
|
@ -31,18 +31,14 @@ public final class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
helloButton.addEventListener("click", evt -> sayHello());
|
helloButton.listenClick(evt -> sayHello());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sayHello() {
|
private static void sayHello() {
|
||||||
helloButton.setDisabled(true);
|
helloButton.setDisabled(true);
|
||||||
thinkingPanel.getStyle().setProperty("display", "");
|
thinkingPanel.getStyle().setProperty("display", "");
|
||||||
XMLHttpRequest xhr = XMLHttpRequest.create();
|
XMLHttpRequest xhr = XMLHttpRequest.create();
|
||||||
xhr.setOnReadyStateChange(() -> {
|
xhr.onComplete(() -> receiveResponse(xhr.getResponseText()));
|
||||||
if (xhr.getReadyState() == XMLHttpRequest.DONE) {
|
|
||||||
receiveResponse(xhr.getResponseText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
xhr.open("GET", "hello");
|
xhr.open("GET", "hello");
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ object Client {
|
||||||
var exprElem = doc.getElementById("expr").asInstanceOf[HTMLInputElement]
|
var exprElem = doc.getElementById("expr").asInstanceOf[HTMLInputElement]
|
||||||
var calcElem = doc.getElementById("calculate")
|
var calcElem = doc.getElementById("calculate")
|
||||||
var resultList = doc.getElementById("result-list");
|
var resultList = doc.getElementById("result-list");
|
||||||
calcElem.addEventListener("click", (e : MouseEvent) => {
|
calcElem.listenClick((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) => {
|
||||||
|
|
|
@ -39,7 +39,7 @@ public final class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLButtonElement saveButton = document.getElementById("save-button").cast();
|
HTMLButtonElement saveButton = document.getElementById("save-button").cast();
|
||||||
saveButton.addEventListener("click", e -> {
|
saveButton.listenClick(e -> {
|
||||||
String key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
String key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
||||||
String value = document.getElementById("value").<HTMLInputElement>cast().getValue();
|
String value = document.getElementById("value").<HTMLInputElement>cast().getValue();
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public final class Application {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
HTMLButtonElement deleteButton = document.getElementById("delete-button").cast();
|
HTMLButtonElement deleteButton = document.getElementById("delete-button").cast();
|
||||||
deleteButton.addEventListener("click", e -> {
|
deleteButton.listenClick(e -> {
|
||||||
String key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
String key = document.getElementById("key").<HTMLInputElement>cast().getValue();
|
||||||
if (key != null && key.length() > 0) {
|
if (key != null && key.length() > 0) {
|
||||||
storage.removeItem(key);
|
storage.removeItem(key);
|
||||||
|
@ -57,7 +57,7 @@ public final class Application {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
HTMLButtonElement deleteAllButton = document.getElementById("delete-all-button").cast();
|
HTMLButtonElement deleteAllButton = document.getElementById("delete-all-button").cast();
|
||||||
deleteAllButton.addEventListener("click", e -> {
|
deleteAllButton.listenClick(e -> {
|
||||||
storage.clear();
|
storage.clear();
|
||||||
draw();
|
draw();
|
||||||
});
|
});
|
||||||
|
@ -75,15 +75,9 @@ public final class Application {
|
||||||
String key = storage.key(i);
|
String key = storage.key(i);
|
||||||
String value = storage.getItem(key);
|
String value = storage.getItem(key);
|
||||||
|
|
||||||
HTMLElement tdKey = document.createElement("td");
|
HTMLElement tdKey = document.createElement("td").withText(key);
|
||||||
tdKey.appendChild(document.createTextNode(key));
|
HTMLElement tdValue = document.createElement("td").withText(value);
|
||||||
|
HTMLElement tr = document.createElement("tr").withChild(tdKey).withChild(tdValue);
|
||||||
HTMLElement tdValue = document.createElement("td");
|
|
||||||
tdValue.appendChild(document.createTextNode(value));
|
|
||||||
|
|
||||||
HTMLElement tr = document.createElement("tr");
|
|
||||||
tr.appendChild(tdKey);
|
|
||||||
tr.appendChild(tdValue);
|
|
||||||
|
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ package org.teavm.samples.video;
|
||||||
|
|
||||||
import org.teavm.jso.browser.Window;
|
import org.teavm.jso.browser.Window;
|
||||||
import org.teavm.jso.dom.html.HTMLBodyElement;
|
import org.teavm.jso.dom.html.HTMLBodyElement;
|
||||||
import org.teavm.jso.dom.html.HTMLButtonElement;
|
|
||||||
import org.teavm.jso.dom.html.HTMLDocument;
|
import org.teavm.jso.dom.html.HTMLDocument;
|
||||||
import org.teavm.jso.dom.html.HTMLElement;
|
import org.teavm.jso.dom.html.HTMLElement;
|
||||||
import org.teavm.jso.dom.html.HTMLSourceElement;
|
import org.teavm.jso.dom.html.HTMLSourceElement;
|
||||||
|
@ -31,17 +30,14 @@ public final class Player {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
HTMLSourceElement sourceMp4 = document.createElement("source").cast();
|
HTMLSourceElement sourceMp4 = document.createElement("source").cast();
|
||||||
sourceMp4.setAttribute("id", "mp4");
|
|
||||||
sourceMp4.setSrc("http://media.w3.org/2010/05/sintel/trailer.mp4");
|
sourceMp4.setSrc("http://media.w3.org/2010/05/sintel/trailer.mp4");
|
||||||
sourceMp4.setAttribute("type", "video/mp4");
|
sourceMp4.setAttribute("type", "video/mp4");
|
||||||
|
|
||||||
HTMLSourceElement sourceWebm = document.createElement("source").cast();
|
HTMLSourceElement sourceWebm = document.createElement("source").cast();
|
||||||
sourceWebm.setAttribute("id", "webm");
|
|
||||||
sourceWebm.setSrc("http://media.w3.org/2010/05/sintel/trailer.webm");
|
sourceWebm.setSrc("http://media.w3.org/2010/05/sintel/trailer.webm");
|
||||||
sourceWebm.setAttribute("type", "video/webm");
|
sourceWebm.setAttribute("type", "video/webm");
|
||||||
|
|
||||||
HTMLSourceElement sourceOgv = document.createElement("source").cast();
|
HTMLSourceElement sourceOgv = document.createElement("source").cast();
|
||||||
sourceOgv.setAttribute("id", "ogv");
|
|
||||||
sourceOgv.setSrc("http://media.w3.org/2010/05/sintel/trailer.ogv");
|
sourceOgv.setSrc("http://media.w3.org/2010/05/sintel/trailer.ogv");
|
||||||
sourceOgv.setAttribute("type", "video/ogg");
|
sourceOgv.setAttribute("type", "video/ogg");
|
||||||
|
|
||||||
|
@ -49,7 +45,6 @@ public final class Player {
|
||||||
p.appendChild(document.createTextNode("Your user agent does not support the HTML5 Video element."));
|
p.appendChild(document.createTextNode("Your user agent does not support the HTML5 Video element."));
|
||||||
|
|
||||||
HTMLVideoElement video = document.createElement("video").cast();
|
HTMLVideoElement video = document.createElement("video").cast();
|
||||||
video.setAttribute("id", "video");
|
|
||||||
video.setControls(true);
|
video.setControls(true);
|
||||||
video.setPreload("none");
|
video.setPreload("none");
|
||||||
video.setMediaGroup("myVideoGroup");
|
video.setMediaGroup("myVideoGroup");
|
||||||
|
@ -62,83 +57,32 @@ public final class Player {
|
||||||
HTMLElement divVideo = document.createElement("div");
|
HTMLElement divVideo = document.createElement("div");
|
||||||
divVideo.appendChild(video);
|
divVideo.appendChild(video);
|
||||||
|
|
||||||
HTMLButtonElement loadButton = document.createElement("button").cast();
|
HTMLElement divButtons = document.createElement("div")
|
||||||
loadButton.appendChild(document.createTextNode("load()"));
|
.withAttr("id", "button")
|
||||||
loadButton.addEventListener("click", evt -> video.load());
|
.withChild("button", elem -> elem.withText("load()").listenClick(evt -> video.load()))
|
||||||
|
.withChild("button", elem -> elem.withText("play()").listenClick(evt -> video.play()))
|
||||||
HTMLButtonElement playButton = document.createElement("button").cast();
|
.withChild("button", elem -> elem.withText("pause()").listenClick(evt -> video.pause()))
|
||||||
playButton.appendChild(document.createTextNode("play()"));
|
.withChild("br")
|
||||||
playButton.addEventListener("click", evt -> video.play());
|
.withChild("button", elem -> elem.withText("currentTime+=10")
|
||||||
|
.listenClick(evt -> video.addCurrentTime(10)))
|
||||||
HTMLButtonElement pauseButton = document.createElement("button").cast();
|
.withChild("button", elem -> elem.withText("currentTime-=10")
|
||||||
pauseButton.appendChild(document.createTextNode("pause()"));
|
.listenClick(evt -> video.addCurrentTime(-10)))
|
||||||
pauseButton.addEventListener("click", evt -> video.pause());
|
.withChild("button", elem -> elem.withText("currentTime-=50")
|
||||||
|
.listenClick(evt -> video.setCurrentTime(50)))
|
||||||
HTMLButtonElement currentTimePlusButton = document.createElement("button").cast();
|
.withChild("br")
|
||||||
currentTimePlusButton.appendChild(document.createTextNode("currentTime+=10"));
|
.withChild("button", elem -> elem.withText("playbackRate++")
|
||||||
currentTimePlusButton.addEventListener("click", evt -> video.setCurrentTime(video.getCurrentTime() + 10));
|
.listenClick(evt -> video.addPlaybackRate(1)))
|
||||||
|
.withChild("button", elem -> elem.withText("playbackRate--")
|
||||||
HTMLButtonElement currentTimeMinusButton = document.createElement("button").cast();
|
.listenClick(evt -> video.addPlaybackRate(-1)))
|
||||||
currentTimeMinusButton.appendChild(document.createTextNode("currentTime-=10"));
|
.withChild("button", elem -> elem.withText("playbackRate+=0.1")
|
||||||
currentTimeMinusButton.addEventListener("click", evt -> video.setCurrentTime(video.getCurrentTime() - 10));
|
.listenClick(evt -> video.addPlaybackRate(0.1)))
|
||||||
|
.withChild("button", elem -> elem.withText("playbackRate-=0.1")
|
||||||
HTMLButtonElement currentTime50Button = document.createElement("button").cast();
|
.listenClick(evt -> video.addPlaybackRate(-0.1)))
|
||||||
currentTime50Button.appendChild(document.createTextNode("currentTime=50"));
|
.withChild("br")
|
||||||
currentTime50Button.addEventListener("click", evt -> video.setCurrentTime(50));
|
.withChild("button", elem -> elem.withText("volume+=1").listenClick(evt -> video.addVolume(0.1F)))
|
||||||
|
.withChild("button", elem -> elem.withText("volume-=1").listenClick(evt -> video.addVolume(-0.1F)))
|
||||||
HTMLButtonElement playbackRateIncrementButton = document.createElement("button").cast();
|
.withChild("button", elem -> elem.withText("mute").listenClick(evt -> video.setMuted(true)))
|
||||||
playbackRateIncrementButton.appendChild(document.createTextNode("playbackRate++"));
|
.withChild("button", elem -> elem.withText("unmute").listenClick(evt -> video.setMuted(false)));
|
||||||
playbackRateIncrementButton.addEventListener("click", evt -> video.setPlaybackRate(
|
|
||||||
video.getPlaybackRate() + 1));
|
|
||||||
|
|
||||||
HTMLButtonElement playbackRateDecrementButton = document.createElement("button").cast();
|
|
||||||
playbackRateDecrementButton.appendChild(document.createTextNode("playbackRate--"));
|
|
||||||
playbackRateDecrementButton.addEventListener("click", evt -> video.setPlaybackRate(
|
|
||||||
video.getPlaybackRate() - 1));
|
|
||||||
|
|
||||||
HTMLButtonElement playbackRatePlusButton = document.createElement("button").cast();
|
|
||||||
playbackRatePlusButton.appendChild(document.createTextNode("playbackRate+=0.1"));
|
|
||||||
playbackRatePlusButton.addEventListener("click", evt -> video.setPlaybackRate(video.getPlaybackRate() + 0.1));
|
|
||||||
|
|
||||||
HTMLButtonElement playbackRateMinusButton = document.createElement("button").cast();
|
|
||||||
playbackRateMinusButton.appendChild(document.createTextNode("playbackRate-=0.1"));
|
|
||||||
playbackRateMinusButton.addEventListener("click", evt -> video.setPlaybackRate(video.getPlaybackRate() - 0.1));
|
|
||||||
|
|
||||||
HTMLButtonElement volumePlusButton = document.createElement("button").cast();
|
|
||||||
volumePlusButton.appendChild(document.createTextNode("volume+=0.1"));
|
|
||||||
volumePlusButton.addEventListener("click", evt -> video.setVolume(video.getVolume() + 0.1f));
|
|
||||||
|
|
||||||
HTMLButtonElement volumeMinusButton = document.createElement("button").cast();
|
|
||||||
volumeMinusButton.appendChild(document.createTextNode("volume-=0.1"));
|
|
||||||
volumeMinusButton.addEventListener("click", evt -> video.setVolume(video.getVolume() - 0.1f));
|
|
||||||
|
|
||||||
HTMLButtonElement muteButton = document.createElement("button").cast();
|
|
||||||
muteButton.appendChild(document.createTextNode("muted=true"));
|
|
||||||
muteButton.addEventListener("click", evt -> video.setMuted(true));
|
|
||||||
|
|
||||||
HTMLButtonElement unmuteButton = document.createElement("button").cast();
|
|
||||||
unmuteButton.appendChild(document.createTextNode("muted=false"));
|
|
||||||
unmuteButton.addEventListener("click", evt -> video.setMuted(false));
|
|
||||||
|
|
||||||
HTMLElement divButtons = document.createElement("div");
|
|
||||||
divButtons.setAttribute("id", "buttons");
|
|
||||||
divButtons.appendChild(loadButton);
|
|
||||||
divButtons.appendChild(playButton);
|
|
||||||
divButtons.appendChild(pauseButton);
|
|
||||||
divButtons.appendChild(document.createElement("br"));
|
|
||||||
divButtons.appendChild(currentTimePlusButton);
|
|
||||||
divButtons.appendChild(currentTimeMinusButton);
|
|
||||||
divButtons.appendChild(currentTime50Button);
|
|
||||||
divButtons.appendChild(document.createElement("br"));
|
|
||||||
divButtons.appendChild(playbackRateIncrementButton);
|
|
||||||
divButtons.appendChild(playbackRateDecrementButton);
|
|
||||||
divButtons.appendChild(playbackRatePlusButton);
|
|
||||||
divButtons.appendChild(playbackRateMinusButton);
|
|
||||||
divButtons.appendChild(document.createElement("br"));
|
|
||||||
divButtons.appendChild(volumePlusButton);
|
|
||||||
divButtons.appendChild(volumeMinusButton);
|
|
||||||
divButtons.appendChild(muteButton);
|
|
||||||
divButtons.appendChild(unmuteButton);
|
|
||||||
|
|
||||||
HTMLBodyElement body = document.getBody();
|
HTMLBodyElement body = document.getBody();
|
||||||
body.appendChild(divVideo);
|
body.appendChild(divVideo);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user