Commit graph

115 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
433f48741b
Fix align-content set to start or end on flexbox (#33667)
We need to handle `flex-wrap: wrap-reverse`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-07 09:15:56 +00:00
Martin Robinson
719b5aba24
tools: Improve instrumentation and add it for some layout (#33647)
Improves the instrumentation to skip all function arguments and also add
spans for some layout modes. This is preparation for improving the
performance of flexbox.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-10-05 08:55:40 +00:00
tanishka
4850caeec4
clippy: Fix too_many_arguments warnings (#33648)
Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
2024-10-04 16:27:23 +00:00
Oriol Brufau
057dd1e9eb
Make ComputedValuesExt expose keywords for the sizing properties (#33558)
This will allow callers to start obeying `min-content`, `max-content`,
`fit-content` and `stretch` in follow-up patches.
The old functionality is kept as deprecated methods that we should
eventually remove.
This patch has very little impact on the existing behavior, just some
very minimal implementation of the keywords for css tables.

This also overhauls fixed-layout-2.html since:
 - It had code that wasn't doing anything
 - It had wrong expecations in prose
 - The logic seemed broken in general
 - All browsers were failing one testcase

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-09-27 17:16:07 +00:00
Oriol Brufau
43d92ecbcb
Use ContentSizes::shrink_to_fit when possible (#33527)
And ensure that the minimum wins for malformed ContentSizes.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-09-25 08:53:04 +00:00
Oriol Brufau
9597390d2b
Enable min-content, max-content, fit-content and stretch (#33492)
For the sizing properties.

We don't actually support them yet, just treating them as
the initial value.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-09-20 14:48:27 +00:00
Martin Robinson
bd632fc814
layout: Add support for object-fit and object-position (#33479)
This also makes a couple small improvements:
 - Rename `IntrinsicSizes` to `NaturalSizes` which reflects more
   modern spec language.
 - Move the conversion of Stylo's `ImageRendering` to WebRender's
   version to a `ToWebRender` trait implementation.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-09-18 06:20:28 +00:00
Oriol Brufau
219a2f2038
Cleanup after #33396 (#33429)
Mostly formatting improvements, but also recovering a pair of parenthesis
that was accidentally removed, changing the logic.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-09-12 19:23:17 +00:00
Martin Robinson
ed5dc43f16
layout: Reverse space-between alignment properly for absolute children of flex containers (#33406)
When aligning with `space-between` the space should be allocated on the
`flex-end` side of the container ie it should be mapped to `flex-start`
(`start` and reversing if necssary).

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-09-11 17:51:56 +00:00
Martin Robinson
027fc53e2f
layout: Right-to-left support for other layout modes (#33375)
This change removes the `effective_writing_mode` concept and tries to
properly implement right-to-left layout support for all non-inline
writing modes. In general, what needs to happen is that rectangles
need to be converted to physical rectangles using the containing block.
A right-to-left rectangle's inline start is on the right physical side
of the containing block. Likewise a positive inline offset in
right-to-left text is a negative physical one.

The implementation here is pretty good for most layout modes, but floats
are still a bit in process. Currently, floats are processed in the
logical layout of the block container, but there still might be issues
with float interaction with mixed RTL and LTR.

While this does move us closer to supporting vertical writing modes,
this is still unsupported.

New failures:
 - Vertical writing mode not supported:
   - `/css/CSS2/floats/floats-placement-vertical-001b.xht`
   - `/css/CSS2/floats/floats-placement-vertical-001c.xht`
 - Absolutes inlines should avoid floats (#33323)
   - `/css/css-position/position-absolute-dynamic-static-position-floats-004.html`
 - No support for grid
   - `/css/css-align/self-alignment/self-align-safe-unsafe-grid-003.html`
   - `/css/css-position/static-position/inline-level-absolute-in-block-level-context-009.html`
   - `/css/css-position/static-position/inline-level-absolute-in-block-level-context-010.html`
 - Cannot reproduce these locally on any platform. Very mysterious:
   - `/css/css-tables/row-group-margin-border-padding.html`
   - `/css/css-tables/row-margin-border-padding.html`
 - Exposes bugs we have related to hanging whitespace in preserved
   whitespace inlines:
   - `/css/css-text/white-space/trailing-space-and-text-alignment-rtl-003.html`
   - `/css/css-text/white-space/white-space-pre-wrap-trailing-spaces-023.html`

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2024-09-11 13:40:11 +00:00
atbrakhi
095590e224
layout: Use Au in ComputedValuesExt (#33396)
* Use app unit in `ComputedValuesExt`

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

* Some miscellaneous fixes

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

* remove redundant defination of `containing_block_inline_size`

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

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-09-10 21:35:17 +00:00
Martin Robinson
d169a82d2e
layout: Implement proper absolute child position for flexbox (#33346)
This implements the requirements outlined in the [flexbox specification]
about how to position absolute children of flex containers. We must
establish a static position rectangle (to use if all insets are auto)
and also align the child into that rectangle.

[flebox specification]: https://drafts.csswg.org/css-flexbox/#abspos-items

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-09-09 14:44:16 +00:00
Oriol Brufau
4d0bef0ac3
Remove unused imports (#33371)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-09-09 03:02:24 +00:00
Martin Robinson
f3f96c3393
layout: Do not use orthogonal baselines in flex layout (#33347)
When a baseline is orthogonal to the main flexbox axis, it should not
take part in baseline alignment. This change does that for column flex.
While there is no support for vertical writing modes, this change is
made to be as writing mode-agnostic as possible.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-09-07 22:08:48 +00:00
Oriol Brufau
37e1c3385e
Treat align-self: normal as stretch on flex items (#33314)
According to https://drafts.csswg.org/css-align/#align-flex
It was being treated as `auto` instead.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-09-05 11:15:41 +00:00
Oriol Brufau
27d87f104e
Fix intrinsic sizing of column flex containers (#33299)
From https://drafts.csswg.org/css-flexbox-1/#intrinsic-cross-sizes,
> The min-content/max-content cross size of a single-line flex container
> is the largest min-content contribution/max-content contribution
> (respectively) of its flex items.

We were using the min/max-content size instead of the min/max-content
contribution.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-09-04 06:44:31 +00:00
Oriol Brufau
3acc9edd82
Fix various issues with replaced elements in flex layout (#33263)
In particular, this takes into account that flex items may be stretched,
and if they have an aspect ratio, we ma6y need to convert the stretched
size through the ratio.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-08-30 23:39:18 +00:00
Oriol Brufau
cd8b803368
Use the proper aspect ratio in flexbox (#33256)
When computing the automatic minimum size, flex layout was using the
natural aspect ratio, ignoring the `aspect-ratio` property.

`ReplacedContent::inline_size_over_block_size_intrinsic_ratio()` is now
made private to avoid more accidental uses.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-08-30 06:28:14 +00:00
Oriol Brufau
4bf941bc8a
Fix automatic minimum size for column flexbox (#33248)
`main_content_size_info()` was always assigning the main-axis automatic
minimum size into the inline axis. But in a column flexbox, the main
axis corresponds to the block axis.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-08-29 16:55:44 +00:00
Oriol Brufau
0643aa4708
Handle aspect ratios in ReplacedContent::inline_content_sizes (#33240)
We were only handling the aspect ratio of a replaced element when
computing its min/max-content contribution, but not when computing
the min/max-content size. Now both cases will take it into account.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-08-29 15:38:59 +00:00
Oriol Brufau
93abdf7cb5
layout: Add an indefinite containing block for intrinsic sizing (#33204)
When computing the min-content or max-content size of an element we
need to ignore `inline-size`, `min-inline-size` and `max-inline-size`.

However, we should take the block-axis sizing properties into account.
That's because the contents could have percentages depending on them,
which can then affect their inline size via an aspect ratio.

Therefore, this patch adds `IndefiniteContainingBlock`, which is similar
to `ContainingBlock`, but it allows an indefinite inline-size. This
struct is then passed arround during intrinsic sizing.

More refinement will be needed in follow-up patches in order to fully
address the problem.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-08-29 14:10:46 +00:00
Oriol Brufau
46dbe4ce32
Obey min and max cross sizes of flex items (#33242)
When laying out the contents of a flex item, we used to resolve their
cross-axis percentages against the preferred cross size of the item.
Now we will take the min and max cross sizes into account.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-08-29 11:24:23 +00:00
atbrakhi
2037884469
Fix clippy wanings in layout (#33215)
Signed-off-by: atbrakhi <atbrakhi@igalia.com>
2024-08-27 20:53:43 +00:00
Oriol Brufau
50eb69a7e0
Allow creating a ContentSizes from Au (#33208)
No change in behavior, it just simplies some code a little bit.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-08-27 15:22:47 +00:00
Martin Robinson
2db9032e72
layout: Add support for flex items with position: relative (#33151)
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-08-23 18:11:22 +00:00
Oriol Brufau
c00cd1326a
Take into account the intrinsic block size when computing the main size of a column flex container (#33135)
In particular, `main_content_sizes()` now works with columns.

`layout_for_block_content_size()` is now used for both intrinsic sizes
and intrinsic contributions, a IntrinsicSizingMode parameter is added
to choose the behavior.

Also, we consider the main size of a flex item as indefinite if its flex
basis is indefinite and the flex container has an indefinite main size.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-08-20 11:30:27 +00:00
Martin Robinson
2f6745c0c6
layout: Layout for column flex-basis and minimum automatic size determination (#33068)
This change adds an expensive layout for the determination of minimum
automatic size and flex basis in process of flexbox layout. Currently,
the layout is not cached, so may be performed up to 2 more times than
necessary.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-08-19 10:54:10 +00:00
Martin Robinson
0d94a8acd2
layout: Prepare for bidi by guarding all access to writing-mode (#33082)
We want to selectively enable right-to-left writing modes per layout
context. This change makes that possible by allowing access to
`writing-mode` though an interface that always returns the default
horizontal top-to-bottom (implicitly left-to-right) writing mode.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2024-08-16 11:38:04 +00:00
Martin Robinson
8159f03288
layout: Support start and end values for flexbox align-self (#33032)
These are similar to `flex-start` and `flex-end`, but in `wrap-reverse`
situations, they are the opposite.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-08-15 08:20:41 +00:00
Martin Robinson
7633bdccd2
layout: Initial implementation of flex-direction: column and column-reverse (#33031)
This change removes restrictions on using the column layout mode of
flexbox and adds an initial implementation of sizing for that flex
direction. There's a lot of missing pieces still, but in some cases this
does render column flexbox.

In particular, there are now two code paths for preferred widths
(intrinsic size) calcuation: one in the main axis (row) and one in
the cross axis (column) corresponding to the flex direciton with
horizontal writing modes.

In addition, `FlexItemBox::inline_content_sizes` is removed in favor of
making `sizing::outer_inline` /
`IndependentFormattingContext::outer_inline_content_sizes` generic
enough to handle using a different value for auto minimum sizes, which
flexbox needs.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-08-14 14:25:09 +00:00
Martin Robinson
d941d2fd67
layout: Convert the FragmentTree to physical geometry (#33030)
This converts all geometry in the FragmentTree into physical geometry,
doing conversions ahead of time instead of when traversing the fragment
tree. This is necessary to properly implement BiDi in Servo as we need
to know what side borders are on in mixed RTL and LTR contexts.

In addition, fragments are laid out in a particular context and only
that context knows its writing mode. There were issues where were using
one writing mode to lay out and another to convert to phyisical
coordinates. This isn't an issue now since we only use the default
writing mode, but starts to be an issue with BiDi text.

Closes #25564.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-08-14 12:22:06 +00:00
Martin Robinson
8582678e4b
Properly handle subpixel units when dividing space between flex lines (#32913)
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-08-13 15:11:01 +00:00