Commit graph

137 commits

Author SHA1 Message Date
Aliaksandr Kalenik 3a605d8c19 LibWeb: Set width in compute_width_for_table_wrapper()
Width of table wrapper need to be set to to calculate width of table
box inside. Otherwise TFC will set wrong width assuming width of
containing block is 0.
2023-05-07 06:31:53 +02:00
Andreas Kling fc3c3aef22 LibWeb: Enforce min/max height constraints on abspos replaced boxes
Fixes #18658
2023-05-07 06:28:47 +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
0GreenClover0 8bb2663a22 LibWeb: Zero out margins if width is not 'auto' in BFC's compute_width
Reverse the condition to satisfy the spec comment. Probably a typo.
A 3 year old typo! :^)
2023-05-05 13:26:41 +02:00
Aliaksandr Kalenik 34b1186272 LibWeb: Remove early resolve to auto while calculating border-box width
`Length::resolved(Node&)` transforms infinite values to "auto".

Following transformations:
Infinite (Length) -> "auto" -> 0 (px)
cause border-box width to be resolved in zero when it should be inf px.

Removing `Length::resolved(Node&)` makes it work right:
Infinite (Length) -> Infinite (px)

Fixes #18649
2023-05-05 10:01:28 +02:00
Aliaksandr Kalenik 0318ac5ce4 LibWeb: Remove setting length to 0px if it is not definite
If available width (or height) is max-content and width (or height)
value is 100% it should be resolved in infinite px, not 0 px.

Fixes #18639
2023-05-05 06:20:44 +02:00
Aliaksandr Kalenik 853ecb8d8e LibWeb: Narrow width of boxes that create BFC to avoid overlap of float
https://www.w3.org/TR/CSS22/visuren.html#floats says that when a box
establishes BFC it should not overlap with floats. The way to avoid
overlaps is up to implementor. This change implements avoiding overlap
by narrowing width of a box because it seems like what other engines
do (in the scenarios I tested).
2023-05-04 06:14:58 +02:00
Andreas Kling 590723aa3b LibWeb: Implement the "The html element fills the viewport quirk"
Fixes #18037.
2023-05-03 20:44:30 +02:00
Andreas Kling 508927cae2 LibWeb: Take floats into account when measuring automatic width of IFC
When there are floats present inside an IFC, we must coordinate with
the parent BFC to calculate the automatic width of the IFC's block box.
This is because the IFC is not directly aware of floats. Only the BFC
knows enough about them to account for them in automatic sizing.
2023-05-03 19:49:43 +02:00
Andreas Kling 610a7603a2 LibWeb: Implement more box type transformation edge cases
In particular, we now blockify layout internal boxes (e.g table parts)
by turning them into `block flow`. This fixes a crash when viewing
our GitHub repo :^)
2023-05-03 16:04:30 +02:00
Aliaksandr Kalenik 09d698e0a0 LibWeb: Exclude table-wrapper margins from table available width
Table should not take up more width than is available inside wrapper
after margins are taken in account.
2023-05-03 15:03:56 +02:00
Aliaksandr Kalenik 4d971b5bc5 LibWeb: Use appropriate containing block width to get width of table
This solves the issue that previously width table-wrapper containing
block were used in the places were containing block of table-root
should be used.
2023-05-03 15:03:56 +02:00
Andreas Kling 968db96101 LibWeb: Show formatting context roots in layout tree dumps
This patch does three things:

- Factors out the code that determines whether a box will create a new
  formatting context for its children (and which type of context)

- Uses that code to mark all formatting context roots in layout tree
  dumps. This makes it much easier to follow along with layout since
  you can now see exactly where control is transferred to a new
  formatting context.

- Rebaselines all existing layout tests, since the output format has
  changed slightly.
2023-05-03 13:14:36 +02:00
Aliaksandr Kalenik f6ff37398c LibWeb: Fix intrinsic sizing when min or max width is specified
Fixes the problem that width is incorrectly computed in intrinsic
sizing mode when there are blocks that have min-width or max-width
specified.

Actually that is just the fix of a symptom of the larger problem that
Length::to_px() returns 0 when value is auto regardless of available
size.
2023-05-02 18:50:26 +02:00
Aliaksandr Kalenik 6cec431720 LibWeb: Set zero underflow when calculating intrinsic width of block
This fix resolves issue where calculating the min size of a block could
result in incorrect value if width of the block's children was
compensated by margins to fit into container width (which is equal to 0
during min size calculation).
2023-05-02 12:41:45 +02:00
Andreas Kling 00e3e82bbd LibWeb: Account for box-sizing:border-box in layout-less definite sizes
When we determine that a size is definite because it can be resolved now
without performing layout, we also need to account for the box-sizing
property.

This lets us remove a hack from flex layout where box-sizing:border-box
was manually undone at one point in the layout algorithm.
2023-05-02 11:47:13 +02:00
martinfalisse 22202715fc LibWeb: Parse grid-template property 2023-04-30 05:56:10 +02:00
Andreas Kling 5236819f58 LibWeb: Resolve horizontal auto margins for images with display: block 2023-04-30 05:52:19 +02:00
Aliaksandr Kalenik e54ee7de96 LibWeb: Exclude borders from width available for table columns
Fix table box width calculation to minus horizonal borders from space
available for columns.
2023-04-29 16:08:48 +02:00
Aliaksandr Kalenik d9f0c2a806 LibWeb: Implement "distribute height to rows" step in TFC
This commit implements following missing steps in table layout:
- Calculate final table height
- Resolve percentage height of cells and rows using final table height
- Distribute avilable height to table rows
2023-04-29 06:46:45 +02:00
Aliaksandr Kalenik 9fd51a59ff LibWeb: Fix division by zero in table columns width distribution
If total max columns width (grid_max) is zero then available width
should be divided equally between columns. Previously there was
division by zero: `column.max_width / grid_max`.
2023-04-29 06:46:45 +02:00
Emil Militzer a8d08357c9 LibWeb: Compute inset for relative positioned inline-block 2023-04-28 18:12:02 +02:00
Aliaksandr Kalenik 2a1e58f8cc LibWeb: Consider cell computed height in total row min height of table
Previously, the minimum height of a table row was calculated based
on the automatic height of the cells inner layout. This change makes
computed height of a cell boxes also be considered if it has definite
value.
2023-04-28 06:17:07 +02:00
Aliaksandr Kalenik 9b4cd0dab7 LibWeb: Consider row computed height in total row min height of table
Fixes the issue that currently we do not consider table rows height
while calculating min row height even if it is definite value.
2023-04-28 06:17:07 +02:00
Andreas Kling c0b4083b02 LibWeb: Blockify pseudo elements that are flex items
When deciding on a box type transformation (blockify/inlinify) for a
pseudo element, we have to use the originating element as a reference
rather than the parent.

(The originating element *is* the parent for its pseudo elements.)
2023-04-27 18:29:02 +02:00
Andreas Kling d053cb6fae LibWeb: Fix bug where box-sizing: border-box made flex items too small
If a flex item has a preferred cross size of "auto", we should not be
subtracting padding and border in the cross axis when computing the
cross size.
2023-04-27 13:57:52 +02:00
Aliaksandr Kalenik 9ee64b5694 LibWeb: Prevent margin double-counting with "collapse through" boxes
If there is a remaining margin-bottom in margin collapsing state
tracker after laying out all boxes in the current BFC, it must be
assigned to the last in-flow child since margin collapsing cannot
occur across a formatting context boundary.

The current issue where margin-bottom may be counted twice due to
"collapse through" margins in the last in-flow child box is addressed
with this fix by excluding such boxes during the search for a box to
assign the remaining margin.

Test case coming with this fix has a layout bug with incorrectly
computed line height.
2023-04-27 07:52:12 +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
Aliaksandr Kalenik ce483fb2c9 Tests/LibWeb: Time limit layout tests
This change will prevent CI runners from being stuck trying to run
layout tests on PR that made browser hang.
2023-04-21 11:00:21 +01:00
Andreas Kling 8c03d21e95 LibWeb: Fix broken handling of flex: <flex-grow> shorthand
This is a tiny bit messy because:

- The spec says we should expand this to `flex: <flex-grow> 1 0`
- All major engines expand it to `flex: <flex-grow> 1 0%`

Spec bug: https://github.com/w3c/csswg-drafts/issues/5742
2023-04-19 12:07:16 +02:00
Andreas Kling ce5a939148 LibWeb: Layout <svg> nested inside <svg>
This is far from perfect, but let's at least make an attempt at laying
out <svg> when encountering it inside another <svg>.

This makes https://awesomekling.substack.com actually load and render
instead of asserting. :^)
2023-04-19 07:52:26 +02:00
Andreas Kling 0d5e0d27aa LibWeb: Treat unresolvable percentage flex-basis values as 'content'
Per CSS-FLEXBOX-1, we should treat percentage values of flex-basis as
'content' if they resolve against an indefinite size of the flex
container.
2023-04-18 10:06:02 +02:00
Andreas Kling c710575f88 LibWeb: Honor box-sizing in flex item "specified size suggestion"
Although the spec doesn't mention it, if a flex item has box-sizing:
border-box, and the specified size suggestion is a definite size, we
have to subtract the borders and padding from the size before using it.

This fixes an issue seen in "This Week in Ladybird #4" where the
screenshots ended up in one long vertical stack instead of paired up
2 by 2.
2023-04-17 18:22:53 +02:00
Andreas Kling 7f79208759 LibWeb: Support implicit lineto commands after moveto in SVG paths
Per SVG2, any coordinate pairs following a moveto command should be
treated as implicit lineto commands with the same absoluteness as the
moveto command.
2023-04-17 14:18:45 +02:00
MacDue f0dde6236d Tests: Add layout test for SVG preserveAspectRatio
This is a cut down version of the example, but it's nice to add a
test to ensure this keeps working.
2023-04-17 07:32:31 +02:00
MacDue 5df4e64eb7 LibWeb: Implement SVG preserveAspectRatio attribute
This attribute is used to define how the viewBox should be scaled.
Previously the behaviour implemented was that of "xMidYMid meet", now
all of them work (expect none :P).

With this the Discord login backend is now correctly scaled/positioned.

This also brings our SVG code a little closer to the spec! With spec
comments and all :^)

(Minor non-visible update to layout tests)
2023-04-17 07:32:31 +02:00
Andreas Kling e7f5b5a2f3 LibWeb: Fix multi-line flex column layouts with auto height on container
When sizing a flex container with flex-direction:column under a
max-content height constraint, we were incorrectly truncating the
infinite available height to 0 when collecting flex items into lines.

This caused us to put every flex item in its own flex line, which is the
complete opposite of what we want during max-content intrinsic sizing,
as the layout would grow wide but not tall.
2023-04-16 21:45:15 +02:00
Andreas Kling b9b6037d2b LibWeb: Honor gap between flex lines when using align-content: stretch
We have to take the cross gap into account when calculating the "sum of
flex line cross sizes" in "Handle 'align-content: stretch'".
2023-04-16 20:52:32 +02:00
MacDue f9c61e3ba7 LibWeb: Scale SVG stroke-width based on viewbox
This fixes the clipping of strokes in quite a few cases and now fixes
the Gartic Phone logo :^)

(Layout test updated but no visible changes there)
2023-04-15 19:28:13 +02:00
Andreas Kling 47c21cc349 LibWeb: Honor column-gap and row-gap CSS properties in flex layout
This isn't actually part of CSS-FLEXBOX-1, but all major engines honor
these properties in flex layout, and it's widely used on the web.

There's a bug open against the flexbox spec where fantasai says the
algorithm will be updated in CSS-FLEXBOX-2:
https://github.com/w3c/csswg-drafts/issues/2336

I've added comments to all the places where we adjust calculations for
gaps with "CSS-FLEXBOX-2" so we can find them easily. When that spec
becomes available, we can add proper spec links.
2023-04-14 13:22:07 +02:00
Sam Atkins d0f80b40b2 LibWeb: Reimplement CalculatedStyleValue as a calculation node tree
VALUES-4 defines the internal representation of `calc()` as a tree of
calculation nodes. ( https://www.w3.org/TR/css-values-4/#calc-internal )

VALUES-3 lacked any definition here, so we had our own ad-hoc
implementation based around the spec grammar. This commit replaces that
with CalculationNodes representing each possible node in the tree.

There are no intended functional changes, though we do now support
nested calc() which previously did not work. For example:
    `width: calc( 42 * calc(3 + 7) );`

I have added an example of this to our test page.

A couple of the layout tests that used `calc()` now return values that
are 0.5px different from before. There's no visual difference, so I
have updated the tests to use the new results.
2023-04-13 09:53:47 +02:00
MacDue 5abffc9c5a Tests: Add layout test for SVG transforms and viewboxes
Now that these are kind of working, lets add a layout test to prevent
future regressions :^)

This test is the same as the previous example (it is copied, though
that seems to have been done for other tests, e.g. Acid 1).
2023-04-12 07:40:22 +02:00
martinfalisse c839c51b0b LibWeb: Use max-width property in table formatting 2023-04-07 10:42:26 +02:00
martinfalisse 1440845aad LibWeb: Add table formatting tests
Creates some TableFormattingContext tests based on the tests in
/html/misc.
2023-04-07 10:42:26 +02:00
martinfalisse c421f1692c LibWeb: Move table tests to their own folder 2023-04-07 10:42:26 +02:00
Andreas Kling 7b4c76788b LibWeb: Don't put abspos grid/flex items in anonymous wrapper
Grid and flex containers have their own rules for abspos items, so we
shouldn't try to be clever and put them in the "current" anonymous
wrapper block. That behavior is primarily for the benefit of block &
inline layout.
2023-04-07 10:15:16 +02:00
Andreas Kling b97229c9b5 LibWeb: Ignore preferred width when calculating intrinsic width of block
When calculating the intrinsic width of a block-level box, we now ignore
the preferred width entirely, and not just when the preferred width
should be treated as auto.

The condition for this was both confused and wrong, as it looked at the
available width around the box, but didn't check for a width constraint
on the box itself.

Just because the available width has an intrinsic sizing constraint
doesn't mean that the box is undergoing intrinsic sizing. It could also
be the box's containing block!
2023-04-06 16:47:40 +02:00
Andreas Kling 68459d43e0 Tests/LibWeb: Move block & inline layout tests into own directory 2023-04-06 16:47:40 +02:00
matcool cc33a57620 LibWeb: Use intrinsic aspect ratio when calculating max content height 2023-04-05 16:23:56 +02:00
martinfalisse 289285cd6e LibWeb: Add borders functionality to CSS Grid 2023-04-02 19:08:04 +02:00