Commit graph

405 commits

Author SHA1 Message Date
Aliaksandr Kalenik
4a7b947c5d LibWeb: Clamp content-based minimum size by limited max track size [GFC]
Progress on https://wpt.live/css/css-grid/grid-items/grid-minimum-size-grid-items-022.html
2025-03-18 15:01:02 +01:00
stasoid
a6935299eb LibWeb: Correctly calculate static position rect when absolutely
positioned element is a descendant of inline-block

Sets inline block offsets in InlineFormattingContext.cpp, but this is
not enough. When static position rect is calculated during layout,
not all ancestors of abspos box may have their offsets calculated yet
(more info here: https://github.com/LadybirdBrowser/ladybird/pull/2583#issuecomment-2507140272).
So now static position rect is calculated relative to static containing
block during layout and calculation relative to actual containing block
is done later in
FormattingContext::layout_absolutely_positioned_element.

Fixes wpt/css/CSS2/abspos/static-inside-inline-block.html
2025-03-17 15:55:06 +01:00
Sam Atkins
95730c66aa LibWeb: Make non-replaced flex items make use of transferred size
Corresponds to 9beaea1f2a
2025-03-17 09:35:58 +00:00
Aliaksandr Kalenik
2e256d2eac LibWeb: Invalidate text-decoration-thickness as paint-only property
Fixes underinvalidation caused by resolving text-decoration-thickness
during layout commit, while this property can be invalidated
independently of layout.
2025-03-16 22:25:26 +01:00
Aliaksandr Kalenik
23151de217 LibWeb/Layout: Fix min{max}-content size calculation for grid items
Instead of directly invoking `to_px()`,
`calculate_min_content_contribution()` needs to use
`calculate_inner_width()` and `calculate_inner_height()`, which are
aware of how to correctly handle `min-content` and `max-content` values.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/3469
2025-03-15 13:51:16 +01:00
Aliaksandr Kalenik
08c155cd3f LibWeb: Resolve "height: auto" using preferred aspect ratio if possible
Fixes https://github.com/LadybirdBrowser/ladybird/issues/2276
2025-03-15 13:51:16 +01:00
Aliaksandr Kalenik
227b4c38b7 LibWeb: Use parent's available space for anonymous blocks in BFC
Height resolution assumes that when available space is definite, it
matches the size of non-anonymous containing block. With this change, we
correctly maintain this assumption when box is wrapped in anonymous
node.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/3422
2025-03-15 13:31:07 +01:00
Aliaksandr Kalenik
733d124380 LibWeb: Delete root pointer in LayoutState
It's no longer needed after we moved intrinsic sizes cache into layout
nodes.
2025-03-14 01:27:40 +01:00
Aliaksandr Kalenik
76aa99a626 LibWeb: Update HTMLSlotElement subtree during partial layout tree build
Before this change, the layout tree for slots was only updated after
creating a layout node for the slot itself. This was not enough to
account for partial layout tree rebuilds when the slot content changed.
With this change, we always recurse into the slot content.

Fixes expanding and collapsing of nodes in DOM tree inspector broken in
9b26f7eb0f
2025-03-13 04:29:26 +01:00
Tim Ledbetter
88d35c547c LibWeb/CSS: Implement the caret-color property 2025-03-09 19:36:29 +01:00
Aliaksandr Kalenik
667cb01b60 LibWeb: Fix layout mode propagation in SVGFormattingContext 2025-03-09 18:40:37 +01:00
Aliaksandr Kalenik
a4463c45b9 LibWeb: Bring back cache of intrinsic sizes across layout runs
12c6ac78e2 with fixed mistake when cache
slot is copied instead of being referenced:
```cpp
auto cache =
    box.cached_intrinsic_sizes().min_content_height.ensure(width);
```
while it should've been:
```cpp
auto& cache =
    box.cached_intrinsic_sizes().min_content_height.ensure(width);
```
2025-03-08 14:52:33 +01:00
Andreas Kling
73a4b176cf Revert "LibWeb: Cache intrinsic sizes across layout runs"
This reverts commit 12c6ac78e2.

Very large performance regression when viewing GitHub repository pages.
2025-03-08 12:08:51 +01:00
Aliaksandr Kalenik
12c6ac78e2 LibWeb: Cache intrinsic sizes across layout runs
This change moves intrinsic sizes cache from
LayoutState, which is local to current layout run,
to layout nodes, so it could be reused between
layout runs. This optimization is possible because
we can guarantee that these measurements will
remain unchanged unless the style of the element
or any of its descendants changes.

For now, invalidation is implemented simply by
resetting cache on whole ancestors chain once we
figured that element needs layout update.
The case when layout is invalidated by DOM's
structural changes is covered by layout tree
invalidation that drops intrinsic sizes cache
along with layout nodes.

I measured improvement on couple websites:
- Mail list on GMail 28ms -> 6ms
- GitHub large code page 47ms -> 36ms
- Discord chat history 15ms -> 8ms
(Time does not include `commit()`)
2025-03-08 11:45:36 +01:00
Andreas Kling
267b84ebb6 LibWeb: Skip flex/grid layout when doing intrinsic sizing for ancestor
We don't need to perform inside layout of flex and grid formatting
contexts when one of their ancestors is undergoing intrinsic size
measurement. This is because the parent formatting context will have
already sized the flex/grid container, and thus inside layout is
completely redundant work.
2025-03-08 03:37:38 +01:00
Aliaksandr Kalenik
dd78d5d50e LibWeb: Don't layout grid descendants in intrinsic layout mode
We already have a check to skip the layout of descendants if the
available size is intrinsic, but this is not sufficient in nested
intrinsic layout cases, where the available size might be definite even
though we are in intrinsic layout mode.
2025-03-05 21:40:59 +01:00
Aliaksandr Kalenik
b51c026f3d LibWeb: Don't layout flex descendants in intrinsic layout mode
We already have a check to skip the layout of descendants if the
available size is intrinsic, but this is not sufficient in nested
intrinsic layout cases, where the available size might be definite even
though we are in intrinsic layout mode.
2025-03-05 21:40:59 +01:00
Lukas Scheller
ce93088a81 LibWeb: Respect margin boxes when center-aligning flex items 2025-03-05 18:07:10 +01:00
Tommy van der Vorst
056205aa76 LibWeb/CSS: Treat 'mask' as a longhand property
Before this change, an element masked with 'mask-image: url(...)' would
show the mask, but 'mask: url(...)' would not. On e.g. dialogic.nl it
would show white boxes instead of the actual images in the top
navigation bar. We still do not support many of the other mask
properties, but with this change at least the masks show up in both
cases.
2025-03-05 12:10:02 +00:00
Aliaksandr Kalenik
da5d4e9f6a LibWeb: Assign sticky insets to Layout::InlineNode
Before this change we were ignoring boxes with `display: inline` while
assigning sticky insets. This was not correct because inline boxes are
allowed to have sticky positioning.

Fixes:
https://github.com/LadybirdBrowser/ladybird/issues/3718
https://github.com/LadybirdBrowser/ladybird/issues/3507
https://github.com/LadybirdBrowser/ladybird/issues/3133
2025-02-27 19:55:46 +01:00
Andreas Kling
5331571fdc LibWeb: Handle interleaved table-row and table-row-group boxes
Before this change, we were always processing all row groups first,
and then all rows. This led to incorrect table layouts when rows and row
groups were encountered in anything but that order.
2025-02-26 13:50:01 +01:00
Andreas Kling
47f5da7523 LibWeb: Actually, don't align all inline content to alphabetic baseline
This essentially reverts 1b46a52cfc
and adds more tests.

The reverted change was an incorrect workaround for the real issue,
which was that we weren't creating anonymous wrapper boxes around inline
children of table-cell boxes.

Now that this has been fixed, we can go back to aligning text properly.
2025-02-25 23:55:36 +01:00
Andreas Kling
7d4d7da28a LibWeb: Wrap inline children of table-cell in anonymous block
This fixes an issue where CSS vertical-align on a table-cell box would
incorrectly apply to both the table-cell box and any inline content it
had inside.
2025-02-25 23:55:36 +01:00
InvalidUsernameException
f7276bfab3 LibWeb: Reduced number of recompiled files for CSS property headers
Some checks are pending
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This reduces the number of `.cpp` files that need to be recompiled when
one of the below header files changes as follows:

CSS/ComputedProperties.h: 1113 -> 49
CSS/ComputedValues.h: 1120 -> 209
2025-02-23 10:14:39 -05:00
InvalidUsernameException
be47f95180 LibWeb: Reduce number of recompiled files for display list headers
This reduces the number of `.cpp` files that need to be recompiled when
one of the below header files changes as follows:

Painting/Command.h: 1030 -> 61
Painting/DisplayList.h: 1030 -> 60
Painting/DisplayListRecorder.h: 557 -> 59
2025-02-23 10:14:39 -05:00
Andreas Kling
cdd2ccac0b LibWeb: Resolve used vertical margins on inline elements
Even though we don't actually make use of these values at the moment,
we still want them to be reflected correctly once we start exposing used
margin values soon.
2025-02-22 20:02:16 +01:00
Andreas Kling
591f06f887 LibWeb: Leave right margin along when BFC solves for width
We were incorrectly shrinking the used right margin to make it fit
within the available space, even though this was not necessary and the
margin is allowed to stretch beyond the containing block.

This is not observable yet, but will be once we start exposing used
margin values in a subsequent change.
2025-02-22 20:02:16 +01:00
Andreas Kling
16662ab230 LibWeb: Account for collapsed top margins in BFC root height calculation
By the time we're measuring the height of a BFC root, we've already
collapsed all relevant margins for the root and its descendants.
Given this, we should simply use 0 (relative to the BFC root) as the
lowest block axis coordinate (i.e Y value) for the margin edges.

This fixes a long-standing issue where BFC roots were sometimes not tall
enough to contain their children due to margins.
2025-02-22 18:41:42 +01:00
Psychpsyo
c0eb072645 LibWeb: Add CSS view-transition-name 2025-02-22 14:52:13 +00:00
Tim Ledbetter
2e27ffab6c LibWeb: Exclude inert elements from find in page queries 2025-02-21 12:41:57 +00:00
Glenn Skrzypczak
0750513993 LibWeb: Support reversed ordered lists
Some checks are pending
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This PR adds support for the `reversed` attribute of
ordered lists.
2025-02-21 04:23:28 +00:00
Andreas Kling
1b46a52cfc LibWeb: Always align inline text content to the alphabetic baseline
This fixes an issue where `vertical-align: middle` would incorrectly
shift the text away from the natural alphabetic baseline.

Fixing this makes many WPT table tests work correctly, so I'm also
importing one of them here. :^)
2025-02-21 01:16:38 +00:00
Jelle Raaijmakers
5f5d18d719 LibWeb: Do not crash when inserting block elements into inline SVGBoxes
Fixes #3395.
2025-02-19 13:49:24 +01:00
Jelle Raaijmakers
0c58dad7a6 LibWeb: Factor out conditions for creation of inline continuation
Having one big `if` to determine whether or not we should restructure an
inline layout node became a bit unwieldy. This extracts the logic into a
separate method.
2025-02-19 13:49:24 +01:00
Jelle Raaijmakers
c0109039cb LibWeb: Do not consider <foreignObject> for inline continuation
We used to have an exception for this element that erroneously got
removed in 336684bc5c.

Fixes #3453.
2025-02-19 13:49:24 +01:00
Jelle Raaijmakers
de7ca7b157 LibWeb: Retain display: contents in ancestor stack for continuations
When restructuring inline nodes because of a block element insertion
during the layout tree build, we might end up with a `display: contents`
element in the ancestor stack that is not part of the actual layout
tree, since it's never actually used as a parent for any node. Because
we were only rewinding the ancestor stack with actual new layout nodes,
it became corrupted and layout nodes were added to the wrong parent.

This new logic leaves the ancestor stack intact, only replacing layout
nodes whenever a new one is created.

Fixes the sidebar on https://reddit.com.
Fixes #3590.
2025-02-18 23:31:49 +01:00
Andreas Kling
fb020a3c8f LibWeb: Store final box model metrics in paint tree, not layout tree
This was a weird case of layout results being stored in the layout tree
instead of in the paint tree like everything else.
2025-02-17 18:28:29 +01:00
InvalidUsernameException
29d74632c7 LibWeb: Move z-index to table wrapper box
When drawing a table, some of the CSS properties must be moved from the
table grid box to an anonamyous table wrapper box. One of these
properties is `position`. `z-index` however is not. This leads to the
following behavior if a table has both `position` and `z-index`:
* The wrapper box has the `position`, but a `z-index` of `auto`.
* The grid box has the `z-index`, but `position: static`.

This effectively means that the `z-index property is ignored since it
has no effect on non-positioned elements. This behavior contradicts what
other browsers do and causes layout issues on websites.

To align Ladybird behavior with other browser this commit also moves the
`z-index` property to the wrapper box.
2025-02-16 21:05:59 +01:00
Andreas Kling
0705efda13 LibWeb: Use cached UsedValues pointer for floating boxes in more places 2025-02-12 00:39:36 +01:00
Andreas Kling
81deaad7ad LibWeb: Cache UsedValues pointers in GridFormattingContext and use them 2025-02-12 00:39:36 +01:00
Andreas Kling
fee0d408a1 LibWeb: Assume flex container forms containing block of abspos items
This avoids a dubious-looking UsedValues lookup.
2025-02-12 00:39:36 +01:00
Andreas Kling
d43cc82b1c LibWeb: Use cached UsedValues pointer in FlexFormattingContext more 2025-02-12 00:39:36 +01:00
Andreas Kling
2f5ce0fcb6 LibWeb: Make LayoutState::UsedValues::m_node a const pointer
No mutations should ever be made to the layout node through this
pointer (and none were).
2025-02-12 00:39:36 +01:00
Andreas Kling
bf15c7fa4b LibWeb: Remove "temporary content size" hack from flex layout
This was an old hack intended to make percentage sizes on flex items
before we had implemented the appropriate special behavior of definite
sizes in flex layout.

Removing it makes flex layout less magical and should not change
behavior in any observable way.
2025-02-11 14:23:13 +01:00
Andreas Kling
4cbd975b66 LibWeb: Simplify determination of flex item's hypothetical cross size
The spec tells us to treat `auto` as `fit-content` when determining
flex item cross sizes, so let's just do *that* instead of awkwardly
doing an uncacheable nested layout of the item.

This was the only instance of `LayoutState` nesting outside of intrinsic
sizing, so removing it is an important step towards simplifying layout.
Turns out it was a lot easier than expected.
2025-02-11 14:23:13 +01:00
Sam Atkins
0fd0596dbf LibWeb: Support strings as list-style-types
We've long claimed to support this, but then silently ignored string
values, until 4cb2063577 which would
not-so-silently crash instead. (Oops)

So, actually pass the string value along and use it in the list marker.

As part of this, rename our `list-style-type` enum to
`counter-style-name-keyword`. This is an awkward name, attempting to be
spec-based. (The spec says `<counter-style>`, which is either a
`<counter-style-name>` or a function, and the `<counter-style-name>` is
a `<custom-ident>` that also has a few predefined values. So this is the
best I could come up with.)

Unfortunately only one WPT test for this passes - the others fail
because we produce a different layout when text is in `::before` than
when it's in `::marker`, and similar issues.
2025-02-11 10:39:27 +01:00
Sam Atkins
b987d53926 LibWeb: Migrate ListItemMarkerBox's text from ByteString to String 2025-02-11 10:39:27 +01:00
Andreas Kling
0084d992d4 LibWeb: Remove unnecessary re-measurement of cross sizes in flex layout
This was an old hack from before we understood how and when to resolve
percentages in flex layout. Removing it should not change anything,
but it does avoid a lot of redundant layout work on many pages.
2025-02-10 01:26:34 +01:00
Psychpsyo
402d8220dd LibWeb: Make style containment influence quotes 2025-02-06 17:44:50 +00:00
Psychpsyo
9b8120d8e8 Meta: Disallow links to single-page HTML spec 2025-02-05 16:04:50 -07:00