Bug 619412 - PanFinished is not fired on the same element as PanBegin [r=mfinkle]
--- 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);