Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Touch Event. Fixes issue #579 #580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions jso/apis/src/main/java/org/teavm/jso/dom/events/Touch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2014 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;

// From https://developer.mozilla.org/en-US/docs/Web/API/Touch

public interface Touch extends JSObject {

@JSProperty
long getIdentifier();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work. JavaScript does not provide int64 type (or at least, did not provide by the time touch event spec was written). I'd replaced this with int, but you should test on real use cases if int fits well or you need double.


@JSProperty
int getScreenX();

@JSProperty
int getScreenY();

@JSProperty
int getClientX();

@JSProperty
int getClientY();

@JSProperty
int getPageX();

@JSProperty
int getPageY();

@JSProperty
EventTarget getTarget();

@JSProperty
int getRadiusX();

@JSProperty
int getRadiusY();

// Not sure if this is an int or a float. This is angle in Degrees
@JSProperty
int getRotationAngle();

// between 0.0 (no pressure) and 1.0 (max pressure)
@JSProperty
float getForce();
}
46 changes: 46 additions & 0 deletions jso/apis/src/main/java/org/teavm/jso/dom/events/TouchEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2014 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.JSArray;

// From https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent

public interface TouchEvent extends Event {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, you created an event class. But how one's to use it. What about declaring corresponding event target interface, like I did it with MouseEventTarget, for example?


@JSProperty
boolean getCtrlKey();

@JSProperty
boolean getShiftKey();

@JSProperty
boolean getAltKey();

@JSProperty
boolean getMetaKey();

@JSProperty
JSArray<Touch> getChangedTouches();

@JSProperty
JSArray<Touch> getTargetTouches();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Is it really necessary to expose this property as JSArray? What about just Touch[]?
  2. If you still want JS native type, consider JSArrayReader<Touch> here


@JSProperty
JSArray<Touch> getTouches();

}