@@ -6,11 +6,17 @@ var { CommandAudiences } = ChromeUtils.importESModule(
6
6
"resource://gre/modules/CommandAudiences.sys.mjs"
7
7
) ;
8
8
9
- const kDebugVisiblePref = "dot.tabs.debug_information.visible" ;
10
-
11
9
class BrowserRenderedTab extends BrowserCustomizableArea {
10
+ /**
11
+ * The minimum width of a tab allowed
12
+ * before we need to hide actions
13
+ */
14
+ TAB_MIN_WIDTH_ACTIONS = 90 ;
15
+
12
16
constructor ( ) {
13
17
super ( ) ;
18
+
19
+ this . resizeObserver = new ResizeObserver ( this . _onTabResize . bind ( this ) ) ;
14
20
}
15
21
16
22
get interactiveTags ( ) {
@@ -414,64 +420,40 @@ class BrowserRenderedTab extends BrowserCustomizableArea {
414
420
} ;
415
421
}
416
422
417
- maybeRenderDebug ( ) {
418
- const isVisible = Services . prefs . getBoolPref ( kDebugVisiblePref , false ) ;
419
-
420
- clearInterval ( this . debugUpdateInt ) ;
421
- this . debugUpdateInt = null ;
422
-
423
- if ( isVisible ) {
424
- if ( ! this . querySelector ( "#tab-debug" ) ) {
425
- this . appendChild (
426
- html (
427
- "div" ,
428
- {
429
- id : "tab-debug" ,
430
- slot : "tab-internal" ,
431
- style : {
432
- display : "flex" ,
433
- flexDirection : "column" ,
434
- position : "fixed" ,
435
- backgroundColor : "black" ,
436
- color : "white" ,
437
- fontWeight : 600 ,
438
- fontSize : "10px" ,
439
- fontFamily : "monospace" ,
440
- whiteSpace : "nowrap"
441
- }
442
- } ,
443
- ""
444
- )
445
- ) ;
446
- }
423
+ _onTabResize ( ) {
424
+ const { width, height } = this . getBoundingClientRect ( ) ;
447
425
448
- this . debugUpdateInt = setInterval ( ( ) => {
449
- const width = this . getBoundingClientRect ( ) . width ;
450
-
451
- this . querySelector ( "#tab-debug" ) . replaceChildren (
452
- html (
453
- "div" ,
454
- { } ,
455
- ...[
456
- `ID: ${ this . id . split ( "tab-" ) [ 1 ] } ` ,
457
- `W: ${ width . toFixed ( 0 ) } ` ,
458
- `MaxW: ${ (
459
- parseInt ( getComputedStyle ( this ) . maxWidth ) ||
460
- width
461
- ) . toFixed ( 0 ) } `,
462
- `MinW: ${ (
463
- parseInt ( getComputedStyle ( this ) . minWidth ) ||
464
- width
465
- ) . toFixed ( 0 ) } `
466
- ] . map ( ( t ) => html ( "span" , { } , t ) )
467
- )
468
- ) ;
469
- } , 1 ) ;
470
- } else {
471
- if ( this . querySelector ( "#tab-debug" ) ) {
472
- this . querySelector ( "#tab-debug" ) . remove ( ) ;
473
- }
474
- }
426
+ this . style . setProperty ( "--tab-true-width" , width + "px" ) ;
427
+ this . style . setProperty ( "--tab-true-height" , height + "px" ) ;
428
+
429
+ this . toggleAttribute (
430
+ "hidetabactions" ,
431
+ width <= this . TAB_MIN_WIDTH_ACTIONS
432
+ ) ;
433
+ }
434
+
435
+ /**
436
+ * @param {BrowserDebugHologram } hologram
437
+ */
438
+ renderDebugHologram ( hologram ) {
439
+ const width = this . getBoundingClientRect ( ) . width ;
440
+
441
+ hologram . replaceChildren (
442
+ html (
443
+ "div" ,
444
+ { } ,
445
+ ...[
446
+ `ID: ${ this . id . split ( "tab-" ) [ 1 ] } ` ,
447
+ `W: ${ width . toFixed ( 0 ) } ` ,
448
+ `MaxW: ${ (
449
+ parseInt ( getComputedStyle ( this ) . maxWidth ) || width
450
+ ) . toFixed ( 0 ) } `,
451
+ `MinW: ${ (
452
+ parseInt ( getComputedStyle ( this ) . minWidth ) || width
453
+ ) . toFixed ( 0 ) } `
454
+ ] . map ( ( t ) => html ( "span" , { } , t ) )
455
+ )
456
+ ) ;
475
457
}
476
458
477
459
connectedCallback ( ) {
@@ -494,11 +476,15 @@ class BrowserRenderedTab extends BrowserCustomizableArea {
494
476
)
495
477
) ;
496
478
497
- Services . prefs . addObserver (
498
- kDebugVisiblePref ,
499
- this . maybeRenderDebug . bind ( this )
479
+ const debugHologram = BrowserDebugHologram . create (
480
+ {
481
+ id : "tab" ,
482
+ prefId : "dot.tabs.debug_information.visible"
483
+ } ,
484
+ this . renderDebugHologram . bind ( this )
500
485
) ;
501
- this . maybeRenderDebug ( ) ;
486
+
487
+ this . shadowRoot . appendChild ( debugHologram ) ;
502
488
503
489
this . shadowRoot . addEventListener ( "mousedown" , this ) ;
504
490
this . addEventListener ( "mouseover" , this ) ;
@@ -507,6 +493,8 @@ class BrowserRenderedTab extends BrowserCustomizableArea {
507
493
this . addEventListener ( "transitionend" , this ) ;
508
494
509
495
window . addEventListener ( "mouseup" , this ) ;
496
+
497
+ this . resizeObserver . observe ( this ) ;
510
498
}
511
499
512
500
disconnectedCallback ( ) {
@@ -519,6 +507,8 @@ class BrowserRenderedTab extends BrowserCustomizableArea {
519
507
this . removeEventListener ( "transitionend" , this ) ;
520
508
521
509
window . removeEventListener ( "mouseup" , this ) ;
510
+
511
+ this . resizeObserver . disconnect ( ) ;
522
512
}
523
513
524
514
/**
0 commit comments