Commit Graph

657 Commits

Author SHA1 Message Date
Timothy Flynn
886f9016ab LibWeb: Iterate over text chunks using a grapheme-aware segmenter
Our current text iterator is not aware of multi-code point graphemes.
Instead of simply incrementing an iterator one code point at a time, use
our Unicode grapheme segmenter to break text into fragments.

(cherry picked from commit f0105b473b9cc3446ec36359b559db9a8e78446d;
amended as usual for Unicode::Segmenter -> Locale::Segmenter, and to
tweak expected/multi-code-point-graphemes.txt for serenity's superior
emoji glyphs)
2024-11-27 11:43:26 -05:00
Jelle Raaijmakers
cbf8857e8d LibWeb: Do not resolve inline block height early if height is definite
This condition was included to implement flex containers with auto
height, but it actually can reset the definitive height to 0 for inline
blocks with only replaced elements such as an SVG. Removing the
condition does not break any in-tree test, so let's improve the
situation on the SVG side of things for now.

(cherry picked from commit 352a66390f27fb7bbbfa823364fefc9af00d4b63)
2024-11-24 13:38:45 -05:00
Neil Viloria
698d7f33d6 LibWeb/Layout: Unify grid justify-content handling for grid area
(cherry picked from commit 9e2b70661ef1c13252a4b213fbd3b735f7301116)
2024-11-24 10:27:54 -05:00
Aliaksandr Kalenik
0928df5937 LibWeb: Resolve not auto height before child box layout in BFC
It's possible to resolve box's height without doing inner layout, when
computed value is not auto. Doing that fixes height resolution, when box
with percentage height has containing block with percentage height.

Before:
- resolve used width
- layout box's content
- resolve height

After:
- resolve used width
- resolve height if treated as not auto
- layout box's content
- resolve height if treated as auto

(cherry picked from commit 9098e39a43313e26023daeedc1dfee7e754ba8f3)
2024-11-24 10:27:12 -05:00
Andreas Kling
f1997d0f87 LibWeb: Allow intrinsic width layout to see definite heights
We were already allowing intrinsic height layout to see definite widths,
and I can't think of a reason *not* to allow it the other way around.

More importantly, this fixes an issue where things with an aspect ratio
didn't have a height to resolve against before.

Makes the logo show up on https://basecamp.com/ :^)

(cherry picked from commit 077bc68a4cbf2d8c97abc818515a22471da42c99)
2024-11-24 00:18:58 -05:00
Pavel Panchekha
ac1e869b20 LibWeb: Change inline float clearance to not reset margin collapsing
When a block container has `clear` set and some clearance is applied,
that clearance prevents margins from adjoining and therefore resets
the margin state. But when a floating box has `clear` set, that
clearance only goes between floating boxes so should not reset margin
state. BlockFormattingContexts already do that correctly, and this PR
changes InlineFormattingContext to do the same.

Fixes #1462; adds reduced input from that issue as test.

(cherry picked from commit 9075f64cacabe7f548481cf63dbaa3e532d93574)
2024-11-24 00:18:58 -05:00
Andreas Kling
303ec1c8a3 LibWeb: Don't let input element placeholders influence line-height
Before this change, we transferred the input element's line-height to
both the editable text *and* the placeholder. This caused some strange
doubling of the effective line-height when the editable text was empty,
pushing down the placeholder.

(cherry picked from commit 13ba491924c4fc3831d5a8986673d832a721f545;
amended some slighly different horizontal sizes in the expectations
file. Maybe due to serenity not using harfbuzz for shaping, or due
to not have another earlier change yet. If it's the latter, this will
fix itself when that's brought in.)
2024-11-23 23:48:34 -05:00
BenJilks
800b4c2301 LibWeb: Layout text chunks based on their Unicode direction
Append text chunks to either the start or end of the text fragment,
depending on the text direction. The direction is determined by what
script its code points are from.

(cherry picked from commit 11e7d72686d86b3e900c0e9ab76e75d3922f06d3;
amended to minorly tweak dimensions in expected files due to serenity
not using harfbuzz for text shaping)
2024-11-23 20:23:39 -05:00
Neil Viloria
a73fb690aa LibWeb/Layout: Implement align-content for grid layout
(cherry picked from commit b9e7c6a2f66d83c6af73bcc102c05d3056382c02)
2024-11-22 10:49:46 -05:00
Neil Viloria
40cc56b029 LibWeb/Layout: Implement justify-content for column spacing in grid
(cherry picked from commit 4bda65c8b361f74c4576a19a64b3f456d1224e7b)
2024-11-22 10:49:46 -05:00
Gingeh
45971381f0 LibWeb: Make empty media query lists evaluate to true
(cherry picked from commit 16f2f6aa4230ad7f2e4b502c1b5fabd53215220c)
2024-11-17 15:35:22 -05:00
Sam Atkins
f63a15665d LibWeb: Calculate hidden password text using code-point count
This means that an `<input type=password>` will show the correct number
of *s in it when non-ASCII characters are entered.

We also don't need to perform text-transform on these as that doesn't
affect the output length, so I've moved it earlier.

(cherry picked from commit c747b1c6b56156b5797fad0d8d95164f415c8b25;
amended to slightly adjust some BlockContainer and PaintableWithLines
widths, since serenity does not use harfbuzz for text shaping)
2024-11-14 23:38:34 -05:00
Simon König
e4903feab8 LibWeb: Don't crash on encountering display: list-item on pseudo element
On any `display: list-item` Node a CSS pseudo element (`::marker`) needs
to be created. This commit allows the ::maker pseudo element to be
nested within other pseudo elements (e. g. ::before or ::after).

This fixes this WPT test:
http://wpt.live/css/CSS2/generated-content/after-content-display-003.xht

(cherry picked from commit 15d2857a01b5bda90ace3d02cf9e1bc8ce279d38)
2024-11-13 10:17:34 -05:00
Tim Ledbetter
be7110a3a4 LibWeb: Map dimension attributes for table elements
(cherry picked from commit 140dc95e6769a41542f98abef333d5bc32b86e39)
2024-11-12 19:57:55 -05:00
Magnus Johansson
099f907420 LibWeb: Fallback to auto when aspect ratio is degenerate as per spec
When aspect-ratio is degenerate (e.g. 0/1 or 1/0) we should
fallback to the same behaviour as `aspect-ratio: auto` according to spec
This commit explicitly handles this case and fixes five WPT test in
css/css-sizing/aspect-ratio (zero-or-infinity-[006-010])

(cherry picked from commit c6f77f4818a03411c14d9e60b743a7541a8280f6)
2024-11-12 07:14:25 -05:00
Andreas Kling
1600dcaf19 LibWeb: Ignore boxes wholly in the negative scrollable overflow region
This fixes an issue where https://hey.com/ was horizontally scrollable
even though it shouldn't be.

(cherry picked from commit 94721385ceb17e20428b94a946d39828bdd5b74e)
2024-11-11 19:54:09 -05:00
Tim Ledbetter
736255ae87 LibWeb: Avoid division by zero in SourceSet width descriptor calculation
(cherry picked from commit 087d4004721193c290b18515e90b047192880a70)
2024-11-10 18:24:10 -05:00
Timothy Flynn
26551f6700 LibWeb: Always call document.close after document.write
This ensures the HTML parser completes running if it previously stopped
at an insertion point during a call to `document.write`.

(cherry picked from commit 230314238655204b89dd0736da4537b475eb252a)
2024-11-10 17:42:37 -05:00
Andreas Kling
bca2b88b45 LibWeb: Always blockify the root element
This is what the spec tells us to do:

    The root element’s display type is always blockified,
    and its principal box always establishes an independent
    formatting context.

    Additionally, a display of contents computes to block
    on the root element.

Spec link: https://drafts.csswg.org/css-display/#root

Fixes #1562

(cherry picked from commit f1be662f683155705f851bcf440fe30d0e606a87)
2024-11-10 10:46:01 -05:00
Aliaksandr Kalenik
8d56f0ed15 LibWeb: Print FIXME instead of crashing in abspos SVG element layout
Currently we are crashing in `verify_cast<BlockContainer>(box)` on
attempt to create BFC for SVG box.

(cherry picked from commit fa907029ee6f202095011b84b109bc4a2b56c58b)
2024-11-09 16:08:01 -05:00
Sam Atkins
fb1b93daba Tests/LibWeb: Correct typo in "overflow: visible"
The test happened to pass anyway because `visible` is the default value.

(cherry picked from commit 9f9ec45a3177cc776fb5bf6adce313b6d6942467)
2024-11-09 07:29:52 -05:00
Andreas Kling
438b1bddbc LibWeb: Implement vertical-align: middle correctly for atomic inlines
This makes inline icons pop into the right place on https://ahrefs.com/

(cherry picked from commit c22acc2551998e1e86970f89a452041dda8c3847)
2024-11-09 07:29:52 -05:00
Andreas Kling
c2a049e031 LibWeb: Derive SVG root's natural size from width/height attributes
We were incorrectly looking at the CSS computed values for width and
height to determine the natural size of <svg> root elements.
This meant that elements where the attribute and computed value were
different values would end up with incorrect natural size.

(cherry picked from commit 8eacfc8f10256f29fed0405a6bf1cb95e73b9bef)
2024-11-08 22:32:11 -05:00
Gingeh
a9dd1a165c LibWeb: Add tests for justify-*: left/right
(cherry picked from commit 1d30d84f4132fce8234e1755dec92d08491726ff)
2024-11-08 07:45:02 -05:00
Aliaksandr Kalenik
a1d89d5956 LibWeb: Fix wrong assumption that repeat() is always first track [GFC]
Fixes crashing in
https://wpt.live/css/css-grid/grid-definition/grid-auto-fit-columns-001.html

(cherry picked from commit ee41dbfec3c48dc58db45e413ff6b5eb11d2fd26)
2024-11-08 07:45:02 -05:00
Aliaksandr Kalenik
7ec8e933e2 LibWeb: Clamp growth limit after adding planned increase in GFC
Fixes implementation of the following line from the spec:
"However, limit the growth of any fit-content() tracks by their
fit-content() argument."

Now we correctly apply a limit to increased growth limit rather than to
the planned increase.

Change in "Tests/LibWeb/Layout/input/grid/fit-content-2.html" is a
progression and "Item as wide as the content." is actually as wide as a
content.

(cherry picked from commit 07aa25ce5095521437889079e511f6885684a762)
2024-11-08 07:45:02 -05:00
BenJilks
a9f5ae40e0 LibWeb: Use the correct dimension when computing the max grid size
When deciding if the grid containers min size should be limited by a
max size. Check for a max height or width depending on the dimension,
instead of just always checking for a max width.

(cherry picked from commit ef037b4152f96d88380005625b8d66761923b7ba)
2024-11-08 07:45:02 -05:00
Aliaksandr Kalenik
3048bcf599 LibWeb: Implement missing step in GFC fr size calculation
Implements:
"If the product of the hypothetical fr size and a flexible track’s flex
factor is less than the track’s base size, restart this algorithm
treating all such tracks as inflexible."

Fixes https://github.com/LadybirdBrowser/ladybird/issues/1211

(cherry picked from commit 7b2042571bf42d140bafb5e771c5bbadbcca2e9d)
2024-11-08 07:45:02 -05:00
Shannon Booth
fd427b4efe LibWeb: Handle cases with <template> on the HTML parsing stack
This appears to have been a bug in the spec which was later corrected -
so to fix the crash we can simply remove this assertion.

Fixes: #868
(cherry picked from commit 07940a89cad5ecfa21c2d1d8e055941bdb097ef9)
2024-11-07 23:07:20 -05:00
Aliaksandr Kalenik
8e3b7e3680 LibWeb: Skip documents of decoded SVGs while processing HTML event loop
None of HTML event loop processing steps are relevant for decoded SVGs,
so we can simply skip them while collecting documents for processing.

(cherry picked from commit c87214d79cf834ee9b7b4da65e902e5233c0a5cc)
2024-11-07 22:42:20 -05:00
Andreas Kling
fbe99575e0 LibWeb: Resolve flex item % main size to 0 during min-content sizing
When the flex container is sized under a min-content constraint in the
main axis, any flex items with a percentage main size should collapse
to zero width, not take up their own intrinsic min-content size.

This is not in the spec, but matches how other browsers behave.

Fixes an issue where the cartoons on https://basecamp.com/ were way
too large. :^)

(cherry picked from commit 59ed823724331d6457e81f8674aef392ca4dc174)
2024-11-04 21:46:05 -05:00
BenJilks
84617a7202 LibWeb: Add support for flex-wrap: wrap-reverse
Reverse the order of flex lines, when the `flex-wrap` property is set to
`wrap-reverse`. This will also swap the cross-start and cross-end
directions.

(cherry picked from commit 46649fbe1b015a7f4bfad4e059ecaf3c513f3a26)
2024-11-04 21:46:05 -05:00
BenJilks
91d454e252 LibWeb: Only reverse each line of a reverse flex-direction
When a flex container with a reverse `flex-direction` is wrapped. Only
each line should be reversed, not all items.

(cherry picked from commit e2c1fe7255c84ad1ee172765ef9f107949117098)
2024-11-04 21:46:05 -05:00
Andreas Kling
213f86d781 LibWeb: Adjust flex item intrinsic contributions through aspect ratio
When determining the intrinsic cross size contribution of a flex item
with a preferred aspect ratio, we have to account for any min/max
constraints in the main axis.

(cherry picked from commit bde2d3dc7b359cd4f56ad9975c44d22e43ef82fe)
2024-11-04 21:46:05 -05:00
Jelle Raaijmakers
94a64acb2e LibWeb: Account for intrinsic width or height in flex base size
In calculating the base size of a flex item, we have a piece of ad-hoc
code that deals with an item that does have an instrinsic aspect ratio,
but not a cross size to resolve that ratio against. In determining the
actual flex item size however, we also take into account the minimum
content width and height, which assumes the box' intrinsic width or
height when available. This would break having an image as a flex item,
which gets stretched to its maximum size within the flex container
instead of the flex item being shrunk to the instrinsic size of the
image.

