Changeset 273164 in webkit


Ignore:
Timestamp:
Feb 19, 2021 1:35:05 PM (3 years ago)
Author:
Nikita Vasilyev
Message:

Web Inspector: CSS Grid Inspector: use a color palette for default grid overlay colors
https://bugs.webkit.org/show_bug.cgi?id=222161

Reviewed by Devin Rousso.

Define a 5-color palette.

  • UserInterface/Controllers/OverlayManager.js:

(WI.OverlayManager):
(WI.OverlayManager.prototype.showGridOverlay):
(WI.OverlayManager.prototype.colorForNode):
(WI.OverlayManager.prototype._handleMainResourceDidChange):

  • UserInterface/Views/CSSGridSection.js:

(WI.CSSGridSection.prototype.layout):

Location:
trunk/Source/WebInspectorUI
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r273148 r273164  
     12021-02-19  Nikita Vasilyev  <nvasilyev@apple.com>
     2
     3        Web Inspector: CSS Grid Inspector: use a color palette for default grid overlay colors
     4        https://bugs.webkit.org/show_bug.cgi?id=222161
     5
     6        Reviewed by Devin Rousso.
     7
     8        Define a 5-color palette.
     9
     10        * UserInterface/Controllers/OverlayManager.js:
     11        (WI.OverlayManager):
     12        (WI.OverlayManager.prototype.showGridOverlay):
     13        (WI.OverlayManager.prototype.colorForNode):
     14        (WI.OverlayManager.prototype._handleMainResourceDidChange):
     15        * UserInterface/Views/CSSGridSection.js:
     16        (WI.CSSGridSection.prototype.layout):
     17
    1182021-02-19  Razvan Caliman  <rcaliman@apple.com>
    219
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/OverlayManager.js

    r273097 r273164  
    3232        this._gridOverlayForNodeMap = new Map;
    3333
     34        // Can't reuse `this._gridOverlayForNodeMap` because nodes are removed from it when overlay isn't visible.
     35        this._colorForNodeMap = new WeakMap;
     36        this._nextDOMNodeColorIndex = 0;
     37
    3438        WI.settings.gridOverlayShowExtendedGridLines.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this);
    3539        WI.settings.gridOverlayShowLineNames.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this);
     
    3741        WI.settings.gridOverlayShowTrackSizes.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this);
    3842        WI.settings.gridOverlayShowAreaNames.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this);
     43        WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._handleMainResourceDidChange, this);
    3944    }
    4045
     
    5661        console.assert(domNode.layoutContextType === WI.DOMNode.LayoutContextType.Grid, domNode.layoutContextType);
    5762
    58         color ||= WI.Color.fromString("magenta"); // fallback color
    59 
     63        color ||= this.colorForNode(domNode);
    6064        let target = WI.assumingMainTarget();
    6165        let commandArguments = {
     
    7276        let overlay = {domNode, ...commandArguments};
    7377        this._gridOverlayForNodeMap.set(domNode, overlay);
     78        this._colorForNodeMap.set(domNode, color);
    7479
    7580        domNode.addEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this);
     
    109114    }
    110115
     116    colorForNode(domNode)
     117    {
     118        let color = this._colorForNodeMap.get(domNode);
     119        if (color)
     120            return color;
     121
     122        const hslColors = [
     123            [329, 91, 70],
     124            [207, 96, 69],
     125            [92, 90, 64],
     126            [291, 73, 68],
     127            [40, 97, 57],
     128        ];
     129
     130        color = new WI.Color(WI.Color.Format.HSL, hslColors[this._nextDOMNodeColorIndex]);
     131        this._colorForNodeMap.set(domNode, color);
     132        this._nextDOMNodeColorIndex = (this._nextDOMNodeColorIndex + 1) % hslColors.length;
     133
     134        return color;
     135    }
     136
    111137    // Private
    112138
     
    130156        }
    131157    }
     158
     159    _handleMainResourceDidChange(event)
     160    {
     161        // Consider the following scenario:
     162        // 1. Click on the badge of an element with `display: grid`. The 1st overlay color is used.
     163        // 2. Reload the webpage.
     164        // 3. Click on the badge of the same element.
     165        //
     166        // We should see the same 1st default overlay color. If we don't reset _nextDOMNodeColorIndex,
     167        // the 2nd default color would be used instead.
     168        //
     169        // `domNode.id` is different for the same DOM element after page reload.
     170        this._nextDOMNodeColorIndex = 0;
     171    }
    132172};
    133173
  • trunk/Source/WebInspectorUI/UserInterface/Views/CSSGridSection.js

    r273148 r273164  
    113113            });
    114114
    115             let swatch = new WI.InlineSwatch(WI.InlineSwatch.Type.Color, WI.Color.fromString("magenta"));
     115            let gridColor = WI.overlayManager.colorForNode(domNode);
     116            let swatch = new WI.InlineSwatch(WI.InlineSwatch.Type.Color, gridColor);
    116117            itemContainerElement.append(swatch.element);
    117118
Note: See TracChangeset for help on using the changeset viewer.