Commit graph

125 commits

Author SHA1 Message Date
atbrakhi
3d520f2668
Use App units in flow layout (#30894)
* use app_unit in flow layout

* fmt

* Avoid crash

* Drop assert that doesn't hold anymore

* update expectation

---------

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-01-19 13:20:01 +00:00
atbrakhi
1b847c3166
layout: Switch IndependentLayout to use Au instead of Length (#31083)
* use au in layout

* fmt

* review fix
2024-01-15 14:31:21 +00:00
Martin Robinson
3555671864
layout: Split LineItem layout into a new file (#31039)
This is just a bit of code movement that trims down the size of the
`inline.rs` file in order to make it a bit more manageable. It leads the
way to more refactoring and cleanup in the future.
2024-01-10 05:42:11 +00:00
Martin Robinson
aa073c3dca
layout: Implement support for line-height and vertical-align (#30902)
* layout: Implement support for `line-height` and `vertical-align`

This is an initial implementation of proper `line-height` and
`vertical-align` support. While this change includes the bulk of the
work there are still many missing pieces for full support. In particular
some big missing things are:

 - Flex containers do not properly compute their baselines. The idea is
   to tackle this in a followup change. This causes various flex tests
   to start failing because everything used to be top aligned.
 - The implementation of the line-height quirks (only active in quirks
   mode) are incomplete. While the quirk works in many cases, there are
   still some cases where it is handled incorrectly. This requires more
   redesign and refinement, better suited for a followup.
 - Most of the features are CSS 3 such as precision control of the
   baseline and first and last baselines are not implemented. This
   change gets us close to CSS 2.x support.

While there are many new test passes with this change some tests are
starting to fail. An accounting of new failures:

Tests failing also in Layout 2013:
 - /css/css2/positioning/toogle-abspos-on-relpos-inline-child.html (only passes in Chrome)
 - /css/CSS2/fonts/font-applies-to-001.xht (potentially an issue with font size)

Invalid tests:
 - /css/CSS2/visudet/inline-block-baseline-003.xht
 - /css/CSS2/visudet/inline-block-baseline-004.xht
 - These are are failing in all browsers. See https://bugs.chromium.org/p/chromium/issues/detail?id=1222151.

Missing table support:
 - /_mozilla/mozilla/table_valign_middle.html

Missing `font-size-adjust` support :
 - /css/css-fonts/font-size-adjust-zero-2.html (also failing in 2013)

Incomplete form field support :
- /html/rendering/widgets/the-select-element/option-add-label-quirks.html (label isn't rendered so button isn't the right size in quirks mode due to line height quirk)

Need support for calculating flexbox baseline:
 - /css/css-flexbox/fieldset-baseline-alignment.html
 - /css/css-flexbox/flex-inline.html
 - /css/css-flexbox/flexbox-baseline-multi-line-horiz-001.html
 - /css/css-flexbox/flexbox-baseline-single-item-001a.html
 - /css/css-flexbox/flexbox-baseline-single-item-001b.html

Failing because we don't create anonymous inline boxes for text children of blocks:
- /css/CSS2/linebox/anonymous-inline-inherit-001.html

Passes locally (potentially related to fonts):
 - /css/CSS2/css1/c414-flt-fit-004.xht
 - /css/css-transforms/transform-input-017.html
 - /html/obsolete/requirements-for-implementations/the-marquee-element-0/marquee-min-intrinsic-size.html
 - /css/css-fonts/first-available-font-005.html
 - /css/css-fonts/first-available-font-006.html

* Some cleanups after live review with @mukilan

Also update results.
2024-01-08 14:49:50 +00:00
Martin Robinson
81f5157522
Add support for table fixups (#30868)
This adds support for fixing up tables so that internal table elements
that are not properly parented in the DOM have the correct box tree
structure according to the CSS Table specification [1]. Note that this
only comes into play when building the DOM via script, as HTML 5 has its
own table fixups that mean that the box tree construction fixups here
are not necessary.

There are no tests for this change. In general, it's hard to write tests
against the shape of the box tree, because it depends on the DOM. We
plan to test this via WPT tests once layout is complete.

1. https://drafts.csswg.org/css-tables/#table-internal-element

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2023-12-22 12:11:58 +00:00
Martin Robinson
2c341d9e69
Allow raising FloatContext ceiling after processing box with overflow (#30539)
When a box has overflow, any floats placed in that box will lower the
float ceiling into the overflow. If no float is placed in the box
though, the ceiling should be the block position where the overflow
starts. We already know where this is, because we might be passing a
negative value for the new block position after processing a box
(content_size - actual_size would be negative). This negative value
never raises the ceiling though since a maximum is used.

In the case that there is overflow, this change allows raising the
ceiling, but never passed the lowest float. This necessitates keeping
two values for the ceiling: one for floats and one for non-floats.

Fixes #30304.
2023-10-17 07:53:57 +00:00
Martin Robinson
8299868bd5
Layout 2020: Rename flow_relative types to Logical... (#30324)
This makes the names of flow relative geometry consistent with what is
used in the style crate and removes them from a module. With this change
it's more obvious what makes these types different from the ones in
`euclid`.
2023-09-12 07:31:30 +00:00
Samson
aad2dccc9c
Strict import formatting (grouping and granularity) (#30325)
* strict imports formatting

* Reformat all imports
2023-09-11 19:16:54 +00:00
Samson
711dbbd4af
remove extern crate (#30311)
* remove extern crate

* Update components/script_plugins/lib.rs

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

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2023-09-08 12:11:31 +00:00
Martin Robinson
59f5414ca8
Split line layout into two phases (#30089)
In the first phase, we gather LineItems and then when we have enough to
form a line we turn them into Fragments. This will make it possible to
more simply implement `vertical-align` and `text-align: justify` because
we need to measure the different aspects of the candidate line and then
produce a Fragments.

This is a general refactor of the way that inline layout works, so comes
with some progressions. In addition there are some new failures.

New failures:

Some tests are now failing because only the test or reference is getting
proper line height when it wasn't before. These should be fixed in a
followup change that properly calculate line-height in more cases:

 - /_mozilla/css/list_style_position_a.html
 - /css/CSS2/floats/float-no-content-beside-001.html
 - /css/css-content/pseudo-element-inline-box.html
 - /css/css-flexbox/flexbox_flex-none-wrappable-content.html

Some tests are now failing because floats are now placed properly, but
are no longer in their inline box stacking contexts. These will be fixed
by a followup change which properly parents them:

- /css/filter-effects/filtered-inline-applies-to-float.html.ini
- /css/css-color/inline-opacity-float-child.html.ini

One test is failing due to floating point precision errors:

- /css/CSS2/floats-clear/floats-141.xht.ini

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2023-08-11 07:19:50 +00:00
Oriol Brufau
8dceb8e412
Handle inline margins when avoiding floats (#30072) 2023-08-09 21:19:16 +00:00
Oriol Brufau
ab0f48f8e8
Handle BFC roots with auto width next to floats (#30057)
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2023-08-08 11:46:36 +00:00
Oriol Brufau
1346c34083
Avoid bad calls to solve_containing_block_padding_border_and_margin_for_in_flow_box (#30073)
Avoid solve_containing_block_padding_border_and_margin_for_in_flow_box()
for a block-level box that establishes an independent formatting context
(or is replaced) in the presence of floats, since the margins and inline
size could then be incorrect.

No actual change in behavior: this patch still resolves the margins
incorrectly with solve_block_margins_for_in_flow_block_level(),
and also keeps the old logic for width:auto.

However, this refactoring prepares the terrain to address these issues
in #30072 and #30057.
2023-08-07 17:47:49 +00:00
Oriol Brufau
d90e3078a6
Never resolve margin-left:auto to a negative amount (#30065)
With direction:ltr (and we don't support direction:rtl yet), the rules
from https://drafts.csswg.org/css2/#blockwidth imply that margin-left
shouldn't resolve auto to a negative amount.

This aligns Servo with Gecko and Blink. WebKit may resolve to a negative
amount in some cases.
2023-08-03 09:21:22 +00:00
Martin Robinson
1296ddf273
Make fewer PositioningContexts when descending (#30061)
When descending and we have the option, don't create new
PositioningContexts just to update the static position of laid out
abspos descendants. Instead, use the new PositioningContextLength to
only update the newly added hoisted abspos boxes.
2023-08-03 08:51:27 +00:00
Oriol Brufau
d9a38b00ff
Simplify solve_containing_block_padding_border_and_margin_for_in_flow_box() (#30060)
Just use clamp_between_extremums() to resolve the inline size, and then
only call solve_inline_margins_for_in_flow_block_level() once.

There should be no change in behavior.
2023-08-02 14:46:07 +00:00
Oriol Brufau
9e4377af47
Fix interaction of margins and clearance for PlacementAmongFloats (#30038)
Consumers of PlacementAmongFloats weren't handling margins properly.
They were assuming that they would either get a positive adjustment,
or zero for no-op.

However, just like the regular clearance triggered by 'clear', the
clearance added onto blocks that establish an independent FC can be
zero or negative, and the effect is different than having no clearance.
2023-07-31 21:07:24 +00:00
Oriol Brufau
b8c04b4bad
Floor child sizes in calculate_inline_content_size_for_block_level_boxes (#30034)
Calculating the max-content size of a block container may add the outer
max-content sizes of multiple children. The problem is that the outer
size may be negative (due to margins), producing an incorrect result.

In particular, it could happen that the max-content size was 50-25=25,
but the min-content size would just take the maximum and be 50, which
doesn't make sense.

Therefore, this patch floors the size of all children by 0. This seems
to match Blink. Firefox and WebKit don't floor in some cases, but then
the result seems suboptimal to me. Note that there is no spec for this,
see https://github.com/w3c/csswg-drafts/issues/9120 for details.
2023-07-27 14:37:21 +00:00
Oriol Brufau
77c6a61dfa
Remove ClearSide enum (#30035)
Just use Clear instead, they have the same values.
2023-07-27 09:46:15 +00:00
Oriol Brufau
e0e970af31
Remove calculate_clearance_and_adjoin_margin (#30033)
It was useful when it had 3 callers, but #29977 removed 2 of them.
2023-07-26 21:34:04 +00:00
Oriol Brufau
727d61a99d
Fix intrinsic sizing of block container containing a BFC root after floats (#30012)
A block that establishes an independent formatting context is placed
next to previous floats, so we should add their sizes when computing
the intrinsic contribution of the parent block container.
2023-07-19 17:14:39 +00:00
Martin Robinson
4f4c2a5922
Remove rayon_croissant and clean up contains_floats (#29960)
Remove rayon_croissant and refactor the way that information about
floats in flows bubbles up. This simplifies the code a good deal and
lets us take advantage of some more optimized functions provided by
rayon. This removes 2 crates from the dependency tree.

In addition, this allows avoiding passing `contains_floats` up from
every box tree construction function. This makes things simpler, but
also opens up the possibility of passing more of these flags up in the
future (such as `contains_counters`).
2023-07-19 07:01:55 +00:00
Oriol Brufau
9c333ab1ee
Totally ignore abspos children for intrinsic sizing (#30010)
calculate_inline_content_size_for_block_level_boxes was relying on
inline_content_sizes to get the size of each block-level box child.
For absolutely positioned boxes, this was 0x0.

That was no-op before #29887, but then it prevented adding the sizes
of a sequence of floats. Abspos should just be ignored instead of
treated as 0x0.

This patch removes inline_content_sizes, moves the logic into
calculate_inline_content_size_for_block_level_boxes (the only caller),
and handles abspos correctly.
2023-07-19 05:38:33 +00:00
Martin Robinson
ae3f33b9d0
Place replaced and non-auto inline size independent FCs next to floats (#29977)
* Place replaced and non-auto inline size independent FCs next to floats

The CSS2 specification says that replaced content and independent
formatting contexts should be placed next to floats. This change adds
support for that, but punts on support for independent formatting
contexts that have an auto inline size. With an auto inline size, we
which requires a much more complex layout algorithm.

Co-authored-by: Oriol Brufau <obrufau@igalia.com>

* Fix issue with where last band was taken into account for inline size

* adjustment_from_floats should prevent margin collapse

* Properly handle elements with 0 height

---------

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2023-07-18 18:43:45 +00:00
Oriol Brufau
befc0f5a5b
De-indent code in find_block_margin_collapsing_with_parent (#29997) 2023-07-13 16:27:21 +00:00
Martin Robinson
fa40c22122
Split layout_in_flow_non_replaced_block_level
This function is already quite big and the changes necessary for
properly laying out independent formatting contexts next to floats will
make it even more unwieldy. Split the function in two and add a helper
for calculating the containing block for children and the margin. As
time goes on the independent formatting case is probably going to be
more like the replaced case anyway.

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2023-07-03 16:11:44 +02:00
Oriol Brufau
a4c4550e3b Layout 2020: Optimize collapsible margin lookahead
Every time that we would lay out a block box that could collapse its
top margin with its contents, we would do a lookahead to compute the
resulting margin in order to place floats correctly.

The problem was that this lookahead could iterate several descendants,
but then when laying these we would run the lookahead again.

This patch restricts the lookahead to boxes that either aren't collapsing
their top margin with their parent, or that have 'clear' different than
'none' (since clearance prevents collapsing margins with the parent).

Since the lookahead stops iterating when it finds a box that doesn't
collapse its top margin with its parent, or whose 'clear' isn't 'none',
this should ensure that lookahead never handles the same box twice.
2023-07-03 11:53:43 +02:00
bors-servo
a1dfadc4fa
Auto merge of #29951 - Loirooriol:margin-collapse-use-computed, r=mrobinson
Check computed (min-)block-size when determining margin collapse

To collapse margins through, CSS2 requires "zero or auto computed height" and "zero computed min-height" (the latter should also also include auto, which was introduced in CSS3 as the new initial value).

Similarly, "auto computed height" is required to collapse the bottom margin with the bottom margin of the contents.

Therefore this patch stops collapsing when the used height is clamped to zero by max-height, but the computed value is not zero. Same for non-zero percentages that are indefinite or that resolve to 0px.

Note that 0% and calc(0% + 0px) are still considered to be zero (so they allow margin collapse), this may a bit inconsistent but matches Firefox (for the collapsing through case).

This also matches the heuristics in find_block_margin_collapsing_with_parent(). We could change the heuristics instead, but then they would have to track block sizes in order to be able to resolve percentages.

The change makes margin-collapse-through-percentage-height-block.html fail, that test is only passing on Blink, which did a different interpretation of the spec. To be fair, various places of CSS2 loosely consider that indefinite percentages compute to auto, and even Firefox does so when determining whether to collapse the top margin with the contents.

Since the spec isn't particularly clear and interoperability is lacking, I filed https://github.com/w3c/csswg-drafts/issues/8919.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #29907
- [X] There are tests for these changes (1 test fails, see above)

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2023-07-01 19:38:30 +02:00
Oriol Brufau
995d607608 Resolve percentages in find_block_margin_collapsing_with_parent
Padding percentages weren't being resolved, this function would think
that margins wouldn't collapse even if the percentage resolved to 0px.
And margin percentages were always resolved to 0px.

So now the function takes a ContainingBlock parameter that is used to
resolve these percentages properly.
2023-07-01 03:18:11 +02:00
Oriol Brufau
7d8122b264 Check computed (min-)block-size when determining margin collapse
To collapse margins through, CSS2 requires "zero or auto computed height"
and "zero computed min-height" (the latter should also also include auto,
which was introduced in CSS3 as the new initial value).

Similarly, "auto computed height" is required to collapse the bottom margin
with the bottom margin of the contents.

Therefore this patch stops collapsing when the used height is clamped
to zero by max-height, but the computed value is not zero. Same for
non-zero percentages that are indefinite or that resolve to 0px.

Note that 0% and calc(0% + 0px) are still considered to be zero (so they
allow margin collapse), this may a bit inconsistent but matches Firefox
(for the collapsing through case).

This also matches the heuristics in find_block_margin_collapsing_with_parent().
We could change the heuristics instead, but then they would have to track
block sizes in order to be able to resolve percentages.

The change makes margin-collapse-through-percentage-height-block.html fail,
that test is only passing on Blink, which did a different interpretation
of the spec. To be fair, various places of CSS2 loosely consider that
indefinite percentages compute to auto, and even Firefox does so when
determining whether to collapse the top margin with the contents.

Since the spec isn't particularly clear and interoperability is lacking,
I filed https://github.com/w3c/csswg-drafts/issues/8919.
2023-07-01 03:00:53 +02:00
Oriol Brufau
95832c999b Layout 2020: Properly calculate clearance
calculate_clearance() was not taking into account that adding clearance
prevents top margin from collapsing with earlier margins.
2023-06-30 16:51:39 +02:00
bors-servo
7412e28349
Auto merge of #29945 - Loirooriol:fix-float-placement-with-future-margins-2, r=mrobinson
Properly position floats when subsequent boxes collapse margins with containing block (2)

PR #29939 tried to address this but missed various cases.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #29944
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2023-06-30 02:28:37 +02:00
Oriol Brufau
6b2bbdd02d Layout 2020: implement clearance as Option<Length>
Clearance was implemented as a Length, where zero meant no clearance.
However, having a clearance of 0px should be different than having
no clearance, since the former can still prevent margin collapse.

This patch keeps the existing behavior, so it won't be possible to get
a clearance of Some(Length::zero()), but it prepares the terrain for
a follow-up to fix calculate_clearance to return the proper thing.
2023-06-29 11:00:45 +02:00
Oriol Brufau
a435e02b78 Properly position floats when subsequent boxes collapse margins with containing block (2)
PR #29939 tried to address this but missed various cases.
2023-06-29 05:49:01 +02:00
Martin Robinson
bb13702556 Properly position floats when subsequent boxes collapse margins with containing block
Margins should be able to collapse through floats when collapsing with
parent blocks (the containing block). To properly place floats in this
situation, we need to look at these subsequent floats to find out how
much of the margin will collapse with the parent.

This initial implementation is very basic and the second step would be
to cache this in order to avoid having to constantly recalculate it.

Fixes #29915.

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2023-06-27 22:45:42 +02:00
Oriol Brufau
246dc983f6 Fix clearance on replaced elements 2023-06-26 17:24:24 +02:00
Oriol Brufau
e38083a96e Increase BFC root height to contain floats 2023-06-26 01:00:00 +02:00
Martin Robinson
30ab348116 Properly position absolutes with static insets that are children of floats
Previously, final float positions were calculated when their parents
were positioned. This prevented proper positioning of absolute children
of floats with static insets, because they accumulate offsets as they
are hoisted up the tree.

This change moves the final float positioning to
`PlacementState::place_fragment` for the float itself so that it happens
before any insets are updated for hoisted descendants. In addition to
simplifying the code, this makes it a bit more efficient. Finally,
floats are taken into account when updating static insets of hoisted
boxes.

Fixes #29826.
2023-06-22 01:55:21 +02:00
Oriol Brufau
0dd6abe023 Fix interaction of clearance with margin collapse
In #29897 I did the simple naive thing, but it wasn't entirely correct.
This patch tries to address the problems. In particular:

 - Clearance should prevent margins from collapsing through if it
   happens between them, as opposed to on the element that owns them.
 - The margins of an element with clearance can still collapse through,
   and collapse with other siblings as normal, but the resulting
   margin can't collapse with the bottom margin of the parent.
2023-06-21 18:00:05 +02:00
bors-servo
fa7107ac12
Auto merge of #29894 - mrobinson:ditch-static-position-closure, r=Loirooriol
Simplify layout of absolutes with static insets

Absolutes with static insets need to be laid out at their ancestor containing blocks, but their position is dependent on their parent's layout. The static layout position is passed up the tree during hoisting and ancestors each add their own offset to the position until it is relative to the containing block that contains the absolute.

This is currently done with a closure and a fairly tricky "tree rank" numbering system that needs to be threaded through the entire layout. This change replaces that system.

Every time a child is laid out we create a positioning context to hold any absolute children (this can be optimized away at a later time). At each of these moments, we call a method to aggregate offsets to the static insets of hoisted absolutes. This makes the logic easier to follow and will also allow implementing this behavior for inline-blocks, which was impossible with the old system.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because it should not change behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2023-06-21 08:16:49 +02:00
bors-servo
07bbbad5f9
Auto merge of #29897 - Loirooriol:clearance-prevents-margin-collapse, r=mrobinson
Prevent margins from collapsing through when separated by clearance

This fixes #29884 and improves #29896.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #29884 and improve #29896
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2023-06-20 23:22:41 +02:00
Oriol Brufau
00a5a4e6c4 Prevent margins from collapsing through when separated by clearance
This fixes #29884 and improves #29896.
2023-06-20 21:27:54 +02:00
bors-servo
47714f767e
Auto merge of #29870 - mrobinson:float-root, r=Loirooriol
Layout 2020: Correct rendering of floated root

Fix two issues around floating a root element:

1. In the StackingContext code handle the case where a root element is a Float fragment and not a Box fragment. This fixes a debug assertion failure in the css/CSS2/float/float-root.html test.
2. When initializing the SequentialLayoutState, use the containing block width as the maximum inline float placement position instead of infinity. This fixes the rendering of css/CSS2/float/float-root.html.

Note that css/CSS2/float/float-root.html was passing before, because both the test and reference were subject to the same bug. This fixes a couple other tests as well.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2023-06-20 18:36:03 +02:00
Martin Robinson
4cb4332602
Correct rendering of floated root
Fix two issues around floating a root element:

1. In the StackingContext code handle the case where a root element is a
   Float fragment and not a Box fragment. This fixes a debug assertion
   failure in the css/CSS2/float/float-root.html test.
2. When initializing the SequentialLayoutState, use the containing block
   width as the maximum inline float placement position instead of
   infinity. This fixes the rendering of css/CSS2/float/float-root.html.

Note that css/CSS2/float/float-root.html was passing before, because
both the test and reference were subject to the same bug. This fixes a
couple other tests as well.
2023-06-20 17:46:45 +02:00
Martin Robinson
459a7d26aa
Simplify layout of absolutes with static insets
Absolutes with static insets need to be laid out at their ancestor
containing blocks, but their position is dependent on their parent's
layout. The static layout position is passed up the tree during hoisting
and ancestors each add their own offset to the position until it is
relative to the containing block that contains the absolute.

This is currently done with a closure and a fairly tricky "tree rank"
numbering system that needs to be threaded through the entire layout.
This change replaces that system.

Every time a child is laid out we create a positioning context to hold
any absolute children (this can be optimized away at a later time). At
each of these moments, we call a method to aggregate offsets to the
static insets of hoisted absolutes. This makes the logic easier to
follow and will also allow implementing this behavior for inline-blocks,
which was impossible with the old system.
2023-06-20 11:44:25 +02:00
Oriol Brufau
4ec6dd1783 Handle floats in BlockContainer::inline_content_sizes
Typically, block-level contents are stacked vertically, so this was just
taking the maximum size among all contents. However, floats can be
stacked horizontally, so we need to sum their sizes.
2023-06-19 16:02:35 +02:00
bors-servo
47fb54fc54
Auto merge of #29883 - Loirooriol:float-inline-size, r=mrobinson
Implement BlockLevelBox::inline_content_sizes for floats

This improves #29874, but `BlockContainer::inline_content_sizes` will still need more changes in order to correctly handle sequences of floats.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2023-06-16 20:03:36 +02:00
Oriol Brufau
66c4eee082 Implement BlockLevelBox::inline_content_sizes for floats
This improves #29874, but BlockContainer::inline_content_sizes will still
need more changes in order to correctly handle sequences of floats.
2023-06-16 15:46:35 +02:00
Martin Robinson
3b3dc4adbe
Layout 2020: Fix issues with float implementation documentation
Fix some rustdoc comments which won't process properly unless they start
with three '/' characters. In addition, improve the name of a function
and add some missing documentation.
2023-06-14 17:09:56 +02:00
Oriol Brufau
5e1f059de2 Improve margin collapse in layout-2020
According to https://drafts.csswg.org/css2/#collapsing-margins, bottom
margins should only collapse with the last child if `height` is `auto`.
Also, the note mentions `min-height: 0`, but the normative text doesn't
have such requirement, so I'm dropping it, matching WebKit.

The previous logic is moved into the case of collapsing the top and
bottom margins of the same element, since this can happen either with
`height: auto` or `height: 0`, and requires `min-height: 0`.
2023-06-08 11:05:57 +02:00