Commit Graph

40 Commits

Author SHA1 Message Date
martinfalisse
937fcfc75c LibWeb+Base: Use line names for positioning grid items
When there are grid tracks with line names, use these to resolve
line-names passed to positioned grid items.
2022-11-01 11:19:41 +01:00
martinfalisse
93211f45a6 LibWeb: Use w3.org for specs and include new ones
Include new w3.org specs for the grid and correct others so they use
w3.org instead of drafts.
2022-11-01 11:19:41 +01:00
martinfalisse
b2b677e984 LibWeb: Refactor GridTrackSize classes
Refactor various classes in the GridTrackSize file for the incoming
named_tracks feature.

Previously the ExplicitTrackSizing had mixed responsiblities with the
newly-named GridRepeat class. This made it so it was not possible to
have multiple repeats within a single 'GridTrackSizeList' definition.

The MetaGridTrackSize class had both the responsibilities of being a
container for minmax values as well as for simple GridSizes. By uniting
the different possible values (repeat, minmax, default) into the
ExplicitGridTrack class are able to be more expressive as to the
different grid size modalities.

The GridTrackSizeList will be useful as compared to a
Vector<ExplicitGridTrack> since this way can keep track of the declared
line names. These same line names are able to be declared within the
values of a repeat function, hence the presence of a GridTrackSizeList
inside the GridRepeat class.
2022-11-01 11:19:41 +01:00
martinfalisse
dc9f8218a9 LibWeb: Fix bug in placing grid items
Before were resetting the auto_placement_cursor_x to 0 at the end of
the row but this was incorrect, especially since the
auto_placement_cursor_y wasn't being incremented.

This made it so that auto-placed items were occasionally placed before
absolutely-placed ones even after the latter had already been placed.
2022-11-01 11:19:41 +01:00
Johannes Laudenberg
2547e0b966 LibWeb: Use calculate_min_content_height() for sizing of grid children
When sizing grid children we now also check whether
calculate_min_content_height() adds to the computed height. Previously
we were using the result of layout_inner() which led to zero height of
not specifically sized block level children.

This fixes a height issue with our GitHub page. The footer is now at
its place and is not hovering over other content anymore.
2022-10-18 12:55:34 +02:00
martinfalisse
bd9ec60305 LibWeb: Implement minmax()
On the basis of the values passed to the minmax functions, do different
actions given different min and max grid track sizes.
2022-10-15 16:04:01 +02:00
martinfalisse
53f3df78e5 LibWeb: Implement auto-fill and auto-fit
Implement auto-fill and auto-fit for the grid, which allow for placing
as many columns as will fit within a given container size.
2022-10-15 16:04:01 +02:00
martinfalisse
4745a0c20a LibWeb: Implement more of the grid spec
This is a small change that implements more of the CSS Grid spec.
2022-10-15 16:04:01 +02:00
martinfalisse
202620e80c LibWeb: Refactor GridTrack maintenance in the GFC
Refactor the m_grid_columns and m_grid_rows to be maintained in the
class, which will make it easier to later create functions relating to
them.
2022-10-15 16:04:01 +02:00
martinfalisse
b6a29ae9e2 LibWeb: Use w3 instead of drafts for spec
Add more specs to the CSS Grid class and update others so as to use
w3.org instead of the drafts website.
2022-10-15 16:04:01 +02:00
martinfalisse
f7af190de0 LibWeb: Add parent classes for managing GridTrackSizes
Add classes ExplicitTrackSizing and MetaGridTrackSize which will allow
for managing properties like auto-fill and minmax.

In the following CSS example there are 3 classes that will be used:
grid-template-column: repeat(auto-fill, minmax(50px, 1fr) 75px);

ExplicitTrackSizing - will contain the entire value. e.g.
repeat(auto-fill, minmax(50px, 1fr) 75px)

With a flag if it's a repeat, as well as references to the
MetaGridTrackSizes which is the next step down.

MetaGridTrackSize:
Contain the individual grid track sizes. Here there are two:
minmax(50px, 1fr) as well as 75px.

