Changeset 273098 in webkit
- Timestamp:
- Feb 18, 2021 12:58:04 PM (17 months ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
inspector/InspectorOverlay.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r273094 r273098 1 2021-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 1 25 2021-02-18 Commit Queue <commit-queue@webkit.org> 2 26 -
trunk/Source/WebCore/inspector/InspectorOverlay.cpp
r273037 r273098 33 33 #include "AXObjectCache.h" 34 34 #include "AccessibilityObject.h" 35 #include "CSSGridAutoRepeatValue.h" 36 #include "CSSGridIntegerRepeatValue.h" 37 #include "CSSGridLineNamesValue.h" 35 38 #include "DOMCSSNamespace.h" 36 39 #include "DOMTokenList.h" … … 61 64 #include "RenderObject.h" 62 65 #include "Settings.h" 66 #include "StyleResolver.h" 63 67 #include <wtf/MathExtras.h> 64 68 #include <wtf/text/StringBuilder.h> … … 79 83 static constexpr float rulerSubStepLength = 5; 80 84 85 static constexpr UChar bullet = 0x2022; 81 86 static constexpr UChar ellipsis = 0x2026; 82 87 static constexpr UChar multiplicationSign = 0x00D7; 88 static constexpr UChar thinSpace = 0x2009; 83 89 84 90 static void truncateWithEllipsis(String& string, size_t length) … … 1182 1188 1183 1189 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); 1186 1193 1187 1194 FontCascade font(WTFMove(fontDescription), 0, 0); … … 1215 1222 labelPath.addLineTo({ (textWidth / 2) + padding, -arrowSize }); 1216 1223 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); 1218 1225 break; 1219 1226 case InspectorOverlay::LabelArrowDirection::Up: … … 1225 1232 labelPath.addLineTo({ (textWidth / 2) + padding, arrowSize }); 1226 1233 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); 1228 1235 break; 1229 1236 case InspectorOverlay::LabelArrowDirection::Right: … … 1265 1272 } 1266 1273 1274 static 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 1267 1334 void InspectorOverlay::drawGridOverlay(GraphicsContext& context, const InspectorOverlay::Grid& gridOverlay) 1268 1335 { … … 1283 1350 return; 1284 1351 } 1352 1353 constexpr auto translucentLabelBackgroundColor = Color::white.colorWithAlphaByte(153); 1285 1354 1286 1355 auto* renderGrid = downcast<RenderGrid>(renderer); … … 1326 1395 // Draw columns and rows. 1327 1396 auto columnWidths = renderGrid->trackSizesForComputedStyle(GridTrackSizingDirection::ForColumns); 1397 auto authoredTrackColumnSizes = authoredGridTrackSizes(node, GridTrackSizingDirection::ForColumns, columnWidths.size()); 1328 1398 float previousColumnX = 0; 1329 1399 for (unsigned i = 0; i < columnPositions.size(); ++i) { … … 1346 1416 columnPaths.addLineTo({ position + width, scrollY + viewportSize.height() }); 1347 1417 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 } 1348 1436 } else 1349 1437 previousColumnX = position; … … 1359 1447 1360 1448 auto rowHeights = renderGrid->trackSizesForComputedStyle(GridTrackSizingDirection::ForRows); 1449 auto authoredTrackRowSizes = authoredGridTrackSizes(node, GridTrackSizingDirection::ForRows, rowHeights.size()); 1361 1450 float previousRowY = 0; 1362 1451 for (unsigned i = 0; i < rowPositions.size(); ++i) { … … 1378 1467 rowPaths.addLineTo({ scrollX + viewportSize.width(), position + height }); 1379 1468 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 } 1380 1487 } else 1381 1488 previousRowY = position; … … 1409 1516 1410 1517 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()); 1412 1519 } 1413 1520 }
Note: See TracChangeset
for help on using the changeset viewer.