Changeset 273098 in webkit


Ignore:
Timestamp:
Feb 18, 2021 12:58:04 PM (17 months ago)
Author:
Patrick Angle
Message:

Web Inspector: Implement Grid Overlay "Show track sizes" drawing
https://bugs.webkit.org/show_bug.cgi?id=222007

Reviewed by BJ Burg.

Show computed and authored track sizes in the grid overlay. Authored sizes are determined from the original
CSSValue, not from the GridTrackSize as the later loses the exact authored syntax (e.g. 14vw is already
resolved to an absolute pixel value).

When the authored size is in px and is identical to the computed size, the value is only shown once for the
track.

  • inspector/InspectorOverlay.cpp:

(WebCore::InspectorOverlay::drawLayoutLabel):

  • Use the system-ui font for layout labels and reduce the font size to improve information density.
  • Drive-by further adjustment to label text positioning to be more accurate.

(WebCore::authoredGridTrackSizes):

  • Get the authored sizes for each track in a sizing direction (row-wise or column-wise).

(WebCore::InspectorOverlay::drawGridOverlay):

  • Draw labels for track sizes with their computed and, if different from the computed, authored values.
  • Drive-by to have area name label backgrounds share a common constant color with track size label backgrounds.
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r273094 r273098  
     12021-02-18  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Implement Grid Overlay "Show track sizes" drawing
     4        https://bugs.webkit.org/show_bug.cgi?id=222007
     5
     6        Reviewed by BJ Burg.
     7
     8        Show computed and authored track sizes in the grid overlay. Authored sizes are determined from the original
     9        `CSSValue`, not from the GridTrackSize as the later loses the exact authored syntax (e.g. `14vw` is already
     10        resolved to an absolute pixel value).
     11
     12        When the authored size is in `px` and is identical to the computed size, the value is only shown once for the
     13        track.
     14
     15        * inspector/InspectorOverlay.cpp:
     16        (WebCore::InspectorOverlay::drawLayoutLabel):
     17        - Use the system-ui font for layout labels and reduce the font size to improve information density.
     18        - Drive-by further adjustment to label text positioning to be more accurate.
     19        (WebCore::authoredGridTrackSizes):
     20        - Get the authored sizes for each track in a sizing direction (row-wise or column-wise).
     21        (WebCore::InspectorOverlay::drawGridOverlay):
     22        - Draw labels for track sizes with their computed and, if different from the computed, authored values.
     23        - Drive-by to have area name label backgrounds share a common constant color with track size label backgrounds.
     24
    1252021-02-18  Commit Queue  <commit-queue@webkit.org>
    226
  • trunk/Source/WebCore/inspector/InspectorOverlay.cpp

    r273037 r273098  
    3333#include "AXObjectCache.h"
    3434#include "AccessibilityObject.h"
     35#include "CSSGridAutoRepeatValue.h"
     36#include "CSSGridIntegerRepeatValue.h"
     37#include "CSSGridLineNamesValue.h"
    3538#include "DOMCSSNamespace.h"
    3639#include "DOMTokenList.h"
     
    6164#include "RenderObject.h"
    6265#include "Settings.h"
     66#include "StyleResolver.h"
    6367#include <wtf/MathExtras.h>
    6468#include <wtf/text/StringBuilder.h>
     
    7983static constexpr float rulerSubStepLength = 5;
    8084
     85static constexpr UChar bullet = 0x2022;
    8186static constexpr UChar ellipsis = 0x2026;
    8287static constexpr UChar multiplicationSign = 0x00D7;
     88static constexpr UChar thinSpace = 0x2009;
    8389
    8490static void truncateWithEllipsis(String& string, size_t length)
     
    11821188   
    11831189    FontCascadeDescription fontDescription;
    1184     fontDescription.setFamilies({ m_page.settings().fixedFontFamily() });
    1185     fontDescription.setComputedSize(13);
     1190    fontDescription.setFamilies({ "system-ui" });
     1191    fontDescription.setWeight(FontSelectionValue(500));
     1192    fontDescription.setComputedSize(12);
    11861193
    11871194    FontCascade font(WTFMove(fontDescription), 0, 0);
     
    12151222        labelPath.addLineTo({ (textWidth / 2) + padding, -arrowSize });
    12161223        labelPath.addLineTo({ (textWidth / 2) + padding, -textHeight - (padding * 2) - arrowSize });
    1217         textPosition = FloatPoint(-(textWidth / 2), -(textHeight / 2) + textDescent - arrowSize - padding);
     1224        textPosition = FloatPoint(-(textWidth / 2), -textDescent - arrowSize - padding);
    12181225        break;
    12191226    case InspectorOverlay::LabelArrowDirection::Up:
     
    12251232        labelPath.addLineTo({ (textWidth / 2) + padding, arrowSize });
    12261233        labelPath.addLineTo({ (textWidth / 2) + padding, textHeight + (padding * 2) + arrowSize });
    1227         textPosition = FloatPoint(-(textWidth / 2), (textHeight / 2) + textDescent + arrowSize + padding);
     1234        textPosition = FloatPoint(-(textWidth / 2), textHeight - textDescent + arrowSize + padding);
    12281235        break;
    12291236    case InspectorOverlay::LabelArrowDirection::Right:
     
    12651272}
    12661273
     1274static Vector<String> authoredGridTrackSizes(Node* node, GridTrackSizingDirection direction, unsigned expectedTrackCount)
     1275{
     1276    if (!is<Element>(node))
     1277        return { };
     1278   
     1279    auto element = downcast<Element>(node);
     1280    auto styleRules = element->styleResolver().styleRulesForElement(element);
     1281    styleRules.reverse();
     1282    RefPtr<CSSValue> cssValue;
     1283    for (auto styleRule : styleRules) {
     1284        ASSERT(styleRule);
     1285        if (!styleRule)
     1286            continue;
     1287        cssValue = styleRule->properties().getPropertyCSSValue(direction == GridTrackSizingDirection::ForColumns ? CSSPropertyID::CSSPropertyGridTemplateColumns : CSSPropertyID::CSSPropertyGridTemplateRows);
     1288        if (cssValue)
     1289            break;
     1290    }
     1291   
     1292    if (!cssValue || !is<CSSValueList>(cssValue))
     1293        return { };
     1294   
     1295    Vector<String> trackSizes;
     1296   
     1297    auto handleValueIgnoringLineNames = [&](const CSSValue& currentValue) {
     1298        if (!is<CSSGridLineNamesValue>(currentValue))
     1299            trackSizes.append(currentValue.cssText());
     1300    };
     1301   
     1302    for (auto& currentValue : downcast<CSSValueList>(*cssValue)) {
     1303        if (is<CSSGridAutoRepeatValue>(currentValue)) {
     1304            // Auto-repeated values will be looped through until no more values were used in layout based on the expected track count.
     1305            while (trackSizes.size() < expectedTrackCount) {
     1306                for (auto& autoRepeatValue : downcast<CSSValueList>(currentValue.get())) {
     1307                    handleValueIgnoringLineNames(autoRepeatValue);
     1308                    if (trackSizes.size() >= expectedTrackCount)
     1309                        break;
     1310                }
     1311            }
     1312            break;
     1313        }
     1314       
     1315        if (is<CSSGridIntegerRepeatValue>(currentValue)) {
     1316            size_t repetitions = downcast<CSSGridIntegerRepeatValue>(currentValue.get()).repetitions();
     1317            for (size_t i = 0; i < repetitions; ++i) {
     1318                for (auto& integerRepeatValue : downcast<CSSValueList>(currentValue.get()))
     1319                    handleValueIgnoringLineNames(integerRepeatValue);
     1320            }
     1321            continue;
     1322        }
     1323       
     1324        handleValueIgnoringLineNames(currentValue);
     1325    }
     1326   
     1327    // Remaining tracks will be `auto`.
     1328    while (trackSizes.size() < expectedTrackCount)
     1329        trackSizes.append("auto"_s);
     1330   
     1331    return trackSizes;
     1332}
     1333
    12671334void InspectorOverlay::drawGridOverlay(GraphicsContext& context, const InspectorOverlay::Grid& gridOverlay)
    12681335{
     
    12831350        return;
    12841351    }
     1352   
     1353    constexpr auto translucentLabelBackgroundColor = Color::white.colorWithAlphaByte(153);
    12851354
    12861355    auto* renderGrid = downcast<RenderGrid>(renderer);
     
    13261395    // Draw columns and rows.
    13271396    auto columnWidths = renderGrid->trackSizesForComputedStyle(GridTrackSizingDirection::ForColumns);
     1397    auto authoredTrackColumnSizes = authoredGridTrackSizes(node, GridTrackSizingDirection::ForColumns, columnWidths.size());
    13281398    float previousColumnX = 0;
    13291399    for (unsigned i = 0; i < columnPositions.size(); ++i) {
     
    13461416            columnPaths.addLineTo({ position + width, scrollY + viewportSize.height() });
    13471417            previousColumnX = position + width;
     1418           
     1419            if (gridOverlay.config.showTrackSizes) {
     1420                auto trackSizeLabel = String::number(roundf(width));
     1421                trackSizeLabel.append("px"_s);
     1422               
     1423                String authoredTrackSize;
     1424                if (i < authoredTrackColumnSizes.size()) {
     1425                    auto authoredTrackSize = authoredTrackColumnSizes[i];
     1426                    if (authoredTrackSize.length() && authoredTrackSize != trackSizeLabel) {
     1427                        trackSizeLabel.append(thinSpace);
     1428                        trackSizeLabel.append(bullet);
     1429                        trackSizeLabel.append(thinSpace);
     1430                        trackSizeLabel.append(authoredTrackSize);
     1431                    }
     1432                }
     1433               
     1434                drawLayoutLabel(context, trackSizeLabel, FloatPoint(position + (width / 2), gridBoundingBox.y()), LabelArrowDirection::Up, translucentLabelBackgroundColor);
     1435            }
    13481436        } else
    13491437            previousColumnX = position;
     
    13591447
    13601448    auto rowHeights = renderGrid->trackSizesForComputedStyle(GridTrackSizingDirection::ForRows);
     1449    auto authoredTrackRowSizes = authoredGridTrackSizes(node, GridTrackSizingDirection::ForRows, rowHeights.size());
    13611450    float previousRowY = 0;
    13621451    for (unsigned i = 0; i < rowPositions.size(); ++i) {
     
    13781467            rowPaths.addLineTo({ scrollX + viewportSize.width(), position + height });
    13791468            previousRowY = position + height;
     1469           
     1470            if (gridOverlay.config.showTrackSizes) {
     1471                auto trackSizeLabel = String::number(roundf(height));
     1472                trackSizeLabel.append("px"_s);
     1473               
     1474                String authoredTrackSize;
     1475                if (i < authoredTrackRowSizes.size()) {
     1476                    auto authoredTrackSize = authoredTrackRowSizes[i];
     1477                    if (authoredTrackSize.length() && authoredTrackSize != trackSizeLabel) {
     1478                        trackSizeLabel.append(thinSpace);
     1479                        trackSizeLabel.append(bullet);
     1480                        trackSizeLabel.append(thinSpace);
     1481                        trackSizeLabel.append(authoredTrackSize);
     1482                    }
     1483                }
     1484               
     1485                drawLayoutLabel(context, trackSizeLabel, FloatPoint(gridBoundingBox.x(), position + (height / 2)), LabelArrowDirection::Left, translucentLabelBackgroundColor);
     1486            }
    13801487        } else
    13811488            previousRowY = position;
     
    14091516           
    14101517            context.strokeRect(areaRect, 3);
    1411             drawLayoutLabel(context, name, areaRect.location(), LabelArrowDirection::None, Color::white.colorWithAlphaByte(153), areaRect.width());
     1518            drawLayoutLabel(context, name, areaRect.location(), LabelArrowDirection::None, translucentLabelBackgroundColor, areaRect.width());
    14121519        }
    14131520    }
Note: See TracChangeset for help on using the changeset viewer.