This way can keep track if it's a minmax function or not, and the
references to both GridTrackSizes in the case it is, or in just the one
if it is not.

GridTrackSize:
Is the most basic element, in this case there are three in total; two of
which are held by the first MetaGridTrackSize, and the third is held by
the second MetaGridTrackSize.
Examples: 50px, 1fr and 75px.
2022-10-15 16:04:01 +02:00
martinfalisse
e537035cc6 LibWeb+Base: Deal with column-spans greater than implicit grid
When the indicated column-span is greater than the implicit grid (like
in cases when the grid has the default size of 1x1, and the column is
supposed to span any number greater than that), then previously were
crashing.
2022-10-08 17:26:41 +02:00
martinfalisse
994d996ab2 LibWeb: Fix bug in maybe_add_column()
Fixes a bug in the maybe_add_column() implementation of the
OccupationGrid. Previously were checking for the width of the grid based
off of the first row, and so when augmenting the column count row-by-row
the latter rows would have differing column counts.

Also, were doing an unnecessary + 1 which I imagine comes from before
when I wasn't quite clear on whether I was referring to columns by
index or by the css-value of the column (column 1 in the css is
column index 0).
2022-10-08 17:26:41 +02:00
martinfalisse
84290ed7c8 Base+LibWeb: Make sure grid positions don't cause out of bounds
Add some tests to the test page to make sure that different combinations
of GridTrackPlacement don't cause out of bounds issues.
2022-10-06 21:16:01 +02:00
martinfalisse
9051a56554 Base+LibWeb: Stub out negative spans
Ensure that when a grid item is passed with a span and a fixed end
position, that if the resulting start of this item is less than 0 then
it won't throw. This is a temporary measure until the correct
functionality is implemented.
2022-10-06 21:16:01 +02:00
martinfalisse
a764e43db3 LibWeb: Factor out OccupationGrid functions
Clean up the code by using an OccupationGrid class. This was a neat idea
proposed by MacDue.
2022-10-06 21:16:01 +02:00
martinfalisse
db19570b94 LibWeb: Truncate oversized grid spans
If a span makes a CSS Grid item overflow vertically, then it should be
truncated as done on other web engines.
2022-10-06 21:16:01 +02:00
martinfalisse
f3bf01f265 LibWeb: Fix bug in placing row-constrained grid items
For row-constrained items (with a row position defined in the CSS),
should be checking for an available position in that row and not in
another..
2022-10-06 21:16:01 +02:00
martinfalisse
a528ea71d1 LibWeb: Use span values for auto-positioned grid items
Auto-positioned items should also take into account the span attributes
passed to them.
2022-10-06 21:16:01 +02:00
martinfalisse
330af1a769 LibWeb: Fix bug in spec implementation auto_placement_cursor 2022-10-06 21:16:01 +02:00
martinfalisse
93824edeb7 LibWeb: Fix implementation bugs of grid track is_span()
After having corrected the tracking of span variables in the
GridTrackPlacement class, now can fix some small bugs for its correct
implementation in the GridFormattingContext class.
2022-10-06 21:16:01 +02:00
martinfalisse
9fd07e9cb1 LibWeb: Make it easier to check if grid track is auto positioned
Add some helper functions for checking if a grid-track is
auto-positioned. I think this makes the code more legible.
2022-10-06 21:16:01 +02:00
martinfalisse
236795e931 LibWeb+Base: Re-implement grid track span
Implement span correctly when indicated in the grid-column-start,
grid-row-start, etc. CSS properties. Previously it had been implemented
as if span was something that went alongside the position property, but
actually it seems like if you do 'span 3' in the grid-column-start
property, for example, this means it literally spans 3 blocks, and the
3 has nothing to do with position.
2022-10-06 21:16:01 +02:00
Andreas Kling
9c44634ca5 LibWeb: Reorganize layout algorithms around available space
This is a big and messy change, and here's the gist:

- AvaliableSpace is now 2x AvailableSize (width and height)

- Layout algorithms are redesigned around the idea of available space

- When doing layout across nested formatting contexts, the parent
  context tells the child context how much space is available for the
  child's root box in both axes.

