forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatchForBug628086_stopSelection.uc.js
More file actions
257 lines (218 loc) · 7.56 KB
/
patchForBug628086_stopSelection.uc.js
File metadata and controls
257 lines (218 loc) · 7.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// ==UserScript==
// @name patchForBug628086_stopSelection.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description Bug 628086 - Text in the input box would not scroll if drag was starting on border even if mouse pointer is I-beam pointer. And drag selection don't stop till i click elsewhere
// @include *
// @compatibility Firefox 4.0 5.0 6.0
// @author alice0775
// @version 2011/04/28
// ==/UserScript==
var stopSelection = {
get domWindowUtils() {
delete this.domWindowUtils;
return this.domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
},
win: null,
init :function(){
this.win = document.getElementById("appcontent") || window;
window.addEventListener('unload', this, false);
this.win.addEventListener('mousedown', this, false);
},
uninit :function(){
window.removeEventListener('unload', this, false);
this.win.removeEventListener('mousedown', this, false);
},
mousedown :function(event){
if (event.button == 0) {
var node = event.originalTarget;
if (node instanceof HTMLInputElement ||
node instanceof HTMLTextAreaElement ||
node instanceof XULTextBoxElement) {
var boxObject = window['piro.sakura.ne.jp'].boxObject;
var style = boxObject._getComputedStyle(node);
var border_top = boxObject._getPropertyPixelValue(style, 'border-top-width');
var border_left = boxObject._getPropertyPixelValue(style, 'border-left-width');
var border_bottom = boxObject._getPropertyPixelValue(style, 'border-bottom-width');
var border_right = boxObject._getPropertyPixelValue(style, 'border-right-width');
var box = boxObject.getBoxObjectFor(node);
var _top = box.screenY + border_top;
var _left = box.screenX + border_left;
var _bottom = box.screenY + box.height - border_bottom;
var _right = box.screenX + box.width - border_right;
userChrome_js.debug("down input");
if (event.screenX < _left || event.screenY < _top ||
event.screenX > _right || event.screenY > _bottom) {
event.preventDefault();
//event.stopPropagation();
}
}
}
},
handleEvent: function(event){
switch (event.type) {
case "mousedown":
this.mousedown(event);
break;
case "mouseup":
this.mouseup(event);
break;
case "unload":
this.uninit();
break;
}
}
}
stopSelection.init();
/*
"getBoxObjectFor()" compatibility library for Firefox 3.6 or later
Usage:
// use instead of HTMLDocument.getBoxObjectFor(HTMLElement)
var boxObject = window['piro.sakura.ne.jp']
.boxObject
.getBoxObjectFor(HTMLElement);
license: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
http://github.com/piroor/fxaddonlibs/blob/master/license.txt
original:
http://github.com/piroor/fxaddonlibs/blob/master/boxObject.js
http://github.com/piroor/fxaddonlibs/blob/master/boxObject.test.js
http://github.com/piroor/fxaddonlibs/blob/master/fixtures/box.html
*/
/* To work as a JS Code Module */
if (typeof window == 'undefined' ||
(window && typeof window.constructor == 'function')) {
this.EXPORTED_SYMBOLS = ['boxObject'];
// If namespace.jsm is available, export symbols to the shared namespace.
// See: http://github.com/piroor/fxaddonlibs/blob/master/namespace.jsm
try {
let ns = {};
Components.utils.import('resource://my-modules/namespace.jsm', ns);
/* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp');
}
catch(e) {
window = {};
}
}
(function() {
const currentRevision = 6;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
var loadedRevision = 'boxObject' in window['piro.sakura.ne.jp'] ?
window['piro.sakura.ne.jp'].boxObject.revision :
0 ;
if (loadedRevision && loadedRevision > currentRevision) {
return;
}
var Cc = Components.classes;
var Ci = Components.interfaces;
window['piro.sakura.ne.jp'].boxObject = {
revision : currentRevision,
getBoxObjectFor : function(aNode, aUnify)
{
return ('getBoxObjectFor' in aNode.ownerDocument) ?
this.getBoxObjectFromBoxObjectFor(aNode, aUnify) :
this.getBoxObjectFromClientRectFor(aNode, aUnify) ;
},
getBoxObjectFromBoxObjectFor : function(aNode, aUnify)
{
var boxObject = aNode.ownerDocument.getBoxObjectFor(aNode);
var box = {
x : boxObject.x,
y : boxObject.y,
width : boxObject.width,
height : boxObject.height,
screenX : boxObject.screenX,
screenY : boxObject.screenY,
element : aNode
};
if (!aUnify) return box;
var style = this._getComputedStyle(aNode);
box.left = box.x - this._getPropertyPixelValue(style, 'border-left-width');
box.top = box.y - this._getPropertyPixelValue(style, 'border-top-width');
if (style.getPropertyValue('position') == 'fixed') {
box.left -= frame.scrollX;
box.top -= frame.scrollY;
}
box.right = box.left + box.width;
box.bottom = box.top + box.height;
return box;
},
getBoxObjectFromClientRectFor : function(aNode, aUnify)
{
var box = {
x : 0,
y : 0,
width : 0,
height : 0,
screenX : 0,
screenY : 0,
element : aNode
};
try {
var zoom = this.getZoom(aNode.ownerDocument.defaultView);
var rect = aNode.getBoundingClientRect();
if (aUnify) {
box.left = rect.left;
box.top = rect.top;
box.right = rect.right;
box.bottom = rect.bottom;
}
var style = this._getComputedStyle(aNode);
var frame = aNode.ownerDocument.defaultView;
// "x" and "y" are offset positions of the "padding-box" from the document top-left edge.
box.x = rect.left + this._getPropertyPixelValue(style, 'border-left-width');
box.y = rect.top + this._getPropertyPixelValue(style, 'border-top-width');
if (style.getPropertyValue('position') != 'fixed') {
box.x += frame.scrollX;
box.y += frame.scrollY;
}
// "width" and "height" are sizes of the "border-box".
box.width = rect.right - rect.left;
box.height = rect.bottom - rect.top;
box.screenX = rect.left * zoom;
box.screenY = rect.top * zoom;
box.screenX += frame.mozInnerScreenX * zoom;
box.screenY += frame.mozInnerScreenY * zoom;
}
catch(e) {
}
'x,y,screenX,screenY,width,height,left,top,right,bottom'
.split(',')
.forEach(function(aProperty) {
if (aProperty in box)
box[aProperty] = Math.round(box[aProperty]);
});
return box;
},
_getComputedStyle : function(aNode)
{
return aNode.ownerDocument.defaultView.getComputedStyle(aNode, null);
},
_getPropertyPixelValue : function(aStyle, aProperty)
{
return parseInt(aStyle.getPropertyValue(aProperty).replace('px', ''));
},
Prefs : Cc['@mozilla.org/preferences;1']
.getService(Ci.nsIPrefBranch)
.QueryInterface(Ci.nsIPrefBranch2),
getZoom : function(aFrame)
{
try {
if (!this.Prefs.getBoolPref('browser.zoom.full'))
return 1;
}
catch(e) {
return 1;
}
var markupDocumentViewer = aFrame.top
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.contentViewer
.QueryInterface(Ci.nsIMarkupDocumentViewer);
return markupDocumentViewer.fullZoom;
}
};
})();
if (window != this) { // work as a JS Code Module
this.boxObject = window['piro.sakura.ne.jp'].boxObject;
}