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