- "Available space" replaces "containing block width" in most places.

- The width and height in a box's UsedValues are considered to be
  definite after they're assigned to. Marking something as having
  definite size is no longer a separate step,

This probably introduces various regressions, but the big win here is
that our layout system now works with available space, just like the
specs are written. Fixing issues will be much easier going forward,
since you don't need to do nearly as much conversion from "spec logic"
to "LibWeb logic" as you previously did.
2022-10-02 21:14:02 +02:00
Andreas Kling
f161e20e57 LibWeb: Make FormattingContext::run() take available space as input
Instead of formatting contexts flailing around to figure out from the
"inside" how much space is available on the "outside", we should
provide the amount of available space in both axes as an input to run().

This basically means that when something creates a nested formatting
context, the parent context is responsible for telling the nested context
how much space is available for layout. This information is provided
immediately when invoking run().

Note that this commit doesn't pass accurate values in all cases yet.
This first step just makes it build, and passes available values in some
cases where getting them was trivial.
2022-09-29 18:33:41 +02:00
Andreas Kling
62974160da LibWeb: Add FormattingContext::automatic_content_height()
This function should return the automatic height of the formatting
context's root box.

Until now, we've been relying on some magical handshakes between parent
and child context, when negotiating the height of child context root
boxes. This is a step towards something more reasonable.
2022-09-24 13:41:08 +02:00
martinfalisse
df22f38feb LibWeb: Inform the parent context of the grid's size 2022-09-14 00:09:14 +02:00
martinfalisse
214329b81c LibWeb: Layout grid items after calculation
Now that the positions of each grid item have been calculated, and the
sizes of the individual rows and columns ascertained, can actually
layout the different items.
2022-09-14 00:09:14 +02:00
martinfalisse
58078c1f40 LibWeb: Calculate sizes of Auto grid tracks 2022-09-14 00:09:14 +02:00
martinfalisse
f558fd93b7 LibWeb: Calculate sizes of FlexibleLength grid tracks 2022-09-14 00:09:14 +02:00
martinfalisse
fbe703e2bd LibWeb: Follow spec for calculating intrinsic track sizes 2022-09-14 00:09:14 +02:00
martinfalisse
b7d053421e LibWeb: Calculate sizes of known grid track sizes
Calculate the sizes of grid tracks for which there is a clear size
(length or percentage has been specified).
2022-09-14 00:09:14 +02:00
martinfalisse
6b649b6343 LibWeb: Start sizing grid tracks
The second part of formatting the display grid is calculating the sizes
of the columns and rows.
2022-09-14 00:09:14 +02:00
martinfalisse
902bdc8f15 LibWeb: Position remaining grid items 2022-09-14 00:09:14 +02:00
martinfalisse
707b76ed41 LibWeb: Position grid items with fixed row positions 2022-09-14 00:09:14 +02:00
martinfalisse
f143fefca2 LibWeb: Position grid items with fixed position values 2022-09-14 00:09:14 +02:00
martinfalisse
e0cd63f531 LibWeb: Add array to keep track of grid boxes left to place
This structure will be useful to subtract from after placing different
boxes into the grid.
2022-09-14 00:09:14 +02:00
martinfalisse
a2ecb903af LibWeb: New start at layouting out the grid
According to the spec it's necessary to:
1. Layout the cells in the grid
2. Find the sizes of the rows and columns

Since I had started to do this backwards, and as I expand in future
commits, I take here the opportunity to start with a clean state.

The occupation_grid keeps track of which cells in the grid have been
filled out.
2022-09-14 00:09:14 +02:00
martinfalisse
79a630adef LibWeb: Begin formatting the grid
This is a really starter attempt at formatting the grid. It doesn't yet
take into account the computed_values of grid-template-rows, nor the
values in grid-column-start and like CSS properties.

But these changes are a start and make it so the examples in
display-grid.html work.

To be fleshed out further..
2022-08-25 13:47:48 +02:00
martinfalisse
e4c5799026 LibWeb: Add GridFormattingContext 2022-08-25 13:47:48 +02:00