From 32d9a5b04b6db05b007b49ce3d0f9d25421684e9 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 16 Feb 2015 19:36:08 +0100 Subject: [PATCH 1/5] Self-host GestureEvent methods --- .../mid/ui/gestures/GestureEventImpl.java | 90 ++++++++++++++----- .../gestures/GestureRegistrationManager.java | 17 +--- midp/gestures.js | 86 ------------------ 3 files changed, 70 insertions(+), 123 deletions(-) diff --git a/java/custom/com/nokia/mid/ui/gestures/GestureEventImpl.java b/java/custom/com/nokia/mid/ui/gestures/GestureEventImpl.java index 378447ef..668bdbc1 100644 --- a/java/custom/com/nokia/mid/ui/gestures/GestureEventImpl.java +++ b/java/custom/com/nokia/mid/ui/gestures/GestureEventImpl.java @@ -1,27 +1,75 @@ package com.nokia.mid.ui.gestures; +import com.sun.midp.events.NativeEvent; + public class GestureEventImpl implements GestureEvent { - public GestureEventImpl(int type, int dragDistanceX, int dragDistanceY, int startX, int startY, - float flickDirection, int flickSpeed, int flickSpeedX, int flickSpeedY, - int pinchDistanceStarting, int pinchDistanceCurrent, int pinchDistanceChange, - int pinchCenterX, int pinchCenterY, int pinchCenterChangeX, int pinchCenterChangeY) { - // Overridden in midp/gestures.js + NativeEvent nativeEvent; + + public GestureEventImpl(NativeEvent nativeEvent) { + this.nativeEvent = nativeEvent; } - native public int getType(); - native public int getDragDistanceX(); - native public int getDragDistanceY(); - native public int getStartX(); - native public int getStartY(); - native public float getFlickDirection(); - native public int getFlickSpeed(); - native public int getFlickSpeedX(); - native public int getFlickSpeedY(); - native public int getPinchDistanceStarting(); - native public int getPinchDistanceCurrent(); - native public int getPinchDistanceChange(); - native public int getPinchCenterX(); - native public int getPinchCenterY(); - native public int getPinchCenterChangeX(); - native public int getPinchCenterChangeY(); + public int getType() { + return nativeEvent.intParam1; + } + + public int getDragDistanceX() { + return nativeEvent.intParam2; + } + + public int getDragDistanceY() { + return nativeEvent.intParam3; + } + + public int getStartX() { + return nativeEvent.intParam5; + } + + public int getStartY() { + return nativeEvent.intParam6; + } + + public float getFlickDirection() { + return nativeEvent.floatParam1; + } + + public int getFlickSpeed() { + return nativeEvent.intParam7; + } + + public int getFlickSpeedX() { + return nativeEvent.intParam8; + } + + public int getFlickSpeedY() { + return nativeEvent.intParam9; + } + + public int getPinchDistanceStarting() { + return nativeEvent.intParam10; + } + + public int getPinchDistanceCurrent() { + return nativeEvent.intParam11; + } + + public int getPinchDistanceChange() { + return nativeEvent.intParam12; + } + + public int getPinchCenterX() { + return nativeEvent.intParam13; + } + + public int getPinchCenterY() { + return nativeEvent.intParam14; + } + + public int getPinchCenterChangeX() { + return nativeEvent.intParam15; + } + + public int getPinchCenterChangeY() { + return nativeEvent.intParam16; + } } diff --git a/java/custom/com/nokia/mid/ui/gestures/GestureRegistrationManager.java b/java/custom/com/nokia/mid/ui/gestures/GestureRegistrationManager.java index 15577cae..b503a8cb 100644 --- a/java/custom/com/nokia/mid/ui/gestures/GestureRegistrationManager.java +++ b/java/custom/com/nokia/mid/ui/gestures/GestureRegistrationManager.java @@ -41,22 +41,7 @@ public class GestureRegistrationManager implements EventListener { public void process(Event event) { NativeEvent nativeEvent = (NativeEvent)event; - GestureEvent gestureEvent = new GestureEventImpl(nativeEvent.intParam1, - nativeEvent.intParam2, - nativeEvent.intParam3, - nativeEvent.intParam5, - nativeEvent.intParam6, - nativeEvent.floatParam1, - nativeEvent.intParam7, - nativeEvent.intParam8, - nativeEvent.intParam9, - nativeEvent.intParam10, - nativeEvent.intParam11, - nativeEvent.intParam12, - nativeEvent.intParam13, - nativeEvent.intParam14, - nativeEvent.intParam15, - nativeEvent.intParam16); + GestureEvent gestureEvent = new GestureEventImpl(nativeEvent); for (int i = 0; i < zoneRegistrations.size(); i++) { ZoneRegistration zoneReg = (ZoneRegistration)zoneRegistrations.elementAt(i); diff --git a/midp/gestures.js b/midp/gestures.js index 0fa13f5c..792e0c96 100644 --- a/midp/gestures.js +++ b/midp/gestures.js @@ -29,89 +29,3 @@ Native["com/nokia/mid/ui/gestures/GestureInteractiveZone.contains.(II)Z"] = func Native["com/nokia/mid/ui/gestures/GestureInteractiveZone.supports.(I)Z"] = function(type) { return ((type & this.gestures) == type) ? 1 : 0; }; - -Override["com/nokia/mid/ui/gestures/GestureEventImpl..(IIIIIFIIIIIIIIII)V"] = -function(type, dragDistanceX, dragDistanceY, startX, startY, flickDirection, flickSpeed, flickSpeedX, flickSpeedY, - pinchDistanceStarting, pinchDistanceCurrent, pinchDistanceChange, pinchCenterX, pinchCenterY, - pinchCenterChangeX, pinchCenterChangeY) { - this.type = type; - this.dragDistanceX = dragDistanceX; - this.dragDistanceY = dragDistanceY; - this.startX = startX; - this.startY = startY; - this.flickDirection = flickDirection; - this.flickSpeed = flickSpeed; - this.flickSpeedX = flickSpeedX; - this.flickSpeedY = flickSpeedY; - this.pinchDistanceStarting = pinchDistanceStarting; - this.pinchDistanceCurrent = pinchDistanceCurrent; - this.pinchDistanceChange = pinchDistanceChange; - this.pinchCenterX = pinchCenterX; - this.pinchCenterY = pinchCenterY; - this.pinchCenterChangeX = pinchCenterChangeX; - this.pinchCenterChangeY = pinchCenterChangeY; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getType.()I"] = function() { - return this.type; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getDragDistanceX.()I"] = function() { - return this.dragDistanceX; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getDragDistanceY.()I"] = function() { - return this.dragDistanceY; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getStartX.()I"] = function() { - return this.startX; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getStartY.()I"] = function() { - return this.startY; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getFlickDirection.()F"] = function() { - return this.flickDirection; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getFlickSpeed.()I"] = function() { - return this.flickSpeed; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getFlickSpeedX.()I"] = function() { - return this.flickSpeedX; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getFlickSpeedY.()I"] = function() { - return this.flickSpeedY; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getPinchDistanceStarting.()I"] = function() { - return this.pinchDistanceStarting; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getPinchDistanceCurrent.()I"] = function() { - return this.pinchDistanceCurrent; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getPinchDistanceChange.()I"] = function() { - return this.pinchDistanceChange; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getPinchCenterX.()I"] = function() { - return this.pinchCenterX; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getPinchCenterY.()I"] = function() { - return this.pinchCenterY; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getPinchCenterChangeX.()I"] = function() { - return this.pinchCenterChangeX; -}; - -Native["com/nokia/mid/ui/gestures/GestureEventImpl.getPinchCenterChangeY.()I"] = function() { - return this.pinchCenterChangeY; -}; From 69afcabdeff16702576bcfb67af8f609f0d0f67e Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 16 Feb 2015 19:36:22 +0100 Subject: [PATCH 2/5] Add GestureEventImpl methods to aot-methods.txt --- aot-methods.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/aot-methods.txt b/aot-methods.txt index 7357dd87..9fba3cd8 100644 --- a/aot-methods.txt +++ b/aot-methods.txt @@ -297,4 +297,14 @@ java/util/Hashtable$HashtableEnumerator.nextElement.()Ljava/lang/Object; com/sun/midp/lcdui/DisplayDevice.isPrimaryDisplay.()Z com/sun/midp/main/MIDletProxy.getClassName.()Ljava/lang/String; com/sun/midp/rms/RmsEnvironment.getSecureFilenameBase.(I)Ljava/lang/String; -com/sun/midp/midletsuite/SuiteContainerAdapter.getSecureFilenameBase.(I)Ljava/lang/String; \ No newline at end of file +com/sun/midp/midletsuite/SuiteContainerAdapter.getSecureFilenameBase.(I)Ljava/lang/String; +com/nokia/mid/ui/gestures/GestureEventImpl..(Lcom/sun/midp/events/NativeEvent;)V +com/nokia/mid/ui/gestures/GestureEventImpl.getType.()I +com/nokia/mid/ui/gestures/GestureEventImpl.getDragDistanceX.()I +com/nokia/mid/ui/gestures/GestureEventImpl.getDragDistanceY.()I +com/nokia/mid/ui/gestures/GestureEventImpl.getStartX.()I +com/nokia/mid/ui/gestures/GestureEventImpl.getStartY.()I +com/nokia/mid/ui/gestures/GestureEventImpl.getFlickDirection.()F +com/nokia/mid/ui/gestures/GestureEventImpl.getFlickSpeed.()I +com/nokia/mid/ui/gestures/GestureEventImpl.getFlickSpeedX.()I +com/nokia/mid/ui/gestures/GestureEventImpl.getFlickSpeedY.()I \ No newline at end of file From 6787575effa80f9f64afbce2628964d1b2d48845 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 16 Feb 2015 19:37:35 +0100 Subject: [PATCH 3/5] Allow running benchmarks using the JS shell --- jsshell.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/jsshell.js b/jsshell.js index 3c1b74cb..2037d585 100755 --- a/jsshell.js +++ b/jsshell.js @@ -65,13 +65,22 @@ var document = { }, getBoundingClientRect: function() { return { top: 0, left: 0, width: 0, height: 0 }; - } + }, + querySelector: function() { + return { style: "" }; + }, + dispatchEvent: function(event) { + }, + style: "", }; }, addEventListener: function() { }, }; +var Event = function() { +} + var config = { logConsole: "native", args: "", @@ -81,8 +90,9 @@ try { load("libs/relooper.js", "build/j2me.js","libs/zipfile.js", "blackBox.js", "libs/encoding.js", "util.js", "override.js", "native.js", "tests/override.js", - "string.js", "midp/midp.js", - "libs/long.js", "midp/crypto.js", "libs/forge/md5.js", "libs/forge/util.js"); + "string.js", "midp/midp.js", "midp/gestures.js", + "libs/long.js", "midp/crypto.js", "libs/forge/md5.js", "libs/forge/util.js", + "build/classes.jar.js"); // load("build/classes.jar.js"); // load("build/program.jar.js"); @@ -96,6 +106,7 @@ try { CLASSES.addPath("java/classes.jar", snarf("java/classes.jar", "binary").buffer); CLASSES.addPath("tests/tests.jar", snarf("tests/tests.jar", "binary").buffer); + CLASSES.addPath("bench/benchmar.jar", snarf("bench/benchmark.jar", "binary").buffer); //CLASSES.addPath("program.jar", snarf("program.jar", "binary").buffer); CLASSES.initializeBuiltinClasses(); From 65c4d7d96f74fa233b0fc51f0a0b3c21e89c5f60 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 16 Feb 2015 19:44:02 +0100 Subject: [PATCH 4/5] Construct GestureEventImpl object only once --- aot-methods.txt | 1 - .../com/nokia/mid/ui/gestures/GestureEventImpl.java | 6 +----- .../nokia/mid/ui/gestures/GestureRegistrationManager.java | 8 ++++++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/aot-methods.txt b/aot-methods.txt index 9fba3cd8..47152e5b 100644 --- a/aot-methods.txt +++ b/aot-methods.txt @@ -298,7 +298,6 @@ com/sun/midp/lcdui/DisplayDevice.isPrimaryDisplay.()Z com/sun/midp/main/MIDletProxy.getClassName.()Ljava/lang/String; com/sun/midp/rms/RmsEnvironment.getSecureFilenameBase.(I)Ljava/lang/String; com/sun/midp/midletsuite/SuiteContainerAdapter.getSecureFilenameBase.(I)Ljava/lang/String; -com/nokia/mid/ui/gestures/GestureEventImpl..(Lcom/sun/midp/events/NativeEvent;)V com/nokia/mid/ui/gestures/GestureEventImpl.getType.()I com/nokia/mid/ui/gestures/GestureEventImpl.getDragDistanceX.()I com/nokia/mid/ui/gestures/GestureEventImpl.getDragDistanceY.()I diff --git a/java/custom/com/nokia/mid/ui/gestures/GestureEventImpl.java b/java/custom/com/nokia/mid/ui/gestures/GestureEventImpl.java index 668bdbc1..df489639 100644 --- a/java/custom/com/nokia/mid/ui/gestures/GestureEventImpl.java +++ b/java/custom/com/nokia/mid/ui/gestures/GestureEventImpl.java @@ -3,11 +3,7 @@ package com.nokia.mid.ui.gestures; import com.sun.midp.events.NativeEvent; public class GestureEventImpl implements GestureEvent { - NativeEvent nativeEvent; - - public GestureEventImpl(NativeEvent nativeEvent) { - this.nativeEvent = nativeEvent; - } + protected NativeEvent nativeEvent; public int getType() { return nativeEvent.intParam1; diff --git a/java/custom/com/nokia/mid/ui/gestures/GestureRegistrationManager.java b/java/custom/com/nokia/mid/ui/gestures/GestureRegistrationManager.java index b503a8cb..57d208c8 100644 --- a/java/custom/com/nokia/mid/ui/gestures/GestureRegistrationManager.java +++ b/java/custom/com/nokia/mid/ui/gestures/GestureRegistrationManager.java @@ -21,6 +21,11 @@ public class GestureRegistrationManager implements EventListener { private static Vector zoneRegistrations = new Vector(); private static Hashtable listenerRegistrations = new Hashtable(); + // http://developer.nokia.com/resources/library/Java/_zip/GUID-237420DE-CCBE-4A74-A129-572E0708D428/com/nokia/mid/ui/gestures/GestureEvent.html + // The API imposes the restriction that the gesture event data is only valid during the call to + // GestureListener.gestureAction(Object, GestureInteractiveZone, GestureEvent). + private static GestureEventImpl gestureEvent = new GestureEventImpl(); + static { EventQueue eventQueue = EventQueue.getEventQueue(); eventQueue.registerEventListener(EventTypes.GESTURE_EVENT, GestureRegistrationManager.getRegistrationManagerInstance()); @@ -40,8 +45,7 @@ public class GestureRegistrationManager implements EventListener { } public void process(Event event) { - NativeEvent nativeEvent = (NativeEvent)event; - GestureEvent gestureEvent = new GestureEventImpl(nativeEvent); + gestureEvent.nativeEvent = (NativeEvent)event; for (int i = 0; i < zoneRegistrations.size(); i++) { ZoneRegistration zoneReg = (ZoneRegistration)zoneRegistrations.elementAt(i); From 2aae7086a1c1d421fd411bcbec5bee81da233c4c Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 17 Feb 2015 21:58:14 +0100 Subject: [PATCH 5/5] Fix bench/benchmar.jar typo --- jsshell.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsshell.js b/jsshell.js index 2037d585..d877867f 100755 --- a/jsshell.js +++ b/jsshell.js @@ -106,7 +106,7 @@ try { CLASSES.addPath("java/classes.jar", snarf("java/classes.jar", "binary").buffer); CLASSES.addPath("tests/tests.jar", snarf("tests/tests.jar", "binary").buffer); - CLASSES.addPath("bench/benchmar.jar", snarf("bench/benchmark.jar", "binary").buffer); + CLASSES.addPath("bench/benchmark.jar", snarf("bench/benchmark.jar", "binary").buffer); //CLASSES.addPath("program.jar", snarf("program.jar", "binary").buffer); CLASSES.initializeBuiltinClasses();