Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 0f6e49eddde2fdb91dcc5dfa65723705b9a6a25b
      
https://github.com/WebKit/WebKit/commit/0f6e49eddde2fdb91dcc5dfa65723705b9a6a25b
  Author: Sammy Gill <[email protected]>
  Date:   2026-09-22 (Tue, 22 Sep 2026)

  Changed paths:
    M Source/WebCore/layout/formattingContexts/grid/GridFormattingContext.cpp
    M Source/WebCore/layout/formattingContexts/grid/GridItemPlacer.cpp
    M Source/WebCore/layout/formattingContexts/grid/GridTypeAliases.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] Simplify ImplicitGrid and item placement.
https://bugs.webkit.org/show_bug.cgi?id=324569
rdar://problem/187803498

Reviewed by Alan Baradlay.

Currently item placement works by passing in a set
of UnplacedGridItems to GridItemPlacer which then
uses an ImplicitGrid to perform placement. As placement
progresses the ImplicitGrid becomes more stateful
since it keeps track of where the items end up getting
positioned.

Then, ImplicitGrid::gridAreas is used to get all of
the positions for the items when placement is done
in order to create a set of PlacedGridItems. This
is fine for the most part but there is a bit of a
side effect that is not ideal: since ImplicitGrid::gridAreas
iterates over a HashMap to get all of the grid areas
this means that the order of a list of PlacedGridItems
may be different from time to time even if the content
is the same depending on how the items got hashed.
This hashing was done by just using the address of
the item. This behavior can actually become visible
with LayoutTests that track repaints since the
order in which the items are processed can change.

However, we can address this problem and simplify
the code overall by keying in on the fact that after
an item has been placed its position within the
ImplicitGrid will never change. This means instead
of trying to figure out all of the areas in
ImplicitGrid::gridAreas after the entirety of placement
has completed we can just return the position to
the caller when the item has been placed. This
allows the caller to store the result however they
want. It also simplifies ImplicitGrid because instead
of having to associate an item with a location in
the grid it can just keep track of whether or not
an area is occupied with a simple bit.

* Source/WebCore/layout/formattingContexts/grid/GridItemPlacer.cpp:
(WebCore::Layout::GridItemPlacer::placeItems const):
Now GridItemPlacer will construct a list of grid areas
and will populate it with each call to the different
APIs in ImplicitGrid. The size of this list is the
number of items.

* Source/WebCore/layout/formattingContexts/grid/ImplicitGrid.cpp:
(WebCore::Layout::ImplicitGrid::ImplicitGrid):
Make sure we initialize each entry in the grid matrix
with a value of false.

(WebCore::Layout::ImplicitGrid::markAreaAsOccupied):
This function used to be insertItemInArea but has been
renamed. What it was doing before was taking
the UnplacedGridItem and adding it into the various
cells associated with its area. Now instead of storing
the actual object we can just flip the bit in the
entry of the matrix to indicate it is occupied. That
is all ImplicitGrid should care about. It does not
need to know the actual items that are in the slots.
All previous calls to insertItemInArea are just
replaced with markAreaAsOccupied and the caller can
do whatever they want with the area that was
marked as occupied.

(WebCore::Layout::ImplicitGrid::gridAreas const): Deleted.
(WebCore::Layout::ImplicitGrid::insertAutoPositionedItems): Deleted.
(WebCore::Layout::ImplicitGrid::insertItemInArea): Deleted.
* Source/WebCore/layout/formattingContexts/grid/ImplicitGrid.h:
* Source/WebCore/layout/formattingContexts/grid/UnplacedGridItem.cpp:
(WebCore::Layout::UnplacedGridItem::operator== const): Deleted.
(WebCore::Layout::add): Deleted.
* Source/WebCore/layout/formattingContexts/grid/UnplacedGridItem.h:
(WebCore::Layout::UnplacedGridItem::isHashTableDeletedValue const): Deleted.
(WebCore::Layout::UnplacedGridItem::isHashTableEmptyValue const): Deleted.
(WTF::HashTraits<WebCore::Layout::UnplacedGridItem>::isEmptyValue): Deleted.
(WTF::HashTraits<WebCore::Layout::UnplacedGridItem>::emptyValue): Deleted.

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to