Changeset 291464 in webkit
- Timestamp:
- Mar 17, 2022 7:33:37 PM (4 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-stretch-expected.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-stretch.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/rendering/RenderBox.cpp (modified) (3 diffs)
-
Source/WebCore/rendering/RenderGrid.cpp (modified) (5 diffs)
-
Source/WebCore/rendering/RenderGrid.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r291420 r291464 1 2022-03-17 Matt Woodrow <mattwoodrow@apple.com> 2 3 Subgrid items should always be stretched. 4 https://bugs.webkit.org/show_bug.cgi?id=237628 5 6 Reviewed by Alan Bujtas. 7 8 * web-platform-tests/css/css-grid/subgrid/subgrid-stretch-expected.html: Added. 9 * web-platform-tests/css/css-grid/subgrid/subgrid-stretch.html: Added. 10 11 Added new WPT test covering various width/height and alignement contraints that should be 12 ignored since subgrids are always stretched. 13 1 14 2022-03-17 Antoine Quint <graouts@webkit.org> 2 15 -
trunk/Source/WebCore/ChangeLog
r291463 r291464 1 2022-03-17 Matt Woodrow <mattwoodrow@apple.com> 2 3 Subgrid items should always be stretched. 4 https://bugs.webkit.org/show_bug.cgi?id=237628 5 6 Reviewed by Alan Bujtas. 7 8 Fixes https://drafts.csswg.org/css-grid-2/#subgrid-box-alignment 9 10 Test: imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-stretch.html 11 12 * rendering/RenderBox.cpp: 13 (WebCore::RenderBox::computeLogicalWidthInFragment const): 14 (WebCore::RenderBox::hasStretchedLogicalHeight const): 15 (WebCore::RenderBox::hasStretchedLogicalWidth const): 16 * rendering/RenderBox.h: 17 18 Makes computeLogicalWidthInFragment use the override logical width for grid items 19 if it's been set, as we already do for height. We don't early return, so that margins 20 still get computed relative to this width. 21 22 * rendering/RenderGrid.cpp: 23 (WebCore::RenderGrid::layoutGridItems): 24 (WebCore::RenderGrid::availableAlignmentSpaceForChildBeforeStretching const): 25 (WebCore::RenderGrid::alignSelfForChild const): 26 (WebCore::RenderGrid::justifySelfForChild const): 27 (WebCore::RenderGrid::applyStretchAlignmentToChildIfNeeded): 28 (WebCore::RenderGrid::applySubgridStretchAlignmentToChildIfNeeded): 29 * rendering/RenderGrid.h: 30 31 Sets the required override width/height size on subgrid items so that they get 32 stretched. 33 1 34 2022-03-17 Alan Bujtas <zalan@apple.com> 2 35 -
trunk/Source/WebCore/rendering/RenderBox.cpp
r290634 r291464 2727 2727 2728 2728 // Width calculations 2729 if (treatAsReplaced) { 2729 if (isGridItem() && hasOverridingLogicalWidth()) { 2730 computedValues.m_extent = overridingLogicalWidth(); 2731 } else if (treatAsReplaced) { 2730 2732 computedValues.m_extent = logicalWidthLength.value() + borderAndPaddingLogicalWidth(); 2731 2733 } else if (shouldComputeLogicalWidthFromAspectRatio() && style().logicalWidth().isAuto()) { … … 2879 2881 return false; 2880 2882 } 2881 if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode()) 2883 if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode()) { 2884 if (is<RenderGrid>(this) && downcast<RenderGrid>(this)->isSubgridInParentDirection(ForColumns)) 2885 return true; 2882 2886 return style.resolvedJustifySelf(&containingBlock->style(), containingBlock->selfAlignmentNormalBehavior(this)).position() == ItemPosition::Stretch; 2887 } 2888 if (is<RenderGrid>(this) && downcast<RenderGrid>(this)->isSubgridInParentDirection(ForRows)) 2889 return true; 2883 2890 return style.resolvedAlignSelf(&containingBlock->style(), containingBlock->selfAlignmentNormalBehavior(this)).position() == ItemPosition::Stretch; 2884 2891 } … … 2897 2904 } 2898 2905 auto normalItemPosition = stretchingMode == StretchingMode::Any ? containingBlock->selfAlignmentNormalBehavior(this) : ItemPosition::Normal; 2899 if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode()) 2906 if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode()) { 2907 if (is<RenderGrid>(this) && downcast<RenderGrid>(this)->isSubgridInParentDirection(ForRows)) 2908 return true; 2900 2909 return style.resolvedAlignSelf(&containingBlock->style(), normalItemPosition).position() == ItemPosition::Stretch; 2910 } 2911 if (is<RenderGrid>(this) && downcast<RenderGrid>(this)->isSubgridInParentDirection(ForColumns)) 2912 return true; 2901 2913 return style.resolvedJustifySelf(&containingBlock->style(), normalItemPosition).position() == ItemPosition::Stretch; 2902 2914 } -
trunk/Source/WebCore/rendering/RenderGrid.cpp
r290879 r291464 1056 1056 // determine the available space before stretching, are not set yet. 1057 1057 applyStretchAlignmentToChildIfNeeded(*child); 1058 applySubgridStretchAlignmentToChildIfNeeded(*child); 1058 1059 1059 1060 child->layoutIfNeeded(); … … 1200 1201 } 1201 1202 1202 LayoutUnit RenderGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox& child ) const1203 LayoutUnit RenderGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox& child, GridTrackSizingDirection direction) const 1203 1204 { 1204 1205 // Because we want to avoid multiple layouts, stretching logic might be performed before 1205 1206 // children are laid out, so we can't use the child cached values. Hence, we need to 1206 1207 // compute margins in order to determine the available height before stretching. 1207 GridTrackSizingDirection childBlockFlowDirection = GridLayoutFunctions::flowAwareDirectionForChild(*this, child, ForRows);1208 return std::max(0_lu, gridAreaBreadthForChild - GridLayoutFunctions::marginLogicalSizeForChild(*this, child BlockFlowDirection, child));1208 auto childFlowDirection = GridLayoutFunctions::flowAwareDirectionForChild(*this, child, direction); 1209 return std::max(0_lu, gridAreaBreadthForChild - GridLayoutFunctions::marginLogicalSizeForChild(*this, childFlowDirection, child)); 1209 1210 } 1210 1211 1211 1212 StyleSelfAlignmentData RenderGrid::alignSelfForChild(const RenderBox& child, StretchingMode stretchingMode, const RenderStyle* gridStyle) const 1212 1213 { 1214 if (isSubgridInParentDirection(ForRows)) 1215 return { ItemPosition::Stretch, OverflowAlignment::Default }; 1213 1216 if (!gridStyle) 1214 1217 gridStyle = &style(); … … 1219 1222 StyleSelfAlignmentData RenderGrid::justifySelfForChild(const RenderBox& child, StretchingMode stretchingMode, const RenderStyle* gridStyle) const 1220 1223 { 1224 if (isSubgridInParentDirection(ForColumns)) 1225 return { ItemPosition::Stretch, OverflowAlignment::Default }; 1221 1226 if (!gridStyle) 1222 1227 gridStyle = &style(); … … 1252 1257 bool allowedToStretchChildBlockSize = blockFlowIsColumnAxis ? allowedToStretchChildAlongColumnAxis(child) : allowedToStretchChildAlongRowAxis(child); 1253 1258 if (allowedToStretchChildBlockSize && !aspectRatioPrefersInline(child, blockFlowIsColumnAxis)) { 1254 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childBlockDirection).value(), child );1259 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childBlockDirection).value(), child, ForRows); 1255 1260 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, std::nullopt); 1256 1261 child.setOverridingLogicalHeight(desiredLogicalHeight); … … 1265 1270 } 1266 1271 } else if (!allowedToStretchChildBlockSize && allowedToStretchChildAlongRowAxis(child)) { 1267 LayoutUnit stretchedLogicalWidth = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childInlineDirection).value(), child );1272 LayoutUnit stretchedLogicalWidth = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childInlineDirection).value(), child, ForColumns); 1268 1273 LayoutUnit desiredLogicalWidth = child.constrainLogicalWidthInFragmentByMinMax(stretchedLogicalWidth, contentWidth(), *this, nullptr); 1269 1274 child.setOverridingLogicalWidth(desiredLogicalWidth); 1270 1275 if (desiredLogicalWidth != child.logicalWidth()) 1271 1276 child.setNeedsLayout(MarkOnlyThis); 1272 } 1277 } 1278 } 1279 1280 void RenderGrid::applySubgridStretchAlignmentToChildIfNeeded(RenderBox& child) 1281 { 1282 if (!is<RenderGrid>(child)) 1283 return; 1284 1285 if (downcast<RenderGrid>(child).isSubgrid(ForRows)) { 1286 auto childBlockDirection = GridLayoutFunctions::flowAwareDirectionForChild(*this, child, ForRows); 1287 auto stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childBlockDirection).value(), child, ForRows); 1288 child.setOverridingLogicalHeight(stretchedLogicalHeight); 1289 } 1290 1291 if (downcast<RenderGrid>(child).isSubgrid(ForColumns)) { 1292 auto childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*this, child, ForColumns); 1293 auto stretchedLogicalWidth = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childInlineDirection).value(), child, ForColumns); 1294 child.setOverridingLogicalWidth(stretchedLogicalWidth); 1295 } 1273 1296 } 1274 1297 -
trunk/Source/WebCore/rendering/RenderGrid.h
r290879 r291464 192 192 193 193 void paintChildren(PaintInfo& forSelf, const LayoutPoint& paintOffset, PaintInfo& forChild, bool usePrintRect) override; 194 LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox& ) const;194 LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox&, GridTrackSizingDirection) const; 195 195 StyleSelfAlignmentData justifySelfForChild(const RenderBox&, StretchingMode = StretchingMode::Any, const RenderStyle* = nullptr) const; 196 196 StyleSelfAlignmentData alignSelfForChild(const RenderBox&, StretchingMode = StretchingMode::Any, const RenderStyle* = nullptr) const; 197 197 void applyStretchAlignmentToChildIfNeeded(RenderBox&); 198 void applySubgridStretchAlignmentToChildIfNeeded(RenderBox&); 198 199 bool hasAutoSizeInColumnAxis(const RenderBox& child) const; 199 200 bool hasAutoSizeInRowAxis(const RenderBox& child) const;
Note: See TracChangeset
for help on using the changeset viewer.