Commit graph

313 commits

Author SHA1 Message Date
Andi Gallo 8afe5ce718 LibWeb: Fix min-content initialization for row measures
This ensures that min-content contributions from cells with no content
are computed using their calculated values, which are never considered
for min-content before then. The specification diverges from column
measures algorithm, which doesn't use specified width of cells anywhere.
2023-06-26 19:25:34 +02:00
Andi Gallo 3a0f7e8eb8 LibWeb: Adjust specified table height
Subtract borders and padding from specified height before comparing to
the used content height.
2023-06-25 15:08:42 +02:00
FalseHonesty 110eeb8591 LibWeb: Support calc(...) in box-shadow's values of type Length
The CSS box-shadow property takes 2-4 properties that are `<length>`s,
those being:
  - offset-x
  - offset-y
  - blur-radius
  - spread-radius

Previously these were resolved directly to concrete Lengths at parse
time, but now they will be parsed as LengthStyleValues and/or
CalculatedStyleValues and be stored that way until styles are later
resolved.
2023-06-25 10:27:08 +01:00
Andi Gallo 8b34af816e LibWeb: Report border box width for tables in a block
For the containing block, table borders are opaque and have to be
accounted when computing the table width since they use available space.
2023-06-25 08:13:04 +02:00
Andi Gallo 2c4908094c LibWeb: Don't subtract border from used table width
The used width is already a content width, which doesn't include
borders. Border widths should be subtracted from the specified width
instead, since that initially specifies the total width including
borders, for consistent comparison. Also handle table box padding as an
additional fix.
2023-06-25 08:13:04 +02:00
Andi Gallo fc45831fb3 LibWeb/Tests: Better trigger for table style update test 2023-06-23 20:23:00 +02:00
Andi Gallo 55f1a70577 LibWeb: Fix style updates for table box nodes
On style update, we have to preserve the invariant established when we
built the layout tree - some properties are applied to the table wrapper
and the table box values are reset to their initial values.

This also ensures that the containing block of a table box is always a
table wrapper, which isn't the case if we set absolute position on the
box instead of the wrapper.

Fixes #19452.
2023-06-23 16:40:19 +02:00
Shannon Booth a92d94f4e9 LibWeb/Tests: Add basic test for ByteLengthQueuingStrategy 2023-06-23 13:27:29 +02:00
Shannon Booth b2a51e86e5 LibWeb/Tests: Add basic test for CountQueuingStrategy 2023-06-23 13:27:29 +02:00
Andi Gallo 8e52d1125d LibWeb: Take specified height into account for automatic table height
Track table grid height stretched to the specified height and use it to
set the final box height in TFC.

Fixes #19563.
2023-06-23 06:24:08 +02:00
Aliaksandr Kalenik 473848be0e LibWeb: Do not treat size of abspos items as definite
This fixes the issue when size of abspos items is considered to be
resolvable without performing layout which is not correct in the
scenarious when top/right/bottom/left properties are not auto.
2023-06-22 18:18:04 +02:00
Aliaksandr Kalenik 20edbb70f8 LibWeb: Implement distributing space to tracks beyond limits in GFC
Implements "Distribute space beyond limits" step from:
https://www.w3.org/TR/css-grid-2/#distribute-extra-space
2023-06-22 06:48:12 +02:00
Andi Gallo caa24d0805 LibWeb: Implement top and bottom vertical-align for table cells 2023-06-22 06:45:58 +02:00
Aliaksandr Kalenik 8c980cf75b LibWeb: Do not crash inside SVGDecodedImageData on invalid SVG input
Return error when input svg is not valid and SVGSVGElement is not
present in the tree instead of doing svg_root nullptr dereference.

Fixes crash on https://apps.kde.org/en-gb/
2023-06-21 19:10:37 +02:00
Shannon Booth 464e428e94 LibWeb/Tests: Add basic tests for {ByteLength,Counting}QueuingStrategy 2023-06-21 12:27:04 +02:00
Andi Gallo 5bd9f4c31c LibWeb: Add undistributable space to GRID{MIN, MAX} instead of content
Adding undistributable space right before setting the content width is
incorrect when it's a percentage. Follow the specification and add it to
GRIDMIN and GRIDMAX instead.
2023-06-21 06:15:04 +02:00
Aliaksandr Kalenik a8211abc1e LibWeb: Support CSS functions other than calc() for grid sizes
Makes grid size parser to handle not only calc() but min(), max() and
other CSS functions we support.
2023-06-21 06:14:51 +02:00
Luke Wilde f4446cdf8c LibWeb: Resolve padding against 0 and not inf for indefinite width more
In particular, in BFC:
- Non-floating, non-replaced elements
- Floating, non-replaced elements
- Floating, replaced elements

The first two regressed in 1d76126abe

The third one seems to have been introduced by this regression, as it
was seemingly copied from compute_width_for_floating_box in
7f9ede07bc
2023-06-21 06:13:05 +02:00
Andreas Kling 0ec522ab54 LibWeb: Don't infer SVG viewBox if width and/or height is zero
The fix here has two parts:
1. Don't use the fallback viewBox at all if we're not in SVG-as-image.
2. Don't make a fallback viewBox with zero width and/or height.

This fixes a crash on Bandcamp pages. Thanks Tim Flynn for reporting!
2023-06-20 20:55:12 +02:00
Aliaksandr Kalenik 21f39061fd LibWeb: Set 0px fixed size to collapsed auto-fit tracks in GFC
Fixes the issue that before we set base_size and growth_limit of
collapsed tracks to 0px which still allowed them to grow by space
distribution.
2023-06-20 18:24:26 +02:00
Andi Gallo e4d0c077c3 LibWeb: Don't skip width computation for intrinsic table width
The shortcut we put in place didn't resolve percentage widths and
ignored border spacing. We can still return early after we compute the
width per the specifications.
2023-06-20 18:24:19 +02:00
Andreas Kling c808f6c637 LibWeb: Don't use BFC auto height for non-BFC abspos elements
While CSS 2.2 does tell us to use the "auto height for BFC roots"
calculation when resolving auto heights for abspos elements, that
doesn't make sense for other formatting context roots, e.g flex.

In lieu of implementing the entire new absolute positioning model from
CSS-POSITION-3, this patch borrows one small nugget from it: using
fit-content height as the auto height for non-BFC-root abspos elements.
2023-06-20 13:42:31 +02:00
Andreas Kling 38a6b7ad3d LibWeb: Don't assert when flex-item has align-self: end
We were missing the code to convert this to `align-items: end`.
2023-06-20 13:26:41 +02:00
Andreas Kling 9f24c1b34c LibWeb: Use width & height to create fallback viewBox for SVG-as-image
When embedding an SVG in an img element, if the external SVG's root
element has both width and height attributes, but no viewBox attribute,
we now create a fallback viewBox with "0 0 width height".

This appears to match the behavior of other browsers. Inspired by
discussion on Mozilla's bug tracker:
https://bugzilla.mozilla.org/show_bug.cgi?id=614649
2023-06-20 11:34:09 +02:00
Andreas Kling a0b4987e92 headless-browser: Paint while running layout tests (but discard results)
If we don't paint, SVG-as-image documents don't get laid out, and so
have 0x0 size throughout.

This change is also generally nice, as it makes the painting code run
on all the layout tests, increasing coverage. :^)
2023-06-20 11:34:09 +02:00
Andi Gallo ac6af51549 LibWeb: Improve span column width distribution
Compute the contributions to a spanning cell width from each cell in the
span. This better handles uneven column widths, since each cell
contribution is proportional with its own width as opposed to the own
width of the first cell in the span.

This better matches the behavior of other browsers and further aligns
with the specification.
2023-06-20 06:59:43 +02:00
Andreas Kling e99a6fede4 LibWeb: Allow IFC to size inline-flex boxes midway through flex layout
The part in FFC where we ask the parent formatting context to size the
flex container midway through layout is really weird, but let's at least
be consistently weird for BFC and IFC. Since IFC always works within its
parent BFC, it can simply forward these requests to the BFC.

This fixes an issue where inline-flex containers incorrectly had main
axis margins subtracted from their content size.
2023-06-19 18:51:00 +02:00
Andreas Kling 1b55ff6f4c LibWeb: Expand CSS var() inside calc() paren blocks
Before this change, this var() would get expanded:

    calc(10px * var(--one))

But this one would not:

    calc(10px * (var(--one))
2023-06-19 17:54:07 +02:00
Andi Gallo 701b170dc0 LibWeb: Clip cell spans past the end of the table
This occurs on Wikipedia for tournament brackets, for example:
https://en.wikipedia.org/wiki/2022%E2%80%9323_UEFA_Champions_League_knockout_phase
2023-06-19 13:19:55 +02:00
Andi Gallo 205f9c75d9 LibWeb: Fix empty slot finding in table formation algorithm
The algorithm which finds the first free slot must run for every cell,
not for every row.
2023-06-19 13:19:32 +02:00
Andi Gallo f154446a9f LibWeb: Skip separate height computation for tables
With multi-line text cells, we don't reliably know the height would stay
the same as the one set by the independent format context run. In such
situations, we can end up with a table box which is sized inconsistently
with the grid boxes of the table due to differences in line breaks.
2023-06-18 20:55:06 +02:00
Aliaksandr Kalenik ca0c2339f4 LibWeb: Use padding box of containing block to resolve % height size
From CSS-POSITION-3 <https://www.w3.org/TR/css-position-3/#def-cb>

"..the containing block is formed by the padding edge of the ancestor.."

Fixes crash on Acid2 test.
2023-06-18 20:29:40 +02:00
Andi Gallo db121c7af1 LibWeb: Handle leading whitespace in grid-template-* block components
We're already handling whitespace between components, do the same for
leading whitespace. Fixes crash on https://distill.pub/2021/gnn-intro.
2023-06-18 13:41:15 +02:00
Andi Gallo c5eeb303d8 LibWeb: Don't cap used width by available width from a constraint
In compute_table_box_width_inside_table_wrapper, we should only consider
available_width when it's valid. Values which come from {min,
max}-content constraints aren't meaningful and shouldn't be considered
for the cap.
2023-06-18 08:27:24 +02:00
Andreas Kling c374541711 LibWeb: Use correct reference for abspos elements with % height sizes
Absolutely positioned elements should have their percentage sizes
resolved against the padding box of the containing block, not the
content box.

