2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2008-10-18 02:57:46 -07:00
|
|
|
|
2013-07-25 02:46:25 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#define USE_HITTEST
|
|
|
|
#elifdef MOZ_WIDGET_COCOA
|
|
|
|
#define USE_HITTEST
|
2013-02-05 13:40:34 -08:00
|
|
|
#endif
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = [ "WindowDraggingElement" ];
|
2008-10-18 02:57:46 -07:00
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.WindowDraggingElement = function WindowDraggingElement(elem) {
|
2008-10-18 02:57:46 -07:00
|
|
|
this._elem = elem;
|
2012-02-02 00:28:04 -08:00
|
|
|
this._window = elem.ownerDocument.defaultView;
|
2013-07-25 02:46:25 -07:00
|
|
|
#ifdef USE_HITTEST
|
|
|
|
if (!this.isPanel())
|
2011-06-03 12:38:24 -07:00
|
|
|
this._elem.addEventListener("MozMouseHittest", this, false);
|
|
|
|
else
|
2013-07-25 02:46:25 -07:00
|
|
|
#endif
|
|
|
|
this._elem.addEventListener("mousedown", this, false);
|
2012-10-31 09:13:28 -07:00
|
|
|
};
|
2008-10-18 02:57:46 -07:00
|
|
|
|
|
|
|
WindowDraggingElement.prototype = {
|
|
|
|
mouseDownCheck: function(e) { return true; },
|
|
|
|
dragTags: ["box", "hbox", "vbox", "spacer", "label", "statusbarpanel", "stack",
|
|
|
|
"toolbaritem", "toolbarseparator", "toolbarspring", "toolbarspacer",
|
2010-06-24 10:11:29 -07:00
|
|
|
"radiogroup", "deck", "scrollbox", "arrowscrollbox", "tabs"],
|
2010-06-27 23:04:05 -07:00
|
|
|
shouldDrag: function(aEvent) {
|
|
|
|
if (aEvent.button != 0 ||
|
2010-06-29 08:11:49 -07:00
|
|
|
this._window.fullScreen ||
|
|
|
|
!this.mouseDownCheck.call(this._elem, aEvent) ||
|
2011-12-08 01:21:32 -08:00
|
|
|
aEvent.defaultPrevented)
|
2010-06-29 08:11:49 -07:00
|
|
|
return false;
|
2010-06-27 23:04:05 -07:00
|
|
|
|
|
|
|
let target = aEvent.originalTarget, parent = aEvent.originalTarget;
|
2011-01-11 15:02:55 -08:00
|
|
|
|
|
|
|
// The target may be inside an embedded iframe or browser. (bug 615152)
|
|
|
|
if (target.ownerDocument.defaultView != this._window)
|
|
|
|
return false;
|
|
|
|
|
2010-06-27 23:04:05 -07:00
|
|
|
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;
|
|
|
|
},
|
2011-06-03 12:38:24 -07:00
|
|
|
isPanel : function() {
|
|
|
|
return this._elem instanceof Components.interfaces.nsIDOMXULElement &&
|
|
|
|
this._elem.localName == "panel";
|
|
|
|
},
|
2008-10-18 02:57:46 -07:00
|
|
|
handleEvent: function(aEvent) {
|
2011-06-03 12:38:24 -07:00
|
|
|
let isPanel = this.isPanel();
|
2013-07-25 02:46:25 -07:00
|
|
|
#ifdef USE_HITTEST
|
|
|
|
if (!isPanel) {
|
2011-06-03 12:38:24 -07:00
|
|
|
if (this.shouldDrag(aEvent))
|
|
|
|
aEvent.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
2013-07-25 02:46:25 -07:00
|
|
|
#endif
|
2011-06-03 12:38:24 -07:00
|
|
|
|
2008-10-18 02:57:46 -07:00
|
|
|
switch (aEvent.type) {
|
|
|
|
case "mousedown":
|
2010-06-27 23:04:05 -07:00
|
|
|
if (!this.shouldDrag(aEvent))
|
2008-10-18 02:57:46 -07:00
|
|
|
return;
|
|
|
|
|
2010-07-17 01:11:54 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
|
|
|
// On GTK, there is a toolkit-level function which handles
|
|
|
|
// window dragging, which must be used.
|
2011-06-03 12:38:24 -07:00
|
|
|
this._window.beginWindowMove(aEvent, isPanel ? this._elem : null);
|
2010-07-17 01:11:54 -07:00
|
|
|
#else
|
2011-06-03 12:38:24 -07:00
|
|
|
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;
|
|
|
|
}
|
2008-10-18 02:57:46 -07:00
|
|
|
this._draggingWindow = true;
|
|
|
|
this._window.addEventListener("mousemove", this, false);
|
|
|
|
this._window.addEventListener("mouseup", this, false);
|
2010-07-17 01:11:54 -07:00
|
|
|
#endif
|
2008-10-18 02:57:46 -07:00
|
|
|
break;
|
|
|
|
case "mousemove":
|
2011-06-03 12:38:24 -07:00
|
|
|
if (this._draggingWindow) {
|
|
|
|
let toDrag = this.isPanel() ? this._elem : this._window;
|
|
|
|
toDrag.moveTo(aEvent.screenX - this._deltaX, aEvent.screenY - this._deltaY);
|
|
|
|
}
|
2008-10-18 02:57:46 -07:00
|
|
|
break;
|
|
|
|
case "mouseup":
|
2010-07-17 01:11:54 -07:00
|
|
|
if (this._draggingWindow) {
|
|
|
|
this._draggingWindow = false;
|
|
|
|
this._window.removeEventListener("mousemove", this, false);
|
|
|
|
this._window.removeEventListener("mouseup", this, false);
|
|
|
|
}
|
2008-10-18 02:57:46 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|