Changeset 272948 in webkit


Ignore:
Timestamp:
Feb 16, 2021 5:16:15 PM (17 months ago)
Author:
Patrick Angle
Message:

Web Inspector: Implement Grid Overlay "Show area names" drawing
https://bugs.webkit.org/show_bug.cgi?id=221979

Reviewed by Devin Rousso.

Added support for showing grid area names and bounds in the grid overlay.

  • inspector/InspectorOverlay.cpp:

(WebCore::InspectorOverlay::drawLayoutLabel):

  • Added support for arrow-less layout labels.
  • Added support for providing a background color to allow area names to have a semi-translucent label background.
  • Added support for clipping labels to a target width.

(WebCore::InspectorOverlay::drawGridOverlay):

  • Added support for stroking grid areas and showing their names in a label.
  • inspector/InspectorOverlay.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r272936 r272948  
     12021-02-16  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Implement Grid Overlay "Show area names" drawing
     4        https://bugs.webkit.org/show_bug.cgi?id=221979
     5
     6        Reviewed by Devin Rousso.
     7
     8        Added support for showing grid area names and bounds in the grid overlay.
     9
     10        * inspector/InspectorOverlay.cpp:
     11        (WebCore::InspectorOverlay::drawLayoutLabel):
     12        - Added support for arrow-less layout labels.
     13        - Added support for providing a background color to allow area names to have a semi-translucent label background.
     14        - Added support for clipping labels to a target width.
     15        (WebCore::InspectorOverlay::drawGridOverlay):
     16        - Added support for stroking grid areas and showing their names in a label.
     17        * inspector/InspectorOverlay.h:
     18
    1192021-02-16  Chris Dumez  <cdumez@apple.com>
    220
  • trunk/Source/WebCore/inspector/InspectorOverlay.cpp

    r272918 r272948  
    4444#include "FrameView.h"
    4545#include "GraphicsContext.h"
     46#include "GridArea.h"
    4647#include "GridPositionsResolver.h"
    4748#include "InspectorClient.h"
     
    5152#include "Node.h"
    5253#include "NodeList.h"
     54#include "NodeRenderStyle.h"
    5355#include "Page.h"
    5456#include "PseudoElement.h"
     
    11731175}
    11741176
    1175 void InspectorOverlay::drawLayoutLabel(GraphicsContext& context, String label, FloatPoint point, InspectorOverlay::LabelArrowDirection direction)
     1177void InspectorOverlay::drawLayoutLabel(GraphicsContext& context, String label, FloatPoint point, InspectorOverlay::LabelArrowDirection direction, Color backgroundColor, float maximumWidth)
    11761178{
    11771179    GraphicsContextStateSaver saver(context);
     
    11851187    FontCascade font(WTFMove(fontDescription), 0, 0);
    11861188    font.update(nullptr);
    1187    
    1188     float textWidth = font.width(TextRun(label));
     1189
     1190    constexpr auto padding = 4;
     1191    constexpr auto arrowSize = 4;
    11891192    float textHeight = font.fontMetrics().floatHeight();
    11901193    float textDescent = font.fontMetrics().floatDescent();
    1191     constexpr auto padding = 4;
    1192     constexpr auto arrowSize = 4;
     1194   
     1195    float textWidth = font.width(TextRun(label));
     1196    if (maximumWidth && textWidth + (padding * 2) > maximumWidth) {
     1197        label.append("..."_s);
     1198        while (textWidth + (padding * 2) > maximumWidth && label.length() >= 4) {
     1199            // Remove the fourth from last character (the character before the ellipsis) and remeasure.
     1200            label.remove(label.length() - 4);
     1201            textWidth = font.width(TextRun(label));
     1202        }
     1203    }
    11931204   
    11941205    Path labelPath;
     
    12361247        textPosition = FloatPoint(arrowSize + padding, (textHeight / 2) - textDescent);
    12371248        break;
     1249    case InspectorOverlay::LabelArrowDirection::None:
     1250        labelPath.addLineTo({ 0, textHeight + (padding * 2) });
     1251        labelPath.addLineTo({ textWidth + (padding * 2), textHeight + (padding * 2) });
     1252        labelPath.addLineTo({ textWidth + (padding * 2), 0 });
     1253        textPosition = FloatPoint(padding, padding + textHeight - textDescent);
     1254        break;
    12381255    }
    12391256   
    12401257    labelPath.closeSubpath();
    12411258   
    1242     context.setFillColor(Color::white);
     1259    context.setFillColor(backgroundColor);
    12431260    context.fillPath(labelPath);
    12441261    context.strokePath(labelPath);
     
    13721389        }
    13731390    }
     1391   
     1392    if (gridOverlay.config.showAreaNames) {
     1393        for (auto& [name, area] : node->renderStyle()->namedGridArea()) {
     1394            // Named grid areas will always be rectangular per the CSS Grid specification.
     1395            auto columnStartLine = area.columns.startLine();
     1396            auto columnEndLine = area.columns.endLine();
     1397            auto rowStartLine = area.rows.startLine();
     1398            auto rowEndLine = area.rows.endLine();
     1399           
     1400            FloatRect areaRect = {
     1401                columnPositions[columnStartLine] + gridBoundingBox.x(),
     1402                rowPositions[rowStartLine] + gridBoundingBox.y(),
     1403                columnPositions[columnEndLine - 1] + columnWidths[columnEndLine - 1] - columnPositions[columnStartLine],
     1404                rowPositions[rowEndLine - 1] + rowHeights[rowEndLine - 1] - rowPositions[rowStartLine],
     1405            };
     1406           
     1407            context.strokeRect(areaRect, 3);
     1408            drawLayoutLabel(context, name, areaRect.location(), LabelArrowDirection::None, Color::white.colorWithAlphaByte(153), areaRect.width());
     1409        }
     1410    }
    13741411}
    13751412
  • trunk/Source/WebCore/inspector/InspectorOverlay.h

    r272918 r272948  
    169169   
    170170    enum class LabelArrowDirection {
     171        None,
    171172        Down,
    172173        Up,
     
    184185   
    185186    void drawLayoutHatching(GraphicsContext&, FloatRect, IntPoint);
    186     void drawLayoutLabel(GraphicsContext&, String, FloatPoint, LabelArrowDirection);
     187    void drawLayoutLabel(GraphicsContext&, String, FloatPoint, LabelArrowDirection, Color backgroundColor = Color::white, float maximumWidth = 0);
    187188
    188189    void drawGridOverlay(GraphicsContext&, const InspectorOverlay::Grid&);
Note: See TracChangeset for help on using the changeset viewer.