Bug 640613 - Chrome scrollbars stays visible if a context menu show up while panning [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Wed, 30 Mar 2011 20:05:03 +0200
changeset 2953 cf2ab7ef19206809fcf83c79b073a4c0bc1b5a22
parent 2952 173bf6f09ebb731155844de258ba5a5cc92611b7
child 2954 0429ed06c6480bbd2768f6c89c66c64caf826704
push id2490
push uservnicolas@mozilla.com
push dateWed, 30 Mar 2011 18:06:25 +0000
reviewersmfinkle
bugs640613
Bug 640613 - Chrome scrollbars stays visible if a context menu show up while panning [r=mfinkle]
chrome/content/bindings.xml
chrome/content/common-ui.js
chrome/content/input.js
chrome/tests/browser_scrollbar.js
--- a/chrome/content/bindings.xml
+++ b/chrome/content/bindings.xml
@@ -152,16 +152,17 @@
             target: this,
             json: {
               types: types,
               label: value,
               linkTitle: value,
               linkURL: url
             }
           };
+
           ContextHelper.showPopup(data);
         ]]>
       </handler>
     </handlers>
     <content orient="vertical">
       <xul:hbox class="autocomplete-item-container" align="top" xbl:inherits="favorite,remote,search" mousethrough="always">
         <xul:image xbl:inherits="src"/>
         <xul:vbox flex="1">
@@ -617,16 +618,17 @@
           let data = {
             target: this,
             json: {
               types: types,
               label: this.name,
               linkTitle: this.name,
               linkURL: this.spec
            }};
+
            ContextHelper.showPopup(data);
          ]]>
        </handler>
      </handlers>
 
     <implementation>
       <field name="_uri">null</field>
       <field name="_control">null</field>
@@ -1759,18 +1761,14 @@
 
           let clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
           let flavors = ["text/unicode"];
           let hasData = clipboard.hasDataMatchingFlavors(flavors, flavors.length, Ci.nsIClipboard.kGlobalClipboard);
 
           if (hasData && (!aTextbox.readOnly || aIgnoreReadOnly))
             json.types.push("paste");
 
-          if (ContextHelper.showPopup({ target: aTextbox, json: json })) {
-            let event = document.createEvent("Events");
-            event.initEvent("CancelTouchSequence", true, false);
-            document.dispatchEvent(event);
-          }
+          ContextHelper.showPopup({ target: aTextbox, json: json });
         ]]></body>
       </method>
     </implementation>
   </binding>
 </bindings>
--- a/chrome/content/common-ui.js
+++ b/chrome/content/common-ui.js
@@ -1213,16 +1213,21 @@ var ContextHelper = {
     label.value = this.popupState.label || "";
 
     this._panel.hidden = false;
     window.addEventListener("resize", this, true);
     window.addEventListener("keypress", this, true);
 
     this.sizeToContent();
     BrowserUI.pushPopup(this, [this._popup]);
+
+    let event = document.createEvent("Events");
+    event.initEvent("CancelTouchSequence", true, false);
+    this.popupState.target.dispatchEvent(event);
+
     return true;
   },
 
   hide: function ch_hide() {
     if (this._panel.hidden)
       return;
     this.popupState = null;
     this._panel.hidden = true;
--- a/chrome/content/input.js
+++ b/chrome/content/input.js
@@ -629,21 +629,25 @@ var ScrollUtils = {
 
       return false;
     },
 
     _showScrollbars: function _showScrollbars(aEvent) {
       let scrollbox = aEvent.target;
       scrollbox.setAttribute("panning", "true");
 
+      let hideScrollbars = function() {
+        scrollbox.removeEventListener("PanFinished", hideScrollbars, false);
+        scrollbox.removeEventListener("CancelTouchSequence", hideScrollbars, false);
+        scrollbox.removeAttribute("panning");
+      }
+
       // Wait for panning to be completely finished before removing scrollbars
-      scrollbox.addEventListener("PanFinished", function(aEvent) {
-        scrollbox.removeEventListener("PanFinished", arguments.callee, false);
-        scrollbox.removeAttribute("panning");
-      }, false);
+      scrollbox.addEventListener("PanFinished", hideScrollbars, false);
+      scrollbox.addEventListener("CancelTouchSequence", hideScrollbars, false);
     }
   }
 };
 
 /**
  * DragData handles processing drags on the screen, handling both
  * locking of movement on one axis, and click detection.
  */
--- a/chrome/tests/browser_scrollbar.js
+++ b/chrome/tests/browser_scrollbar.js
@@ -88,18 +88,47 @@ gTests.push({
 
     waitForPageShow(testURL_01 + "both", gCurrentTest.checkBothScrollable);
     gOpenedTabs.push(Browser.addTab(testURL_01 + "both", true));
   },
 
   checkBothScrollable: function() {
     checkScrollbars(true, true);
     Elements.browsers.addEventListener("PanFinished", function(aEvent) {
+      Elements.browsers.removeEventListener("PanFinished", arguments.callee, false);
       setTimeout(function() {
-        for (let iTab=0; iTab<gOpenedTabs.length; iTab++)
-          Browser.closeTab(gOpenedTabs[iTab]);
         Browser.hideSidebars();
       }, 0);
+      runNextTest();
     }, false);
+  }
+});
+
+
+gTests.push({
+  desc: "Check scrollbar visibility when the touch sequence is cancelled",
+
+  run: function() {
+    waitForPageShow(testURL_01 + "both", gCurrentTest.checkVisibility);
+    gOpenedTabs.push(Browser.addTab(testURL_01 + "both", true));
+  },
+
+  checkVisibility: function() {
+    let browser = getBrowser();
+    let width = browser.getBoundingClientRect().width;
+    let height = browser.getBoundingClientRect().height;
+    EventUtils.synthesizeMouse(browser, width / 2, height / 4, { type: "mousedown" });
+    EventUtils.synthesizeMouse(browser, width / 2, height * 3 / 4, { type: "mousemove" });
+
+    let event = document.createEvent("Events");
+    event.initEvent("CancelTouchSequence", true, false);
+    document.dispatchEvent(event);
+
+    let horizontalVisible = horizontalScrollbar.hasAttribute("panning"),
+        verticalVisible = verticalScrollbar.hasAttribute("panning");
+    is(horizontalVisible, false, "The horizontal scrollbar should be hidden when a canceltouchsequence is fired");
+    is(verticalVisible, false, "The vertical scrollbar should be hidden should be hidden when a canceltouchsequence is called");
+
+    for (let iTab=0; iTab<gOpenedTabs.length; iTab++)
+      Browser.closeTab(gOpenedTabs[iTab]);
     runNextTest();
   }
 });
-