Changeset 272948 in webkit
- Timestamp:
- Feb 16, 2021 5:16:15 PM (17 months ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
inspector/InspectorOverlay.cpp (modified) (6 diffs)
-
inspector/InspectorOverlay.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r272936 r272948 1 2021-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 1 19 2021-02-16 Chris Dumez <cdumez@apple.com> 2 20 -
trunk/Source/WebCore/inspector/InspectorOverlay.cpp
r272918 r272948 44 44 #include "FrameView.h" 45 45 #include "GraphicsContext.h" 46 #include "GridArea.h" 46 47 #include "GridPositionsResolver.h" 47 48 #include "InspectorClient.h" … … 51 52 #include "Node.h" 52 53 #include "NodeList.h" 54 #include "NodeRenderStyle.h" 53 55 #include "Page.h" 54 56 #include "PseudoElement.h" … … 1173 1175 } 1174 1176 1175 void InspectorOverlay::drawLayoutLabel(GraphicsContext& context, String label, FloatPoint point, InspectorOverlay::LabelArrowDirection direction )1177 void InspectorOverlay::drawLayoutLabel(GraphicsContext& context, String label, FloatPoint point, InspectorOverlay::LabelArrowDirection direction, Color backgroundColor, float maximumWidth) 1176 1178 { 1177 1179 GraphicsContextStateSaver saver(context); … … 1185 1187 FontCascade font(WTFMove(fontDescription), 0, 0); 1186 1188 font.update(nullptr); 1187 1188 float textWidth = font.width(TextRun(label)); 1189 1190 constexpr auto padding = 4; 1191 constexpr auto arrowSize = 4; 1189 1192 float textHeight = font.fontMetrics().floatHeight(); 1190 1193 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 } 1193 1204 1194 1205 Path labelPath; … … 1236 1247 textPosition = FloatPoint(arrowSize + padding, (textHeight / 2) - textDescent); 1237 1248 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; 1238 1255 } 1239 1256 1240 1257 labelPath.closeSubpath(); 1241 1258 1242 context.setFillColor( Color::white);1259 context.setFillColor(backgroundColor); 1243 1260 context.fillPath(labelPath); 1244 1261 context.strokePath(labelPath); … … 1372 1389 } 1373 1390 } 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 } 1374 1411 } 1375 1412 -
trunk/Source/WebCore/inspector/InspectorOverlay.h
r272918 r272948 169 169 170 170 enum class LabelArrowDirection { 171 None, 171 172 Down, 172 173 Up, … … 184 185 185 186 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); 187 188 188 189 void drawGridOverlay(GraphicsContext&, const InspectorOverlay::Grid&);
Note: See TracChangeset
for help on using the changeset viewer.