Bug 441584: properly handle mouseup on the toolbar (end the pan), r=mfinkle
authorGavin Sharp <gavin@mozilla.com>
Tue, 24 Jun 2008 21:03:37 -0400
changeset 64727 070ee15767622d8fac25b9a1ff14ac565ab1b5cf
parent 64726 79096ef6862b16fc135a3b49c7adbbb5a55fdb8b
child 64728 21482a4f1183c5575ff0cdaff46b4e187f44817d
push idunknown
push userunknown
push dateunknown
reviewersmfinkle
bugs441584
Bug 441584: properly handle mouseup on the toolbar (end the pan), r=mfinkle
mobile/chrome/content/deckbrowser.xml
--- a/mobile/chrome/content/deckbrowser.xml
+++ b/mobile/chrome/content/deckbrowser.xml
@@ -24,17 +24,18 @@
     </content>
 
     <implementation>
       <constructor>
         this._zoomLevel = 1;
 
         // panning
         this._stack.addEventListener("mousedown", this.stackEventHandler, true);
-        this._stack.addEventListener("mouseup", this.stackEventHandler, true);
+        // need mouseup handled on the window to catch mouseups on e.g. the toolbar
+        window.addEventListener("mouseup", this.stackEventHandler, true);
         this._stack.addEventListener("mousemove", this.stackEventHandler, true);
 
         // zoom
         this._stack.addEventListener("dblclick", this.stackEventHandler, true);
         this._stack.addEventListener("DOMMouseScroll", this.stackEventHandler, true);
       </constructor>
 
       <field name="dragData">
@@ -203,22 +204,39 @@
           //this.dragData.offX = aDx;
 
           this._updateCanvasPosition();
         ]]></body>
       </method>
 
       <method name="_dragStartTimer">
         <body><![CDATA[
-          this._scrollStartTimeout = -1;
           this.dragData.lastMouseEvent = Date.now() - 10;
           this.dragData.dragging = true;
         ]]></body>
       </method>
 
+      <method name="_endPan">
+        <body><![CDATA[
+          // update the pageX/Y coords
+          this.dragData.pageX += this.dragData.offX;
+          this.dragData.pageY += this.dragData.offY;
+
+          // relocate the canvas to 0x0 in the window
+          this.dragData.offX = 0;
+          this.dragData.offY = 0;
+
+          // update canvas position and draw the canvas at the new location
+          this._updateCanvasPosition();
+          this._browserToCanvas();
+
+          this.dragData.dragging = false;
+        ]]></body>
+      </method>
+
       <field name="stackEventHandler">
         <![CDATA[
         ({
           deckbrowser: this,
 
           handleEvent: function seh_handleEvent(aEvent) {
             if (!aEvent.type in this) {
               dump("MouseController called with unknown event type " + aEvent.type + "\n");
@@ -256,50 +274,30 @@
 
             //this.deckbrowser._updateCanvasPosition();
 
             var self = this.deckbrowser;
             this.deckbrowser._scrollStartTimeout = setTimeout(function () {
               self._dragStartTimer();
             }, 200);
             //this.deckbrowser._dragStartTimer();
-
-            // don't send the mousedown here, we'll do it in the mouseup handler if we aren't dragging
-            aEvent.preventDefault();
-            return true;
           },
 
           mouseup: function seh_mouseup(aEvent) {
-            if (aEvent.button == 0 && this.deckbrowser._scrollStartTimeout == -1 && this.deckbrowser.dragData.dragging) {
-              // update the pageX/Y coords
-              this.deckbrowser.dragData.pageX += this.deckbrowser.dragData.offX;
-              this.deckbrowser.dragData.pageY += this.deckbrowser.dragData.offY;
-
-              // relocate the canvas to 0x0 in the window
-              this.deckbrowser.dragData.offX = 0;
-              this.deckbrowser.dragData.offY = 0;
-
-              // update canvas position and draw the canvas at the new location
-              this.deckbrowser._updateCanvasPosition();
-              this.deckbrowser._browserToCanvas();
-
-            } else {
-              //dump("Mouseup that isn't a drag\n");
+            if (aEvent.button == 0 && this.deckbrowser.dragData.dragging) {
+              this.deckbrowser._endPan();
+            } else if (aEvent.originalTarget == this.deckbrowser._canvas) {
+              // Mouseup on canvas that isn't releasing from a drag
+              // cancel scrollStart timer
               clearTimeout(this.deckbrowser._scrollStartTimeout);
 
-              // send a mousedown first
+              // send mousedown & mouseup
               this.deckbrowser._redispatchMouseEvent(aEvent, "mousedown");
-
-              // send the mouseup
               this.deckbrowser._redispatchMouseEvent(aEvent);
             }
-
-            this.deckbrowser.dragData.dragging = false;
-            aEvent.preventDefault();
-            return true;
           },
 
           mousemove: function seh_mousemove(aEvent) {
             if (!this.deckbrowser.dragData.dragging)
               return false;
 
             var dx = aEvent.screenX - this.deckbrowser.dragData.sX;
             var dy = aEvent.screenY - this.deckbrowser.dragData.sY;