aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/table/construct.rs
Commit message (Collapse)AuthorAgeFilesLines
* layout: Combine `layout_2020` and `layout_thread_2020` into a crate called ↵Martin Robinson8 days1-1160/+0
| | | | | | | | | | | | | | | | | | `layout` (#36613) Now that legacy layout has been removed, the name `layout_2020` doesn't make much sense any longer, also it's 2025 now for better or worse. The split between the "layout thread" and "layout" also doesn't make as much sense since layout doesn't run on it's own thread. There's a possibility that it will in the future, but that should be something that the user of the crate controls rather than layout iself. This is part of the larger layout interface cleanup and optimization that @Looriool and I are doing. Testing: Covered by existing tests as this is just code movement. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* layout: Store `Fragment` results in `LayoutBoxBase` and start using them for ↵Martin Robinson9 days1-10/+5
| | | | | | | | | | | | | | | | | | | | | | | | 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: Store table parts in DOM layout data (#36447)Martin Robinson2025-04-121-71/+92
| | | | | | | | | | | | | | | | | | | When laying out tables, store the boxes of non-anonymous table parts in their respective DOM objects. This is going to be important for incremental layout, but also for mapping from the DOM to the box tree (and eventually the fragment tree). For now, anonymous table parts are still lost to time and space, but in a followup change we hope to store them somewhere. Testing: This has no visible change to web rendering, so is covered by existing 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: Simplify and generalize the usage of pseudo-elements (#36202)Martin Robinson2025-03-291-49/+37
| | | | | | | | | | | | | | | | | | | | | - Remove the last remaining Servo-specific PseudoElement enum from layout. This was made to select `::before` and `::after` (both eager pseudo-elements), but now `traverse_pseudo_element` is called `traverse_eager_pseudo_element` and should work on any eager pseudo element. - Expose a single way of getting psuedo-element variants of ThreadSafeLayoutElement in the Layout DOM, which returns `None` when the pseudo-element doesn't apply (not defined for eager pseudo-elements or when trying to get `<details>` related pseudo-elements on elements that they don't apply to). - Ensure that NodeAndStyleInfo always refers to a node. This is done by making sure that anonymous boxes are all associated with their originating node. These changes are prepatory work for implementation of the `::marker` pseudo-element as well as ensuring that all anonymous boxes can be cached into the box tree eventually. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Migrate to the 2024 edition (#35755)Simon Wülker2025-03-131-3/+3
| | | | | | | | | | | | | | | | | | | | | | * Migrate to 2024 edition Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Allow unsafe_op_in_unsafe_fn lint This lint warns by default in the 2024 edition, but is *way* too noisy for servo. We might enable it in the future, but not now. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Compile using the 2024 edition Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* Update rustfmt to the 2024 style edition (#35764)Simon Wülker2025-03-031-3/+5
| | | | | | | | | | | | | * 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>
* Protect `create_spanned_slot_based_on_cell_above()` against arithmetic ↵Oriol Brufau2025-02-121-37/+33
| | | | | | | | | | | | | | | | | | | underflow (#35437) `Table::create_spanned_slot_based_on_cell_above()` was performing the subtraction `self.slots.len() - 2`, which could theoretically result in underflow if `self.slots.len()` is 0 or 1. That shouldn't have been possible in practice, but it may be worth addressing, to improve code robustness. So this patch: - Switches to `self.current_y()?.checked_sub(1)?`, which is safe and is easier to understand. - Moves `create_spanned_slot_based_on_cell_above()` to `TableBuilder`, since `current_y()` is there, and the method is only used when building the table anyways. - Ensures that both callers use `expect()` to assert that the method returned a value. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* layout: Take percentage columns into account when sizing table grid min and ↵Martin Robinson2025-01-271-29/+44
| | | | | | | | | | | | | | | | | | | | | 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>
* Elide lifetimes where possible after rustup (#34824)Martin Robinson2025-01-031-6/+4
| | | | | | | | | The new version of rust allows us to elide some lifetimes and clippy is now complaining about this. This change elides them where possible and removes the clippy exceptions. Fixes #34804. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* layout: Add `LayoutBox` to `TableSlotCell` (#34513)Martin Robinson2024-12-081-4/+2
| | | | | | This allows cells to cache their inline content size and will eventually allow them to participate in incremental layout. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* layout: Add `LayoutBoxBase` and use it for `IndependentFormattingContext` ↵Martin Robinson2024-12-071-22/+19
| | | | | | | | | | | | | | | | | | (#34507) Add a new struct `LayoutBoxBase`, that will be used throughout the box tree. The idea of this struct is that we have a place to consistently store common layout information (style and node information) and also to cache layout results such as content sizes (inline and maybe later box sizes) and eventually layout results. In addition to the addition of this struct, `IndependentFormattingContext` is flattened slightly so that it directly holds the contents of both replaced and non-replaced elements. This is only added to independent formatting contexts, but will later be added to all block containers as well. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Protect against arithmetic underflow in TableBuilder::current_y() (#34247)Oriol Brufau2024-11-141-20/+34
| | | | | | It doesn't seem like any web page could trigger the underflow, but this makes the code more robust. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Use a RwLock to cache inline_content_sizes() (#34232)Oriol Brufau2024-11-131-2/+2
| | | | | | | | | | | 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>
* Avoid recomputing inline_content_sizes() when not needed (#33806)Oriol Brufau2024-10-141-2/+2
| | | | | | | | | | | 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>
* Do not remove extra columns at the end of the table (#33451)Oriol Brufau2024-09-161-21/+11
| | | | | | | | | | | <col> and <colgroup> elements can be used to create extra columns that have no cell. We were removing these columns and column groups, but in general we shouldn't do that. Now we will only remove them if the table has no row nor row group. matching WebKit and the expectations of some tests. But note that Gecko and Blink never remove them. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Fix reordering of table-header-group and table-footer-group (#33383)Oriol Brufau2024-09-091-63/+66
| | | | | | | | | | | | | | | We weren't moving a table-header-group to the front if it was the first row group. However, there might still be preceding rows that don't belong to any row group. And similarly, we weren't moving a table-footer-group to the end if it was the last row group. However, there might still be following rows that don't belong to any row group. This patch fixes the logic, and enables existing tests from Microsoft that were missing a reference. Signed-off-by: Oriol Brufau <obrufau@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* fonts: Add support for generic font families and font size configuration ↵Martin Robinson2024-07-081-2/+5
| | | | | | | | | | | | | | | | | | (#32673) This adds support for generic font families in Servo and allows for configuration of them as well as their default font sizes. One interesting fix here is that now monospace default to 13px, like it does in other browsers. In addition to that, this exposes a new interface in Stylo which allows setting a default style. This is quite useful for fonts, but also for other kinds of default style settings -- like text zoom. Fixes #8371. Fixes #14773. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* layout: Improve layout of table captions (#32695)Martin Robinson2024-07-081-11/+20
| | | | | | | | | | | | | | | | - Instead of treating captions as a `BlockFormattingContext`, treat it as a `NonReplacedFormattingContext`, which allows reusing flow layout for captions -- fixing some issues with sizing. - Pass in the proper size of the containing block when laying out, fixing margin calculation. - Follow the unspecified rules about how various size properties on captions affect their size. - Improve linebreaking around atomics, which is tested by caption-related tests. This fixes intrinsic size calculation regarding soft wrap opportunities around atomic and also makes the code making these actual soft wrap opportunities a bit better. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* layout: Add support for table captions (#32657)Martin Robinson2024-07-031-14/+48
| | | | | | | | | | | | | This adds initial support for table captions. To do this, the idea of the table wrapper becomes a bit more concrete. Even so, the wrapper is still reponsible for allocating space for the grid's border and padding, as those properties are specified on the wrapper and not grid in CSS. In order to account for this weirdness of HTML/CSS captions and grid are now laid out and placed with a negative offset in the table wrapper content rect. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Fix and unify 'span' attribute for table columns (#32467)Oriol Brufau2024-06-101-34/+41
| | | | | | | | The attribute was only taken into account on columns that are immediate children of tables, and on column groups. It was ignored on columns within column groups. This patch moves the logic into a helper function that is then called from the three consumers.
* Don't trim leading whitespace of anonymous table cells (#31803)Oriol Brufau2024-03-211-8/+19
| | | | | | A sequence of whitespace shouldn't generate an anonymous table row/cell, but we can't just throw away the leading whitespace, because afterwards we may encounter some other content, and then the leading whitespace should appear in the cell (noticeable with e.g. `white-space: pre`).
* rustdoc: Correct unresolved link to `handle_cell. (#31708)Aarya Khandelwal2024-03-191-1/+1
|
* layout: Properly parent table-row and table-row-group (#31619)Martin Robinson2024-03-141-11/+21
| | | | | | | | Put table cell content fragments into a hieararchy of fragments that include their table row and table row group fragments. This ensures that things like relative positioning and transforms set on rows and row groups properly affect cells and cell content. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* clippy: Fix warnings in `components/layout_2020` (#31611)eri2024-03-111-2/+2
| | | | | * clippy: fix warnings in components/layout_2020 * fix: review comments
* layout: Do not inherit node and fragment flags in anonymous boxes (#31586)Martin Robinson2024-03-091-21/+22
| | | | | | | This doesn't really have observable behavior right now, as much as I tried to trigger some kind of bug. On the other hand, it's just wrong and is very obvious when you dump the Fragment tree. If you create a `display: table-cell` that is a child of the `<body>` all parts of the anonymous table are flagged as if they are the `<body>` element.
* layout: Fix the pseudo for anonymous tables (#31578)Martin Robinson2024-03-081-3/+1
| | | | | | | Anonymous tables should not use legacy pseudos, as the legacy layout engine had them inherit lots of random properites that lead to bad layout in the new layout engine. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* layout: Properly propagate text decoration values in tables (#31487)Martin Robinson2024-03-041-15/+28
| | | | Instead of just taking the value from the ancestor outside the table, combine the values when constructing the table.
* layout: Add support for table rows, columns, rowgroups and colgroups (#31341)Martin Robinson2024-02-201-21/+341
| | | | | | | | | | | | | | This adds support for table rows, columns, rowgroups and colgroups. There are few additions here: 1. The createion of fragments, which allows script queries and hit testing to work properly. These fragments are empty as all cells are still direct descendants of the table fragment. 2. Properly handling size information from tracks and track groups as well as frustrating rules about reordering rowgroups. 3. Painting a background seemlessly across track groups and groups. This is a thing that isn't done in legacy layout (nor WebKit)! Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* layout: Start work on table row height and vertical-align (#31246)Martin Robinson2024-02-101-1/+22
| | | | | | | | | This implements a very naive row height allocation approach. It has just enough to implement `vertical-align` in table cells. Rowspanned cells get enough space for their content, with the extra space necessary being allocated to the last row. There's still a lot missing here, including proper distribution of row height to rowspanned cells. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Lint layout_2020 with clippy (#31169)Oriol Brufau2024-01-251-13/+9
| | | cargo clippy --fix -p layout_2020 --allow-dirty --broken-code
* layout: Convert layout internal display to inline for replaced elements (#31133)Martin Robinson2024-01-231-1/+1
| | | | | | Replaced elements should never be able to have a layout internal display, according to the specification. This change makes it so that the used value of replaced element's display is always inline, as the specification says.
* 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.
* layout: Add *very* basic support for table layout (#31121)Martin Robinson2024-01-191-14/+46
| | | | | | | | | | | | | | | | | | | | | * layout: Add *very* basic support for table layout This is the first step to proper table layout. It implements a naive layout algorithm, notably only taking into account the preferred widths of the first table row. Still, it causes some float tests to start passing, so turn on the `layout.tables.enabled` preference for those directories. Co-authored-by: Oriol Brufau <obrufau@igalia.com> * Address review comments * Fix a crash with rowspan=0 * Turn on pref and update results for `/css/css-tables` and `/css/CSS2/tables` --------- Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Add support for table fixups (#30868)Martin Robinson2023-12-221-39/+288
| | | | | | | | | | | | | | | | 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>
* Add initial support for table box tree construction (#30799)Martin Robinson2023-12-051-0/+439
This is the first part of constructing the box tree for table layout. No layout is actually done and the construction of tables is now hidden behind a flag (in order to not regress WPT). Notably, this does not handle anonymous table part construction, when the DOM does not reflect a fully-formed table. That's part two. Progress toward #27459. Co-authored-by: Oriol Brufau <obrufau@igalia.com> Co-authored-by: Manish Goregaokar <manishsmail@gmail.com>