aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/flow/inline.rs
Commit message (Collapse)AuthorAgeFilesLines
* layout: Add a `InlineFormattingContextBuilder` (#32415)Martin Robinson2024-06-031-2524/+0
| | | | | | | | | | | | | | | | The main change here is that collapsed and `text-transform`'d text is computed as it's processed by DOM traversal. This single transformed text is stored in the root of the `InlineFormattingContext`. This will eventually allow performing linebreaking and shaping of the entire inline formatting context at once. Allowing for intelligent processing of linebreaking and also shaping across elements. This matches more closely what LayoutNG does. This shouldn't have any (or negligable) behavioral changes, but will allow us to prevent linebreaking inside of clusters in a followup change. Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
* layout: Add support for `white-space-collapse: break-spaces` (#32388)Martin Robinson2024-05-301-7/+18
| | | | | | | | | | | | | | This change adds support for `white-space-collapse: break-spaces` and adds initial parsing support for `overflow-wrap` and `word-break`. The later two properties are not fully supported, only in their interaction with `break-spaces`. This is a preliminary change preparing to implement them. In addition, `break_and_shape` is now forked and added to Layout 2020. This function is going to change a lot soon and forking is preparation for this. More code that is only used by Layout 2013 is moved from `gfx` to that crate. Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
* layout: When line-height is not `Normal` use metrics of first font not ↵Martin Robinson2024-05-131-4/+16
| | | | | fallback (#32165) This fixes an issue revealed by more consistent font fallback.
* fonts: Make `FontContext` thread-safe and share it per-Layout (#32205)Martin Robinson2024-05-021-32/+27
| | | | | | | | | | | | This allows sharing font templates, fonts, and platform fonts across layout threads. It's the first step toward storing web fonts in the layout versus the shared `FontCacheThread`. Now fonts and font groups have some locking (especially on FreeType), which will probably affect performance. On the other hand, we measured memory usage and this saves roughly 40 megabytes of memory when loading servo.org based on data from the memory profiler. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* Turn white-space into a shorthand (#32146)Oriol Brufau2024-04-291-18/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | Bumps Stylo to servo/stylo#37 `white-space` is split into `white-space-collapse` and `text-wrap-mode`: | white-space | white-space-collapse | text-wrap-mode | | ----------- | -------------------- | -------------- | | normal | collapse | wrap | | nowrap | collapse | nowrap | | pre-wrap | preserve | wrap | | pre | preserve | nowrap | | pre-line | preserve-breaks | wrap | | - | preserve-breaks | nowrap | Note this introduces a combination that wasn't previously possible, but I think the existing logic can handle it well enough. The old `allow_wrap()` is replaced by checking whether `text-wrap-mode` is set to `wrap`. The old `preserve_newlines()` is replaced by checking whether `white-space-collapse` is *not* set to `collapse`. The old `preserve_spaces()` is replaced by checking whether `white-space-collapse` is set to `preserve`.
* layout: Have `TextRun::glyph_run_is_preserved_newline` take into account ↵Martin Robinson2024-04-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `TextRunSegment` offset (#32119) A `TextRun` is composed of `TextRunSegment`s that are composed of `GlyphRun`s. `TextRun::glyph_run_is_preserved_newline` is indexing into the `TextRun` text, but the `GlyphRun` indexes that it uses are relative to the `TextRunSegment` offset. Before the code was using the offset without incorporating the `TextRunSegment` offset. This led to miscalculation of preserved newline location while processing text content. <!-- 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] There are tests for these changes <!-- 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. -->
* clippy: Fix collapsible_if warning (#32109)Oluwatobi Sofela2024-04-191-4/+3
|
* layout: Add support for `clear` on `<br>` elements (#32094)Martin Robinson2024-04-171-2/+34
| | | | | | | | `<br>` elements are a bit "special" in the sense that they defer a linebreak, but can also have `clear` applied to them. The `clear` that they supply should be applie *after* the linebreak is processed. This change adds special processing for this situation. Fixes #15402.
* Keep 1st collapsible space after a preserved one (#32037)Oriol Brufau2024-04-151-6/+7
| | | | | | | | The logic was to remove any collapsible white space preceded by other white space. However, this should only happen if the preceding space is also collapsible. Also fixing the logic in ContentSizesComputation, which was wrong but previously it didn't matter.
* Upgrade Stylo to 2023-12-01 (#32032)Oriol Brufau2024-04-101-0/+1
| | | | | | | | | | | | | | | | | | | * Upgrade Stylo to 2023-12-01 * Fixup for https://phabricator.services.mozilla.com/D191362 * Fixup for https://phabricator.services.mozilla.com/D191522 * Fixup for https://phabricator.services.mozilla.com/D191613 * Fixup for https://phabricator.services.mozilla.com/D191161 * Fixup for https://phabricator.services.mozilla.com/D191615 * Fixup for https://phabricator.services.mozilla.com/D193048 * Fixup for https://phabricator.services.mozilla.com/D193547 * Update test expectations
* layout: Add a `FontMetricsProvider` for resolving font-relative units (#31966)Martin Robinson2024-04-041-6/+5
| | | | | | | | | | | | | | | | | | | The only font relative unit that Servo knows how to resolve currently is `rem` (relative to the root font size). This is because Stylo cannot do any font queries. This adds a mechanism to allow this, exposing the ability to properly render `ex` units in Servo. This change only allows resolving some font size relative units thoug, as Servo doesn't collect all the FontMetrics it needs to resolve them all. This capability will be added in followup changes. Some new tests fail: - ex-unit-001.html: This test fails because Servo does not yet have support for setting the weight using @font-face rules on web fonts. - ex-unit-004.html: This test fails because Servo does not yet have support for setting the Unicode range of a web font using @font-face rules. - first-available-font-001.html: This test fails because the above two feature are missing.
* Implementation of baseline-source (#31904)Munish Mummadi2024-04-021-6/+12
| | | Updating Stylo and test expectations.
* Update Stylo to 2023-10-16 (#31932)Oriol Brufau2024-03-301-5/+6
| | | | | | | | | | | | | | | | | | | | | | | * Update Stylo to 2023-10-16 * Fixup for https://phabricator.services.mozilla.com/D185154 * Fixup for https://phabricator.services.mozilla.com/D188216 * Fixup for https://phabricator.services.mozilla.com/D185677 * Fixup for https://phabricator.services.mozilla.com/D188566 * Fixup for https://phabricator.services.mozilla.com/D188727 * Fixup for https://phabricator.services.mozilla.com/D189475 * Fixup for https://phabricator.services.mozilla.com/D189521 * Fixup for https://phabricator.services.mozilla.com/D188812 * Fixup for https://phabricator.services.mozilla.com/D189484 * Update test expectations
* Obey `white-space: pre-wrap` when intrinsically sizing an IFC (#31930)Oriol Brufau2024-03-291-10/+20
| | | It was being treated like `pre`, but it allows wrapping lines.
* Ignore spaces before atomic inline for the min-content size (#31896)Oriol Brufau2024-03-271-1/+4
| | | | | | | | | | | | | | | * Ignore spaces before atomic inline for the min-content size For the min-content size we should wrap lines wherever is possible, so wrappable spaces shouldn't increase the length of the line, they will just be removed or hang at the end of the line. * Add a clarifying comment Co-authored-by: Martin Robinson <mrobinson@igalia.com> --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Pick the first or last baseline as appropriate (#31705)Oriol Brufau2024-03-251-4/+17
| | | | | | | The old logic was always picking the last baseline, but this should only happen for inline-blocks. Since replaced elements and flex containers aren't currently setting their baselines, this is only an improvement for inline-tables.
* layout: use `Au` in `BoxFragment` (#31794)atbrakhi2024-03-221-7/+7
| | | | | * use au in BoxFragement * review fix
* layout: Take into account `text-indent` for justification (#31777)Martin Robinson2024-03-211-1/+6
| | | | | | This change makes it so that when calculating the space added between words for justification, text-indent is taken into account. Fixes #31775.
* clippy: Fix several warnings (#31710)RustAndMetal2024-03-181-4/+1
| | | Signed-off-by: RustAndMetal <111676747+RustAndMetal@users.noreply.github.com>
* Allow pre-wrap whitespace to hang at the end of the line (#31681)Oriol Brufau2024-03-151-18/+54
| | | | | * Allow pre-wrap whitespace to hang at the end of the line * Use bitflags
* Obey white-space when intrinsically sizing an IFC (#31660)Oriol Brufau2024-03-151-19/+23
| | | | | | | | | | | | | | | | | The old logic was assuming that all whitespace was a break opportunity, and that no newlines would be preserved. Note that text shaping considers the advance of a newline to be the same as a space. This was problematic because if we have a segment with a preserved space and newline, only the advance of the space should contrinute to the size of the block container. Therefore, I'm changing the breaker logic in other to have newline characters in their own segment. Then glyph_run_is_whitespace_ending_with_preserved_newline can just be renamed to glyph_run_is_preserved_newline. This patch is still not perfect because it doesn't check allow_wrap(), so `nowrap` is treated like `normal`, and `pre-wrap` like `pre`.
* layout: IFCs should not always be marked as containing floats (#31641)Martin Robinson2024-03-141-1/+3
| | | | | | | Marking all IFCs as containing floats shouldn't change layout results, but does prevent parallel layout in some cases. This change fixes an issue where we were marking all IFCs as containing floats. Fixes #31540.
* rustdoc: Fix warnings in `components/layout_2020` (#31640)Aarya Khandelwal2024-03-131-3/+3
| | | | | * Changed LineItems to LineItem to make it a clickable link * No variant named Anonymous is present in Fragment.
* Fix vertical alignment at the root of an IFC (#31636)Oriol Brufau2024-03-131-22/+52
| | | | | | | | | | | | | | At the root of an inline formatting context, we used its vertical-align in order to compute the strut. That was wrong, since vertical-align on a block container shouldn't affect the contents, it should only affect the alignment of the block container (if it's inline-level) within the parent IFC. This was only working well if the block container was block-level, since effective_vertical_align_for_inline_layout returned `baseline` for block-level boxes. Instead of the outer display type, this patch changes the logic to check whether we are at the root of the IFC.
* layout: make `margin` in `pbm` use app unit (#31621)atbrakhi2024-03-131-6/+12
| | | | | | | | | | | * 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-22/+16
| | | | | * clippy: fix warnings in components/layout_2020 * fix: review comments
* Take spaces into account in the max-content size of an IFC (#31613)Oriol Brufau2024-03-111-11/+9
| | | | | | They were only considered in min-content sizes. Also avoid some pointless conversions from Au to Length. Fixes #31605.
* layout: Add start of documentation for inline layout (#31519)Martin Robinson2024-03-061-0/+66
| | | Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
* Fix size of tables in flow layout (#31455)Oriol Brufau2024-03-021-13/+21
| | | | | | | | | | | | | | | | | | | | | | * 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>
* layout: Turn on synthetic small-caps for layout 2020 (#31435)Martin Robinson2024-02-281-1/+1
| | | | | | | | | | | | Synthetic small caps is supported by the font subsystem, but this is disabled in Layout 2020. We can turn this on to bring support to parity with the old layout system. In addition to turning on synthetic small-caps this change also improves the way that they work. Before, synthetic small caps meant that every character was a small version of capitalized character. After this change, capital letters are larger than small caps versions of small letters -- matching other browsers and the common expectation of how small caps works.
* layout: Add line height from preserved segment breaks in quirks mode (#31419)Martin Robinson2024-02-261-8/+33
| | | | | | | | | | 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.
* Support <div align="..."> and <center> on inline layout (#31388)Oriol Brufau2024-02-231-12/+15
| | | | | | | | | | As per HTML [1], <div align="..."> and <center> should behave as if they had the text-align property set to the corresponding value. Servo implements that as internal text-align values because there should the extra effect of aligning block descendants, but that part has not been implemented yet. This patch only adds support for inline layout. [1]: https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3
* layout: Add initial support for `text-transform` (#31396)Martin Robinson2024-02-221-0/+5
| | | | | | | | | | | | | This adds basic support for `text-transform` in a way that is more complete than legacy layout. There are still many missing elements of proper `text-transform` support such as: 1. Support for `full-width` and `full-size-kana` 2. Support for grapheme based uppercasing, lowercasing, and capitalization. These are all done per-code point right now. 3. Support for the language-specific `SpecialCasing.txt` cases for case mapping such as the ones for Irish and Turkish. Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
* layout: Add support for table rows, columns, rowgroups and colgroups (#31341)Martin Robinson2024-02-201-3/+3
| | | | | | | | | | | | | | 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>
* make ContainingBlock use Au for inline_size and block_size (#31370)atbrakhi2024-02-201-11/+10
|
* make size of DefiniteContainingBlock use app units (#31369)atbrakhi2024-02-171-1/+1
|
* layout: Do whitespace collapse during breaking and shaping (#31322)Martin Robinson2024-02-131-13/+20
| | | | | | | | This moves white space collapse to right before breaking and shaping happens, which is more similar to what happens in legacy layout. This is the first step toward making this procedure more efficient (avoiding string copies) and also implementing support for `text-transform`. Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
* layout: make `padding` and `border` use `Au` in `pbm` (#31289)atbrakhi2024-02-121-24/+26
| | | | | * use au for padding and border in pbm * review fix
* layout: Implement support for font fallback (#31254)Martin Robinson2024-02-111-81/+130
| | | | | | | This adds an initial implementation of font fallback, on part with the one used in legacy layout. There are still issues. For instance, font matching is done per unicode character rather than based on graphemes or the shape first approach of Chrome. The idea is that these changes can be made later.
* layout: Wait to count justification opportunities until justification (#31236)Martin Robinson2024-02-061-38/+30
| | | | | | | | | | Instead of tracking justification opportunities during line layout, wait until the line is about to be laid out and justification is about happen. This makes the logic for tracking justification opportunities simpler. In particular, we no longer have to carefully adjust them when trimming whitespace. Additionally, this avoids a bit of work unless justification is turned on. This also includes a small cleanup of the justification code.
* layout: Collect both start and end baselines for fragments (#31230)Martin Robinson2024-02-051-24/+23
| | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | * 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>
* layout: Shape text only once (#31146)Martin Robinson2024-01-251-229/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | Shape text during InlineFormattingContext construction rather than doing it twice during fragment tree construction. This is a step on the way toward proper font fallback. This also moves all `TextRun` related code into `text_run.rs` to try to trim down the size of `inline.rs`. <!-- 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 this should only have performance impacts. <!-- 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. -->
* Lint layout_2020 with clippy (#31169)Oriol Brufau2024-01-251-34/+27
| | | cargo clippy --fix -p layout_2020 --allow-dirty --broken-code
* layout: Count word separators as justification opportunities when trimming ↵Martin Robinson2024-01-231-6/+8
| | | | | | | | | | | | | | | | | whitespace (#31161) Before counting whitepsace-only `GlyphStore`s where counted as a single justification opportunity when trimming whitespace from the front and back of lines. This isn't correct, instead count the actual number of word seperators of the trimmed `GlyphStore`s. These two counts can be different in the case where whitespace collapse isn't happening yet (flexbox). In addition, using word seperators means the code is making less assumptions about the contents of the line and is more robust. This fixes some crashes in flexbox tests on debug builds. Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
* Layout: use `Au` in `ContentSizes` (#31135)atbrakhi2024-01-231-14/+14
| | | | | | | | | | | | | * 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-9/+9
| | | | 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: Clean up `Au` conversion helper functions in the flexbox (#31137)atbrakhi2024-01-221-1/+2
| | | | | * cleanup helper functions in flexbox * fmt
* layout: Convert all inline iteration to a new `foreach` function (#31117)Martin Robinson2024-01-191-230/+243
| | | | | | | | | | | | | | | | Instead of a tricky stack of enum iterators expose a `foreach()` function on InlineFormattingContext, which takes a `FnMut`. This prevents callers wanting to iterate from keeping a stack of iterators and will potentially allow a future version of this function to avoid borrowing the ArcRefCell<...> of inline boxes for every iteration (presumably using something like OwnedRef). Convert `inline_content_sizes` to use this new `foreach()` function and move the `Computation` out of the function body to `ContentSizesComputation`. This reduces the stack depth of inline size computation, because `foreach()` is iterative and not recursive. This is a preliminary change to removing the second round of text shaping during layout, because shaping will use this new iterator.
* Use App units in flow layout (#30894)atbrakhi2024-01-191-14/+20
| | | | | | | | | | | | | | | * 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>