Commit graph

166 commits

Author SHA1 Message Date
Martin Robinson
48ab8d8847
layout: Add a InlineFormattingContextBuilder (#32415)
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>
2024-06-03 14:46:53 +00:00
Martin Robinson
60b4b6c9f0
layout: Add support for white-space-collapse: break-spaces (#32388)
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>
2024-05-30 05:33:07 +00:00
Martin Robinson
77c50ad356
layout: When line-height is not Normal use metrics of first font not fallback (#32165)
This fixes an issue revealed by more consistent font fallback.
2024-05-13 08:26:31 +00:00
Martin Robinson
556bfb7dff
fonts: Make FontContext thread-safe and share it per-Layout (#32205)
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>
2024-05-02 10:34:10 +00:00
Oriol Brufau
d490fdf83c
Turn white-space into a shorthand (#32146)
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`.
2024-04-29 10:40:44 +00:00
Martin Robinson
a7838ae7cc
layout: Have TextRun::glyph_run_is_preserved_newline take into account 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. -->
2024-04-21 20:09:49 +00:00
Oluwatobi Sofela
df4c56efa4
clippy: Fix collapsible_if warning (#32109) 2024-04-19 08:29:01 +00:00
Martin Robinson
4ec61c2cdc
layout: Add support for clear on <br> elements (#32094)
`<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.
2024-04-17 14:15:06 +00:00
Oriol Brufau
1898394cb3
Keep 1st collapsible space after a preserved one (#32037)
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.
2024-04-15 12:02:09 +00:00
Oriol Brufau
5acfce5b89
Upgrade Stylo to 2023-12-01 (#32032)
* 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
2024-04-10 13:03:56 +00:00
Martin Robinson
fe8b23d14a
layout: Add a FontMetricsProvider for resolving font-relative units (#31966)
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.
2024-04-04 12:35:15 +00:00
Munish Mummadi
2a517f786b
Implementation of baseline-source (#31904)
Updating Stylo and test expectations.
2024-04-02 10:20:13 +00:00
Oriol Brufau
fff9ef87e6
Update Stylo to 2023-10-16 (#31932)
* 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
2024-03-30 13:30:13 +00:00
Oriol Brufau
07391e346b
Obey white-space: pre-wrap when intrinsically sizing an IFC (#31930)
It was being treated like `pre`, but it allows wrapping lines.
2024-03-29 15:02:47 +00:00
Oriol Brufau
b77ec08ab6
Ignore spaces before atomic inline for the min-content size (#31896)
* 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>
2024-03-27 16:46:54 +00:00
Oriol Brufau
e77dc36842
Pick the first or last baseline as appropriate (#31705)
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.
2024-03-25 16:19:06 +00:00
atbrakhi
95e69fe4ff
layout: use Au in BoxFragment (#31794)
* use au in BoxFragement

* review fix
2024-03-22 04:30:39 +00:00
Martin Robinson
841bd91784
layout: Take into account text-indent for justification (#31777)
This change makes it so that when calculating the space added between
words for justification, text-indent is taken into account.

Fixes #31775.
2024-03-21 15:58:03 +00:00
RustAndMetal
f6a975fc58
clippy: Fix several warnings (#31710)
Signed-off-by: RustAndMetal <111676747+RustAndMetal@users.noreply.github.com>
2024-03-18 08:33:43 +00:00
Oriol Brufau
39f660f520
Allow pre-wrap whitespace to hang at the end of the line (#31681)
* Allow pre-wrap whitespace to hang at the end of the line

* Use bitflags
2024-03-15 16:12:41 +00:00
Oriol Brufau
99c14c83ed
Obey white-space when intrinsically sizing an IFC (#31660)
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`.
2024-03-15 12:45:23 +00:00
Martin Robinson
871a9bf677
layout: IFCs should not always be marked as containing floats (#31641)
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.
2024-03-14 09:55:01 +00:00
Aarya Khandelwal
f5a1879bac
rustdoc: Fix warnings in components/layout_2020 (#31640)
* Changed LineItems to LineItem to make it a clickable link

* No variant named Anonymous is present in Fragment.
2024-03-13 13:50:26 +00:00
Oriol Brufau
0860deba05
Fix vertical alignment at the root of an IFC (#31636)
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.
2024-03-13 10:39:01 +00:00
atbrakhi
0fda14263a
layout: make margin in pbm use app unit (#31621)
* 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>
2024-03-13 03:15:20 +00:00
eri
b03411f567
clippy: Fix warnings in components/layout_2020 (#31611)
* clippy: fix warnings in components/layout_2020

* fix: review comments
2024-03-11 14:24:33 +00:00
Oriol Brufau
de7b9bed85
Take spaces into account in the max-content size of an IFC (#31613)
They were only considered in min-content sizes.
Also avoid some pointless conversions from Au to Length.

Fixes #31605.
2024-03-11 12:01:53 +00:00
Martin Robinson
096bd2977a
layout: Add start of documentation for inline layout (#31519)
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2024-03-06 12:55:35 +00:00
Oriol Brufau
50fdb82246
Fix size of tables in flow layout (#31455)
* 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>
2024-03-02 01:39:41 +00:00
Martin Robinson
5ba29c20ac
layout: Turn on synthetic small-caps for layout 2020 (#31435)
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.
2024-02-28 15:09:26 +00:00
Martin Robinson
e5598590ba
layout: Add line height from preserved segment breaks in quirks mode (#31419)
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.
2024-02-26 17:26:41 +00:00
Oriol Brufau
38d2ad9592
Support <div align="..."> and <center> on inline layout (#31388)
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
2024-02-23 15:36:36 +00:00
Martin Robinson
d8b326528b
layout: Add initial support for text-transform (#31396)
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>
2024-02-22 14:15:59 +00:00
Martin Robinson
02ae1f448e
layout: Add support for table rows, columns, rowgroups and colgroups (#31341)
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>
2024-02-20 13:22:02 +00:00
atbrakhi
74c07db56c
make ContainingBlock use Au for inline_size and block_size (#31370) 2024-02-20 09:14:44 +00:00
atbrakhi
d5c9e569bf
make size of DefiniteContainingBlock use app units (#31369) 2024-02-17 01:10:14 +00:00
Martin Robinson
6d73832009
layout: Do whitespace collapse during breaking and shaping (#31322)
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>
2024-02-13 23:08:00 +00:00
atbrakhi
8ba251c95f
layout: make padding and border use Au in pbm (#31289)
* use au for padding and border in pbm

* review fix
2024-02-12 22:49:50 +00:00
Martin Robinson
cdc3c369f0
layout: Implement support for font fallback (#31254)
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.
2024-02-11 10:08:49 +00:00
Martin Robinson
5dda97d187
layout: Wait to count justification opportunities until justification (#31236)
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.
2024-02-06 16:33:22 +00:00
Martin Robinson
7f13316f24
layout: Collect both start and end baselines for fragments (#31230)
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>
2024-02-05 18:06:05 +00:00
atbrakhi
091653417a
use app unit in replaced elements (#31178)
* 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>
2024-01-29 09:21:52 +00:00
Martin Robinson
094f7845b1
layout: Shape text only once (#31146)
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. -->
2024-01-25 14:33:47 +00:00
Oriol Brufau
50f56affe3
Lint layout_2020 with clippy (#31169)
cargo clippy --fix -p layout_2020 --allow-dirty --broken-code
2024-01-25 09:03:31 +00:00
Martin Robinson
7de0486e2e
layout: Count word separators as justification opportunities when trimming 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>
2024-01-23 11:47:13 +00:00
atbrakhi
45af1198aa
Layout: use Au in ContentSizes (#31135)
* use app_units

* resolve errors in table layout

* fmt

* add back current_line.min_content

* update expectation

* review fix
2024-01-23 10:18:39 +00:00
Martin Robinson
5c1723c983
rustdoc: Fix many rustdoc errors (#31147)
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.
2024-01-22 13:13:48 +00:00
atbrakhi
8e6bdb69b1
Layout: Clean up Au conversion helper functions in the flexbox (#31137)
* cleanup helper functions in flexbox

* fmt
2024-01-22 09:28:19 +00:00
Martin Robinson
a8b34e88ca
layout: Convert all inline iteration to a new foreach function (#31117)
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.
2024-01-19 13:56:14 +00:00
atbrakhi
3d520f2668
Use App units in flow layout (#30894)
* 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>
2024-01-19 13:20:01 +00:00