mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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>
This commit is contained in:
parent
3d3621b652
commit
0d94a8acd2
14 changed files with 129 additions and 88 deletions
|
@ -976,7 +976,8 @@ impl FloatBox {
|
|||
);
|
||||
children = replaced.contents.make_fragments(
|
||||
&replaced.style,
|
||||
content_size.to_physical_size(containing_block.style.writing_mode),
|
||||
content_size
|
||||
.to_physical_size(containing_block.effective_writing_mode()),
|
||||
)
|
||||
},
|
||||
};
|
||||
|
@ -986,7 +987,7 @@ impl FloatBox {
|
|||
size: content_size,
|
||||
};
|
||||
|
||||
let containing_block_writing_mode = containing_block.style.writing_mode;
|
||||
let containing_block_writing_mode = containing_block.effective_writing_mode();
|
||||
BoxFragment::new(
|
||||
self.contents.base_fragment_info(),
|
||||
style.clone(),
|
||||
|
|
|
@ -360,7 +360,7 @@ impl<'a> LineItemLayout<'a> {
|
|||
},
|
||||
};
|
||||
|
||||
let ifc_writing_mode = self.ifc_containing_block.style.writing_mode;
|
||||
let ifc_writing_mode = self.ifc_containing_block.effective_writing_mode();
|
||||
if inner_state
|
||||
.flags
|
||||
.contains(LineLayoutInlineContainerFlags::HAD_ANY_FLOATS)
|
||||
|
@ -486,7 +486,7 @@ impl<'a> LineItemLayout<'a> {
|
|||
self.state.fragments.push(Fragment::Text(TextFragment {
|
||||
base: text_item.base_fragment_info.into(),
|
||||
parent_style: text_item.parent_style,
|
||||
rect: rect.to_physical(self.ifc_containing_block.style.writing_mode),
|
||||
rect: rect.to_physical(self.ifc_containing_block.effective_writing_mode()),
|
||||
font_metrics: text_item.font_metrics,
|
||||
font_key: text_item.font_key,
|
||||
glyphs: text_item.text,
|
||||
|
@ -511,7 +511,7 @@ impl<'a> LineItemLayout<'a> {
|
|||
relative_adjustement(&atomic.fragment.style, self.ifc_containing_block);
|
||||
}
|
||||
|
||||
let ifc_writing_mode = self.ifc_containing_block.style.writing_mode;
|
||||
let ifc_writing_mode = self.ifc_containing_block.effective_writing_mode();
|
||||
atomic.fragment.content_rect.origin += atomic_offset.to_physical_size(ifc_writing_mode);
|
||||
|
||||
if let Some(mut positioning_context) = atomic.positioning_context {
|
||||
|
@ -589,7 +589,7 @@ impl<'a> LineItemLayout<'a> {
|
|||
block: self.line_metrics.block_offset + self.state.parent_offset.block,
|
||||
};
|
||||
float.fragment.content_rect.origin -= distance_from_parent_to_ifc
|
||||
.to_physical_size(self.ifc_containing_block.style.writing_mode);
|
||||
.to_physical_size(self.ifc_containing_block.effective_writing_mode());
|
||||
self.state.fragments.push(Fragment::Float(float.fragment));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -890,7 +890,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
|
|||
start_positioning_context_length,
|
||||
);
|
||||
|
||||
let line_rect = line_rect.to_physical(self.containing_block.style.writing_mode);
|
||||
let line_rect = line_rect.to_physical(self.containing_block.effective_writing_mode());
|
||||
self.fragments
|
||||
.push(Fragment::Positioning(PositioningFragment::new_anonymous(
|
||||
line_rect, fragments,
|
||||
|
@ -934,14 +934,14 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
|
|||
TextAlignKeyword::Center | TextAlignKeyword::MozCenter => TextAlign::Center,
|
||||
TextAlignKeyword::End => TextAlign::End,
|
||||
TextAlignKeyword::Left | TextAlignKeyword::MozLeft => {
|
||||
if style.writing_mode.line_left_is_inline_start() {
|
||||
if style.effective_writing_mode().line_left_is_inline_start() {
|
||||
TextAlign::Start
|
||||
} else {
|
||||
TextAlign::End
|
||||
}
|
||||
},
|
||||
TextAlignKeyword::Right | TextAlignKeyword::MozRight => {
|
||||
if style.writing_mode.line_left_is_inline_start() {
|
||||
if style.effective_writing_mode().line_left_is_inline_start() {
|
||||
TextAlign::End
|
||||
} else {
|
||||
TextAlign::Start
|
||||
|
@ -1013,7 +1013,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
|
|||
state.current_containing_block_offset();
|
||||
state.place_float_fragment(
|
||||
fragment,
|
||||
self.containing_block.style.writing_mode,
|
||||
self.containing_block.effective_writing_mode(),
|
||||
CollapsedMargin::zero(),
|
||||
block_offset_from_containining_block_top,
|
||||
);
|
||||
|
@ -1035,7 +1035,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
|
|||
let margin_box = float_item
|
||||
.fragment
|
||||
.margin_rect()
|
||||
.to_logical(self.containing_block.style.writing_mode);
|
||||
.to_logical(self.containing_block.effective_writing_mode());
|
||||
let inline_size = margin_box.size.inline.max(Au::zero());
|
||||
|
||||
let available_inline_size = match self.current_line.placement_among_floats.get() {
|
||||
|
@ -1912,7 +1912,7 @@ impl IndependentFormattingContext {
|
|||
let container_writing_mode = inline_formatting_context_state
|
||||
.containing_block
|
||||
.style
|
||||
.writing_mode;
|
||||
.effective_writing_mode();
|
||||
let pbm = style.padding_border_margin(inline_formatting_context_state.containing_block);
|
||||
let margin = pbm.margin.auto_is(Au::zero);
|
||||
let pbm_sums = pbm.padding + pbm.border + margin;
|
||||
|
@ -1986,8 +1986,8 @@ impl IndependentFormattingContext {
|
|||
inline_formatting_context_state
|
||||
.containing_block
|
||||
.style
|
||||
.writing_mode,
|
||||
containing_block_for_children.style.writing_mode,
|
||||
.effective_writing_mode(),
|
||||
containing_block_for_children.effective_writing_mode(),
|
||||
"Mixed writing modes are not supported yet"
|
||||
);
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ impl OutsideMarker {
|
|||
sequential_layout_state: Option<&mut SequentialLayoutState>,
|
||||
collapsible_with_parent_start_margin: Option<CollapsibleWithParentStartMargin>,
|
||||
) -> Fragment {
|
||||
let containing_block_writing_mode = containing_block.style.writing_mode;
|
||||
let containing_block_writing_mode = containing_block.effective_writing_mode();
|
||||
let content_sizes = self
|
||||
.block_container
|
||||
.inline_content_sizes(layout_context, containing_block_writing_mode);
|
||||
|
@ -377,7 +377,10 @@ fn calculate_inline_content_size_for_block_level_boxes(
|
|||
let size = sizing::outer_inline(
|
||||
style,
|
||||
writing_mode,
|
||||
|| contents.inline_content_sizes(layout_context, style.writing_mode),
|
||||
|| {
|
||||
contents
|
||||
.inline_content_sizes(layout_context, style.effective_writing_mode())
|
||||
},
|
||||
Au::zero,
|
||||
)
|
||||
.max(ContentSizes::zero());
|
||||
|
@ -579,7 +582,7 @@ fn layout_block_level_children_in_parallel(
|
|||
placement_state.place_fragment_and_update_baseline(&mut fragment, None);
|
||||
child_positioning_context.adjust_static_position_of_hoisted_fragments(
|
||||
&fragment,
|
||||
containing_block.style.writing_mode,
|
||||
containing_block.effective_writing_mode(),
|
||||
PositioningContextLength::zero(),
|
||||
);
|
||||
positioning_context.append(child_positioning_context);
|
||||
|
@ -617,7 +620,7 @@ fn layout_block_level_children_sequentially(
|
|||
.place_fragment_and_update_baseline(&mut fragment, Some(sequential_layout_state));
|
||||
positioning_context.adjust_static_position_of_hoisted_fragments(
|
||||
&fragment,
|
||||
containing_block.style.writing_mode,
|
||||
containing_block.effective_writing_mode(),
|
||||
positioning_context_length_before_layout,
|
||||
);
|
||||
|
||||
|
@ -920,7 +923,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
|
|||
},
|
||||
};
|
||||
|
||||
let containing_block_writing_mode = containing_block.style.writing_mode;
|
||||
let containing_block_writing_mode = containing_block.effective_writing_mode();
|
||||
BoxFragment::new(
|
||||
base_fragment_info,
|
||||
style.clone(),
|
||||
|
@ -1006,7 +1009,7 @@ impl NonReplacedFormattingContext {
|
|||
};
|
||||
|
||||
let block_margins_collapsed_with_children = CollapsedBlockMargins::from_margin(&margin);
|
||||
let containing_block_writing_mode = containing_block.style.writing_mode;
|
||||
let containing_block_writing_mode = containing_block.effective_writing_mode();
|
||||
BoxFragment::new(
|
||||
self.base_fragment_info,
|
||||
self.style.clone(),
|
||||
|
@ -1257,7 +1260,7 @@ impl NonReplacedFormattingContext {
|
|||
};
|
||||
let block_margins_collapsed_with_children = CollapsedBlockMargins::from_margin(&margin);
|
||||
|
||||
let containing_block_writing_mode = containing_block.style.writing_mode;
|
||||
let containing_block_writing_mode = containing_block.effective_writing_mode();
|
||||
BoxFragment::new(
|
||||
self.base_fragment_info,
|
||||
self.style.clone(),
|
||||
|
@ -1291,7 +1294,7 @@ fn layout_in_flow_replaced_block_level(
|
|||
let effective_margin_inline_start;
|
||||
let (margin_block_start, margin_block_end) = solve_block_margins_for_in_flow_block_level(&pbm);
|
||||
|
||||
let containing_block_writing_mode = containing_block.style.writing_mode;
|
||||
let containing_block_writing_mode = containing_block.effective_writing_mode();
|
||||
let physical_content_size = content_size.to_physical_size(containing_block_writing_mode);
|
||||
let fragments = replaced.make_fragments(style, physical_content_size);
|
||||
|
||||
|
@ -1444,7 +1447,8 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
|
|||
};
|
||||
// https://drafts.csswg.org/css-writing-modes/#orthogonal-flows
|
||||
assert_eq!(
|
||||
containing_block.style.writing_mode, containing_block_for_children.style.writing_mode,
|
||||
containing_block.effective_writing_mode(),
|
||||
containing_block_for_children.effective_writing_mode(),
|
||||
"Mixed writing modes are not supported yet"
|
||||
);
|
||||
ContainingBlockPaddingAndBorder {
|
||||
|
@ -1498,8 +1502,16 @@ fn justify_self_alignment(containing_block: &ContainingBlock, free_space: Au) ->
|
|||
debug_assert!(free_space >= Au::zero());
|
||||
match style.clone_text_align() {
|
||||
TextAlignKeyword::MozCenter => free_space / 2,
|
||||
TextAlignKeyword::MozLeft if !style.writing_mode.line_left_is_inline_start() => free_space,
|
||||
TextAlignKeyword::MozRight if style.writing_mode.line_left_is_inline_start() => free_space,
|
||||
TextAlignKeyword::MozLeft
|
||||
if !style.effective_writing_mode().line_left_is_inline_start() =>
|
||||
{
|
||||
free_space
|
||||
},
|
||||
TextAlignKeyword::MozRight
|
||||
if style.effective_writing_mode().line_left_is_inline_start() =>
|
||||
{
|
||||
free_space
|
||||
},
|
||||
_ => Au::zero(),
|
||||
}
|
||||
}
|
||||
|
@ -1659,7 +1671,7 @@ impl PlacementState {
|
|||
inflow_baselines: Baselines::default(),
|
||||
is_inline_block_context,
|
||||
marker_block_size: None,
|
||||
writing_mode: containing_block_style.writing_mode,
|
||||
writing_mode: containing_block_style.effective_writing_mode(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue