Commit graph

102 commits

Author SHA1 Message Date
Aliaksandr Kalenik
5f2264a2bd LibWeb: Skip non-spanning items sizing if there are no such items
Otherwise base_size and growth_limit for tracks that do not have any
spanning items will be overriden with wrong values.
2023-05-17 07:48:38 +02:00
Aliaksandr Kalenik
95d17ee875 LibWeb: Rename flexible_length to flex_factor in GridSize
Let's match the name used in the spec.
2023-05-17 07:48:38 +02:00
Aliaksandr Kalenik
a3759b6e76 LibWeb: Implement more of "Expand Flexible Tracks" in GFC
Implements "Otherwise, if the free space is an indefinite length:" from
the spec.
2023-05-17 07:48:38 +02:00
Aliaksandr Kalenik
2d05c63c7c LibWeb: Skip frozen tracks while distributing space in GFC 2023-05-16 07:47:47 +02:00
Aliaksandr Kalenik
a613a0973e LibWeb: Reset item_incurred_increase before distributing space in GFC
item_incurred_increase should be reset before every next distirbution
because otherwise it will accumulate increases from previous
distributions which is not supposed to happen.
2023-05-16 07:47:47 +02:00
Aliaksandr Kalenik
ae5bb13f1f LibWeb: Do not layout grid items during grid container intrinsic sizing
There is not need to run layout inside grid items for intrinsic sizing
of grid container.
2023-05-15 16:27:53 +02:00
Aliaksandr Kalenik
1ecbbadf3a LibWeb: Fix specified_size_suggestion to use size of dimension
specified_size_suggestion() should use width or height depending on
specified dimension.
2023-05-15 16:20:51 +02:00
Aliaksandr Kalenik
daf86eaabc LibWeb: Fix UBSAN issue caused by invalid TemporaryTrack pointer in GFC
Fixes the issue when if there are enough rows/column to force
m_row_gap_tracks or m_column_gap_tracks be resized during gaps
initialization then pointers stored in m_grid_columns_and_gaps or
m_grid_rows_and_gaps become invalid.
2023-05-15 15:35:34 +02:00
Aliaksandr Kalenik
87a7299078 LibWeb: Start implementing sizing for tracks with span > 1 items in GFC
Partially implements:
- Increase sizes to accommodate spanning items crossing content-sized
  tracks
- Increase sizes to accommodate spanning items crossing flexible tracks

from https://www.w3.org/TR/css-grid-2/#algo-content
2023-05-14 19:32:34 +02:00
Aliaksandr Kalenik
7a5603052a LibWeb: Separate grid tracks from gaps in GFC
This change is supposed to solve the problem that currenty when grid
tracks are interleaved with gaps it is impossible to iterate tracks
spanned by a specific grid item. There is a pair of functions:
gap_adjusted_row() and gap_adjusted_column() but they won't work
when it comes to items spanning > 1 track.

Separating gaps from tracks is going to make it possible to iterate
just tracks or both tracks and gaps when it is required. And now tracks
spanned by an item can be accessed by just index without doing any
additional math.
2023-05-14 18:18:31 +02:00
Aliaksandr Kalenik
07b6fb9104 LibWeb: Remove unused line in calculate_min_content_size() in GFC 2023-05-14 13:45:29 +02:00
Aliaksandr Kalenik
46db51a8c0 LibWeb: Remove excessive spec referencing in GridFormattingContext
Removes unrelated to the code copy paste from spec (sometimes
duplicated).
2023-05-14 13:45:29 +02:00
Aliaksandr Kalenik
6f82079a93 LibWeb: Remove dead code in resolve_intrinsic_track_sizes() in GFC
Removes partially implemented algorithm for distributing extra space
from spanning item:
https://www.w3.org/TR/css-grid-2/#extra-space

This algorithm should not be part of resolving track sizing on its own
but instead be a subfunction of step 3:
https://www.w3.org/TR/css-grid-2/#track-size-max-content-min

There are changes in layout tests but those are not regressions.
2023-05-14 13:45:29 +02:00
Aliaksandr Kalenik
dbafb11a7e LibWeb: Flesh out basic support of min-width/height for grid items
This change brings calculate_minimum_contribution() for grid items and
supporting functions.
2023-05-13 18:43:34 +02:00
Aliaksandr Kalenik
d187862f76 LibWeb: Return grid container width from automatic_content_width in GFC
automatic_content_width() should return grid container width that is
supposed to be set by determine_intrinsic_size_of_grid_container().
2023-05-13 12:53:25 +02:00
Aliaksandr Kalenik
644e4f4c99 LibWeb: Implement grid container intrinsic sizes calculation
When a width/height constraint is applied to GFC it should set its own
width/height to the sum of track sizes according to the spec.

