Skip to content

Commit 344ea64

Browse files
committed
♻️ Refactor responsive buttons to work in other types of area
1 parent fd58632 commit 344ea64

File tree

7 files changed

+59
-36
lines changed

7 files changed

+59
-36
lines changed

components/panels/content/browser-panel-button.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ button[is=browser-panel-button] {
1919
gap: 10px;
2020
align-items: center;
2121

22+
padding: 0;
23+
2224
flex: 1;
2325
}
2426
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ button.browser-tab-button {
1010

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

13-
--button-padding-percent: 12;
14-
padding: calc(var(--tab-true-height) / 100 * var(--button-padding-percent));
13+
--button-inner-padding-scale: 0.5;
1514

1615
& .browser-button-icon {
1716
--size: 14px;

components/toolbar/content/browser-toolbar-button.css

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,18 @@ button.browser-toolbar-button {
66
display: flex;
77

88
align-self: stretch;
9-
10-
background-color: transparent !important;
9+
justify-content: center;
1110

1211
min-height: auto;
1312
min-width: auto;
1413

15-
--button-area-height: max(var(--area-min-height, var(--area-height)), var(--area-height));
16-
17-
--x-padding: var(--area-x-padding, calc((var(--button-area-height) - var(--y-padding) - 16px) / 2));
18-
--y-padding: var(--area-y-padding, calc(var(--button-area-height) * 0.1 * 2 * calc(2 - var(--button-scale-factor, 1))));
19-
--content-size: min(var(--button-area-height) / 1.5, 1rem);
20-
21-
padding: calc(var(--y-padding) / 2) 0;
14+
padding: 0;
2215

2316
-moz-window-dragging: no-drag;
2417

25-
outline: none !important;
26-
transition: none !important;
27-
z-index: initial !important;
18+
margin-block: calc(var(--toolbar-height) * 0.1);
19+
20+
--button-default-color: transparent;
2821
}
2922

3023
button.browser-toolbar-button .browser-button-container {
@@ -34,26 +27,11 @@ button.browser-toolbar-button .browser-button-container {
3427
justify-content: center;
3528
align-self: stretch;
3629

37-
background-color: var(--button-background);
38-
outline: var(--button-outline);
39-
outline-offset: var(--button-outline-offset);
40-
41-
gap: max(var(--x-padding), 4px);
42-
4330
max-width: max-content;
4431
max-height: max-content;
45-
46-
border-radius: calc(var(--content-size) / 2);
47-
48-
padding: 0 var(--x-padding);
49-
50-
transition: var(--button-transition);
51-
52-
z-index: var(--button-z-index);
5332
}
5433

5534
button.browser-toolbar-button .browser-button-label {
56-
font-size: var(--content-size);
5735
white-space: nowrap;
5836
text-overflow: ellipsis;
5937
overflow: hidden;

components/toolbar/content/browser-toolbar.css

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
@import url("chrome://dot/content/widgets/browser-toolbar-button.css");
66
@import url("chrome://dot/content/widgets/browser-toolbar-overflow.css");
77

8+
:host(browser-toolbar) {
9+
--toolbar-width: var(--area-width, inherit);
10+
--toolbar-height: var(--area-height, inherit);
11+
}
12+
813
:host(browser-toolbar) {
914
display: flex;
1015
align-items: stretch;
1116

12-
width: var(--area-width, inherit);
13-
height: var(--area-height, inherit);
17+
width: var(--toolbar-width);
18+
height: var(--toolbar-height);
1419

15-
min-height: var(--area-min-height);
20+
min-height: var(--toolbar-min-height);
1621

1722
background-color: transparent;
1823
color: var(--lwt-text-color);
@@ -21,7 +26,7 @@
2126

2227
-moz-window-dragging: drag;
2328

24-
--area-min-height: 28px;
29+
--toolbar-min-height: 28px;
2530

2631
--csd-visibility: none;
2732
}

components/widgets/content/browser-button.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616
pointer-events: auto;
1717
}
1818

19+
.browser-button .browser-button-container {
20+
padding: 0 calc(var(--button-physical-height) * var(--button-inner-padding-scale, 0.25));
21+
gap: calc(var(--button-physical-height) * var(--button-inner-gap-scale, 0.2));
22+
}
23+
1924
.browser-button[mode=icons],
2025
:host([mode=icons]) .browser-button:not([mode]),
2126
[mode=icons]>.browser-button:not([mode]) {
27+
aspect-ratio: 1;
28+
2229
& .browser-button-container {
2330
justify-content: center;
2431

components/widgets/content/browser-button.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) {
66
constructor() {
77
super();
8+
9+
this.resizeObserver = new ResizeObserver(
10+
this._onBrowserButtonResize.bind(this)
11+
);
812
}
913

1014
/**
@@ -51,6 +55,14 @@ class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) {
5155
};
5256
}
5357

58+
/**
59+
* The button container element
60+
* @type {HTMLDivElement}
61+
*/
62+
get container() {
63+
return this.querySelector(".browser-button-container");
64+
}
65+
5466
/**
5567
* The icon of the browser button
5668
*/
@@ -172,6 +184,22 @@ class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) {
172184
}
173185
}
174186

187+
/**
188+
* Fired when the button's physical size is changed
189+
*/
190+
_onBrowserButtonResize() {
191+
const { width, height } = this.container.getBoundingClientRect();
192+
193+
this.container.style.setProperty(
194+
"--button-physical-width",
195+
+width.toFixed(2) + "px"
196+
);
197+
this.container.style.setProperty(
198+
"--button-physical-height",
199+
+height.toFixed(2) + "px"
200+
);
201+
}
202+
175203
connectedCallback() {
176204
this.classList.add("browser-button");
177205
this.classList.toggle(
@@ -196,6 +224,8 @@ class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) {
196224
"focusout",
197225
this._handleBrowserButtonEvent.bind(this)
198226
);
227+
228+
this.resizeObserver.observe(this);
199229
}
200230

201231
disconnectedCallback() {
@@ -207,6 +237,8 @@ class BrowserButton extends BrowserContextualMixin(HTMLButtonElement) {
207237
"focusout",
208238
this._handleBrowserButtonEvent.bind(this)
209239
);
240+
241+
this.resizeObserver.disconnect();
210242
}
211243
}
212244

themes/shared/xul/input.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ html|button[primary],
178178

179179
@media (prefers-contrast) {
180180

181-
button:not(:disabled),
181+
button:not(:disabled, [inert]),
182182
select:not(:disabled),
183-
xul|button:not(:disabled),
184-
html|button:not(:disabled),
183+
xul|button:not(:disabled, [inert]),
184+
html|button:not(:disabled, [inert]),
185185
html|select:not(:disabled),
186186
::slotted(menuitem:not([disabled])),
187187
::slotted(menu:not([disabled])) {

0 commit comments

Comments
 (0)