Bug 639338 Unable to specify XBL modifiers for all possible mouse events r=smaug
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Mon, 18 Apr 2011 21:57:32 +0100
changeset 68256 c65c39ca8b11e83c459758fc0feb10dad5573817
parent 68255 7a88edaf7c5ca01d5b704fe24407bf6ae6d5a343
child 68257 37ad2e03e38e8c07b10ba51eb88194af5844106c
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs639338
milestone6.0a1
Bug 639338 Unable to specify XBL modifiers for all possible mouse events r=smaug
content/base/public/nsContentUtils.h
content/base/src/nsContentUtils.cpp
content/xbl/src/nsXBLEventHandler.cpp
content/xbl/test/Makefile.in
content/xbl/test/test_bug639338.xhtml
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -986,16 +986,25 @@ public:
    * event name with the 'on' prefix. Returns NS_USER_DEFINED_EVENT if the
    * event doesn't match a known event name.
    *
    * @param aName the event name to look up
    */
   static PRUint32 GetEventId(nsIAtom* aName);
 
   /**
+   * Return the category for the event with the given name. The name is the
+   * event name *without* the 'on' prefix. Returns NS_EVENT if the event
+   * is not known to be in any particular category.
+   *
+   * @param aName the event name to look up
+   */
+  static PRUint32 GetEventCategory(const nsAString& aName);
+
+  /**
    * Return the event id and atom for the event with the given name.
    * The name is the event name *without* the 'on' prefix.
    * Returns NS_USER_DEFINED_EVENT on the aEventID if the
    * event doesn't match a known event name in the category.
    *
    * @param aName the event name to look up
    * @param aEventStruct only return event id in aEventStruct category
    */
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -3327,16 +3327,27 @@ nsContentUtils::GetEventId(nsIAtom* aNam
 {
   EventNameMapping mapping;
   if (sAtomEventTable->Get(aName, &mapping))
     return mapping.mId;
 
   return NS_USER_DEFINED_EVENT;
 }
 
+// static
+PRUint32
+nsContentUtils::GetEventCategory(const nsAString& aName)
+{
+  EventNameMapping mapping;
+  if (sStringEventTable->Get(aName, &mapping))
+    return mapping.mStructType;
+
+  return NS_EVENT;
+}
+
 nsIAtom*
 nsContentUtils::GetEventIdAndAtom(const nsAString& aName,
                                   PRUint32 aEventStruct,
                                   PRUint32* aEventID)
 {
   EventNameMapping mapping;
   if (sStringEventTable->Get(aName, &mapping)) {
     *aEventID =
--- a/content/xbl/src/nsXBLEventHandler.cpp
+++ b/content/xbl/src/nsXBLEventHandler.cpp
@@ -186,33 +186,26 @@ nsXBLKeyEventHandler::HandleEvent(nsIDOM
 
 ///////////////////////////////////////////////////////////////////////////////////
 
 nsresult
 NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
                       nsIAtom* aEventType,
                       nsXBLEventHandler** aResult)
 {
-  if (aEventType == nsGkAtoms::mousedown ||
-      aEventType == nsGkAtoms::mouseup ||
-      aEventType == nsGkAtoms::click ||
-      aEventType == nsGkAtoms::dblclick ||
-      aEventType == nsGkAtoms::mouseover ||
-      aEventType == nsGkAtoms::mouseout ||
-      aEventType == nsGkAtoms::mousemove ||
-      aEventType == nsGkAtoms::contextmenu ||
-      aEventType == nsGkAtoms::dragenter ||
-      aEventType == nsGkAtoms::dragover ||
-      aEventType == nsGkAtoms::dragdrop ||
-      aEventType == nsGkAtoms::dragexit ||
-      aEventType == nsGkAtoms::draggesture) {
-    *aResult = new nsXBLMouseEventHandler(aHandler);
-  }
-  else {
-    *aResult = new nsXBLEventHandler(aHandler);
+  switch (nsContentUtils::GetEventCategory(nsDependentAtomString(aEventType))) {
+    case NS_DRAG_EVENT:
+    case NS_MOUSE_EVENT:
+    case NS_MOUSE_SCROLL_EVENT:
+    case NS_SIMPLE_GESTURE_EVENT:
+      *aResult = new nsXBLMouseEventHandler(aHandler);
+      break;
+    default:
+      *aResult = new nsXBLEventHandler(aHandler);
+      break;
   }
 
   if (!*aResult)
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*aResult);
 
   return NS_OK;
--- a/content/xbl/test/Makefile.in
+++ b/content/xbl/test/Makefile.in
@@ -70,12 +70,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug481558.html \
 		file_bug481558css.sjs \
 		file_bug481558.xbl \
 		test_bug526178.xhtml \
 		test_bug542406.xhtml \
 		test_bug591198.html \
 		file_bug591198_xbl.xml \
 		file_bug591198_inner.html \
+		test_bug639338.xhtml \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
copy from content/xbl/test/test_bug403162.xhtml
copy to content/xbl/test/test_bug639338.xhtml
--- a/content/xbl/test/test_bug403162.xhtml
+++ b/content/xbl/test/test_bug639338.xhtml
@@ -1,57 +1,66 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=403162
 -->
 <head>
-  <title>Test for Bug 403162</title>
+  <title>Test for Bug 639338</title>
   <script type="text/javascript" src="/MochiKit/packed.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <bindings xmlns="http://www.mozilla.org/xbl">
     <binding id="test">
       <handlers>
-        <handler event="foo" action="window.triggerCount++"/>
+        <handler event="DOMMouseScroll" action="window.triggerCount++"/>
+        <handler event="DOMMouseScroll" modifiers="shift" action="window.shiftCount++"/>
+        <handler event="DOMMouseScroll" modifiers="control" action="window.controlCount++"/>
       </handlers>
     </binding>
   </bindings>
 </head>
 <body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=403162">Mozilla Bug 403162</a>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=639338">Mozilla Bug 639338</a>
 <p id="display" style="-moz-binding: url(#test)"></p>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 <![CDATA[
 var triggerCount = 0;
+var shiftCount = 0;
+var controlCount = 0;
 
-function dispatchEvent(t) {
-  var ev = document.createEvent("Events");
-  ev.initEvent("foo", true, true);
+function dispatchEvent(t, controlKey, shiftKey) {
+  var ev = document.createEvent("MouseScrollEvents");
+  ev.initMouseScrollEvent("DOMMouseScroll", true, true, window, 0, 0, 0, 0, 0, controlKey, false, shiftKey, false, 0, null, 0);
   t.dispatchEvent(ev);  
 }
 
 /** Test for Bug 403162 **/
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(function() {
   var t = $("display");
   is(triggerCount, 0, "Haven't dispatched event");
 
-  dispatchEvent(t);
+  dispatchEvent(t, false, false);
   is(triggerCount, 1, "Dispatched once");
+  is(shiftCount, 0, "Not shift");
+  is(controlCount, 0, "Not control");
 
-  dispatchEvent(t);
+  dispatchEvent(t, false, true);
   is(triggerCount, 2, "Dispatched twice");
+  is(shiftCount, 1, "Shift");
+  is(controlCount, 0, "Not control");
 
-  t.parentNode.removeChild(t);
-  dispatchEvent(t);
-  is(triggerCount, 2, "Listener should be gone now");
+  dispatchEvent(t, true, false);
+  is(triggerCount, 3, "Dispatched thrice");
+  is(shiftCount, 1, "Not shift");
+  is(controlCount, 1, "Control");
 
   SimpleTest.finish();
 });
 ]]>
 </script>
 </pre>
 </body>
 </html>