mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
jso: add TouchEvent bindings
This commit is contained in:
parent
9b3652697d
commit
8889b63df7
|
@ -27,9 +27,10 @@ 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.Registration;
|
||||||
import org.teavm.jso.dom.events.StorageEvent;
|
import org.teavm.jso.dom.events.StorageEvent;
|
||||||
|
import org.teavm.jso.dom.events.TouchEventTarget;
|
||||||
|
|
||||||
public interface WindowEventTarget extends EventTarget, FocusEventTarget, MouseEventTarget, KeyboardEventTarget,
|
public interface WindowEventTarget extends EventTarget, FocusEventTarget, MouseEventTarget, KeyboardEventTarget,
|
||||||
LoadEventTarget, GamepadEventTarget {
|
LoadEventTarget, GamepadEventTarget, TouchEventTarget {
|
||||||
@Deprecated
|
@Deprecated
|
||||||
default void listenBeforeOnload(EventListener<Event> listener) {
|
default void listenBeforeOnload(EventListener<Event> listener) {
|
||||||
addEventListener("beforeunload", listener);
|
addEventListener("beforeunload", listener);
|
||||||
|
|
123
jso/apis/src/main/java/org/teavm/jso/dom/events/Touch.java
Normal file
123
jso/apis/src/main/java/org/teavm/jso/dom/events/Touch.java
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 pizzadox9999, 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p></p>The Touch interface represents a single contact point on a touch-sensitive device.
|
||||||
|
* The contact point is commonly a finger or stylus and the device may be a touchscreen or trackpad.</p>
|
||||||
|
*
|
||||||
|
* <p>The {@link #getRadiusX()}, {@link #getRadiusY()}, and {@link #getRotationAngle()}
|
||||||
|
* describe the area of contact between the user and the screen, the touch area.
|
||||||
|
* This can be helpful when dealing with imprecise pointing devices such as fingers.
|
||||||
|
* These values are set to describe an ellipse that as closely as possible matches
|
||||||
|
* the entire area of contact (such as the user's fingertip).</p>
|
||||||
|
*/
|
||||||
|
public interface Touch extends JSObject {
|
||||||
|
/**
|
||||||
|
* Returns a unique identifier for this Touch object. A given touch point (say,
|
||||||
|
* by a finger) will have the same identifier for the duration of its movement
|
||||||
|
* around the surface. This lets you ensure that you're tracking the same touch
|
||||||
|
* all the time.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
int getIdentifier();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the X coordinate of the touch point relative to the left edge of the
|
||||||
|
* screen.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getScreenX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Y coordinate of the touch point relative to the top edge of the
|
||||||
|
* screen.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getScreenY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the X coordinate of the touch point relative to the left edge of the
|
||||||
|
* browser viewport, not including any scroll offset.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getClientX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Y coordinate of the touch point relative to the top edge of the
|
||||||
|
* browser viewport, not including any scroll offset.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getClientY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the X coordinate of the touch point relative to the left edge of the
|
||||||
|
* document. Unlike clientX, this value includes the horizontal scroll offset,
|
||||||
|
* if any.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getPageX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Y coordinate of the touch point relative to the top of the
|
||||||
|
* document. Unlike clientY, this value includes the vertical scroll offset, if
|
||||||
|
* any.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getPageY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link TouchEventTarget} on which the touch point started when it was first placed
|
||||||
|
* on the surface, even if the touch point has since moved outside the
|
||||||
|
* interactive area of that element or even been removed from the document.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
TouchEventTarget getTarget();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the X radius of the ellipse that most closely circumscribes the area
|
||||||
|
* of contact with the screen. The value is in pixels of the same scale as
|
||||||
|
* screenX.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getRadiusX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Y radius of the ellipse that most closely circumscribes the area
|
||||||
|
* of contact with the screen. The value is in pixels of the same scale as
|
||||||
|
* screenY.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getRadiusY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the angle (in degrees) that the ellipse described by radiusX and
|
||||||
|
* radiusY must be rotated, clockwise, to most accurately cover the area of
|
||||||
|
* contact between the user and the surface.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getRotationAngle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the amount of pressure being applied to the surface by the user, as a
|
||||||
|
* float between 0.0 (no pressure) and 1.0 (maximum pressure).
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
double getForce();
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 pizzadox9999, 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.JSProperty;
|
||||||
|
import org.teavm.jso.core.JSArrayReader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p></p>The <strong>TouchEvent</strong> interface represents an UIEvent which is sent when the state
|
||||||
|
* of contacts with a touch-sensitive surface changes.
|
||||||
|
* This surface can be a touch screen or trackpad, for example.
|
||||||
|
* The event can describe one or more points of contact with the screen and includes support
|
||||||
|
* for detecting movement, addition and removal of contact points, and so forth.</p>
|
||||||
|
*
|
||||||
|
* <p>Touches are represented by the {@link Touch} object; each touch is described by a position,
|
||||||
|
* size and shape, amount of pressure, and target element.</p>
|
||||||
|
*/
|
||||||
|
public interface TouchEvent extends Event {
|
||||||
|
/**
|
||||||
|
* A {@code boolean} value indicating whether the alt key was down when the touch
|
||||||
|
* event was fired.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
boolean isAltKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all the {@link Touch} objects representing individual points of
|
||||||
|
* contact whose states changed between the previous touch event and this one.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
JSArrayReader<Touch> getChangedTouches();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@code boolean} value indicating whether the control key was down when the
|
||||||
|
* touch event was fired.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
boolean isCtrlKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@code boolean} value indicating whether the meta key was down when the
|
||||||
|
* touch event was fired.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
boolean isMetaKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@code boolean} value indicating whether the shift key was down when the
|
||||||
|
* touch event was fired.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
boolean isShiftKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all the {@link Touch} objects that are both currently in contact with
|
||||||
|
* the touch surface and were also started on the same element that is the
|
||||||
|
* target of the event.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
JSArrayReader<Touch> getTargetTouches();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all the {@link Touch} objects representing all current points of
|
||||||
|
* contact with the surface, regardless of target or changed status.
|
||||||
|
*/
|
||||||
|
@JSProperty
|
||||||
|
JSArrayReader<Touch> getTouches();
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 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;
|
||||||
|
|
||||||
|
public interface TouchEventTarget extends EventTarget {
|
||||||
|
/**
|
||||||
|
* The touchstart event is fired when one or more touch points are placed on the touch surface.
|
||||||
|
*/
|
||||||
|
default Registration onTouchStart(EventListener<TouchEvent> listener) {
|
||||||
|
return onEvent("touchstart", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The touchend event fires when one or more touch points are removed from the touch surface.
|
||||||
|
* Remember that it is possible to get a touchcancel event instead.
|
||||||
|
*/
|
||||||
|
default Registration onTouchEnd(EventListener<TouchEvent> listener) {
|
||||||
|
return onEvent("touchend", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>The touchcancel event is fired when one or more touch points have been disrupted in an
|
||||||
|
* implementation-specific manner.</p>
|
||||||
|
*
|
||||||
|
* <p>Some examples of situations that will trigger a touchcancel event:</p>
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>A hardware event occurs that cancels the touch activities.
|
||||||
|
* This may include, for example, the user switching applications using an application switcher
|
||||||
|
* interface or the "home" button on a mobile device.</li>
|
||||||
|
* <li>The device's screen orientation is changed while the touch is active.</li>
|
||||||
|
* <li>The browser decides that the user started touch input accidentally.
|
||||||
|
* This can happen if, for example, the hardware supports palm rejection to prevent a hand resting on
|
||||||
|
* the display while using a stylus from accidentally triggering events.</li>
|
||||||
|
* <li>The {@code touch-action} CSS property prevents the input from continuing.
|
||||||
|
* When the user interacts with too many fingers simultaneously, the browser can fire this event
|
||||||
|
* for all existing pointers (even if the user is still touching the screen).</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
default Registration onTouchCancel(EventListener<TouchEvent> listener) {
|
||||||
|
return onEvent("touchcancel", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The touchmove event is fired when one or more touch points are moved along the touch surface.
|
||||||
|
*/
|
||||||
|
default Registration onTouchMove(EventListener<TouchEvent> listener) {
|
||||||
|
return onEvent("touchmove", listener);
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ import org.teavm.jso.dom.events.FocusEventTarget;
|
||||||
import org.teavm.jso.dom.events.KeyboardEventTarget;
|
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.MouseEventTarget;
|
import org.teavm.jso.dom.events.MouseEventTarget;
|
||||||
|
import org.teavm.jso.dom.events.TouchEventTarget;
|
||||||
import org.teavm.jso.dom.events.WheelEventTarget;
|
import org.teavm.jso.dom.events.WheelEventTarget;
|
||||||
import org.teavm.jso.dom.types.DOMTokenList;
|
import org.teavm.jso.dom.types.DOMTokenList;
|
||||||
import org.teavm.jso.dom.xml.Element;
|
import org.teavm.jso.dom.xml.Element;
|
||||||
|
@ -30,7 +31,7 @@ import org.teavm.jso.dom.xml.Node;
|
||||||
import org.teavm.jso.dom.xml.NodeList;
|
import org.teavm.jso.dom.xml.NodeList;
|
||||||
|
|
||||||
public abstract class HTMLElement implements Element, ElementCSSInlineStyle, EventTarget, FocusEventTarget,
|
public abstract class HTMLElement implements Element, ElementCSSInlineStyle, EventTarget, FocusEventTarget,
|
||||||
MouseEventTarget, WheelEventTarget, KeyboardEventTarget, LoadEventTarget {
|
MouseEventTarget, WheelEventTarget, KeyboardEventTarget, LoadEventTarget, TouchEventTarget {
|
||||||
@Override
|
@Override
|
||||||
public abstract NodeList<? extends HTMLElement> getElementsByTagName(String name);
|
public abstract NodeList<? extends HTMLElement> getElementsByTagName(String name);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user