Skip to content

Commit 2498ae3

Browse files
committed
💄 Fix padding on tab buttons getting smaller on squished tabs
1 parent efd6fa4 commit 2498ae3

File tree

5 files changed

+63
-69
lines changed

5 files changed

+63
-69
lines changed

‎components/tabs/content/browser-tab-button.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
button[is=browser-tab-button] {
5+
button.browser-tab-button {
66
padding: 0px;
77

88
min-height: 0px;
99
min-width: 0px;
1010

1111
--button-default-color: transparent;
1212

13-
padding: 2%;
13+
--button-padding-percent: 12;
14+
padding: calc(var(--tab-true-height) / 100 * var(--button-padding-percent));
1415

1516
& .browser-button-icon {
1617
--size: 14px;

‎components/tabs/content/browser-tab-button.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class BrowserTabButton extends BrowserCommandButton {
1313

1414
connectedCallback() {
1515
super.connectedCallback();
16+
17+
this.classList.add("browser-tab-button");
1618
}
1719

1820
disconnectedCallback() {

‎components/tabs/content/browser-tab-label.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ browser-tab-label:not([customizablearg-fit="true"]) {
1818
flex: 1;
1919

2020
&:-moz-locale-dir(ltr) {
21-
mask-image: linear-gradient(to right, black 90%, #fff0);
21+
mask-image: linear-gradient(to left, transparent, black var(--tab-label-mask-size, 2em));
2222
}
2323

2424
&:-moz-locale-dir(rtl) {
25-
mask-image: linear-gradient(to left, black 90%, #fff0);
25+
mask-image: linear-gradient(to right, transparent, black var(--tab-label-mask-size, 2em));
2626
}
2727
}

‎components/tabs/content/browser-tab.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ browser-tab .browser-tab-background {
5555

5656
browser-tab:hover {
5757
--tab-background: rgba(128, 128, 128, 0.125);
58+
--tab-label-mask-size: 1em;
5859
}
5960

6061
browser-tab[selected] {
@@ -220,6 +221,6 @@ browser-tab::part(customizable) {
220221
margin-inline-end: var(--tab-padding-end);
221222
}
222223

223-
browser-tabs[hidetabactions] browser-tab:not([selected]) {
224-
--tab-action-visibility: none;
224+
:host(browser-tab) browser-debug-hologram {
225+
position: fixed;
225226
}

‎components/tabs/content/browser-tab.js

Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ var { CommandAudiences } = ChromeUtils.importESModule(
66
"resource://gre/modules/CommandAudiences.sys.mjs"
77
);
88

9-
const kDebugVisiblePref = "dot.tabs.debug_information.visible";
10-
119
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+
1216
constructor() {
1317
super();
18+
19+
this.resizeObserver = new ResizeObserver(this._onTabResize.bind(this));
1420
}
1521

1622
get interactiveTags() {
@@ -414,64 +420,40 @@ class BrowserRenderedTab extends BrowserCustomizableArea {
414420
};
415421
}
416422

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();
447425

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+
);
475457
}
476458

477459
connectedCallback() {
@@ -494,11 +476,15 @@ class BrowserRenderedTab extends BrowserCustomizableArea {
494476
)
495477
);
496478

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)
500485
);
501-
this.maybeRenderDebug();
486+
487+
this.shadowRoot.appendChild(debugHologram);
502488

503489
this.shadowRoot.addEventListener("mousedown", this);
504490
this.addEventListener("mouseover", this);
@@ -507,6 +493,8 @@ class BrowserRenderedTab extends BrowserCustomizableArea {
507493
this.addEventListener("transitionend", this);
508494

509495
window.addEventListener("mouseup", this);
496+
497+
this.resizeObserver.observe(this);
510498
}
511499

512500
disconnectedCallback() {
@@ -519,6 +507,8 @@ class BrowserRenderedTab extends BrowserCustomizableArea {
519507
this.removeEventListener("transitionend", this);
520508

521509
window.removeEventListener("mouseup", this);
510+
511+
this.resizeObserver.disconnect();
522512
}
523513

524514
/**

0 commit comments

Comments
 (0)