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