Commit graph

41 commits

Author SHA1 Message Date
Simon Wülker
3d320fa96a
Update rustfmt to the 2024 style edition (#35764)
* 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>
2025-03-03 11:26:53 +00:00
Euclid Ye
28cea920ec
layout: Merge BoxFragment::used_overflow into ComputedValuesExt::effective_overflow (#35670) (#35670)
* Update wpt-test



* Merge used_overflow to effective_overflow; remove duplicate call



* Remove more duplicate calls; update effective_overflow logic



* Update reference link&style



* Apply final review suggestions

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-03-02 21:44:59 +00:00
Martin Robinson
102b77aef8
Make naming of variables consistent with SpecificLayoutInfo (#35104)
This is a followup to #34926.

Fixes #35078.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-01-21 17:28:14 +00:00
Oriol Brufau
d00d76c1e8
layout: Paint collapsed table borders on their own (#35075)
We were previously splitting collapsed borders into two halves, and then
paint each one as part of the corresponding cell. This looked wrong when
the border style wasn't solid, or when a cell spanned multiple tracks
and the border wasn't the same for all of them.

Now the borders of a table wrapper, table grid or table cell aren't
painted in collapsed borders mode. Instead, the resulting collapsed
borders are painted on their own.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-01-21 13:10:27 +00:00
Oriol Brufau
9b388da9cb
layout: Fix clientWidth & friends for tables (#35096)
`clientWidth` shouldn't include the borders of a box. The problem was
that we pretend that table wrapper boxes have the border specified on
the table element, even though this border actually applies to the
table grid box instead of the table wrapper box.

Therefore, `clientWidth` was wrong when it subtracted the borders.
This patch fixes it.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-01-20 17:18:20 +00:00
Martin Robinson
e81951a973
layout: Remove the obsolete layout tracing functionality (#35001)
There were two kinds of layout tracing controlled by the same debugging
option:

 - modern layout: Functionality that dumped a JSON serialization of the
   layout tree before and after layout.
 - legacy layout: A scope based tracing that reported the process of
   layout in a structured way.

I don't think anyone working on layout is using either of these two
features. For modern layout requiring data structure to implement
`serde` serialization is incredibly inconvenient and also generates a
lot of extra code.

We also have a more modern tracing functionality based on perfetto that
we have started to use for layout and IMO it's actually being used and
more robust.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-01-15 13:24:14 +00:00
Martin Robinson
de780dcde4
layout: Make Fragment hold ArcRefCell inside (#34923)
Push the interior mutability into enum variants of `Fragment`, so that
they can be cloned. This saves memory in the `Fragment` tree as the
`Fragment` enum is now a relatively wee 16 bytes and the interior parts
can be a variety of sizes. Before, every `Fragment` was the size of the
biggest kind (`BoxFragment` - 248 bytes).

This a step on the way toward incremental layout.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-01-13 09:59:59 +00:00
Oriol Brufau
e2be55b873
layout: Improve painting of collapsed borders in table layout (#34933)
This is still not the right approach, because we are not painting
collapsed borders as a single thing. Instead, we are splitting them
into two halves and paint each half on a different cell. This only
looks good for solid borders.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-01-11 00:38:31 +00:00
Steven Novaryo
bbb255d81c
layout: grid-template getComputedStyle cleanup (#34926)
* Update Taffy and WPT expectations

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Rename DetailedInfo to SpecificInfo

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Run fmt

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

---------

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
2025-01-10 09:04:49 +00:00
Steven Novaryo
76fa456a9a
layout: grid template getComputedStyle resolved value (#34885)
* Store taffy detailed info into fragment

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Fix info propagation and resolved grid track query

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Fix import

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Fix tracklist matching logic and type optimization

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Run fmt

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Update wpt expectations

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Optimizing info propagation and minor qol

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

* Run fmt

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>

---------

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
2025-01-09 10:49:27 +00:00
Oriol Brufau
bf75f17348
Add BoxFragment::is_inline_box() (#34233)
A helper function to check for inline boxes.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-11-12 15:50:20 +00:00
Oriol Brufau
c75f6627ba
Upgrade Stylo to 2024-10-04 (#33767)
* Upgrade Stylo to 2024-10-04

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D220285

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://bugzilla.mozilla.org/show_bug.cgi?id=1918093

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222817

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222856

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222532

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222533

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D222534

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Fixup for https://phabricator.services.mozilla.com/D223878

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-20 19:53:38 +00:00
Oriol Brufau
73880ee1d0
Remove BoxFragment::overconstrained (#33907)
This was only used for serializing inset properties in getComputedStyle,
but it was unnecessary and the logic was wrong anyways: an `auto` size
doesn't imply that we won't be overconstrained, because it won't become
negative even if the insets are big enough.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-19 01:55:55 +00:00
Oriol Brufau
09fc988d3a
Fix resolved value of insets to use margin box instead of content box (#33906)
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-18 23:55:53 +00:00
Oriol Brufau
76cdb0173e
Remove dead (and incorrect) logic about vertical overconstrainment (#33696)
BoxFragment::new() had some logic to mark relative positioned boxes with
both insets in the same axis set to something different than `auto` as
overconstrained.

However, this was dead code, since overconstrainment is checked for
getComputedStyle queries, but not for relative positioning.

Also, the logic was wrong: it was detecting vertical overconstrainment
by checking `left` and `bottom` (instead of `top` and `bottom`).

So it can just be removed.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-10-08 09:32:47 +00:00
Oriol Brufau
9175e598ad
Let table-related boxes adjust their overflow values (#33400)
The `overflow` property doesn't apply to table track and track groups,
and table elements only accept a few `overflow` values.

Therefore, this patch adds an `effective_overflow()` method to get the
actual value that needs to be used.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-09-11 15:30:17 +00:00
Martin Robinson
027fc53e2f
layout: Right-to-left support for other layout modes (#33375)
This change removes the `effective_writing_mode` concept and tries to
properly implement right-to-left layout support for all non-inline
writing modes. In general, what needs to happen is that rectangles
need to be converted to physical rectangles using the containing block.
A right-to-left rectangle's inline start is on the right physical side
of the containing block. Likewise a positive inline offset in
right-to-left text is a negative physical one.

The implementation here is pretty good for most layout modes, but floats
are still a bit in process. Currently, floats are processed in the
logical layout of the block container, but there still might be issues
with float interaction with mixed RTL and LTR.

While this does move us closer to supporting vertical writing modes,
this is still unsupported.

New failures:
 - Vertical writing mode not supported:
   - `/css/CSS2/floats/floats-placement-vertical-001b.xht`
   - `/css/CSS2/floats/floats-placement-vertical-001c.xht`
 - Absolutes inlines should avoid floats (#33323)
   - `/css/css-position/position-absolute-dynamic-static-position-floats-004.html`
 - No support for grid
   - `/css/css-align/self-alignment/self-align-safe-unsafe-grid-003.html`
   - `/css/css-position/static-position/inline-level-absolute-in-block-level-context-009.html`
   - `/css/css-position/static-position/inline-level-absolute-in-block-level-context-010.html`
 - Cannot reproduce these locally on any platform. Very mysterious:
   - `/css/css-tables/row-group-margin-border-padding.html`
   - `/css/css-tables/row-margin-border-padding.html`
 - Exposes bugs we have related to hanging whitespace in preserved
   whitespace inlines:
   - `/css/css-text/white-space/trailing-space-and-text-alignment-rtl-003.html`
   - `/css/css-text/white-space/white-space-pre-wrap-trailing-spaces-023.html`

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2024-09-11 13:40:11 +00:00
atbrakhi
095590e224
layout: Use Au in ComputedValuesExt (#33396)
* Use app unit in `ComputedValuesExt`

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* Some miscellaneous fixes

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

* remove redundant defination of `containing_block_inline_size`

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-09-10 21:35:17 +00:00
Martin Robinson
0d94a8acd2
layout: Prepare for bidi by guarding all access to writing-mode (#33082)
We want to selectively enable right-to-left writing modes per layout
context. This change makes that possible by allowing access to
`writing-mode` though an interface that always returns the default
horizontal top-to-bottom (implicitly left-to-right) writing mode.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2024-08-16 11:38:04 +00:00
Martin Robinson
d941d2fd67
layout: Convert the FragmentTree to physical geometry (#33030)
This converts all geometry in the FragmentTree into physical geometry,
doing conversions ahead of time instead of when traversing the fragment
tree. This is necessary to properly implement BiDi in Servo as we need
to know what side borders are on in mixed RTL and LTR contexts.

In addition, fragments are laid out in a particular context and only
that context knows its writing mode. There were issues where were using
one writing mode to lay out and another to convert to phyisical
coordinates. This isn't an issue now since we only use the default
writing mode, but starts to be an issue with BiDi text.

Closes #25564.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2024-08-14 12:22:06 +00:00
Martin Robinson
959ffad99a
layout: Add support for table captions (#32657)
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>
2024-07-03 18:24:19 +00:00
atbrakhi
044ab3eeab
fix clippy warning (#32667) 2024-07-02 14:59:46 +00:00
atbrakhi
26c585a0c5
use app unit in box_fragement (#32349) 2024-06-21 14:54:21 +00:00
Martin Robinson
3398fc017b
Move non-gfx things out of gfx_traits and create a base crate (#32296)
For a long time, `gfx_traits` has held a lot of things unrelated to graphics
and also unrelated to the `gfx` crate (which is mostly about fonts).
This is a cleanup which does a few things:

1. Move non `gfx` crate things out of `gfx_traits`. This is important in
   order to prevent dependency cycles with a different integration between
   layout, script, and fonts.
2. Rename the `msg` crate to `base`. It didn't really contain anything
   to do with messages and instead mostly holds ids, which are used
   across many different crates in Servo. This new crate will hold the
   *rare* data types that are widely used.

Details:

 - All BackgroundHangMonitor-related things from base to a new
   `background_hang_monitor_api` crate.
 - Moved `TraversalDirection` to `script_traits`
 - Moved `Epoch`-related things from `gfx_traits` to `base`.
 - Moved `PrintTree` to base. This should be widely useful in Servo.
 - Moved `WebrenderApi` from `base` to `webrender_traits` and renamed it
   to `WebRenderFontApi`.
2024-05-17 12:28:58 +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
78fe461ff2
layout: Properly parent table-row and table-row-group (#31619)
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>
2024-03-14 10:33:42 +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
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
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
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
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
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
Martin Robinson
aa073c3dca
layout: Implement support for line-height and vertical-align (#30902)
* layout: Implement support for `line-height` and `vertical-align`

This is an initial implementation of proper `line-height` and
`vertical-align` support. While this change includes the bulk of the
work there are still many missing pieces for full support. In particular
some big missing things are:

 - Flex containers do not properly compute their baselines. The idea is
   to tackle this in a followup change. This causes various flex tests
   to start failing because everything used to be top aligned.
 - The implementation of the line-height quirks (only active in quirks
   mode) are incomplete. While the quirk works in many cases, there are
   still some cases where it is handled incorrectly. This requires more
   redesign and refinement, better suited for a followup.
 - Most of the features are CSS 3 such as precision control of the
   baseline and first and last baselines are not implemented. This
   change gets us close to CSS 2.x support.

While there are many new test passes with this change some tests are
starting to fail. An accounting of new failures:

Tests failing also in Layout 2013:
 - /css/css2/positioning/toogle-abspos-on-relpos-inline-child.html (only passes in Chrome)
 - /css/CSS2/fonts/font-applies-to-001.xht (potentially an issue with font size)

Invalid tests:
 - /css/CSS2/visudet/inline-block-baseline-003.xht
 - /css/CSS2/visudet/inline-block-baseline-004.xht
 - These are are failing in all browsers. See https://bugs.chromium.org/p/chromium/issues/detail?id=1222151.

Missing table support:
 - /_mozilla/mozilla/table_valign_middle.html

Missing `font-size-adjust` support :
 - /css/css-fonts/font-size-adjust-zero-2.html (also failing in 2013)

Incomplete form field support :
- /html/rendering/widgets/the-select-element/option-add-label-quirks.html (label isn't rendered so button isn't the right size in quirks mode due to line height quirk)

Need support for calculating flexbox baseline:
 - /css/css-flexbox/fieldset-baseline-alignment.html
 - /css/css-flexbox/flex-inline.html
 - /css/css-flexbox/flexbox-baseline-multi-line-horiz-001.html
 - /css/css-flexbox/flexbox-baseline-single-item-001a.html
 - /css/css-flexbox/flexbox-baseline-single-item-001b.html

Failing because we don't create anonymous inline boxes for text children of blocks:
- /css/CSS2/linebox/anonymous-inline-inherit-001.html

Passes locally (potentially related to fonts):
 - /css/CSS2/css1/c414-flt-fit-004.xht
 - /css/css-transforms/transform-input-017.html
 - /html/obsolete/requirements-for-implementations/the-marquee-element-0/marquee-min-intrinsic-size.html
 - /css/css-fonts/first-available-font-005.html
 - /css/css-fonts/first-available-font-006.html

* Some cleanups after live review with @mukilan

Also update results.
2024-01-08 14:49:50 +00:00
Martin Robinson
a05598402e
Add initial support for sticky positioning for non-legacy layout (#30686)
* Add initial support for sticky positioning for non-legacy layout

Many tests still fail for a variety of reasons. One of the primary ones
is that CSSOM currently does not return correct values for elements
positioned by sticky nodes. This requires changes to WebRender to work
properly.

* Fix an assertion failure in the legacy layout sticky code
2023-11-29 09:03:24 +00:00
Delan Azabani
66258bfbbd
Temporarily convert existing cfg(debug_assertions) crashes to warnings (#30578) 2023-10-18 13:16:11 +00:00
Martin Robinson
8299868bd5
Layout 2020: Rename flow_relative types to Logical... (#30324)
This makes the names of flow relative geometry consistent with what is
used in the style crate and removes them from a module. With this change
it's more obvious what makes these types different from the ones in
`euclid`.
2023-09-12 07:31:30 +00:00
Samson
aad2dccc9c
Strict import formatting (grouping and granularity) (#30325)
* strict imports formatting

* Reformat all imports
2023-09-11 19:16:54 +00:00
Samson
711dbbd4af
remove extern crate (#30311)
* remove extern crate

* Update components/script_plugins/lib.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2023-09-08 12:11:31 +00:00
Martin Robinson
59f5414ca8
Split line layout into two phases (#30089)
In the first phase, we gather LineItems and then when we have enough to
form a line we turn them into Fragments. This will make it possible to
more simply implement `vertical-align` and `text-align: justify` because
we need to measure the different aspects of the candidate line and then
produce a Fragments.

This is a general refactor of the way that inline layout works, so comes
with some progressions. In addition there are some new failures.

New failures:

Some tests are now failing because only the test or reference is getting
proper line height when it wasn't before. These should be fixed in a
followup change that properly calculate line-height in more cases:

 - /_mozilla/css/list_style_position_a.html
 - /css/CSS2/floats/float-no-content-beside-001.html
 - /css/css-content/pseudo-element-inline-box.html
 - /css/css-flexbox/flexbox_flex-none-wrappable-content.html

Some tests are now failing because floats are now placed properly, but
are no longer in their inline box stacking contexts. These will be fixed
by a followup change which properly parents them:

- /css/filter-effects/filtered-inline-applies-to-float.html.ini
- /css/css-color/inline-opacity-float-child.html.ini

One test is failing due to floating point precision errors:

- /css/CSS2/floats-clear/floats-141.xht.ini

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2023-08-11 07:19:50 +00:00
Oriol Brufau
6b2bbdd02d Layout 2020: implement clearance as Option<Length>
Clearance was implemented as a Length, where zero meant no clearance.
However, having a clearance of 0px should be different than having
no clearance, since the former can still prevent margin collapse.

This patch keeps the existing behavior, so it won't be possible to get
a clearance of Some(Length::zero()), but it prepares the terrain for
a follow-up to fix calculate_clearance to return the proper thing.
2023-06-29 11:00:45 +02:00
Martin Robinson
e563927718 Layout 2020: Move all Fragment code to the fragment_tree directory
This is a simple code organization change with no behavior change with
the idea of making Layout 2020 easier to understand by new folks to the
project. The idea is that we will have a cleaner separation between the
different parts of layout ie one directory for the fragment tree and one
(currently multiple) directory for the box tree.
2023-06-04 18:12:11 +02:00