aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/dom_traversal.rs
Commit message (Collapse)AuthorAgeFilesLines
* Cleanup after #36461 (#36472)Oriol Brufau2025-04-111-8/+4
| | | | | | | This avoids some minor code duplication. Testing: not needed (no behavior change) Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* fix: Crashing due to input element hack (#36461)DK Liao2025-04-111-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR addresses a crash in text input element due to a hack to prevent text input being trimmed. The updated behavior will only add `zero width space` unicode character to the node if there's no text content instead of adding it constantly. Also by adding the same `zero width space` unicode character to text area when there's no text content within will allow text area element to properly display caret. <img width="197" alt="截圖 2025-04-11 中午12 51 00" src="https://github.com/user-attachments/assets/10bc7314-9aa3-49df-baac-ef26d39a96d8" /> This PR also addresses issues with multiple glyph runs: https://github.com/user-attachments/assets/658db56f-b166-47ec-bc77-c6c13114d669 Testing: This PR is tested using: - `./mach run -d 'data:text/html,<input id="input_element" value="xxxxxxxxxxxxxxxxxxxx">'` - `./mach run -d 'data:text/html,<textarea id="input_element" value="xxxxxxxxxxxxxxxxxxxx">'` without causing crashes, while the results should be covered by WPT tests Fixes: https://github.com/servo/servo/issues/36449 --------- Signed-off-by: DK Liao <dklassic@gmail.com>
* feat: Implement display for text selection and caret (#35830)DK Liao2025-04-101-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR introduces an initial, straightforward implementation for displaying text selection and the caret. This is achieved by passing the selection range and insertion point index down to `TextFragment`, along with the starting offset of each `TextFragment` to determine the proper range for displaying the caret and text selection. Additionally, the `selected_style` was passed into `TextFragment` to specify the background color. During the final build phase, although whitespace is typically ignored when constructing glyphs, we still need to retrieve it to render both the caret and text selection at the correct location. This ensures that whitespace is not overlooked when the `TextFragment` contains an insertion point or selection range. There are several improvements yet to be made, including: - The caret is static and does not flash. - The caret is not rendered when the input field is empty. (I suppose there should be an easy fix somewhere but I haven't found it yet) **Working Examples** macOS https://github.com/user-attachments/assets/f3622cbe-9fa6-40c0-b2d8-b3a8f9842c28 Windows https://github.com/user-attachments/assets/9b008a0d-0011-4c76-a2e2-0e35869a216c Linux [Screencast from 03-07-2025 11_05_41 AM.webm](https://github.com/user-attachments/assets/09a311ad-f975-4450-a66c-b20be525a5ed) --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix part of #33237 (But the cursor isn't blinking yet) - [x] These changes do not require tests because there's no behavior change Signed-off-by: DK Liao <dklassic@gmail.com>
* layout: Add initial support for the `::marker` pseudo-element (#36317)Martin Robinson2025-04-071-0/+4
| | | | | | | | | | | | | | | This change adds support for the `::marker` pseudo-element and ensure that markers are cached into the box tree. This is only initial support, there are a few things missing such as animations, transitions, and support the `content` CSS property. Testing: There are WPT tests for this change. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* fix: root element not establishing stacking context (#35390) (#36174)Michael Rees2025-04-031-0/+5
| | | | | | | | | | | | | | | | | - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #35390 - [X] There are tests for these changes [Successful WPT run](https://github.com/reesmichael1/servo/actions/runs/14097679625) (which includes the new test files) (I didn't make the formatting changes intentionally--those came from `mach format` following `mach test-tidy`.) --------- Signed-off-by: Michael Rees <mrees@noeontheend.com>
* layout: Simplify and generalize the usage of pseudo-elements (#36202)Martin Robinson2025-03-291-107/+82
| | | | | | | | | | | | | | | | | | | | | - 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>
* script: Eliminate `PseudoElementType` (#36146)Martin Robinson2025-03-261-2/+2
| | | | | | | | | | | | | Servo has a `PseudoElementType` which more or less duplicate's Stylo's `PseudoElement` with the addition of a non-pseudo element variant. This type needs to be converted into `PseudoElement` anyway when asking for the style of an element from Stylo, so eliminate Servo's version and simply use `Option<PseudoElement>` with the `None` variant meaning the non-pseudo. This is preparation for adding support for the `::marker` pseudo element. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Make input element display-inside always flow-root (#35908)Kenzie Raditya Tirtarahardja2025-03-231-3/+27
| | | | Signed-off-by: Kenzie Raditya Tirtarahardja <kenzieradityatirtarahardja.18@gmail.com> Co-authored-by: Kenzie Raditya Tirtarahardja <kenzieradityatirtarahardja.18@gmail.com>
* Migrate to the 2024 edition (#35755)Simon Wülker2025-03-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | * 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-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: Implement a non-recursive version of CSS `quotes` (#34770)Xiaocheng Hu2025-02-271-2/+35
| | | | | | | | | | | | | | | | | * Squash and don't explicitly use noto-cjk in tests Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com> * Mark quotes-034.html.ini failure Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com> * Address review comments Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com> --------- Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
* Lay out the contents of slot elements (#35220)Simon Wülker2025-02-021-11/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Make Slottable match layout/alignment of NonNull<Node> Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Implement ServoLayoutElement::slotted_nodes Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Bump mozjs Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Layout the contents of slot elements Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Implement ServoLayoutElement::assigned_slot Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * implement ServoLayoutElement::traversal_parent Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Simplify slottable name update Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Don't iterate over children of shadow hosts Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Recompute slot style when contents change Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Change match_slottable to a function instead of a macro Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Fix crown errors Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Update WPT expectations Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Reset a slottable's assigned slot when it's removed from the slot Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* layout: Lay out Shadow DOM elements (#34701)Martin Robinson2024-12-191-0/+5
| | | | | | | | | | | When an element is a shadow root, lay out the shadow root elements instead of the non-shadow children. This fixes some tests and introduces some failures, due to bugs in the Shadow DOM implementation. In general, this is very low impact as the Shadow DOM is still disabled by default. At least this gets elements rendering when the preference is turned on though. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* layout: Fix CSS `attr()` function case sensitivity matching (#34574)Steven Novaryo2024-12-131-2/+23
| | | Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
* build: upgrade rustc to 1.81.0 (#34270)Mukilan Thiyagarajan2024-12-121-2/+1
| | | Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* layout: Add `LayoutBoxBase` and use it for `IndependentFormattingContext` ↵Martin Robinson2024-12-071-5/+5
| | | | | | | | | | | | | | | | | | (#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>
* Replace .map_or(false with Option::is_some_and (#33468)Simon Wülker2024-09-161-1/+1
| | | Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* layout: Fix display of new text in `textarea` elements (#32886)Martin Robinson2024-07-301-18/+29
| | | | | | | Previously `<textarea>` was just displaying node contents, which is the original text content, not the one updated by later typing. This change fixes that issue. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* layout: Simplify `Contents` a little (#32487)Martin Robinson2024-06-211-26/+21
| | | | | | | Instead of duplicating some of `NonReplacedContents` in `Contents`, divide it into either replaced and non-replaced content, since this is how the layout system processes `Contents` always. In addition, stop using `TryInto` to match replaced or non-replaced contents, as it is quite confusing to handle an `Err` as a success case.
* layout: Add very basic support for showing text in input boxes (#32365)Martin Robinson2024-06-201-1/+25
| | | | | | | | | | | | | | | | | | This only paints text in input fields. Selection and cursor are still not painted. In addition to adding this feature, the change also updates the user-agent.css with the latest from the HTML specification. Extra padding and extraneous settings (such as a bogus line-height and min-height) are also removed from servo.css. This leads to some new passes. There are some new passes, this introduces failures as inserting text reveals issues that were hidden before. Notably: - failures in `/html/editing/editing-0/spelling-and-grammar-checking/`: We do not support spell-checking. - Most of the rest of the new failures are missing features of input boxes that are also missing in legacy layout.
* layout: Take into account `display: table` etc in offset* queries (#32448)Martin Robinson2024-06-101-8/+15
| | | | | | | | | | | | | | | * layout: Take into account `display: table` etc in offset* queries The specification says that for deciding whether an element should be used for offset* queries, a browser should take into account whether the element is a table cell or table. This change makes that happen. Co-authored-by: Oriol Brufau <obrufau@igalia.com> * Only tag HTML elements if they are in the HTML namespace --------- Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Upgrade stylo to 2024-05-15 (#32334)Oriol Brufau2024-05-271-1/+1
| | | | | | | | | | | | | * Upgrade stylo to 2024-05-15 * Fixup for https://phabricator.services.mozilla.com/D208599 * Fixup for https://phabricator.services.mozilla.com/D208569 * Fixup for https://phabricator.services.mozilla.com/D207796 * Fixup for https://phabricator.services.mozilla.com/D209690 * hashbrown and indexmap are no longer duplicated
* layout: Add support for `<object>` with image data URLs (#32069)Martin Robinson2024-04-151-1/+1
| | | | | This is enough support for `<object>` to get Acid2 working. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* layout: Do not inherit node and fragment flags in anonymous boxes (#31586)Martin Robinson2024-03-091-6/+27
| | | | | | | 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: Add line height from preserved segment breaks in quirks mode (#31419)Martin Robinson2024-02-261-1/+4
| | | | | | | | | | In quirks mode, preserved segment breaks should add line height to lines. This matches the behavior of WebKit and Blink, but not Gecko. This also handles the special-case of `<br>` elements, which are implemented with preserved segment breaks via `white-space: pre-line`. This is an implementation detail though because `<br>` has a special behavior if the line isn't empty -- it doesn't add any line height in this case.
* layout: Place absolutes in IFCs at their hypothetical static position (#31418)Martin Robinson2024-02-231-0/+2
| | | | | | | | Absolutes need to be placed at their hypothetical position as if the position value was static. This position differs based on the value they had before blockification. The code for placing absolutes was taking into account the original display for the inline value, but not for the block value. A static `display: block` box would placed at a new block position past the end of the linebox.
* Lint layout_2020 with clippy (#31169)Oriol Brufau2024-01-251-2/+2
| | | 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-0/+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-1/+1
| | | | 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.
* Anonymous boxes that wrap inlines should not inherit overflow (#30579)Martin Robinson2023-10-191-1/+1
| | | | | | | | | | | | | | In legacy layout, anonymous text wrappers were inheriting the `overflow` and `text-overflow` properties. This results in the creation of extra clipping for these anonymous wrappers which could clip away floats. We will likely implement `text-overflow` differently in non-legacy layout. This change marks all legacy layout pseudo elements as "legacy" and also adds a new pseudo element for non-legacy layout that does not inherit `overflow`. Fixes #30562. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Strict import formatting (grouping and granularity) (#30325)Samson2023-09-111-8/+9
| | | | | * strict imports formatting * Reformat all imports
* Make the choice of layout runtime settingMartin Robinson2023-07-061-0/+8
| | | | Co-authored-by: Samson <16504129+sagudev@users.noreply.github.com>
* Further changes required by ServoOriol Brufau2023-05-161-2/+2
|
* Combine DOM-related concepts in Layout 2020 into dom.rsMartin Robinson2023-05-131-195/+5
|
* Detect body elements during layoutMartin Robinson2023-05-041-0/+26
| | | | | | | | | | | | | | | | | During layout it is often useful, for various specification reasons, to know if an element is the `<body>` element of an `<html>` element root. There are a couple places where a brittle heuristic is used to detect `<body>` elements. This information is going to be even more important to properly handle `<html>` elements that inherit their overflow property from their `<body>` children. Implementing this properly requires updating the DOM wrapper interface. This check does reach up to the parent of thread-safe nodes, but this is essentially the same kind of operation that `parent_style()` does, so is ostensibly safe. This change should not change any behavior and is just a preparation step for properly handle `<body>` overflow.
* Add support for <iframe> elements for Layout 2020Martin Robinson2023-04-041-0/+12
| | | | | | This change adds support for the <iframe> element to Layout 2020. In addition, certain aspects of the implementation are made the same between both layout systems.
* Don’t parse unspported values of `content`Simon Sapin2020-07-241-2/+0
|
* Make a bool for `display: list-item` available to flow box constructionSimon Sapin2020-07-231-1/+3
|
* Bump rust to 1.46.0-nightly (a8cf39911 2020-06-21)Anthony Ramine2020-06-231-1/+1
| | | | This fixes a rustfmt reporting bug when the code contains syntax errors.
* Add WebGPU to Layout-2020Kunal Mohan2020-06-141-0/+1
|
* layout_2020: Tag fragments with their pseudo content typeMartin Robinson2020-06-061-28/+62
| | | | | This will allow us to answer queries and properly handle animations in the future for fragments generated for pseudo content.
* Owned `ServoArc<ComputedValues>` in `TraversalHandler`Simon Sapin2020-06-041-7/+7
|
* Don't panic while already panicking in BoxSlot::dropAnthony Ramine2020-05-181-2/+4
|
* Correctly paint the CSS canvas’ backgroundSimon Sapin2020-05-151-3/+14
| | | | | | | https://drafts.csswg.org/css-backgrounds/#special-backgrounds Fixes https://github.com/servo/servo/issues/25559 Closes https://github.com/servo/servo/pull/26121, as it is an alternative.
* Rewrite handling of pointers to boxes in the DOM treeSimon Sapin2020-05-151-65/+30
|
* Rename a bunch of style/layout data itemsAnthony Ramine2020-04-061-2/+2
| | | | | | | | | | | | | GetLayoutData::get_style_and_layout_data becomes GetOpaqueStyleAndLayoutData::get_opaque_style_and_layout_data. GetRawData::get_raw_data becomes GetStyleAndLayoutData::get_style_and_layout_data. LayoutNode::init_style_and_layout_data becomes LayoutNode::init_opaque_style_and_layout_data. LayoutNode::take_style_and_layout_data becomes LayoutNode::take_opaque_style_and_layout_data.
* Make DOM own the style and layout data, in an UnsafeCellAnthony Ramine2020-04-041-7/+5
| | | | The previous Cell was a lie.
* Make OpaqueLayoutAndStyleData just a bit less opaqueAnthony Ramine2020-04-041-3/+6
| | | | It now stores a NonNull<dyn Any>.
* Make LayoutNodeHelpers::text_content return a cowAnthony Ramine2020-03-311-4/+10
|
* Add a 'dom lifetime to GetLayoutDataAnthony Ramine2020-03-261-2/+2
|