Commit graph

315 commits

Author SHA1 Message Date
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
Rhea-Eve
1ab8fa2895
rustdoc: Fix two warnings in components/layout_2020 (#31712)
* Fix BoxFragment reference.

Signed-off-by: Rhea Karty <rheakarty@gmail.com>

* Fix reference to InlineFormattingContext.

Signed-off-by: Rhea Karty <rheakarty@gmail.com>

* Rewrap lines to avoid long length

* Remove trailing whitesapce

---------

Signed-off-by: Rhea Karty <rheakarty@gmail.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-03-18 08:33:15 +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
ad37a54f59
dependencies: Upgrade to WebRender 0.64 (#31486)
This brings the version of WebRender used in Servo up-to-date with Gecko
upstream. The big change here is that HiDPI is no longer handled via
WebRender. Instead this happens via a scale applied to the root layer in
the compositor. In addition to this change, various changes are made to
Servo to adapt to the new WebRender API.

Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-03-14 17:40:54 +00:00
Oriol Brufau
0e78c8114b
Allow finishing anonymous inline-table at the end of inline elements (#31650)
This avoids inserting it outside of its parent.
2024-03-14 09:58:00 +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
Oriol Brufau
f3a73dbed3
End ongoing IFC when inserting anonymous block-level table (#31606)
So that the table appears after preceding inline-level contents.
Fixes #31603.
2024-03-13 21:03:06 +00:00
Aarya Khandelwal
525fc58ed9
rustdoc: Fix warnings in components/layout_2020 (#31647)
* Added a : to make it a clickable link

* changed block_offset_of_parent to parent_offset , to make it a clickable link.
2024-03-13 18:16:31 +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
Martin Robinson
716f4a006d
layout: Propagate overflow values from <body> to root element (#31618)
The specification gives instructions for how these values should be
propagated. The other big changs here is that they aren't applied to the
`<body>`.

 Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-03-13 09:17:09 +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
1f23ec2b27
layout: Do not inherit node and fragment flags in anonymous boxes (#31586)
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.
2024-03-09 09:13:19 +00:00
Wepngong Maureen
0f4522c360
Fixed unresolved links by appropriately linking to parent (#31588)
Signed-off-by: Wepngong Maureen <maureenwepngong@gmail.com>
2024-03-08 19:53:44 +00:00
sandeep
81e6bd962b
Fix rustdoc warnings in components/layout_2020 (#31587)
* fix rustdoc warnings in components/layout_2020

Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>

* made suggested changes

Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>

---------

Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>
Co-authored-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>
2024-03-08 15:51:18 +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
Oriol Brufau
a97a04d84c
Support <div align="..."> and <center> in block layout (#31423)
As per HTML [1], <div align="..."> and <center> should align descendants
to the left/center/right. This is similar to having 'auto' margins [2],
but without changing their used values [3].

[1]: https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3
[2]: https://html.spec.whatwg.org/multipage/rendering.html#align-descendants
[3]: https://github.com/whatwg/html/issues/10149
2024-02-26 18:00:01 +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
Martin Robinson
0d4e4748c4
layout: Place absolutes in IFCs at their hypothetical static position (#31418)
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.
2024-02-23 17:55:18 +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
Oriol Brufau
4532f211be
Do not adjust margins in over-constrained cases (#31345)
This deviates from css2, but it's mandated by css-align, and matches
what other browsers do when no margin is 'auto'.

When some margin is 'auto', this should keep the proper round-tripping
behavior that Gecko and WebKit lack, and Blink recently adopted.
2024-02-21 17:07:20 +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
35fb95ca85
layout: Start work on table row height and vertical-align (#31246)
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>
2024-02-10 08:03:01 +00:00
Martin Robinson
f6b81a97f3
layout: Use BoxFragment border widths for display list generation (#31292)
Instead of using the border widths from the style, use the ones recorded
by the `BoxFragment`. This is necessary because inline layout can
override these border widths during fragmentation. For instance, when a
box is split across two lines only one fragment should have an inline
start border.
2024-02-08 23:21:24 +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
d68c7e7881
layout: Implement computation of table column widths (#31165)
* layout: Implement computation of table column widths

This change implements the various steps of table column width
computation, ignoring features that don't exist yet (such as separated
borders, column elements, and colgroups).

Co-authored-by: Oriol Brufau <obrufau@igalia.com>

* Fix an issue with the assignment of column percent width

* Respond to review comments

---------

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-01-25 23:13:13 +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