Changeset 275519 in webkit
- Timestamp:
- Apr 6, 2021 8:56:18 AM (16 months ago)
- Location:
- trunk/Source
- Files:
-
- 4 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/inspector/InspectorOverlay.cpp (modified) (14 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/UIProcess/Inspector/ios/WKInspectorHighlightView.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r275518 r275519 1 2021-04-06 Patrick Angle <pangle@apple.com> 2 3 Web Inspector: Grid overlay does not honor writing modes and RTL layout direction. 4 https://bugs.webkit.org/show_bug.cgi?id=224127 5 6 Reviewed by BJ Burg. 7 8 Grid overlays did not previous honor writing modes and RTL layout direction correctly. The underlying math was 9 correct, but the 'origin' of the element's grid, and the direction in which rows and columns increased, was not 10 handled correctly. This patch resolves this by taking writing mode and direction into account when calculating 11 row/column line positions as well as correctly orienting layout label arrows based on the current writing 12 mode/direction. 13 14 Area names have been moved to the center of their respective areas, which both helps to make sure the label is 15 within the area for all writing modes/direction/transformation, as well as improved legibility on smaller grids 16 where area names were previously behind other labels. 17 18 * inspector/InspectorOverlay.cpp: 19 (WebCore::InspectorOverlay::backgroundPathForLayoutLabel): 20 (WebCore::InspectorOverlay::drawLayoutLabel): 21 (WebCore::InspectorOverlay::drawGridOverlay): 22 - `backgroundPathForLayoutLabel`, `drawLayoutLabel`, and `drawGridOverlay` now interpret the `None` arrow direction 23 as using the label's location as its center, not top-left. 24 (WebCore::authoredGridTrackSizes): 25 - Drive-by removal of extra whitespace. 26 (WebCore::InspectorOverlay::buildGridOverlay): 27 - Use the element's computed style to determine writing mode and direction (which takes into account the `dir` attribute). 28 - Adjust columnLineAt and rowLineAt calculations based on writing mode and direction. 29 - Adjust all arrow directions and positions based on writing mode and direction. 30 31 1 32 2021-04-06 Stephan Szabo <stephan.szabo@sony.com> 2 33 -
trunk/Source/WebCore/inspector/InspectorOverlay.cpp
r275293 r275519 1331 1331 break; 1332 1332 case InspectorOverlay::LabelArrowDirection::None: 1333 path.addLineTo({ 0, height }); 1334 path.addLineTo({ width, height }); 1335 path.addLineTo({ width, 0 }); 1333 path.moveTo({ -(width / 2), -(height / 2) }); 1334 path.addLineTo({ -(width / 2), height / 2 }); 1335 path.addLineTo({ width / 2, height / 2 }); 1336 path.addLineTo({ width / 2, -(height / 2) }); 1336 1337 break; 1337 1338 } … … 1449 1450 break; 1450 1451 case InspectorOverlay::LabelArrowDirection::None: 1451 textPosition = FloatPoint( layoutLabelPadding, layoutLabelPadding + textHeight- textDescent);1452 textPosition = FloatPoint(-(textWidth / 2), (textHeight / 2) - textDescent); 1452 1453 break; 1453 1454 } … … 1488 1489 context.setStrokeThickness(1); 1489 1490 for (auto area : gridOverlay.areas) 1490 drawLayoutLabel(context, area.name, area.quad. p1(), LabelArrowDirection::None, LabelArrowEdgePosition::None, translucentLabelBackgroundColor, area.quad.boundingBox().width());1491 drawLayoutLabel(context, area.name, area.quad.center(), LabelArrowDirection::None, LabelArrowEdgePosition::None, translucentLabelBackgroundColor, area.quad.boundingBox().width()); 1491 1492 1492 1493 for (auto label : gridOverlay.labels) … … 1515 1516 } 1516 1517 } 1517 1518 1518 1519 if (!cssValue || !is<CSSValueList>(cssValue)) 1519 1520 return { }; … … 1525 1526 trackSizes.append(currentValue.cssText()); 1526 1527 }; 1527 1528 1528 1529 for (auto& currentValue : downcast<CSSValueList>(*cssValue)) { 1529 1530 if (is<CSSGridAutoRepeatValue>(currentValue)) { … … 1538 1539 break; 1539 1540 } 1540 1541 1541 1542 if (is<CSSGridIntegerRepeatValue>(currentValue)) { 1542 1543 size_t repetitions = downcast<CSSGridIntegerRepeatValue>(currentValue.get()).repetitions(); … … 1547 1548 continue; 1548 1549 } 1549 1550 1550 1551 handleValueIgnoringLineNames(currentValue); 1551 1552 } 1552 1553 1553 1554 // Remaining tracks will be `auto`. 1554 1555 while (trackSizes.size() < expectedTrackCount) … … 1653 1654 FrameView* containingView = containingFrame->view(); 1654 1655 1655 auto columnLineAt = [&](int x) -> FloatLine { 1656 auto computedStyle = node->computedStyle(); 1657 if (!computedStyle) 1658 return { }; 1659 1660 auto isHorizontalWritingMode = computedStyle->isHorizontalWritingMode(); 1661 auto isDirectionFlipped = !computedStyle->isLeftToRightDirection(); 1662 auto isWritingModeFlipped = computedStyle->isFlippedBlocksWritingMode(); 1663 auto contentBox = renderGrid.absoluteBoundingBoxRectIgnoringTransforms(); 1664 1665 auto columnLineAt = [&](float x) -> FloatLine { 1666 FloatPoint startPoint; 1667 FloatPoint endPoint; 1668 if (isHorizontalWritingMode) { 1669 startPoint = { isDirectionFlipped ? contentBox.width() - x : x, isWritingModeFlipped ? contentBox.height() - gridStartY : gridStartY }; 1670 endPoint = { isDirectionFlipped ? contentBox.width() - x : x, isWritingModeFlipped ? contentBox.height() - gridEndY : gridEndY }; 1671 } else { 1672 startPoint = { isWritingModeFlipped ? contentBox.width() - gridStartY : gridStartY, isDirectionFlipped ? contentBox.height() - x : x }; 1673 endPoint = { isWritingModeFlipped ? contentBox.width() - gridEndY : gridEndY, isDirectionFlipped ? contentBox.height() - x : x }; 1674 } 1656 1675 return { 1657 localPointToRootPoint(containingView, renderGrid.localToContainerPoint( FloatPoint(x, gridStartY), nullptr)),1658 localPointToRootPoint(containingView, renderGrid.localToContainerPoint( FloatPoint(x, gridEndY), nullptr)),1676 localPointToRootPoint(containingView, renderGrid.localToContainerPoint(startPoint, nullptr)), 1677 localPointToRootPoint(containingView, renderGrid.localToContainerPoint(endPoint, nullptr)), 1659 1678 }; 1660 1679 }; 1661 auto rowLineAt = [&](int y) -> FloatLine { 1680 auto rowLineAt = [&](float y) -> FloatLine { 1681 FloatPoint startPoint; 1682 FloatPoint endPoint; 1683 if (isHorizontalWritingMode) { 1684 startPoint = { isDirectionFlipped ? contentBox.width() - gridStartX : gridStartX, isWritingModeFlipped ? contentBox.height() - y : y }; 1685 endPoint = { isDirectionFlipped ? contentBox.width() - gridEndX : gridEndX, isWritingModeFlipped ? contentBox.height() - y : y }; 1686 } else { 1687 startPoint = { isWritingModeFlipped ? contentBox.width() - y : y, isDirectionFlipped ? contentBox.height() - gridStartX : gridStartX }; 1688 endPoint = { isWritingModeFlipped ? contentBox.width() - y : y, isDirectionFlipped ? contentBox.height() - gridEndX : gridEndX }; 1689 } 1662 1690 return { 1663 localPointToRootPoint(containingView, renderGrid.localToContainerPoint( FloatPoint(gridStartX, y), nullptr)),1664 localPointToRootPoint(containingView, renderGrid.localToContainerPoint( FloatPoint(gridEndX, y), nullptr)),1691 localPointToRootPoint(containingView, renderGrid.localToContainerPoint(startPoint, nullptr)), 1692 localPointToRootPoint(containingView, renderGrid.localToContainerPoint(endPoint, nullptr)), 1665 1693 }; 1694 }; 1695 1696 auto correctedArrowDirection = [&](LabelArrowDirection direction, GridTrackSizingDirection sizingDirection) -> LabelArrowDirection { 1697 if ((sizingDirection == GridTrackSizingDirection::ForColumns && isWritingModeFlipped) || (sizingDirection == GridTrackSizingDirection::ForRows && isDirectionFlipped)) { 1698 switch (direction) { 1699 case LabelArrowDirection::Down: 1700 direction = LabelArrowDirection::Up; 1701 break; 1702 case LabelArrowDirection::Up: 1703 direction = LabelArrowDirection::Down; 1704 break; 1705 case LabelArrowDirection::Left: 1706 direction = LabelArrowDirection::Right; 1707 break; 1708 case LabelArrowDirection::Right: 1709 direction = LabelArrowDirection::Left; 1710 break; 1711 case LabelArrowDirection::None: 1712 break; 1713 } 1714 } 1715 1716 if (!isHorizontalWritingMode) { 1717 switch (direction) { 1718 case LabelArrowDirection::Down: 1719 direction = LabelArrowDirection::Right; 1720 break; 1721 case LabelArrowDirection::Up: 1722 direction = LabelArrowDirection::Left; 1723 break; 1724 case LabelArrowDirection::Left: 1725 direction = LabelArrowDirection::Up; 1726 break; 1727 case LabelArrowDirection::Right: 1728 direction = LabelArrowDirection::Down; 1729 break; 1730 case LabelArrowDirection::None: 1731 break; 1732 } 1733 } 1734 1735 return direction; 1736 }; 1737 1738 auto correctedArrowEdgePosition = [&](LabelArrowEdgePosition edgePosition, GridTrackSizingDirection sizingDirection) -> LabelArrowEdgePosition { 1739 if ((sizingDirection == GridTrackSizingDirection::ForRows && isWritingModeFlipped) || (sizingDirection == GridTrackSizingDirection::ForColumns && isDirectionFlipped)) { 1740 if (edgePosition == LabelArrowEdgePosition::Leading) 1741 return LabelArrowEdgePosition::Trailing; 1742 if (edgePosition == LabelArrowEdgePosition::Trailing) 1743 return LabelArrowEdgePosition::Leading; 1744 } 1745 1746 return edgePosition; 1666 1747 }; 1667 1748 … … 1707 1788 auto trackSizeLabel = String::number(roundf(width)); 1708 1789 trackSizeLabel.append("px"_s); 1709 1790 1710 1791 String authoredTrackSize; 1711 1792 if (i < authoredTrackColumnSizes.size()) { … … 1718 1799 } 1719 1800 } 1720 1801 1721 1802 FloatLine trackTopLine = { columnStartLine.start(), columnEndLine.start() }; 1722 gridHighlightOverlay.labels.append(buildLabel(trackSizeLabel, trackTopLine.pointAtRelativeDistance(0.5), translucentLabelBackgroundColor, LabelArrowDirection::Up, LabelArrowEdgePosition::Middle));1803 gridHighlightOverlay.labels.append(buildLabel(trackSizeLabel, trackTopLine.pointAtRelativeDistance(0.5), translucentLabelBackgroundColor, correctedArrowDirection(LabelArrowDirection::Up, GridTrackSizingDirection::ForColumns), LabelArrowEdgePosition::Middle)); 1723 1804 } 1724 1805 } else … … 1738 1819 if (!lineLabel.isEmpty()) { 1739 1820 auto text = lineLabel.toString(); 1740 auto arrowDirection = LabelArrowDirection::Down;1741 auto arrowEdgePosition = LabelArrowEdgePosition::Middle;1821 auto arrowDirection = correctedArrowDirection(LabelArrowDirection::Down, GridTrackSizingDirection::ForColumns); 1822 auto arrowEdgePosition = correctedArrowEdgePosition(LabelArrowEdgePosition::Middle, GridTrackSizingDirection::ForColumns); 1742 1823 1743 1824 if (!i) 1744 arrowEdgePosition = LabelArrowEdgePosition::Leading;1825 arrowEdgePosition = correctedArrowEdgePosition(LabelArrowEdgePosition::Leading, GridTrackSizingDirection::ForColumns); 1745 1826 else if (i == columnPositions.size() - 1) 1746 arrowEdgePosition = LabelArrowEdgePosition::Trailing;1827 arrowEdgePosition = correctedArrowEdgePosition(LabelArrowEdgePosition::Trailing, GridTrackSizingDirection::ForColumns); 1747 1828 1748 1829 auto expectedLabelSize = expectedSizeForLayoutLabel(text, arrowDirection); … … 1752 1833 auto topEdgeInset = pageView->topContentInset(ScrollView::TopContentInsetType::WebCoreOrPlatformContentInset); 1753 1834 if (gapLabelLine.start().y() - expectedLabelSize.height() - topEdgeInset + scrollPosition.y() - viewportBounds.y() < 0) { 1754 arrowDirection = LabelArrowDirection::Up;1835 arrowDirection = correctedArrowDirection(LabelArrowDirection::Up, GridTrackSizingDirection::ForColumns); 1755 1836 1756 1837 // Special case for the first column to make sure the label will be out of the way of the first row's label. … … 1812 1893 } 1813 1894 } 1895 1814 1896 FloatLine trackLeftLine = { rowStartLine.start(), rowEndLine.start() }; 1815 gridHighlightOverlay.labels.append(buildLabel(trackSizeLabel, trackLeftLine.pointAtRelativeDistance(0.5), translucentLabelBackgroundColor, LabelArrowDirection::Left, LabelArrowEdgePosition::Middle));1897 gridHighlightOverlay.labels.append(buildLabel(trackSizeLabel, trackLeftLine.pointAtRelativeDistance(0.5), translucentLabelBackgroundColor, correctedArrowDirection(LabelArrowDirection::Left, GridTrackSizingDirection::ForRows), LabelArrowEdgePosition::Middle)); 1816 1898 } 1817 1899 } else … … 1831 1913 if (!lineLabel.isEmpty()) { 1832 1914 auto text = lineLabel.toString(); 1833 auto arrowDirection = LabelArrowDirection::Right;1834 auto arrowEdgePosition = LabelArrowEdgePosition::Middle;1915 auto arrowDirection = correctedArrowDirection(LabelArrowDirection::Right, GridTrackSizingDirection::ForRows); 1916 auto arrowEdgePosition = correctedArrowEdgePosition(LabelArrowEdgePosition::Middle, GridTrackSizingDirection::ForRows); 1835 1917 1836 1918 if (!i) 1837 arrowEdgePosition = LabelArrowEdgePosition::Leading;1919 arrowEdgePosition = correctedArrowEdgePosition(LabelArrowEdgePosition::Leading, GridTrackSizingDirection::ForRows); 1838 1920 else if (i == rowPositions.size() - 1) 1839 arrowEdgePosition = LabelArrowEdgePosition::Trailing;1921 arrowEdgePosition = correctedArrowEdgePosition(LabelArrowEdgePosition::Trailing, GridTrackSizingDirection::ForRows); 1840 1922 1841 1923 auto expectedLabelSize = expectedSizeForLayoutLabel(text, arrowDirection); 1842 1924 if (gapLabelPosition.x() - expectedLabelSize.width() + scrollPosition.x() - viewportBounds.x() < 0) 1843 arrowDirection = LabelArrowDirection::Left;1925 arrowDirection = correctedArrowDirection(LabelArrowDirection::Left, GridTrackSizingDirection::ForRows); 1844 1926 1845 1927 gridHighlightOverlay.labels.append(buildLabel(text, gapLabelPosition, Color::white, arrowDirection, arrowEdgePosition)); -
trunk/Source/WebKit/ChangeLog
r275517 r275519 1 2021-04-06 Patrick Angle <pangle@apple.com> 2 3 Web Inspector: Grid overlay does not honor writing modes and RTL layout direction. 4 https://bugs.webkit.org/show_bug.cgi?id=224127 5 6 Reviewed by BJ Burg. 7 8 * UIProcess/Inspector/ios/WKInspectorHighlightView.mm: 9 (createLayoutLabelLayer): 10 - WebCore::backgroundPathForLayoutLabel now treats the `None` arrow direction as being centered on the label's 11 location. 12 1 13 2021-04-06 Philippe Normand <pnormand@igalia.com> 2 14 -
trunk/Source/WebKit/UIProcess/Inspector/ios/WKInspectorHighlightView.mm
r275128 r275519 401 401 break; 402 402 case WebCore::InspectorOverlay::LabelArrowDirection::None: 403 textPosition = WebCore::FloatPoint(padding + (textWidth / 2), padding + (textHeight / 2));403 // Text position will remain (0, 0). 404 404 break; 405 405 }
Note: See TracChangeset
for help on using the changeset viewer.