aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/flow/float.rs
Commit message (Collapse)AuthorAgeFilesLines
* Use a RwLock to cache inline_content_sizes() (#34232)Oriol Brufau2024-11-131-1/+1
| | | | | | | | | | | 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>
* Unify logic for laying out floats and atomic inlines (#33802)Oriol Brufau2024-10-111-143/+11
| | | Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Implement keyword sizes on floats (#33666)Oriol Brufau2024-10-081-40/+64
| | | | | | Adds support for min-content, max-content, fit-content and stretch, for floated elements. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Make ComputedValuesExt expose keywords for the sizing properties (#33558)Oriol Brufau2024-09-271-3/+3
| | | | | | | | | | | | | | | | 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>
* layout: Add support for `object-fit` and `object-position` (#33479)Martin Robinson2024-09-181-0/+1
| | | | | | | | | | 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>
* uses app units in display_list (#33420)atbrakhi2024-09-131-1/+1
| | | | Signed-off-by: atbrakhi <atbrakhi@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* layout: Right-to-left support for other layout modes (#33375)Martin Robinson2024-09-111-35/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix various issues with replaced elements in flex layout (#33263)Oriol Brufau2024-08-301-1/+0
| | | | | | | | 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>
* layout: Add an indefinite containing block for intrinsic sizing (#33204)Oriol Brufau2024-08-291-24/+33
| | | | | | | | | | | | | | | | | | 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>
* Obey `min-block-size` and `max-block-size` in floats (#33241)Oriol Brufau2024-08-291-1/+1
| | | | | We were using the unclamped `box_size.block` instead of `block_size`. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* layout: Prepare for bidi by guarding all access to `writing-mode` (#33082)Martin Robinson2024-08-161-2/+3
| | | | | | | | | 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>
* layout: Convert the FragmentTree to physical geometry (#33030)Martin Robinson2024-08-141-22/+25
| | | | | | | | | | | | | | | | 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>
* layout: Make `geom.rs` logical geoemetry types more ergonomic (#32633)Martin Robinson2024-06-281-5/+5
| | | | | | Make using the logical geometry types more ergonomic by having them all implement `Copy` (at most 4 64-bit numbers), similar to what `euclid` does. In addition add an implementation of `Neg` for `LogicalVec` and `LogicalSides` as it will be used in upcoming table implementation code.
* use app unit in box_fragement (#32349)atbrakhi2024-06-211-3/+3
|
* tables: Add a naive implementation of `border-collapse` (#32309)Martin Robinson2024-05-181-17/+8
| | | | | | | | | This change adds a very simple implementation of `border-collapse` for tables. No harmonization or merging is done at all for borders. Instead, the largest border for every continuous border sets the size. Instead of merging different border styles, they are squashed to half size -- which isn't great, but ensures appropriate positioning. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Implement special table sizing for floats (#32150)Oriol Brufau2024-04-261-4/+18
| | | | | | | Tables should always be at least as big as their min-content size, even if we would expect a smaller size according to CSS sizing properties. #31455 implemented it for in-flow tables participting in flow layout, but a few cases remained. This patch addresses floated tables.
* Address issues uncovered by rust-1.78 beta (#32130)Martin Robinson2024-04-221-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change makes changes to allow Servo to compile with the 1.78 version of Rust: - Dead code is removd (Rust seems to have gotten better at detecting it). - The `FlowRef` `DerefMut` is updated according to @SimonSapin's advice [^1]. - The `imports.rs` now explicitly silences warnings about unused imports. [^1]: https://github.com/servo/servo/issues/6503#issuecomment-2066088179 <!-- 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 they 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. -->
* Obey min-height and max-height on floated elements (#32057)Oriol Brufau2024-04-121-4/+8
| | | Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* layout: Use `Au` in `ResolvedMargins` and `CollapsedMargin` (#31848)Ekta Siwach2024-03-281-13/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * change ResolvedMargins to use Au instead of length * made suggested changes removed whitespace changes made suggested changes * Update components/layout_2020/flexbox/layout.rs Co-authored-by: Oriol Brufau <obrufau@igalia.com> * Update components/layout_2020/flow/mod.rs Co-authored-by: Oriol Brufau <obrufau@igalia.com> * fixed errors fixed errors fixed formatting fixed errors * modified changes made suggested changes * Update components/layout_2020/fragment_tree/fragment.rs Co-authored-by: Oriol Brufau <obrufau@igalia.com> updated components/layout_2020/fragment_tree/fragment.rs * Update components/layout_2020/flow/mod.rs Co-authored-by: Oriol Brufau <obrufau@igalia.com> * Update components/layout_2020/flow/mod.rs Co-authored-by: Oriol Brufau <obrufau@igalia.com> * updated changes updated changes * unified all the suggested changes here * fixed formatting * reverted unnecessary changes * fixed unnecessary warnings --------- Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* layout: use `Au` in `BoxFragment` (#31794)atbrakhi2024-03-221-7/+6
| | | | | * use au in BoxFragement * review fix
* clippy: Fix several warnings (#31710)RustAndMetal2024-03-181-1/+1
| | | Signed-off-by: RustAndMetal <111676747+RustAndMetal@users.noreply.github.com>
* layout: make `margin` in `pbm` use app unit (#31621)atbrakhi2024-03-131-6/+6
| | | | | | | | | | | * make margin in pbm use app unit * Simplification * Consistently resolve inline margins as Au, like block margins --------- Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* clippy: Fix warnings in `components/layout_2020` (#31611)eri2024-03-111-1/+1
| | | | | * clippy: fix warnings in components/layout_2020 * fix: review comments
* Fix size of tables in flow layout (#31455)Oriol Brufau2024-03-021-0/+13
| | | | | | | | | | | | | | | | | | | | | | * Fix size of tables in flow layout The contents of a table can make it bigger than what we would expect from its 'width', 'min-width', 'height' and ' min-height' properties. Also, 'width: auto' doesn't stretch it to fill the containing block. We had to refactor the resolution of margins to happen after layout, otherwise 'auto' margins wouldn't align correctly. Co-authored-by: Martin Robinson <mrobinson@igalia.com> * Feedback * Consistently use `containing_block_for_table` in table layout * Update test result --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* make ContainingBlock use Au for inline_size and block_size (#31370)atbrakhi2024-02-201-4/+4
|
* layout: make `padding` and `border` use `Au` in `pbm` (#31289)atbrakhi2024-02-121-4/+4
| | | | | * use au for padding and border in pbm * review fix
* layout: Collect both start and end baselines for fragments (#31230)Martin Robinson2024-02-051-1/+0
| | | | | | | | This change starts collecting the starting baseline set for fragments, which is necessary for some layout modes (flex and tables, namely) as well as being important for the implementation of `align-items`. In addition, it converts baseline measurement to use `Au` everywhere. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* use app unit in replaced elements (#31178)atbrakhi2024-01-291-7/+10
| | | | | | | | | | | | | | | | | * use app unit in replaced elements * more app unit usage * Avoid unnecessary into() * Run ./mach fmt * use scaleby * update --------- Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Lint layout_2020 with clippy (#31169)Oriol Brufau2024-01-251-24/+29
| | | cargo clippy --fix -p layout_2020 --allow-dirty --broken-code
* Layout: use `Au` in `ContentSizes` (#31135)atbrakhi2024-01-231-1/+2
| | | | | | | | | | | | | * use app_units * resolve errors in table layout * fmt * add back current_line.min_content * update expectation * review fix
* rustdoc: Fix many rustdoc errors (#31147)Martin Robinson2024-01-221-6/+8
| | | | This fixes many rustdoc errors that occur due to raw URLs in rustdoc comments as well as unescaped Rust code that should be in backticks.
* Use App units in flow layout (#30894)atbrakhi2024-01-191-119/+128
| | | | | | | | | | | | | | | * 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>
* layout: Switch `IndependentLayout` to use `Au` instead of `Length` (#31083)atbrakhi2024-01-151-1/+1
| | | | | | | * use au in layout * fmt * review fix
* layout: Implement support for `line-height` and `vertical-align` (#30902)Martin Robinson2024-01-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Allow raising FloatContext ceiling after processing box with overflow (#30539)Martin Robinson2023-10-171-11/+28
| | | | | | | | | | | | | | | 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.
* Layout 2020: Rename `flow_relative` types to `Logical...` (#30324)Martin Robinson2023-09-121-26/+30
| | | | | | 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`.
* Strict import formatting (grouping and granularity) (#30325)Samson2023-09-111-11/+13
| | | | | * strict imports formatting * Reformat all imports
* remove `extern crate` (#30311)Samson2023-09-081-0/+1
| | | | | | | | | | | * 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>
* Fix PlacementAmongFloats to avoid missing some bands (#30280)Oriol Brufau2023-09-011-2/+18
| | | | | | | | | | PlacementAmongFloats would stop iterating when current_bands would be empty, even if next_band wasn't at infinity. Then the BFC root or replaced block was placed after all the floats, even if it could fit next to some of them. This patch moves the next_band into current_bands so that the loop keeps considering bands.
* Avoid crash in PlacementAmongFloats (#30235)Oriol Brufau2023-08-291-1/+1
| | | | | | | | | | | PlacementAmongFloats was assuming that there would always be a FloatBand at a position smaller than or equal to the given ceiling, but this was not the case for negative ceilings. The reason is that the FloatContext initialized the FloatBandTree with a band at 0, and another at +∞. This patch changes the initial bands to −∞ and +∞. This seems more consistent and matches the expectation of PlacementAmongFloats.
* Handle inline margins when avoiding floats (#30072)Oriol Brufau2023-08-091-13/+26
|
* Handle BFC roots with auto width next to floats (#30057)Oriol Brufau2023-08-081-3/+65
| | | Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Refactor PlacementAmongFloats (#30068)Oriol Brufau2023-08-041-30/+65
| | | | | | | | | | | | | | - Add explanatory comments. - Rename some methods. - Store the ceiling instead of relying on the first band, this allows calling place() when current_bands is empty. - Make current_bands_height() work when current_bands is empty. - Add add_one_band() helper method. - Make place() return a Rect. Follow-up patches will need to know the size of the area shrunk by floats. This will be useful for #30057 and #30050. Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Minor refactoring for PlacementAmongFloats (#30055)Oriol Brufau2023-08-011-20/+17
| | | | | | | | | | | | No difference in behavior, just these changes: - PlacementAmongFloats::new() initializes the top of the 1st band to the ceiling, so that other methods can just refer to the former without having to floor by the later. - In fact, the 'ceiling' field becomes unnecessary, and is removed. - top_of_placement_for_current_bands() is renamed to current_ceiling(). - try_place_once() is reorganized to reduce indentation. - The condition 'len() > 0' becomes '!is_empty()'. - The 1st band is now popped in place() instead of try_place_once(), then it's easier to see why the loop will end.
* Fix interaction of margins and clearance for PlacementAmongFloats (#30038)Oriol Brufau2023-07-311-26/+71
| | | | | | | | | 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.
* Remove ClearSide enum (#30035)Oriol Brufau2023-07-271-37/+14
| | | Just use Clear instead, they have the same values.
* Run unit tests with both layout 2013 and layout 2020 (#30032)Oriol Brufau2023-07-271-2/+2
| | | | | | | | Since #29950, unit tests were only running with the legacy layout, and there was no way to run them for layout 2020. This patch makes './mach test-unit' run unit tests for both. Also doing some changes so that the layout 2020 floats.rs tests compile.
* Remove calculate_clearance_and_adjoin_margin (#30033)Oriol Brufau2023-07-261-16/+0
| | | It was useful when it had 3 callers, but #29977 removed 2 of them.
* Place replaced and non-auto inline size independent FCs next to floats (#29977)Martin Robinson2023-07-181-13/+120
| | | | | | | | | | | | | | | | | | | | | * 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>
* Layout 2020: Properly calculate clearanceOriol Brufau2023-06-301-16/+52
| | | | | calculate_clearance() was not taking into account that adding clearance prevents top margin from collapsing with earlier margins.