toolkit/modules/WindowDraggingUtils.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifdef XP_WIN
michael@0 6 #define USE_HITTEST
michael@0 7 #elifdef MOZ_WIDGET_COCOA
michael@0 8 #define USE_HITTEST
michael@0 9 #endif
michael@0 10
michael@0 11 this.EXPORTED_SYMBOLS = [ "WindowDraggingElement" ];
michael@0 12
michael@0 13 this.WindowDraggingElement = function WindowDraggingElement(elem) {
michael@0 14 this._elem = elem;
michael@0 15 this._window = elem.ownerDocument.defaultView;
michael@0 16 #ifdef USE_HITTEST
michael@0 17 if (!this.isPanel())
michael@0 18 this._elem.addEventListener("MozMouseHittest", this, false);
michael@0 19 else
michael@0 20 #endif
michael@0 21 this._elem.addEventListener("mousedown", this, false);
michael@0 22 };
michael@0 23
michael@0 24 WindowDraggingElement.prototype = {
michael@0 25 mouseDownCheck: function(e) { return true; },
michael@0 26 dragTags: ["box", "hbox", "vbox", "spacer", "label", "statusbarpanel", "stack",
michael@0 27 "toolbaritem", "toolbarseparator", "toolbarspring", "toolbarspacer",
michael@0 28 "radiogroup", "deck", "scrollbox", "arrowscrollbox", "tabs"],
michael@0 29 shouldDrag: function(aEvent) {
michael@0 30 if (aEvent.button != 0 ||
michael@0 31 this._window.fullScreen ||
michael@0 32 !this.mouseDownCheck.call(this._elem, aEvent) ||
michael@0 33 aEvent.defaultPrevented)
michael@0 34 return false;
michael@0 35
michael@0 36 let target = aEvent.originalTarget, parent = aEvent.originalTarget;
michael@0 37
michael@0 38 // The target may be inside an embedded iframe or browser. (bug 615152)
michael@0 39 if (target.ownerDocument.defaultView != this._window)
michael@0 40 return false;
michael@0 41
michael@0 42 while (parent != this._elem) {
michael@0 43 let mousethrough = parent.getAttribute("mousethrough");
michael@0 44 if (mousethrough == "always")
michael@0 45 target = parent.parentNode;
michael@0 46 else if (mousethrough == "never")
michael@0 47 break;
michael@0 48 parent = parent.parentNode;
michael@0 49 }
michael@0 50 while (target != this._elem) {
michael@0 51 if (this.dragTags.indexOf(target.localName) == -1)
michael@0 52 return false;
michael@0 53 target = target.parentNode;
michael@0 54 }
michael@0 55 return true;
michael@0 56 },
michael@0 57 isPanel : function() {
michael@0 58 return this._elem instanceof Components.interfaces.nsIDOMXULElement &&
michael@0 59 this._elem.localName == "panel";
michael@0 60 },
michael@0 61 handleEvent: function(aEvent) {
michael@0 62 let isPanel = this.isPanel();
michael@0 63 #ifdef USE_HITTEST
michael@0 64 if (!isPanel) {
michael@0 65 if (this.shouldDrag(aEvent))
michael@0 66 aEvent.preventDefault();
michael@0 67 return;
michael@0 68 }
michael@0 69 #endif
michael@0 70
michael@0 71 switch (aEvent.type) {
michael@0 72 case "mousedown":
michael@0 73 if (!this.shouldDrag(aEvent))
michael@0 74 return;
michael@0 75
michael@0 76 #ifdef MOZ_WIDGET_GTK
michael@0 77 // On GTK, there is a toolkit-level function which handles
michael@0 78 // window dragging, which must be used.
michael@0 79 this._window.beginWindowMove(aEvent, isPanel ? this._elem : null);
michael@0 80 #else
michael@0 81 if (isPanel) {
michael@0 82 let screenRect = this._elem.getOuterScreenRect();
michael@0 83 this._deltaX = aEvent.screenX - screenRect.left;
michael@0 84 this._deltaY = aEvent.screenY - screenRect.top;
michael@0 85 }
michael@0 86 else {
michael@0 87 this._deltaX = aEvent.screenX - this._window.screenX;
michael@0 88 this._deltaY = aEvent.screenY - this._window.screenY;
michael@0 89 }
michael@0 90 this._draggingWindow = true;
michael@0 91 this._window.addEventListener("mousemove", this, false);
michael@0 92 this._window.addEventListener("mouseup", this, false);
michael@0 93 #endif
michael@0 94 break;
michael@0 95 case "mousemove":
michael@0 96 if (this._draggingWindow) {
michael@0 97 let toDrag = this.isPanel() ? this._elem : this._window;
michael@0 98 toDrag.moveTo(aEvent.screenX - this._deltaX, aEvent.screenY - this._deltaY);
michael@0 99 }
michael@0 100 break;
michael@0 101 case "mouseup":
michael@0 102 if (this._draggingWindow) {
michael@0 103 this._draggingWindow = false;
michael@0 104 this._window.removeEventListener("mousemove", this, false);
michael@0 105 this._window.removeEventListener("mouseup", this, false);
michael@0 106 }
michael@0 107 break;
michael@0 108 }
michael@0 109 }
michael@0 110 }

mercurial