Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 5063ef34f4f66ebb467473eb9ed62e5a40cdbe7b
      
https://github.com/WebKit/WebKit/commit/5063ef34f4f66ebb467473eb9ed62e5a40cdbe7b
  Author: Sammy Gill <sammy.g...@apple.com>
  Date:   2025-09-17 (Wed, 17 Sep 2025)

  Changed paths:
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/layout/formattingContexts/grid/GridFormattingContext.cpp
    M Source/WebCore/layout/formattingContexts/grid/GridFormattingContext.h
    M Source/WebCore/layout/formattingContexts/grid/GridLayout.cpp
    M Source/WebCore/layout/formattingContexts/grid/GridLayout.h
    A Source/WebCore/layout/formattingContexts/grid/ImplicitGrid.cpp
    A Source/WebCore/layout/formattingContexts/grid/ImplicitGrid.h
    A Source/WebCore/layout/formattingContexts/grid/PlacedGridItem.cpp
    A Source/WebCore/layout/formattingContexts/grid/PlacedGridItem.h
    M Source/WebCore/layout/formattingContexts/grid/UnplacedGridItem.cpp
    M Source/WebCore/layout/formattingContexts/grid/UnplacedGridItem.h

  Log Message:
  -----------
  [GFC] Initial implementation of grid item placement.
https://bugs.webkit.org/show_bug.cgi?id=298989
rdar://problem/160729099

Reviewed by Sam Weinig and Alan Baradlay.

This patch introduces the initial implementation of grid item placement
by implementing some overall logic around simple content. In this case,
simple content refers to grid content in which all items are explicitly
placed, span only a single track, and other placement constraints which
should be documented through the code. In addition, we only support
placement by placing items within columns and grids that are explicitly
defined via the grid-template-{columns, rows} properties.

The overall purpose of this patch is not to implement all of the logic
required to satisfy item placement in all scenarios but rather provide
some overall scaffolding in which we can build upon one at a time. We
liberally use ASSERT_NOT_IMPLEMENTED to help identify these areas in which
we can and will need to build upon in future work.

* Source/WebCore/layout/formattingContexts/grid/GridFormattingContext.cpp:
(WebCore::Layout::GridFormattingContext::constructUnplacedGridItems const):
* Source/WebCore/layout/formattingContexts/grid/GridFormattingContext.h:
(WebCore::Layout::GridFormattingContext::root const):
* Source/WebCore/layout/formattingContexts/grid/GridLayout.cpp:
(WebCore::Layout::GridLayout::layout):
(WebCore::Layout::GridLayout::placeGridItems):
* Source/WebCore/layout/formattingContexts/grid/GridLayout.h:
(WebCore::Layout::GridLayout::gridContainer const):
(WebCore::Layout::GridLayout::gridContainerStyle const):

* Source/WebCore/layout/formattingContexts/grid/ImplicitGrid.cpp: Added.
(WebCore::Layout::ImplicitGrid::ImplicitGrid):
The main purpose of ImplicitGrid is to serve as a helper structure to
keep track of some state during item placement. Since an implicit grid
is constructed from the explicit grid, as described in the spec, the
idea is that the constructor takes in the number of explicit columns and
rows that are specified in the style. For now, we only take in the
columns and rows that are specified by grid-template-{columns, rows}, but
eventually, we will also need to take into consideration the fact
that the number of explicit tracks can also be influenced by the
grid-template-areas property.

(WebCore::Layout::ImplicitGrid::insertUnplacedGridItem):
Users of ImplicitGrid will insert unplaced items through this API, and
the ImplicitGrid will handle resizing the grid (i.e. adding implicit
columns and rows) as necessary to fit the items. This logic isn't
implemented currently since we are only worrying about items that fit
within the explicitly sized grid, and as a result, we should not need to
expect to resize the grid.

* Source/WebCore/layout/formattingContexts/grid/PlacedGridItem.cpp:
(WebCore::Layout::PlacedGridItem::PlacedGridItem):
* Source/WebCore/layout/formattingContexts/grid/PlacedGridItem.h:
A PlacedGridItem is the result of resolving the placement (i.e. the grid
area) of an UnplacedGridItem. This structure is very similar to
UnplacedGridItem, with the main difference being that the positions are
typed by size_t wthin a GridAreaLines struct to indicate the fact that
the location is resolved within the implicit grid.

(WebCore::Layout::UnplacedGridItem::explicitColumnStart const):
(WebCore::Layout::UnplacedGridItem::explicitColumnEnd const):
(WebCore::Layout::UnplacedGridItem::explicitRowStart const):
(WebCore::Layout::UnplacedGridItem::explicitRowEnd const):
Some straightforward helper functions to access the item's explicit
column/row positions. Since the grid lines in the properties' grammar are
1-indexed, we also subtract 1 from these values so that they map nicely
to our 0 indexed structures. For example, grid-column-start: 1 and
grid-column-end: 2 would return [0, 1] which would map the item to be
placed into GridMatrix[rowIndex][0]. We also leave negative line numbers
to be handled in a future patch to maintain simplicity.

* Source/WebCore/layout/formattingContexts/grid/UnplacedGridItem.h:
In order to place an UnplacedGridItem we need to know its placement
(position and span) which are given from the grid-{column, row}-{start, end}
properties. Any information that is needed to resolve a grid item's
placement should be stored on this class and be accessed through a
dedicated API, such as the explicit position helper functions above.

Also, we change PlacedGridItems from being a simple Vector<PlacedGridItem>
to a struct instead. This is because it will organize the different
unplaced grid items into a way that is easily accessible to the
placement logic in a manner that is similar to how the spec reads. For
example, the first step in placement is to place all non-auto positioned
items so this will be a collection of items in UnplacedGridItems that
the code can get to perform that step.

Canonical link: https://commits.webkit.org/300141@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to