Commit graph

27 commits

Author SHA1 Message Date
Narfinger
4ddcba240b
Update deprecated use of PanicInfo to PanicHookInfo (#34659)
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2024-12-17 03:50:26 +00:00
Oriol Brufau
681d7dca9b
Use inline-start/inline-end instead of left/right terminology for floats (#34608)
It was a bit confusing that e.g. a float with `FloatSide::InlineStart`
would set `FloatBand::left`, or that `PlacementAmongFloats` would
compute `max_inline_start` from the various `FloatBand::left`.
So now all the float logic will consistently use logical terminoligy.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-12-13 16:37:35 +00:00
Oriol Brufau
61ca2dde29
Upgrade Stylo to 2024-12-04 (#34501)
* Upgrade Stylo to 2024-12-04

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

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

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

* Update test expectations

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

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2024-12-06 01:05:54 +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
Hayashi Mikihiro
4cc1b68546
Remove lazy static (#33078)
* remove from rand

Mutex<OsRng> can be initialized in compile time.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* remove from layout_2020

Mutex<()> can be initialize in compile time

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* remove from media

`IS_MULTIPROCESS` doesn't be used.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* remove lazy_static from dependencies

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* rewrite suppressed_leaks_for_asan.txt

For all of lazy_static was replaced with LazyLock.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

---------

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
2024-08-16 03:57:09 +00:00
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
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
atbrakhi
95e69fe4ff
layout: use Au in BoxFragment (#31794)
* use au in BoxFragement

* review fix
2024-03-22 04:30:39 +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
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
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
fc31e69f79
layout: Add *very* basic support for table layout (#31121)
* layout: Add *very* basic support for table layout

This is the first step to proper table layout. It implements a naive
layout algorithm, notably only taking into account the preferred widths
of the first table row. Still, it causes some float tests to start
passing, so turn on the `layout.tables.enabled` preference for those
directories.

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

* Address review comments

* Fix a crash with rowspan=0

* Turn on pref and update results for `/css/css-tables` and `/css/CSS2/tables`

---------

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-01-19 13:20:20 +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
Martin Robinson
f0b4162328
Add initial support for table box tree construction (#30799)
This is the first part of constructing the box tree for table layout. No
layout is actually done and the construction of tables is now hidden
behind a flag (in order to not regress WPT).  Notably, this does not
handle anonymous table part construction, when the DOM does not reflect
a fully-formed table. That's part two.

Progress toward #27459.

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Manish Goregaokar <manishsmail@gmail.com>
2023-12-05 11:10:45 +00:00
Martin Robinson
2c341d9e69
Allow raising FloatContext ceiling after processing box with overflow (#30539)
When a box has overflow, any floats placed in that box will lower the
float ceiling into the overflow. If no float is placed in the box
though, the ceiling should be the block position where the overflow
starts. We already know where this is, because we might be passing a
negative value for the new block position after processing a box
(content_size - actual_size would be negative). This negative value
never raises the ceiling though since a maximum is used.

In the case that there is overflow, this change allows raising the
ceiling, but never passed the lowest float. This necessitates keeping
two values for the ceiling: one for floats and one for non-floats.

Fixes #30304.
2023-10-17 07:53:57 +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
Yutaro Ohno
e6c9ca207c
Fix failing unit test due to overflow (#30074) 2023-08-08 11:29:14 +00:00
Oriol Brufau
77c6a61dfa
Remove ClearSide enum (#30035)
Just use Clear instead, they have the same values.
2023-07-27 09:46:15 +00:00
Oriol Brufau
e38d21d33d
Run unit tests with both layout 2013 and layout 2020 (#30032)
Since #29950, unit tests were only running with the legacy layout, and
there was no way to run them for layout 2020.

This patch makes './mach test-unit' run unit tests for both.

Also doing some changes so that the layout 2020 floats.rs tests compile.
2023-07-27 05:04:55 +00:00
Martin Robinson
4cb4332602
Correct rendering of floated root
Fix two issues around floating a root element:

1. In the StackingContext code handle the case where a root element is a
   Float fragment and not a Box fragment. This fixes a debug assertion
   failure in the css/CSS2/float/float-root.html test.
2. When initializing the SequentialLayoutState, use the containing block
   width as the maximum inline float placement position instead of
   infinity. This fixes the rendering of css/CSS2/float/float-root.html.

Note that css/CSS2/float/float-root.html was passing before, because
both the test and reference were subject to the same bug. This fixes a
couple other tests as well.
2023-06-20 17:46:45 +02:00
Martin Robinson
5c5cc4b795 Fix the unit test
These were broken for various issues.
2023-06-03 06:10:17 +02:00
Martin Robinson
25f6cc04a2 Do not hoist floated fragments
Instead of hoisting floated fragments to be siblings of the fragment
created by their containing block formatting context, keep them in
"normal" fragment tree position and adjust their positioning to be
relative to the containing block. This means that float fragments follow
the existing invariants of the fragment tree and properly handle hit
testing, painting order, and relative positioning.

The tradeoff here is more complexity tracking the containing block
offsets from the block formatting context (including handling collapsed
margins), but less complexity dealing with hoisting / shared ownership
in addition to the correctness benefits.

Some tests are failing now because this change revealed some additional
shortcomings with clearing block formatting context content size past
the end of their contained floats. This will be fixed in a followup
change.

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2023-06-03 06:10:17 +02:00
Patrick Walton
cdec48328e Place floats in layout 2020, but don't flow text around the floats yet.
This commit puts floats behind the `layout.floats.enabled` pref, because of the
following issues and unimplemented features:

* Inline formatting contexts don't take floats into account, so text doesn't
  flow around the floats yet.

* Non-floated block formatting contexts don't take floats into account, so BFCs
  can overlap floats.

* Block formatting contexts that contain floats don't expand vertically to
  contain all the floats. That is, floats can stick out the bottom of BFCs,
  contra spec.
2023-06-03 06:09:21 +02:00
Patrick Walton
362b64aa68 Use the size of the containing block, not the size of the block formatting
context, to place floats in layout 2020.

The containing block for a float is not necessarily the same as the block
formatting context the float is in per CSS 2.1 [1]:

"For other elements, if the element’s position is relative or static, the
containing block is formed by the content edge of the nearest block container
ancestor box."

This shows up in the simplest case:

	<html>
	<body>
	<div style="float: left">Hello</div>
	</body>
	</html>

In this case, the `<html>` element is the block formatting context with inline
size equal to the width of the window, but the `<body>` element with nonzero
inline margins is the containing block for the float. The float placement must
respect the content box of the `<body>` element (i.e. floats must not overlap
the `<body>` element's margins), not that of the `<html>` element.

Because a single block formatting context may contain floats with different
containing blocks, the left and right "walls" of that containing block become
properties of individual floats at the time of placement, not properties of the
float context itself.

Additionally, this commit generalizes the float placement logic a bit to allow
the placement of arbitrary objects, not just floats. This is intended to
support inline layout and block formatting context placement.

This commit updates the `FloatContext` and associated tests only and doesn't
actually wire the context up to the rest of layout, so floats in pages still
aren't actually laid out.

[1]: https://drafts.csswg.org/css2/#containing-block-details
2020-07-22 19:58:28 -07:00
Patrick Walton
5b36d211b4 Add an implementation of the core float and clear placement logic in layout
2020, not yet wired to the rest of layout.

This commit implements an object that handles the 10 rules in CSS 2.1:

https://www.w3.org/TR/CSS2/visuren.html#float-position

The implementation strategy is that of a persistent balanced binary search tree
of float bands. Binary search trees are commonly used for implementing float
positioning; e.g. by WebKit.  Persistence enables each object that interacts
with floats to efficiently contain a snapshot of the float list at the time
that object was laid out. That way, incremental layout can invalidate and start
reflow at any point in a containing block.

This commit features extensive use of
[QuickCheck](https://github.com/BurntSushi/quickcheck) to ensure that the rules
of the CSS specification are followed.

Because this is not yet connected to layout, floats will not actually be laid
out in Web pages yet.

Note that unit tests as set up in Servo currently require types that they
access to be public. Therefore, some internal layout 2020 types that were
previously private have been made public. This is somewhat unfortunate.

Part of #25167.
2020-07-20 12:42:34 -07:00