aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/flexbox/mod.rs
Commit message (Collapse)AuthorAgeFilesLines
* layout: Store `Fragment` results in `LayoutBoxBase` and start using them for ↵Martin Robinson7 days1-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | queries (#36583) Start storing a link to laid-out `Fragment`s in `LayoutBoxBase`, so that these are accessible for queries and eventually for incremental layout. Some box tree data structures lacked a `LayoutBoxBase`, such as table tracks and table track groups[^1]. In addition, start using these `Fragment`s for queries instead of walking the entire `Fragment` tree. Currently, this isn't possible for most queries as `Fragment`s do not cache their absolute offsets (which are often necessary). This change uses the new box tree `Fragment`s for most resolved style queries. [^1]: Note that only rows and row groups store `Fragment`s as columsn and colgroups do not produce any. Testing: This is covered by existing tests. Fixes: This is part of #36525. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* layout: Enable using cached fragments when there is a BoxTree update point ↵Martin Robinson2025-04-091-0/+16
| | | | | | | | | | | | | | | | | | (#36404) This starts to enable the fragment cache for all layout modes, except grid. The main tricky bit here is that update points are absolutes and these need to be laid out again in their containing blocks. We punt a little bit on this, by forcing ancestors of update points to rebuild their Fragments. This is just the first step. Testing: We do not currently have layout performance tests, but will try to run some tests manually later. Behavior is covered by the WPT. Co-authored-by: Oriol Brufau <obrufau@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* layout: Cache `IndependentNonReplacedContents::layout()` (#36082)Oriol Brufau2025-03-241-22/+3
| | | | | | | | | | | | | | | This replaces `IndependentLayout` with `CacheableLayoutResult` and stores it in `LayoutBoxBase` so it can be reused when we need to lay out a box multiple times. This is a generalization of the caching that we had for flexbox, which is now removed in favor of the new one. With this, the number of runs per second in the Chromium perf test `flexbox-deeply-nested-column-flow.html` are multiplied by 3. Signed-off-by: Oriol Brufau <obrufau@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Update rustfmt to the 2024 style edition (#35764)Simon Wülker2025-03-031-1/+1
| | | | | | | | | | | | | * Use 2024 style edition Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Reformat all code Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* layout: Take percentage columns into account when sizing table grid min and ↵Martin Robinson2025-01-271-7/+4
| | | | | | | | | | | | | | | | | | | | | max (#35167) The specification doesn't say how to deal with percentages when determining the minimum and maximum size of a table grid, so follow the approach that Chromium uses. Essentially, figure out the "missing" percentage from the non-percentage columns and then use that to work backwards to fine the size of the percentage ones. This change is larger than one might expect, because this percentage approach shouldn't happen for tables that are descendants of a flex, grid or table container (except when there is an interceding absolute). We have to pass this information down when building the box tree. This will also make it easier to improve propagated text decorations in the future. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* layout: Remove the obsolete layout tracing functionality (#35001)Martin Robinson2025-01-151-7/+3
| | | | | | | | | | | | | | | | | | | | There were two kinds of layout tracing controlled by the same debugging option: - modern layout: Functionality that dumped a JSON serialization of the layout tree before and after layout. - legacy layout: A scope based tracing that reported the process of layout in a structured way. I don't think anyone working on layout is using either of these two features. For modern layout requiring data structure to implement `serde` serialization is incredibly inconvenient and also generates a lot of extra code. We also have a more modern tracing functionality based on perfetto that we have started to use for layout and IMO it's actually being used and more robust. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* layout: Generalize `ContainingBlock`'s block size to a `SizeConstraint` (#34946)Oriol Brufau2025-01-131-1/+1
| | | | | | | | | | | | | It used to be an `AuOrAuto`, turning it into a `SizeConstraint` allows passing the information about the min and max constraints when the containing block doesn't have a definite block size. This will be useful for table layout. Note that in most cases we were already constructing the containing block from a `SizeConstraint`, but we were calling `to_auto_or()` to turn it into an `AuOrAuto`. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* layout: Make a new `ContainingBlockSize` type (#34565)Martin Robinson2024-12-111-2/+2
| | | | | | | | This might make caching these values a bit easier in the future. Correcting the visibility of `ContainingBlock` also exposed some new rustc and clippy warnings that are fixed here. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Improve performance of flex column layouts by caching (#34461)Oriol Brufau2024-12-031-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Obey min and max properties when computing main size of column flex When laying out a column flex container with an auto preferred main size, we were resolving the used main size to the intrinsic max-content size. However, we weren't clamping this amount between the min and max sizes. Co-authored-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Oriol Brufau <obrufau@igalia.com> * Improve performance of flex column layouts by caching We were already using a cache for layout_for_block_content_size(), but we were only storing the intrinsic block size. Thus when laying out the flex items for real, we would perform new layouts, triggering an exponential complexity in case of nested flexboxes. Now we cache the entire layout result so that we can avoid doing the work again. This improves the results of flexbox-deeply-nested-column-flow.html (a Blink perf test) from ~40 runs/second to ~500 runs/second on my PC. Co-authored-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Oriol Brufau <obrufau@igalia.com> --------- Signed-off-by: Oriol Brufau <obrufau@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Layout: Implement CSS Grid using `taffy` (#32619)Nico Burns2024-11-211-6/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add layout.grid.enabled pref Signed-off-by: Nico Burns <nico@nicoburns.com> * Add taffy dependency Signed-off-by: Nico Burns <nico@nicoburns.com> * Import taffy <-> stylo conversion code from taffy_stylo crate Signed-off-by: Nico Burns <nico@nicoburns.com> * Add `Grid` variant to DisplayInside Signed-off-by: Nico Burns <nico@nicoburns.com> * Implement CSS Grid using Taffy Signed-off-by: Nico Burns <nico@nicoburns.com> Import full stylo_taffy crate Signed-off-by: Nico Burns <nico@nicoburns.com> Squashed PR feedback changes Deduplicate is_document_only_whitespace Signed-off-by: Nico Burns <nico@nicoburns.com> Import taffy::AvailableSpace Signed-off-by: Nico Burns <nico@nicoburns.com> Rename FlexContext to TaffyContainerContext Signed-off-by: Nico Burns <nico@nicoburns.com> Eliminate references to flexbox in taffy/layout module Signed-off-by: Nico Burns <nico@nicoburns.com> Use constructors for geom types Signed-off-by: Nico Burns <nico@nicoburns.com> Remove comment about abspos elements splitting contiguous text runs Signed-off-by: Nico Burns <nico@nicoburns.com> Remove reference to flexbox in taffy/construct Signed-off-by: Nico Burns <nico@nicoburns.com> Deduplicate construction of flexbox/grid containers Signed-off-by: Nico Burns <nico@nicoburns.com> Make anonymous text runs InFlow Signed-off-by: Nico Burns <nico@nicoburns.com> Remove commented code Signed-off-by: Nico Burns <nico@nicoburns.com> Update comments Signed-off-by: Nico Burns <nico@nicoburns.com> Inline/vendor the stylo/taffy interop code Signed-off-by: Nico Burns <nico@nicoburns.com> * Update test expectations Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix nits from PR review Signed-off-by: Nico Burns <nico@nicoburns.com> --------- Signed-off-by: Nico Burns <nico@nicoburns.com>
* layout: Avoid layout sometimes when stretching (#33967)Martin Robinson2024-10-241-14/+2
| | | | | | | | | | | | | | | | | | | | 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>
* layout: Cache content block size contributions (#33964)Martin Robinson2024-10-221-1/+27
| | | | | | | | 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>
* layout: Right-to-left support for other layout modes (#33375)Martin Robinson2024-09-111-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* layout: Implement proper absolute child position for flexbox (#33346)Martin Robinson2024-09-091-2/+2
| | | | | | | | | | | 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>
* Remove unused imports (#33371)Oriol Brufau2024-09-091-2/+2
| | | Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* layout: Do not use orthogonal baselines in flex layout (#33347)Martin Robinson2024-09-071-2/+6
| | | | | | | | | 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>
* layout: Layout for column flex-basis and minimum automatic size ↵Martin Robinson2024-08-191-0/+85
| | | | | | | | | | | 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>
* layout: Compute intrinsic sizes for flex items and flex containers (#32854)Delan Azabani2024-08-021-1/+17
| | | | | Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* remove `extern crate` (#30311)Samson2023-09-081-0/+2
| | | | | | | | | | | * 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>
* First pass at implementing the Flex Layout AlgorithmSimon Sapin2020-06-231-7/+1
| | | | https://drafts.csswg.org/css-flexbox/#layout-algorithm
* Compute content sizes lazily in layout 2020Anthony Ramine2020-06-181-0/+7
|
* Split `layout_2020/flexbox.rs` into modulesSimon Sapin2020-06-101-0/+21