Commit Graph

3519 Commits

Author SHA1 Message Date
Shubham Gupta
77e4bfbcc4 Pass Request's URL for LargestContentfulPaint Entry (#42901)
Pass Request URL to `LargestContnetfulPaint` Entry

Testing: WPT Expectations Updated.
Fixes: #42902

---------

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-03-02 20:35:37 +00:00
Shubham Gupta
062bb35ac5 layout: Add image_url to ImageInfo struct (#42949)
This just adds URL to pass to ImageFragment for LargestContentfulPaint
Entry

Rebased on: #42948

Testing: No expected change in behavior, Successful Compilation is
enough to verify.

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-03-02 16:34:17 +00:00
Shubham Gupta
71974ea830 layout: Wrap Image related data in ImageInfo struct in NodeExt impl (#42948)
Encapsulating Image related data in ImageInfo in NodeExt impl.

Testing: This is just a little refactor. No change in behavior expected.
Successful compilation is enough to verify.

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-03-02 10:34:39 +00:00
Jonathan Schwender
37dfa42731 Unify servo package naming (#42916)
This is a preparation for publishing to crates.io. Changes include:
- Add `servo-` prefixes to avoid name collisions on crates.io
- Use `-` instead of `_` in package names.
- Rename the crates to their original names in Cargo.toml,
  to keep the diff minimal
- Rename `media` to `servo-media-thread` to avoid name collision with
  `servo-media` (originally from the media repository).

This is an outcome of the previous discussion at [#general > Switch
remaining git dependencies to
crates.io](https://servo.zulipchat.com/#narrow/channel/263398-general/topic/Switch.20remaining.20git.20dependencies.20to.20crates.2Eio/with/576336288)

Testing: This should be mostly covered by our CI, but some amount of
breakage is to be expected, since some package names could still be
referenced from scripts which are not tested or run in CI. [mach try
run](https://github.com/jschwe/servo/actions/runs/22502945949)

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2026-03-01 14:15:27 +00:00
Oriol Brufau
d5c55eb87c layout: Fix bottom margin of block-in-inline getting ignored (#42889)
In order to know whether a block box can collapse its bottom margin with
the bottom margin of its last child, we need to check its tentative
block size. Most usually, this will be the block size of the containing
block that is used when laying out the children.

However, anonymous blocks do not establish a containing block. So using
the containing block for children meant that we were using the tentative
block size of its parent. If that parent had a definite size, this would
prevent the anonymous block from collapsing bottom margins with its
children. This situation could happen when placing a block-level inside
of an inline box.

This patch fixes the problem by using an indefinite tentative block size
for anonymous blocks, instead of the containing block for children.

Testing: Adding new test
Fixes: #42469

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2026-02-27 10:23:21 +00:00
Josh Matthews
d2047c20ab layout: Always treat SVG elements as replaced content. (#42594)
The current implementation treats an SVG element that needs a new
serialized tree as non-replaced content, so we attempt to lay out all of
the children. If serialization is successful, subsequent layouts treat
the SVG as replaced content and ignore the children, but the children's
layout data is never cleaned up. This means that layout queries against
those children can return stale data, which can lead to unexpected
results. By always treating SVG elements as replaced content, we remove
this footgun and improve consistency.

Testing: New crashtest added. It doesn't make sense to upstream this
because our SVG implementation is very nonstandard.
Fixes: #42291
Fixes: #40900

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2026-02-26 20:44:29 +00:00
Oriol Brufau
876abf9001 layout: Remove box damage for parent when we can reuse the box (#42847)
This fixes an oversight from #42783: when detecting that a box can be
reused, we weren't clearing the box damage propagated to ancestors, so
ancestors were still recollecting children.

This exposed some problems in
`rebuild_box_tree_from_independent_formatting_context()`:
1. When reusing a block-level box that established an independent
formatting context, we weren't checking that the new style was still
block-level.
2. When reusing a block-level abspos box, we weren't checking if the new
original display was inline-level, preventing it from being handled as a
block-level because of the static position.
3. When reusing a flex item, we weren't checking if the `order` had
changed.

Testing: we have test coverage for the 3 problems above:
1. Covered by
`/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-display.html`,
and also adding a new `/css/css-display/display-flow-root-dynamic.html`.
2. Covered by `/css/CSS2/abspos/hypothetical-box-dynamic.html`
3. Covered by `/css/css-display/order-dynamic.html`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2026-02-26 19:23:04 +00:00
Oriol Brufau
e0bd48f16a layout: Fix abspos position when it would be preceded by phantom line (#42586)
The static position of an abspos is the hypothetical position that it
would have had in the normal flow. If the abspos is inside inline layout
and it had a block-level original display, then the static position is
computed as if the abspos was a block-level that breaks the inline.

Usually this places the static position after the current line. However,
if the abspos is not preceded by any text, padding, border, margin,
preserved newline or atomic inline, then the static position should be
as if the abspos was preceded by a 0px tall phantom line. Previously we
weren't taking that into account.

Note that browsers aren't completely interoperable in corner cases.

Testing: Adding 3 new tests. Blink fails the 2nd one and Gecko fails the
3rd one. WebKit and Servo pass them all.
Fixes: #41990

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2026-02-26 18:20:46 +00:00
Shubham Gupta
ac0994da34 layout: Encapsulate Image related Info into ImageInfo (#42869)
Add Image related Info into `ImageInfo`.

This will help in processing some other attributes like URL which are
needed for `PaintTiming`.

Testing: This is just a little refactor. No change in behavior expected.
Successful compilation is enough to verify.

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-02-26 15:43:03 +00:00
Martin Robinson
df36372dfe layout: Preserve independent formatting contexts fragment caches when undamaged (#42871)
When fragment tree layout is going to run for a node that starts an
independent formatting context, but only because an ancestor was
damaged, preserve the fragment cache. This means that in the optimistic
case we do not need to re-run fragment tree layout for this independent
formatting context. Previously this was only done for the children of
the independent formatting context, but the fragment cache is robust
enough to detect any layout changes necessary for the IFC fragment
itself as well. This helps to avoid so much fragment reconstruction
during incremental layout.

Testing: `basic-fragment-tree-layout.html` is updated reflecting the
decrease
in the number of fragments rebuilt.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2026-02-26 12:03:35 +00:00
Oriol Brufau
80318ad25e layout: Let OutsideMarker store an IndependentFormattingContext (#42864)
`OutsideMarker` was storing the `BlockFormattingContext` and the
`LayoutBoxBase` in separate fields. Now it will store an entire
`IndependentFormattingContext` in a single field.

In particular, this fixes the issue that `OutsideMarker::repair_style()`
wasn't calling `BlockFormattingContext::repair_style()`. Now we can just
rely on `IndependentFormattingContext::repair_style()`, which correctly
repairs the style of both the `BlockFormattingContext` and the
`LayoutBoxBase`.

Also, the `BlockLevelBox::repair_style()` was repairing the style of the
`LayoutBoxBase` twice, for all kinds of block-level boxes. This removes
the duplication.

Testing: Adding a new test
Fixes: #42779

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2026-02-26 09:55:15 +00:00
Shubham Gupta
9f426e38ba layout: Encapsulate ImageKey in VideoInfo (#42865)
Makes standardized to `CanvasInfo`

Testing: This is just a little refactor. No change in behavior expected.
Successful compilation is enough to verify.

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-02-26 06:25:55 +00:00
Oriol Brufau
d5c82150e0 layout: Add testing API for counting restyled and rebuilt fragments (#42817)
Now `ServoTestUtils.forceLayout()` will provide the number of fragments
that have been restyled and rebuilt. This will be useful to test that
incremental layout works well.

Testing: Adds a test using this new API

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2026-02-25 21:25:32 +00:00
Oriol Brufau
60c5977291 layout: Correctly repair OutsideMarker::list_item_style (#42825)
`OutsideMarker::repair_style()` was setting `list_item_style` to the
style of the marker, not the style of the list item.

This patch sets it to `node.parent_style(context)` instead, and it fixes
`ServoThreadSafeLayoutNode::parent_style()` to take the pseudo-element
chain into account. This requires modifying a bunch of logic to pass the
`SharedStyleContext` around.

Testing: Adding a new test

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2026-02-25 13:25:45 +00:00
Oriol Brufau
e70d76d513 layout: Reuse float boxes with own damage (#42816)
Previously, when a float box had rebuild damage from its own (not from
ancestors), we weren't reusing it. Now we will reuse them just like we
do for other independent formatting context roots.

Testing: Not needed, just an optimization, there should be no behavior
change

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2026-02-25 11:11:05 +00:00
Oriol Brufau
a2041d6263 layout: Reuse boxes for independent formatting contexts with self damage if compatible (#42783)
Previously, when a formatting context root had rebuild damage from its
own (not from ancestors), we weren't reusing it. Now we check if the
level of the box (i.e. whether it's inline-level, block-level, a table
cell, a table caption, or absolutely positioned) that will be generated
by the new style is compatible with the old box. And if so, we reuse it.

Testing: Not needed, there should be no behavior change

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2026-02-24 17:19:24 +00:00
Shubham Gupta
e94e98754c layout: Move LCPCandidateID logic to PaintTimingHandler (#42799)
This eliminates some code duplication.

Testing: This change is just moving code and should not change
functionality, so should be covered by existing tests.

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-02-24 12:43:57 +00:00
Oriol Brufau
8dfda0979d layout: Let TableSlotCell store an IndependentFormattingContext (#42778)
`TableSlotCell` was storing the `BlockFormattingContext` and the
`LayoutBoxBase` in separate fields. Now it will store an entire
`IndependentFormattingContext` in a single field.

In particular, this fixes the issue that `TableSlotCell::repair_style()`
wasn't calling `BlockFormattingContext::repair_style()`. Now we can just
rely on the correct `IndependentFormattingContext::repair_style()`.

Testing: Adding a new test
Fixes: #42777

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2026-02-23 21:17:07 +00:00
Shubham Gupta
6d0b651218 layout: Account opacity for marking first-contentful-paint (#42768)
As per the spec opacity should be considered for
`first-contentful-paint`

> An [element](https://dom.spec.whatwg.org/#concept-element) el is
paintable when all of the following apply:
> 
> - el and all of its ancestors'
[used](https://www.w3.org/TR/css-cascade-5/#used-value)
[opacity](https://www.w3.org/TR/css-color-3/#opacity) is greater than
zero.

Testing: WPT Tests Passed

---------

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-02-23 16:17:42 +00:00
Martin Robinson
ff014d9889 layout: Extend damage propagation isolation to table cells and captions (#42717)
These two types of boxes should also be able to isolate damage during
propagation and serve as roots for box tree reconstruction, as their
contents are independent of their containing box.

Testing: This should not change testable behavior so is covered by
existing WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
2026-02-23 14:26:00 +00:00
TIN TUN AUNG
64b77376a4 layout: align/justify-self last baseline should be treated as safe end in absolute position box. (#42724)
`align-self: last baseline` should be treated as `safe end` in absolute
position box. Given the `baseline` require a group of box, and in the
context of absolute position box, there always would be only one box, we
can follow the [spec of baseline fallback
spec](https://drafts.csswg.org/css-align-3/#ref-for-fallback-alignment),
make `last baseline` fallback to `end`.

Testing: More WPT test is passing.
Fixes: N/A

---------

Signed-off-by: rayguo17 <rayguo17@gmail.com>
2026-02-23 10:13:28 +00:00
Simon Wülker
98c63925b6 layout: Create a webrender stacking context for fragments with transform-style: preserve-3d (#42755)
Such elements already establish stacking contexts, but we don't tell
webrender about them.

Two new failures appear, which I believe incorrectly passed before. We
fail because we don't support the concept of a [3D rendering
context](https://drafts.csswg.org/css-transforms-2/#3d-rendering-context).

If I understand correctly then we act as if a 3D rendering context was
the same as a stacking context, but elements in the same stacking
context may use different 3D coordinate systems, see
1903a5a804/css/css-transforms/transform3d-sorting-004.html (L9-L14)
for example.

Fixes https://github.com/servo/servo/issues/30474
Testing: New tests start to pass.

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2026-02-22 22:31:24 +00:00
shuppy
c07682f222 libservo: Allow the embedder to activate accessibility (#42336)
this patch adds a Servo::set_accessibility_active() method that
embedders can use to tell Servo to start building and sending
accessibility trees to the platform, as long as the pref is enabled
(#42333). doing so sets a global flag in the constellation, which is
then propagated to the layout of all existing and future pipelines.

Testing: none yet, no functional change
Fixes: part of #4344

---------

Signed-off-by: delan azabani <dazabani@igalia.com>
Signed-off-by: Alice Boxhall <alice@igalia.com>
Co-authored-by: Alice Boxhall <alice@igalia.com>
2026-02-20 05:56:15 +00:00
Martin Robinson
042d95220a layout: Replace dirty root approach with flexible box tree layout (#42700)
Replace the old dirty root box tree layout approach with one that works
based on independent formatting contexts. Instead of just allowing a
single dirty root to be the source of box tree reconstruction, allow box
tree reconstruction to happen anywhere in the tree that can isolate box
tree damage from ancestors. This essentially combines damage propagation
and box tree construction into a single step.

There is currently one downside to this approach compared to the dirty
root approach which is that we currently cannot detect and start box
tree layout when the dirty has a compatible `display` and `position`
value. This can mean the scope of box tree layout extends further up the
tree. We will address this in a followup -- but have not noticed any
major performance implications (currently fragment tree layout is much
more expensive than box tree layout).

Benefits:
 1. Damage propagation now only happens under the dirty root.
 2. Future changes can limit the scope of damage up the tree and perhaps
    preserve the inline content size cache between box tree rebuilds.

Testing: This should not change behavior in a testable way (we currently
do
not have robust performance tests), so WPT test results should not
change.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
2026-02-19 14:31:13 +00:00
Martin Robinson
a753fbb26a layout: Preserve fragment tree layout caches in clean subtrees (#42687)
Instead of clearing the fragment tree layout cache in a clean subtree of
a node that needs a new fragment, preserve caches when crossing
(roughly) independent formatting context boundaries [^1]. This should
allow layout to preserve more fragments when, for instance, a node
changes size, but its children do not.

[^1]: Currently things like table cells and captions do not do this.
Support for these will be added gradually.

Testing: This should not change behavior in a testable way, but should
result in less work done during layout.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
2026-02-18 09:02:27 +00:00
Shubham Gupta
3d18f331db layout: Consider border-image contentful for first-contentful-paint (#42581)
We have test for border-image with svg. Adding this with png

Testing: `wpt/tests/paint-timing/fcp-only/fcp-border-image.html`
Fixes: #42618

---------

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-02-16 12:38:55 +00:00
Martin Robinson
59f2325ff1 layout: Clear all node damage during damage traversal (#42600)
Instead of waiting until the box tree construction phase of layout to
clear node damage, clear it during the damage traversal. This means that
damage is cleared in the same way in all types of situations, which
simplifies the code and will make it easier to implement future
optimizations.

Testing: This should not really change behavior (other than being
marginally more
efficient when there is a dirty root), so existing tests should suffice.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
2026-02-16 11:11:02 +00:00
Shubham Gupta
ebcb92d6c1 layout: Simply check of non-zero bounding rect for contentful_paint (#42617)
Use helper function to evaluate non-zero bounding rect size 

Testing: Existing WPT Tests Passed. No change in behaviour.

Signed-off-by: Shubham Gupta <shubham13297@gmail.com>
2026-02-14 10:05:13 +00:00
Shubham Gupta
01bb13ee99 layout: Consider image backgrounds as contentful for the first-contentful-paint paint metric (#42569)
As per W3C [spec](https://www.w3.org/TR/paint-timing/#sec-terminology)

> An [element](https://dom.spec.whatwg.org/#concept-element) target is
contentful when one or more of the following apply:
> - target has a
[background-image](https://www.w3.org/TR/css-backgrounds-3/#propdef-background-image)
which is a [contentful
image](https://www.w3.org/TR/paint-timing/#contentful-image), and its
[used](https://www.w3.org/TR/css-cascade-5/#used-value)
[background-size](https://www.w3.org/TR/css-backgrounds-3/#background-size)
has non-zero width and height values.

Testing: Updated WPT Expectations
Fixes: #42568

---------

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-02-13 17:41:14 +00:00
Martin Robinson
150f767b19 layout: Store a fallback cache in the FontGroup (#42466)
Store a list of recently used fallbacks in the `FontGroups`, keyed by
`lang` property and the detected `UnicodeBlock` and `Script` of the
character in question. This should mean that less work is done when
switching between falling back and not falling back. In addition, this
will allow better caching of `FontRef`s that come directly from the
platform font backend -- something necessary for the next generation
font fallback code.

Testing: This should not change rendering output so is covered by
existing
tests. It might have a minor affect on performance.
Fixes: This is part of #41426.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-02-13 17:01:41 +00:00
Martin Robinson
0c182904f5 layout: Clear dirty box tree nodes during damage traversal (#42596)
Instead of keeping dirty box tree nodes around after the damage
traversal, clear them readily (like `display: none` nodes). This
simplifies the logic during box tree reconstruction and also prepares
the damage traversal for future work.

In addition, restructure the logic of the damage traversal to make it a
bit easier to follow.

Testing: This shouldn't change observable behavior so should be covered
by existing
tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
2026-02-13 13:43:13 +00:00
Shubham Gupta
53bef8e484 layout: Only mark contentful for non-zero bounding rect (#42178)
Check for non-zero width and height values for marking contentful.

Testing: Existing WPT Tests Passed
Fixes: #42592

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-02-13 08:39:33 +00:00
Shubham Gupta
0c2962e2c2 layout: Introduce PaintTimingHandler (#42541)
This PR aims to open doors for common handler for all `PaintTiming`
protocols.
Will add more logic related to `PaintTiming` here targeting completeness
of it.

Changes included in this PR.
1. Ports existing `LargestContentfulPaintCandidateCollector` to
`PaintTimingHandler`.
2. Aligns more close to **W3C** specs, added few steps as well.
3. Adding helper functions.

Testing: No change in behavior expected.
- `components/servo/tests/largest_contentful_paint.rs`

Signed-off-by: Shubham Gupta <shubham13297@gmail.com>
2026-02-13 07:09:33 +00:00
Martin Robinson
dca5250222 layout: Clear display: none boxes during damage traversal (#42584)
There is no need to wait until box tree layout to do this and we want to
make clearing boxes a thing that happens in the damage traversal.

Testing: This should not change behavior in an observable way, so should
be covered by existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
2026-02-12 18:54:58 +00:00
Oriol Brufau
28065dfc4f layout: Fix intrinsic size of replaced with ratio and natural height only (#42577)
If a replaced element has a natural width and a natural height, then the
natural width wins, and the intrinsic height is computed thru the
preferred aspect ratio.

If it has no natural width and no natural height, then the width falls
back to 300px, and again compute the intrinsic height thru the ratio.

However, if it has a natural height but no natural width, then we should
compute the intrinsic width from the natural height thru the ratio. We
were still letting the 300px fallback width win.

Testing: Some tests pass
Fixes: #42573

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2026-02-12 18:03:45 +00:00
Martin Robinson
260eb8688c layout: Preserve boxes in rebuilt subtrees underneath independent formatting contexts (#42582)
When a box needs to be rebuilt due to a style change, it previously
would rebuild the entire box subtree, including all descendants. This is
probably unnecessary when crossing independent formatting context
boundaries. This change limits box tree damage pushed downward when
entering certain types of independent formatting contexts. The types can
be expanded later, but this is just a first conservative step. This is
necessary in order to start preserving fragments in these subtrees.

Testing: This should not change observable layout behavior. We do not
really
have tests to verify these kind of optimizations.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
2026-02-12 16:08:10 +00:00
Martin Robinson
25b4121ad7 layout: Ensure layout damage clears inline content size cache of parent (#42574)
This change fixes an issue where layout damage to a node was not
clearing the inline content size cache of the parent node. In addition
it starts to clean up the damage traversal logic in preparation for
changes to the way that damage is processed and box tree layout is done.

Testing: This change adds a new WPT test.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Luke Warlow <lwarlow@igalia.com>
2026-02-12 12:21:50 +00:00
Martin Robinson
6d2960ab36 layout: Properly set parent of dirty root after box tree layout (#42535)
When laying out the box tree from a dirty root, we were replacing the
inner layout
box contents of the dirty root, but not updating its parent. This change
fixes
that. This is important because any sort of operation that will need the
parent
will subsequently fail unless it is properly set. We do not use the
parent now, but
we will in the future.

Testing: The parent is currently unused, but it will be used in the
future. This
shouldn't change the functioning of Servo currently.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-02-12 10:00:11 +00:00
Oriol Brufau
ec984b3c76 layout: SVG with zero size should get natural ratio from viewBox (#42545)
This logic was (accidentally?) changed in #40761. Revert it back to the
original one, which is simpler, and matches Blink and WebKit.

Testing: Adding new test

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2026-02-12 04:10:48 +00:00
Shubham Gupta
f1ff08ca0e layout: Get rid of LargestContentfulPaintType struct (#42539)
LargestContentfulPaintType is not useful.

Testing: No behaviour change expected

Signed-off-by: Shubham Gupta <shubham13297@gmail.com>
2026-02-11 13:49:59 +00:00
Shubham Gupta
dbc8a7f9da layout: Do not consider iframe fragments at contentful for paint timing (#42498)
This aligns `first-contentful-paint` about `iframe` according to
[specs](https://www.w3.org/TR/paint-timing/#mark-paint-timing), Step:
10.2.1.
 
> NOTE: A parent frame should not be aware of the paint events from its
child iframes, and vice versa. This means that a frame that contains
just iframes will have [first
paint](https://www.w3.org/TR/paint-timing/#first-paint) (due to the
enclosing boxes of the iframes) but no [first contentful
paint](https://www.w3.org/TR/paint-timing/#first-contentful-paint).

Testing: Update WPT tests expectations.

---------

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2026-02-11 09:43:02 +00:00
Shubham Gupta
8d474e7fa0 layout: Mark Contentful for Images only if they have ImageKey (#42411)
This PR checks if `ImageKey` is available, then it marks it as
`Contentful`. For Videos, if valid `poster` or `first frame`, it will be
stored in `ImageKey`.
Hence, appropriate way to mark `Contentful`.

Testing: 

- `/paint-timing/fcp-only/fcp-video-poster.html`
-  `/paint-timing/fcp-only/fcp-video-frame.html`

Fixes #42359
Fixes #42360

Signed-off-by: Shubham Gupta <shubham13297@gmail.com>
2026-02-10 12:50:32 +00:00
Mukilan Thiyagarajan
b682f03394 layout: Move UserAgentStylesheets struct from stylo to layout. (#42499)
This struct is only ever used by Servo so there is not reason to have it
defined in stylo. A follow-up PR in stylo will remove the struct.


Testing: This change simply moves an existing struct from stylo, so
shouldn't have any behavioral changes.

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2026-02-10 08:02:34 +00:00
Oriol Brufau
2a3f23c78d Upgrade Stylo to 2026-02-02 (#42361)
This continues #41916

Changelog:
- Upstream:
360787fff5...7cd2a178d3
- Servo fixups:
e4d50e905e...d9831d464b

Stylo tracking issue: https://github.com/servo/stylo/issues/305

In particular, this adds support for `alignment-baseline` and
`baseline-shift`, and turns `vertical-align` into a shorthand of them.
This also introduces `vertical-align: center`.

Testing: Various tests improve. Some internal tests are updated because
they were wrong. And some fail because we don't support presentation
attributes on SVG elements.

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2026-02-09 11:16:42 +00:00
Martin Robinson
36aa8e9c73 layout: Expand text clipping boundaries based on the largest advance in run (#42403)
Servo does not yet calculate the ink overflow area, as this sort of
thing is usually a result of `contain: paint` which Servo does not
support yet. We just need to ensure that text clipping is large
enough to contain the ink of all of the glyphs in the run. This change
just expands the rectangle based on glyph advances by 2 times the
largest advance, which should be big enough for most glyphs.

This is a big of a workaround until we have support for `contain:
paint`.

Testing:
- This change adds a Servo-specific test to ensure glyphs are fully
inked. While this test would run just fine in other browsers, it isn't
very
useful to them as this is test is very specific to the way that Servo
draws
glyphs.
- This also fixes a variety of existing WPT tests.

Fixes: #41413.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-02-07 22:12:15 +00:00
Martin Robinson
edbce7e854 layout: Properly count characters when segmenting IFC text (#42399)
There was a bug where characters were not properly counted when
segmeting IFC text. Immediately incrementing the
`current_character_index` meant that the count was always one character
off. This character count is mainly used for drawing selections and
really matters when multiple text segments are in a single IFC. This
change fixes that by counting characters in the same way we were
counting byte indices for the text.

Testing: This change adds a Servo-specific WPT-style test. As it is
quite
difficult to reproduce the correct display in a different way, a
mismatch test
is used. Since this is mainly about appearance and is very specific to
our
implementation the test is Servo-specific.
Fixes: #42354.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-02-06 13:37:19 +00:00
webbeef
86403fa4e5 layout: get rid of some collect() calls (#42327)
Profiling a speedometer run showed significant time spent in some layout
function in vector allocations. The main change is to switch the result
of `query_box_areas()` from a Vec<T> to and iterator.

Testing: refactoring with no expected test changes

Signed-off-by: webbeef <me@webbeef.org>
2026-02-06 09:38:49 +00:00
Luke Warlow
5f884cfe29 layout: Do not consider pseudo-elements widgets for the purposes of replaced content (#42332)
When an element has an image content value or list-style-image value
they end up duplicating the content of the element inside the generated
'::marker'.

This is caused by code inside IndependentFormattingContext for user
agent widgets (all user agent shadow dom), this code is specifically
aimed at video and audio elements.

This patch adapts that code to be more specific to elements without a
pseudo-element chain (e.g. audio and video)

Testing: newly added test crashes on main servo (slightly flakily), but
passes consistently now.
Fixes: #42329 
Fixes: #41231

---------

Signed-off-by: Luke Warlow <lwarlow@igalia.com>
2026-02-05 16:01:35 +00:00
Mukilan Thiyagarajan
79ed814ec1 libservo: Expand the UserContentManager API. (#42288)
The patch adds the following functionality to the per-WebView
`UserContentManager` API.
- Removing a `UserScript` at that was previously added.
- Adding a new `UserStyleSheet` representing a user-origin style sheet.
allow removing user script
- Removing a previously added `UserStyleSheet`.

There might be scope for some improvements in the API:
- `UserScript` and `UserStyleSheet` have different ways of representing
the source location - a `PathBuf` and `Url` respectively. This is due to
how those values are used by the underlying evaluation APIs in script
and stylo. More investigation is needed here and could be addressed in
future patches.

Testing: New unit tests are added for the user stylesheet APIs. Existing
tests have been updated to test the removal of user scripts.
2026-02-05 13:26:54 +00:00
Luke Warlow
7bf00ecb51 script: Match :modal when dialog is modal (#42201)
In addition, clean-up the UA stylesheet for dialogs.

Stylo PR: servo/stylo#301
Testing: change causes several WPT tests to start passing.

Signed-off-by: Luke Warlow <lwarlow@igalia.com>
2026-02-04 15:00:50 +00:00