Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Buschtoens2012-01-27 13:49:01 +0000
committerTim Buschtoens2012-01-27 13:49:01 +0000
commitbc9012eacc0f752662aee78cb80f94b9b1833945 (patch)
tree89a4f4f3ffe85a83d293cf0dfe3f16d6f21e584d
parentff28887c09f68f0fccdd293607e8b82c170f61f5 (diff)
downloadorg.eclipse.rap.incubator.clientscripting-bc9012eacc0f752662aee78cb80f94b9b1833945.tar.gz
org.eclipse.rap.incubator.clientscripting-bc9012eacc0f752662aee78cb80f94b9b1833945.tar.xz
org.eclipse.rap.incubator.clientscripting-bc9012eacc0f752662aee78cb80f94b9b1833945.zip
event.doit support for text input
-rw-r--r--org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventBinding_Test.js15
-rw-r--r--org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventProxy_Test.js2
-rw-r--r--org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js6
-rw-r--r--org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventBinding.js3
-rw-r--r--org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventProxy.js22
5 files changed, 45 insertions, 3 deletions
diff --git a/org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventBinding_Test.js b/org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventBinding_Test.js
index 6b38271..f0767a7 100644
--- a/org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventBinding_Test.js
+++ b/org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventBinding_Test.js
@@ -17,6 +17,7 @@ var TestUtil = org.eclipse.rwt.test.fixture.TestUtil;
var Processor = org.eclipse.rwt.protocol.Processor;
var ObjectManager = org.eclipse.rwt.protocol.ObjectManager;
var Function = org.eclipse.rap.clientscripting.Function;
+var EventHandlerUtil = org.eclipse.rwt.EventHandlerUtil;
var text;
@@ -76,6 +77,20 @@ qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", {
assertTrue( TestUtil.hasNoObjects( event ) );
},
+ testDoItFalse : function() {
+ var listener = {
+ "call" : function( event ) {
+ event.doit = false;
+ }
+ };
+
+ var binding = new EventBinding( text, "KeyDown", listener );
+ var domEvent = TestUtil.createFakeDomKeyEvent( text.getElement(), "keypress", "a" );
+ TestUtil.fireFakeDomEvent( domEvent );
+
+ assertTrue( EventHandlerUtil.wasStopped( domEvent ) );
+ },
+
/////////
// helper
diff --git a/org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventProxy_Test.js b/org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventProxy_Test.js
index c295eac..cfe1673 100644
--- a/org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventProxy_Test.js
+++ b/org.eclipse.rap.clientscripting.test/js/org/eclipse/rap/clientscripting/EventProxy_Test.js
@@ -60,8 +60,6 @@ qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", {
assertEquals( "a", eventProxy.character );
},
-
- // TODO testDoIt
/////////
// Helper
diff --git a/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js b/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js
index 2ff85cd..0ae29cb 100644
--- a/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js
+++ b/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js
@@ -45,6 +45,12 @@ org.eclipse.rap.clientscripting.ClientScriptingUtil = {
return result;
},
+ postProcessEvent : function( eventProxy, event ) {
+ if( eventProxy.doit === false ) {
+ event.preventDefault();
+ }
+ },
+
initEvent : function( event, type, originalEvent ) {
var control = org.eclipse.swt.WidgetUtil.getControl( originalEvent.getTarget() );
event.widget = org.eclipse.rap.clientscripting.WidgetProxy.getInstance( control );
diff --git a/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventBinding.js b/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventBinding.js
index 90b5418..8853403 100644
--- a/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventBinding.js
+++ b/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventBinding.js
@@ -30,11 +30,12 @@ org.eclipse.rap.clientscripting.EventBinding.prototype = {
_unbind : function() {
this._source.removeEventListener( this._nativeType, this._processEvent, this );
},
-
+
_processEvent : function( event ) {
var EventProxy = org.eclipse.rap.clientscripting.EventProxy;
var eventProxy = new EventProxy( this._protocolAdapter, event );
this._targetFunction.call( eventProxy );
+ org.eclipse.rap.clientscripting.ClientScriptingUtil.postProcessEvent( eventProxy, event );
EventProxy.disposeEventProxy( eventProxy );
},
diff --git a/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventProxy.js b/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventProxy.js
index 95d05ab..9090df9 100644
--- a/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventProxy.js
+++ b/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/EventProxy.js
@@ -17,12 +17,34 @@ org.eclipse.rap.clientscripting.EventProxy = function( eventType, originalEvent
org.eclipse.rap.clientscripting.EventProxy.prototype = {
+ /**
+ * An object representing the widget that issued the event.
+ * It has setter and getter named after the properties used in the RAP protocol.
+ * Only a subset of getter is currently supported.
+ * (See org.eclipse.rap.clientscripting.ClientScriptingUtil#attachGetter.)
+ * Setting properties might result in server and client getting out-of-sync in RAP 1.5,
+ * unless it is a property that can be changed by user-input (e.g. selection).
+ */
widget : null,
+ /**
+ * depending on the event, a flag indicating whether the operation should be
+ * allowed. Setting this field to false will cancel the operation.
+ * Currently only supports preventing input into a Text or Text-like widget.
+ */
doit : true,
+ /**
+ * depending on the event, the character represented by the key that was
+ * typed. This is the final character that results after all modifiers have
+ * been applied. For non-printable keys (like arrow-keys) this field is not set.
+ * Changing its value has no effect.
+ */
character : '\u0000',
+ /**
+ * Currently not supported.
+ */
keyCode : 0,
};

Back to the top