Bug 221370

Summary: Web Inspector: Elements: show badges for CSS Grid container elements
Product: WebKit Reporter: Nikita Vasilyev <nvasilyev>
Component: Web InspectorAssignee: Nikita Vasilyev <nvasilyev>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, ews-watchlist, hi, inspector-bugzilla-changes, nvasilyev, rcaliman
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 221923    
Attachments:
Description Flags
WIP
nvasilyev: review-, nvasilyev: commit-queue-
Patch
ews-feeder: commit-queue-
[Video] With patch applied
none
[Image] Selected element, gray badge
none
Patch
ews-feeder: commit-queue-
[Video] With patch applied none

Description Nikita Vasilyev 2021-02-03 18:10:52 PST
Elements with `display: grid` or `display: inline-grid` should have a "grid" badge:

    <div class="wrapper"> [grid]

Clicking [grid] should toggle the grid overlay.

<rdar://problem/67881277>
Comment 1 Nikita Vasilyev 2021-02-10 22:38:01 PST
Created attachment 419947 [details]
WIP
Comment 2 Nikita Vasilyev 2021-02-16 15:33:55 PST
Created attachment 420549 [details]
Patch
Comment 3 Nikita Vasilyev 2021-02-16 15:35:03 PST
Created attachment 420550 [details]
[Video] With patch applied
Comment 4 Devin Rousso 2021-02-16 15:57:59 PST
Comment on attachment 420549 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=420549&action=review

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:26
> +.tree-outline.dom .badge-css-grid {

I think this should be more specific like `.tree-outline.dom li > .badge-css-grid` so that there's less of a chance of a selector clash.

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:36
> +    margin-left: 3px;

Is the DOM tree always LTR?  If not, I think this should be `margin-inline-start`.

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:42
> +    color: white;

dark mode?

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:48
> +    background-color: transparent;
> +    border-color: transparent;

Why are we removing the border and background when the element is selected?  This looks really weird IMO (especially when unfocused, as it's like the badge disappears and there's this random text left there).

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:53
> +    color: white;

ditto (:+42)

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js:450
> +        if (this.representedObject.layoutContextType === WI.DOMNode.LayoutContextType.Grid) {
> +            WI.overlayManager.addEventListener(WI.OverlayManager.Event.GridOverlayShown, this._updateGridBadgeStatus, this);
> +            WI.overlayManager.addEventListener(WI.OverlayManager.Event.GridOverlayHidden, this._updateGridBadgeStatus, this);
> +        }

You probably need to add/remove these event listeners inside `_handleLayoutContextTypeChanged` in case a node that initially wasn't a grid context later becomes one.

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js:2015
> +        if (!WI.settings.experimentalEnableLayoutPanel.value)

this should use a different setting (or this setting should be renamed to be more generic) as it has nothing to do with the Layout panel

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js:2047
> +        WI.overlayManager.toggleGridOverlay(this.representedObject);

IMO we should maintain some state on `WI.DOMNode` that indicates what overlays are currently shown and use that to determine whether to `showGridOverlay` or `hideGridOverlay`.  `toggle*` functions are not great IMO because it's very easy for them to get out of sync.
Comment 5 Nikita Vasilyev 2021-02-17 12:27:53 PST
Comment on attachment 420549 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=420549&action=review

>> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:36
>> +    margin-left: 3px;
> 
> Is the DOM tree always LTR?  If not, I think this should be `margin-inline-start`.

It is always LTR.

>> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:42
>> +    color: white;
> 
> dark mode?

I attached a video. It's white text on blue background on both light and dark modes.

>> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:48
>> +    border-color: transparent;
> 
> Why are we removing the border and background when the element is selected?  This looks really weird IMO (especially when unfocused, as it's like the badge disappears and there's this random text left there).

I agree this can be improved. I'll reiterate on this.

>> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js:450
>> +        }
> 
> You probably need to add/remove these event listeners inside `_handleLayoutContextTypeChanged` in case a node that initially wasn't a grid context later becomes one.

Oh, good catch.

>> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js:2047
>> +        WI.overlayManager.toggleGridOverlay(this.representedObject);
> 
> IMO we should maintain some state on `WI.DOMNode` that indicates what overlays are currently shown and use that to determine whether to `showGridOverlay` or `hideGridOverlay`.  `toggle*` functions are not great IMO because it's very easy for them to get out of sync.

WI.OverlayManager seems more appropriate for this. It already has ` _gridOverlayForNodeMap`. I don't see the case when it gets out of sync but wouldn't with the state being on `WI.DOMNode`.
Comment 6 Nikita Vasilyev 2021-02-17 17:02:29 PST
Comment on attachment 420549 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=420549&action=review

>> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:26
>> +.tree-outline.dom .badge-css-grid {
> 
> I think this should be more specific like `.tree-outline.dom li > .badge-css-grid` so that there's less of a chance of a selector clash.

`.tree-outline.dom li > .badge-css-grid` won't work — it would have to be `.tree-outline.dom li > span > .badge-css-grid`.

I'm not a fan of overcomplicating selectors. It would agree with you if one badge could be inside of another. It isn't the case here.
Comment 7 Nikita Vasilyev 2021-02-17 17:14:13 PST
Created attachment 420763 [details]
[Image] Selected element, gray badge

View in context: https://bugs.webkit.org/attachment.cgi?id=420549&action=review

>>> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css:48
>>> +    border-color: transparent;
>> 
>> Why are we removing the border and background when the element is selected?  This looks really weird IMO (especially when unfocused, as it's like the badge disappears and there's this random text left there).
> 
> I agree this can be improved. I'll reiterate on this.

In my very first iteration, non-activated badges looked the same on selected and non-selected elements. Is that what you're suggesting? It looks a bit foreign on macOS.
Comment 8 Nikita Vasilyev 2021-02-17 17:42:02 PST
Created attachment 420767 [details]
Patch
Comment 9 Nikita Vasilyev 2021-02-17 17:45:23 PST
Created attachment 420768 [details]
[Video] With patch applied

I added borders for badges when the element is selected.

Note that badges may end up looking different after Bug 221923: Web Inspector: Display color swatch inside of "grid" element badge.
Comment 10 BJ Burg 2021-02-18 11:25:33 PST
Comment on attachment 420767 [details]
Patch

r=me.

The code changes look good to me. At this point it's tweaking color styles. As we discussed, the  gray on gray on gray scheme for inactive badge in an inactive window has low contrast and doesn't look like a button. To be consistent with our other button UI (especially scope bar), the background color shouldn't change when the DOMTreeElement selection color goes from blue to gray upon losing keyboard focus or window focus.

I'm open to considering a wholesale change to dim our custom buttons when losing window focus. Even if it's a good idea, it should not be considered as part of this button patch.
Comment 11 Nikita Vasilyev 2021-02-18 11:37:34 PST
Comment on attachment 420767 [details]
Patch

I'll iterate on the colors in 'Bug 221923: Web Inspector: Display color swatch inside of "grid" element badge' or even before that.
Comment 12 EWS 2021-02-18 12:51:57 PST
Committed r273097: <https://commits.webkit.org/r273097>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 420767 [details].