|
From: <et...@us...> - 2011-10-19 23:51:58
|
Revision: 4493
http://mxquery.svn.sourceforge.net/mxquery/?rev=4493&view=rev
Author: etterth
Date: 2011-10-19 23:51:52 +0000 (Wed, 19 Oct 2011)
Log Message:
-----------
- added the functions b:preventDefault() and b:stopPropagation()
- added overloads for capturing in b:addEventListener()
- added a test for capturing and b:stopPropagation
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/EventListeners.java
Added Paths:
-----------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/PreventDefault.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/StopPropagation.java
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-10-19 12:37:25 UTC (rev 4492)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -126,7 +126,7 @@
JavaScriptObject handler = createHandler(fi);
- nativeAddEventListener(el, eventName, handler, false);
+ nativeAddEventListener(el, eventName, handler, captures);
lst.add(new FunctionItemAndHandler(fi, handler,captures));
}
@@ -314,9 +314,6 @@
e.printStackTrace();
}
// }
- // TODO decide this dynamically
- event.stopPropagation();
- event.preventDefault();
}
/**
* the callback called by any listened window event
@@ -566,6 +563,14 @@
return false;
}
+ public static void stopPropagation() {
+ current_event.stopPropagation();
+ }
+
+ public static void preventDefault() {
+ current_event.preventDefault();
+ }
+
}
class NodeAndEventName {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-10-19 12:37:25 UTC (rev 4492)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-10-19 23:51:52 UTC (rev 4493)
@@ -237,10 +237,12 @@
</parameters>
<className>RemoveAnonymousEventListener</className>
</functionDescription>
+<!-- dom -->
<functionDescription>
<functionName>dom</functionName>
<className>Dom</className>
</functionDescription>
+<!-- windowinfo -->
<functionDescription>
<functionName>windowInfo</functionName>
<className>WindowInfo</className>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-10-19 12:37:25 UTC (rev 4492)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -43,6 +43,7 @@
TypeInfo xs_dateTime = new TypeInfo(FunctionGallery.getType("xs:dateTime",ctx), Type.OCCURRENCE_IND_EXACTLY_ONE,null);
TypeInfo node___plus = new TypeInfo(FunctionGallery.getType("node()+",ctx), Type.OCCURRENCE_IND_ONE_OR_MORE,null);
TypeInfo node__ = new TypeInfo(FunctionGallery.getType("node()",ctx), Type.OCCURRENCE_IND_EXACTLY_ONE,null);
+ TypeInfo xs_boolean = new TypeInfo(FunctionGallery.getType("xs:boolean",ctx), Type.OCCURRENCE_IND_EXACTLY_ONE,null);
TypeInfo xs_string_quest = new TypeInfo(FunctionGallery.getType("xs:string?",ctx), Type.OCCURRENCE_IND_ZERO_OR_ONE,null);
TypeInfo numeric_quest = new TypeInfo(FunctionGallery.getType("numeric?",ctx), Type.OCCURRENCE_IND_ZERO_OR_ONE,null);
TypeInfo xs_date_quest = new TypeInfo(FunctionGallery.getType("xs:date?",ctx), Type.OCCURRENCE_IND_ZERO_OR_ONE,null);
@@ -694,6 +695,30 @@
qn = new QName(
"http://xqib.org",
"b",
+ "addEventListener");
+ paramTypes = new TypeInfo[4];
+
+ paramTypes[0] = node___plus;
+ paramTypes[1] = xs_string;
+ paramTypes[2] = function__;
+ paramTypes[3] = xs_boolean;
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.AddEventListener iter = new ch.ethz.mxquery.functions.b.AddEventListener();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"removeEventListener");
paramTypes = new TypeInfo[3];
@@ -717,6 +742,30 @@
qn = new QName(
"http://xqib.org",
"b",
+ "removeEventListener");
+ paramTypes = new TypeInfo[4];
+
+ paramTypes[0] = node__;
+ paramTypes[1] = xs_string;
+ paramTypes[2] = function__;
+ paramTypes[3] = xs_boolean;
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.RemoveEventListener iter = new ch.ethz.mxquery.functions.b.RemoveEventListener();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"removeAnonymousEventListeners");
paramTypes = new TypeInfo[2];
@@ -739,6 +788,46 @@
qn = new QName(
"http://xqib.org",
"b",
+ "preventDefault");
+ paramTypes = new TypeInfo[0];
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.PreventDefault iter = new ch.ethz.mxquery.functions.b.PreventDefault();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "stopPropagation");
+ paramTypes = new TypeInfo[0];
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
+
+ {
+ ch.ethz.mxquery.functions.b.StopPropagation iter = new ch.ethz.mxquery.functions.b.StopPropagation();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"dom");
paramTypes = new TypeInfo[0];
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/PreventDefault.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/PreventDefault.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/PreventDefault.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -0,0 +1,34 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import ch.ethz.mxqjs.client.Environment;
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.model.Iterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class PreventDefault extends Iterator {
+
+ public PreventDefault() {
+ super(null,null);
+ }
+
+ @Override
+ public TokenInterface next() throws MXQueryException {
+ Environment.preventDefault();
+ return Token.END_SEQUENCE_TOKEN;
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ PreventDefault copy = new PreventDefault();
+ copy.setContext(context, true);
+ return copy;
+ }
+
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/StopPropagation.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/StopPropagation.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/StopPropagation.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -0,0 +1,35 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import ch.ethz.mxqjs.client.Environment;
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.model.EmptySequenceIterator;
+import ch.ethz.mxquery.model.Iterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class StopPropagation extends Iterator {
+
+ public StopPropagation() {
+ super(null,null);
+ }
+
+ @Override
+ public TokenInterface next() throws MXQueryException {
+ Environment.stopPropagation();
+ return Token.END_SEQUENCE_TOKEN;
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ StopPropagation copy = new StopPropagation();
+ copy.setContext(context, true);
+ return copy;
+ }
+
+}
Modified: trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/EventListeners.java
===================================================================
--- trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/EventListeners.java 2011-10-19 12:37:25 UTC (rev 4492)
+++ trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/EventListeners.java 2011-10-19 23:51:52 UTC (rev 4493)
@@ -35,6 +35,34 @@
@Test
/**
+ * test the b:addEventListener with capturing and stopPropagation
+ */
+ public void event_add_listener_stopPropagation() throws Exception {
+ driver.get(executionpath + "/test/test.html");
+ executeNewScript("insert node <div id='b1_parent'><div id='b1' type='button'>text</div></div> as first into b:dom()//body");
+ executeNewScript("declare updating function local:onclick($loc, $evtObj) {\n" +
+ " insert node <p name='b1_fired'/> as last into b:dom()//body\n" +
+ "};\n" +
+ "b:addEventListener(b:dom()/id('b1'), \"onclick\", local:onclick#2, true())");
+ executeNewScript("declare updating function local:onclick($loc, $evtObj) {\n" +
+ " insert node <p name='parent_fired'/> as last into b:dom()//body\n" +
+ ", b:stopPropagation()\n" +
+ "};\n" +
+ "b:addEventListener(b:dom()/id('b1_parent'), \"onclick\", local:onclick#2, true())");
+
+ WebElement button = driver.findElementById("b1");
+ button.click();
+ button.click();
+
+ //if the capture fails, 4 are added
+ Assert.assertEquals(2,driver.findElementsByTagName("p").size());
+ //if the capture is correct, all elements created are from the parent
+ Assert.assertEquals(2,driver.findElementsByName("parent_fired").size());
+ }
+
+
+ @Test
+ /**
* test b:removeEventListener
* the click should only trigger an insert once
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|