Commit graph

93 commits

Author SHA1 Message Date
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
Tom
6e29f693f5 LibWeb: Refactor GridFormattingContext
For legibility, split up the run() function of the GridFormattingContext
into individual components.
2022-12-28 15:04:58 +01:00
Tom
0bbf7a1b54 LibWeb: Refactor should_skip_anonymous_text_runs
This same function was being copied in the {Flex,Grid}FormattingContext,
so unify them in the parent FormattingContext.
2022-12-28 15:04:58 +01:00
Tom
9d5049230c LibWeb: Clamp {row,column} spans if outside of grid
A bug was found where grid items were being drawn outside of the grid if
the item had a large span and the grid was defined as having gaps
between the rows/columns.

This was caused by an erroneous calculation of the
{row,column}_{start,span} properties.
2022-12-26 16:02:48 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
martinfalisse
964c18419f LibWeb: Use span value if given in the grid-*-end property
Previously were not using the span value if it was given in the
grid-column/row-end properties.
2022-11-29 19:27:31 +01:00
martinfalisse
35094fc744 LibWeb: Make auto-fit compatible with grid-gap
This fixes an error when using auto-fit with grid-gap, as previously
were not taking into account the fact that more columns had been added
to the grid yet the occupation grid had not grown.
2022-11-16 00:53:00 +01:00
martinfalisse
188856c5eb LibWeb: Implement gap in CSS Grid 2022-11-07 10:06:07 +01:00
martinfalisse
2b69fa5649 LibWeb: Add some helpers for TemporaryTrack
Add some helpers to the TemporaryTrack struct to assist in making future
commits more legible.
2022-11-07 10:06:07 +01:00
martinfalisse
03949296c7 LibWeb: Calculate grid content height using column width
Should use the min_content_height function for calculating the height of
content. Thanks to previous commits, are able to use the width of the
column for this calculation.
2022-11-06 13:23:33 +01:00