Changes in layout tests are improvement over what we had before.
2023-05-13 12:53:25 +02:00
Aliaksandr Kalenik
d0ce61bf13 LibWeb: Fix condition to determine auto tracks while sizing in GFC
This solves the issue when track with "fixed" min sizing function were
treated like "auto" during sizing.
2023-05-13 12:53:25 +02:00
Aliaksandr Kalenik
d7ca52afaf LibWeb: Fix typo in containing_block_size_for_item in GFC 2023-05-13 06:48:55 +02:00
Aliaksandr Kalenik
4ef997c47c LibWeb: Align calculate_min/max_content_contribution with the spec
This change brings more spec compliant implementation of functions to
calculate min/max contributions of grid items in containing block size.
2023-05-13 06:29:42 +02:00
Aliaksandr Kalenik
de970c2dce LibWeb: Resolve grid items preferred width in GFC
Previously, the width and height of grid items were set to match the
size of the grid area they belonged to. With this change, if a grid
item has preferred width or height specified to not "auto" value it
will be resolved using grid area as containing block and used instead.
2023-05-11 18:37:06 +02:00
Aliaksandr Kalenik
7fee05e18c LibWeb: Use LengthPercentage in CSS::GridSize
Using LengthPercentage instead of Length and Percentage separately
is going to allow GridSize to store calc() values. It also allows
to simplify some parts of layout code.
2023-05-11 18:36:56 +02:00
Aliaksandr Kalenik
14cb0067bb LibWeb: Implement more of "Resolve Intrinsic Track Sizes" in GFC
Implements some parts of "Resolve Intrinsic Track Sizes" algorithm
from spec to make it more spec compliant.
2023-05-10 05:52:47 +02:00
Aliaksandr Kalenik
1ada6a43e2 LibWeb: Split run_track_sizing into smaller method in GFC
Splits run_track_sizing into following methods:
- initialize_track_sizes (12.4. Initialize Track Sizes)
- resolve_intrinsic_track_sizes (12.5. Resolve Intrinsic Track Sizes)
- maximize_tracks (12.6. Maximize Tracks)
- expand_flexible_tracks (12.7 Expand Flexible Tracks)
- stretch_auto_tracks (12.8. Stretch auto Tracks)
2023-05-10 05:52:47 +02:00
Aliaksandr Kalenik
352037664d LibWeb: Use size_t instead of int when appropriate in GFC
size_t should be used instead of int in loop counter and to store
rows/columns positions because they can't be negative values.
This allows to remove some static casts to int.
2023-05-09 20:34:28 +02:00
Aliaksandr Kalenik
d9960a8d1d LibWeb: Refactor tracks initialization in GFC to reduce code duplication
This change moves code that was duplicated for rows and columns into
separate function.
2023-05-09 20:34:28 +02:00
Aliaksandr Kalenik
0a1bffdd92 LibWeb: Move gap tracks initialization into separate method in GFC 2023-05-09 20:34:28 +02:00
Aliaksandr Kalenik
62d26a5afb LibWeb: Move grid items placement algorithm into separate method in GFC
Let's follow pattern of other formatting context where steps of layout
are separated into method.
2023-05-09 20:34:28 +02:00
Aliaksandr Kalenik
fb6b52b3fb LibWeb: Align GridFormattingContext::run_track_sizing() with the spec
1. Stop using -1 to indicate infinity value of growth limit. Just use
   INFINITY for that.
2. More complete implementation of "Expand Flexible Tracks" step.
3. Return AvailableSize from get_free_space: spec says that this
   function can return indefinite size and it is ok.
2023-05-09 06:37:30 +02:00
Andreas Kling
ca1fa5f748 LibWeb: Use the new to_px() helpers in CSS, SVG and layout code
There should be no behavior change from this, only slightly less
verbosity. :^)
2023-05-06 18:41:34 +02:00
Aliaksandr Kalenik
d6ee4e7fdc LibWeb: Remove resolve_size method in GFC
Duplicate of CSS::Size::resolved().
2023-05-06 07:01:27 +02:00
Aliaksandr Kalenik
3d05ed6b53 LibWeb: Use grid_container() to access root grid box in GFC
There is grid_container() method that can be used to access root box
in GFC without passing it through methods arguments.
2023-05-06 07:01:27 +02:00
Aliaksandr Kalenik
ced862e16f LibWeb: Consolidate track sizing code for rows and columns in GFC
Although the algorithm for sizing tracks (rows or columns) is defined
once for both dimensions in the specification
(https://www.w3.org/TR/css-grid-2/#algo-track-sizing), we have
implemented it twice separately for sizing rows and columns.

In addition to code duplication, another issue is that these
implementations of the same algorithm have already diverged in some
places, and this divergence is likely to become even worse as our
implementation evolves.

This change unifies code for both dimension into one method that runs
track sizing.

While this change brings a bit of collateral damange (border.html and
minmax.html got changes in layout snaphots) it ultimately brings more
benefits because now we can evolve layout for both rows and colums
without duplicating the code :)
2023-05-06 07:01:27 +02:00
martinfalisse
c987c934d0 LibWeb: Fix grid size when intrinsically sized
This fixes a bug that was seen when a combination of the grid having
been floated with `float: left` and a `minmax()` column size were used.

