servo/components/layout_2020/fragment_tree/hoisted_shared_fragment.rs
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

58 lines
2.5 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use app_units::Au;
use serde::Serialize;
use style::logical_geometry::WritingMode;
use style::values::specified::align::AlignFlags;
use super::Fragment;
use crate::cell::ArcRefCell;
use crate::geom::{LogicalVec2, PhysicalRect, PhysicalVec};
/// A reference to a Fragment which is shared between `HoistedAbsolutelyPositionedBox`
/// and its placeholder `AbsoluteOrFixedPositionedFragment` in the original tree position.
/// This will be used later in order to paint this hoisted box in tree order.
#[derive(Serialize)]
pub(crate) struct HoistedSharedFragment {
pub fragment: Option<ArcRefCell<Fragment>>,
/// The "static-position rect" of this absolutely positioned box. This is defined by the
/// layout mode from which the box originates.
///
/// See <https://drafts.csswg.org/css-position-3/#staticpos-rect>
pub static_position_rect: PhysicalRect<Au>,
/// The resolved alignment values used for aligning this absolutely positioned element
/// if the "static-position rect" ends up being the "inset-modified containing block".
/// These values are dependent on the layout mode (currently only interesting for
/// flexbox).
pub resolved_alignment: LogicalVec2<AlignFlags>,
/// This is the [`WritingMode`] of the original parent of the element that created this
/// hoisted absolutely-positioned fragment. This helps to interpret the offset for
/// static positioning. If the writing mode is right-to-left or bottom-to-top, the static
/// offset needs to be adjusted by the absolutely positioned element's inline size.
pub original_parent_writing_mode: WritingMode,
}
impl HoistedSharedFragment {
pub(crate) fn new(
static_position_rect: PhysicalRect<Au>,
resolved_alignment: LogicalVec2<AlignFlags>,
original_parent_writing_mode: WritingMode,
) -> Self {
HoistedSharedFragment {
fragment: None,
static_position_rect,
resolved_alignment,
original_parent_writing_mode,
}
}
}
impl HoistedSharedFragment {
/// `inset: auto`-positioned elements do not know their precise position until after
/// they're hoisted. This lets us adjust auto values after the fact.
pub(crate) fn adjust_offsets(&mut self, offset: &PhysicalVec<Au>) {
self.static_position_rect = self.static_position_rect.translate(*offset);
}
}