... |
... |
@@ -537,27 +537,17 @@ class _RFPHelper { |
537
|
537
|
])
|
538
|
538
|
);
|
539
|
539
|
|
540
|
|
- if (
|
541
|
|
- !win._rfpSizeOffset ||
|
542
|
|
- (win._rfpOriginalSize &&
|
543
|
|
- win.outerWidth === win._rfpOriginalSize.width &&
|
544
|
|
- win.outerHeight === win._rfpOriginalSize.height)
|
545
|
|
- ) {
|
546
|
|
- const BASELINE_ROUNDING = 10;
|
547
|
|
- const offset = s =>
|
548
|
|
- s - Math.round(s / BASELINE_ROUNDING) * BASELINE_ROUNDING;
|
|
540
|
+ const isInitialSize =
|
|
541
|
+ win._rfpOriginalSize &&
|
|
542
|
+ win.outerWidth === win._rfpOriginalSize.width &&
|
|
543
|
+ win.outerHeight === win._rfpOriginalSize.height;
|
|
544
|
+
|
|
545
|
+ // We may need to shrink this window to rounded size if the browser container
|
|
546
|
+ // area is taller than the original, meaning extra chrome (like the optional
|
|
547
|
+ // "Only Show on New Tab" bookmarks toobar) was present and now gone.
|
|
548
|
+ const needToShrink =
|
|
549
|
+ isInitialSize && containerHeight > win._rfpOriginalSize.containerHeight;
|
549
|
550
|
|
550
|
|
- win._rfpSizeOffset = {
|
551
|
|
- width: offset(parentWidth),
|
552
|
|
- height: offset(parentHeight),
|
553
|
|
- };
|
554
|
|
- log(
|
555
|
|
- `${logPrefix} Window size offsets %o (from %s, %s)`,
|
556
|
|
- win._rfpSizeOffset,
|
557
|
|
- parentWidth,
|
558
|
|
- parentHeight
|
559
|
|
- );
|
560
|
|
- }
|
561
|
551
|
log(
|
562
|
552
|
`${logPrefix} contentWidth=${contentWidth} contentHeight=${contentHeight} parentWidth=${parentWidth} parentHeight=${parentHeight} containerWidth=${containerWidth} containerHeight=${containerHeight}${
|
563
|
553
|
isNewTab ? " (new tab)." : "."
|
... |
... |
@@ -573,33 +563,27 @@ class _RFPHelper { |
573
|
563
|
|
574
|
564
|
const roundDimensions = (aWidth, aHeight) => {
|
575
|
565
|
const r = (width, height) => {
|
576
|
|
- lastRoundedSize = {width, height};
|
|
566
|
+ lastRoundedSize = { width, height };
|
|
567
|
+ log(
|
|
568
|
+ `${logPrefix} roundDimensions(${aWidth}, ${aHeight}) = ${width} x ${height}`
|
|
569
|
+ );
|
577
|
570
|
return {
|
578
|
571
|
"--letterboxing-width": `var(--rdm-width, ${width}px)`,
|
579
|
572
|
"--letterboxing-height": `var(--rdm-height, ${height}px)`,
|
580
|
|
- }
|
|
573
|
+ };
|
581
|
574
|
};
|
582
|
575
|
|
583
|
|
- let result;
|
|
576
|
+ log(`${logPrefix} roundDimensions(${aWidth}, ${aHeight})`);
|
584
|
577
|
|
585
|
|
- if (!this.letterboxingEnabled) {
|
586
|
|
- const offset = win._rfpSizeOffset;
|
587
|
|
- result = r(aWidth - offset.width, aHeight - offset.height);
|
588
|
|
- log(
|
589
|
|
- `${logPrefix} Letterboxing disabled, applying baseline rounding offsets: (${aWidth}, ${aHeight}) => ${result.width} x ${result.height})`
|
590
|
|
- );
|
591
|
|
- return result;
|
|
578
|
+ if (!(isInitialSize || this.letterboxingEnabled)) {
|
|
579
|
+ // just round size to int
|
|
580
|
+ return r(aWidth, aHeight);
|
592
|
581
|
}
|
593
|
582
|
|
594
|
|
- log(`${logPrefix} roundDimensions(${aWidth}, ${aHeight})`);
|
595
|
583
|
// If the set is empty, we will round the content with the default
|
596
|
584
|
// stepping size.
|
597
|
585
|
if (!this._letterboxingDimensions.length) {
|
598
|
|
- result = r(this.steppedSize(aWidth, true), this.steppedSize(aHeight));
|
599
|
|
- log(
|
600
|
|
- `${logPrefix} roundDimensions(${aWidth}, ${aHeight}) = ${result.width} x ${result.height}`
|
601
|
|
- );
|
602
|
|
- return result;
|
|
586
|
+ return r(this.steppedSize(aWidth, true), this.steppedSize(aHeight));
|
603
|
587
|
}
|
604
|
588
|
|
605
|
589
|
let matchingArea = aWidth * aHeight;
|
... |
... |
@@ -625,14 +609,9 @@ class _RFPHelper { |
625
|
609
|
// If we cannot find any dimensions match to the real content window, this
|
626
|
610
|
// means the content area is smaller the smallest size in the set. In this
|
627
|
611
|
// case, we won't round the size and default to the max.
|
628
|
|
- result = targetDimensions
|
|
612
|
+ return targetDimensions
|
629
|
613
|
? r(targetDimensions.width, targetDimensions.height)
|
630
|
614
|
: r(aWidth, aHeight);
|
631
|
|
-
|
632
|
|
- log(
|
633
|
|
- `${logPrefix} roundDimensions(${aWidth}, ${aHeight}) = ${result.width} x ${result.height}`
|
634
|
|
- );
|
635
|
|
- return result;
|
636
|
615
|
};
|
637
|
616
|
|
638
|
617
|
const styleChanges = Object.assign([], {
|
... |
... |
@@ -654,6 +633,10 @@ class _RFPHelper { |
654
|
633
|
lazy.logConsole.error(e);
|
655
|
634
|
}
|
656
|
635
|
}
|
|
636
|
+ if (needToShrink) {
|
|
637
|
+ win.shrinkToLetterbox();
|
|
638
|
+ this._recordWindowSize(win);
|
|
639
|
+ }
|
657
|
640
|
});
|
658
|
641
|
},
|
659
|
642
|
});
|
... |
... |
@@ -741,15 +724,20 @@ class _RFPHelper { |
741
|
724
|
aWindow.setTimeout(() => {
|
742
|
725
|
tabBrowser.tabpanels?.classList.add("letterboxing-ready");
|
743
|
726
|
if (!aWindow._rfpOriginalSize) {
|
744
|
|
- aWindow._rfpOriginalSize = {
|
745
|
|
- width: aWindow.outerWidth,
|
746
|
|
- height: aWindow.outerHeight,
|
747
|
|
- };
|
748
|
|
- log("Recording original window size", aWindow._rfpOriginalSize);
|
|
727
|
+ this._recordWindowSize(aWindow);
|
749
|
728
|
}
|
750
|
729
|
});
|
751
|
730
|
}
|
752
|
731
|
|
|
732
|
+ _recordWindowSize(aWindow) {
|
|
733
|
+ aWindow._rfpOriginalSize = {
|
|
734
|
+ width: aWindow.outerWidth,
|
|
735
|
+ height: aWindow.outerHeight,
|
|
736
|
+ containerHeight: aWindow.gBrowser.getBrowserContainer()?.clientHeight,
|
|
737
|
+ };
|
|
738
|
+ log("Recording original window size", aWindow._rfpOriginalSize);
|
|
739
|
+ }
|
|
740
|
+
|
753
|
741
|
// We will attach this method to each browser window. When called
|
754
|
742
|
// it will instantly resize the window to exactly fit the selected
|
755
|
743
|
// (possibly letterboxed) browser.
|