From CSS-POSITION-3 <https://www.w3.org/TR/css-position-3/#def-cb>

"..the containing block is formed by the padding edge of the ancestor.."
2023-06-17 20:35:19 +02:00
Andi Gallo 52956d355c LibWeb: Make border-collapse actually inherited
Move it to the inherited section of ComputedValues.
2023-06-16 17:21:15 +02:00
Andreas Kling a988241f3f LibWeb: Resolve % min-sizes against 0 while under min-content constraint
When resolving a percentage min-width or min-height size against a
containing block currently under a min-content constraint, we should act
as if the containing block has zero size in that axis.
2023-06-16 14:39:03 +02:00
Andreas Kling 1578121dcb Tests/LibWeb: Fix typo in test
"display: max-content" is not a thing. The test was actually not working
correctly, it just looked like it did. Now it has correct metrics for
the body element.
2023-06-16 14:39:03 +02:00
Andi Gallo b69036970b LibWeb: Add layout support for border spacing
When border-collapse is separate, border-spacing affects layout.
Implement most of that functionality.
2023-06-16 13:57:31 +02:00
kamp 23aae7c7f3 LibWeb: Implement the align attribute for divs
As specified in section 15.3.3 of the HTML spec.
2023-06-16 06:55:21 +02:00
Aliaksandr Kalenik c48f60a98d Tests/LibWeb: Add a flag to update expectation metadata in WPT runner
Adds `--update-expectations-metadata` that allows to automatically
rebuild metadata.txt file with test expectations.
2023-06-14 20:50:32 +02:00
Aliaksandr Kalenik 67de71d302 Tests/LibWeb: Do not fail WPT tests on unexpected results
Since both the WebDriver and Browser API are currently unstable during
WPT tests, it's a good idea to make sure that WPT passes even if there
are unexpected results. This will help avoid having failures marked as
red in the CI system caused by flaky WPT tests.
2023-06-14 20:50:32 +02:00
Andreas Kling 3a11b55286 LibWeb: Treat % max-width as none when containing block size indefinite
This is technically "undefined behavior" per CSS 2.2, but it seems
sensible to mirror the behavior of max-height in the same situation.
It also appears to match how other engines behave.

Fixes #19242
2023-06-14 20:12:02 +02:00
Andreas Kling 43e1343abf LibWeb: Treat % max-height as none when containing block size indefinite
Fixes #19371
2023-06-14 17:08:15 +02:00
Andi Gallo ce186dca70 LibWeb: Fix the x coordinate of a block after a float
The margin from the containing blocks shouldn't be included in the
amount by which we increment x after a float was places. That coordinate
should be relative to the containing block.

Fixes the comments layout on https://lobste.rs.
2023-06-14 08:30:22 +02:00
Aliaksandr Kalenik a414ddcbf3 LibWeb: Add a script to run Web Platform Tests
Introduce very initial and basic support for running Web Platform Tests
for Ladybird. This change includes simple bash script that currently
works only on Debian and could run tests with patched runner.

For now script to run WPT is not integrated in CI.

There is also a bunch of metadata required to run WPT. To avoid
introducing thousands of files in the initial commit for now it is
limited to run only css/CSS2/floats tests subdirectory.
2023-06-14 06:45:04 +02:00
Andreas Kling 41da9a4231 LibWeb: Resolve auto margins on abspos elements in more cases
Specifically, we now handle cases where all three of `left`, `width`
and `right` are non-`auto`.
2023-06-13 17:47:50 +02:00
Andreas Kling 434df52b91 LibWeb: Make stretch-fit return 0 when the available size is indefinite
The spec says the result of this algorithm is undefined in such cases,
and it appears that other engines yield a zero size.

More importantly, this prevents us from leaking a non-finite value into
the layout tree.
2023-06-13 16:14:45 +02:00
Aliaksandr Kalenik 147c3b3d97 LibWeb+WebContent: Forbid access to underlying type of CSSPixels
Although DistinctNumeric, which is supposed to abstract the underlying
type, was used to represent CSSPixels, we have a whole bunch of places
in the layout code that assume CSSPixels::value() returns a
floating-point type. This assumption makes it difficult to replace the
underlying type in CSSPixels with a non-floating type.

To make it easier to transition CSSPixels to fixed-point math, one step
we can take is to prevent access to the underlying type using value()
and instead use explicit conversions with the to_float(), to_double(),
and to_int() methods.
2023-06-13 06:08:27 +02:00
Andreas Kling 867e04768e LibWeb: Use grid item *outer* size when calculating minimum contribution
Previously we used the border box, which meant that tracks did not grow
to accommodate item margins.
2023-06-12 17:51:08 +02:00