-
Notifications
You must be signed in to change notification settings - Fork 123
/
GrabScroll_Fx29.uc.xul
1133 lines (1049 loc) · 43.5 KB
/
GrabScroll_Fx29.uc.xul
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0"?>
<?xml-stylesheet href="data:text/css,@namespace%20url('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul');@namespace%20html%20url('http://www.w3.org/1999/xhtml');
%23GrabScroll-status {
padding-left:0px !important;
padding-right:0px !important;
}
%23GrabScroll-image {
list-style-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAlklEQVQ4jaWTuw0EIQxEd8UFBFeEczoYCYkm6IeiSU+zySIZjs9+JrKQ52GDvW1jGQA84905953k/gsASVJBlvoAKAajAeq8yu/eqE0l1uciYqcl6+QeYNpSm9wCvPe/nDNDCKxMABhjNG0VI1VVFFNKia8Ad/QK0HvE/Q5k+AuP+n8CWY72DHJpL0aAy0slIlYv0Gp8D2h34zRWWYjjAAAAAElFTkSuQmCC');
}
%23GrabScroll-image[status='true']{
opacity:1.0;
}
%23GrabScroll-image[status='false'] {
opacity:0.3;
}
" type="text/css"?>
<overlay id="GrabScroll"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!--
// ==UserScript==
// @name GrabScroll_Fx29.uc.xul
// @namespace http://pc11.2ch.net/test/read.cgi/software/1168635399/
// @description This script allow scroll with drag screen. If you want to do select text, press alt Key
// @include main
// @compatibility Firefox 29+
// @author Original DragImage.uc.js
// @Modifier Alice0775
// @Note 文字列を選択したいときは,左click後にTIMER以内に選択開始する,またはaltKeyを押しながら選択
// @Note altキーを押しながらドラッグで文字列を選択
// @Note clickとmouseupのタイミングはWInXPの時 -mouseup-clickの順, 他のOSは知らん
// @Note shiftキーを押しながらドラッグでスクロール
// @version 2017/11/18 nsIPrefBranch2 to nsIPrefBranch
// @version 2016/07/19 0800 zoom
// @version 2016/04/19 0800 judge >fx46
// @version 2016/04/19 0700 fix regression of 2016/03/27 0100 prevent Bug 1209100
// @version 2016/03/27 0100 prevent Bug 1209100
// @version 2014/10/27 17:30 adhoc adhoc adhoc fix for Bug 962249 RTL
// @version 2014/05/13 10:30 fix second window
// @version 2014/05/12 08:30 Working on Firefox29+
// ==/UserScript==
// @version 2013/09/13 00:00 Bug 856437 Remove Components.lookupMethod
// @version 2013/04/14 21:00 checking element using Ci.nsIImageLoadingContent instead of HTMLImageElement
// @version 2013/01/08 02:00 Bug 827546
// @version 2012/01/30 01:00 pagehide, this.xxx = null;
// @version 2011/10/30 Bug 684821 - Remove nsIDOMNSHTMLElement
// @version 2011/10/18 22:00 オーバーフロウなしのiframeの場合は親ドキュメント
// @version 2010/10/28 22:00 image documentの時自動リサイズされてしまうのを修正。
// @version 2010/08/14 12:00 クリックしたときの処理を変更
// @version 2010/03/19 23:00 Bug 442228 - Implement CSS property to control element resizability
// @version 2010/02/25 17:00
// @version 2010/01/16 18:00 viewSource
// @version 2009/08/22 18:00 要素のドラッグなど, カーソル形状がresize|move|all-scroll|crosshairの時は何もしないようにした。
// @version 2009/08/19 00:30 背の高いdivの場合, カーソル形状変更しない
// @version 2009/06/14 00:30 xmlに対応させた
// @version 2009/06/03 06:00 videoタグのビデオコントロール付きはドラッグしない
// @version 2009/05/21 12:00 typo
// @version 2009/05/21 00:00 tableのborder-widthを考慮してみた
// @version 2009/05/09 00:00 長いページでは閾値を少し長めにするため 閾値を調整
// @version 2009/05/05 00:00 文字の選択をしやすくするためにmousemove時の判定順番を変更, frame間等のdocumentの相違による制限を取りやめ
// @version 2009/04/30 19:00 2009/03/22 19:00のregressionでエラーが出る場合があった
// @version 2009/04/07 13:00 タイマー解除のタイミングを変更
// @version 2009/04/06 17:00 linuxでも
// @version 2009/03/28 12:00 長尺ページの時, document.body.style.cursorが 異様に遅い(cssのbug?)ので ターゲットがhtml/bodyだった時は cursorはいじらないようにした
// @version 2009/03/22 19:00 ResizeTa等でstyle.cursor = *-resizeの時は何もしない様にした
// @version 2009/02/19 19:00 メニュー修正
// @version 2009/02/18 14:00 "mouse moveがこの値以下の場合スタートしない"閾値を指定するようにした
// @version 2009/02/13 23:00 Flash等があるページで認識が甘かったので, mouseupの処理を修正してみた
// @version 2009/01/19 23:00 動かなくなっていた, 中ボタン,右ボタンを復活してみた。
// @version 2009/01/14 18:00 閾値すぎたらカーソル形状を元に戻すようにした
// @version 2009/01/11 00:00 キャプチャフェーズのフラグが違っていた
// @version 2009/01/10 00:00 getScrollViewのバグ
// @version 2009/01/05 14:00 Fixed bug: Can not scroll at the case that mouse pointer on document root.
// @version 2008/12/31 08:00 エラー出ていたので
// @version 2008/12/26 07:00 Bug 466856 - Crash [@ nsTypedSelection::CopyRangeToAnchorFocus] with triple-clicking changing display style on body 対策// @version 2008/12/26 07:00 開始の判定を改良 慣性スクロールはもひとつなのでデフォoff
// @version 2008/08/21 14:00 コンテンツの外でmouseupしたときstop
// @version 2008/08/14 21:00 zoom
// @version 2008/08/06 01:00 DIV要素等にも対応
// @version 2008/08/21 00:00 ドラッグ中にマウスが画面外になった場合, なんかリンク上の処理が変になっていた
// @version 2008/08/19 18:00 適当にブレーキががかるように
// @version 2008/07/26 17:00 マウス慣性を使うかどうか
// @version 2008/03/26 16:00
-->
<script type="application/x-javascript" xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
var GrabScroll = {
MOUSEBUTTON :0, //0 LeftButton, 1 MiddleButton, 2 RightButton
MOVERATE :-1, // [+-]rate, マイナスの時ドラッグに画面が追従する方向,プラスはその逆
TIMER :500, //この値以上マウス長押した場合はGrabScrollを開始しない,
//連続ドラッグの時は, 閾値は自動的にこの値の1/10となる
INERTIA :false,//慣性を有効とするかどうか
INERTIATHRESHOLD :80, //自動スクロールの閾値
INERTIARATE :50, //自動スクロールの速度
NOTCLICABLELINK :true, //クリックできるリンク上はGrabScrollを開始しない
NOTIMAGE :false,//イメージはGrabScrollを開始しない
TOLERANCE :3, //mouse moveがこの値以下の場合スタートしない
TOLERANCE_WHEN_NO_H_SCROLL : 5, //横スクロールできないときに値以上横に動かした, GrabScrollをキャンセル
CANCEL_WHEN_SELECTION: true, //選択範囲があるときは, GrabScrollをキャンセル
// about:config grabScroll.disable.urlに GrabScrollを無視するURLをスペース区切りで列挙できる。
// 例 http://www.google.com/sky* http://books.google.co.jp/books?id=*
CURSOR: "-moz-grab",// cursor style
mStatus: 0, //0:アイドル, 1:mousedown中, 2:mousemove中, 3:スクロール後mouseup
mLastX: 0,
mLastY: 0,
mCursor: null,
mCursorElement: null,
_target: null, //マウスが指したエレメント
_target2: null, //マウスが指したエレメント
_isImage:false,
_timer:0, //閾値を判断するためのmouseup時の時刻保存
_ctimer:0,
_mtimer: false,
cScroll:false,
cSpeedX:0,
cSpeedY:0,
_doc:null,
_MOVERATEpZoom:1,
IGNOREURL:[],
_window: null,
Bug1209100: 1, //Bug 1209100
initGrabScroll: function() {
var curentBrowserVersion = Services.appinfo.platformVersion; //example: '31.*'
var compareToThisVersion = '46.*';
var compareResult = Services.vc.compare(curentBrowserVersion, compareToThisVersion);
this.Bug1209100 = (compareResult < 0) ? 10 : 1;
Components.utils.import("resource:///modules/CustomizableUI.jsm");
try {
CustomizableUI.createWidget({ //must run createWidget before windowListener.register because the register function needs the button added first
id: 'GrabScroll-image',
type: 'custom',
defaultArea: CustomizableUI.AREA_NAVBAR,
onBuild: function(aDocument) {
var toolbaritem = aDocument.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton');
var props = {
id: 'GrabScroll-image',
align: 'center',
removable: 'true',
overflows: true,
class: "toolbarbutton-1 chromeclass-toolbar-additional",
label: "GrabScroll",
status: "false",
tooltiptext: "GrabScroll",
oncommand: "GrabScroll.toggle();",
};
for (var p in props) {
toolbaritem.setAttribute(p, props[p]);
}
return toolbaritem;
}
});
} catch(ee) {}
if (GrabScroll.activeBrowser().mPanelContainer) {
this._window = GrabScroll.activeBrowser().mPanelContainer;
} else {
this._window = document.getElementById('content');
}
this._window.setCapture();
this._window.addEventListener("mousedown", this, true);
this._window.addEventListener("click", this, true);
this._window.addEventListener("mouseup", this, true);
gBrowser.addEventListener('pagehide', this, false);
GrabScroll.addPrefListener(GrabScroll.buttonPrefListener); // 登録処理
setTimeout(function(){GrabScroll.initPrefs();},0);
},
initPrefs: function() {
this.MOUSEBUTTON = this.getPref("grabScroll.button","int",this.MOUSEBUTTON);
this.MOVERATE = this.getPref("grabScroll.moverate","int",this.MOVERATE);
this.TIMER = this.getPref("grabScroll.timer","int",this.TIMER);
this.INERTIA = this.getPref("grabScroll.enableinertia","bool",this.INERTIA);
this.INERTIATHRESHOLD = this.getPref("grabScroll.inertiathreshold","int",this.INERTIATHRESHOLD);
this.INERTIARATE = this.getPref("grabScroll.inertiarate","int",this.INERTIARATE);
this.NOTCLICABLELINK = this.getPref("grabScroll.clickable","bool",this.NOTCLICABLELINK);
this.IGNOREURL = this.getPref("grabScroll.disable.url", "str", "").split(' ');
this.IGNOREURL.push("http://maps.google.*/*");
this.IGNOREURL.push("http://maps.yahoo.co.jp/pl*");
this.IGNOREURL.push("http://map.yahoo.co.jp/pl*");
this.IGNOREURL.push("http://map.goo.ne.jp/*");
this.IGNOREURL.push("http://www.mapion.co.jp/c/f*");
this.IGNOREURL.push("http://books.google.co.jp/books?id=*");
for(var aURL in this.IGNOREURL) {
if(this.IGNOREURL[aURL]==='')continue;
this.IGNOREURL[aURL] = this.convert2RegExp(this.IGNOREURL[aURL]);
}
var count = 0;
var timer = setInterval(function(self, enable){
if(++count > 100 || self.setIcon(enable))
clearInterval(timer);
},100, this, this.getPref("grabScroll.enable", "bool", true));
},
uninitGrabScroll: function() {
//document.documentElement.removeEventListener('SubBrowserFocusMoved', this.initGrabScroll(), false);
this._window.removeEventListener("mousedown", this, true);
this._window.removeEventListener("click", this, true);
this._window.removeEventListener("mouseup", this, true);
gBrowser.removeEventListener('pagehide', this, false);
GrabScroll.removePrefListener(GrabScroll.buttonPrefListener); // 登録処理
this.mStatus==0;
this._window.removeEventListener("mousemove", this, true);
},
activeBrowser: function() {
return ('SplitBrowser' in window ? SplitBrowser.activeBrowser : null )
|| gBrowser;
},
handleEvent: function(event) {
event = new XPCNativeWrapper(event);
switch(event.type) {
case "mousedown":
if (this.cScroll){
clearTimeout(this.cScroll);
this.cSpeedX = this.cSpeedY = 0;
}
if (this.getPref("grabScroll.enable", "bool", true) &&
!event.shiftKey && !event.ctrlKey && !event.altKey) {
this.grabStart(event);
} else if(!this.getPref("grabScroll.enable", "bool", true) &&
event.shiftKey && !event.ctrlKey && !event.altKey) {
this.grabStart(event);
}
break;
case "mousemove":
this.mousemove(event); break;
case "click":
this.click(event); break;
case "mouseup":
this.mouseup(event); break;
case 'pagehide':
this._doc = null;
this.mCursorElement = null;
this._target = null;
this._target2 = null;
this._isImage = null;
this.NS = this.EW = this.NSEW = null;
break;
}
},
grabStart: function(event) {
if (this.mStatus == 3)
this.mStatus = 0;
// マウスダウンが連続して発火した場合はGrabScrollを開始しない
if (this.MOUSEBUTTON == 0) {
if (Math.abs(this.mLastX - event.screenX) < 5 &&
Math.abs(this.mLastY - event.screenY) < 5 )
return
}
var doc = event.originalTarget.ownerDocument;
if (!doc)
return;
if (doc.contentType == 'application/vnd.mozilla.xul+xml')
return;
this._doc = doc;
if (event.button == this.MOUSEBUTTON && this.mStatus == 0) {
//選択範囲があるときはGrabScrollを開始しない
if (this.CANCEL_WHEN_SELECTION && this.MOUSEBUTTON == 0 && doc.defaultView.getSelection() != "")
return;
//開始ターゲット保存
this._target = event.originalTarget;
//マウスカーソル用のターゲット
if (/^(html|body)$/.test(this._target.localName.toLowerCase()) || this._target.clientHeight > 30000)
this._target2 = null;
else if (/div/.test(this._target.localName.toLowerCase()) && this._target.clientHeight > 1000)
this._target2 = null;
else
this._target2 = this._target;
//無視URLのときはGrabScrollを開始しない
for (aURL in this.IGNOREURL) {
if (this.IGNOREURL[aURL] === '')continue;
try {
if (doc.documentURI.match(this.IGNOREURL[aURL]))
return;
} catch(ex) {
dump(this.IGNOREURL[aURL]+'\n'+ex);
}
}
//エディット可能要素はGrabScrollを開始しない
if (this.isParentEditableNode(this._target))
return;
//ドラッガブル要素はGrabScrollを開始しない
if (this.isParentDraggableNode(this._target))
return;
//無死すべき要素はGrabScrollを開始しない
if (this.isIgnore(this._target))
return;
//ビデオコントロールはGrabScrollを開始しない
if (this.isVideoControl(event.target))
return;
//クリックできるリンク上はGrabScrollを開始しない
if (this.isParentClickableNode(this._target)){
if (this.NOTCLICABLELINK)
return;
//リンクのDragStart阻止
if (!('linkDragSelection' in window))
event.preventDefault();
}
//イメージ
this._isImage = this.isImage(event);
if (this._isImage) {
//イメージはGrabScrollを開始しない
if (this.NOTIMAGE)
return;
//イメージのDragStart阻止
event.preventDefault();
}
//Compativility with ResizeTa
var target = this._target;
while (target){
if ("getAttribute" in target && target.getAttribute("draggable") == "true")
return;
try {
var style = this._doc.defaultView.getComputedStyle(target, null);
//window.userChrome_js.debug(style.getPropertyValue("cursor"));
if (/resize|move|all-scroll|crosshair/.test(style.getPropertyValue("cursor")))
return;
else if (/resize|move|all-scroll|crosshair/.test(style.getPropertyValue("auto")))
break;
} catch(e) {}
target = target.parentNode;
}
//中クリックや右クリックの時, オートスクロールやマウスジェスチャをキャンセル
if (this.MOUSEBUTTON > 0) {
event.preventDefault();
event.stopPropagation();
}
this._timer = new Date().getTime();
this.mLastX = event.screenX;
this.mLastY = event.screenY;
this.mStatus = 1;
//ズームを考慮した移動量
this._MOVERATEpZoom = this.MOVERATE / (ZoomManager.useFullZoom ? ZoomManager.zoom : 1);
[this.NS, this.EW, this.NSEW] = this.getScrollView(event);
this._window.addEventListener("mousemove", this, true);
//マウス グラブ形状
this.setCursor(this._target2, this.CURSOR);
//マウス タイマーで戻す
this.resetCursorWithTimer(this._target2);
}
},
//長いページでは閾値を少し長めにするため 閾値を調整
adjustedTimer: function(){
var magTimer = this.TIMER;
/*
var height = 0;
if (this._doc.contentType != 'application/xml') { //orz
if (this._doc.body)
height = Math.max(this._doc.body.offsetHeight, this._doc.body.scrollHeight);
height = Math.max(height, this._doc.body.clientHeight);
}
magTimer *= Math.min(1, Math.max(Math.sqrt(Math.sqrt(height / 10000)),1));
*/
return magTimer;
},
grabFinish: function() {
//マウス 形状戻す
this.resetCursorTimer();
this.resetCursor();
this._window.removeEventListener("mousemove", this, true);
var selCon = this.getSelconForDoc(this._doc);
if (selCon)
selCon.setDisplaySelection(selCon.SELECTION_ON);
},
mousemove: function(event) {
//window.userChrome_js.debug("mousemove " + this.mStatus);
if (this.mStatus == 2 || this.mStatus == 1 ) {
var x = event.screenX;
var y = event.screenY;
var doc = event.originalTarget.ownerDocument;
//スクロール中にドキュメントが開始時点と異なっている(マウスジェスチャー等によって変わった可能性がある), GrabScrollをキャンセル
/*
if (this._doc != doc) {
this.cSpeedX = this.cSpeedY = 0;
this.grabFinish();
this.mStatus = 0;
return;
}
*/
if (this.mStatus == 1) {
//ドラッグスタートがthis.TIMERより遅いとき, GrabScrollをキャンセル
//長いページでは閾値を少し長めに
if (!this._isImage &&
(new Date().getTime() - this._timer) > this.adjustedTimer()) {
this.grabFinish();
this.mStatus = 0;
return;
}
//横スクロールできないときに横に動かした, GrabScrollをキャンセル
if (Math.abs(x-this.mLastX) < this.TOLERANCE_WHEN_NO_H_SCROLL) {
var movingh = Math.abs(x-this.mLastX) > Math.abs(y-this.mLastY) * 50;
if (!this._isImage && this.MOUSEBUTTON == 0 && this.isText(event) && movingh && !this.EW) {
this.grabFinish();
this.mStatus = 0;
return;
}
}
//マウス移動量が小さいときは何もしない
if(Math.abs(x - this.mLastX) + Math.abs(y - this.mLastY) < this.TOLERANCE / (ZoomManager.useFullZoom ? ZoomManager.zoom : 1))
return;
if (this.MOUSEBUTTON == 0) {
//選択範囲あれば解除 (次のバグ回避のため removeAllRanges の直後に何かの style を変更しないこと)
// Bug 466856 - Crash [@ nsTypedSelection::CopyRangeToAnchorFocus] with
// triple-clicking changing display style on body
var selCon = this.getSelconForDoc(this._doc);
if (selCon) {
var selection = selCon.getSelection(selCon.SELECTION_NORMAL);
selection.removeAllRanges();
selCon.setDisplaySelection(selCon.SELECTION_OFF);
}
} else {
if ("ucjsMouseGestures" in window){
ucjsMouseGestures._isMouseDownR = false;
}
}
// this.mLastX += (x - this.mLastX) ? -this.MOVERATE: this.MOVERATE;
// this.mLastY += (y - this.mLastY) ? -this.MOVERATE: this.MOVERATE;
this.mLastX = x - (x - this.mLastX) / 10;
this.mLastY = y - (y - this.mLastY) / 10;
this.mStatus = 2;
}
//マウス タイマー解除
if (this._ctimer)
this.resetCursorTimer();
if (this._mtimer)
return;
this.cSpeedX = this._MOVERATEpZoom * (x - this.mLastX);
this.cSpeedY = this._MOVERATEpZoom * (y - this.mLastY);
if (this.scroll(event)) {
this.mLastX = x;
this.mLastY = y;
}
}
},
getSelconForDoc: function getSelconForDoc(doc){
if (!doc)
return null;
var aFrame = doc.defaultView;
if (!aFrame)
return null;
var docShell = this.getDocShellForFrame(aFrame);
var selCon = docShell
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsISelectionDisplay)
.QueryInterface(Components.interfaces.nsISelectionController);
return selCon;
},
getDocShellForFrame: function getDocShellForFrame(aFrame){
return aFrame
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
},
click: function(event) {
//window.userChrome_js.debug("click " + this.mStatus);
if (event.button == this.MOUSEBUTTON && this.mStatus == 2) {
event.preventDefault();
event.stopPropagation();
}
if (event.button == 0 && this.mStatus >= 2 && this._doc instanceof Ci.nsIImageDocument) {
event.preventDefault();
event.stopPropagation();
}
this.grabFinish();
this.mStatus = 0;
},
mouseup: function(event) {
//window.userChrome_js.debug("museup " + this.mStatus);
if (event.button == this.MOUSEBUTTON && this.mStatus > 1) {
event.preventDefault();
//event.stopPropagation();
this.grabFinish();
if (this.mStatus == 2)
this.mStatus = 3;
if (this.INERTIA &&
(Math.abs(this.cSpeedX) > this.INERTIATHRESHOLD || Math.abs(this.cSpeedY) > this.INERTIATHRESHOLD )){
if (this.cScroll)
clearTimeout(this.cScroll);
//this.winY = this.NS ? (this.NS.clientHeight) : (this.NSEW ? this.NSEW.clientHeight : 0);
//this.winX = this.EW ? (this.EW.clientWidth) : (this.NSEW ? this.NSEW.clientWidth : 0);
var v = this.INERTIARATE;
if (this.cSpeedX > 0)
this.cSpeedX = Math.min(this.cSpeedX, v);
else
this.cSpeedX = Math.max(this.cSpeedX, -v);
if (this.cSpeedY > 0)
this.cSpeedY = Math.min(this.cSpeedY, v);
else
this.cSpeedY = Math.max(this.cSpeedY, -v);
var Start;
function scrolling(event, self){
Start = new Date().getTime();
self.scroll2(event);
self.cScroll = setTimeout(arguments.callee,
Math.max(25 - ((new Date()).getTime()-Start), 0), event, self);
}
this.scroll2(event);
scrolling(event, this);
/*
this.cScroll = setInterval(function(self){
self.scroll2(event);
}, Math.max(20 - ((new Date()).getTime()-Start), 0), this)
*/
}
} else if (event.button == this.MOUSEBUTTON && this.mStatus == 1){
this.grabFinish();
this.mStatus = 0;
}
},
scroll2: function(event){
var ay = Math.abs(this.cSpeedY);
var ax = Math.abs(this.cSpeedX);
//this.winY -= ay;
//this.winX -= ax;
//if (this.winY < 30)this.cSpeedY = 0;
//if (this.winX < 30)this.cSpeedX = 0;
if (ay < 10 && ax < 10){
clearTimeout(this.cScroll);
return;
}
this.scroll(event);
if (ax >= 100) this.cSpeedX = this.cSpeedX * 0.95;
else if (ax < 100) this.cSpeedX = this.cSpeedX * 0.95;
else if (ax < 20) this.cSpeedX = this.cSpeedX * 0.95;
else if (ax < 10) this.cSpeedX = 0;
if (ay >= 100) this.cSpeedY = this.cSpeedY * 0.95;
else if (ay < 100) this.cSpeedY = this.cSpeedY * 0.95;
else if (ay < 20) this.cSpeedY = this.cSpeedY * 0.95;
else if (ay < 10) this.cSpeedY = 0;
},
scroll: function(event){
var minScroll = this.Bug1209100 / (ZoomManager.useFullZoom ? ZoomManager.zoom : 1); // prevent Bug 1209100, 10px <fx46. 1px >=fx46
this._mtimer = true;
var flg = false;
if (this.NS && this.NS == this.EW &&
(Math.abs(this.cSpeedX) > minScroll || Math.abs(this.cSpeedY) > minScroll)) {
flg = true;
if ("scrollBy" in this.NS) {
this.NS.scrollBy(this.cSpeedX, this.cSpeedY);
} else {
this.NS.scrollLeft += this.cSpeedX;
this.NS.scrollTop += this.cSpeedY;
}
} else {
if (this.NS && Math.abs(this.cSpeedY) > minScroll) {
flg = true;
if ("scrollBy" in this.NS) {
this.NS.scrollBy(0, this.cSpeedY);
} else {
this.NS.scrollTop += this.cSpeedY;
}
}
if (this.EW && Math.abs(this.cSpeedX) > minScroll){
flg = true;
if ("scrollBy" in this.EW) {
this.EW.scrollBy(this.cSpeedX, 0);
} else {
this.EW.scrollLeft += this.cSpeedX;
}
}
}
setTimeout(function(self){
self._mtimer = false;
}, 20, this);
return flg;
},
isText: function(event) {
return event.explicitOriginalTarget.nodeType == document.TEXT_NODE;
},
isImage: function(event) {
if (event.target instanceof Ci.nsIImageLoadingContent)
return event.target;
else
return null;
},
isIgnore: function(aNode){
while (aNode){
var name = aNode.nodeName.toLowerCase();
if (name == "html")
return false;
if (/(scrollbar|select|option|embed|object|tree|applet|statusbar)/.test(name))
return true;
aNode = aNode.parentNode;
}
return false;
},
isParentClickableNode : function(aNode) {
if (!aNode) return null;
var d = aNode.ownerDocument;
try {
var xpathResult = d.evaluate(
/*'ancestor-or-self::*[((local-name() = "a" or local-name() = "A") and @href) or local-name() = "button" or local-name() = "BUTTON" or ((local-name() = "input" or local-name() = "INPUT") and (@type = "SUBMIT" or @type = "submit" or @type = "BUTTON" or @type = "button" or @type = "IMAGE" or @type = "image"))]',*/
'ancestor-or-self::*[((local-name() = "a" or local-name() = "A")) or local-name() = "button" or local-name() = "BUTTON" or ((local-name() = "input" or local-name() = "INPUT") and (@type = "SUBMIT" or @type = "submit" or @type = "BUTTON" or @type = "button" or @type = "IMAGE" or @type = "image"))]',
aNode,
this.NSResolver,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
);
}
catch(e) {
return null;
}
return xpathResult.singleNodeValue;
},
NSResolver : {
lookupNamespaceURI : function(aPrefix) {
switch (aPrefix) {
case 'xul':
return 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
case 'html':
case 'xhtml':
return 'http://www.w3.org/1999/xhtml';
case 'xlink':
return 'http://www.w3.org/1999/xlink';
default:
return '';
}
}
},
isParentEditableNode : function(node){
try {
if (node.ownerDocument.designMode == 'on')
return node;
} catch(e) {}
while (node && node.parentNode) {
try {
if (!(node instanceof Ci.nsIDOMNSEditableElement))
throw 0;
node.QueryInterface(Ci.nsIDOMNSEditableElement);
return node;
}
catch(e) {
}
node = node.parentNode;
}
return null;
},
isParentDraggableNode : function(node){
while (node && node.parentNode) {
//window.userChrome_js.debug(node.getAttribute('draggable') == 'true');
if (node.getAttribute('draggable') == 'true')
return node;
node = node.parentNode;
}
return null;
},
isVideoControl: function(node) {
if (/^(audio|video)$/i.test(node.localName)) {
return true;
var i = 0;
while (i < node.childNodes.length) {
var child =node.childNodes[i];
if (child.hasAttribute('controls') && child.getAttribute('controls') == 'controls') {
return true;
}
i++;
}
}
return false;
},
setCursor: function(element, cursor) {
if (!!element && element.style) {
try {
this.mCursor = element.style.cursor;
this.mCursorElement = element;
element.style.cursor = cursor;
} catch(e) { }
}
},
resetCursor: function() {
var element = this.mCursorElement;
if (!!element) {
try {
element.style.cursor = this.mCursor;
this.mCursor = null;
this.mCursorElement = null;
} catch(e) { }
}
},
resetCursorWithTimer: function() {
if (this._ctimer)
clearTimeout(this._ctimer);
this._ctimer = setTimeout(function(self){
self.resetCursor();
}, this.adjustedTimer(), this);
},
resetCursorTimer: function() {
if (this._ctimer) {
clearTimeout(this._ctimer);
this._ctimer = null;
}
},
// Converts a pattern in this programs simple notation to a regular expression.
// thanks AdBlock! http://www.mozdev.org/source/browse/adblock/adblock/
convert2RegExp: function( pattern ) {
var s = new String(pattern);
var res = new String("^");
for (var k = 0 ; k < s.length ; k++) {
switch(s[k]) {
case '*' :
res += ".*";
break;
case '.' :
case '?' :
case '^' :
case '$' :
case '+' :
case '{' :
case '[' :
case '|' :
case '(' :
case ')' :
case ']' :
res += "\\" + s[k];
break;
case '\\' :
res += "\\\\";
break;
case ' ' :
// Remove spaces from URLs.
break;
default :
res += s[k];
break;
}
}
// fortunately, we don't need .tld in chrome :)
return new RegExp(res + '$', "i");
},
toggle: function(flag){
if(typeof flag =='undefined')
flag = this.getPref("grabScroll.enable","bool",true);
this.setPref("grabScroll.enable","bool",!flag);
this.setIcon(!flag);
},
button: function(){
this.MOUSEBUTTON = this.getPref("grabScroll.button","int",this.MOUSEBUTTON);
var value = prompt("button(L M R): ","LMR".substr(this.MOUSEBUTTON,1));
if (!value)
return;
switch(value.toUpperCase()){
case "M": value =1; break;
case "R": value =2; break;
default:
case "L": value =0; break;
}
this.MOUSEBUTTON = value;
this.setPref("grabScroll.button","int",value);
},
threshold: function(){
this.TIMER = this.getPref("grabScroll.timer","int",this.TIMER);
var value = prompt("Timer: ",this.TIMER);
if (!value)
return;
this.TIMER = parseInt(value,10);
if( this.TIMER <=0 || !this.TIMER ) this.TIMER = 1000;
this.setPref("grabScroll.timer","int",this.TIMER);
},
moverate: function(){
this.MOVERATE = this.getPref("grabScroll.moverate","int",this.MOVERATE);
var value = prompt("[+-]rate: ",this.MOVERATE);
if (!value)
return;
this.MOVERATE = parseInt(value,10);
if( !this.MOVERATE ) this.MOVERATE = -1;
this.setPref("grabScroll.moverate","int",this.MOVERATE);
},
inertiaToggle: function(){
this.INERTIA = !this.getPref("grabScroll.enableinertia","bool",this.INERTIA);
this.setPref("grabScroll.enableinertia","bool",this.INERTIA);
},
inertiaThreshold: function(){
this.INERTIATHRESHOLD = this.getPref("grabScroll.inertiathreshold","int",this.INERTIATHRESHOLD);
var value = prompt("Kinetic scroll threshold: ",this.INERTIATHRESHOLD);
if (!value)
return;
this.INERTIATHRESHOLD = parseInt(value,10);
if( !this.INERTIATHRESHOLD ) this.INERTIATHRESHOLD = 20;
this.setPref("grabScroll.inertiathreshold","int",this.INERTIATHRESHOLD);
},
inertiarate: function(){
this.INERTIARATE = this.getPref("grabScroll.inertiarate","int",this.INERTIARATE);
var value = prompt("Kinetic scroll speed: ",this.INERTIARATE);
if (!value)
return;
this.INERTIARATE = parseInt(value,10);
if( !this.INERTIARATE ) this.INERTIARATE = 20;
this.setPref("grabScroll.inertiarate","int",this.INERTIARATE);
},
clickable: function(){
this.NOTCLICABLELINK = !this.getPref("grabScroll.clickable","bool",this.NOTCLICABLELINK);
this.setPref("grabScroll.clickable","bool",this.NOTCLICABLELINK);
},
onpopup: function(){
document.getElementById('GrabScroll_enable')
.setAttribute('checked', this.getPref("grabScroll.enable","bool",true));
document.getElementById('GrabScroll_enableInertia')
.setAttribute('checked', this.getPref("grabScroll.enableinertia","bool",this.INERTIA));
document.getElementById('GrabScroll_clickable')
.setAttribute('checked', !this.getPref("grabScroll.clickable","bool",this.NOTCLICABLELINK));
},
setIcon: function(flag){
try{
document.getElementById("GrabScroll-image").setAttribute('status', flag);
return true;
}catch(e){
return false;
}
},
getScrollView: function (event) {
//var Start = new Date().getTime();
var NS,EW,NSEW;
NS = EW = NSEW = null;
var _scrollingView = null;
var overflowx, overflowy, ox, oy;
var scw, sch, horz, vert;
var doc, style;
var borderTop;
var borderBottom;
var borderLeft;
var borderRight;
if (event.originalTarget.ownerDocument.contentType == "application/xml") {
_scrollingView = event.originalTarget.ownerDocument.defaultView;
if (_scrollingView.scrollMaxX != _scrollingView.scrollMinX) {
if (_scrollingView.scrollMaxY != _scrollingView.scrollMinY) {
NSEW = _scrollingView;
NS = _scrollingView;
EW = _scrollingView;
} else {
EW = _scrollingView;
}
} else if (_scrollingView.scrollMaxY != _scrollingView.scrollMinY) {
NS = _scrollingView;
} else if (_scrollingView.frameElement) {
//this.findNearestScrollableElement(_scrollingView.frameElement);
} else {
// abort scrolling
}
if (_scrollingView.scrollMaxX > 0) {
if (_scrollingView.scrollMaxY > 0) {
NSEW = !NSEW ? _scrollingView : NSEW;
NS = !NS ? _scrollingView : NS;
}
EW = !EW ? _scrollingView : EW;
}
else if (_scrollingView.scrollMaxY > 0) {
NS = !NS ? _scrollingView : NS;
}
else {
return [NS, EW, NSEW];
}
} else {
for (_scrollingView = event.originalTarget; _scrollingView; _scrollingView = _scrollingView.parentNode) {
if (_scrollingView instanceof HTMLElement) {
if (_scrollingView.localName.toUpperCase() == "HTML" ||
_scrollingView.localName.toUpperCase() == "BODY") {
_scrollingView = _scrollingView.ownerDocument.defaultView;
if (_scrollingView.scrollMaxX != _scrollingView.scrollMinX) {
if (_scrollingView.scrollMaxY != _scrollingView.scrollMinY) {
NSEW = !NSEW ? _scrollingView : NSEW;
EW = !EW ? _scrollingView : EW;
NS = !NS ? _scrollingView : NS;
} else {
EW = !EW ? _scrollingView : EW;
}
} else if (_scrollingView.scrollMaxY != _scrollingView.scrollMinY) {
NS = !NS ? _scrollingView : NS;
} else if (_scrollingView.frameElement) {
//return this.getScrollView({originalTarget : _scrollingView.frameElement});
} else {
// abort scrolling
}
if (_scrollingView.scrollMaxX > 0 &&
_scrollingView.scrollMaxY > 0) {
NSEW = !NSEW ? _scrollingView : NSEW;
EW = !EW ? _scrollingView : EW;
NS = !NS ? _scrollingView : NS;
}
if (_scrollingView.scrollMaxX > 0) {
EW = !EW ? _scrollingView : EW;
}
if (_scrollingView.scrollMaxY > 0) {
NS = !NS ? _scrollingView : NS;
}
if (_scrollingView.frameElement && !NS && !EW && !NSEW) {
return this.getScrollView({originalTarget : _scrollingView.frameElement});
}
break;
}
if (_scrollingView.localName.toLowerCase() == "select") {
_scrollingView.parentNode.focus();
return [NS, EW, NSEW];
}
overflowx = "";
overflowy = "";
ox = true;
oy = true;
try {
doc = _scrollingView.ownerDocument;
style = doc.defaultView.getComputedStyle(_scrollingView, "");
overflowx = style.getPropertyValue("overflow-x");
ox = overflowx != "hidden" && overflowx != "visible";
overflowy = style.getPropertyValue("overflow-y");
oy = overflowy != "hidden" && overflowy != "visible";
} catch (ex) {
}
borderTop = 0;
borderBottom = 0;
borderLeft = 0;
borderRight = 0;
if (/^(table|td|th)$/i.test(_scrollingView.localName)) {
try {
doc = _scrollingView.ownerDocument;
style = doc.defaultView.getComputedStyle(_scrollingView, "");
borderTop = style.getPropertyValue("border-top-width").replace('px', '');
borderBottom = style.getPropertyValue("border-bottom-width").replace('px', '');
borderLeft = style.getPropertyValue("border-left-width").replace('px', '');
borderRight = style.getPropertyValue("border-right-width").replace('px', '');
} catch (ex) {
}
}
scw = _scrollingView.clientWidth;
horz = ox && scw !== 0 &&
scw + borderLeft + borderRight < _scrollingView.scrollWidth;
sch = _scrollingView.clientHeight;
vert = oy && sch !== 0 &&
sch + borderTop + borderBottom < _scrollingView.scrollHeight;
if (horz && vert) {
NSEW = !NSEW ? _scrollingView : NSEW;