mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
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>
This commit is contained in:
parent
65f90ff1fd
commit
d941d2fd67
17 changed files with 502 additions and 432 deletions
|
@ -71,6 +71,19 @@ impl<T: Clone> LogicalVec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_physical_point(physical_point: &PhysicalPoint<T>, mode: WritingMode) -> Self {
|
||||
// https://drafts.csswg.org/css-writing-modes/#logical-to-physical
|
||||
let (i, b) = if mode.is_horizontal() {
|
||||
(&physical_point.x, &physical_point.y)
|
||||
} else {
|
||||
(&physical_point.y, &physical_point.x)
|
||||
};
|
||||
LogicalVec2 {
|
||||
inline: i.clone(),
|
||||
block: b.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map<U>(&self, f: impl Fn(&T) -> U) -> LogicalVec2<U> {
|
||||
LogicalVec2 {
|
||||
inline: f(&self.inline),
|
||||
|
@ -195,7 +208,7 @@ impl fmt::Debug for LogicalRect<Au> {
|
|||
}
|
||||
|
||||
impl<T: Clone> LogicalVec2<T> {
|
||||
pub fn to_physical(&self, mode: WritingMode) -> PhysicalSize<T> {
|
||||
pub fn to_physical_size(&self, mode: WritingMode) -> PhysicalSize<T> {
|
||||
// https://drafts.csswg.org/css-writing-modes/#logical-to-physical
|
||||
let (x, y) = if mode.is_horizontal() {
|
||||
(&self.inline, &self.block)
|
||||
|
@ -204,6 +217,16 @@ impl<T: Clone> LogicalVec2<T> {
|
|||
};
|
||||
PhysicalSize::new(x.clone(), y.clone())
|
||||
}
|
||||
|
||||
pub fn to_physical_point(&self, mode: WritingMode) -> PhysicalPoint<T> {
|
||||
// https://drafts.csswg.org/css-writing-modes/#logical-to-physical
|
||||
let (x, y) = if mode.is_horizontal() {
|
||||
(&self.inline, &self.block)
|
||||
} else {
|
||||
(&self.block, &self.inline)
|
||||
};
|
||||
PhysicalPoint::new(x.clone(), y.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone> LogicalSides<T> {
|
||||
|
@ -464,14 +487,7 @@ impl<T> LogicalRect<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_physical(
|
||||
&self,
|
||||
mode: WritingMode,
|
||||
// Will be needed for other writing modes
|
||||
// FIXME: what if the containing block has a different mode?
|
||||
// https://drafts.csswg.org/css-writing-modes/#orthogonal-flows
|
||||
_containing_block: &PhysicalRect<T>,
|
||||
) -> PhysicalRect<T>
|
||||
pub fn to_physical(&self, mode: WritingMode) -> PhysicalRect<T>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
|
@ -482,7 +498,7 @@ impl<T> LogicalRect<T> {
|
|||
};
|
||||
PhysicalRect::new(
|
||||
PhysicalPoint::new(tl_x.clone(), tl_y.clone()),
|
||||
self.size.to_physical(mode),
|
||||
self.size.to_physical_size(mode),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -522,3 +538,37 @@ impl From<LogicalRect<CSSPixelLength>> for LogicalRect<Au> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait ToLogical<Unit, LogicalType> {
|
||||
fn to_logical(&self, writing_mode: WritingMode) -> LogicalType;
|
||||
}
|
||||
|
||||
impl<Unit: Copy> ToLogical<Unit, LogicalRect<Unit>> for PhysicalRect<Unit> {
|
||||
fn to_logical(&self, writing_mode: WritingMode) -> LogicalRect<Unit> {
|
||||
LogicalRect {
|
||||
start_corner: LogicalVec2::from_physical_size(
|
||||
&PhysicalSize::new(self.origin.x, self.origin.y),
|
||||
writing_mode,
|
||||
),
|
||||
size: LogicalVec2::from_physical_size(&self.size, writing_mode),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Unit: Copy> ToLogical<Unit, LogicalVec2<Unit>> for PhysicalSize<Unit> {
|
||||
fn to_logical(&self, writing_mode: WritingMode) -> LogicalVec2<Unit> {
|
||||
LogicalVec2::from_physical_size(self, writing_mode)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Unit: Copy> ToLogical<Unit, LogicalVec2<Unit>> for PhysicalPoint<Unit> {
|
||||
fn to_logical(&self, writing_mode: WritingMode) -> LogicalVec2<Unit> {
|
||||
LogicalVec2::from_physical_point(self, writing_mode)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Unit: Copy> ToLogical<Unit, LogicalSides<Unit>> for PhysicalSides<Unit> {
|
||||
fn to_logical(&self, writing_mode: WritingMode) -> LogicalSides<Unit> {
|
||||
LogicalSides::from_physical(self, writing_mode)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue