Commit graph

203 commits

Author SHA1 Message Date
Callum Law
64ccb9a015 LibWeb: Make @counter-style tree-scoped
This was a pretty straightforward change of storing registered counter
styles on the relevant `StyleScope`s and resolving by following the
process to dereference a global tree-scoped name, the only things of
note are:
 - We only define predefined counter styles (e.g. decimal) on the
   document's scope (since otherwise overrides in outer scopes would
   themselves be overriden).
 - When registering counter styles we don't have the full list of
   extendable styles so we defer fallback to "decimal" for undefined
   styles until `CounterStyle::from_counter_style_definition`.
2026-04-15 11:07:38 +01:00
Callum Law
fedd1f8d55 LibWeb: Add method to get style scope from layout node 2026-04-15 11:07:38 +01:00
Jelle Raaijmakers
4293c841f3 LibWeb: Implement CSS anchor positioning
When `position-anchor` is used, resolve the insets for that absolutely
positioned box.

Co-authored-by: Rob Ryan <rob@affclicks.com>
2026-04-01 19:41:46 +01:00
Jelle Raaijmakers
3d2571b46e LibWeb: Implement text-decoration-skip-ink painting
Use Skia's SkTextBlob::getIntercepts() to find where glyph outlines
cross the underline/overline band, then split the decoration line into
segments with gaps around those intersections.
2026-03-26 12:15:36 +00:00
Luke Wilde
df32da5e86 LibWeb: Make every HTMLElement potentially form-associated
This can be the case for form-associated custom elements, where any
HTML element can be form-associated.
2026-03-25 13:18:15 +00:00
Callum Law
f347be8206 LibWeb: Store underlying RatioStyleValue values as StyleValues
Previously we stored a fully formed `Ratio` - this restricted us from
supporting calculated values which will be implemented in a later commit
2026-03-24 14:00:01 +00:00
Callum Law
b07ef9435e LibWeb: Remove fallback behavior from color_or_fallback
All of the properties using this method only accept color values so the
fallback behavior wasn't required
2026-03-24 13:56:01 +01:00
Callum Law
e2f2f813b6 LibWeb: Handle accent-color auto value explicitly
`accent-color` is the only user of the fallback functionality of
`color_or_fallback`, by handling this explicitly we can remove that
fallback functionality in a later commit.

Also includes a couple of improvements for `accent-color` specifically:
 - We don't set it in `ComputedValues` twice.
 - `ComputedProperties::accent_color` returns a non-optional value
   (since we always have one)
 - `ComputedProperties::accent_color` takes a `ColorResolutionContext`
   instead of generating one itself from a `LayoutNode`, this will allow
   us to reuse shared resolution contexts in the future
2026-03-24 13:56:01 +01:00
Tim Ledbetter
2fbc4d26ff LibWeb: Allow SVG root elements to participate in inline continuation 2026-03-05 17:16:42 +01:00
Michael Watt
1243dbd72f LibWeb: Create absolute container for will-change: position
This fixes:
http://wpt.live/css/css-will-change/will-change-abspos-cb-001.html
2026-03-03 16:52:57 +01:00
Tim Ledbetter
804287847a LibWeb: Add SVG paint fallback color support to CSS parsing 2026-02-27 17:14:50 +01:00
Andreas Kling
a146225331 LibWeb: Use unsafe layout/paintable accessors where appropriate
Add unsafe_layout_node(), unsafe_paintable(), and unsafe_paintable_box()
accessors that skip layout-staleness verification. These are for use in
contexts where accessing layout/paintable data is legitimate despite
layout not being up to date: tree construction, style recalculation,
painting, animation interpolation, DOM mutation, and invalidation
propagation.

Also add wrapper APIs on Node to centralize common patterns:
- set_needs_display() wraps if (unsafe_paintable()) ...set_needs_display
- set_needs_paint_only_properties_update() wraps similar
- set_needs_layout_update() wraps if (unsafe_layout_node()) ...

And add Document::layout_is_up_to_date() which checks whether layout
tree update flags are all clear.
2026-02-26 21:09:08 +01:00
Tim Ledbetter
f05bc7c0cd LibWeb: Implement dominant-baseline for SVG text
This property determines the default baseline used to align content
within the given box.
2026-02-26 09:23:23 +01:00
Callum Law
8d4084261a LibWeb: Resolve list item marker using registered counter styles 2026-02-23 11:21:09 +00:00
Callum Law
32b9ff21df LibWeb: Add generic int_from_style_value method
Reduces duplication in line with `number_from_style_value`,
`string_from_style_value` etc
2026-02-23 11:21:09 +00:00
Zaggy1024
dd0c821291 LibWeb: Allow replaced elements to host children
We add a new formatting context that simply runs layout for an
anonymous block formatting context within it. This allows replaced
elements to contain children, if the parent rewrites inline-flow to
inline-block.
2026-02-23 07:27:31 +01:00
Andreas Kling
1b41c9109d LibWeb: Cache is_body() on layout nodes
Cache the result of the body element check as a bool set once during
NodeWithStyle construction, instead of calling document().body() (which
walks the children of <html>) on every call. This is called from
PaintableBox::paint_background() for every box on every frame.

This was 0.9% of CPU time while playing a YouTube video.
2026-02-21 15:53:22 +01:00
Aliaksandr Kalenik
b3231ea2a0 LibWeb: Make foreignObject establish a containing block for abspos
Absolutely positioned elements inside SVG foreignObject were being
positioned relative to an ancestor containing block outside the SVG,
instead of relative to the foreignObject itself. Per a W3C resolution
and the behavior of other browsers, foreignObject should establish a
containing block for absolutely and fixed positioned elements.

With this fix, the `has_abspos_with_external_containing_block` check
in `set_needs_layout_update()` and the abspos preservation loop in
`relayout_svg_root()` become dead code — remove both and simplify the
ancestor loops. Rename related tests to reflect the new behavior.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/3241
2026-02-17 15:59:59 +01:00
Callum Law
3d3d0a50b6 LibWeb: Add generic Length::from_style_value method 2026-02-16 12:09:23 +00:00
Callum Law
846493831d LibWeb: Add generic number_from_style_value method 2026-02-16 12:09:23 +00:00
Psychpsyo
a7267f711b LibWeb: Add overflow-clip-margin-* properties
The corner radius isn't quite right yet, but this gives us
another couple WPT passes for these.
2026-02-14 22:58:21 +01:00
Aliaksandr Kalenik
085cf42712 LibWeb: Fix SVG partial relayout skipping abspos sibling updates
When a CharacterData mutation inside a foreignObject triggered partial
SVG relayout, sibling absolutely positioned elements whose containing
block is outside the SVG were not being repositioned. This happened
because the check only walked ancestors of the changed node looking for
abspos elements — it never saw abspos siblings.

Fix by querying contained_abspos_children() on boxes outside the SVG
subtree, which finds all abspos elements regardless of their position
in the tree relative to the changed node.
2026-02-14 03:20:34 +01:00
Aliaksandr Kalenik
01334c4481 LibWeb: Fix partial relayout of abspos with containing block outside SVG
When a text node changes inside an absolutely positioned element within
an SVG <foreignObject>, and the abspos element's containing block is
outside the SVG subtree, the layout invalidation was incorrectly
stopping at the SVG root boundary. This triggered partial SVG relayout,
which cannot re-layout the abspos element since it's laid out by its
containing block's formatting context (outside the SVG).

The previous check only tested whether `this` (the node triggering
invalidation, e.g. a text node) was absolutely positioned, missing the
case where an abspos *ancestor* in the path has its containing block
outside the SVG. Fix this by walking from `this` up to the SVG root and
checking every abspos node in the path. If any has a containing block
outside the SVG subtree, skip the SVG boundary so layout propagation
continues upward and a full layout runs.
2026-02-13 17:47:49 +01:00
Callum Law
87eef9e21a LibWeb: Always apply stroke-dasharray
Previously we didn't apply the value of `stroke-dasharray` if it was
`none`.

We also move resolution of this property into `ComputedProperties` in
line with other properties.
2026-02-12 10:26:43 +00:00
Callum Law
379db7a42c LibWeb: Support animation-timeline scroll() value 2026-02-11 10:49:34 +01:00
Tim Ledbetter
6cf506d980 LibWeb: Allow table fixup to find internal table boxes in inline parents 2026-02-11 09:58:38 +01:00
Aliaksandr Kalenik
abecc746d7 LibWeb: Implement partial SVG relayout
Previously, any SVG geometry attribute change would mark the entire
document layout tree as dirty, triggering a full layout pass even though
only the SVG subtree was affected. This made SVG geometry animations
unnecessarily expensive.

Fix this by stopping `needs_layout_update` propagation at the SVGSVGBox
boundary and tracking dirty SVG roots separately on the Document. When
`update_layout()` finds that only SVG roots need relayout (and the
document layout root is clean), it runs SVGFormattingContext on each
dirty SVG root in a fresh LayoutState and commits the results directly,
bypassing the full document layout pass entirely.

This results in a substantial performance improvement on pages with
animated SVGs, such as https://www.cloudflare.com/,
https://www.duolingo.com/, and our GC graph explorer page.
2026-02-09 03:02:49 +01:00
Aliaksandr Kalenik
12ba454a5b LibWeb: Stop intrinsic size cache invalidation at SVG root boundaries
SVG root elements (SVGSVGBox) have intrinsic sizes determined solely
by their own attributes (width, height, viewBox), not by their
children. SVGFormattingContext::automatic_content_width/height() both
return 0 unconditionally, confirming children never contribute to the
SVG root's intrinsic size from the CSS layout perspective.

This means changes inside an SVG subtree cannot affect ancestor
intrinsic sizes, so we can stop the cache invalidation traversal at
SVG root boundaries, just like we already do for absolutely positioned
elements.
2026-02-05 20:26:30 +01:00
Callum Law
a0c8dc29b8 LibWeb: Don't return unnecessary optional when propagating border radius 2026-02-03 10:33:04 +00:00
Callum Law
0c4bab4390 LibWeb: Simplify ComputedProperties::length_box
Value clamping is no longer required since we now do it at interpolation
time (96b628f)
2026-02-03 10:33:04 +00:00
Callum Law
f13e0bb8a5 LibWeb: Replace ComputedProperties::length_percentage
Since we now clamp values as part of interpolation (96b628f) this
function is equivalent to `LengthPercentage::from_style_value`
2026-02-03 10:33:04 +00:00
Callum Law
11654d0d7e LibWeb: Propagate rx/ry auto value in apply_style
We stored and initialized this value as a `LengthPercentageOrAuto` but
didn't propagate a computed `auto` value.
2026-02-03 10:33:04 +00:00
Vahan Arakelyan
d04b74555b LibWeb/CSS: Make accentColor and accentColorText take accent-color value 2026-02-02 14:19:08 +00:00
Callum Law
b55023fad3 LibGfx+LibWeb: Resolve font features per font rather than per element
Previously we would resolve font features
(https://drafts.csswg.org/css-fonts-4/#feature-variation-precedence)
per element, while this works for the current subset of the font feature
resolution algorithm that we support, some as yet unimplemented parts
require us to know whether we are resolving against a CSS @font-face
rule, and if so which one (e.g. applying descriptors from the @font-face
rule, deciding which @font-feature-values rules to apply, etc).

To achieve this we store the data required to resolve font features in a
struct and pass that to `FontComputer` which resolves the font features
and stores them with the computed `Font`.

We no longer need to invalidate the font shaping cache when features
change since the features are defined per font (and therefore won't ever
change).
2026-02-02 14:11:43 +00:00
Aliaksandr Kalenik
04e777b493 LibWeb: Always update filter and backdrop-filter in apply_style()
Previously, filter and backdrop-filter were only set when they had
filters (has_filters() returned true). This meant that when these
properties were changed to 'none', the old filter values were never
cleared from computed_values.

This caused elements to incorrectly retain their stacking contexts
after setting filter/backdrop-filter to none, because
establishes_stacking_context() continued to see the old filter values.
2026-01-28 18:05:41 +01:00
Callum Law
afdde488c3 LibWeb: Correctly parse logical border-*-*-radius shorthands
Builds on #7609 by parsing these properties correctly in the first place
2026-01-25 10:22:10 +01:00
Aliaksandr Kalenik
2075eddbf1 LibWeb: Fix logical border-radius properties not being applied
Logical border-radius properties are parsed as Percentage/Length values,
not BorderRadiusStyleValue. Handle these types when applying style.
2026-01-24 21:43:23 +01:00
Andreas Kling
dc79259970 LibWeb: Support inline elements as abspos containing blocks
CSS allows inline elements with `position: relative` (or other
containing-block-establishing properties) to serve as the containing
block for their absolutely positioned descendants. However, our layout
system stores containing blocks as `Box*`, which cannot represent
inline elements (they are `InlineNode`, not `Box`).

This patch adds a workaround: when computing containing blocks, we
also check if there's an inline element between the abspos element
and its Box containing block that should actually be the CSS
containing block. If found, we store it in a new member called
`m_inline_containing_block_if_applicable` and use it during abspos
layout to:

1. Compute the inline's fragment bounding box as the containing
   block rectangle (including padding, per CSS spec)
2. Resolve percentage-based insets against the inline's dimensions
3. Position the abspos element relative to the inline's location

Some details to be aware of:

- The inline containing block search happens in the function
  `recompute_containing_block()` by walking DOM ancestors (not layout
  tree ancestors, since the layout tree restructures blocks inside
  inlines as siblings)

- For pseudo-elements like `::after`, we start the search from the
  generating element itself, since it may be the inline containing
  block

- Fragment offsets are relative to their block container, so we
  translate the computed rect to the abspos element's containing
  block coordinate system by accumulating offsets up the ancestor
  chain

- When the abspos element uses static position (auto insets), we
  don't apply the inline rect translation since static position is
  already computed in the correct coordinate system

Long term, we want to refactor our "containing block" concept to
map more cleanly to the spec concept. That means turning it into
a rectangle instead of the box this rectangle was derived from.
That's an invasive change for another day though.
2026-01-19 17:34:46 +01:00
Michael Watt
9e35e06dc3 LibWeb: Create containing blocks for non-initial filter values
This fixes:
http://wpt.live/css/css-will-change/will-change-abspos-cb-002.html
http://wpt.live/css/css-will-change/will-change-abspos-cb-003.html
http://wpt.live/css/css-will-change/will-change-fixedpos-cb-001.html
http://wpt.live/css/css-will-change/will-change-fixedpos-cb-004.html
2026-01-12 11:52:50 +00:00
Jonathan Gamble
4579bb5bed LibWeb: Add resize property plumbing 2026-01-12 11:00:14 +00:00
Andreas Kling
a9cc425cde LibJS+LibWeb: Add missing GC marking visits
This adds visit_edges(Cell::Visitor&) methods to various helper structs
that contain GC pointers, and makes sure they are called from owning
GC-heap-allocated objects as needed.

These were found by our Clang plugin after expanding its capabilities.
The added rules will be enforced by CI going forward.
2026-01-07 12:48:58 +01:00
Sam Atkins
89def06fcc LibWeb/Layout: Implement fixed positioning containing blocks
Previously we only allowed the viewport itself to be the containing
block for fixed-position elements, but the specs give us a few other
situations. Many of these are the same as for absolute-positioned ones.
2026-01-06 15:54:57 +00:00
Sam Atkins
cc3e427498 LibWeb/Layout: Make transform-style: preserve-3d establish APCBs 2026-01-06 15:54:57 +00:00
Sam Atkins
cf2520d6a4 LibWeb/Node: Rename Node::can_contain_boxes_with_position_absolute()
This method matches the spec concept of "establishing an absolute
positioning containing block", so let's use that name.
2026-01-06 15:54:57 +00:00
Aliaksandr Kalenik
5336c53171 LibWeb: Stop intrinsic size cache invalidation at abspos boundaries
When content changes inside a layout node, we now reset intrinsic size
caches only up to the nearest absolutely positioned ancestor, rather
than all the way to the document root.

This optimization is safe because absolutely positioned elements don't
contribute to their ancestors' intrinsic sizes - they are skipped in
min/max content width calculations.

The needs_layout_update flag still propagates to all ancestors so the
document knows layout is needed. Only the cache reset is bounded.
2026-01-05 23:00:06 +01:00
Callum Law
79740b04b3 LibWeb: Don't generate layer for background-image none entry
Reduces the time spent in `background_layers()` from 1.5% to 0.04% when
loading https://en.wikipedia.org/wiki/2023_in_American_television
2026-01-05 11:35:26 +00:00
Callum Law
1708ce2e2b LibWeb: Propagate background-clip value for color layer separately
This is required for an optimization in a later commit
2026-01-05 11:35:26 +00:00
Sam Atkins
c446281844 LibWeb/CSS: Remove Transformation in favor of TransformationStyleValue
The Transformation class wasn't really accomplishing anything. It still
had to store StyleValues, so it was basically the same as
TransformationStyleValue, with extra steps to convert from one to the
other. So... let's just use TransformationStyleValue instead!

Apart from moving code around, the behavior has changed a bit. We now
actually acknowledge unresolvable parameters and return an error when
we try to produce a matrix from them. Previously we just skipped over
them, which was pretty wrong. This gets us an extra pass in the
typed-om test.

We also get some slightly different results with our transform
serialization, because we're not converting to CSSPixels and back.
2025-12-19 14:51:53 +01:00
Sam Atkins
45fc72214f LibWeb/CSS: Set border-widths to 0 at used time, not computed time
...when the style is `none` or `hidden`. `outline-width` is not affected
by `outline-style: none` at all.

In our codebase, that means doing the border-width conversion when
assigning to ComputedValues.

Corresponds to:
2a3d1e4d10
09f11f2ef9
2025-12-15 21:28:19 +01:00
Lorenz A
0313b2d97e LibWeb: Produce containing absolute boxes with will-change properties 2025-12-11 09:59:52 +00:00