Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 7be8af50b716ba102581dc35e626637cfa45c693
https://github.com/WebKit/WebKit/commit/7be8af50b716ba102581dc35e626637cfa45c693
Author: Sammy Gill <[email protected]>
Date: 2026-07-28 (Tue, 28 Jul 2026)
Changed paths:
M Source/WebCore/layout/formattingContexts/grid/GridFormattingContext.cpp
M Source/WebCore/layout/formattingContexts/grid/GridLayout.cpp
M Source/WebCore/layout/formattingContexts/grid/GridLayout.h
M Source/WebCore/layout/formattingContexts/grid/ImplicitGrid.cpp
M Source/WebCore/layout/formattingContexts/grid/ImplicitGrid.h
M Source/WebCore/layout/formattingContexts/grid/UnplacedGridItem.cpp
M Source/WebCore/layout/formattingContexts/grid/UnplacedGridItem.h
Log Message:
-----------
[GFC] Apply a grid item's negative line offset when constructing
UnplacedGridItem
https://bugs.webkit.org/show_bug.cgi?id=320382
rdar://problem/183344674
Reviewed by Alan Baradlay.
When a negative line number is used to position a grid item this causes
us to begin searching from the line from the end of the grid instead of
from the beginning. Depending on the value of this negative line number
we may end up going past the beginning of the explicit grid and create
implicit tracks at the beginning. For example a grid with two explicit
columns with lines L1 L2 L3, a grid item with position -4 / -3 would end
up creating one implicit column in the beginning of the grid.
We currently keep track of where this position is by computing a
normalization offset which basically keeps track of the magnitude of the
negative grid positions. We then shift each grid item's position by this
offset so that the resulting position is relative to the start of the
impicit grid. We currently have a dedicated API which callers are
expected to use during item placement that contains some debug asserts
to make sure that the normalization offset was computed and applied. To
simplify this API, we can move this logic outside of GridLayout and into
the formatting context since we should be able to compute this
information beforehand. Then, when we create the GridPosition type that
we created recently we can compute and set a position that is relative
to the implicit grid as we create the UnplacedGridItem. We can then get
rid of one of the two APIs we have for getting an item's position which
should make things overall a bit simpler.
* Source/WebCore/layout/formattingContexts/grid/GridFormattingContext
(WebCore::Layout::GridFormattingContext::constructUnplacedGridItems
We go through all of the grid items already so during this process let's
try to figure out the largest magnitude of the negative line numbers. We
will then plumb this value into the rest of the code that creates the
UnplacedGridItem and corresponding GridPosition. The resulting
GridPosition will be relative to the implicit grid.
* Source/WebCore/layout/formattingContexts/grid/GridLayout.cpp:
(WebCore::Layout::GridLayout::calculateInitialImplicitGridDimension
Now that we compute the positions relative to the implicit grid itself
the number of columns/tracks is just the maximum of the column/row
positions of the items.
* Source/WebCore/layout/formattingContexts/grid/UnplacedGridItem.cp
(WebCore::Layout::UnplacedGridItem::GridPosition::create):
Take into consideration the offset that we computed earlier inside
GridFormattingContext when we construct the positions of the
UnplacedGridItem now.
(WebCore::Layout::UnplacedGridItem::resolveDefinitePosition):
New helper that is used to determine if a grid item's position or not
according to:
https://drafts.csswg.org/css-grid-1/#placement
(WebCore::Layout::UnplacedGridItem::definiteRowStartEnd const):
(WebCore::Layout::UnplacedGridItem::definiteColumnStartEnd const):
(WebCore::Layout::UnplacedGridItem::normalizedColumnStart const): D
(WebCore::Layout::UnplacedGridItem::normalizedColumnEnd const): Del
(WebCore::Layout::UnplacedGridItem::normalizedRowStart const): Dele
(WebCore::Layout::UnplacedGridItem::normalizedRowEnd const): Delete
(WebCore::Layout::UnplacedGridItem::normalizedRowStartEnd const): D
(WebCore::Layout::UnplacedGridItem::normalizedColumnStartEnd const)
Now that we no longer have the contept of a normalized position we can
just have the single definite position API.
Canonical link: https://commits.webkit.org/318071@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications