Skip to content

Commit b97ab3d

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
[ui] Bring back dedicated toolbar.css.
The current styling for `<devtools-toolbar>` is difficult to comprehend, because the global styles peek into deep DOM trees, and there's little to no isolation. While it's beneficial to have the toolbar items in the light DOM, it still makes sense to encapsulate the toolbar specific styles in a shadow DOM. This is a first step to move the styling for the toolbar itself into a separate CSS file again. Drive-by-fix: Also add support for the `hidden` attribute. Bug: 388445687 Change-Id: I4a74df36cf2bfdd21e65ed9067fd84a8f8fdf415 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6172348 Reviewed-by: Alex Rudenko <[email protected]> Auto-Submit: Benedikt Meurer <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent fd8226a commit b97ab3d

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,7 @@ grd_files_debug_sources = [
25032503
"front_end/ui/legacy/themeColors.css.legacy.js",
25042504
"front_end/ui/legacy/theme_support/ThemeSupport.js",
25052505
"front_end/ui/legacy/tokens.css.legacy.js",
2506+
"front_end/ui/legacy/toolbar.css.legacy.js",
25062507
"front_end/ui/legacy/treeoutline.css.legacy.js",
25072508
"front_end/ui/legacy/viewContainers.css.legacy.js",
25082509
"front_end/ui/lit-html/i18n-template.js",

front_end/ui/legacy/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ generate_css("legacy_css_files") {
5050
"textPrompt.css",
5151
"themeColors.css",
5252
"tokens.css",
53+
"toolbar.css",
5354
"treeoutline.css",
5455
"viewContainers.css",
5556
]

front_end/ui/legacy/Toolbar.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ describeWithLocale('Toolbar', () => {
2424
assert.instanceOf(toolbar, Toolbar);
2525
});
2626

27-
it('does not attach a shadow root', () => {
27+
it('attaches a shadow root', () => {
2828
const toolbar = document.createElement('devtools-toolbar');
2929

30-
assert.isNull(toolbar.shadowRoot, 'Expected Toolbar to use Light DOM');
30+
assert.isNotNull(toolbar.shadowRoot, 'Expected Toolbar to use Light DOM');
3131
});
3232

3333
describe('connectedCallback', () => {

front_end/ui/legacy/Toolbar.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ import {GlassPane, PointerEventsBehavior} from './GlassPane.js';
4545
import {bindCheckbox} from './SettingsUI.js';
4646
import type {Suggestion} from './SuggestBox.js';
4747
import {Events as TextPromptEvents, TextPrompt} from './TextPrompt.js';
48+
import toolbarStyles from './toolbar.css.legacy.js';
4849
import {Tooltip} from './Tooltip.js';
49-
import {CheckboxLabel, LongClickController} from './UIUtils.js';
50+
import {CheckboxLabel, createShadowRootWithCoreStyles, LongClickController} from './UIUtils.js';
5051

5152
const UIStrings = {
5253
/**
@@ -81,6 +82,11 @@ export class Toolbar extends HTMLElement {
8182
enabled: boolean = true;
8283
private compactLayout = false;
8384

85+
constructor() {
86+
super();
87+
createShadowRootWithCoreStyles(this, {cssFile: toolbarStyles}).createChild('slot');
88+
}
89+
8490
connectedCallback(): void {
8591
if (!this.hasAttribute('role')) {
8692
this.setAttribute('role', 'toolbar');

front_end/ui/legacy/inspectorCommon.css

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -794,24 +794,6 @@ iframe.panel.extension {
794794

795795
/* Toolbar styles */
796796
devtools-toolbar {
797-
padding: 0 2px;
798-
position: relative;
799-
white-space: nowrap;
800-
height: var(--toolbar-height);
801-
overflow: hidden;
802-
display: flex;
803-
flex: none;
804-
align-items: center;
805-
z-index: 0;
806-
807-
--toolbar-height: 26px;
808-
809-
&[wrappable] {
810-
flex-wrap: wrap;
811-
overflow: visible;
812-
height: initial;
813-
}
814-
815797
& > * {
816798
position: relative;
817799
display: flex;

front_end/ui/legacy/toolbar.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2025 The Chromium Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
7+
:host {
8+
padding: 0 2px;
9+
position: relative;
10+
white-space: nowrap;
11+
height: var(--toolbar-height);
12+
overflow: hidden;
13+
display: flex;
14+
flex: none;
15+
align-items: center;
16+
z-index: 0;
17+
18+
--toolbar-height: 26px;
19+
}
20+
21+
:host([hidden]) {
22+
display: none;
23+
}
24+
25+
:host([wrappable]) {
26+
flex-wrap: wrap;
27+
overflow: visible;
28+
height: initial;
29+
}

0 commit comments

Comments
 (0)