Commit Graph

1682 Commits

Author SHA1 Message Date
Andreas Kling
4474aa0ae5 LibWeb: Resolve flex item auto cross sizes through aspect ratio
Makes the bird logo show up on https://twitter.com/ :^)
2023-07-05 19:03:20 +02:00
Andreas Kling
6b3b056476 LibWeb: Support CSS font shorthand with up to 4 consecutive normal
All of the following properties in the font shorthand can be `normal`:

- font-style
- font-variant
- font-weight
- font-stretch

This means that we must allow up to four consecutive `normal` at the
start of a font shorthand value.
2023-07-04 16:25:23 +02:00
Andreas Kling
793c2ff65a LibWeb: Improve align-items in abspos static position of flex child
Basically, just support more values. And add a test. :^)
2023-07-04 16:25:23 +02:00
Andreas Kling
80a734d42e LibWeb: Improve justify-content in abspos static position of flex child
Also, add a test so we know these actually work correctly now. :^)
2023-07-04 16:25:23 +02:00
Andreas Kling
477a96820d LibWeb: Support valign attribute on td elements
This presentational hint maps to the CSS `vertical-align` property.

Fixes #19786.
2023-07-04 13:26:49 +02:00
Andreas Kling
fb727332f9 LibWeb: Decode linked style sheets before parsing them
This fixes an issue where a BOM at the head of a style sheet would be
passed verbatim to the parser, who would then interpret it as an ident
token and (after some confusion) fail to parse the first rule, but then
carry on with the rest of the sheet.
2023-07-04 10:45:20 +02:00
Andreas Kling
e7e454f1d6 LibWeb: Resolve used insets for grid items 2023-07-04 06:43:53 +02:00
Andreas Kling
03ec17fd37 LibWeb: Resolve used insets for flex items 2023-07-04 06:43:53 +02:00
Andreas Kling
c83ae729d2 LibWeb: Resolve used insets for floating elements
This makes the game carousel work on https://null.com/ :^)
2023-07-04 06:43:53 +02:00
Andreas Kling
510dfbb7e6 LibWeb: Update anonymous wrappers when applying style changes
Anonymous wrapper boxes inherit style from their layout tree parent,
and since style data is per-layout-node, we have to manually sync them
from parent to anonymous children when something changes.

This is not very elegant or efficient, so I've left a FIXME about
solving it in a nicer way.

This fixes horizontal dog alignment on https://waffles.dog/ :^)
2023-07-03 13:37:14 +02:00
Andreas Kling
b918ce4022 LibWeb: Make Layout::TextNode::text_for_rendering() lazily computed
As it turns out, Layout::TreeBuilder never managed to wrap text within
table boxes in anonymous wrapper boxes, since it relied on checking
text_for_rendering(), and that was never initialized during that early
stage of tree building.

This patch fixes the issue by making text_for_rendering() compute the
(potentially collapsed) text lazily when called.

Note that the test included with this patch is still totally wrong,
but that is now a TFC problem rather than a TreeBuilder problem. :^)
2023-07-03 11:50:58 +02:00
Andreas Kling
5cdb394400 LibWeb: Make HTML parser flush all pending tokens in "in table text"
There were multiple bugs in the parsing algorithm for handling text
occurring inside a `table` element:

- When there was pending non-whitespace text inside a table, we only
  flushed one token instead of all pending tokens.

- Also, we didn't even flush one of the right tokens, but instead the
  token that caused the flush to happen.

- Once we started flushing the right tokens, it turned out we had not
  yet implemented character insertion points expressed as "before X".

- Finally, we were not exiting the "in table text" mode after flushing
  pending tokens, effectively getting us stuck in that mode until EOF.
2023-07-03 11:50:58 +02:00
Sebastian Zaha
553694679e LibWeb: Fix alternating-sides float positioning
The "y" check for when to reset float side positioning was comparing an
offset that included the border, while the offset of the other side does
not.
2023-07-02 18:43:20 +02:00
MacDue
40fa07a6e1 LibWeb: Force paintable to exist for SVG <g> elements
This (along with the previous commit) fixes the missing tears on the
sad Duolingo owl.
2023-07-02 01:31:18 +02:00
Andreas Kling
3f022f4040 LibWeb: Treat non-finite containing block width as zero for percentages
Fixes an assertion when loading https://bun.sh/
2023-07-01 09:06:49 +02:00
Haikal Zain
bf16618fba LibWeb: Add vertical border heights to tr
tr y offset is not being computed correctly.
This is causing errors in hit testing since
td and tr are misaligned.
2023-07-01 08:07:49 +02:00
Andi Gallo
d33b99dd24 LibWeb: Check whether table box width is auto when resolving cell width
Computing the table width algorithm bifurcates based on whether
table-root width is auto. We only adjust the used table width based on
cell percentage widths on the auto branch, thus the same check is needed
when we initialize cell widths.
2023-06-29 05:37:34 +02:00
Andi Gallo
4596d41291 LibWeb: Make cell percentage widths relative to table
Cell percentage widths are relative to table width, not containing
block width. If the table width is auto, there isn't a normative
specification, only a brief mention that the user agent should try to
meet it.

As a starting point, we increase the width of the table such that it's
sufficient to cover min-width of cells with a percentage width. This
matches the behavior of other browsers, at least for simple cases.
2023-06-28 16:14:42 +02:00
Andi Gallo
9cb4fe6a6f LibWeb: Don't distribute excess width to constrained columns
Bring our implementation closer to the specification, which distributes
excess width to unconstrained columns first.
2023-06-28 12:17:55 +02:00
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
Andreas Kling
741c7aef21 LibWeb: Support more CSS functions in grid track size lists
Instead of hard-coding a check for "calc", we now call out to
parse_dynamic_value() which allows use of other functions like min(),
max(), clamp(), etc.
2023-06-12 17:51:08 +02:00
Andi Gallo
6a7a7e2337 LibWeb: Some row span fixes when combined with nested tables
Add logic to compute {min, max}-height and use min-height when
calculating table height, per specifications.

Fixes some issues with phylogenetic tree visualizations on Wikipedia.
2023-06-12 17:51:00 +02:00
Aliaksandr Kalenik
3fba0a944a LibWeb: Expand minmax in grid tracks defined by grid-auto-rows/columns
Use GridTrack::create_from_definition() that takes care of minmax().
2023-06-12 06:33:51 +02:00
Andreas Kling
8a43f5a64a LibWeb: Forward media attribute from link element to loaded style sheet
Otherwise, we will treat the loaded style sheet as if it had media="all"
which is not always appropriate.
2023-06-11 06:05:03 +02:00
Andreas Kling
79d2c9f3e8 LibWeb: Don't justify text lines that end in a forced break
These are treated the same as the last line in a block, per CSS-TEXT-3.
2023-06-10 21:46:33 +02:00
Andreas Kling
358a4fe3cb Tests/LibWeb: Update rebaseline-libweb-test for path changes 2023-06-10 21:46:33 +02:00
Andreas Kling
69c33bd4ca LibGfx/OpenType: Load x-height metrics from OS/2 table if available
Before this change we always returned the font's point size as the
x-height which was basically never correct.

We now get it from the OS/2 table (if one with version >= 2 is available
in the file). Otherwise we fall back to using the ascent of the 'x'
glyph. Most fonts appear to have a sufficiently modern OS/2 table.
2023-06-10 21:46:33 +02:00
Andi Gallo
8090adf268 LibWeb: Add partial implementation of border conflict resolution
Fix handling of border style specified per column as well.
2023-06-10 11:17:21 +02:00
Andi Gallo
4d49852454 LibWeb: Distribute cell contribution to all spanned columns
The specification isn't explicit about it, but the contribution we
compute should be distributed to all columns, not just the first one.

The first reason for it is symmetry, it doesn't make sense for the
increased width of the spanning column to only affect the first column
in the span.

The second reason is the formula for the cell contribution, which is
weighted by the non-spanning width of the cell relative to the total
width of the columns in the same row. This only covers a fraction of the
gap, in order to fully cover it we have to add it to all columns in the
span. For this to be exactly the case when the columns don't all have
the same width, we'd have to add additional weighting based on the width
ratios, but given that the specification doesn't suggest it at all we'll
leave it out for now.
2023-06-10 07:10:06 +02:00
Andi Gallo
50df78d2a2 LibWeb: Fix upper limit of span when computing column measures
The maximum span limit has to be inclusive, not exclusive.
2023-06-10 07:10:06 +02:00
Andi Gallo
940d9b98ae LibWeb: Add support for table caption
Adds layout support and the CSS caption-side property.
2023-06-10 07:09:11 +02:00
Aliaksandr Kalenik
10cab5fbdb LibWeb: Include gaps in for_each_spanned_track_by_item in GFC
This fixes the issue when left free space is calculated incorrectly
because for_each_spanned_track_by_item does not include gap tracks.
2023-06-10 07:08:01 +02:00
Sam Atkins
1051624084 LibWeb: Obey CSS aspect-ratio property during layout
Calculate a "preferred aspect ratio" based on the value of
`aspect-ratio` and the presence of a natural aspect ratio, and use that
in layout.

This is by no means complete or perfect, but we do now apply the given
aspect-ratio to things.

The spec is a bit vague, just saying to calculate sizes for
aspect-ratio'ed boxes the same as you would for replaced elements. My
naive solution here is to find everywhere we were checking for a
ReplacedBox, and then also accept a regular Box with a preferred aspect
ratio. This gets us pretty far. :^)

https://www.w3.org/TR/css-sizing-4/#aspect-ratio-minimum is not at all
implemented.
2023-06-09 20:37:51 +02:00
Timothy Flynn
bf242efd1d LibWeb: Remove outdated layout/text test scripts
These are superseded by headless-browser running these tests in a single
process, and aren't used by CI anymore. It's a bit confusing having them
still around so let's be rid of them.
2023-06-09 20:36:54 +02:00
Ali Mohammad Pur
141143a1c6 LibWeb: Serialize custom properties in CSSStyleDeclaration::serialized()
Prior to this commit, PropertyOwningCSSStyleDeclaration::serialized()
did not include custom properties, which lead to an incomplete
`cssRule.cssText` result.
This commit makes that class also serialize the custom properties and
place them before the regular properties in the rule text.
2023-06-09 11:17:44 +01:00
implicitfield
71b184accf Meta+Lagom: Enable CMAKE_BUILD_WITH_INSTALL_RPATH
On macOS, CMake incorrectly tries to add and/or remove rpaths from files
that it has already processed when it performs installation. Setting the
rpaths during the build process ensures that they are only set once, and
as a bonus, makes installation slightly more performant.

Fixes #10055.
2023-06-08 17:59:53 +02:00
Andreas Kling
3365a1e034 LibWeb: Resolve cyclic % against 0 when available size is min-content
This fixes an issue where replaced elements with cyclic percentage width
would make an oversized min-content contribution to its container.
2023-06-08 13:54:11 +02:00
Andreas Kling
a5f8f8238f LibWeb: Fix a case of incorrect flex container max-content main size
We were incorrectly returning a "specified size suggestion" for flex
items with a definite main size where that main size was also automatic.

This led to us incorrectly choosing 0 as the automatic minimum size for
that flex item, instead of its min-content size.
2023-06-08 13:54:11 +02:00
Andreas Kling
102b8d717f LibWeb: Set flex-basis to 0% when omitted from flex shorthand
This doesn't match the spec, *but* matches what other engines do, and it
turns out this is required for web compat. (It fixes the menu on MDN.)
2023-06-08 10:05:56 +02:00
Andreas Kling
7f90b0cab7 LibWeb: Don't override prototype on generated iterator prototypes
Generated iterator prototypes already have the IteratorPrototype as
their prototype, but we were incorrectly hijacking them and rerouting
to ObjectPrototype.

Regressed in cfe663435e.
2023-06-08 10:05:56 +02:00
Timothy Flynn
f2a28e83de LibWeb: Implement the document title attribute closer to the spec
The main differences between our current implementation and the spec
are:

    * The title element need not be a child of the head element.

    * If the title element does not exist, the default value should be
      the empty string - we currently return a null string.

    * We've since added AOs for several of the spec steps here, so we
      do not need to implement those steps inline.
2023-06-08 07:21:08 +02:00
Aliaksandr Kalenik
1c979e0ed7 LibWeb: Resolve percentage padding and margins for grid items in GFC
Adds a second pass to resolve percentage paddings and margins of grid
items after track sizes are known. If resolving percentage paddings
or margins affects tracks sizes then second pass to re-resolve track
sizes might also be needed but I cannot come up with an example to
reproduce that so we can leave it to improve in the future :)
2023-06-08 07:14:47 +02:00
Aliaksandr Kalenik
775742b35d LibWeb: Add support for horizontal margins of grid items in GFC 2023-06-08 07:14:47 +02:00
Aliaksandr Kalenik
0177e4e6ba LibWeb: Consider all spanned tracks while finding extra space in GFC
This fixes the issue when functions that distribute base_size
or growth_limit to tracks only considered *affected* spanned tracks
while calculating left extra that is available for distribution while
indeed it should be just *all* spanned track by specific item that
extra space size.
2023-06-07 19:44:47 +02:00
Aliaksandr Kalenik
3b3ade0b8d LibWeb: Use none as initial value for grid-template-column/rows
This fixes the issue that currently we use "auto" as initial value for
grid-template-column and grid-template-rows although spec says it
should be "none". This makes a lot of difference for these properties
because currently we represent "auto" as a list with one auto-sized
track which means initial value for grid-template-column defines one
"explicit" track while it should define none of them.

This change makes grid-auto-columns/rows be applied to the correct
tracks when initial values is used for grid-template-column/rows.
2023-06-07 14:13:07 +02:00
Aliaksandr Kalenik
0f1f95da46 LibWeb: Add support for grid items with negative column-start in GFC
This changes grid items position storage type from unsigned to signed
integer so it can represent negative offsets and also updates placement
for grid items with specified column to correctly handle negative
offsets.
2023-06-07 11:37:11 +02:00
Andreas Kling
2c16e8371f LibWeb: Add naive support for {margin,padding}-{block,inline}
Like other logical properties, we just alias these to the LTR TB default
properties for now.
2023-06-07 11:20:42 +02:00
Andreas Kling
9e807d7c6a LibWeb: Support start and end alignment values in flex layout
These should just behave the same as `flex-start` and `flex-end`.
2023-06-06 21:02:04 +02:00
Andreas Kling
abd6380cce LibWeb: Add CSS logical property aliases for margin and padding sides
These just map to the LTR+TB defaults for now, as we don't yet resolve
any of the inputs to the logical property selection algorithm.
2023-06-06 21:02:04 +02:00
Andreas Kling
c50ce2030d LibWeb: Allow event handler attributes on HTMLLinkElement
We were neglecting to set up event handlers for these due to a missing
call to the base class in HTMLLinkElement::parse_attribute().
2023-06-06 09:06:27 +02:00
Andreas Kling
b97004ea4a LibWeb: Fire "load" and "error" events for rel=preload link loads 2023-06-06 09:06:27 +02:00
Andreas Kling
3cea86632d LibWeb: Invalidate the layout tree on DOM node insertion 2023-06-06 09:06:27 +02:00
Andreas Kling
c197fb4037 LibWeb: Take box-sizing into account when sizing replaced elements
This fixes an issue where images with padding and/or border did not have
their size adjusted for `border-box`, thereby becoming larger than
intended by the author.
2023-06-05 09:00:00 +02:00
Shannon Booth
a9e37be7a0 Tests/LibWeb: Add some text tests for 'parsing a legacy color value'
I was not aware of this framework back when implementing this back in
bc54560e59. Add in some basic tests for
this now that we are compliant with the specification.
2023-06-05 06:54:33 +02:00
Andreas Kling
89ba00304c LibWeb: Account for negative margins when calculating float intrusion
If a box has a negative margin-left, it may have a negative effective
offset within its parent BFC root coordinate system.

We can account for this when calculating the amount of left-side float
intrusion by flooring the X offset at 0.
2023-06-04 18:14:12 +02:00
Andreas Kling
7115446995 LibWeb: Support font-size: calc()
Now that we have a way to resolve calc() lengths without a layout node,
we can finally support calc() values in font-size.

This wasn't possible before because font-related properties have to be
resolved eagerly in StyleComputer due to font-relative CSS length units
depending on the computed font being known.
2023-06-02 20:03:28 +02:00
Aliaksandr Kalenik
2ade229f27 LibWeb: Fix crashing when grid track size is calc() with percentage
Use contains_percentage() that works for calc() values instead of
is_percentage().

This fixes issue when tracks with calc() that has percentages where
considered as "fixed" tracks with resolvable size which led to
incorrectly resolved infinite final track sizes.
2023-06-02 19:02:31 +02:00
Sam Atkins
1f2629f132 LibWeb: Bounds-check parsed CSS types
This reintroduces bounds-checking for the CSS `<angle>`, `<frequency>`,
`<integer>`, `<length>`, `<number>`, `<percentage>`, `<resolution>`,
and `<time>` types.

I regressed this around 6b8f484114 when
changing how we parsed StyleValues.

This is an improvement from before though, since we now allow the bounds
of a dimension type to have units.

Added a test to make sure we don't regress this again. :^)
2023-06-02 17:46:35 +02:00
Andreas Kling
06617a982e LibWeb: Support flex items with calc() main size containing percentages
If a flex item's main size is a CSS calc() value that resolves to a
length and contains a percentage, we can only resolve it when we have
the corresponding reference size for the containing block.
2023-06-02 17:17:45 +02:00
FalseHonesty
de9604212f LibWeb: Avoid text-aligning content that is too long for its line box
Previously, we would always respect the `text-align` property, even if
the text being aligned was too long for its line box and would be
clipped. This led to seeing the clipped middle/end of strings when we
should instead always see the beginning of the text.
2023-06-02 05:21:22 +02:00
Andreas Kling
1a6a4ca7d4 LibWeb: Round lengths to 3 decimals after resolving from percentage
This is a hack to emulate the behavior of other engines that use
fixed-point math. By rounding to 3 decimals, we retain a fair amount of
detail, while still allowing overshooting 100% without breaking lines.

This is both gross and slow, but it fixes real sites. Notably, the
popular Bootstrap library uses overshooting percentages in their
12-column grid system.

This hack can be removed when CSSPixels is made a fixed-point type.
2023-06-01 18:13:42 +02:00
Andreas Kling
3f9cfa144c LibWeb: Allow infinitely long flex lines when sizing under max-content
If the flex container is being sized under a max-content main size
constraint, there is effectively infinite space available for flex
items. Thus, flex lines should be allowed to be infinitely long.

This is a little awkward, because the spec doesn't mention specifics
about how to resolve flexible lengths during intrninsic sizing.
I've marked the spec deviations with big "AD-HOC" comments.
2023-06-01 15:11:48 +02:00
Andreas Kling
caa491b72a LibWeb: Measure the overflow for all scroll containers
Instead of just measuring the layout viewport, we now measure overflow
in every box that is a scroll container.

This has the side effect of no longer creating paintables for layout
boxes that didn't participate in layout. (For example, empty/anonymous
boxes that were ignored by flex itemization.)

Such boxes are now marked as "(not painted)" in the layout tree dumps,
as they have no paintable to dump geometry from.
2023-06-01 13:33:35 +02:00
Andreas Kling
966058d693 LibWeb: Support line-height: calc(...) values that resolve to number
This is used on GitHub and many other websites.
2023-06-01 09:20:05 +02:00
FalseHonesty
dcead6f5eb LibWeb: Add support for parsing place-content shorthand CSS property 2023-06-01 09:06:13 +02:00
Andreas Kling
427cf14d71 Tests/LibWeb: Import my test rebaselining script
This is not a beautiful program, but it does allow you to regenerate
the baseline expectation for a given layout or text test with a single
command. :^)
2023-06-01 08:26:33 +02:00
stelar7
421559d725 LibWeb: Change calc node representation from float to double 2023-05-31 10:56:32 +02:00
Simon Wanner
29088f58ed LibWeb/Tests: Add missing newline in inset-shorthand-property.txt 2023-05-30 21:28:18 +02:00
Ali Mohammad Pur
0e3fb39a0a LibWeb: Make 'optional BufferSource' IDL arguments actually optional
Previously this was compiled to require an object despite the IDL file
specifying 'optional'.
This commit makes IDLGenerator respect this modifier, and fixes the only
affected instance.
2023-05-30 12:50:13 +02:00
Andi Gallo
7f9ede07bc LibWeb: Set margin, padding and border for replaced boxes
Separating the paths for replaced and non-replaced floating boxes lost
the logic for margin, padding and border which was done by
compute_width_for_floating_box. Set them the same way as we do for
block-level replaced elements, per the specification.
2023-05-30 10:09:47 +02:00
FalseHonesty
cabfb7867c LibWeb: Add support for parsing 'inset' shorthand CSS property 2023-05-30 06:02:06 +02:00
Aliaksandr Kalenik
0bef3085dd LibWeb: Output names of inner table boxes in layout dump
Since there are no table-specific boxes anymore it would be nice to
output their types additionally in layout dump so we can tell table
boxes from "regular" boxes.
2023-05-29 21:36:17 +02:00
Aliaksandr Kalenik
787f2d2a10 LibWeb: Remove Layout::TableCellBox
Special box types for inner table boxes might conflict with special
types for <button>, <input> or <label>.
2023-05-29 21:36:17 +02:00
Aliaksandr Kalenik
3a3a085404 LibWeb: Remove Layout::TableRowBox
Special box types for inner table boxes might conflict with special
types for <button>, <input> or <label>.
2023-05-29 21:36:17 +02:00
Aliaksandr Kalenik
578a937f94 LibWeb: Remove Layout::TableRowGroupBox
Special box types for inner table boxes might conflict with special
types for <button>, <input> or <label>.
2023-05-29 21:36:17 +02:00
Andreas Kling
af004ff0ef LibWeb: Support min-content for width, min-width and max-width
We're gonna need to handle this in many more places, this patch only
adds it to calculate_inner_width().
2023-05-29 21:29:25 +02:00
Andreas Kling
97c510329c LibWeb: Support max-content for width, min-width and max-width
We're gonna need to handle this in many more places, this patch only
adds it to calculate_inner_width().
2023-05-29 21:29:25 +02:00
Aliaksandr Kalenik
258f3ea952 LibWeb: Remove Layout::TableBox
Solves conflict in layout tree "type system" when elements <label> (or
<button>) can't have `display: table` because Box can't be
Layout::Label (or Layout::ButtonBox) and Layout::TableBox at the same
time.
2023-05-29 14:12:29 +02:00
Andreas Kling
58c1cb80bb Tests/LibWeb: Use the include.js helper in "basic.html" 2023-05-28 22:03:57 +02:00
Aliaksandr Kalenik
94fd17a467 LibWeb: Wrap child text sequences of grid container in anonymous blocks
From spec https://drafts.csswg.org/css-grid/#grid-items:
"Each in-flow child of a grid container becomes a grid item, and each
child text sequence is wrapped in an anonymous block container grid
item."

Fixes the problem that text sequences inside grid containers are
ignored and not displayed.
2023-05-28 21:12:04 +02:00
Aliaksandr Kalenik
537256fae2 LibWeb: Treat unresolvable percentages as auto to resolve sizes in GFC
Fixes the bug that currently we always consider tracks with percentage
size as ones with "fixed" length even when available size is not
definite. With this change tracks with percentage size when available
size is not definite will be considered as "intrinsic" sized.
2023-05-28 20:26:05 +02:00
Andreas Kling
30feb95d53 LibWeb: Support reverse flex layout with space-around/space-between
We were not taking reverse flex directions into account when choosing
the initial offset for flex item placement if justify-content were
either space-around or space-between.
2023-05-28 18:02:00 +02:00
Andi Gallo
29d29134ba LibWeb: Skip children based on media when updating the source set
If child has a media attribute and its value does not match the
environment, continue to the next child.
2023-05-28 12:11:10 +02:00
Andreas Kling
a98f5c7251 LibWeb: Make resolved serialization of CSS display prefer short form
Although we translate e.g `block` to `block flow` for internal use in
the engine, CSS-DISPLAY-3 tells us to use the short form in
serializations for compatibility reasons.

This adds 9 points to our score on https://html5test.com/ :^)
2023-05-27 16:43:35 +02:00
Karthik Karanth
f60446bbfe LibWeb: Unit tests for min/max-inline-size 2023-05-27 16:02:33 +02:00
Andreas Kling
edbc732785 Ladybird+Tests/LibWeb: Add very basic text-only test harness
This allows us to create "text tests" in addition to "layout tests".
Text tests work the same as layout tests, but dump the document content
as text and exit upon receiving the window "load" event.
2023-05-27 14:03:49 +02:00
Andreas Kling
8ba7bd1b67 LibWeb: Accept fit-content as a value for min-width and max-width
This starts working immediately in BFC thanks to calculate_inner_width
being used for width constraints. :^)
2023-05-27 05:47:54 +02:00
Andreas Kling
1bb4e5c428 LibWeb: Support fit-content width for block-level boxes 2023-05-27 05:47:54 +02:00
Andreas Kling
a277c393b9 LibWeb: Support grid items with fit-content width :^) 2023-05-27 05:47:54 +02:00
Aliaksandr Kalenik
ab5b89eb95 LibWeb: Add basic parsing of grid shorthand CSS property
Introduces incomplete parsing of grid shorthand property. Only
<grid-template> part of syntax is supported for now but it is enough
to significantly improve rendering of websites that use this shorthand
to define grid :)
2023-05-27 05:47:14 +02:00
Andi Gallo
1e526af430 LibWeb: Fix width calculation for floating replaced elements
The path for floating, replaced elements must not fall through to the
path taken for floating, non-replaced elements. The former works like
inline replaced elements, while the latter uses a completely different
algorithm which doesn't account for intrinsic ratio. Falling through
overrides the correct value computed by the former.

Fixes #19061.
2023-05-26 21:20:56 +02:00
Aliaksandr Kalenik
7cc20f4cb5 LibWeb: Reset margin collapsing state only if box indeed add clearance
This fixes the issue when margin collapsing state was always reset if
a box has clear property not equal to none even if it does not actually
introduce clearance.
2023-05-26 18:11:35 +02:00
Cameron Youell
0afdde0eef LibWeb: Consume sign in SVG::parse_elliptical_arg_argument
This was crashing on google.com with the linux chrome user agent,
interestingly it seems like this behavior may have been accidental as
only two of the three `parse_number()` were changed in f7dbcb6
2023-05-26 14:54:00 +02:00
Andi Gallo
5cec517153 LibWeb: Get reference height from closest non-anonymous ancestor
Ignore anonymous block boxes when resolving percentage weights that
would refer to them, per the CSS 2 visual formatting model
specification. This fixes the case when we create an anonymous block
between an image which uses a percentage height relative to a parent
which specifies a definite height.

Fixes #19052.
2023-05-26 14:53:53 +02:00
Andreas Kling
7d24c13d8b LibWeb: Make input element placeholders look better
We now create a flex container inside the input element's UA shadow tree
and add the placeholder and non-placeholder text as flex items (wrapped
in elements whose style we can manipulate).

This fixes the visual glitch where the placeholder would appear below
the bounding box of the input element. It also allows us to align the
text vertically inside the input element (like we're supposed to).

In order to achieve this, I had to make two small architectural changes
to layout tree building:

- Elements can now report that they represent a given pseudo element.
  This allows us to instantiate the ::placeholder pseudo element as an
  actual DOM element inside the input element's UA shadow tree.

- We no longer create a separate layout node for the shadow root itself.
  Instead, children of the shadow root are treated as if they were
  children of the DOM element itself for the purpose of layout tree
  building.
2023-05-25 14:42:24 +02:00
Sam Atkins
03613dc14d LibWeb: Make value_id_from_string() return Optional 2023-05-25 06:36:10 +02:00
Aliaksandr Kalenik
202b24584f LibWeb: Sum horizontal margins to calculate space used by floats
This fixes the issue where max margin is used to find offset of
floating box although horizonal margins do not collapse so they need
to be summed instead.
2023-05-24 18:58:42 +02:00
Jelle Raaijmakers
90d8844c77 LibWeb: Remove Gfx::Rect<float> workarounds from BFC
No longer is the last horizontal line of pixels ignored during layout.
This used to be a bug in `Gfx::Rect<float>` that was fixed in
f391ccfe53.
2023-05-24 18:19:45 +02:00
Andreas Kling
655d9d1462 LibWeb: Make CSSPixels and Length use 64-bit (double) floating point
This fixes a plethora of rounding problems on many websites.
In the future, we may want to replace this with fixed-point arithmetic
(bug #18566) for performance (and consistency with other engines),
but in the meantime this makes the web look a bit better. :^)

There's a lot more things that could be converted to doubles, which
would reduce the amount of casting necessary in this patch.
We can do that incrementally, however.
2023-05-24 14:40:35 +02:00
Andreas Kling
30262d7023 LibWeb: Rebaseline a layout test after 10ceacf5fb 2023-05-24 13:25:05 +02:00
Andreas Kling
71d5dc510e LibWeb: Resolve CSS variables if present in SVG presentation attributes
SVG presentation attributes are parsed as CSS values, so we also need to
handle CSS variable expansion when handling them.

This (roughly) matches the behavior of other engines. It's also used on
the web, for example on https://stripe.com/ :^)
2023-05-24 06:43:21 +02:00
Aliaksandr Kalenik
76aa17be86 LibWeb: Make sure collapsed margins are not ignored if box creates FC
Fixes a bug that if box creates new formatting context then all already
collapsed margins are ignored and only margin_top is used.
2023-05-22 12:51:24 +02:00
Andi Gallo
668578ddc0 LibWeb: Propagate children_are_inline in wrap_in_anonymous
This fixes a crash in box_baseline, due to cells created for
display: table expecting a box child and getting the inline node wrapper
instead.

Fixes #18972.
2023-05-22 10:25:18 +02:00
Aliaksandr Kalenik
193290b19a LibWeb: Support grid-auto-columns and grid-auto-rows properties in GFC
Implements assignment of sizes specified in grid-auto-columns/rows for
implicitly created tracks.
2023-05-22 06:05:19 +02:00
Andi Gallo
e6221117a5 LibWeb: Implement table rowspan
Adjust computing the table height and positioning of cells to account
for the rowspan property.

Fixes #18952.
2023-05-21 14:23:41 +02:00
Andreas Kling
6cb9d755d9 LibWeb: Don't crash on percentage values for CSS stroke-width
Fixes a crash when loading https://vercel.com/
2023-05-21 12:40:27 +02:00
Aliaksandr Kalenik
409333d80a LibWeb: Implement more of spanning tracks sizing in GFC
Implements more parts of sizing algorithm for tracks with spanning
items to archive parity with implementation for sizing of tracks
with non-spanning items.
2023-05-21 11:59:19 +02:00
Andreas Kling
94a26e2715 LibWeb: Include SVG-as-image isolated contexts in layout/DOM tree dumps
This allows us to see the inside of SVG-as-image in layout tests. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
24ea78c613 LibWeb: Add a very basic test for SVG-as-image
This mainly just checks that we load the file and learn the correct
intrinsic aspect ratio from the external SVG.
2023-05-21 07:44:29 +02:00
Andreas Kling
f0560fd087 LibWeb: Support <svg> elements with display: block
There are a couple of things that went into this:

- We now calculate the intrinsic width/height and aspect ratio of <svg>
  elements based on the spec algorithm instead of our previous ad-hoc
  guesswork solution.

- Replaced elements with automatic size and intrinsic aspect ratio but
  no intrinsic dimensions are now sized with the stretch-fit width
  formula.

- We take care to assign both used width and used height to <svg>
  elements before running their SVG formatting contexts. This ensures
  that the inside SVG content is laid out with knowledge of its
  viewport geometry.

- We avoid infinite recursion in tentative_height_for_replaced_element()
  by using the already-calculated used width instead of calling the
  function that calculates the used width (since that may call us right
  back again).
2023-05-20 08:49:42 +02:00
Andreas Kling
6f204f8c32 LibWeb: Fix null dereference on SVG element with bogus fill URL
Fixes a crash seen on YouTube channel pages.
2023-05-19 15:41:34 +02:00
Andreas Kling
411b28fc59 LibWeb: Make sure that margins don't collapse across a nested BFC
In order to fix this, I also had to reorganize the code so that we
create an independent formatting context even for block-level boxes
that don't have any children. This accidentally improves a table
layout test as well (for empty tables).
2023-05-19 15:09:09 +02:00
Aliaksandr Kalenik
902ceb1675 LibWeb: Resolve grid item fixed size paddings in GFC
Adds support for grid items with fixed size paddings. Supporting
percentage paddings will probably require to do second pass of tracks
layout: second pass is needed to recalculate tracks sizes when final
items sizes are known when percentage paddings are already resolved.
2023-05-19 06:12:05 +02:00
Aliaksandr Kalenik
82aedfcaf0 LibWeb: Use grid item used width as available width during track sizing
This change addresses the incorrect assumption that the available width
inside a grid item is equal to the width of the track it belongs to.
For instance, if a grid item has a width of 200px, the available width
inside that item is also 200px regardless of its column(s) base size.

To solve this issue, it was necessary to move the final resolution of
grid items to occur immediately after the final column track sizes are
determined. By doing so, it becomes possible to obtain correct
available width inside grid items while resolving the row track sizes.
2023-05-18 18:06:05 +02:00
Andreas Kling
fb722e69f3 LibWeb: Resolve CSS custom properties on pseudo elements
The resolved property sets are stored with the element in a
per-pseudo-element array (same as for pseudo element layout nodes).

Longer term, we should stop storing this with elements entirely and make
it temporary state in StyleComputer somehow, so we don't waste memory
keeping all the resolved properties around.

This makes various gradients show up on https://shopify.com/ :^)
2023-05-17 20:37:29 +02:00
Aliaksandr Kalenik
628efda754 LibWeb: Consider span > 1 while getting available space for items in GFC 2023-05-17 15:55:14 +02:00
Aliaksandr Kalenik
d6d097b671 LibWeb: Remove borders from TemporaryTrack in GFC
This change makes grid items be responsible for their borders instead
of grid tracks which can not have borders itself.

There are changes in layout tests but those are improvements :)
2023-05-17 09:11:29 +02:00
Aliaksandr Kalenik
c61bb1706f LibWeb: Use auto minimimum size while resolving flexible tracks in GFC 2023-05-17 07:48:38 +02:00
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
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
Andreas Kling
2e13f65ff4 LibWeb: Support flex-basis: calc(...)
1. Propagate calc() values from StyleProperties to ComputedValues.
2. Actually resolve calc() values when determining the used flex basis.

This makes the "support" section on https://shopify.com/ show up
correctly as a 2x2 grid (instead of 1x4). :^)
2023-05-17 07:40:17 +02:00
Andreas Kling
e81d4ca1ac LibWeb: Fix off-by-one in CSS calc() "negate" operation
When negating a number, we should subtract it from 0, not 1. :^)
2023-05-17 07:40:17 +02:00
Andreas Kling
e938860126 LibWeb: Make text justification work between floats
While inline content between floating elements was broken correctly,
text justification was still using the original amount of available
space (without accounting for floats) when justifying fragments.
2023-05-16 14:35:10 +02:00
Andreas Kling
bab6796099 LibWeb: Rewrite calculation of available space between floats
This code now works in terms of *intrusion* by left and right side
floats into a given box whose insides we're trying to layout.

Previously, it worked in terms of space occupied by floats in the root
box of the BFC they participated in. That created a bunch of edge cases
since the code asking about the information wasn't operating in root
coordinate space, but in the coordinate space of some arbitrarily nested
block descendant of the root.

This finally allows horizontal margins in the containing block chain to
affect floats and nested content correctly, and it also allows us to
remove a bogus workaround in InlineFormattingContext.
2023-05-16 14:35:10 +02:00
Andi Gallo
9a6a635e51 LibWeb: Fix for absolutely positioned elements with specified height
Use inner height since the paintable adds padding back.

Fixes #18842.
2023-05-16 14:34:53 +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
Andreas Kling
5d4e9a0673 LibWeb: Basic support for CSS text-indent: <length-percentage>
Note that this simple form of text-indent only affects the first line
of formatted content in each block.

Percentages are resolved against the width of the block.
2023-05-15 19:31:09 +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
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
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
c2f6ba8f5f LibWeb: Parse calc() function in grid sizes
Adds missing part of grid size parsing function to handle calc().
2023-05-11 18:36:56 +02:00
Andreas Kling
b98252728e LibWeb: Fix percentage min/max sizes on flex items with intrinsic ratio
We were resolving percentage values against the containing block size in
the wrong axis.
2023-05-10 18:46:04 +02:00
Andreas Kling
89ba7246dd LibWeb: Don't resolve CSS property values for unconnected elements
While it's possible to getComputedStyle() on an unconnected element,
the resulting object is not supposed to have any values, since we can't
resolve style without a document root anyway.

This fixes a crash on https://bandcamp.com
2023-05-10 17:27:07 +02:00
Andreas Kling
0c26717ba3 LibWeb: Adjust flex item main size through aspect ratio if needed
If there are min or max size constraints in the cross axis for a flex
item that has a desired aspect ratio, we may need to adjust the main
size *after* applying the cross size constraints.

All the steps to achieving this aren't mentioned in the spec, but it
seems that all other browsers behave this way, so we should too.
2023-05-10 13:03:05 +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
Andreas Kling
197efc8985 LibWeb: Improve handling of min/max constraint violations on images
Instead of bailing after resolving one violated constraint, we have to
continue down the list of remaining constraints.

We now also call the constraint solver for all replaced elements with
"auto" for both width and height.

Co-authored-by: 0GreenClover0 <clovers02123@gmail.com>
2023-05-09 12:11:28 +02:00
Emil Militzer
8200d1f68b LibWeb: Initial offset in reverse flex layout moved to opposite side
This change moves the initial offset for justify-content: center to the
opposite side if the flex layout is in the reverse direction.
2023-05-09 10:32:09 +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
Aliaksandr Kalenik
f2323b5b99 Tests/LibWeb: Split input/grid/minmax.html into smaller tests 2023-05-09 06:37:30 +02:00
Aliaksandr Kalenik
0dcc93ed3d Tests/LibWeb: Split input/grid/gap.html into smaller tests
The file gap.html, which previously had multiple grid tests, has now
been divided into smaller files, each containing only one grid test.
It is going to make it easier to identify what inputs have been
affected by changes in layout code.
2023-05-09 06:37:30 +02:00
Aliaksandr Kalenik
bb90bf0141 Tests/LibWeb: Split input/grid/template-areas.html into smaller tests
The file template-areas.html, which previously had multiple grid tests,
has now been divided into smaller files, each containing only one grid
test. It is going to make it easier to identify what inputs have been
affected by changes in layout code.

Also this change removes parts of template-areas.html that we can't
layout correctly yet.
2023-05-09 06:37:30 +02:00
Andreas Kling
1ebae7a779 LibWeb: Stop changing width of block-level flex containers during layout
If the parent BFC can come up with a nice stretch-fit width for the flex
container, it will have already done so *before* even entering flex
layout. There's no need to do it again, midway through the flex layout
algorithm.

This wasn't just unnecessary, but we were also doing it incorrectly and
not taking margins into account when calculating the amount of available
space for stretch-fit. This led to oversized flex containers in the
presence of negative margins.

Fixes #18614
2023-05-08 15:56:00 +02:00
martinfalisse
ea61296738 LibWeb: Use layout-test-mode for layout tests
Also do some test changes to test it out :^)
2023-05-08 14:47:52 +02:00
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
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
Andreas Kling
8bb0be7d4f LibWeb: Don't apply presentational hints to associated pseudo elements
CSS properties generated by presentational hints in content attributes
should not leak into pseudo elements.
2023-04-02 15:00:06 +02:00
Andreas Kling
620a34a463 LibWeb: Don't apply element inline style to associated pseudo elements
An element's inline style, if present, should not leak into any pseudo
elements generated by that element.
2023-04-02 15:00:06 +02:00
Andreas Kling
9cded6e1b5 LibWeb: Fix application of intrinsic aspect ratio to flex column items
The intrinsic aspect ratio of a box is a width:height ratio, so if we
have the width and need the height, we should divide, not multiply. :^)
2023-04-02 06:45:44 +02:00
martinfalisse
57cdb0c972 LibWeb: Add display grid automated tests 2023-04-01 21:45:29 +02:00
martinfalisse
7028f75779 Tests: Use layout tests placed in subdirectories
Allows organizing layout tests into subdirectories.
2023-04-01 21:45:29 +02:00
Andreas Kling
45f8542965 LibWeb: Actually visit rules and media queries in imported style sheets
Due to CSSImportRule::has_import_result() being backwards, we never
actually entered imported style sheets when traversing style rules or
media queries.

With this fixed, we no longer need the "collect style sheets" step in
StyleComputer, as normal for_each_effective_style_rule() will now
actually find all the rules. :^)
2023-03-30 16:54:15 +02:00
Andreas Kling
e4b71495f5 LibWeb: Resolve percentage vertical-align values against line-height
...instead of not resolving them at all. :^)
2023-03-29 18:38:29 +02:00
Andreas Kling
c0a7a61288 LibWeb: Clamp fit-content widths in flex layout to min/max-width
In situations where we need a width to calculate the intrinsic height of
a flex item, we use the fit-content width as a stand-in. However, we
also need to clamp it to any min-width and max-width properties present.
2023-03-28 21:08:54 +02:00
Luke Wilde
4c090a9a35 Tests/LibWeb: Add layout test for layout fix in PR #15780
Adds a layout test for the fix in 488a979.
2023-03-28 19:45:00 +01:00
Andreas Kling
af118abdf0 LibWeb: Use fit-content width in place of indefinite flex item widths
In `flex-direction: column` layouts, a flex item's intrinsic height may
depend on its width, but the width is calculated *after* the intrinsic
height is required.

Unfortunately, the specification doesn't tell us exactly what to do here
(missing inputs to intrinsic sizing is a common problem) so we take the
solution that flexbox applies in 9.2.3.C and apply it to all intrinsic
height calculations within FlexFormattingContext: if the used width of
an item is not yet known when its intrinsic height is requested, we
substitute the fit-content width instead.

Note that while this is technically ad-hoc, it's basically extrapolating
the spec's suggestion in one specific case and using it in all cases.
2023-03-27 23:28:07 +02:00
Aliaksandr Kalenik
1ee99017e2 LibWeb: Fix intrinsic sizing early return condition in TFC
Early return before running full TFC algorithm is only possible when
just table width need to be calculated.
2023-03-27 23:10:16 +02:00
Andreas Kling
949483fb01 Tests/LibWeb: Test flex column item with auto height and max-width
This case is important because we have to clamp the width before using
it to determine the auto height.
2023-03-26 15:14:35 +02:00
Andreas Kling
5b030a6923 Tests/LibWeb: Add test for flex item auto height with flex-wrap: wrap 2023-03-26 15:14:35 +02:00
Andreas Kling
4bf10674fa LibWeb: Don't allow resolved height of abspos elements to become negative
We have to clamp the resulting height to 0 when solving for it.
2023-03-25 19:41:31 +01:00
Andreas Kling
3f6f3966b9 LibWeb: Don't allow resolved width of abspos elements to become negative
We have to clamp the resulting width to 0 when solving for it.
2023-03-25 19:41:31 +01:00
Andreas Kling
8f311c61af LibWeb: Add out-of-flow boxes to anonymous wrapper block when possible
If the previous sibling of an out-of-flow box has been wrapped in an
anonymous block, we now stuff the out-of-flow box into the anonymous
block as well.

Co-authored-by: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
2023-03-25 19:41:31 +01:00
Andreas Kling
d005b1ad1b LibWeb: Support loading file:// URLs via fetch (through ResourceLoader)
This builds on the existing ad-hoc ResourceLoader code for HTTP fetches
which works for files as well.

This also includes a test that checks that stylesheets loaded with the
"file" URL scheme actually work.
2023-03-22 23:34:32 +00:00
Andreas Kling
a6d1307aa4 LibWeb: Don't crash on HTML input element with display: inline
This would previously assert in InlineFormattingContext because we had
an outwardly inline box that wasn't inwardly flow.

Fix this by converting text-based input boxes to inline-blocks. This is
an ad-hoc solution, and there might be a much better way to solve it.
2023-03-20 17:57:58 +01:00
Aliaksandr Kalenik
7ddacef3b5 LibWeb: Apply border-radius clip only if overflow hidden for both axis
Before this change `apply_clip_overflow_rect` might crash trying to
access `clip_rect` that does not have value because we currently
support calculation of visible rectangle when `overflow: hidden`
is applied for both axis.
2023-03-19 19:04:51 +01:00
Simon Wanner
482fa2d4e2 Tests/LibWeb: Add two tests for lh and rlh units 2023-03-18 20:14:52 +01:00
Andreas Kling
1dc074fc18 LibWeb: Treat flex item's cyclic percentage cross size as auto
This fixes an issue where e.g `height: 100%` on a flex item whose
container has indefinite height was being resolved to 0. It now
correctly behaves the same as auto.
2023-03-18 00:26:19 +01:00
Mathis Wiehl
9927dab993 LibWeb: Don't drop single <br/> lines
Previously, when having inline contexts consisting of just a `<br/>`
tag, we would not create a line box.

Ensure that there is always a line box when a line is explicitly being
broken and also ensure it won't be trimmed due to being empty.

This will a fix a number of sites that use `<br>` tags for layouts
between block elements (even though the spec says they shouldn't).
2023-03-16 08:40:29 +00:00
Andreas Kling
71b7e65a52 Tests/LibWeb: Add ACID1 as a layout test
This will help us catch any future regressions immediately.
2023-03-15 11:43:54 +01:00
Andreas Kling
db545b51ef LibWeb: Make sure float: left boxes get pushed down if they can't fit 2023-03-15 11:43:54 +01:00
Andreas Kling
50f9a86086 LibWeb/Tests: Remove image from a test
The image made the test flaky when running on my machine, so this
doesn't seem safe at the moment. We can just hardcode the dimensions.

Eventually we should make it possible to use external images in tests,
but for now let's not flake up the CI.
2023-03-14 18:49:37 +01:00
Mathis Wiehl
b96920a9d6 LibWeb: Consider margins of atomic inlines in layout
According to CSS Inline Layout Module Level 3 § 2.2 Step 1. atomic
inlines should be layed out in a line box based on their margin box.

However, up until this patch we were unconditionally considering only
the border box during line box height calculation. This made us
essentially drop all vertical margins for atomic inlines.
2023-03-14 14:45:40 +01:00
Tim Schumacher
ae51c1821c Everywhere: Remove unintentional partial stream reads and writes 2023-03-13 15:16:20 +00:00
Tim Schumacher
d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
2023-03-13 15:16:20 +00:00
Timothy Flynn
127d2e2098 LibWeb: Run LibWeb layout tests using headless-browser 2023-03-13 12:41:10 +00:00
Andreas Kling
7bb7d87807 LibWeb: Resolve percentage line-height values before CSS inheritance
Percentage line-height values are relative to 1em (i.e the font-size
of the element). We have to resolve their computed values before
proceeding with inheritance.
2023-03-12 18:10:32 +01:00
Andreas Kling
7b55d79d3a LibWeb: Actually incorporate style from imported style sheets 2023-03-12 18:10:32 +01:00
Andreas Kling
1b262f8c89 Tests/LibWeb: Only care about *.html files in layout test runner 2023-03-12 18:10:32 +01:00
Andreas Kling
92eaad8f2e LibWeb: Consider entire stack of floated boxes when floating new box
If normal flow layout has caused us to progress past the current
innermost float in the block axis, we still need to consider the floats
stacked outside of it.

Fix this by always walking the currently stacked floats from innermost
to outermost when placing new floats.
2023-03-12 18:10:32 +01:00
Andreas Kling
f3556f239e LibWeb: Don't touch flex items after they we've been frozen
When using the flex shrink factor, the flexible length resolution
algorithm was incorrectly ignoring the `frozen` flag on items and would
update the same items again, causing overconsumption of the remaining
free space on the flex line.
2023-03-11 11:52:19 +01:00
Andreas Kling
f97754942c LibWeb: Collapse margin-left with space used by left-side floats
We had an issue where boxes with margin-left were shifted right by
left-side floats twice instead of just once.
2023-03-11 10:46:26 +01:00
Mathis Wiehl
ab4cf7c57d LibWeb: Don't overflow flex containers on margin auto
In case flex items had `margin: auto` on the primary flex axis, we were
still also distributing remaining space according to `justify-content`
rules. This lead to duplicated spacing in various places and overflows.

It looks like this issue was observed previously but missidentified
because there was logic to ignore margins at the start and end which
would partially paper over the root cause. However this created other
bugs (like for example not having a margin at beginning and end ;-)) and
I can find nothing in the spec or other browser behaviour that indicates
that this is something that should be done.

Now we skip justify-content space distribution alltogether if it has
already been distributed to auto margins.
2023-03-11 10:46:21 +01:00
Andreas Kling
da861fe7af Tests/LibWeb: Use SerenitySans in new layout tests
This ensures consistent font metrics no matter which platform fonts
are available.
2023-03-10 18:10:33 +01:00
Andreas Kling
109ed27423 LibWeb: Rewrite FFC "resolve flexible lengths" algorithm from draft spec
The draft CSS-FLEXBOX-1 spec had a more detailed description of this
algorithm, so let's use that as our basis for the implementation.

Test by Aliaksandr. :^)
2023-03-10 13:38:34 +01:00
Andreas Kling
1cd61723f0 LibWeb: Show layout test failure diffs in unified format (diff -u) 2023-03-10 13:38:34 +01:00
Andreas Kling
0ef07383e5 LibWeb: Fix bogus min/max-height for box-sizing:border-box flex items
When resolving these constraints to CSS pixel sizes, we have to resolve
padding-top and padding-bottom against the flex container's *width*,
not its height.
2023-03-10 13:38:34 +01:00
Andreas Kling
24d5a9d7df LibWeb: Fix bogus percentage vertical padding with box-sizing:border-box
The padding-top and padding-bottom properties are relative to the
*width* of the containing block, not the height.

It's funny how we keep making this same mistake again and again. :^)
2023-03-10 13:38:34 +01:00
Andreas Kling
7e76a51cb0 LibWeb: Rename Layout::InitialContainingBlock to Layout::Viewport
The name "initial containing block" was wrong for this, as it doesn't
correspond to the HTML element, and that's specifically what it's
supposed to do! :^)
2023-02-28 12:21:56 +01:00
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
606a3982f3 LibCore: Move Stream-based file into the Core namespace 2023-02-13 00:50:07 +00:00
Aliaksandr Kalenik
92cb32b905 LibWeb: Add tests for flex formatting context 2023-02-11 10:42:52 +01:00
Aliaksandr Kalenik
2ed5415750 LibWeb: Fix clearance to update y offset within current block
If a box has clearance and margin bottom of preceding box is greater
than static y of the box then it should also affect y offset in current
block container so subsequent boxes will get correct y position too.
2023-02-10 20:55:33 +01:00
Aliaksandr Kalenik
f43f4feb1e LibWeb: Table wrappers should not be ignored in auto height calculation
Though table wrappers are anonymous block containers (because
TableWrapper is inherited from BlockContainer) with no lines they
should not be skipped in block auto height calculation.
2023-02-07 17:04:38 +01:00
Aliaksandr Kalenik
900cd78121 LibWeb: Add layout tests for floats, margins collapsing and positioning
Those are copied from 'Base/res/html/misc/'.
2023-02-06 20:42:14 +01:00
Aliaksandr Kalenik
12eca612bc Ladybird: Specify window size in layout dump mode 2023-02-06 20:42:14 +01:00
Timothy Flynn
9f9b8e7273 CI: Move running LibWeb layout tests to Azure
The current config on GitHub Actions does not use ccache, so it takes
quite a while to build. Instead, let's just run these tests on Azure
where we already build Ladybird and have ccache enabled. This also lets
us sanitize LibWeb on both Linux and macOS.

The script changes here are to A) handle differences between Azure and
GitHub Actions and B) to support running on macOS.
2023-02-01 14:04:44 +00:00
Aliaksandr Kalenik
78b503946c Tests: Add LibWeb layout tests 2023-01-29 11:33:33 +00:00
Ben Wiederhake
b3d2fdceb1 LibWeb+Tests: Demonstrate slowness of CSS::value_id_from_string 2023-01-14 15:43:27 -07:00
Ben Wiederhake
0687a75eaa LibWeb: Run tests in lagom if ENABLE_LAGOM_LIBWEB is set 2023-01-14 15:43:27 -07:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +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
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Andreas Kling
81aa601637 Tests: Remove test-web
This was not used or maintained, and relied on InProcessWebView which we
need to get rid of.
2022-04-06 19:35:07 +02:00
Sam Atkins
82605e2dff Tests: Port TestHTMLTokenizer to Core::Stream 2022-03-10 12:04:22 -05:00
Linus Groh
1422bd45eb LibWeb: Move Window from DOM directory & namespace to HTML
The Window object is part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/window-object.html
2022-03-08 00:30:30 +01:00
Andreas Kling
8b2499b112 LibWeb: Make document.write() work while document is parsing
This necessitated making HTMLParser ref-counted, and having it register
itself with Document when created. That makes it possible for scripts to
add new input at the current parser insertion point.

There is now a reference cycle between Document and HTMLParser. This
cycle is explicitly broken by calling Document::detach_parser() at the
end of HTMLParser::run().

This is a huge progression on ACID3, from 31% to 49%! :^)
2022-02-21 22:00:28 +01:00
Adam Hodgen
b6eaefa87d LibWeb: Fix 'Comment end state' in HTML Tokenizer
Also, update the expected hash in the LibWeb TestHTMLTokenizer
regression test.

This is due to the "This comment has a few too many dashes." comment
token being updated.
2022-02-21 16:31:45 +01:00
Karol Kosek
fb5e2670d6 LibWeb: Fix highlighting HTML comments
Commit b193351a99 caused the HTML comments to flash when changing
the text cursor. Also, when double-clicking on a comment, the selection
started from the beginning of the file instead.

The following message was displaying when `TOKENIZER_TRACE_DEBUG`
was enabled:

    (Tokenizer::nth_last_position) Invalid position requested: 4th-last
    of 4. Returning (0-0).

Changing the `nth_last_position` to 3 fixes this. I'm guessing that's
because the parser is at that moment on the second hyphen of the `<!--`
string, so it has to go back only by three characters.
2022-02-14 12:50:44 +03:30
Timothy Flynn
7e63f0eb32 LibWeb: Update TestHTMLTokenizer's expected token hash
The output of the tokenizer changed in commit:
b193351a99.
2022-02-13 17:37:33 +00:00
Luke Wilde
f71f404e0c LibWeb: Introduce the Environment Settings Object
The environment settings object is effectively the context a piece of
script is running under, for example, it contains the origin,
responsible document, realm, global object and event loop for the
current context. This effectively replaces ScriptExecutionContext, but
it cannot be removed in this commit as EventTarget still depends on it.

https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
2022-02-08 17:47:44 +00:00
davidot
9264f9d24e LibJS+Everywhere: Remove VM::exception() and most related functions
This commit removes all exception related code:
Remove VM::exception(), VM::throw_exception() etc. Any leftover
throw_exception calls are moved to throw_completion.
The one method left is clear_exception() which is now a no-op. Most of
these calls are just to clear whatever exception might have been thrown
when handling a Completion. So to have a cleaner commit this will be
removed in a next commit.

It also removes the actual Exception and TemporaryClearException classes
since these are no longer used.

In any spot where the exception was actually used an attempt was made to
preserve that behavior. However since it is no longer tracked by the VM
we cannot access exceptions which were thrown in previous calls.
There are two such cases which might have different behavior:
- In Web::DOM::Document::interpreter() the on_call_stack_emptied hook
  used to print any uncaught exception but this is now no longer
  possible as the VM does not store uncaught exceptions.
- In js the code used to be interruptable by throwing an exception on
  the VM. This is no longer possible but was already somewhat fragile
  before as you could happen to throw an exception just before a VERIFY.
2022-02-08 09:12:42 +00:00
mjz19910
1ef633472b Everywhere: Convert VM::call() to JS::call() 2022-01-23 15:24:45 +00:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Idan Horowitz
44555eb50a LibJS: Convert test-js/test-web/test-wasm to ThrowCompletionOr 2021-10-20 12:27:19 +01:00
Linus Groh
4d8912a92b LibJS: Convert to_string() to ThrowCompletionOr
Also update get_function_name() to use ThrowCompletionOr, but this is
not a standard AO and should be refactored out of existence eventually.
2021-10-13 09:55:10 +01:00
Andreas Kling
f67648f872 LibWeb: Rename HTMLDocumentParser => HTMLParser 2021-09-25 23:36:43 +02:00
Timothy Flynn
c59b97043e LibWeb: Use ErrorType::NotAnObjectOfType instead of NotA 2021-09-12 00:16:39 +02:00
Andrew Kaster
58797a1289 Tests: Remove all file(GLOB) from CMakeLists in Tests
Using a file(GLOB) to find all the test files in a directory is an easy
hack to get things started, but has some drawbacks. Namely, if you add
a test, it won't be found again without re-running CMake. `ninja` seems
to do this automatically, but it would be nice to one day stop seeing it
rechecking our globbed directories.
2021-09-02 09:08:23 +02:00
ovf
898b8ffcb6 LibWeb: Avoid assertion failure on parsing numeric character references 2021-07-28 18:32:22 +02:00
ovf
13c7d55320 LibWeb: Fix parsing of character references in attribute values 2021-07-27 00:03:43 +02:00
Max Wipfli
b6e995ca3c Tests: Use pointers in TestHTMLTokenizer to avoid copying HTMLTokens 2021-07-17 16:24:57 +04:30
Max Wipfli
918bde98b1 LibWeb: Hide implementation details of HTMLToken attribute list
Previously, HTMLToken would expose the Vector<Attribute> directly to
its users. In preparation for a future change, all users now use
implementation-agnostic APIs which do not expose the Vector directly.
2021-07-17 16:24:57 +04:30
Max Wipfli
2404ad6897 LibWeb: Fix assertion failure when tokenizing JS regex literals
This fixes parsing the following regular expression: /</g;

It also adds a simple script element to the HTMLTokenizer regression
test, which also contains that specific regex.
2021-07-15 01:47:22 +02:00
Max Wipfli
a9a54914bf Tests: Add comments to the HTMLTokenizer regression test file 2021-07-15 00:48:45 +02:00
Max Wipfli
5a44a0b9f4 Tests: Add a basic test suite for HTMLTokenizer
The test suite includes a few basic tests and a very crude regression
test, which just concatenates the to_string() of all tokens and checks
the String's hash to be equal. This relies on the format of
HTMLToken::to_string() to stay the same, which is not ideal.
2021-07-14 23:03:36 +02:00
Andreas Kling
ba9d5c4d54 LibJS: Rename Function => FunctionObject 2021-06-27 22:36:04 +02:00
Gunnar Beutner
631d36fd98 Everywhere: Add component declarations
This adds component declarations so that users can select to not build
certain parts of the OS.
2021-06-17 11:03:51 +02:00
Ali Mohammad Pur
51c2c69357 AK+Everywhere: Disallow constructing Functions from incompatible types
Previously, AK::Function would accept _any_ callable type, and try to
call it when called, first with the given set of arguments, then with
zero arguments, and if all of those failed, it would simply not call the
function and **return a value-constructed Out type**.
This lead to many, many, many hard to debug situations when someone
forgot a `const` in their lambda argument types, and many cases of
people taking zero arguments in their lambdas to ignore them.
This commit reworks the Function interface to not include any such
surprising behaviour, if your function instance is not callable with
the declared argument set of the Function, it can simply not be
assigned to that Function instance, end of story.
2021-06-06 00:27:30 +04:30
Ali Mohammad Pur
d897abf4c2 LibWeb: Implement test-web in terms of LibTest/JavaScriptTestRunner
This deduplicates the test-js copy-ism :^)
2021-05-18 18:48:15 +01:00
Ali Mohammad Pur
a91a49337c LibCore+Everywhere: Move OpenMode out of IODevice
...and make it an enum class so people don't omit "OpenMode".
2021-05-12 11:00:45 +01:00
Brian Gianforcaro
10a594e6fe Tests: Fix install of test-js and test-web
When these were moved, there was a copy paste bug in the install
directives of both of these binaries.
2021-05-09 11:04:38 +02:00
Brian Gianforcaro
b390554ad8 Tests: Move Userland/Utilities/test-web to Tests/LibWeb 2021-05-08 00:04:10 +01:00