Bug 619412 - PanFinished is not fired on the same element as PanBegin [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Thu, 16 Dec 2010 07:45:40 +0100
changeset 2516 096d85e9344c3f288b5ad8958f9492ec3039c46e
parent 2515 640448390697a3e44d86f2f9160ab7afd9a68494
child 2517 1c8519353a3cc47fe97ba255f95e71b7c3c070d1
push id2117
push uservnicolas@mozilla.com
push dateThu, 16 Dec 2010 06:46:20 +0000
reviewersmfinkle
bugs619412
Bug 619412 - PanFinished is not fired on the same element as PanBegin [r=mfinkle]
chrome/content/browser-ui.js
chrome/content/browser.js
chrome/content/input.js
--- a/chrome/content/browser-ui.js
+++ b/chrome/content/browser-ui.js
@@ -441,17 +441,18 @@ var BrowserUI = {
 
     window.addEventListener("NavigationPanelShown", this, false);
     window.addEventListener("NavigationPanelHidden", this, false);
 
     let tabs = document.getElementById("tabs");
     tabs.addEventListener("TabSelect", this, true);
     tabs.addEventListener("TabOpen", this, true);
     tabs.addEventListener("TabOpen", NewTabPopup, true);
-    window.addEventListener("PanFinished", this, true);
+
+    Elements.browsers.addEventListener("PanFinished", this, true);
 
     // listen content messages
     messageManager.addMessageListener("DOMLinkAdded", this);
     messageManager.addMessageListener("DOMTitleChanged", this);
     messageManager.addMessageListener("DOMWillOpenModalDialog", this);
     messageManager.addMessageListener("DOMWindowClose", this);
 
     messageManager.addMessageListener("Browser:OpenURI", this);
--- a/chrome/content/browser.js
+++ b/chrome/content/browser.js
@@ -1145,17 +1145,17 @@ var Browser = {
 
 
 Browser.MainDragger = function MainDragger() {
   this._horizontalScrollbar = document.getElementById("horizontal-scroller");
   this._verticalScrollbar = document.getElementById("vertical-scroller");
   this._scrollScales = { x: 0, y: 0 };
 
   Elements.browsers.addEventListener("PanBegin", this, false);
-  window.addEventListener("PanFinished", this, false);
+  Elements.browsers.addEventListener("PanFinished", this, false);
   Elements.contentNavigator.addEventListener("SizeChanged", this, false);
 };
 
 Browser.MainDragger.prototype = {
   isDraggable: function isDraggable(target, scroller) {
     return { x: true, y: true };
   },
 
--- a/chrome/content/input.js
+++ b/chrome/content/input.js
@@ -89,16 +89,17 @@ const kStateActive = 0x00000001;
  */
 function MouseModule() {
   this._dragData = new DragData();
 
   this._dragger = null;
   this._inputField = null;
 
   this._downUpEvents = [];
+  this._targetScrollbox = null;
   this._targetScrollInterface = null;
   this._suppressNextMouseUp = false;
 
   this._kinetic = new KineticController(this._dragBy.bind(this),
                                         this._kineticStop.bind(this));
 
   this._singleClickTimeout = new Util.Timeout(this._doSingleClick.bind(this));
   this._longClickTimeout = new Util.Timeout(this._doLongClick.bind(this));
@@ -164,16 +165,17 @@ MouseModule.prototype = {
    */
   cancelPending: function cancelPending() {
     this._doDragStop();
 
     // Kinetic panning may have already been active or drag stop above may have
     // made kinetic panning active.
     this._kinetic.end();
 
+    this._targetScrollbox = null;
     this._targetScrollInterface = null;
 
     this._cleanClickBuffer();
   },
 
   /** Begin possible pan and send tap down event. */
   _onMouseDown: function _onMouseDown(aEvent) {
     let dragData = this._dragData;
@@ -188,16 +190,17 @@ MouseModule.prototype = {
     // returned if none found.
     let [targetScrollbox, targetScrollInterface, dragger]
       = ScrollUtils.getScrollboxFromElement(aEvent.target);
 
     // stop kinetic panning if targetScrollbox has changed
     if (this._kinetic.isActive() && this._dragger != dragger)
       this._kinetic.end();
 
+    this._targetScrollbox = targetScrollbox;
     this._targetScrollInterface = targetScrollInterface;
 
     // Do tap
     let event = document.createEvent("Events");
     event.initEvent("TapDown", true, true);
     event.clientX = aEvent.clientX;
     event.clientY = aEvent.clientY;
     let success = aEvent.target.dispatchEvent(event);
@@ -299,17 +302,17 @@ MouseModule.prototype = {
         this._doDragMove();
 
         // Let everyone know when mousemove begins a pan
         if (!oldIsPan && dragData.isPan()) {
           this._longClickTimeout.clear();
 
           let event = document.createEvent("Events");
           event.initEvent("PanBegin", true, false);
-          aEvent.target.dispatchEvent(event);
+          this._targetScrollbox.dispatchEvent(event);
         }
       }
     }
     else if (!dragData.dragging && this._downUpEvents.length) {
       let oldEvent = this._downUpEvents[0];
       dragData._isPan = ScrollUtils.isPan(new Point(oldEvent.clientX, oldEvent.clientY),
                                           new Point(aEvent.clientX, aEvent.clientY));
       if (dragData.isPan())
@@ -387,21 +390,19 @@ MouseModule.prototype = {
   _kineticStop: function _kineticStop() {
     // Kinetic panning could finish while user is panning, so don't finish
     // the pan just yet.
     let dragData = this._dragData;
     if (!dragData.dragging) {
       this._dragger.dragStop(0, 0, this._targetScrollInterface);
       this._dragger = null;
 
-      // bug 619412
-      // XXX why is PanFinished not dispatched on the same target as PanBegin
       let event = document.createEvent("Events");
       event.initEvent("PanFinished", true, false);
-      document.dispatchEvent(event);
+      this._targetScrollbox.dispatchEvent(event);
     }
   },
 
   /** Called when tap down times out and becomes a long tap. */
   _doLongClick: function _doLongClick() {
     let ev = this._downUpEvents[0];
     this._suppressNextMouseUp = true;
     this._dispatchTap("TapLong", ev);