Commit graph

977 commits

Author SHA1 Message Date
Oriol Brufau
e10e989abb
Don't transfer indefinite height: stretch to inline axis (#34557)
Consider this testcase:
```html
<canvas style="aspect-ratio: 1; height: stretch; background: cyan"
        width="200" height="100"></canvas>
```

To compute the intrinsic inline sizes we were treating `height: stretch`
as the natural height (100px) and then transferring that to the inline
axis through the preferred aspect ratio. So the element was 100px wide.

However, an indefinite `stretch` should be treated as an automatic size,
which wouldn't be transferred to the inline axis.

The fix actually makes the code slightly simpler.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-12-10 11:12:28 +00:00
Martin Robinson
f5fdbd70d0
layout: Have SameFormattingContextBlock be a LayoutBoxBase (#34530)
This allows `SameFormattingContextBlock` to cache inline content sizes
and will eventually allow it to participate in incremental layout.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-12-09 06:57:15 +00:00
Martin Robinson
1b1a4eca55
layout: Add LayoutBox to TableSlotCell (#34513)
This allows cells to cache their inline content size and will eventually
allow them to participate in incremental layout.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-12-08 08:54:40 +00:00
Martin Robinson
264c0f972f
layout: Add LayoutBoxBase and use it for IndependentFormattingContext (#34507)
Add a new struct `LayoutBoxBase`, that will be used throughout the box
tree. The idea of this struct is that we have a place to consistently
store common layout information (style and node information) and also to
cache layout results such as content sizes (inline and maybe later box
sizes) and eventually layout results.

In addition to the addition of this struct,
`IndependentFormattingContext` is flattened slightly so that it directly
holds the contents of both replaced and non-replaced elements.

This is only added to independent formatting contexts, but will later be
added to all block containers as well.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-12-07 19:12:25 +00:00
Oriol Brufau
61ca2dde29
Upgrade Stylo to 2024-12-04 (#34501)
* Upgrade Stylo to 2024-12-04

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

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

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

* Update test expectations

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

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-12-06 01:05:54 +00:00
Oriol Brufau
5201c84fb4
Fix stretch sizes on replaced abspos (#34430)
We were sizing absolutely positioned replaced elements within their
actual containing block instead of the inset-modified containing block.
Then the `stretch` keyword would result in a wrong size.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-12-05 20:45:20 +00:00
tanishka
bba3bc6ac2
layout: Add missing support for some alignment keywords on absolutely positioned elements (#34365)
* Add missing support for some alignment keywords on absolutely positioned elements

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

* Check the direction of the alignment container, nits, test expectations

In this case we need to check the direction of the static position
containing block, not the actual containing block:
```html
<!DOCTYPE html>
<div style="position: relative">
  <div style="display: flex; flex-direction: column; width: 100px; height: 100px; border: solid; direction: rtl">
    <div style="position: absolute; width: 20px; height: 20px; background: cyan; top: 20px; align-self: self-start"></div>
    <div style="position: absolute; width: 20px; height: 20px; background: magenta; bottom: 20px; align-self: self-end"></div>
  </div>
</div>
```

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

---------

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-12-05 11:33:09 +00:00
Oriol Brufau
0be5209003
Improve performance of flex column layouts by caching (#34461)
* Obey min and max properties when computing main size of column flex

When laying out a column flex container with an auto preferred main size,
we were resolving the used main size to the intrinsic max-content size.
However, we weren't clamping this amount between the min and max sizes.

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Improve performance of flex column layouts by caching

We were already using a cache for layout_for_block_content_size(), but
we were only storing the intrinsic block size. Thus when laying out the
flex items for real, we would perform new layouts, triggering an
exponential complexity in case of nested flexboxes.

Now we cache the entire layout result so that we can avoid doing the
work again.

This improves the results of flexbox-deeply-nested-column-flow.html
(a Blink perf test) from ~40 runs/second to ~500 runs/second on my PC.

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Oriol Brufau <obrufau@igalia.com>

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-12-03 12:35:24 +00:00
Oriol Brufau
ad448da7de
Obey min and max properties when computing main size of column flex (#34450)
When laying out a column flex container with an auto preferred main size,
we were resolving the used main size to the intrinsic max-content size.
However, we weren't clamping this amount between the min and max sizes.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-12-02 22:14:54 +00:00
Oriol Brufau
888a93af47
Refactor AbsoluteAxisSolver (#34443)
`AbsoluteAxisSolver::solve()` would compute, among other things, the
position of the absolute positioned element if it had start alignment.
Then, `AbsoluteAxisSolver::origin_for_alignment_or_justification()`
could optionally opt into modifying that alignment if needed.

This was quite convoluted and not easy to follow. It's simpler to not
compute the position in `AbsoluteAxisSolver::solve()`, and instead do it
always in `AbsoluteAxisSolver::origin_for_alignment_or_justification()`,
which I'm renaming to `AbsoluteAxisSolver::origin_for_margin_box()`
because it aligns the margin box of the abspos within its alignment
container.

Then the `Anchor` struct becomes useless and can be removed.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-12-02 12:49:00 +00:00
Oriol Brufau
f2b5f515d7
Fix alignment of abspos child of flexbox with flipped direction (#34426)
The containing block for the static position of an absolutely positioned
element in flex layout is established by the flex container. However, if
the flex container has static position, the actual containing block will
be established by another ancestor.

If the flex container and the containing block have different directions,
the static position needs especial handling when aligning the abspos.
We were already trying to do so with the `flip_anchor` flag, but there
were bugs.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-30 14:25:10 +00:00
Oriol Brufau
19a7e95a6a
Refactor computation of preferred aspect ratios (#34416)
* Refactor computation of preferred aspect ratios

Computing min/max-content sizes required a ContainingBlock in order to
resolve the padding and border when determining the preferred aspect
ratio. However, all callers already knew the padding and border, so they
can compute the ratio themselves, and pass it directly instead of
the ContainingBlock.

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

* Put preferred aspect ratio into ConstraintSpace

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

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-29 11:40:52 +00:00
tanishka
16da1c2721
Ensure taffy uses margin when calling used_size_as_if_inline_element_from_content_box_sizes() (#34421)
Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
2024-11-28 19:20:39 +00:00
Oriol Brufau
a37ccc3e64
Use natural ratio for object-fit (#34413)
We were using the preferred aspect ratio provided by the `aspect-ratio`
property instead of the natural aspect ratio. However, the preferred
aspect ratio should only be used to size the replaced element. To paint
the replaced contents into that element we need the natural ratio.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-28 12:57:38 +00:00
Delan Azabani
d65a2e9797
Additional tracing for flex layout, inline layout, and fonts (#34392)
Signed-off-by: Delan Azabani <dazabani@igalia.com>
2024-11-27 02:44:06 +00:00
Oriol Brufau
d034385f76
Use an AtomicRefCell instead of a RwLock for caching intrinsic sizes (#34384)
It panics if the value is mutably borrowed concurrently, but this allows
it to perform better.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-26 13:35:41 +00:00
Nico Burns
63793ccbb7
Use webrender_api::units::DevicePixel rather than style_traits::DevicePixel unless interfacing with Stylo (#34353)
* Use webrender_api::units::DevicePixel rather than style_traits::DevicePixel unless interfacing with Stylo

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Fix OpenHarmony build

Signed-off-by: Nico Burns <nico@nicoburns.com>

---------

Signed-off-by: Nico Burns <nico@nicoburns.com>
2024-11-25 23:42:04 +00:00
Nico Burns
97154d9cf8
Avoid laying out grid items and generating fragments if only inline size is requested (#34352)
* Layout: Short-circuit grid item layout if only inline size is requested

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Layout: Avoid creating grid item fragments if only size is requested

Signed-off-by: Nico Burns <nico@nicoburns.com>

---------

Signed-off-by: Nico Burns <nico@nicoburns.com>
2024-11-25 21:32:52 +00:00
Oriol Brufau
ba061ec2b0
Refine logic for laying out flex item in column layout after #34346 (#34372)
- Clamp the stretch size to not be negative when the sum of padding,
  borders and margins exceed the available space. This avoids a 2nd
  layout.
- Avoid computing the inline content sizes if the result isn't needed.
- Instead of clamping both the min-content and max-content sizes to be
  between the min and max constraints, just compute the fit-content size
  first, and then clamp. Then `ContentSizes::map()` can be removed.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-25 16:17:54 +00:00
Jonathan Schwender
810a91ecac
Remove some unused dependencies (#34355)
* Remove unused deps

This doesn't seem to remove any deps from the workspace.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* ohos: Remove gaol dependency

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2024-11-25 10:29:58 +00:00
Martin Robinson
c11e0e8e70
layout: Add a hit test item that covers all scroll frame contents (#34347)
When building scroll frames, add a special
`StackingContextContent::Fragment` type for a hit test that covers all
scroll frame contents. This makes it so that you don't have to be
hovering over actual content to scroll the scroll frame.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-11-24 19:04:57 +00:00
Nico Burns
9542466b31
Remove unnecessary clone in layout (#34350)
Signed-off-by: Nico Burns <nico@nicoburns.com>
2024-11-23 01:22:40 +00:00
Oriol Brufau
f943ba023a
Improve performance of column flexboxes (#34346)
If a flex item in a single-line column flex container stretches, then
we can know its final size. So instead of first laying it out using its
intrinsic inline size, and then stretching it later, we can use the
correct size from the very beginning.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-11-22 22:52:47 +00:00
Nico Burns
6cbd89dbb0
Layout: Implement CSS Grid using taffy (#32619)
* Add layout.grid.enabled pref

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Add taffy dependency

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Import taffy <-> stylo conversion code from taffy_stylo crate

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Add `Grid` variant to DisplayInside

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Implement CSS Grid using Taffy

Signed-off-by: Nico Burns <nico@nicoburns.com>

Import full stylo_taffy crate

Signed-off-by: Nico Burns <nico@nicoburns.com>

Squashed PR feedback changes

Deduplicate is_document_only_whitespace

Signed-off-by: Nico Burns <nico@nicoburns.com>

Import taffy::AvailableSpace

Signed-off-by: Nico Burns <nico@nicoburns.com>

Rename FlexContext to TaffyContainerContext

Signed-off-by: Nico Burns <nico@nicoburns.com>

Eliminate references to flexbox in taffy/layout module

Signed-off-by: Nico Burns <nico@nicoburns.com>

Use constructors for geom types

Signed-off-by: Nico Burns <nico@nicoburns.com>

Remove comment about abspos elements splitting contiguous text runs

Signed-off-by: Nico Burns <nico@nicoburns.com>

Remove reference to flexbox in taffy/construct

Signed-off-by: Nico Burns <nico@nicoburns.com>

Deduplicate construction of flexbox/grid containers

Signed-off-by: Nico Burns <nico@nicoburns.com>

Make anonymous text runs InFlow

Signed-off-by: Nico Burns <nico@nicoburns.com>

Remove commented code

Signed-off-by: Nico Burns <nico@nicoburns.com>

Update comments

Signed-off-by: Nico Burns <nico@nicoburns.com>

Inline/vendor the stylo/taffy interop code

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Update test expectations

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Fix nits from PR review

Signed-off-by: Nico Burns <nico@nicoburns.com>

---------

Signed-off-by: Nico Burns <nico@nicoburns.com>
2024-11-21 20:21:01 +00:00
Oriol Brufau
97f53021b1
Upgrade Stylo to 2024-11-01 (#34322)
* Upgrade Stylo to 2024-11-01

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

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

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

* Update test expectations

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

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-21 15:14:45 +00:00
Oriol Brufau
138ec6d0ec
Remove the containing_block parameter from TableLayout::layout_caption (#34297)
It was only used for the style, but the containing block of the caption
is the table wrapper box, whose style is stored in `self.table.style`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-20 16:24:00 +00:00
Delan Azabani
caf2467649
Set all tracing spans to trace level for now (#34256)
* Clean up tracing instrumentation

Signed-off-by: Delan Azabani <dazabani@igalia.com>

* Set all tracing spans to trace level for now

Signed-off-by: Delan Azabani <dazabani@igalia.com>

---------

Signed-off-by: Delan Azabani <dazabani@igalia.com>
2024-11-19 02:53:43 +00:00
Oriol Brufau
8c689aac67
Fix min/max-content block size of replaced element (#34284)
The min-content and max-content sizes on the block axis depend on the
inline size. But when computing the SizeConstraint corresponding to the
inline axis, we were resolving the preferred inline size ignoring
intrinsic keywords. Now we will only ignore `auto`.

Also, this patch refactors the logic to compute the min-content and
max-content block sizes after fully resolving the inline size.
This avoids having to resolve the inline sizing properties twice.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-18 22:04:57 +00:00
tanishka
11dfbd6f90
layout: Use Size::FitContent when the alignment isn't normal or stretch for absolutely positioned elements (#34264)
* layout: Use Size::FitContent when the alignment isn't normal or stretch

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

* Use unwrap_or_default()

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

* Use self.alignment.value()

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

* Refactor used_size to handle non-definite sizes

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

* Include AlignFlags::Auto

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-11-18 15:06:23 +00:00
Nico Burns
6955950948
Fix offsetLeft/offsetTop to match major browsers (#32761)
* Fix offsetLeft/offsetTop to match major browsers

See: https://github.com/w3c/csswg-drafts/issues/10549
Signed-off-by: Nico Burns <nico@nicoburns.com>

Fix crash when <html> element is absolutely positioned

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Update test expectations

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Update test expectations again

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Use PhysicalRect and PhysicalVec types

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Use is_some_and

Signed-off-by: Nico Burns <nico@nicoburns.com>

* clippy

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Apply comment changes from code review

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: Nico Burns <nico@nicoburns.com>

---------

Signed-off-by: Nico Burns <nico@nicoburns.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-11-16 15:28:38 +00:00
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