-
Notifications
You must be signed in to change notification settings - Fork 29
/
bootstrap.js
3537 lines (3294 loc) · 161 KB
/
bootstrap.js
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
/*
* This file is part of Tab Tree,
* Copyright (C) 2015-2016 Sergey Zelentsov <[email protected]>
*/
'use strict';
/* jshint moz:true */
/* global Components, CustomizableUI, Services, SessionStore, APP_SHUTDOWN, ShortcutUtils, NavBarHeight, AddonManager */
//const {classes: Cc, interfaces: Ci, utils: Cu} = Components; // WebStorm inspector doesn't understand destructuring assignment
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/ShortcutUtils.jsm");
Cu.import("resource:///modules/CustomizableUI.jsm");
Cu.import("resource://gre/modules/AddonManager.jsm");
var ssHack = Cu.import("resource:///modules/sessionstore/SessionStore.jsm");
var ssOrig;
const ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
var stringBundle = Services.strings.createBundle('chrome://tabtree/locale/global.properties?' + Math.random()); // Randomize URI to work around bug 719376
const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});
var keyboardUtils = null;
try {
keyboardUtils = require("sdk/keyboard/utils");
}catch(e) {
// low level SDK API not available
}
var prefsObserver;
var defaultThemeAddonListener;
var tabHeightGlobal = {value: -1, uri: null};
var tabNumbers = false;
const TT_POS_LEFT = 0;
const TT_POS_RIGHT = 1;
const TT_POS_SB_TOP = 2;
const TT_POS_SB_BOT = 3;
const TT_COL_TITLE = 0;
const TT_COL_OVERLAY = 1;
const TT_COL_CLOSE = 2;
//noinspection JSUnusedLocalSymbols
const TT_COL_SCROLLBAR = 3; // Keep this one at the end, it has CSS to keep other columns from being hidden by the scrollbar
// Test keys either using low level SDK API if available, or without (which does not handle many layouts properly)
function keyboardHelper(keyboardEvent) {
return {
keyboardEvent: keyboardEvent,
translatedKey: keyboardUtils ? keyboardUtils.getKeyForCode(keyboardEvent.keyCode) : null,
testCode: function(code, translation) {
return keyboardUtils ? this.translatedKey === translation : keyboardEvent.code === code;
},
testKey: function(key, translation) {
return keyboardUtils ? this.translatedKey === translation : keyboardEvent.key === key;
}
};
}
//noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
function startup(data, reason)
{
let uri = Services.io.newURI("chrome://tabtree/skin/tt-tree.css", null, null);
sss.loadAndRegisterSheet(uri, sss.AUTHOR_SHEET);
uri = Services.io.newURI("chrome://tabtree/skin/tt-other.css", null, null);
sss.loadAndRegisterSheet(uri, sss.AUTHOR_SHEET);
uri = Services.io.newURI("chrome://tabtree/skin/tt-auto-hide.css", null, null);
sss.loadAndRegisterSheet(uri, sss.AUTHOR_SHEET);
uri = Services.io.newURI("chrome://tabtree/skin/tt-navbar-private.css", null, null);
sss.loadAndRegisterSheet(uri, sss.AUTHOR_SHEET);
uri = Services.io.newURI("chrome://tabtree/skin/tt-options.css", null, null);
sss.loadAndRegisterSheet(uri, sss.AUTHOR_SHEET);
// // Why do we use Proxy here? Let's see the chain how SS works:
// // <window onload="gBrowserInit.onLoad()" /> ->
// // -> Services.obs.notifyObservers(window, "browser-window-before-show", ""); ->
// // -> SessionStore.jsm ->
// // -> OBSERVING.forEach(function(aTopic) { Services.obs.addObserver(this, aTopic, true); }, this); ->
// // -> case "browser-window-before-show": this.onBeforeBrowserWindowShown(aSubject); ->
// // -> SessionStoreInternal.onLoad(aWindow); ->
// // (1) -> Services.obs.notifyObservers(null, NOTIFY_WINDOWS_RESTORED, "");
// // (2) -> or just end
// // UPD: Firefox 41+ splits SessionStoreInternal.onLoad in two - onLoad and initializeWindow
// // Here we dispatch our new event 'tt-TabsLoad'
if (ssHack.SessionStoreInternal.initializeWindow) { // Fix for Firefox 41+
ssOrig = ssHack.SessionStoreInternal.initializeWindow;
ssHack.SessionStoreInternal.initializeWindow = new Proxy(ssHack.SessionStoreInternal.initializeWindow, {
apply: function (target, thisArg, argumentsList) {
target.apply(thisArg, argumentsList); // returns nothing
let aWindow = argumentsList[0];
//noinspection JSClosureCompilerSyntax
let event = new Event('tt-TabsLoad'); // we just added our event after this function is executed
aWindow.dispatchEvent(event);
}
});
} else { // to support Firefox before version 41
ssOrig = ssHack.SessionStoreInternal.onLoad;
ssHack.SessionStoreInternal.onLoad = new Proxy(ssHack.SessionStoreInternal.onLoad, {
apply: function (target, thisArg, argumentsList) {
target.apply(thisArg, argumentsList); // returns nothing
let aWindow = argumentsList[0];
//noinspection JSClosureCompilerSyntax
let event = new Event('tt-TabsLoad'); // we just added our event after this function is executed
aWindow.dispatchEvent(event);
}
});
}
// I leave it here just in case. It also works, but the upper version is better tested.
//ssHack.SessionStoreInternal._setWindowStateBusyValue = new Proxy(ssHack.SessionStoreInternal._setWindowStateBusyValue, {
// apply: function (target, thisArg, argumentsList) {
// target.apply(thisArg, argumentsList); // returns nothing
// let aWindow = argumentsList[0];
// let aValue = argumentsList[1];
// if (!aValue) { //noinspection JSClosureCompilerSyntax
// let event = new Event('tt-TabsLoad'); // we just added our event after this function is executed
// aWindow.dispatchEvent(event);
// }
// }
//});
ssHack.SessionStoreInternal.ttOrigOfUndoCloseTab = ssHack.SessionStoreInternal.undoCloseTab;
ssHack.SessionStoreInternal.undoCloseTab = new Proxy(ssHack.SessionStoreInternal.undoCloseTab, {
apply: function (target, thisArg, argumentsList) {
let aWindow = argumentsList[0];
aWindow.ttIsRestoringTab = true;
return target.apply(thisArg, argumentsList); // returns a tab
}
}); // restored in shutdown()
try { // 1.4.5 -> 1.4.6
if (Services.prefs.getBoolPref("extensions.tabtree.dblclick")) {
Services.prefs.deleteBranch("extensions.tabtree.dblclick");
Services.prefs.setIntPref("extensions.tabtree.dblclick", 1)
} else {
Services.prefs.deleteBranch("extensions.tabtree.dblclick");
Services.prefs.setIntPref("extensions.tabtree.dblclick", 0)
}
} catch (e) {
} // should be deleted when 1.4.5 isn't in use anymore
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.treelines', true); // setting default pref
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.highlight-unloaded-tabs', 0); // setting default pref
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.dblclick', 0); // setting default pref // 0 - No action, 1 - Close tab, 2 - Pin tab, 3 - Reload
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.middle-click-tabbar', false); // #36 (Middle click on empty space to open a new tab)
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.delay', 0); // setting default pref
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.position', 1); // setting default pref // 0 - Left, 1 - Right
// 0 - Top, 1 - Bottom (before "New tab" button), 2 - Bottom (after "New tab" button):
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.search-position', 0);
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.search-autohide', true); // setting default pref
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.show-default-tabs', false); // hidden pref for test purposes
// 0 - default, 1 - flst, 2 - the closest tab in the tree (first child -> sibling below -> sibling above -> parent), 3 - the previous tab
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.after-close', 1); //focus closest tab in tree after closing a current tab
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.highlight-unread-tabs', false);
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.new-tab-button', true);
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.close-tab-buttons', true);
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.max-indent', -1); // -1 means no maximum indent level
// 0 - "without Shift - ordinary scrolling, with Shift - changing selected tab"
// 1 - "without Shift - changing selected tab, with Shift - ordinary scrolling"
// 2 - "always ordinary scrolling" 3 - "always changing selected tab":
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.wheel', 0);
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.search-jump', false); // jump to the first search match
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.search-jump-min-chars', 4); // min chars to jump
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.insertRelatedAfterCurrent', false); // #19 // false - Bottom, true - Top
// 0 - default, 1 - try to mimic Firefox theme, 2 - dark
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.theme', 2); // #35 #50
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.prefix-context-menu-items', false); // #60 (Garbage in menu items)
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.tab-height', -1); // #67 [Feature] Provide a way to change the items height
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.tab-flip', true);
Services.prefs.getDefaultBranch(null).setCharPref('extensions.tabtree.auto-hide-key', 'F8');
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.auto-hide-when-fullscreen', true); // #18 hold the tab tree in full screen mode
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.auto-hide-when-maximized', false); // #40 #80
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.auto-hide-when-normal', false); // #40 #80
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.auto-hide-when-only-one-tab', true); // #31
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.tab-numbers', false); // #90 (Show tab numbers in tab titles)
// 0 - close tab, 1 - do nothing, 2 - close tab and all children, 3 - close all children
Services.prefs.getDefaultBranch(null).setIntPref('extensions.tabtree.middle-click-tab', false); // #217 Close Tree of Tabs on Middle-Click
Services.prefs.getDefaultBranch(null).setBoolPref('extensions.tabtree.scroll-wrap', false); // Scroll wheel wraps tab selection
// migration code :
try {
Services.prefs.setBoolPref("extensions.tabtree.auto-hide-when-fullscreen", !Services.prefs.getBoolPref("extensions.tabtree.fullscreen-show"));
Services.prefs.deleteBranch("extensions.tabtree.fullscreen-show");
Services.prefs.setBoolPref("extensions.tabtree.auto-hide-when-only-one-tab", Services.prefs.getBoolPref("extensions.tabtree.hide-tabtree-with-one-tab"));
Services.prefs.deleteBranch("extensions.tabtree.hide-tabtree-with-one-tab");
} catch (e) {
}
// - end migration code // don't forget to delete when v1.4.4 or older aren't in use anymore
let uriTabsToolbar = Services.io.newURI("chrome://tabtree/skin/tt-TabsToolbar.css", null, null);
if (!Services.prefs.getBoolPref('extensions.tabtree.show-default-tabs')) {
sss.loadAndRegisterSheet(uriTabsToolbar, sss.AUTHOR_SHEET);
}
//noinspection JSUnusedGlobalSymbols
Services.prefs.addObserver('extensions.tabtree.', (prefsObserver = {
observe: function(subject, topic, data) {
if (topic == 'nsPref:changed') {
switch (data) {
case 'extensions.tabtree.show-default-tabs':
if (Services.prefs.getBoolPref('extensions.tabtree.show-default-tabs')) {
sss.unregisterSheet(uriTabsToolbar, sss.AUTHOR_SHEET);
} else {
sss.loadAndRegisterSheet(uriTabsToolbar, sss.AUTHOR_SHEET);
}
break;
case "extensions.tabtree.theme":
// Get default theme:
AddonManager.getAddonByID("{972ce4c6-7e08-4474-a285-3208198ce6fd}", (x) => {
[
"chrome://tabtree/skin/tt-theme-mimic.css",
"chrome://tabtree/skin/tt-theme-dark.css",
"chrome://tabtree/skin/tt-theme-default.css",
"chrome://tabtree/skin/tt-theme-osx.css",
].forEach((x) => {
let uri = Services.io.newURI(x, null, null);
if (sss.sheetRegistered(uri, sss.AUTHOR_SHEET)) {
sss.unregisterSheet(uri, sss.AUTHOR_SHEET);
}
});
switch (Services.prefs.getIntPref("extensions.tabtree.theme")) {
case 1: // try to mimic the current Firefox theme
if (x.userDisabled) { // if the default Firefox theme is disabled then load mimic CSS
sss.loadAndRegisterSheet(Services.io.newURI("chrome://tabtree/skin/tt-theme-mimic.css", null, null), sss.AUTHOR_SHEET);
} else { // if the default Firefox theme is enabled then load default CSS
sss.loadAndRegisterSheet(Services.io.newURI("chrome://tabtree/skin/tt-theme-default.css", null, null), sss.AUTHOR_SHEET);
if (Services.appinfo.OS == "Darwin") {
sss.loadAndRegisterSheet(Services.io.newURI("chrome://tabtree/skin/tt-theme-osx.css", null, null), sss.AUTHOR_SHEET);
}
}
break;
case 2: // force the dark theme
sss.loadAndRegisterSheet(Services.io.newURI("chrome://tabtree/skin/tt-theme-dark.css", null, null), sss.AUTHOR_SHEET);
break;
default:
sss.loadAndRegisterSheet(Services.io.newURI("chrome://tabtree/skin/tt-theme-default.css", null, null), sss.AUTHOR_SHEET);
if (Services.appinfo.OS == "Darwin") {
sss.loadAndRegisterSheet(Services.io.newURI("chrome://tabtree/skin/tt-theme-osx.css", null, null), sss.AUTHOR_SHEET);
}
}
// Determine ID of the current theme:
AddonManager.getAddonsByTypes(["theme"], (themes) => {
for (let theme of themes) {
if (!theme.userDisabled) {
Services.obs.notifyObservers(null, "tt-theme-changed", theme.id);
break;
}
}
});
});
}
}
}
}), false); // don't forget to remove // there must be only one pref observer for all Firefox windows for sss prefs
prefsObserver.observe(null, 'nsPref:changed', 'extensions.tabtree.theme');
// Refresh the Tab Tree theme when the Firefox theme is changed from/to the default theme:
AddonManager.addAddonListener((defaultThemeAddonListener = {
onEnabled(a) {
if (a.id === "{972ce4c6-7e08-4474-a285-3208198ce6fd}") {
prefsObserver.observe(null, 'nsPref:changed', 'extensions.tabtree.theme');
}
if (a.type === "theme") {
Services.obs.notifyObservers(null, "tt-theme-changed", a.id);
}
},
onDisabled(a) {
if (a.id === "{972ce4c6-7e08-4474-a285-3208198ce6fd}") {
prefsObserver.observe(null, 'nsPref:changed', 'extensions.tabtree.theme');
}
},
}));
Cu.import(data.resourceURI.spec + "modules/NavBarHeight/NavBarHeight.jsm");
NavBarHeight.data = data;
NavBarHeight.packageName = "tabtree";
NavBarHeight.init();
windowListener.register();
}
//noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
function shutdown(data, reason)
{
if (reason == APP_SHUTDOWN) return;
[
"chrome://tabtree/skin/tt-tree.css",
"chrome://tabtree/skin/tt-theme-mimic.css",
"chrome://tabtree/skin/tt-theme-dark.css",
"chrome://tabtree/skin/tt-theme-default.css",
"chrome://tabtree/skin/tt-theme-osx.css",
"chrome://tabtree/skin/tt-other.css",
"chrome://tabtree/skin/tt-auto-hide.css",
"chrome://tabtree/skin/tt-navbar-private.css",
"chrome://tabtree/skin/tt-options.css",
"chrome://tabtree/skin/tt-TabsToolbar.css",
].forEach(function(x) {
let uri = Services.io.newURI(x, null, null);
if (sss.sheetRegistered(uri, sss.AUTHOR_SHEET)) {
sss.unregisterSheet(uri, sss.AUTHOR_SHEET);
}
});
if (tabHeightGlobal.uri && sss.sheetRegistered(tabHeightGlobal.uri, sss.AUTHOR_SHEET)) {
sss.unregisterSheet(tabHeightGlobal.uri, sss.AUTHOR_SHEET);
}
if (ssHack.SessionStoreInternal.initializeWindow) { // Fix for Firefox 41+
ssHack.SessionStoreInternal.initializeWindow = ssOrig;
} else { // to support Firefox before version 41
ssHack.SessionStoreInternal.onLoad = ssOrig;
}
ssHack.SessionStoreInternal.undoCloseTab = ssHack.SessionStoreInternal.ttOrigOfUndoCloseTab;
Services.prefs.removeObserver('extensions.tabtree.', prefsObserver); // sss related prefs
AddonManager.removeAddonListener(defaultThemeAddonListener);
if (ss.getGlobalValue('tt-saved-widgets')) {
let save = JSON.parse(ss.getGlobalValue('tt-saved-widgets'));
save.forEach(function (x) {
try {
CustomizableUI.addWidgetToArea(x, 'TabsToolbar');
} catch (e) {
}
});
ss.deleteGlobalValue('tt-saved-widgets');
}
NavBarHeight.uninit();
Cu.unload(data.resourceURI.spec + "modules/NavBarHeight/NavBarHeight.jsm");
windowListener.unregister();
}
//noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
function install(aData, aReason) { }
//noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
function uninstall(aData, aReason) { }
//noinspection JSUnusedGlobalSymbols
var windowListener = {
onOpenWindow: function (aXULWindow) {
// In Gecko 7.0 nsIDOMWindow2 has been merged into nsIDOMWindow interface.
// In Gecko 8.0 nsIDOMStorageWindow and nsIDOMWindowInternal have been merged into nsIDOMWindow interface.
// Since ≈FF50 "Use of nsIDOMWindowInternal is deprecated. Use nsIDOMWindow instead."
let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
aDOMWindow.addEventListener('tt-TabsLoad', function onTabsLoad(event) {
aDOMWindow.removeEventListener('tt-TabsLoad', onTabsLoad, false);
windowListener.loadIntoWindow(aDOMWindow);
}, false);
},
onCloseWindow: function (aXULWindow) {
// In Gecko 7.0 nsIDOMWindow2 has been merged into nsIDOMWindow interface.
// In Gecko 8.0 nsIDOMStorageWindow and nsIDOMWindowInternal have been merged into nsIDOMWindow interface.
// Since ≈FF50 "Use of nsIDOMWindowInternal is deprecated. Use nsIDOMWindow instead."
let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
if (!aDOMWindow) {
return;
}
let browser = aDOMWindow.document.querySelector('#browser');
if (!browser) {
return;
}
let sidebar = aDOMWindow.document.querySelector('#tt-sidebar');
ss.setWindowValue(aDOMWindow, 'tt-width', sidebar.width); // Remember the width of 'tt-sidebar'
ss.setWindowValue(aDOMWindow, 'tt-height', sidebar.height); // Remember the height of 'tt-sidebar'
// Remember the first visible row of the <tree id="tt">:
ss.setWindowValue(aDOMWindow, 'tt-first-visible-row', aDOMWindow.document.querySelector('#tt').treeBoxObject.getFirstVisibleRow().toString());
Services.prefs.removeObserver('', aDOMWindow.tt.toRemove.prefsObserver); // it can also be removed in 'unloadFromWindow'
// "themeChangedObserver" must be removed in
// 1) "onCloseWindow" in case Tab Tree is enabled and one Firefox window is being closed
// 2) "unloadFromWindow" in case Tab Tree is being disabled
Services.obs.removeObserver(aDOMWindow.tt.toRemove.themeChangedObserver, "tt-theme-changed");
},
onWindowTitleChange: function (aXULWindow, aNewTitle) {},
register: function () {
// Load into any existing windows
let XULWindows = Services.wm.getXULWindowEnumerator(null);
while (XULWindows.hasMoreElements()) {
let aXULWindow = XULWindows.getNext();
let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
windowListener.loadIntoWindow(aDOMWindow);
}
// Listen to new windows
Services.wm.addListener(windowListener);
},
unregister: function () {
// Unload from any existing windows
let XULWindows = Services.wm.getXULWindowEnumerator(null);
while (XULWindows.hasMoreElements()) {
let aXULWindow = XULWindows.getNext();
let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
windowListener.unloadFromWindow(aDOMWindow, aXULWindow);
}
//Stop listening so future added windows don't get this attached
Services.wm.removeListener(windowListener);
},
unloadFromWindow: function (aDOMWindow, aXULWindow) {
if (!aDOMWindow) {
return;
}
let browser = aDOMWindow.document.querySelector('#browser');
if (!browser) {
return;
}
let splitter = aDOMWindow.document.querySelector('#tt-splitter');
if (splitter) {
let sidebar = aDOMWindow.document.querySelector('#tt-sidebar');
ss.deleteWindowValue(aDOMWindow, 'tt-width', sidebar.width); // Restore the width of 'tt-sidebar' to 200px
ss.deleteWindowValue(aDOMWindow, 'tt-height', sidebar.height); // Restore the height of 'tt-sidebar' to 400px
splitter.parentNode.removeChild(splitter);
sidebar.parentNode.removeChild(sidebar);
let toggler = aDOMWindow.document.querySelector("#tt-toggler");
toggler.parentNode.removeChild(toggler);
let hoverArea = aDOMWindow.document.querySelector("#tt-hover-area");
hoverArea.parentNode.removeChild(hoverArea);
let titlebarButtonsClone = aDOMWindow.document.querySelector('#titlebar-buttonbox-container.tt-clone');
if (titlebarButtonsClone && titlebarButtonsClone.parentNode !== null) { // if it exists
titlebarButtonsClone.parentNode.removeChild(titlebarButtonsClone);
}
let slimSpacer = aDOMWindow.document.querySelector('#tt-slimChrome-spacer');
if(slimSpacer && slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
let titlebarButtonboxContainer = aDOMWindow.document.querySelector('#titlebar-buttonbox-container');
if (titlebarButtonboxContainer) {
titlebarButtonboxContainer.style.marginRight = ''; // Beyond Australis compatibility
}
let windowControlsClone = aDOMWindow.document.querySelector('#tt-window-controls-clone');
if (windowControlsClone && windowControlsClone.parentNode !== null) { // if it exists
windowControlsClone.parentNode.removeChild(windowControlsClone);
}
aDOMWindow.tt.toRemove.contextMenuEls.forEach( (el)=>{el.remove();} );
}
Object.keys(aDOMWindow.tt.toRestore.g).forEach( (x)=>{aDOMWindow.gBrowser[x] = aDOMWindow.tt.toRestore.g[x];} );
// only 1 at the moment - 'updateContextMenu':
Object.keys(aDOMWindow.tt.toRestore.TabContextMenu).forEach( (x)=>{aDOMWindow.TabContextMenu[x] = aDOMWindow.tt.toRestore.TabContextMenu[x];} );
if (aDOMWindow.updateTitlebarDisplay) {
aDOMWindow.updateTitlebarDisplay = aDOMWindow.tt.toRestore.updateTitlebarDisplay;
}
aDOMWindow.gBrowser.tabContainer.removeEventListener("TabMove", aDOMWindow.tt.toRemove.eventListeners.onTabMove, false);
aDOMWindow.gBrowser.tabContainer.removeEventListener("TabSelect", aDOMWindow.tt.toRemove.eventListeners.onTabSelect, false);
aDOMWindow.gBrowser.tabContainer.removeEventListener("TabAttrModified", aDOMWindow.tt.toRemove.eventListeners.onTabAttrModified, false);
aDOMWindow.gBrowser.tabContainer.removeEventListener("SSWindowStateReady", aDOMWindow.tt.toRemove.eventListeners.onSSWindowStateReady, false);
aDOMWindow.gBrowser.removeTabsProgressListener(aDOMWindow.tt.toRemove.tabsProgressListener);
aDOMWindow.removeEventListener("sizemodechange", aDOMWindow.tt.toRemove.eventListeners.onSizemodechange, false);
aDOMWindow.removeEventListener("keydown", aDOMWindow.tt.toRemove.eventListeners.onWindowKeyPress, false);
// it's probably already removed but "Calling removeEventListener() with arguments that do not identify any currently registered EventListener ... has no effect.":
aDOMWindow.document.querySelector('#appcontent').removeEventListener('mouseup', aDOMWindow.tt.toRemove.eventListeners.onAppcontentMouseUp, false);
aDOMWindow.document.querySelector('#tabContextMenu').removeEventListener("popupshowing", aDOMWindow.tt.toRemove.eventListeners.onPopupshowing, false);
aDOMWindow.document.querySelector('#tabContextMenu').removeEventListener("popuphidden", aDOMWindow.tt.toRemove.eventListeners.onPopuphidden, false);
if (aDOMWindow.tt.toRestore.tabsintitlebar) { // restoring 'tabsintitlebar' attr
aDOMWindow.document.documentElement.setAttribute("tabsintitlebar", "true"); // hide native titlebar
} else {
aDOMWindow.document.documentElement.removeAttribute("tabsintitlebar"); // show native titlebar
}
aDOMWindow.TabsInTitlebar.updateAppearance(true); // It is needed to recalculate negative 'margin-bottom' for 'titlebar' and 'margin-bottom' for 'titlebarContainer'
Services.prefs.removeObserver('', aDOMWindow.tt.toRemove.prefsObserver); // it could be already removed in 'onCloseWindow'
if (Services.appinfo.OS == 'WINNT') { // all Windows despite name 'WINNT'
aDOMWindow.tt.toRemove._menuObserver.disconnect();
aDOMWindow.tt.toRemove._toolboxObserver.disconnect();
} else if (Services.appinfo.OS == "Darwin") { // disconnect OS X specific MutationObserver
aDOMWindow.tt.toRemove.osxMutationObserver.disconnect();
}
aDOMWindow.tt.toRemove.sidebarWidthObserver.disconnect();
aDOMWindow.tt.toRemove.numberOfTabsObserver.disconnect();
// "themeChangedObserver" must be removed in
// 1) "onCloseWindow" in case Tab Tree is enabled and one Firefox window is being closed
// 2) "unloadFromWindow" in case Tab Tree is being disabled
Services.obs.removeObserver(aDOMWindow.tt.toRemove.themeChangedObserver, "tt-theme-changed");
delete aDOMWindow.tt;
},
loadIntoWindow: function(aDOMWindow) {
if (!aDOMWindow) {
return;
}
let browser = aDOMWindow.document.querySelector('#browser');
if (!browser) {
return;
}
if (aDOMWindow.tt) { // To fix bug #15 (Duplicate tree in private browsing mode)
return;
}
let g = aDOMWindow.gBrowser;
let appcontent = aDOMWindow.document.querySelector('#appcontent');
let sidebar_box = aDOMWindow.document.querySelector('#sidebar-box');
let sidebar_header = aDOMWindow.document.querySelector('#sidebar-header');
aDOMWindow.tt = {
toRemove: {
eventListeners: {},
prefsObserver: null,
tabsProgressListener: null,
_menuObserver: null,
_toolboxObserver: null,
sidebarWidthObserver: null,
themeChangedObserver: null,
osxMutationObserver: null,
},
toRestore: {g: {}, TabContextMenu: {}, tabsintitlebar: true},
dropEvent: {},
};
if (!ss.getGlobalValue('tt-saved-widgets')) {
// "getWidgetIdsInArea" is called here (and not in startup()) because of
// "NB: will throw if called too early (before placements have been fetched) or if the area is not currently known to CustomizableUI."
let save = CustomizableUI.getWidgetIdsInArea('TabsToolbar');
save.forEach(function (x) {
switch (x) {
case 'tabbrowser-tabs':
case 'new-tab-button':
case 'alltabs-button':
// "If the widget cannot be removed from its area, or is not in any area, this will no-op."
CustomizableUI.removeWidgetFromArea(x);
break;
default:
// "If the widget cannot be removed from its original location, this will no-op."
CustomizableUI.addWidgetToArea(x, 'nav-bar');
}
});
ss.setGlobalValue('tt-saved-widgets', JSON.stringify(save));
}
// remember 'tabsintitlebar' attr before beginning to interact with it // default is 'true':
aDOMWindow.tt.toRestore.tabsintitlebar = aDOMWindow.document.documentElement.getAttribute('tabsintitlebar')=='true';
//////////////// Utility Functions (used in multiple areas) ///////////
let openNewSibling = function (sibling) {
let tPos = sibling._tPos;
let lvl = ss.getTabValue(sibling, "ttLevel");
let newTab = g.addTab("about:newtab"); // our new tab will be opened at position g.tabs.length - 1
for (let i = tPos + 1; i < g.tabs.length - 1; ++i) {
if (parseInt(ss.getTabValue(g.tabs[i], "ttLevel")) <= parseInt(lvl)) {
g.moveTabTo(newTab, i);
break;
}
}
ss.setTabValue(newTab, "ttLevel", lvl);
g.selectedTab = newTab;
aDOMWindow.focusAndSelectUrlBar();
};
let openNewChild = function (parent) {
let lvl = ss.getTabValue(parent, "ttLevel");
let newTab = g.addTab("about:newtab"); // our new tab will be opened at position g.tabs.length - 1
if (Services.prefs.getBoolPref("extensions.tabtree.insertRelatedAfterCurrent")) {
g.moveTabTo(newTab, parent._tPos + 1);
} else {
g.moveTabTo(newTab, tt.lastDescendantPos(parent) + 1);
}
ss.setTabValue(newTab, "ttLevel", (parseInt(lvl) + 1).toString());
g.selectedTab = newTab;
aDOMWindow.focusAndSelectUrlBar();
};
const closeTabAndAllChildren = function (tab) {
const tPos = tab._tPos;
const lvl = ss.getTabValue(tab, 'ttLevel');
while (g.tabs[tPos+1] && ss.getTabValue(g.tabs[tPos+1], 'ttLevel') > lvl) {
g.removeTab(g.tabs[tPos+1]);
}
g.removeTab(g.tabs[tPos]);
};
const closeAllChildren = function (tab) {
const tPos = tab._tPos;
const lvl = ss.getTabValue(tab, 'ttLevel');
while (g.tabs[tPos+1] && ss.getTabValue(g.tabs[tPos+1], 'ttLevel') > lvl) {
g.removeTab(g.tabs[tPos+1]);
}
};
//////////////////// TITLE BAR STANDARD BUTTONS (Minimize, Restore/Maximize, Close) ////////////////////////////
// We can't use 'window.load' event here, because it always shows windowState==='STATE_NORMAL' even when the actual state is 'STATE_MAXIMIZED'
// Now we have elements with the same id:
let titlebarButtons = aDOMWindow.document.querySelector('#titlebar-buttonbox-container'); // it's present only on Windows and Mac
let titlebarButtonsClone;
if (titlebarButtons && Services.appinfo.OS == 'WINNT') { // it's present only on Windows and Mac
titlebarButtonsClone = aDOMWindow.document.querySelector('#titlebar-buttonbox-container').cloneNode(true);
titlebarButtonsClone.classList.add('tt-clone'); // add a class to distinguish the elements with the same id
}
let menu = aDOMWindow.document.querySelector('#toolbar-menubar');
let navToolbox = aDOMWindow.document.querySelector('#navigator-toolbox');
let navBar = aDOMWindow.document.querySelector('#nav-bar');
let windowControlsClone = aDOMWindow.document.querySelector('#window-controls').cloneNode(true);
windowControlsClone.id = 'tt-window-controls-clone'; // change id to distinguish the new element
windowControlsClone.hidden = false;
let slimSpacer = aDOMWindow.document.createElement('spacer');
slimSpacer.id = 'tt-slimChrome-spacer';
slimSpacer.setAttribute('flex', '1');
if (aDOMWindow.updateTitlebarDisplay) {
// #136 [Bug] UI breaks with Firefox 47
// More info at https://dxr.mozilla.org/mozilla-central/source/browser/base/content/browser-tabsintitlebar.js
aDOMWindow.tt.toRestore.updateTitlebarDisplay = aDOMWindow.updateTitlebarDisplay;
aDOMWindow.updateTitlebarDisplay = new Proxy(aDOMWindow.updateTitlebarDisplay, {
apply: function(target, thisArg, argumentsList) {
target.apply(thisArg, argumentsList);
if (aDOMWindow.windowState === aDOMWindow.STATE_NORMAL) {
// #154 [Bug] Broken compatibility with Hide Caption Titlebar Plus since version 1.4.7
AddonManager.getAddonByID("[email protected]", function (addon) {
if (addon && addon.isActive) {
// "Hide Caption Titlebar Plus" is installed and enabled
} else {
aDOMWindow.document.documentElement.removeAttribute("chromemargin");
}
});
}
}
});
}
// console.log(`Window: '${aDOMWindow.document.title} (${g.tabs.length})' (windowState=${aDOMWindow.windowState}). Injecting Tab Tree ...`);
if (Services.appinfo.OS == 'WINNT') {
switch (aDOMWindow.windowState) {
case aDOMWindow.STATE_MAXIMIZED:
if (Services.prefs.getBoolPref('browser.tabs.drawInTitlebar')) {
if (menu.getAttribute('autohide') == 'true' && menu.hasAttribute('inactive')) {
// BEGIN Beyond Australis compatibility:
// window controls wouldn't be visible because the buttonbox container wouldn't be in the right place
if(navToolbox.getAttribute('slimChromeNavBar') == 'true') {
let slimmer = aDOMWindow.document.querySelector('#theFoxOnlyBetter-slimChrome-slimmer');
slimmer.appendChild(slimSpacer);
slimmer.appendChild(titlebarButtonsClone);
} else {
navBar.appendChild(titlebarButtonsClone);
if(slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
}
// END Beyond Australis compatibility
// It can't be plain ".collapsed = true" because it would affect ".updateTitlebarDisplay()"
// and consequently "aDOMWindow.TabsInTitlebar.updateAppearance(true);" margin calculations:
titlebarButtons.style.marginRight = '-9999px'; // Beyond Australis compatibility
aDOMWindow.document.documentElement.setAttribute("tabsintitlebar", "true"); // hide native titlebar
aDOMWindow.updateTitlebarDisplay();
}
}
break;
case aDOMWindow.STATE_NORMAL:
aDOMWindow.document.documentElement.removeAttribute("tabsintitlebar"); // show native titlebar
aDOMWindow.updateTitlebarDisplay();
break;
case aDOMWindow.STATE_FULLSCREEN:
navBar.appendChild(windowControlsClone);
break;
}
aDOMWindow.addEventListener('sizemodechange', (aDOMWindow.tt.toRemove.eventListeners.onSizemodechange = function(event) {
// console.log(`Window: '${aDOMWindow.document.title} (${g.tabs.length})' (windowState=${aDOMWindow.windowState}). Event: 'sizemodechange'`);
switch (aDOMWindow.windowState) {
case aDOMWindow.STATE_MAXIMIZED:
if (windowControlsClone.parentNode !== null) { // if windowControlsClone exists
navBar.removeChild(windowControlsClone);
}
if (Services.prefs.getBoolPref('browser.tabs.drawInTitlebar')) {
if (menu.getAttribute('autohide') == 'true' && menu.hasAttribute('inactive')) {
// BEGIN Beyond Australis compatibility:
// window controls wouldn't be visible because the buttonbox container wouldn't be in the right place
if(navToolbox.getAttribute('slimChromeNavBar') == 'true') {
let slimmer = aDOMWindow.document.querySelector('#theFoxOnlyBetter-slimChrome-slimmer');
slimmer.appendChild(slimSpacer);
slimmer.appendChild(titlebarButtonsClone);
} else {
navBar.appendChild(titlebarButtonsClone);
if(slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
}
// END Beyond Australis compatibility
titlebarButtons.style.marginRight = '-9999px'; // Beyond Australis compatibility
aDOMWindow.setTimeout(() => {
aDOMWindow.document.documentElement.setAttribute("tabsintitlebar", "true"); // hide native titlebar
aDOMWindow.updateTitlebarDisplay();
}, 0);
}
}
break;
case aDOMWindow.STATE_NORMAL:
if (windowControlsClone.parentNode !== null) { // if windowControlsClone exists
navBar.removeChild(windowControlsClone);
}
aDOMWindow.document.documentElement.removeAttribute("tabsintitlebar"); // show native toolbar
if (titlebarButtonsClone.parentNode !== null) { // if it exists
titlebarButtonsClone.parentNode.removeChild(titlebarButtonsClone);
titlebarButtons.style.marginRight = ''; // Beyond Australis compatibility
if(slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
}
aDOMWindow.updateTitlebarDisplay();
break;
case aDOMWindow.STATE_FULLSCREEN:
if (titlebarButtonsClone.parentNode !== null) { // if it exists
titlebarButtonsClone.parentNode.removeChild(titlebarButtonsClone);
titlebarButtons.style.marginRight = ''; // Beyond Australis compatibility
if(slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
}
navBar.appendChild(windowControlsClone);
break;
}
}), false); // removed in unloadFromWindow()
(aDOMWindow.tt.toRemove._menuObserver = new aDOMWindow.MutationObserver(function(aMutations) {
for (let mutation of aMutations) {
if (mutation.attributeName == 'inactive' || mutation.attributeName == 'autohide') {
if (
Services.prefs.getBoolPref('browser.tabs.drawInTitlebar') &&
aDOMWindow.windowState==aDOMWindow.STATE_MAXIMIZED &&
mutation.target.getAttribute('autohide')=='true' &&
mutation.target.hasAttribute('inactive')
) {
// BEGIN Beyond Australis compatibility:
// window controls wouldn't be visible because the buttonbox container wouldn't be in the right place
if(navToolbox.getAttribute('slimChromeNavBar') == 'true') {
let slimmer = aDOMWindow.document.querySelector('#theFoxOnlyBetter-slimChrome-slimmer');
slimmer.appendChild(slimSpacer);
slimmer.appendChild(titlebarButtonsClone);
} else {
navBar.appendChild(titlebarButtonsClone);
if(slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
}
// END Beyond Australis compatibility
titlebarButtons.style.marginRight = '-9999px'; // Beyond Australis compatibility
} else {
if (titlebarButtonsClone.parentNode !== null) { // if it exists
titlebarButtonsClone.parentNode.removeChild(titlebarButtonsClone);
if(slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
}
titlebarButtons.style.marginRight = ''; // Beyond Australis compatibility
}
return;
}
}
})).observe(menu, {attributes: true}); // removed in unloadFromWindow()
(aDOMWindow.tt.toRemove._toolboxObserver = new aDOMWindow.MutationObserver(function(aMutations) {
for (let mutation of aMutations) {
if (mutation.attributeName == 'slimChromeNavBar') {
if (
Services.prefs.getBoolPref('browser.tabs.drawInTitlebar') &&
aDOMWindow.windowState==aDOMWindow.STATE_MAXIMIZED &&
menu.getAttribute('autohide')=='true' &&
menu.hasAttribute('inactive')
) {
// BEGIN Beyond Australis compatibility:
// window controls wouldn't be visible because the buttonbox container wouldn't be in the right place
if(navToolbox.getAttribute('slimChromeNavBar') == 'true') {
let slimmer = aDOMWindow.document.querySelector('#theFoxOnlyBetter-slimChrome-slimmer');
slimmer.appendChild(slimSpacer);
slimmer.appendChild(titlebarButtonsClone);
} else {
navBar.appendChild(titlebarButtonsClone);
if(slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
}
// END Beyond Australis compatibility
titlebarButtons.style.marginRight = '-9999px'; // Beyond Australis compatibility
} else {
if (titlebarButtonsClone.parentNode !== null) { // if it exists
titlebarButtonsClone.parentNode.removeChild(titlebarButtonsClone);
if(slimSpacer.parentNode !== null) {
slimSpacer.parentNode.removeChild(slimSpacer);
}
}
titlebarButtons.style.marginRight = ''; // Beyond Australis compatibility
}
return;
}
}
})).observe(navToolbox, {attributes: true}); // removed in unloadFromWindow()
} else if (Services.appinfo.OS == 'Darwin') { // Mac
// here we just always force a native titlebar
// it's probably possible to move minimize/maximize/close buttons to #nav-bar
// but it would probably look ugly therefore we just mimic Safari
aDOMWindow.document.documentElement.removeAttribute("tabsintitlebar"); // show a native titlebar like in Safari
// It seems that Firefox restores "chromemargin" and "tabsintitlebar" attributes by itself
// It sometimes happens when resizing a Firefox window
// So we can't rely upon the "sizemodechange" event
// And we use MutationObvserver instead:
(aDOMWindow.tt.toRemove.osxMutationObserver = new aDOMWindow.MutationObserver((mutations) => {
for (let mutation of mutations) {
if (mutation.attributeName === "tabsintitlebar" || mutation.attributeName === "chromemargin") {
aDOMWindow.document.documentElement.removeAttribute("chromemargin");
aDOMWindow.document.documentElement.removeAttribute("tabsintitlebar");
return;
}
}
})).observe(aDOMWindow.document.documentElement, {attributes: true}); // removed in unloadFromWindow()
aDOMWindow.updateTitlebarDisplay();
} else { // Linux
// Set tab position to buttom to fix compatibility with certain extensions:
navBar.setAttribute('default-tabs-position', 'bottom');
// here we are concerned only with STATE_FULLSCREEN:
switch (aDOMWindow.windowState) {
case aDOMWindow.STATE_FULLSCREEN:
navBar.appendChild(windowControlsClone);
break;
}
aDOMWindow.addEventListener('sizemodechange', (aDOMWindow.tt.toRemove.eventListeners.onSizemodechange = function(event) {
switch (aDOMWindow.windowState) {
case aDOMWindow.STATE_MAXIMIZED:
case aDOMWindow.STATE_NORMAL:
if (windowControlsClone.parentNode !== null) { // if windowControlsClone exists
navBar.removeChild(windowControlsClone);
}
break;
case aDOMWindow.STATE_FULLSCREEN:
navBar.appendChild(windowControlsClone);
break;
}
}), false); // removed in unloadFromWindow()
}
//////////////////// END TITLE BAR STANDARD BUTTONS (Minimize, Restore/Maximize, Close) ////////////////////////
let propsToSet;
// for "Left" position:
// <spacer id="tt-toggler" />
// <vbox id="tt-sidebar" width="200">
// <toolbox></toolbox>
// <tree id="tt" flex="1" seltype="single" context="tabContextMenu" treelines="true" hidecolumnpicker="true"></tree>
// </vbox>
// <splitter id="tt-splitter" />
// <vbox id="tt-hover-area></vbox>"
// for "Right" position:
// <vbox id="tt-hover-area></vbox>"
// <splitter id="tt-splitter" />
// <vbox id="tt-sidebar" width="200">
// <toolbox></toolbox>
// <tree id="tt" flex="1" seltype="single" context="tabContextMenu" treelines="true" hidecolumnpicker="true"></tree>
// </vbox>
// <spacer id="tt-toggler" />
// for "sidebar top" position:
// <vbox id="sidebar-box">
// <vbox id="tt-sidebar"></vbox>
// <splitter id="tt-splitter" />
// <sidebarheader id="sidebar-header"></sidebarheader>
// ...
// </vbox>
// for "sidebar bottom" position:
// <vbox id="sidebar-box">
// ...
// <browser id="sidebar"></browser>
// <splitter id="tt-splitter" />
// <vbox id="tt-sidebar"></vbox>
// </vbox>
//////////////////// #tt-toggler /////////////////////////////////////////////////////////////////////////////////
let toggler = aDOMWindow.document.createElement("spacer");
toggler.id = "tt-toggler";
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////// VBOX ///////////////////////////////////////////////////////////////////////
let sidebar = aDOMWindow.document.createElement('vbox');
propsToSet = {
id: 'tt-sidebar',
width: ss.getWindowValue(aDOMWindow, 'tt-width') || ss.getGlobalValue('tt-new-sidebar-width') || '200',
height: ss.getWindowValue(aDOMWindow, 'tt-height') || ss.getGlobalValue('tt-new-sidebar-height') || '400'
//persist: 'width' // It seems 'persist' attr doesn't work in bootstrap addons, I'll use SS instead
};
Object.keys(propsToSet).forEach( (p)=>{sidebar.setAttribute(p, propsToSet[p])} );
// added later
//////////////////// END VBOX ///////////////////////////////////////////////////////////////////////
//////////////////// SPLITTER ///////////////////////////////////////////////////////////////////////
let splitter = aDOMWindow.document.createElement('splitter');
propsToSet = {
id: 'tt-splitter'
//class: 'sidebar-splitter' // "I'm just copying what mozilla does for their social sidebar splitter"
// "I left it out, but you can leave it in to see how you can style the splitter"
};
Object.keys(propsToSet).forEach( (p)=>{splitter.setAttribute(p, propsToSet[p]);} );
// added later
//////////////////// END SPLITTER ///////////////////////////////////////////////////////////////////////
//////////////////// #tt-hover-area /////////////////////////////////////////////////////////////////////////////////
let hoverArea = aDOMWindow.document.createElement("vbox");
hoverArea.id = "tt-hover-area";
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
let setTTPos = function (aPos) {
splitter.removeAttribute("resizeafter");
switch (aPos) {
case TT_POS_SB_TOP:
sidebar_box.insertBefore(toggler, sidebar_header.nextElementSibling);
sidebar_box.insertBefore(sidebar, toggler.nextElementSibling);
sidebar_box.insertBefore(splitter, sidebar.nextElementSibling);
sidebar_box.insertBefore(hoverArea, splitter.nextElementSibling);
splitter.setAttribute("resizebefore", "closest");
splitter.setAttribute("resizeafter", "farthest");
splitter.setAttribute("orient", "vertical");
break;
case TT_POS_SB_BOT:
sidebar_box.appendChild(hoverArea);
sidebar_box.appendChild(splitter);
sidebar_box.appendChild(sidebar);
sidebar_box.appendChild(toggler);
splitter.setAttribute("resizebefore", "flex");
splitter.setAttribute("resizeafter", "closest");
splitter.setAttribute("orient", "vertical");
break;
case TT_POS_RIGHT:
browser.appendChild(hoverArea);
browser.appendChild(splitter);
browser.appendChild(sidebar);
browser.appendChild(toggler);
splitter.setAttribute("resizebefore", "flex");
splitter.setAttribute("resizeafter", "closest");
splitter.setAttribute("orient", "horizontal");
break;
case TT_POS_LEFT:
default:
browser.insertBefore(toggler, appcontent);
browser.insertBefore(sidebar, appcontent);
browser.insertBefore(splitter, appcontent);
browser.insertBefore(hoverArea, appcontent);
splitter.setAttribute("resizebefore", "closest");
splitter.setAttribute("resizeafter", "flex");
splitter.setAttribute("orient", "horizontal");
break;
}
};
setTTPos(Services.prefs.getIntPref('extensions.tabtree.position'));
//////////////////// DROP INDICATOR //////////////////////////////////////////////////////////////////////////////
/*
<hbox id="tt-drop-indicator-container">
<image id="tt-drop-indicator" />
</hbox>
*/
let dropIndicator = aDOMWindow.document.createElement("image");
dropIndicator.id = "tt-drop-indicator";
let dropIndicatorContainer = aDOMWindow.document.createElement("hbox");
dropIndicatorContainer.id = "tt-drop-indicator-container";
dropIndicatorContainer.appendChild(dropIndicator);
sidebar.appendChild(dropIndicatorContainer);
dropIndicator.collapsed = true;
//////////////////// END DROP INDICATOR //////////////////////////////////////////////////////////////////////////
//////////////////// TOOLBOX /////////////////////////////////////////////////////////////////
/*
<toolbox id="tt-toolbox">
<toolbar id="tt-toolbar">
<ttpinnedtab /> <!-- see bindings.xml -->
<ttpinnedtab />
<ttpinnedtab />
<ttpinnedtab />
...
</toolbar>
</toolbox>
*/
// #tt-toolbox can be decorated to look different in different themes
// borders shouldn't be added to #tt-toolbar because they slightly break drag'n'drop behaviour
let toolbox = aDOMWindow.document.createElement('toolbox');
toolbox.id = 'tt-toolbox';
let toolbar = aDOMWindow.document.createElement('toolbar');
toolbar.id = 'tt-toolbar';
toolbar.setAttribute('fullscreentoolbar', 'true');
toolbox.appendChild(toolbar);