aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/sizing.rs
Commit message (Collapse)AuthorAgeFilesLines
* Refactor computation of preferred aspect ratios (#34416)Oriol Brufau2024-11-291-1/+3
| | | | | | | | | | | | | | | | | | | * 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>
* Refine logic for laying out flex item in column layout after #34346 (#34372)Oriol Brufau2024-11-251-7/+0
| | | | | | | | | | | - 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>
* Fix inline content sizes of intrinsic element with indefinite block size ↵Oriol Brufau2024-11-111-21/+15
| | | | | | | | | | | | | | | | | (#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>
* Replace ComputedValues with WritingMode on IndefiniteContainingBlock (#34090)Oriol Brufau2024-11-041-1/+4
| | | | | We only need the writing mode, not the entire computed style. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Implement keyword sizes for intrinsic contributions (#33854)Oriol Brufau2024-10-261-38/+88
| | | | | | Correctly handle keyword sizes when computing the min-content or max-content contribution of a box. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* layout: Avoid layout sometimes when stretching (#33967)Martin Robinson2024-10-241-10/+15
| | | | | | | | | | | | | | | | | | | | 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>
* Avoid recomputing inline_content_sizes() when not needed (#33806)Oriol Brufau2024-10-141-6/+26
| | | | | | | | | | | 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>
* Make ComputedValuesExt expose keywords for the sizing properties (#33558)Oriol Brufau2024-09-271-1/+1
| | | | | | | | | | | | | | | | 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>
* Use `ContentSizes::shrink_to_fit` when possible (#33527)Oriol Brufau2024-09-251-1/+7
| | | | | And ensure that the minimum wins for malformed ContentSizes. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Fix various issues with replaced elements in flex layout (#33263)Oriol Brufau2024-08-301-6/+12
| | | | | | | | 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-67/+26
| | | | | | | | | | | | | | | | | | 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>
* Allow creating a `ContentSizes` from `Au` (#33208)Oriol Brufau2024-08-271-8/+11
| | | | | No change in behavior, it just simplies some code a little bit. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Take into account the intrinsic block size when computing the main size of a ↵Oriol Brufau2024-08-201-0/+16
| | | | | | | | | | | | | | | 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>
* layout: Initial implementation of `flex-direction: column` and ↵Martin Robinson2024-08-141-12/+14
| | | | | | | | | | | | | | | | | | | | | | `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>
* layout: Compute intrinsic sizes for flex items and flex containers (#32854)Delan Azabani2024-08-021-1/+1
| | | | | Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* layout: Add initial support for row height distribution (#31421)Martin Robinson2024-02-291-7/+13
| | | | | | | | | | | | This change adds a version of row height distribution that follows the distribtuion algorithm used for tables in Blink's LayoutNG. This is just an intermediate step toward implementing a distribution algorithm for both rows and columns more similar to Layout NG. The CSS Table 3 specification is often wrong with regard to web compatability, which is why we have abandoned it in favor of the Layout NG algorithm for row height distribution. this work. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* layout: Implement computation of table column widths (#31165)Martin Robinson2024-01-251-2/+25
| | | | | | | | | | | | | | | | | * layout: Implement computation of table column widths This change implements the various steps of table column width computation, ignoring features that don't exist yet (such as separated borders, column elements, and colgroups). Co-authored-by: Oriol Brufau <obrufau@igalia.com> * Fix an issue with the assignment of column percent width * Respond to review comments --------- Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Lint layout_2020 with clippy (#31169)Oriol Brufau2024-01-251-3/+3
| | | cargo clippy --fix -p layout_2020 --allow-dirty --broken-code
* Layout: use `Au` in `ContentSizes` (#31135)atbrakhi2024-01-231-15/+18
| | | | | | | | | | | | | * 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-3/+3
| | | | 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.
* Strict import formatting (grouping and granularity) (#30325)Samson2023-09-111-1/+2
| | | | | * 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>
* Resolve cyclic margin and padding percentages against zero (#30085)Oriol Brufau2023-08-101-38/+13
| | | | | | | From https://drafts.csswg.org/css-sizing-3/#min-percentage-contribution > For the min size properties, as well as for margins and paddings > (and gutters), a cyclic percentage is resolved against zero > for determining intrinsic size contributions.
* Handle floats in BlockContainer::inline_content_sizesOriol Brufau2023-06-191-1/+8
| | | | | | 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.
* Parallelize `BlockContainer::inline_content_sizes`Simon Sapin2020-06-191-3/+5
|
* Compute content sizes lazily in layout 2020Anthony Ramine2020-06-181-58/+3
|
* Make outer_inline and outer_inline_and_percentages free functionsAnthony Ramine2020-06-151-84/+83
| | | | They now take a closure that will compute the content sizes on demand.
* Use the writing mode of the containing block when accessing CSS propertiesSimon Sapin2020-06-101-8/+15
| | | | | | | | … and converting them to flow-relative geometric values. These values are almost always used to size and position a fragment within its containing block, so using the mode of the containing block seems more correct. Note that the `writing-mode` and `direction` properties are disabled in Servo at the moment, so this PR by itself should have no effect: the writing mode of an element is always the same of that of its containing block since they’re both horizontal rtl.
* Less cloningSimon Sapin2020-04-011-6/+5
|
* Implement the `box-sizing` propertySimon Sapin2020-03-311-38/+53
|
* Dump box tree state into json files and display it on layout 2020 viewerFernando Jiménez Moreno2020-02-211-2/+2
|
* layout_2020: Avoid decomposing mixed length / percentages in intrinsic sizing.Emilio Cobos Álvarez2020-02-121-2/+6
| | | | As that makes no sense in presence of min / max.
* style: Miscellaneous Servo build fixes.Emilio Cobos Álvarez2020-02-121-2/+2
|
* layout-2020: build fixes.Emilio Cobos Álvarez2019-12-161-5/+5
|
* Account for min/max-width in outer intrinsic sizingSimon Sapin2019-12-101-6/+26
|
* Use a new `BoxContentSizes` enum instead of `Option<ContentSizes>`Simon Sapin2019-12-041-61/+71
|
* Replace boolean parameters by a new `ContentSizesRequest` enumSimon Sapin2019-12-041-0/+31
|
* Use `Sides::inline_sum` methodSimon Sapin2019-12-041-4/+3
|
* Fix incorrect variable nameSimon Sapin2019-12-041-2/+2
| | | | This was not the specified value
* Implement shrink-to-fit for absposSimon Sapin2019-12-031-4/+18
|
* Finish plumbing intrinsic min/max-content through box constructionSimon Sapin2019-12-031-1/+4
|
* Add content sizes computation for block containersSimon Sapin2019-12-031-2/+17
|
* Rename IntrinsicSizes to ContentSizesSimon Sapin2019-12-031-0/+80