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>
This commit is contained in:
Martin Robinson 2024-09-11 06:40:11 -07:00 committed by GitHub
parent bc8d8b62c3
commit 027fc53e2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
99 changed files with 946 additions and 867 deletions

View file

@ -16,9 +16,7 @@ use style::Zero;
use super::{BaseFragment, BaseFragmentInfo, CollapsedBlockMargins, Fragment};
use crate::cell::ArcRefCell;
use crate::formatting_contexts::Baselines;
use crate::geom::{
AuOrAuto, LogicalRect, PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize, ToLogical,
};
use crate::geom::{AuOrAuto, PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize, ToLogical};
use crate::style_ext::ComputedValuesExt;
/// Describes how a [`BoxFragment`] paints its background.
@ -36,7 +34,7 @@ pub(crate) enum BackgroundMode {
pub(crate) struct ExtraBackground {
pub style: ServoArc<ComputedValues>,
pub rect: LogicalRect<Au>,
pub rect: PhysicalRect<Au>,
}
#[derive(Serialize)]
@ -165,16 +163,15 @@ impl BoxFragment {
/// Get the baselines for this [`BoxFragment`] if they are compatible with the given [`WritingMode`].
/// If they are not compatible, [`Baselines::default()`] is returned.
pub fn baselines(&self, writing_mode: WritingMode) -> Baselines {
let mut baselines = if writing_mode.is_horizontal() ==
self.style.effective_writing_mode().is_horizontal()
{
self.baselines
} else {
// If the writing mode of the container requesting baselines is not
// compatible, ensure that the baselines established by this fragment are
// not used.
Baselines::default()
};
let mut baselines =
if writing_mode.is_horizontal() == self.style.writing_mode.is_horizontal() {
self.baselines
} else {
// If the writing mode of the container requesting baselines is not
// compatible, ensure that the baselines established by this fragment are
// not used.
Baselines::default()
};
// From the https://drafts.csswg.org/css-align-3/#baseline-export section on "block containers":
// > However, for legacy reasons if its baseline-source is auto (the initial
@ -185,12 +182,12 @@ impl BoxFragment {
// This applies even if there is no baseline set, so we unconditionally set the value here
// and ignore anything that is set via [`Self::with_baselines`].
if self.style.establishes_scroll_container() {
let content_rect = self.content_rect.to_logical(writing_mode);
let content_rect_size = self.content_rect.size.to_logical(writing_mode);
let padding = self.padding.to_logical(writing_mode);
let border = self.border.to_logical(writing_mode);
let margin = self.margin.to_logical(writing_mode);
baselines.last = Some(
content_rect.size.block + padding.block_end + border.block_end + margin.block_end,
content_rect_size.block + padding.block_end + border.block_end + margin.block_end,
)
}
baselines
@ -229,6 +226,10 @@ impl BoxFragment {
self.border_rect().outer_rect(self.margin)
}
pub(crate) fn padding_border_margin(&self) -> PhysicalSides<Au> {
self.margin + self.border + self.padding
}
pub fn print(&self, tree: &mut PrintTree) {
tree.new_level(format!(
"Box\