Bug 477323 - WHATWG HTML5 drag and drop event handlers could not be set dynamically, r+sr=smaug, a=jst
authorHonza Bambas <honzab.moz@firemni.cz>
Wed, 25 Feb 2009 13:24:00 +0100
changeset 23423 5ee71b8d3cdbaf421a0e0f9bd0bacee2d2590704
parent 23422 9ae1b088d9e4652cf9eeb798484ff31c6bbf820d
child 23424 23152c9ee5779bb7f9639971ae93398e311ff1ed
push id767
push userhonzab.moz@firemni.cz
push dateWed, 25 Feb 2009 12:27:55 +0000
reviewersjst
bugs477323
milestone1.9.1b3pre
Bug 477323 - WHATWG HTML5 drag and drop event handlers could not be set dynamically, r+sr=smaug, a=jst
dom/src/base/nsDOMClassInfo.cpp
dom/src/base/nsDOMClassInfo.h
dom/tests/mochitest/whatwg/Makefile.in
dom/tests/mochitest/whatwg/test_bug477323.html
--- a/dom/src/base/nsDOMClassInfo.cpp
+++ b/dom/src/base/nsDOMClassInfo.cpp
@@ -1394,16 +1394,23 @@ jsval nsDOMClassInfo::sOnbeforeunload_id
 jsval nsDOMClassInfo::sOnunload_id        = JSVAL_VOID;
 jsval nsDOMClassInfo::sOnpageshow_id      = JSVAL_VOID;
 jsval nsDOMClassInfo::sOnpagehide_id      = JSVAL_VOID;
 jsval nsDOMClassInfo::sOnabort_id         = JSVAL_VOID;
 jsval nsDOMClassInfo::sOnerror_id         = JSVAL_VOID;
 jsval nsDOMClassInfo::sOnpaint_id         = JSVAL_VOID;
 jsval nsDOMClassInfo::sOnresize_id        = JSVAL_VOID;
 jsval nsDOMClassInfo::sOnscroll_id        = JSVAL_VOID;
+jsval nsDOMClassInfo::sOndrag_id          = JSVAL_VOID;
+jsval nsDOMClassInfo::sOndragend_id       = JSVAL_VOID;
+jsval nsDOMClassInfo::sOndragenter_id     = JSVAL_VOID;
+jsval nsDOMClassInfo::sOndragleave_id     = JSVAL_VOID;
+jsval nsDOMClassInfo::sOndragover_id      = JSVAL_VOID;
+jsval nsDOMClassInfo::sOndragstart_id     = JSVAL_VOID;
+jsval nsDOMClassInfo::sOndrop_id          = JSVAL_VOID;
 jsval nsDOMClassInfo::sScrollIntoView_id  = JSVAL_VOID;
 jsval nsDOMClassInfo::sScrollX_id         = JSVAL_VOID;
 jsval nsDOMClassInfo::sScrollY_id         = JSVAL_VOID;
 jsval nsDOMClassInfo::sScrollMaxX_id      = JSVAL_VOID;
 jsval nsDOMClassInfo::sScrollMaxY_id      = JSVAL_VOID;
 jsval nsDOMClassInfo::sOpen_id            = JSVAL_VOID;
 jsval nsDOMClassInfo::sItem_id            = JSVAL_VOID;
 jsval nsDOMClassInfo::sNamedItem_id       = JSVAL_VOID;
