Bug 894099 - Optimize client hittest and use WindowDraggingUtils.jsm for dragging the window on pre-Vista, r=felipe,jimm
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 22 Jul 2013 23:08:09 -0700
changeset 155585 d6623f06fe55de418f70332f88e79d7ed6923056
parent 155584 d7fd9dcb68a8a404b226cfe7dbbcb05fd5c0d8e0
child 155586 0a565c255a8bc1b5a79561f87a8b304c2034ed16
push id25666
push userjwein@mozilla.com
push dateMon, 18 Nov 2013 15:56:58 +0000
treeherdermozilla-central@f2adb62d07eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, jimm
bugs894099
milestone25.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 894099 - Optimize client hittest and use WindowDraggingUtils.jsm for dragging the window on pre-Vista, r=felipe,jimm
toolkit/modules/WindowDraggingUtils.jsm
widget/windows/nsWindow.cpp
--- a/toolkit/modules/WindowDraggingUtils.jsm
+++ b/toolkit/modules/WindowDraggingUtils.jsm
@@ -1,29 +1,42 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#ifdef MOZ_WIDGET_COCOA
+let useHitTest = true;
+#else
+let useHitTest = false;
+#endif
+
 #ifdef XP_WIN
-#define USE_HITTEST
-#elifdef MOZ_WIDGET_COCOA
-#define USE_HITTEST
+let hitTestUsageUpdated = false;
+function updateHitTestUsage() {
+  if (!hitTestUsageUpdated) {
+    let sysInfo = Components.classes["@mozilla.org/system-info;1"]
+                  .getService(Components.interfaces.nsIPropertyBag2);
+    useHitTest = parseFloat(sysInfo.getProperty("version")) >= 6;
+    hitTestUsageUpdated = true;
+  }
+}
 #endif
 
 this.EXPORTED_SYMBOLS = [ "WindowDraggingElement" ];
 
 this.WindowDraggingElement = function WindowDraggingElement(elem) {
+#ifdef XP_WIN
+  updateHitTestUsage();
+#endif
   this._elem = elem;
   this._window = elem.ownerDocument.defaultView;
-#ifdef USE_HITTEST
-  if (!this.isPanel())
+  if (useHitTest && !this.isPanel())
     this._elem.addEventListener("MozMouseHittest", this, false);
   else
-#endif
-  this._elem.addEventListener("mousedown", this, false);
+    this._elem.addEventListener("mousedown", this, false);
 };
 
 WindowDraggingElement.prototype = {
   mouseDownCheck: function(e) { return true; },
   dragTags: ["box", "hbox", "vbox", "spacer", "label", "statusbarpanel", "stack",
              "toolbaritem", "toolbarseparator", "toolbarspring", "toolbarspacer",
              "radiogroup", "deck", "scrollbox", "arrowscrollbox", "tabs"],
   shouldDrag: function(aEvent) {
@@ -55,23 +68,21 @@ WindowDraggingElement.prototype = {
     return true;
   },
   isPanel : function() {
     return this._elem instanceof Components.interfaces.nsIDOMXULElement &&
            this._elem.localName == "panel";
   },
   handleEvent: function(aEvent) {
     let isPanel = this.isPanel();
-#ifdef USE_HITTEST
-    if (!isPanel) {
+    if (useHitTest && !isPanel) {
       if (this.shouldDrag(aEvent))
         aEvent.preventDefault();
       return;
     }
-#endif
 
     switch (aEvent.type) {
       case "mousedown":
         if (!this.shouldDrag(aEvent))
           return;
 
 #ifdef MOZ_WIDGET_GTK2
         // On GTK, there is a toolkit-level function which handles
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -5490,21 +5490,25 @@ nsWindow::ClientMarginHitTestPoint(int32
                                      kResizableBorderMinSize),
                             std::max(mHorResizeMargin - mNonClientOffset.right,
                                      kResizableBorderMinSize),
                             std::max(mVertResizeMargin - mNonClientOffset.bottom,
                                      kResizableBorderMinSize),
                             std::max(mHorResizeMargin - mNonClientOffset.left,
                                      kResizableBorderMinSize));
 
-  bool allowContentOverride = mSizeMode == nsSizeMode_Maximized ||
-                              (mx >= winRect.left + nonClientSize.left &&
-                               mx <= winRect.right - nonClientSize.right &&
-                               my >= winRect.top + nonClientSize.top &&
-                               my <= winRect.bottom - nonClientSize.bottom);
+  bool allowContentOverride = false;
+  // Only allow content overrides on Windows Vista and later.
+  if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
+    allowContentOverride = mSizeMode == nsSizeMode_Maximized ||
+                           (mx >= winRect.left + nonClientSize.left &&
+                            mx <= winRect.right - nonClientSize.right &&
+                            my >= winRect.top + nonClientSize.top &&
+                            my <= winRect.bottom - nonClientSize.bottom);
+  }
 
   // The border size.  If there is no content under mouse cursor, the border
   // size should be larger than the values in system settings.  Otherwise,
   // contents under the mouse cursor should be able to override the behavior.
   // E.g., user must expect that Firefox button always opens the popup menu
   // even when the user clicks on the above edge of it.
   nsIntMargin borderSize(std::max(nonClientSize.top,    mVertResizeMargin),
                          std::max(nonClientSize.right,  mHorResizeMargin),