gecko/toolkit/modules/WindowDraggingUtils.jsm
Ekanan Ketunuti 620410f94c Bug 828116 - Move modules in toolkit/content and toolkit/mozapps/shared to toolkit/modules. r=Mossop
--HG--
rename : toolkit/mozapps/shared/CertUtils.jsm => toolkit/modules/CertUtils.jsm
rename : toolkit/content/DeferredTask.jsm => toolkit/modules/DeferredTask.jsm
rename : toolkit/content/Deprecated.jsm => toolkit/modules/Deprecated.jsm
rename : toolkit/content/Dict.jsm => toolkit/modules/Dict.jsm
rename : toolkit/mozapps/shared/FileUtils.jsm => toolkit/modules/FileUtils.jsm
rename : toolkit/content/Geometry.jsm => toolkit/modules/Geometry.jsm
rename : toolkit/content/InlineSpellChecker.jsm => toolkit/modules/InlineSpellChecker.jsm
rename : toolkit/content/LightweightThemeConsumer.jsm => toolkit/modules/LightweightThemeConsumer.jsm
rename : toolkit/content/PageMenu.jsm => toolkit/modules/PageMenu.jsm
rename : toolkit/content/PopupNotifications.jsm => toolkit/modules/PopupNotifications.jsm
rename : toolkit/content/PrivateBrowsingUtils.jsm => toolkit/modules/PrivateBrowsingUtils.jsm
rename : toolkit/content/PropertyListUtils.jsm => toolkit/modules/PropertyListUtils.jsm
rename : toolkit/content/Services.jsm => toolkit/modules/Services.jsm
rename : toolkit/content/Task.jsm => toolkit/modules/Task.jsm
rename : toolkit/content/Troubleshoot.jsm => toolkit/modules/Troubleshoot.jsm
rename : toolkit/content/UpdateChannel.jsm => toolkit/modules/UpdateChannel.jsm
rename : toolkit/content/WindowDraggingUtils.jsm => toolkit/modules/WindowDraggingUtils.jsm
rename : toolkit/content/debug.js => toolkit/modules/debug.js
rename : toolkit/content/tests/browser/browser_DeferredTask.js => toolkit/modules/tests/browser/browser_DeferredTask.js
rename : toolkit/content/tests/browser/browser_Deprecated.js => toolkit/modules/tests/browser/browser_Deprecated.js
rename : toolkit/content/tests/browser/browser_Geometry.js => toolkit/modules/tests/browser/browser_Geometry.js
rename : toolkit/content/tests/browser/browser_InlineSpellChecker.js => toolkit/modules/tests/browser/browser_InlineSpellChecker.js
rename : toolkit/content/tests/browser/browser_Services.js => toolkit/modules/tests/browser/browser_Services.js
rename : toolkit/content/tests/browser/browser_Troubleshoot.js => toolkit/modules/tests/browser/browser_Troubleshoot.js
rename : toolkit/mozapps/shared/test/chrome/Makefile.in => toolkit/modules/tests/chrome/Makefile.in
rename : toolkit/mozapps/shared/test/chrome/moz.build => toolkit/modules/tests/chrome/moz.build
rename : toolkit/mozapps/shared/test/chrome/test_bug544442_checkCert.xul => toolkit/modules/tests/chrome/test_bug544442_checkCert.xul
rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListBinary.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListBinary.plist
rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListXML.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListXML.plist
rename : toolkit/mozapps/shared/test/unit/test_FileUtils.js => toolkit/modules/tests/xpcshell/test_FileUtils.js
rename : toolkit/content/tests/unit/test_dict.js => toolkit/modules/tests/xpcshell/test_dict.js
rename : toolkit/content/tests/unit/test_propertyListsUtils.js => toolkit/modules/tests/xpcshell/test_propertyListsUtils.js
rename : toolkit/mozapps/shared/test/unit/test_readCertPrefs.js => toolkit/modules/tests/xpcshell/test_readCertPrefs.js
rename : toolkit/content/tests/unit/test_task.js => toolkit/modules/tests/xpcshell/test_task.js
2013-05-14 14:37:18 -07:00

111 lines
3.5 KiB
JavaScript

/* 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 XP_WIN
#define USE_HITTEST
#elifdef MOZ_WIDGET_COCOA
#define USE_HITTEST
#endif
this.EXPORTED_SYMBOLS = [ "WindowDraggingElement" ];
this.WindowDraggingElement = function WindowDraggingElement(elem) {
this._elem = elem;
this._window = elem.ownerDocument.defaultView;
#ifdef USE_HITTEST
if (!this.isPanel())
this._elem.addEventListener("MozMouseHittest", this, false);
else
#endif
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) {
if (aEvent.button != 0 ||
this._window.fullScreen ||
!this.mouseDownCheck.call(this._elem, aEvent) ||
aEvent.defaultPrevented)
return false;
let target = aEvent.originalTarget, parent = aEvent.originalTarget;
// The target may be inside an embedded iframe or browser. (bug 615152)
if (target.ownerDocument.defaultView != this._window)
return false;
while (parent != this._elem) {
let mousethrough = parent.getAttribute("mousethrough");
if (mousethrough == "always")
target = parent.parentNode;
else if (mousethrough == "never")
break;
parent = parent.parentNode;
}
while (target != this._elem) {
if (this.dragTags.indexOf(target.localName) == -1)
return false;
target = target.parentNode;
}
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 (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
// window dragging, which must be used.
this._window.beginWindowMove(aEvent, isPanel ? this._elem : null);
#else
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;
}
this._draggingWindow = true;
this._window.addEventListener("mousemove", this, false);
this._window.addEventListener("mouseup", this, false);
#endif
break;
case "mousemove":
if (this._draggingWindow) {
let toDrag = this.isPanel() ? this._elem : this._window;
toDrag.moveTo(aEvent.screenX - this._deltaX, aEvent.screenY - this._deltaY);
}
break;
case "mouseup":
if (this._draggingWindow) {
this._draggingWindow = false;
this._window.removeEventListener("mousemove", this, false);
this._window.removeEventListener("mouseup", this, false);
}
break;
}
}
}