Fix this by only stretching flex items that do not have an instrinsic
width nor height set.

(cherry picked from commit 7a783d3a89aec0caaa63a483c855fe921b6d0984)
2024-11-04 21:46:05 -05:00
Andreas Kling
b3e8e67ca3 LibWeb: Honor appearance: none when creating input element layout node
Per css-ui-4, setting `appearance: none` is supposed to suppress the
creation of a native-looking widget for stuff like checkboxes, radio
buttons, etc.

This patch implements this behavior by simply falling back to creating
a layout node based on the CSS `display` property in such cases.

This fixes an issue on the hey.com imbox page where we were rendering
checkboxes on top of sender profile photos.

(cherry picked from commit 58c523ae46af90ab17d6b98966d97fa776ae2bf4)
2024-11-04 10:34:34 -05:00
Andreas Kling
4a4da86792 LibWeb: Don't crash when encountering calc() inside a CSS rect() value
This allows us to run the WPT tests under quirks/unitless-length/
without crashing, giving us over 4600 new passing subtests. :^)

(cherry picked from commit 5df6c6eecff678bf2a1fe8960149302d42015439)
2024-10-26 23:26:45 -04:00
Andreas Kling
0ed1c4fcab LibWeb: Don't crash when encountering border-spacing: calc(...)
This allows us to progress further on this WPT test:
https://wpt.live/quirks/unitless-length/quirks.html

...although it still crashes before finishing.

(cherry picked from commit 5e240f997caa8b62275d3c5d18a1cf1885349971)
2024-10-26 23:26:45 -04:00
Aliaksandr Kalenik
ddd5e399e6 LibWeb: Use correct resolved type for round() CSS function
Function is defined as `round(<rounding-strategy>?, A, B?)`

With this change resolved type is `typeof(resolve(A))`, instead of
`typeof(A)`.

For example `round(up, 20%, 1px)` with 200px percentage basis is now
correctly resolved in 40px instead of 40%.

Progress on https://www.notion.so/ landing page.

(cherry picked from commit 41e37f00795920686fad7b211381905618fb345a)
2024-10-20 16:38:56 -04:00
Adam Harald Jørgensen
9c20df1684 LibWeb: Set correct longhand values when using grid-placement shorthand
According to https://www.w3.org/TR/css-grid-2/#placement-shorthands
when setting the 'grid-row' and 'grid-column' shorthand property to a
single <custom-ident> value, both 'grid-row-start'/'grid-column-start'
and 'grid-row-end'/'grid-column-end' should be set to that
<custom_ident>.

(cherry picked from commit 3e92ec80f3873bb81cbc8b0dc93bb3a6a145172c)
2024-10-11 21:15:26 -04:00
Sam Atkins
39b3746306 LibWeb/CSS: Treat counters() function with 1 argument as invalid
Fixes LadybirdBrowser/ladybird#887.

(cherry picked from commit 5abe246385dc70e9b69426cd19302d28b7d869d0)
2024-10-10 09:36:41 -04:00
BenJilks
1741fee83f LibWeb: Add start and end values to text-align
The `start` and `end` value set the text alignment based on the computed
value of `direction`. The default value of `text-align` is now `start`
instead of `left`.

(cherry picked from commit 1537d589ca4908c3631dc38e66c97fd37fa2f526)
2024-09-29 08:03:58 -04:00
BenJilks
20c9e18d25 LibWeb: Use reverse direction on flex containers with rtl direction
If a flex container has `direction: rtl` set, reverse the row direction.

(cherry picked from commit 82989554abf6ca8f261de9a51c9e3d3c20f5e68b)
2024-09-29 08:03:58 -04:00
BenJilks
736c931a15 LibWeb: Add additional padding to the end of the scrollable overflow
Adds additional padding to the end-side of the scrollable overflow
rectangle as necessary to enable a scroll position that satisfies
the requirements of `place-content: end` alignment.

(cherry picked from commit 963cf1c2c4e4b1cd482c41d6f673b7207bbcc067)
2024-08-13 15:43:28 -04:00
Sam Atkins
fc6c6573b1 LibWeb: Prevent elements with no layout box from modifying counters
(cherry picked from commit 696ccc1aa992fdd7e22a44571d8be7d89738261d)
2024-07-28 13:31:02 -04:00
Sam Atkins
6ab5a043e6 Last: LibWeb: Add counter() and counters() functions to content property
These let you format counters' current values as strings for use in
generated content.

(cherry picked from commit 898e3bd89878ddb87df06e056031673dc770be2b)
2024-07-28 13:31:02 -04:00
Sam Atkins
c847487f30 LibWeb: Reserve enough space for span>1 columns in BorderConflictFinder
This code previously only allocated enough space in
m_col_elements_by_index for 1 slot per column, meaning that columns
with a span > 1 would write off the end of it.

(cherry picked from commit 9e32c9329acd89d73eeff3494a5e728077962513)
2024-07-28 13:00:11 -04:00
Andreas Kling
a8a5463d33 LibWeb: Make offsetTop and offsetLeft behave more like other browsers
We now follow the rules from the spec more closely, along with an
unspecified quirk for when the offsetParent is a non-positioned body
element. (Spec bug linked in a comment.)

This fixes a whole bunch of css-flexbox tests on WPT, which already had
correct layout, but the reported metrics from JS API were wrong.

(cherry picked from commit d49ae5af32044cb83bc14073b92676a1662c3bc1)
2024-07-28 07:32:17 -04:00
Edwin Hoksberg
dd843ae282 LibWeb: Implement grid-template function fit-content()
(cherry picked from commit e5deaa1c073f4762fe2cdc7d36f90099f0ca4d11)
2024-07-28 07:31:47 -04:00
Andreas Kling
c2fce0f19c LibWeb: Implement :host and :host(<compound-selector>) selector matching
The :host family of pseudo class selectors select the shadow host
element when matching against a rule from within the element's shadow
tree.

This is a bit convoluted due to the fact that the document-level
StyleComputer keeps track of *all* style rules, and not just the
document-level ones.

In the future, we should refactor style storage so that shadow roots
have their own style scope, and we can simplify a lot of this.

(cherry picked from commit 4c326fc5f6f64797764e7f32a9789b74665f2fec)
2024-07-27 22:53:52 -04:00