@@ -1586,16 +1593,23 @@ nsDOMClassInfo::DefineStaticJSVals(JSCon
   SET_JSVAL_TO_STRING(sOnunload_id,        cx, "onunload");
   SET_JSVAL_TO_STRING(sOnpageshow_id,      cx, "onpageshow");
   SET_JSVAL_TO_STRING(sOnpagehide_id,      cx, "onpagehide");
   SET_JSVAL_TO_STRING(sOnabort_id,         cx, "onabort");
   SET_JSVAL_TO_STRING(sOnerror_id,         cx, "onerror");
   SET_JSVAL_TO_STRING(sOnpaint_id,         cx, "onpaint");
   SET_JSVAL_TO_STRING(sOnresize_id,        cx, "onresize");
   SET_JSVAL_TO_STRING(sOnscroll_id,        cx, "onscroll");
+  SET_JSVAL_TO_STRING(sOndrag_id,          cx, "ondrag");
+  SET_JSVAL_TO_STRING(sOndragend_id,       cx, "ondragend");
+  SET_JSVAL_TO_STRING(sOndragenter_id,     cx, "ondragenter");
+  SET_JSVAL_TO_STRING(sOndragleave_id,     cx, "ondragleave");
+  SET_JSVAL_TO_STRING(sOndragover_id,      cx, "ondragover");
+  SET_JSVAL_TO_STRING(sOndragstart_id,     cx, "ondragstart");
+  SET_JSVAL_TO_STRING(sOndrop_id,          cx, "ondrop");
   SET_JSVAL_TO_STRING(sScrollIntoView_id,  cx, "scrollIntoView");
   SET_JSVAL_TO_STRING(sScrollX_id,         cx, "scrollX");
   SET_JSVAL_TO_STRING(sScrollY_id,         cx, "scrollY");
   SET_JSVAL_TO_STRING(sScrollMaxX_id,      cx, "scrollMaxX");
   SET_JSVAL_TO_STRING(sScrollMaxY_id,      cx, "scrollMaxY");
   SET_JSVAL_TO_STRING(sOpen_id,            cx, "open");
   SET_JSVAL_TO_STRING(sItem_id,            cx, "item");
   SET_JSVAL_TO_STRING(sNamedItem_id,       cx, "namedItem");
@@ -4263,16 +4277,23 @@ nsDOMClassInfo::ShutDown()
   sOnunload_id        = JSVAL_VOID;
   sOnpageshow_id      = JSVAL_VOID;
   sOnpagehide_id      = JSVAL_VOID;
   sOnabort_id         = JSVAL_VOID;
   sOnerror_id         = JSVAL_VOID;
   sOnpaint_id         = JSVAL_VOID;
   sOnresize_id        = JSVAL_VOID;
   sOnscroll_id        = JSVAL_VOID;
+  sOndrag_id          = JSVAL_VOID;
+  sOndragend_id       = JSVAL_VOID;
+  sOndragenter_id     = JSVAL_VOID;
+  sOndragleave_id     = JSVAL_VOID;
+  sOndragover_id      = JSVAL_VOID;
+  sOndragstart_id     = JSVAL_VOID;
+  sOndrop_id          = JSVAL_VOID;
   sScrollIntoView_id  = JSVAL_VOID;
   sScrollX_id         = JSVAL_VOID;
   sScrollY_id         = JSVAL_VOID;
   sScrollMaxX_id      = JSVAL_VOID;
   sScrollMaxY_id      = JSVAL_VOID;
   sOpen_id            = JSVAL_VOID;
   sItem_id            = JSVAL_VOID;
   sEnumerate_id       = JSVAL_VOID;
@@ -7052,17 +7073,24 @@ nsEventReceiverSH::ReallyIsEventName(jsv
     return id == sOnfocus_id;
   case 'c' :
     return (id == sOnchange_id       ||
             id == sOnclick_id        ||
             id == sOncontextmenu_id  ||
             id == sOncopy_id         ||
             id == sOncut_id);
   case 'd' :
-    return id == sOndblclick_id;
+    return (id == sOndblclick_id     || 
+            id == sOndrag_id         ||
+            id == sOndragend_id      ||
+            id == sOndragenter_id    ||
+            id == sOndragleave_id    ||
+            id == sOndragover_id     ||
+            id == sOndragstart_id    ||
+            id == sOndrop_id);
   case 'l' :
     return id == sOnload_id;
   case 'p' :
     return (id == sOnpaint_id        ||
             id == sOnpageshow_id     ||
             id == sOnpagehide_id     ||
             id == sOnpaste_id);
   case 'k' :
--- a/dom/src/base/nsDOMClassInfo.h
+++ b/dom/src/base/nsDOMClassInfo.h
@@ -297,16 +297,23 @@ protected:
   static jsval sOnunload_id;
   static jsval sOnpageshow_id;
   static jsval sOnpagehide_id;
   static jsval sOnabort_id;
   static jsval sOnerror_id;
   static jsval sOnpaint_id;
   static jsval sOnresize_id;
   static jsval sOnscroll_id;
+  static jsval sOndrag_id;
+  static jsval sOndragend_id;
+  static jsval sOndragenter_id;
+  static jsval sOndragleave_id;
+  static jsval sOndragover_id;
+  static jsval sOndragstart_id;
+  static jsval sOndrop_id;
   static jsval sScrollIntoView_id;
   static jsval sScrollX_id;
   static jsval sScrollY_id;
   static jsval sScrollMaxX_id;
   static jsval sScrollMaxY_id;
   static jsval sOpen_id;
   static jsval sItem_id;
   static jsval sNamedItem_id;
--- a/dom/tests/mochitest/whatwg/Makefile.in
+++ b/dom/tests/mochitest/whatwg/Makefile.in
@@ -71,16 +71,17 @@ include $(topsrcdir)/config/rules.mk
 		postMessage_userpass_helper.html \
 		test_postMessage_origin.xhtml \
 		postMessage_origin_helper.xhtml \
 		test_postMessage_closed.html \
 		postMessage_closed_helper.html \
 		test_postMessage_jar.html \
 		postMessage.jar \
 		postMessage.jar^headers^ \
+		test_bug477323.html \
 		$(NULL)
 
 _CHROME_FILES	= \
 		test_postMessage_chrome.html \
 		$(NULL)		
 
 libs:: 	$(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/whatwg/test_bug477323.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Dynamically assigned drag and drop handlers</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>        
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onload="start()">
+<script class="testbody" type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+function start()
+{
+  var element = document.getElementById("draggable_span");
+  var dataTransfer = null;
+  
+  var gotdragstart = false, gotdrag = false, gotdragenter = false, 
+    gotdragover = false, gotdragleave = false, gotdrop = false, gotdragend = false;
+  
+  element.ondragstart = function(event) 
+  {
+    gotdragstart = true;
+    dataTransfer = event.dataTransfer;
+    event.dataTransfer.setData("Text", "hallo world");
+  }
+  
+  element.ondrag = function(event) {gotdrag = true;}
+  element.ondragenter = function(event) {gotdragenter = true;}
+  element.ondragover = function(event) {gotdragover = true;}
+  element.ondragleave = function(event) {gotdragleave = true;}
+  element.ondrop = function(event) {gotdrop = true;}
+  element.ondragend = function(event) {gotdragend = true;}
+  
+  ok(synthesizeDragStart(element, [["Text: hallo world"]]), "dragstart passed correct data");
+  ok(gotdragstart, "Got ondragstart event");
+  ok(!gotdrag, "Didn't get ondrag event");
+  
+  function dispatch(eventName)
+  {
+    var event = document.createEvent("DragEvents");
+    event.initDragEvent(eventName, true, true, window, 0, 5, 5, 5, 5,
+      false, false, false, false, 0, null, dataTransfer);
+    element.dispatchEvent(event);
+  }
+  
+  dispatch("drag");
+  dispatch("dragenter");
+  dispatch("dragover");
+  dispatch("dragleave");
+  dispatch("drop");
+  dispatch("dragend");
+
+  ok(gotdrag, "Got ondrag event");
+  ok(gotdragenter, "Got ondragenter event");
+  ok(gotdragover, "Got ondragover event");
+  ok(gotdragleave, "Got ondragleave event");
+  ok(gotdrop, "Got ondrop event");
+  ok(gotdragend, "Got ondragend event");
+  
+  SimpleTest.finish();
+}
+
+</script>
+
+<img src="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%02%03%00%00%00%9D%19%D5k%00%00%00%04gAMA%00%00%B1%8F%0B%FCa%05%00%00%00%0CPLTE%FF%FF%FF%FF%FF%FF%F7%DC%13%00%00%00%03%80%01X%00%00%00%01tRNS%08N%3DPT%00%00%00%01bKGD%00%88%05%1DH%00%00%00%09pHYs%00%00%0B%11%00%00%0B%11%01%7Fd_%91%00%00%00%07tIME%07%D2%05%0C%14%0C%0D%D8%3F%1FQ%00%00%00%5CIDATx%9C%7D%8E%CB%09%C0%20%10D%07r%B7%20%2F%E9wV0%15h%EA%D9%12D4%BB%C1x%CC%5C%1E%0C%CC%07%C0%9C0%9Dd7()%C0A%D3%8D%E0%B8%10%1DiCHM%D0%AC%D2d%C3M%F1%B4%E7%FF%10%0BY%AC%25%93%CD%CBF%B5%B2%C0%3Alh%CD%AE%13%DF%A5%F7%E0%03byW%09A%B4%F3%E2%00%00%00%00IEND%AEB%60%82" draggable="true" id="draggable_span"/>
+
+</body>
+</html>