chrome-devtools-frontend 1.0.1568864 → 1.0.1570343
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WATCHLISTS +1 -1
- package/front_end/core/common/ParsedURL.ts +3 -0
- package/front_end/core/host/AidaClient.ts +1 -0
- package/front_end/core/root/Runtime.ts +4 -8
- package/front_end/core/sdk/DOMModel.ts +6 -2
- package/front_end/entrypoints/main/MainImpl.ts +17 -20
- package/front_end/generated/SupportedCSSProperties.js +14 -14
- package/front_end/models/ai_assistance/agents/PatchAgent.ts +4 -1
- package/front_end/models/ai_assistance/agents/PerformanceAgent.ts +12 -0
- package/front_end/models/ai_assistance/agents/StylingAgent.snapshot.txt +12 -2
- package/front_end/models/ai_assistance/agents/StylingAgent.ts +4 -1
- package/front_end/models/stack_trace/StackTraceImpl.ts +12 -2
- package/front_end/models/stack_trace/StackTraceModel.ts +9 -1
- package/front_end/models/trace/Styles.ts +11 -8
- package/front_end/models/trace/handlers/PageLoadMetricsHandler.ts +3 -2
- package/front_end/models/trace/types/TraceEvents.ts +19 -10
- package/front_end/panels/common/AiCodeGenerationTeaser.ts +1 -1
- package/front_end/panels/common/DOMLinkifier.ts +12 -1
- package/front_end/panels/elements/AdoptedStyleSheetTreeElement.ts +6 -1
- package/front_end/panels/elements/ElementsPanel.ts +34 -12
- package/front_end/panels/elements/ElementsSidebarPane.ts +5 -2
- package/front_end/panels/elements/ElementsTreeOutline.ts +22 -2
- package/front_end/panels/elements/MetricsSidebarPane.ts +192 -177
- package/front_end/panels/elements/StylePropertiesSection.ts +10 -0
- package/front_end/panels/elements/StylesSidebarPane.ts +1 -1
- package/front_end/panels/elements/elements-meta.ts +1 -0
- package/front_end/panels/elements/metricsSidebarPane.css +3 -11
- package/front_end/panels/emulation/DeviceModeToolbar.ts +49 -60
- package/front_end/panels/settings/SettingsScreen.ts +8 -38
- package/front_end/panels/settings/settingsScreen.css +0 -4
- package/front_end/panels/sources/BreakpointEditDialog.ts +203 -138
- package/front_end/panels/sources/DebuggerPlugin.ts +15 -7
- package/front_end/panels/timeline/TimelineUIUtils.ts +61 -34
- package/front_end/panels/timeline/TimingsTrackAppender.ts +1 -0
- package/front_end/panels/timeline/overlays/OverlaysImpl.ts +3 -1
- package/front_end/panels/timeline/timelineFlameChartView.css +1 -0
- package/front_end/third_party/chromium/README.chromium +1 -1
- package/front_end/ui/components/text_editor/AiCodeCompletionProvider.ts +23 -1
- package/front_end/ui/components/text_editor/AiCodeGenerationProvider.ts +16 -4
- package/front_end/ui/kit/link/Link.ts +14 -8
- package/front_end/ui/kit/link/link.css +1 -1
- package/front_end/ui/legacy/components/utils/JSPresentationUtils.ts +11 -0
- package/front_end/ui/legacy/treeoutline.css +1 -1
- package/front_end/ui/visual_logging/KnownContextValues.ts +2 -0
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import * as Common from '../../core/common/common.js';
|
|
6
6
|
import * as i18n from '../../core/i18n/i18n.js';
|
|
7
7
|
import * as SDK from '../../core/sdk/sdk.js';
|
|
8
|
+
import type * as Protocol from '../../generated/protocol.js';
|
|
8
9
|
import * as UI from '../../ui/legacy/legacy.js';
|
|
9
10
|
import {Directives, html, nothing, render} from '../../ui/lit/lit.js';
|
|
10
11
|
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
|
|
@@ -212,14 +213,16 @@ const DEFERRED_DEFAULT_VIEW: DeferredView = (input, _output, target: HTMLElement
|
|
|
212
213
|
export class DeferredDOMNodeLink extends UI.Widget.Widget {
|
|
213
214
|
#deferredNode: SDK.DOMModel.DeferredDOMNode|undefined = undefined;
|
|
214
215
|
#options: Options|undefined = undefined;
|
|
216
|
+
#styleSheetId: Protocol.DOM.StyleSheetId|undefined = undefined;
|
|
215
217
|
#view: DeferredView;
|
|
216
218
|
|
|
217
219
|
constructor(
|
|
218
220
|
element?: HTMLElement, deferredNode?: SDK.DOMModel.DeferredDOMNode, options?: Options,
|
|
219
|
-
view: DeferredView = DEFERRED_DEFAULT_VIEW) {
|
|
221
|
+
styleSheetId?: Protocol.DOM.StyleSheetId, view: DeferredView = DEFERRED_DEFAULT_VIEW) {
|
|
220
222
|
super(element, {useShadowDom: true});
|
|
221
223
|
this.element.classList.remove('vbox');
|
|
222
224
|
this.#deferredNode = deferredNode;
|
|
225
|
+
this.#styleSheetId = styleSheetId;
|
|
223
226
|
this.#options = options;
|
|
224
227
|
this.#view = view;
|
|
225
228
|
this.performUpdate();
|
|
@@ -230,6 +233,14 @@ export class DeferredDOMNodeLink extends UI.Widget.Widget {
|
|
|
230
233
|
preventKeyboardFocus: this.#options?.preventKeyboardFocus,
|
|
231
234
|
onClick: () => {
|
|
232
235
|
this.#deferredNode?.resolve?.(node => {
|
|
236
|
+
if (node && this.#styleSheetId) {
|
|
237
|
+
for (const adoptedStyle of node.adoptedStyleSheetsForNode) {
|
|
238
|
+
if (adoptedStyle.id === this.#styleSheetId) {
|
|
239
|
+
void Common.Revealer.reveal(adoptedStyle);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
233
244
|
void Common.Revealer.reveal(node);
|
|
234
245
|
void node?.scrollIntoView();
|
|
235
246
|
});
|
|
@@ -9,11 +9,12 @@ import * as CodeHighlighter from '../../ui/components/code_highlighter/code_high
|
|
|
9
9
|
import * as Components from '../../ui/legacy/components/utils/utils.js';
|
|
10
10
|
import * as UI from '../../ui/legacy/legacy.js';
|
|
11
11
|
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
|
|
12
|
+
import {PanelUtils} from '../utils/utils.js';
|
|
12
13
|
|
|
13
14
|
export class AdoptedStyleSheetTreeElement extends UI.TreeOutline.TreeElement {
|
|
14
15
|
private eventListener: Common.EventTarget.EventDescriptor|null = null;
|
|
15
16
|
|
|
16
|
-
constructor(
|
|
17
|
+
constructor(readonly adoptedStyleSheet: SDK.DOMModel.AdoptedStyleSheet) {
|
|
17
18
|
super('');
|
|
18
19
|
const header = adoptedStyleSheet.cssModel.styleSheetHeaderForId(adoptedStyleSheet.id);
|
|
19
20
|
if (header) {
|
|
@@ -50,6 +51,10 @@ export class AdoptedStyleSheetTreeElement extends UI.TreeOutline.TreeElement {
|
|
|
50
51
|
}
|
|
51
52
|
treeElement.appendChild(new AdoptedStyleSheetContentsTreeElement(header));
|
|
52
53
|
}
|
|
54
|
+
|
|
55
|
+
highlight(): void {
|
|
56
|
+
PanelUtils.highlightElement(this.listItemElement);
|
|
57
|
+
}
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
export class AdoptedStyleSheetContentsTreeElement extends UI.TreeOutline.TreeElement {
|
|
@@ -795,7 +795,7 @@ export class ElementsPanel extends UI.Panel.Panel implements UI.SearchableView.S
|
|
|
795
795
|
return this.#domTreeWidget.selectedDOMNode();
|
|
796
796
|
}
|
|
797
797
|
|
|
798
|
-
selectDOMNode(node: SDK.DOMModel.DOMNode, focus?: boolean): void {
|
|
798
|
+
selectDOMNode(node: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet, focus?: boolean): void {
|
|
799
799
|
this.#domTreeWidget.selectDOMNode(node, focus);
|
|
800
800
|
}
|
|
801
801
|
|
|
@@ -899,6 +899,18 @@ export class ElementsPanel extends UI.Panel.Panel implements UI.SearchableView.S
|
|
|
899
899
|
this.notFirstInspectElement = true;
|
|
900
900
|
}
|
|
901
901
|
|
|
902
|
+
async revealAndSelectAdoptedStyleSheet(nodeToReveal: SDK.DOMModel.AdoptedStyleSheet, opts?: RevealAndSelectNodeOpts):
|
|
903
|
+
Promise<void> {
|
|
904
|
+
const {showPanel = true, focusNode = false} = opts ?? {};
|
|
905
|
+
this.omitDefaultSelection = true;
|
|
906
|
+
|
|
907
|
+
if (showPanel) {
|
|
908
|
+
await UI.ViewManager.ViewManager.instance().showView('elements', false, !focus);
|
|
909
|
+
}
|
|
910
|
+
this.selectDOMNode(nodeToReveal, focusNode);
|
|
911
|
+
delete this.omitDefaultSelection;
|
|
912
|
+
}
|
|
913
|
+
|
|
902
914
|
private showUAShadowDOMChanged(): void {
|
|
903
915
|
this.#domTreeWidget.reload();
|
|
904
916
|
}
|
|
@@ -982,7 +994,6 @@ export class ElementsPanel extends UI.Panel.Panel implements UI.SearchableView.S
|
|
|
982
994
|
|
|
983
995
|
const showMetricsWidgetInComputedPane = (): void => {
|
|
984
996
|
this.metricsWidget.show(computedStylePanesWrapper.element, this.computedStyleWidget.element);
|
|
985
|
-
this.metricsWidget.toggleVisibility(true /* visible */);
|
|
986
997
|
this.stylesWidget.removeEventListener(StylesSidebarPaneEvents.STYLES_UPDATE_COMPLETED, toggleMetricsWidget);
|
|
987
998
|
};
|
|
988
999
|
|
|
@@ -993,14 +1004,18 @@ export class ElementsPanel extends UI.Panel.Panel implements UI.SearchableView.S
|
|
|
993
1004
|
} else {
|
|
994
1005
|
this.metricsWidget.show(matchedStylePanesWrapper.element);
|
|
995
1006
|
if (!this.stylesWidget.hasMatchedStyles) {
|
|
996
|
-
this.metricsWidget.
|
|
1007
|
+
this.metricsWidget.hideWidget();
|
|
997
1008
|
}
|
|
998
1009
|
this.stylesWidget.addEventListener(StylesSidebarPaneEvents.STYLES_UPDATE_COMPLETED, toggleMetricsWidget);
|
|
999
1010
|
}
|
|
1000
1011
|
};
|
|
1001
1012
|
|
|
1002
1013
|
const toggleMetricsWidget = (event: Common.EventTarget.EventTargetEvent<StylesUpdateCompletedEvent>): void => {
|
|
1003
|
-
|
|
1014
|
+
if (event.data.hasMatchedStyles) {
|
|
1015
|
+
this.metricsWidget.showWidget();
|
|
1016
|
+
} else {
|
|
1017
|
+
this.metricsWidget.hideWidget();
|
|
1018
|
+
}
|
|
1004
1019
|
};
|
|
1005
1020
|
|
|
1006
1021
|
const tabSelected = (event: Common.EventTarget.EventTargetEvent<UI.TabbedPane.EventData>): void => {
|
|
@@ -1306,10 +1321,12 @@ export class ContextMenuProvider implements
|
|
|
1306
1321
|
}
|
|
1307
1322
|
}
|
|
1308
1323
|
|
|
1309
|
-
export class DOMNodeRevealer implements
|
|
1310
|
-
|
|
1311
|
-
reveal(
|
|
1312
|
-
|
|
1324
|
+
export class DOMNodeRevealer implements Common.Revealer.Revealer<
|
|
1325
|
+
SDK.DOMModel.DOMNode|SDK.DOMModel.DeferredDOMNode|SDK.RemoteObject.RemoteObject|SDK.DOMModel.AdoptedStyleSheet> {
|
|
1326
|
+
reveal(
|
|
1327
|
+
node: SDK.DOMModel.DOMNode|SDK.DOMModel.DeferredDOMNode|SDK.RemoteObject.RemoteObject|
|
|
1328
|
+
SDK.DOMModel.AdoptedStyleSheet,
|
|
1329
|
+
omitFocus?: boolean): Promise<void> {
|
|
1313
1330
|
const panel = ElementsPanel.instance();
|
|
1314
1331
|
panel.pendingNodeReveal = true;
|
|
1315
1332
|
|
|
@@ -1329,7 +1346,7 @@ export class DOMNodeRevealer implements
|
|
|
1329
1346
|
|
|
1330
1347
|
function revealPromise(
|
|
1331
1348
|
resolve: () => void, reject: (arg0: Platform.UserVisibleError.UserVisibleError) => void): void {
|
|
1332
|
-
if (node instanceof SDK.DOMModel.DOMNode) {
|
|
1349
|
+
if (node instanceof SDK.DOMModel.DOMNode || node instanceof SDK.DOMModel.AdoptedStyleSheet) {
|
|
1333
1350
|
onNodeResolved((node));
|
|
1334
1351
|
} else if (node instanceof SDK.DOMModel.DeferredDOMNode) {
|
|
1335
1352
|
(node).resolve(checkDeferredDOMNodeThenReveal);
|
|
@@ -1343,14 +1360,15 @@ export class DOMNodeRevealer implements
|
|
|
1343
1360
|
}
|
|
1344
1361
|
}
|
|
1345
1362
|
|
|
1346
|
-
function onNodeResolved(resolvedNode: SDK.DOMModel.DOMNode): void {
|
|
1363
|
+
function onNodeResolved(resolvedNode: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet): void {
|
|
1347
1364
|
panel.pendingNodeReveal = false;
|
|
1348
1365
|
|
|
1349
1366
|
// A detached node could still have a parent and ownerDocument
|
|
1350
1367
|
// properties, which means stepping up through the hierarchy to ensure
|
|
1351
1368
|
// that the root node is the document itself. Any break implies
|
|
1352
1369
|
// detachment.
|
|
1353
|
-
let currentNode: SDK.DOMModel.DOMNode =
|
|
1370
|
+
let currentNode: SDK.DOMModel.DOMNode =
|
|
1371
|
+
resolvedNode instanceof SDK.DOMModel.AdoptedStyleSheet ? resolvedNode.parent : resolvedNode;
|
|
1354
1372
|
while (currentNode.parentNode) {
|
|
1355
1373
|
currentNode = currentNode.parentNode;
|
|
1356
1374
|
}
|
|
@@ -1364,7 +1382,11 @@ export class DOMNodeRevealer implements
|
|
|
1364
1382
|
}
|
|
1365
1383
|
|
|
1366
1384
|
if (resolvedNode) {
|
|
1367
|
-
|
|
1385
|
+
const opts: RevealAndSelectNodeOpts = {showPanel: true, focusNode: !omitFocus};
|
|
1386
|
+
const promise = resolvedNode instanceof SDK.DOMModel.AdoptedStyleSheet ?
|
|
1387
|
+
panel.revealAndSelectAdoptedStyleSheet(resolvedNode, opts) :
|
|
1388
|
+
panel.revealAndSelectNode(resolvedNode, opts);
|
|
1389
|
+
void promise.then(resolve);
|
|
1368
1390
|
return;
|
|
1369
1391
|
}
|
|
1370
1392
|
const msg = i18nString(UIStrings.nodeCannotBeFoundInTheCurrent);
|
|
@@ -10,8 +10,11 @@ import {type ComputedStyleModel, type CSSModelChangedEvent, Events} from './Comp
|
|
|
10
10
|
|
|
11
11
|
export class ElementsSidebarPane extends UI.Widget.VBox {
|
|
12
12
|
protected computedStyleModelInternal: ComputedStyleModel;
|
|
13
|
-
constructor(computedStyleModel: ComputedStyleModel,
|
|
14
|
-
|
|
13
|
+
constructor(computedStyleModel: ComputedStyleModel, options: UI.Widget.WidgetOptions = {}) {
|
|
14
|
+
options.useShadowDom = options.useShadowDom ?? true;
|
|
15
|
+
options.classes = options.classes ?? [];
|
|
16
|
+
options.classes.push('flex-none');
|
|
17
|
+
super(options);
|
|
15
18
|
this.computedStyleModelInternal = computedStyleModel;
|
|
16
19
|
this.computedStyleModelInternal.addEventListener(Events.CSS_MODEL_CHANGED, this.onCSSModelChanged, this);
|
|
17
20
|
this.computedStyleModelInternal.addEventListener(Events.COMPUTED_STYLE_CHANGED, this.onComputedStyleChanged, this);
|
|
@@ -274,8 +274,12 @@ export class DOMTreeWidget extends UI.Widget.Widget {
|
|
|
274
274
|
this.performUpdate();
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
selectDOMNode(node: SDK.DOMModel.DOMNode|null, focus?: boolean): void {
|
|
278
|
-
|
|
277
|
+
selectDOMNode(node: SDK.DOMModel.DOMNode|SDK.DOMModel.AdoptedStyleSheet|null, focus?: boolean): void {
|
|
278
|
+
if (node instanceof SDK.DOMModel.AdoptedStyleSheet) {
|
|
279
|
+
this.#viewOutput?.elementsTreeOutline?.highlightAdoptedStyleSheet(node);
|
|
280
|
+
} else {
|
|
281
|
+
this.#viewOutput?.elementsTreeOutline?.selectDOMNode(node, focus);
|
|
282
|
+
}
|
|
279
283
|
}
|
|
280
284
|
|
|
281
285
|
highlightNodeAttribute(node: SDK.DOMModel.DOMNode, attribute: string): void {
|
|
@@ -911,6 +915,22 @@ export class ElementsTreeOutline extends
|
|
|
911
915
|
}
|
|
912
916
|
}
|
|
913
917
|
|
|
918
|
+
highlightAdoptedStyleSheet(adoptedStyleSheet: SDK.DOMModel.AdoptedStyleSheet): void {
|
|
919
|
+
const parentNode = !this.includeRootDOMNode && adoptedStyleSheet.parent === this.rootDOMNode && this.rootDOMNode ?
|
|
920
|
+
this.rootElement() :
|
|
921
|
+
this.createTreeElementFor(adoptedStyleSheet.parent);
|
|
922
|
+
if (!parentNode) {
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
for (const child of parentNode.children()) {
|
|
927
|
+
if (child instanceof AdoptedStyleSheetTreeElement && child.adoptedStyleSheet === adoptedStyleSheet) {
|
|
928
|
+
child.highlight();
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
914
934
|
editing(): boolean {
|
|
915
935
|
const node = this.selectedDOMNode();
|
|
916
936
|
if (!node) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// Copyright 2021 The Chromium Authors
|
|
2
2
|
// Use of this source code is governed by a BSD-style license that can be
|
|
3
3
|
// found in the LICENSE file.
|
|
4
|
-
/* eslint-disable @devtools/no-imperative-dom-api */
|
|
5
|
-
/* eslint-disable @devtools/no-lit-render-outside-of-view */
|
|
6
4
|
|
|
7
5
|
/*
|
|
8
6
|
* Copyright (C) 2007 Apple Inc. All rights reserved.
|
|
@@ -45,6 +43,144 @@ import metricsSidebarPaneStyles from './metricsSidebarPane.css.js';
|
|
|
45
43
|
|
|
46
44
|
const {live} = Directives;
|
|
47
45
|
|
|
46
|
+
interface ViewInput {
|
|
47
|
+
style: Map<string, string>;
|
|
48
|
+
highlightedMode: string;
|
|
49
|
+
node: SDK.DOMModel.DOMNode|null;
|
|
50
|
+
contentWidth: string;
|
|
51
|
+
contentHeight: string;
|
|
52
|
+
onHighlightNode: (showHighlight: boolean, mode: string) => void;
|
|
53
|
+
onStartEditing: (target: Element, box: string, styleProperty: string, computedStyle: Map<string, string>) => void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type View = (input: ViewInput, output: undefined, target: HTMLElement) => void;
|
|
57
|
+
|
|
58
|
+
const DEFAULT_VIEW: View = (input, output, target) => {
|
|
59
|
+
const {style, highlightedMode, node, contentWidth, contentHeight, onHighlightNode, onStartEditing} = input;
|
|
60
|
+
|
|
61
|
+
function createBoxPartElement(style: Map<string, string>, name: string, side: string, suffix: string): LitTemplate {
|
|
62
|
+
const propertyName = (name !== 'position' ? name + '-' : '') + side + suffix;
|
|
63
|
+
let value = style.get(propertyName);
|
|
64
|
+
|
|
65
|
+
if (value === '' || (name !== 'position' && value === 'unset')) {
|
|
66
|
+
value = '\u2012';
|
|
67
|
+
} else if (name === 'position' && value === 'auto') {
|
|
68
|
+
value = '\u2012';
|
|
69
|
+
}
|
|
70
|
+
value = value?.replace(/px$/, '');
|
|
71
|
+
value = value ? Platform.NumberUtilities.toFixedIfFloating(value) : value;
|
|
72
|
+
// clang-format off
|
|
73
|
+
return html`<div class=${side} jslog=${VisualLogging.value(propertyName).track({
|
|
74
|
+
dblclick: true, keydown: 'Enter|Escape|ArrowUp|ArrowDown|PageUp|PageDown', change: true,
|
|
75
|
+
})}
|
|
76
|
+
@dblclick=${(e: Event) => onStartEditing(e.currentTarget as Element, name, propertyName, style)}
|
|
77
|
+
.innerText=${live(value ?? '')}>
|
|
78
|
+
</div>`;
|
|
79
|
+
// clang-format on
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Display types for which margin is ignored.
|
|
83
|
+
const noMarginDisplayType = new Set<string>([
|
|
84
|
+
'table-cell',
|
|
85
|
+
'table-column',
|
|
86
|
+
'table-column-group',
|
|
87
|
+
'table-footer-group',
|
|
88
|
+
'table-header-group',
|
|
89
|
+
'table-row',
|
|
90
|
+
'table-row-group',
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
// Display types for which padding is ignored.
|
|
94
|
+
const noPaddingDisplayType = new Set<string>([
|
|
95
|
+
'table-column',
|
|
96
|
+
'table-column-group',
|
|
97
|
+
'table-footer-group',
|
|
98
|
+
'table-header-group',
|
|
99
|
+
'table-row',
|
|
100
|
+
'table-row-group',
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
// Position types for which top, left, bottom and right are ignored.
|
|
104
|
+
const noPositionType = new Set<string>(['static']);
|
|
105
|
+
|
|
106
|
+
const boxes = ['content', 'padding', 'border', 'margin', 'position'];
|
|
107
|
+
const boxColors = [
|
|
108
|
+
Common.Color.PageHighlight.Content,
|
|
109
|
+
Common.Color.PageHighlight.Padding,
|
|
110
|
+
Common.Color.PageHighlight.Border,
|
|
111
|
+
Common.Color.PageHighlight.Margin,
|
|
112
|
+
Common.Color.Legacy.fromRGBA([0, 0, 0, 0]),
|
|
113
|
+
];
|
|
114
|
+
const boxLabels = ['content', 'padding', 'border', 'margin', 'position'];
|
|
115
|
+
let previousBox: LitTemplate = nothing;
|
|
116
|
+
for (let i = 0; i < boxes.length; ++i) {
|
|
117
|
+
const name = boxes[i];
|
|
118
|
+
const display = style.get('display');
|
|
119
|
+
const position = style.get('position');
|
|
120
|
+
if (!display || !position) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (name === 'margin' && noMarginDisplayType.has(display)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (name === 'padding' && noPaddingDisplayType.has(display)) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (name === 'position' && noPositionType.has(position)) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const shouldHighlight = !node || highlightedMode === 'all' || name === highlightedMode;
|
|
134
|
+
const backgroundColor = boxColors[i].asString(Common.Color.Format.RGBA) || '';
|
|
135
|
+
|
|
136
|
+
const suffix = (name === 'border' ? '-width' : '');
|
|
137
|
+
// clang-format off
|
|
138
|
+
const box: LitTemplate = html`
|
|
139
|
+
<div
|
|
140
|
+
class="${name} ${shouldHighlight ? 'highlighted' : ''}"
|
|
141
|
+
style="background-color: ${shouldHighlight ? backgroundColor : ''}"
|
|
142
|
+
jslog=${VisualLogging.metricsBox().context(name).track({hover: true})}
|
|
143
|
+
@mouseover=${(e: Event) => {e.consume(); onHighlightNode(true, name === 'position' ? 'all' : name);}}>
|
|
144
|
+
${name === 'content' ? html`
|
|
145
|
+
<span jslog=${VisualLogging.value('width').track({
|
|
146
|
+
dblclick: true,
|
|
147
|
+
keydown: 'Enter|Escape|ArrowUp|ArrowDown|PageUp|PageDown',
|
|
148
|
+
change: true,
|
|
149
|
+
})}
|
|
150
|
+
@dblclick=${(e: Event) => onStartEditing(e.currentTarget as Element, 'width', 'width', style)}
|
|
151
|
+
.innerText=${live(contentWidth)}>
|
|
152
|
+
</span>
|
|
153
|
+
<span> × </span>
|
|
154
|
+
<span jslog=${VisualLogging.value('height').track({
|
|
155
|
+
dblclick: true,
|
|
156
|
+
keydown: 'Enter|Escape|ArrowUp|ArrowDown|PageUp|PageDown',
|
|
157
|
+
change: true,
|
|
158
|
+
})}
|
|
159
|
+
@dblclick=${(e: Event) => onStartEditing(e.currentTarget as Element, 'height', 'height', style)}
|
|
160
|
+
.innerText=${live(contentHeight)}>
|
|
161
|
+
</span>` : html`
|
|
162
|
+
<div class="label">${boxLabels[i]}</div>
|
|
163
|
+
${createBoxPartElement(style, name, 'top', suffix)}
|
|
164
|
+
<br>
|
|
165
|
+
${createBoxPartElement(style, name, 'left', suffix)}
|
|
166
|
+
${previousBox}
|
|
167
|
+
${createBoxPartElement(style, name, 'right', suffix)}
|
|
168
|
+
<br>
|
|
169
|
+
${createBoxPartElement(style, name, 'bottom', suffix)}`}
|
|
170
|
+
</div>`;
|
|
171
|
+
// clang-format on
|
|
172
|
+
|
|
173
|
+
previousBox = box;
|
|
174
|
+
}
|
|
175
|
+
// clang-format off
|
|
176
|
+
render(html`
|
|
177
|
+
<div class="metrics ${!node ? 'collapsed' : ''}" @mouseover=${(e: Event) => { e.consume(); onHighlightNode(true, 'all'); }}
|
|
178
|
+
@mouseleave=${(e: Event) => { e.consume(); onHighlightNode(false, 'all'); }}>
|
|
179
|
+
${previousBox}
|
|
180
|
+
</div>`, target);
|
|
181
|
+
// clang-format on
|
|
182
|
+
};
|
|
183
|
+
|
|
48
184
|
export class MetricsSidebarPane extends ElementsSidebarPane {
|
|
49
185
|
originalPropertyData: SDK.CSSProperty.CSSProperty|null;
|
|
50
186
|
previousPropertyDataCandidate: SDK.CSSProperty.CSSProperty|null;
|
|
@@ -52,9 +188,10 @@ export class MetricsSidebarPane extends ElementsSidebarPane {
|
|
|
52
188
|
private highlightMode: string;
|
|
53
189
|
private computedStyle: Map<string, string>|null;
|
|
54
190
|
private isEditingMetrics?: boolean;
|
|
191
|
+
private view: View;
|
|
55
192
|
|
|
56
|
-
constructor(computedStyleModel: ComputedStyleModel) {
|
|
57
|
-
super(computedStyleModel);
|
|
193
|
+
constructor(computedStyleModel: ComputedStyleModel, view = DEFAULT_VIEW) {
|
|
194
|
+
super(computedStyleModel, {jslog: `${VisualLogging.pane('styles-metrics')}`});
|
|
58
195
|
this.registerRequiredCSS(metricsSidebarPaneStyles);
|
|
59
196
|
|
|
60
197
|
this.originalPropertyData = null;
|
|
@@ -62,7 +199,7 @@ export class MetricsSidebarPane extends ElementsSidebarPane {
|
|
|
62
199
|
this.inlineStyle = null;
|
|
63
200
|
this.highlightMode = '';
|
|
64
201
|
this.computedStyle = null;
|
|
65
|
-
this.
|
|
202
|
+
this.view = view;
|
|
66
203
|
}
|
|
67
204
|
|
|
68
205
|
override async performUpdate(): Promise<void> {
|
|
@@ -76,8 +213,17 @@ export class MetricsSidebarPane extends ElementsSidebarPane {
|
|
|
76
213
|
const node = this.node();
|
|
77
214
|
const cssModel = this.cssModel();
|
|
78
215
|
if (!node || node.nodeType() !== Node.ELEMENT_NODE || !cssModel) {
|
|
79
|
-
this.
|
|
80
|
-
|
|
216
|
+
this.view(
|
|
217
|
+
{
|
|
218
|
+
style: new Map(),
|
|
219
|
+
highlightedMode: '',
|
|
220
|
+
node: null,
|
|
221
|
+
contentWidth: '',
|
|
222
|
+
contentHeight: '',
|
|
223
|
+
onHighlightNode: () => {},
|
|
224
|
+
onStartEditing: () => {},
|
|
225
|
+
},
|
|
226
|
+
undefined, this.contentElement);
|
|
81
227
|
return await Promise.resolve();
|
|
82
228
|
}
|
|
83
229
|
|
|
@@ -109,16 +255,6 @@ export class MetricsSidebarPane extends ElementsSidebarPane {
|
|
|
109
255
|
this.requestUpdate();
|
|
110
256
|
}
|
|
111
257
|
|
|
112
|
-
/**
|
|
113
|
-
* Toggle the visibility of the Metrics pane. This toggle allows external
|
|
114
|
-
* callers to control the visibility of this pane, but toggling this on does
|
|
115
|
-
* not guarantee the pane will always show up, because the pane's visibility
|
|
116
|
-
* is also controlled by the internal condition that style cannot be empty.
|
|
117
|
-
*/
|
|
118
|
-
toggleVisibility(isVisible: boolean): void {
|
|
119
|
-
this.element.classList.toggle('invisible', !isVisible);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
258
|
private getPropertyValueAsPx(style: Map<string, string>, propertyName: string): number {
|
|
123
259
|
const propertyValue = style.get(propertyName);
|
|
124
260
|
if (!propertyValue) {
|
|
@@ -141,8 +277,7 @@ export class MetricsSidebarPane extends ElementsSidebarPane {
|
|
|
141
277
|
return {left, top, right, bottom};
|
|
142
278
|
}
|
|
143
279
|
|
|
144
|
-
private highlightDOMNode(showHighlight: boolean, mode: string
|
|
145
|
-
event.consume();
|
|
280
|
+
private highlightDOMNode(showHighlight: boolean, mode: string): void {
|
|
146
281
|
const node = this.node();
|
|
147
282
|
if (showHighlight && node) {
|
|
148
283
|
if (this.highlightMode === mode) {
|
|
@@ -160,175 +295,55 @@ export class MetricsSidebarPane extends ElementsSidebarPane {
|
|
|
160
295
|
}
|
|
161
296
|
}
|
|
162
297
|
|
|
163
|
-
private
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
function createBoxPartElement(
|
|
168
|
-
this: MetricsSidebarPane, style: Map<string, string>, name: string, side: string, suffix: string): LitTemplate {
|
|
169
|
-
const propertyName = (name !== 'position' ? name + '-' : '') + side + suffix;
|
|
170
|
-
let value = style.get(propertyName);
|
|
171
|
-
|
|
172
|
-
if (value === '' || (name !== 'position' && value === 'unset')) {
|
|
173
|
-
value = '\u2012';
|
|
174
|
-
} else if (name === 'position' && value === 'auto') {
|
|
175
|
-
value = '\u2012';
|
|
176
|
-
}
|
|
177
|
-
value = value?.replace(/px$/, '');
|
|
178
|
-
value = value ? Platform.NumberUtilities.toFixedIfFloating(value) : value;
|
|
179
|
-
// clang-format off
|
|
180
|
-
return html`<div class=${side} jslog=${VisualLogging.value(propertyName).track({
|
|
181
|
-
dblclick: true, keydown: 'Enter|Escape|ArrowUp|ArrowDown|PageUp|PageDown', change: true,
|
|
182
|
-
})}
|
|
183
|
-
@dblclick=${(e: Event) => this.startEditing(e.currentTarget, name, propertyName, style)}
|
|
184
|
-
.innerText=${live(value ?? '')}>
|
|
185
|
-
</div>`;
|
|
186
|
-
// clang-format on
|
|
298
|
+
private getContentAreaWidthPx(style: Map<string, string>): string {
|
|
299
|
+
let width = style.get('width');
|
|
300
|
+
if (!width) {
|
|
301
|
+
return '';
|
|
187
302
|
}
|
|
303
|
+
width = width.replace(/px$/, '');
|
|
304
|
+
const widthValue = Number(width);
|
|
305
|
+
if (!isNaN(widthValue) && style.get('box-sizing') === 'border-box') {
|
|
306
|
+
const borderBox = this.getBox(style, 'border');
|
|
307
|
+
const paddingBox = this.getBox(style, 'padding');
|
|
188
308
|
|
|
189
|
-
|
|
190
|
-
let width = style.get('width');
|
|
191
|
-
if (!width) {
|
|
192
|
-
return '';
|
|
193
|
-
}
|
|
194
|
-
width = width.replace(/px$/, '');
|
|
195
|
-
const widthValue = Number(width);
|
|
196
|
-
if (!isNaN(widthValue) && style.get('box-sizing') === 'border-box') {
|
|
197
|
-
const borderBox = self.getBox(style, 'border');
|
|
198
|
-
const paddingBox = self.getBox(style, 'padding');
|
|
199
|
-
|
|
200
|
-
width = (widthValue - borderBox.left - borderBox.right - paddingBox.left - paddingBox.right).toString();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return Platform.NumberUtilities.toFixedIfFloating(width);
|
|
309
|
+
width = (widthValue - borderBox.left - borderBox.right - paddingBox.left - paddingBox.right).toString();
|
|
204
310
|
}
|
|
205
311
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (!height) {
|
|
209
|
-
return '';
|
|
210
|
-
}
|
|
211
|
-
height = height.replace(/px$/, '');
|
|
212
|
-
const heightValue = Number(height);
|
|
213
|
-
if (!isNaN(heightValue) && style.get('box-sizing') === 'border-box') {
|
|
214
|
-
const borderBox = self.getBox(style, 'border');
|
|
215
|
-
const paddingBox = self.getBox(style, 'padding');
|
|
312
|
+
return Platform.NumberUtilities.toFixedIfFloating(width);
|
|
313
|
+
}
|
|
216
314
|
|
|
217
|
-
|
|
218
|
-
|
|
315
|
+
private getContentAreaHeightPx(style: Map<string, string>): string {
|
|
316
|
+
let height = style.get('height');
|
|
317
|
+
if (!height) {
|
|
318
|
+
return '';
|
|
319
|
+
}
|
|
320
|
+
height = height.replace(/px$/, '');
|
|
321
|
+
const heightValue = Number(height);
|
|
322
|
+
if (!isNaN(heightValue) && style.get('box-sizing') === 'border-box') {
|
|
323
|
+
const borderBox = this.getBox(style, 'border');
|
|
324
|
+
const paddingBox = this.getBox(style, 'padding');
|
|
219
325
|
|
|
220
|
-
|
|
326
|
+
height = (heightValue - borderBox.top - borderBox.bottom - paddingBox.top - paddingBox.bottom).toString();
|
|
221
327
|
}
|
|
222
328
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
'table-cell',
|
|
226
|
-
'table-column',
|
|
227
|
-
'table-column-group',
|
|
228
|
-
'table-footer-group',
|
|
229
|
-
'table-header-group',
|
|
230
|
-
'table-row',
|
|
231
|
-
'table-row-group',
|
|
232
|
-
]);
|
|
233
|
-
|
|
234
|
-
// Display types for which padding is ignored.
|
|
235
|
-
const noPaddingDisplayType = new Set<string>([
|
|
236
|
-
'table-column',
|
|
237
|
-
'table-column-group',
|
|
238
|
-
'table-footer-group',
|
|
239
|
-
'table-header-group',
|
|
240
|
-
'table-row',
|
|
241
|
-
'table-row-group',
|
|
242
|
-
]);
|
|
243
|
-
|
|
244
|
-
// Position types for which top, left, bottom and right are ignored.
|
|
245
|
-
const noPositionType = new Set<string>(['static']);
|
|
246
|
-
|
|
247
|
-
const boxes = ['content', 'padding', 'border', 'margin', 'position'];
|
|
248
|
-
const boxColors = [
|
|
249
|
-
Common.Color.PageHighlight.Content,
|
|
250
|
-
Common.Color.PageHighlight.Padding,
|
|
251
|
-
Common.Color.PageHighlight.Border,
|
|
252
|
-
Common.Color.PageHighlight.Margin,
|
|
253
|
-
Common.Color.Legacy.fromRGBA([0, 0, 0, 0]),
|
|
254
|
-
];
|
|
255
|
-
const boxLabels = ['content', 'padding', 'border', 'margin', 'position'];
|
|
256
|
-
let previousBox: LitTemplate = nothing;
|
|
257
|
-
for (let i = 0; i < boxes.length; ++i) {
|
|
258
|
-
const name = boxes[i];
|
|
259
|
-
const display = style.get('display');
|
|
260
|
-
const position = style.get('position');
|
|
261
|
-
if (!display || !position) {
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
if (name === 'margin' && noMarginDisplayType.has(display)) {
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
if (name === 'padding' && noPaddingDisplayType.has(display)) {
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
if (name === 'position' && noPositionType.has(position)) {
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
329
|
+
return Platform.NumberUtilities.toFixedIfFloating(height);
|
|
330
|
+
}
|
|
273
331
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
${name === 'content' ? html`
|
|
287
|
-
<span jslog=${VisualLogging.value('width').track({
|
|
288
|
-
dblclick: true,
|
|
289
|
-
keydown: 'Enter|Escape|ArrowUp|ArrowDown|PageUp|PageDown',
|
|
290
|
-
change: true,
|
|
291
|
-
})}
|
|
292
|
-
@dblclick=${(e: Event) => this.startEditing(e.currentTarget, 'width', 'width', style)}
|
|
293
|
-
.innerText=${live(getContentAreaWidthPx(style))}>
|
|
294
|
-
</span>
|
|
295
|
-
<span> × </span>
|
|
296
|
-
<span jslog=${VisualLogging.value('height').track({
|
|
297
|
-
dblclick: true,
|
|
298
|
-
keydown: 'Enter|Escape|ArrowUp|ArrowDown|PageUp|PageDown',
|
|
299
|
-
change: true,
|
|
300
|
-
})}
|
|
301
|
-
@dblclick=${(e: Event) => this.startEditing(e.currentTarget, 'height', 'height', style)}
|
|
302
|
-
.innerText=${live(getContentAreaHeightPx(style))}>
|
|
303
|
-
</span>` : html`
|
|
304
|
-
<div class="label">${boxLabels[i]}</div>
|
|
305
|
-
${createBoxPartElement.call(this, style, name, 'top', suffix)}
|
|
306
|
-
<br>
|
|
307
|
-
${createBoxPartElement.call(this, style, name, 'left', suffix)}
|
|
308
|
-
${previousBox}
|
|
309
|
-
${createBoxPartElement.call(this, style, name, 'right', suffix)}
|
|
310
|
-
<br>
|
|
311
|
-
${createBoxPartElement.call(this, style, name, 'bottom', suffix)}`}
|
|
312
|
-
</div>`;
|
|
313
|
-
// clang-format on
|
|
314
|
-
|
|
315
|
-
previousBox = box;
|
|
316
|
-
}
|
|
317
|
-
// clang-format off
|
|
318
|
-
render(html`
|
|
319
|
-
<div class="metrics" @mouseover=${this.highlightDOMNode.bind(this, false, 'all')}
|
|
320
|
-
@mouseleave=${this.highlightDOMNode.bind(this, false, 'all')}>
|
|
321
|
-
${previousBox}
|
|
322
|
-
</div>`, this.contentElement);
|
|
323
|
-
// clang-format on
|
|
324
|
-
this.element.classList.remove('collapsed');
|
|
332
|
+
private updateMetrics(style: Map<string, string>, highlightedMode = 'all'): void {
|
|
333
|
+
this.view(
|
|
334
|
+
{
|
|
335
|
+
style,
|
|
336
|
+
highlightedMode,
|
|
337
|
+
node: this.node(),
|
|
338
|
+
contentWidth: this.getContentAreaWidthPx(style),
|
|
339
|
+
contentHeight: this.getContentAreaHeightPx(style),
|
|
340
|
+
onHighlightNode: this.highlightDOMNode.bind(this),
|
|
341
|
+
onStartEditing: this.startEditing.bind(this),
|
|
342
|
+
},
|
|
343
|
+
undefined, this.contentElement);
|
|
325
344
|
}
|
|
326
345
|
|
|
327
|
-
startEditing(
|
|
328
|
-
if (!(target instanceof Element)) {
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
const targetElement = target as Element;
|
|
346
|
+
startEditing(targetElement: Element, box: string, styleProperty: string, computedStyle: Map<string, string>): void {
|
|
332
347
|
if (UI.UIUtils.isBeingEdited(targetElement)) {
|
|
333
348
|
return;
|
|
334
349
|
}
|