Changeset 273155 in webkit


Ignore:
Timestamp:
Feb 19, 2021 12:01:31 PM (17 months ago)
Author:
Patrick Angle
Message:

Web Inspector: Implement Grid Overlay "Show line names" drawing
https://bugs.webkit.org/show_bug.cgi?id=222006
<rdar://problem/74409722>

Reviewed by BJ Burg.

Add support for showing line names to the grid overlay, including explicit, auto-repeated, and implicit names.

  • inspector/InspectorOverlay.cpp:

(WebCore::gridLineNames):

  • Gather the grid line names for a grid from the multiple possible sources.

(WebCore::InspectorOverlay::drawGridOverlay):

  • Support showing grid line name labels.
  • Refactored line number label drawing to share a common structure with line name label drawing.
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r273143 r273155  
     12021-02-19  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Implement Grid Overlay "Show line names" drawing
     4        https://bugs.webkit.org/show_bug.cgi?id=222006
     5        <rdar://problem/74409722>
     6
     7        Reviewed by BJ Burg.
     8
     9        Add support for showing line names to the grid overlay, including explicit, auto-repeated, and implicit names.
     10
     11        * inspector/InspectorOverlay.cpp:
     12        (WebCore::gridLineNames):
     13        - Gather the grid line names for a grid from the multiple possible sources.
     14        (WebCore::InspectorOverlay::drawGridOverlay):
     15        - Support showing grid line name labels.
     16        - Refactored line number label drawing to share a common structure with line name label drawing.
     17
    1182021-02-19  Devin Rousso  <drousso@apple.com>
    219
  • trunk/Source/WebCore/inspector/InspectorOverlay.cpp

    r273098 r273155  
    6464#include "RenderObject.h"
    6565#include "Settings.h"
     66#include "StyleGridData.h"
    6667#include "StyleResolver.h"
    6768#include <wtf/MathExtras.h>
     
    13321333}
    13331334
     1335static OrderedNamedGridLinesMap gridLineNames(const RenderStyle* renderStyle, GridTrackSizingDirection direction, unsigned expectedLineCount)
     1336{
     1337    if (!renderStyle)
     1338        return { };
     1339   
     1340    OrderedNamedGridLinesMap combinedGridLineNames;
     1341    auto appendLineNames = [&](unsigned index, Vector<String> newNames) {
     1342        if (combinedGridLineNames.contains(index)) {
     1343            auto names = combinedGridLineNames.take(index);
     1344            names.appendVector(newNames);
     1345            combinedGridLineNames.add(index, names);
     1346        } else
     1347            combinedGridLineNames.add(index, newNames);
     1348    };
     1349   
     1350    auto orderedGridLineNames = direction == GridTrackSizingDirection::ForColumns ? renderStyle->orderedNamedGridColumnLines() : renderStyle->orderedNamedGridRowLines();
     1351    for (auto& [i, names] : orderedGridLineNames)
     1352        appendLineNames(i, names);
     1353   
     1354    auto autoRepeatOrderedGridLineNames = direction == GridTrackSizingDirection::ForColumns ? renderStyle->autoRepeatOrderedNamedGridColumnLines() : renderStyle->autoRepeatOrderedNamedGridRowLines();
     1355    auto autoRepeatInsertionPoint = direction == GridTrackSizingDirection::ForColumns ? renderStyle->gridAutoRepeatColumnsInsertionPoint() : renderStyle->gridAutoRepeatRowsInsertionPoint();
     1356    unsigned autoRepeatIndex = 0;
     1357    while (autoRepeatOrderedGridLineNames.size() && autoRepeatIndex < expectedLineCount - autoRepeatInsertionPoint) {
     1358        auto names = autoRepeatOrderedGridLineNames.get(autoRepeatIndex % autoRepeatOrderedGridLineNames.size());
     1359        auto lineIndex = autoRepeatIndex + autoRepeatInsertionPoint;
     1360        appendLineNames(lineIndex, names);
     1361        ++autoRepeatIndex;
     1362    }
     1363
     1364    auto implicitGridLineNames = direction == GridTrackSizingDirection::ForColumns ? renderStyle->implicitNamedGridColumnLines() : renderStyle->implicitNamedGridRowLines();
     1365    for (auto& [name, indexes] : implicitGridLineNames) {
     1366        for (auto i : indexes)
     1367            appendLineNames(i, {name});
     1368    }
     1369   
     1370    return combinedGridLineNames;
     1371}
     1372
    13341373void InspectorOverlay::drawGridOverlay(GraphicsContext& context, const InspectorOverlay::Grid& gridOverlay)
    13351374{
     
    13951434    // Draw columns and rows.
    13961435    auto columnWidths = renderGrid->trackSizesForComputedStyle(GridTrackSizingDirection::ForColumns);
     1436    auto columnLineNames = gridLineNames(node->renderStyle(), GridTrackSizingDirection::ForColumns, columnPositions.size());
    13971437    auto authoredTrackColumnSizes = authoredGridTrackSizes(node, GridTrackSizingDirection::ForColumns, columnWidths.size());
    13981438    float previousColumnX = 0;
     
    14391479        context.strokePath(columnPaths);
    14401480       
     1481        Vector<String> lineLabelParts;
    14411482        if (gridOverlay.config.showLineNumbers) {
     1483            lineLabelParts.append(String::number(i + 1));
     1484            lineLabelParts.append(String::number(-static_cast<int>(columnPositions.size() - i)));
     1485        }
     1486        if (gridOverlay.config.showLineNames && columnLineNames.contains(i))
     1487            lineLabelParts.appendVector(columnLineNames.get(i));
     1488        if (lineLabelParts.size()) {
     1489            auto lineLabel = lineLabelParts[0];
     1490            for (size_t i = 1; i < lineLabelParts.size(); ++i) {
     1491                lineLabel.append(thinSpace);
     1492                lineLabel.append(bullet);
     1493                lineLabel.append(thinSpace);
     1494                lineLabel.append(lineLabelParts[i]);
     1495            }
    14421496            // FIXME: <webkit.org/b/221972> Layout labels can be drawn outside the viewport, and a best effort should be made to keep them in the viewport while the grid is in the viewport.
    1443             drawLayoutLabel(context, String::number(i + 1), FloatPoint(labelX, gridBoundingBox.y()), LabelArrowDirection::Down);
    1444             drawLayoutLabel(context, String::number(-static_cast<int>(columnPositions.size() - i)), FloatPoint(labelX, gridBoundingBox.y() + gridBoundingBox.height()), LabelArrowDirection::Up);
     1497            drawLayoutLabel(context, lineLabel, FloatPoint(labelX, gridBoundingBox.y()), LabelArrowDirection::Down);
    14451498        }
    14461499    }
    14471500
    14481501    auto rowHeights = renderGrid->trackSizesForComputedStyle(GridTrackSizingDirection::ForRows);
     1502    auto rowLineNames = gridLineNames(node->renderStyle(), GridTrackSizingDirection::ForRows, rowPositions.size());
    14491503    auto authoredTrackRowSizes = authoredGridTrackSizes(node, GridTrackSizingDirection::ForRows, rowHeights.size());
    14501504    float previousRowY = 0;
     
    14901544        context.strokePath(rowPaths);
    14911545       
     1546        Vector<String> lineLabelParts;
    14921547        if (gridOverlay.config.showLineNumbers) {
     1548            lineLabelParts.append(String::number(i + 1));
     1549            lineLabelParts.append(String::number(-static_cast<int>(rowPositions.size() - i)));
     1550        }
     1551        if (gridOverlay.config.showLineNames && rowLineNames.contains(i))
     1552            lineLabelParts.appendVector(rowLineNames.get(i));
     1553        if (lineLabelParts.size()) {
     1554            auto lineLabel = lineLabelParts[0];
     1555            for (size_t i = 1; i < lineLabelParts.size(); ++i) {
     1556                lineLabel.append(thinSpace);
     1557                lineLabel.append(bullet);
     1558                lineLabel.append(thinSpace);
     1559                lineLabel.append(lineLabelParts[i]);
     1560            }
    14931561            // FIXME: <webkit.org/b/221972> Layout labels can be drawn outside the viewport, and a best effort should be made to keep them in the viewport while the grid is in the viewport.
    1494             drawLayoutLabel(context, String::number(i + 1), FloatPoint(gridBoundingBox.x(), labelY), LabelArrowDirection::Right);
    1495             drawLayoutLabel(context, String::number(-static_cast<int>(rowPositions.size() - i)), FloatPoint(gridBoundingBox.x() + gridBoundingBox.width(), labelY), LabelArrowDirection::Left);
     1562            drawLayoutLabel(context, lineLabel, FloatPoint(gridBoundingBox.x(), labelY), LabelArrowDirection::Right);
    14961563        }
    14971564    }
Note: See TracChangeset for help on using the changeset viewer.