Bug 1455596 - Remove support for <panel backdrag="true"/>. r=enn,ehsan
authorDão Gottwald <dao@mozilla.com>
Tue, 24 Apr 2018 22:07:20 +0200
changeset 469016 4aeafd05a3b20e23248868beb5e8b950dda50866
parent 469015 a1e3dce97e85597982416ffb9dc8f81ac9c56bc2
child 469017 5b969b333346ad90606f86e34e4fd006fb825f31
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenn, ehsan
bugs1455596
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1455596 - Remove support for <panel backdrag="true"/>. r=enn,ehsan
dom/base/nsGlobalWindowInner.cpp
dom/base/nsGlobalWindowInner.h
dom/webidl/Window.webidl
toolkit/content/tests/chrome/window_panel.xul
toolkit/content/widgets/popup.xml
toolkit/modules/WindowDraggingUtils.jsm
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -7346,37 +7346,20 @@ nsGlobalWindowInner::GetAttentionWithCyc
   nsCOMPtr<nsIWidget> widget = GetMainWidget();
 
   if (widget) {
     aError = widget->GetAttention(aCycleCount);
   }
 }
 
 void
-nsGlobalWindowInner::BeginWindowMove(Event& aMouseDownEvent, Element* aPanel,
+nsGlobalWindowInner::BeginWindowMove(Event& aMouseDownEvent,
                                      ErrorResult& aError)
 {
-  nsCOMPtr<nsIWidget> widget;
-
-  // if a panel was supplied, use its widget instead.
-#ifdef MOZ_XUL
-  if (aPanel) {
-    nsIFrame* frame = aPanel->GetPrimaryFrame();
-    if (!frame || !frame->IsMenuPopupFrame()) {
-      return;
-    }
-
-    widget = (static_cast<nsMenuPopupFrame*>(frame))->GetWidget();
-  }
-  else {
-#endif
-    widget = GetMainWidget();
-#ifdef MOZ_XUL
-  }
-#endif
+  nsCOMPtr<nsIWidget> widget = GetMainWidget();
 
   if (!widget) {
     return;
   }
 
   WidgetMouseEvent* mouseEvent =
     aMouseDownEvent.WidgetEventPtr()->AsMouseEvent();
   if (!mouseEvent || mouseEvent->mClass != eMouseEventClass) {
--- a/dom/base/nsGlobalWindowInner.h
+++ b/dom/base/nsGlobalWindowInner.h
@@ -938,17 +938,16 @@ public:
   void Maximize();
   void Minimize();
   void Restore();
   void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton,
                                  mozilla::ErrorResult& aError);
   mozilla::dom::ChromeMessageBroadcaster* MessageManager();
   mozilla::dom::ChromeMessageBroadcaster* GetGroupMessageManager(const nsAString& aGroup);
   void BeginWindowMove(mozilla::dom::Event& aMouseDownEvent,
-                       mozilla::dom::Element* aPanel,
                        mozilla::ErrorResult& aError);
 
   already_AddRefed<mozilla::dom::Promise>
   PromiseDocumentFlushed(mozilla::dom::PromiseDocumentFlushedCallback& aCallback,
                          mozilla::ErrorResult& aError);
 
   void DidRefresh() override;
 
--- a/dom/webidl/Window.webidl
+++ b/dom/webidl/Window.webidl
@@ -441,22 +441,20 @@ partial interface Window {
   ChromeMessageBroadcaster getGroupMessageManager(DOMString aGroup);
 
   /**
    * On some operating systems, we must allow the window manager to
    * handle window dragging. This function tells the window manager to
    * start dragging the window. This function will fail unless called
    * while the left mouse button is held down, callers must check this.
    *
-   * The optional panel argument should be set when moving a panel.
-   *
    * Throws NS_ERROR_NOT_IMPLEMENTED if the OS doesn't support this.
    */
   [Throws, Func="nsGlobalWindowInner::IsPrivilegedChromeWindow"]
-  void beginWindowMove(Event mouseDownEvent, optional Element? panel = null);
+  void beginWindowMove(Event mouseDownEvent);
 
   /**
    * Calls the given function as soon as a style or layout flush for the
    * top-level document is not necessary, and returns a Promise which
    * resolves to the callback's return value after it executes.
    *
    * In the event that the window goes away before a flush can occur, the
    * callback will still be called and the Promise resolved as the window
--- a/toolkit/content/tests/chrome/window_panel.xul
+++ b/toolkit/content/tests/chrome/window_panel.xul
@@ -226,41 +226,16 @@ var tests = [
 
       var tree = $("tree");
       tree.currentIndex = 0;
       panel.appendChild(tree);
       checkTreeCoords();
     }
   },
   {
-    testname: "noautohide panel with backdrag",
-    attrs: { noautohide: true, backdrag: "true" },
-    test: function(panel) {
-      var label = document.createElement("label");
-      label.id = "backdragspot";
-      label.setAttribute("value", "Hello There");
-      panel.appendChild(label);
-      panel.openPopupAtScreen(200, 230);
-    },
-    result: function(testname, panel) {
-      var oldrect = panel.getOuterScreenRect();
-
-      // Linux uses native window moving
-      if (!navigator.platform.includes("Linux")) {
-        var backdragspot = document.getElementById("backdragspot");
-        synthesizeMouse(backdragspot, 5, 5, { type: "mousedown" });
-        synthesizeMouse(backdragspot, 15, 20, { type: "mousemove" });
-        synthesizeMouse(backdragspot, 15, 20, { type: "mouseup" });
-
-        is(panel.getOuterScreenRect().left, 210, testname + "left");
-        is(panel.getOuterScreenRect().top, 245, testname + "top");
-      }
-    }
-  },
-  {
     // The panel should be allowed to appear and remain offscreen
     testname: "normal panel with flip='none' off-screen",
     attrs: { "flip": "none" },
     test: function(panel) {
       panel.openPopup(document.documentElement, "", -100 - mozInnerScreenX, -100 - mozInnerScreenY, false, false, null);
     },
     result: function(testname, panel) {
       var panelrect = panel.getBoundingClientRect();
--- a/toolkit/content/widgets/popup.xml
+++ b/toolkit/content/widgets/popup.xml
@@ -270,32 +270,16 @@
       </handler>
     </handlers>
   </binding>
 
   <binding id="panel"
            extends="chrome://global/content/bindings/popup.xml#popup-base">
     <implementation>
       <field name="_prevFocus">0</field>
-      <field name="_dragBindingAlive">true</field>
-      <constructor>
-      <![CDATA[
-        if (this.getAttribute("backdrag") == "true" && !this._draggableStarted) {
-          this._draggableStarted = true;
-          try {
-            let tmp = {};
-            ChromeUtils.import("resource://gre/modules/WindowDraggingUtils.jsm", tmp);
-            let draghandle = new tmp.WindowDraggingElement(this);
-            draghandle.mouseDownCheck = function() {
-              return this._dragBindingAlive;
-            };
-          } catch (e) {}
-        }
-      ]]>
-      </constructor>
     </implementation>
 
     <handlers>
       <handler event="popupshowing"><![CDATA[
         // Capture the previous focus before has a chance to get set inside the panel
         try {
           this._prevFocus = Cu
                             .getWeakReference(document.commandDispatcher.focusedElement);
--- a/toolkit/modules/WindowDraggingUtils.jsm
+++ b/toolkit/modules/WindowDraggingUtils.jsm
@@ -4,22 +4,21 @@
 
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 const HAVE_CSS_WINDOW_DRAG_SUPPORT = ["win", "macosx"].includes(AppConstants.platform);
 
 var EXPORTED_SYMBOLS = [ "WindowDraggingElement" ];
 
 function WindowDraggingElement(elem) {
+  if (HAVE_CSS_WINDOW_DRAG_SUPPORT) {
+    return;
+  }
   this._elem = elem;
   this._window = elem.ownerGlobal;
-  if (HAVE_CSS_WINDOW_DRAG_SUPPORT && !this.isPanel()) {
-    return;
-  }
-
   this._elem.addEventListener("mousedown", this);
 }
 
 WindowDraggingElement.prototype = {
   mouseDownCheck(e) { return true; },
   dragTags: ["box", "hbox", "vbox", "spacer", "label", "statusbarpanel", "stack",
              "toolbaritem", "toolbarseparator", "toolbarspring", "toolbarspacer",
              "radiogroup", "deck", "scrollbox", "arrowscrollbox", "tabs"],
@@ -46,56 +45,26 @@ WindowDraggingElement.prototype = {
     }
     while (target != this._elem) {
       if (!this.dragTags.includes(target.localName))
         return false;
       target = target.parentNode;
     }
     return true;
   },
-  isPanel() {
-    return ChromeUtils.getClassName(this._elem) == "XULElement" &&
-           this._elem.localName == "panel";
-  },
   handleEvent(aEvent) {
-    let isPanel = this.isPanel();
     switch (aEvent.type) {
       case "mousedown":
-        if (!this.shouldDrag(aEvent))
-          return;
-        if (!/^gtk/i.test(AppConstants.MOZ_WIDGET_TOOLKIT)) {
-          if (isPanel) {
-            let screenRect = this._elem.getOuterScreenRect();
-            this._deltaX = aEvent.screenX - screenRect.left;
-            this._deltaY = aEvent.screenY - screenRect.top;
-          } else {
-            this._deltaX = aEvent.screenX - this._window.screenX;
-            this._deltaY = aEvent.screenY - this._window.screenY;
-          }
+        if (this.shouldDrag(aEvent)) {
+          this._window.addEventListener("mousemove", this, { once: true });
+          this._window.addEventListener("mouseup", this, { once: true });
         }
-        this._draggingWindow = true;
-        this._window.addEventListener("mousemove", this);
-        this._window.addEventListener("mouseup", this);
         break;
       case "mousemove":
-        if (/^gtk/i.test(AppConstants.MOZ_WIDGET_TOOLKIT)) {
-          // On GTK, there is a toolkit-level function which handles
-          // window dragging. We want to start moving the window
-          // on the first mousemove event after mousedown.
-          this._window.beginWindowMove(aEvent, isPanel ? this._elem : null);
-          this._window.removeEventListener("mousemove", this);
-          break;
-        }
-        if (this._draggingWindow) {
-          let toDrag = this.isPanel() ? this._elem : this._window;
-          toDrag.moveTo(aEvent.screenX - this._deltaX, aEvent.screenY - this._deltaY);
-        }
+        this._window.beginWindowMove(aEvent);
+        this._window.removeEventListener("mouseup", this);
         break;
       case "mouseup":
-        if (this._draggingWindow) {
-          this._draggingWindow = false;
-          this._window.removeEventListener("mousemove", this);
-          this._window.removeEventListener("mouseup", this);
-        }
+        this._window.removeEventListener("mousemove", this);
         break;
     }
   }
 };