The issue was that a grid track size should be considered intrinsically
sized if both the min and max sizes are intrinsic, not just one of them.
2023-04-24 07:55:40 +02:00
martinfalisse
289285cd6e LibWeb: Add borders functionality to CSS Grid 2023-04-02 19:08:04 +02:00
martinfalisse
6f52272d34 LibWeb: Fix regression in definite grid row heights
Fixes a row height bug when a grid item in a row has a definite height.
2023-04-02 19:08:04 +02:00
martinfalisse
e65f4b3dc5 LibWeb: Rename PositionedBox to GridItem
This seems like a more accurate description of what this class really
is, and easier to understand in my opinion.
2023-04-02 19:08:04 +02:00
Sam Atkins
53a4a31af2 LibWeb: Remove CalculatedStyleValue from Length 2023-03-30 21:29:50 +02:00
Andreas Kling
00999a245c LibWeb: Let FormattingContext decide the automatic width of its root
Instead of special-casing FlexFormattingContext in the intrinsic sizing
layout helpers, add FormattingContext::automatic_content_width() and let
each context subclass decide what that means.

No behavior change here, just moving this responsibility.
2023-03-20 17:57:58 +01:00
Matthew Olsson
7c0c1c8f49 LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Tom
52e45fb6fa LibWeb+Base: Fix row-height bug in Grid when there is a column gap
This fixes a bug in the CSS Grid when there is a column and/or row gap,
as previously it would take the index of the incorrect column when
finding the `AvailableSize`.

There is a mild complication in the GridFormattingContext as the
OccupationGrid does not take into account the gap columns and rows that
later appear in the `Vector<TemporaryTrack>` columns and rows. The
PositionedBoxes are kind of a connection between the two, and so it's
now more explicit whether you would like to refer to a column by its
position taking into the gap columns/rows or not.
2023-03-10 18:20:27 +01:00
Andreas Kling
8fe748bb89 LibWeb: Make grid containers be Layout::Box
Grid containers were incorrectly represented as BlockContainer before.
Furthermore, GridFormattingContext had a bogus inheritance relationship
with BlockFormattingContext.

This patch brings our architecture closer to spec by making grid
containers be plain boxes and making GFC not inherit from BFC.
2023-01-24 11:44:03 +01:00
martinfalisse
fa2c3b7c3d LibWeb: Place grid items in grid-areas if applicable
If valid grid-template-areas were given, then place grid items within
these areas. Grid-template-areas take precedence over named line
tracks, meaning if there are grid-areas as well as named tracks, should
use the grid-areas.
2023-01-21 14:35:00 +01:00
martinfalisse
47c77858b6 LibWeb: Calculate valid grid areas
When starting the GridFormattingContext, calculate the valid grid areas
as declared in the `grid-template-areas` property. Since this doesn't
change, are able to do this once and store the results.
2023-01-21 14:35:00 +01:00
martinfalisse
fa5d016176 LibWeb: Implement min/max-content
Use the min/max-content properties when given as a size for a
grid-column or grid-row.
2023-01-21 14:35:00 +01:00
martinfalisse
9d07ec3934 LibWeb: Refactor grid item positioning to use zero-index
In some sections of the code, previously would use the values passed to
`grid-column-start`, `grid-row-end`, etc. literally. Since these values
start at grid-column 1 instead of 0 (as represented in most areas in
the code), this made the code unnecessarily complicated.

Now the values are zero-indexed from the getgo.
2023-01-21 14:35:00 +01:00
martinfalisse
9d99bd8258 LibWeb: Use String class in certain CSS Grid classes
Converts the remaining instances of DeprecatedString to String in the
CSS Grid classes.
2023-01-21 14:35:00 +01:00
Sam Atkins
c70dcaefcd LibWeb: Convert LayoutState to new pixel units 2023-01-05 17:42:31 +01:00
Sam Atkins
55ddfa9348 LibWeb: Convert GridFormattingContext to new pixel units 2023-01-05 17:42:31 +01:00
Sam Atkins
f5f25562d1 LibWeb: Convert FormattingContext to new pixel units
Just FormattingContext and AvailableSpace, and the minor adjustments to
make everything else work.
2023-01-05 17:42:31 +01:00
Tom
bb062e50b0 LibWeb: Don't expand grid for {row,column} spans
Fixes a bug where when you had spans that that were bigger than the
grid, would create enough tracks to accomodate them. When a fixed
position is given, there should be at a minimum a row/column available
for the track. The span will be truncated if there is no space for it
later.
2022-12-28 15:04:58 +01:00