Commit graph

847 commits

Author SHA1 Message Date
Oriol Brufau
557a0ceb89
Protect against arithmetic underflow in TableBuilder::current_y() (#34247)
It doesn't seem like any web page could trigger the underflow,
but this makes the code more robust.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-14 16:03:39 +00:00
chickenleaf
91f96cc9dd
Support justify-self on absolutely positioned elements (#34235)
* Support justify-self on absolutely positioned elements

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* updating test expectations

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
2024-11-13 14:14:44 +00:00
Oriol Brufau
9102644470
Use a RwLock to cache inline_content_sizes() (#34232)
In order to support size keywords in block layout, we may need to call
`inline_content_sizes()` in order to compute the min/max-content sizes.
But this required a mutable reference in order the update the cache,
and in various places we already had mutable references.

So this switches the cache into a RwLock to avoid needing mutable refs.
Note OnceCell wouldn't work because it's not thread-safe.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-13 09:56:02 +00:00
Oriol Brufau
bf75f17348
Add BoxFragment::is_inline_box() (#34233)
A helper function to check for inline boxes.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-12 15:50:20 +00:00
Oriol Brufau
6a62d52cbb
Use LazyCells instead of callbacks when resolving size keywords (#34211)
In most cases we already had a LazyCell anyways, since we could need the
value for multiple properties. Instead of passing a callback that forces
the evaluation of the LazyCell, it's simpler to just pass the LazyCell
directly.

Also, this way we no longer need mutable references.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-11 16:26:20 +00:00
Oriol Brufau
b28260aa13
Fix inline content sizes of intrinsic element with indefinite block size (#34152)
To compute the min-content and max-content inline sizes of a replaced
element, we were only using the aspect ratio to transfer definite block
sizes resulting from clamping the preferred block size between the min
and max block sizes.

However, if the preferred block size is indefinite, then we weren't
transfering the min and max through the aspect ratio.

This patch adds a `SizeConstraint` enum that can represent these cases,
and a `ConstraintSpace` struct analogous to `IndefiniteContainingBlock`
but with no inline size, and a `SizeConstraint` block size.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-11 11:38:19 +00:00
Martin Robinson
f4cc20f7ef
layout: Fix caching of streching flex items in row flex (#34162)
When a flex item stretches in the cross axis in a row flex, the flex
container layout should depend on block constraints. In this case the
cross axis is the block axis (assuming horizontal writing modes --
vertical are not yet supported). This changes fixes an issue where the
cached layout was used in this case when stretching should trigger a new
layout.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-11-08 16:59:23 +00:00
atbrakhi
85a9ca7cb6
layout: Add instrumentation for display_list (#34128)
* Add instrumentation for display_list

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* review update

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* review fix

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
2024-11-08 09:05:07 +00:00
Martin Robinson
a61522a1e8
layout: Clean up the flexible length resolution algorithm (#34153)
Instead of doing so much zipping, which is confusing, create a temporary
data structure for each item that holds all relevant information. In
addition, add detailed specification text so it is easier to understand
what is going on.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-11-06 09:54:20 +00:00
Oriol Brufau
ee7b207f96
Implement keyword sizes for replaced elements (#34091)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-05 13:46:58 +00:00
Martin Robinson
3289e7d84d
layout: Properly calculate free space in flexbox flexible length resolution (#34150)
Previously, when there were no more violations, the returned value for
line free space was incorrect for flexible length resolution. It was
returning the container main space minus the inner length of each item.
Free space is determined by the outer length though. Fix this by reusing
the `free_space()` function, but with an argument indicating that all
items are now frozen.

Fixes #34079.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-11-05 13:32:34 +00:00
Martin Robinson
fe0701e226
layout: Add parallel layout to flexbox (#34132)
This adds parallelism using rayon to the initial layout of flex lines
and line item. There is still no support for parallelism when laying out
line items again to account for stretch. This can be done in a followup
change.

In addition, the array of data for each line item is collected into a
new structure, `FlexLineItem`. This prevents a lot of needless zipping
of iterators at the expense of some new vector allocations. A folluwup
change can likely unify this structure and `FlexItemLayoutResult` though
that will require a larger refactor.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-11-05 11:48:27 +00:00
Martin Robinson
f151cdf6ee
layout: Remove an obselete comment from flexbox (#34148)
This behavior is handled properly in `style_ext.rs`.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-11-05 09:50:22 +00:00
Oriol Brufau
072ff302d2
Replace ComputedValues with WritingMode on IndefiniteContainingBlock (#34090)
We only need the writing mode, not the entire computed style.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-04 18:00:58 +00:00
Oriol Brufau
2a6d480cd8
Remove unnecessary clamping in used_size_as_if_inline_element() (#34114)
We don't need to floor the preferred box sizes to be at least zero,
since `used_size_as_if_inline_element_from_content_box_sizes()` will
take care of applying min and max constraints, and the min has been
floored to be at least zero.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-03 14:46:21 +00:00
Oriol Brufau
d2c4448ac8
Unify sizing logic for replaced elements (#34076)
The logic varied quite a bit depending on the case, now it's unified.

This also fixes the following case where the iframe was 150px tall
instead of 50px:
```html
<iframe style="min-width: 400px; max-height: 50px"></iframe>
```

This also modifies video-intrinsic-width-height.html to expect the new
behavior that we share with Blink and WebKit. In fact WebKit already
modified this test but forgot to export the change upstream. Firefox is
different but it was already failing anyways.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-01 12:34:28 +00:00
Oriol Brufau
0d7fa75447
Use default object size as fallback for intrinsic size of replaced element (#34084)
Instead of falling back to zero.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-31 17:05:17 +00:00
Oriol Brufau
851b125d4b
Properly handle fallback aspect ratio for videos (#34082)
A `<video>` element with no source won't have a natural aspect ratio,
but `aspect-ratio: auto` should still fall back to a ratio of 300/150.

`used_size_as_if_inline_element_from_content_box_sizes()` was already
handling this, but other consumers of `preferred_aspect_ratio()` were
wrong. In particular, this resulted in a 0px wide inline-block:

```html
<div style="display: inline-block; border: solid">
  <video style="height: 100px; background: cyan"></video>
</div>
```

So this patch moves the fallback into `preferred_aspect_ratio()`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-31 14:45:03 +00:00
Oriol Brufau
31566aef02
Fix geometry queries for floats and replaced inlines (#34083)
APIs like `clientWidth` were returning zero.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-31 14:44:15 +00:00
Oriol Brufau
1891c5cfaf
Properly transfer min/max constraints on auto-sized replaced elements (#34026)
We were following CSS2, which didn't handle `aspect-ratio`.
This patch simplifies the logic and handles it correctly.

Unfortunately this makes 2 tests fail, but I'm pretty sure they aren't
spec-compliant. I'm leaving them as-is for now since they are part of
interop-2021, and Gecko, Blink and WebKit pass them (because of some
non-interoperable incorrect behaviors).

I'm adding a new test that is fully passed by Servo and WebKit.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-30 14:01:47 +00:00
eri
01820e2a8a
Improve how intrinsic sizes work for videos (#31746)
* feat: patch for video layout sizes

added rebase from main 2024/10/05

Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: eri <epazos@igalia.com>

* feat: take width and height parameters if provided

Signed-off-by: eri <epazos@igalia.com>

* chore: tidy the code and update test expectations

Signed-off-by: eri <epazos@igalia.com>

* feat: handle removing poster

Signed-off-by: eri <epazos@igalia.com>

* chore: update test expectations and remove debug code

Signed-off-by: eri <epazos@igalia.com>

* fix: issues after rebasing to main

Signed-off-by: eri <epazos@igalia.com>

* feat: pass src remove test and tidy

Signed-off-by: eri <epazos@igalia.com>

* chore: clippy fixes

Signed-off-by: eri <epazos@igalia.com>

* chore: update passing test expectations

Signed-off-by: eri <epazos@igalia.com>

* fix object-position-svg test

Signed-off-by: eri <epazos@igalia.com>

* fix unintentional override of video size and resize events

Signed-off-by: eri <epazos@igalia.com>

* change how resize events are sent to better match the spec

Signed-off-by: eri <epazos@igalia.com>

* simplify poster mutation handling

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: eri <eri@inventati.org>

* improved handling of intrinsic sizes

- differentiate between natural size and css size
- presentational attributes
- fallback ratio for video element
- handle more cases where the src/poster are added/removed
- aspect ratio hints

Signed-off-by: eri <epazos@igalia.com>

* update test expectations

Signed-off-by: eri <epazos@igalia.com>

* fix cleaning current frame

Signed-off-by: eri <epazos@igalia.com>

* update test expectations

Signed-off-by: eri <epazos@igalia.com>

* Apply suggestions from code review

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: eri <eri@inventati.org>

* More code review suggestions

Signed-off-by: eri <epazos@igalia.com>

* Prevent aspect-ratio:auto from pulling the ratio from the default object size

As resolved in https://github.com/w3c/csswg-drafts/issues/7524#issuecomment-1204462924

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

---------

Signed-off-by: eri <epazos@igalia.com>
Signed-off-by: eri <eri@inventati.org>
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-10-29 22:42:22 +00:00
Martin Robinson
d5554235fe
layout: Add support for mix-blend-mode: plus-lighter (#34057)
This just requires translating the style value into a WebRender value.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-10-29 17:50:33 +00:00
Oriol Brufau
faeb31d6c6
Implement keyword sizes for intrinsic contributions (#33854)
Correctly handle keyword sizes when computing the min-content or
max-content contribution of a box.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-26 09:15:19 +00:00
Oriol Brufau
dfe1c95aa6
Avoid crash in replaced layout, and fix behavior for non-auto aspect-ratio (#34006)
Also, it was assuming that the aspect ratio would work with the content
box dimensions, but that isn't the case for `aspect-ratio: <ratio>` with
`box-sizing: border-box`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-25 17:13:07 +00:00
Martin Robinson
52db185568
layout: Avoid layout sometimes when stretching (#33967)
This is the second flexbox caching change. It seeks to detect when a
relayout can be avoided in the case of a stretching flex item. This
heuristic can be combined, because currently we still do relayout
sometimes when we do not need to.

For instance currently we always relayout when a flex child is itself a
column flex. This only needs to happen when the grandchildren themselves
grow or shrink. That optimization is perhaps a lower priority as
`flex-grow: 0 / flex-shrink: 1` is the default behavior for flex.

Since this change means we more consistenly zero out the percentage part
of `calc` expressions when they have circular dependencies, this causes one
test to start failing (`/css/css-values/calc-min-height-block-1.html`).
This is related to w3c/csswg-drafts#10969, which is pending on further
discussion in the working group.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-10-24 17:44:30 +00:00
Oriol Brufau
9ad59d1459
Consistent resolution of cyclic percentages in min sizing properties (#33988)
The spec says that cyclic percentages in min sizing properties should
be resolved against zero when computing intrinsic contributions.
We were already doing that in the inline axis, but we were treating
the entire expression as `auto` in the block axis.

With this patch we will follow the spec in both axes. But note that
browsers don't follo the spec in either axis, so we may have to revisit
(see https://github.com/w3c/csswg-drafts/issues/10969).

calc-min-height-block-1.html now fails because it tests what browsers
do instead of what the spec says.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-24 12:03:32 +00:00
Oriol Brufau
1c26c0335e
Implement keyword sizes on absolute/fixed positioned elements (#33950)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-22 18:50:12 +00:00
Martin Robinson
01c9ecfe01
layout: Cache content block size contributions (#33964)
This is the first part of caching intermediary layout during flexbox
layout. A later change will try to reuse these layouts, when possible,
for actual item layout and re-layout due to stretching.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-10-22 14:43:53 +00:00
Oriol Brufau
8824c90716
Prevent stretch from producing a negative size (#33951)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-22 08:04:15 +00:00
chickenleaf
aeed5ca3b4
Replaced mem::replace with mem::take for old_min_size (#33959)
Signed-off-by: L Ashwin B <lashwinib@gmail.com>
2024-10-21 19:30:57 +00:00
tanishka
571cba4a81
CI: Fail the lint job when cargo-clippy reports some warnings (#33941)
* Fail the lint job when cargo-clippy reports some warnings

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Remove todo comment

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* clippy: use Option::take instead of mem::replace

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>

---------

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-10-21 15:18:32 +00:00
Oriol Brufau
2319764a1e
Refactor positioned layout (#33922)
This unifies the size resolution into AbsoluteAxisSolver, since it needs
to know the size in order to resolve auto margins correctly anyways.
This will allow adding support for sizing keywords in a follow-up patch.

Also, this avoids doing multiple layouts due to min and max constraints,
improving performance.

Additionally, tables may end up having a custom size, different than
what we would expect by just looking at the sizing properties. This
patch ensures that we resolve margins correctly with the final size,
resulting in 2 tests now passing.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-21 10:41:42 +00:00
Noble Chinonso
397c5adf79
clippy: fix explicit lifetime warning in components\layout_2020\style_ext.rs:320:20 (#33936)
Signed-off-by: Noble <nobleuwuja@gmail.com>
2024-10-21 07:03:55 +00:00
Noble Chinonso
c550a70f5c
clippy: fix using clone() warning in components\layout_2020\display_list\mod.rs:1365:25 (#33935)
Signed-off-by: Noble <nobleuwuja@gmail.com>
2024-10-21 05:54:22 +00:00
Oriol Brufau
c75f6627ba
Upgrade Stylo to 2024-10-04 (#33767)
* Upgrade Stylo to 2024-10-04

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D220285

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://bugzilla.mozilla.org/show_bug.cgi?id=1918093

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222817

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222856

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222532

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222533

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222534

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D223878

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-20 19:53:38 +00:00
Oriol Brufau
73880ee1d0
Remove BoxFragment::overconstrained (#33907)
This was only used for serializing inset properties in getComputedStyle,
but it was unnecessary and the logic was wrong anyways: an `auto` size
doesn't imply that we won't be overconstrained, because it won't become
negative even if the insets are big enough.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-19 01:55:55 +00:00
Oriol Brufau
09fc988d3a
Fix resolved value of insets to use margin box instead of content box (#33906)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-18 23:55:53 +00:00
chickenleaf
1ae90dcd95
clippy: Fix a variety of clippy warnings in fonts, layout_2020 and the DOM code (#33894)
* fixed some clippy warnings

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* Delete extra file

Signed-off-by: chickenleaf <lashwinib@gmail.com>

* preserved newline in compositionevent.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: chickenleaf <lashwinib@gmail.com>

* removed the newline in PrototypeList

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* removed the trailing whitespace

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
Signed-off-by: chickenleaf <lashwinib@gmail.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-10-18 13:57:13 +00:00
Oriol Brufau
5148b444be
Minor cleanup for Size after #33844 (#33861)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-16 13:53:46 +00:00
Delan Azabani
fa1f7e5839
Gate all use of tracing behind Cargo feature (#33845)
Signed-off-by: Delan Azabani <dazabani@igalia.com>
2024-10-16 10:24:24 +00:00
Oriol Brufau
103d3aa7bb
Avoid wrapping line at the start of text run with text-wrap-mode: nowrap (#33848)
When computing the min-content size of an inline formatting context,
we could allow a soft wrap opportunity at the start of a text run.
This shouldn't happen with `text-wrap-mode: nowrap`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-16 10:22:11 +00:00
Oriol Brufau
564478ef0d
Remove SizeKeyword, merge it into Size (#33844)
It's not really useful to have it.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-15 10:30:22 +00:00
Oriol Brufau
b9ed45942d
Avoid recomputing inline_content_sizes() when not needed (#33806)
The result of `inline_content_sizes()` may depend on the block size of
the containing block, so we were always recomputing in case we got
a different block size.

However, if no content has a vertical percentage or stretches vertically,
then we don't need to recompute: the result will be the same anyways.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-10-14 16:06:27 +00:00
Oriol Brufau
a86dcfc6e7
Unify logic for laying out floats and atomic inlines (#33802)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-11 18:26:00 +00:00
tanishka
091b8ecda0
layout: Handle inline margins in layout_for_block_content_size() (#33780)
* fix: Handle inline margins in layout_for_block_content_size()

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Update test expectations

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

---------

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
2024-10-10 20:45:18 +00:00
birdbrained
a591778a25
Improve Au(0) constructions (#33709)
This replaces `Au(0)` with `Au::zero()` and other utility functions when possible.

Signed-off-by: hackerbirds <120066692+hackerbirds@users.noreply.github.com>
2024-10-10 16:45:18 +00:00
Oriol Brufau
8c56cbdab2
Implement keyword sizes on atomic inlines (#33737)
Adds support for min-content, max-content, fit-content and stretch,
for atomic inlines.

There are some new test failures because we don't support vertical
writing modes nor `transition-behavior:allow-discrete`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-10 15:25:59 +00:00
Adavize Promise
52cddb45bd
Use content_box_sizes_and_padding_border_margin_deprecated() in FlexItem::new() (#33754)
* Use content_box_sizes_and_padding_border_margin_deprecated() in FlexItem::new()

Signed-off-by: PS Adavize <siyakapromise@gmail.com>

* remove unnecessary variable declaration declaration

Signed-off-by: PS Adavize <siyakapromise@gmail.com>

* Remove redundant variable pbm

Signed-off-by: PS Adavize <siyakapromise@gmail.com>

---------

Signed-off-by: PS Adavize <siyakapromise@gmail.com>
2024-10-10 11:13:48 +00:00
Oriol Brufau
2805d3ce14
Fix writing mode in content_box_sizes_and_padding_border_margin() (#33773)
This method should use the writing mode from the containing block,
not the one of the current style.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-10 09:55:35 +00:00
Oriol Brufau
c1b744b2b2
Implement keyword sizes on floats (#33666)
Adds support for min-content, max-content, fit-content and stretch,
for floated elements.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-08 13:07:59 +00:00