use app unit in box_fragement (#32349)

This commit is contained in:
atbrakhi 2024-06-21 16:54:21 +02:00 committed by GitHub
parent 66edef8065
commit 26c585a0c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 273 additions and 289 deletions

View file

@ -991,7 +991,7 @@ impl FloatBox {
self.contents.base_fragment_info(),
style.clone(),
children,
content_rect,
content_rect.into(),
pbm.padding,
pbm.border,
margin,
@ -1209,7 +1209,7 @@ impl SequentialLayoutState {
);
let pbm_sums = &(&box_fragment.padding + &box_fragment.border) + &box_fragment.margin;
let content_rect: LogicalRect<Au> = box_fragment.content_rect.clone().into();
let content_rect = box_fragment.content_rect.clone();
let margin_box_start_corner = self.floats.add_float(&PlacementInfo {
size: &content_rect.size + &pbm_sums.sum(),
side: FloatSide::from_style(&box_fragment.style).expect("Float box wasn't floated!"),
@ -1227,6 +1227,6 @@ impl SequentialLayoutState {
block: new_position_in_bfc.block - block_start_of_containing_block_in_bfc,
};
box_fragment.content_rect.start_corner = new_position_in_containing_block.into();
box_fragment.content_rect.start_corner = new_position_in_containing_block;
}
}

View file

@ -240,7 +240,7 @@ impl TextRunLineItem {
Some(TextFragment {
base: self.base_fragment_info.into(),
parent_style: self.parent_style,
rect,
rect: rect.into(),
font_metrics: self.font_metrics,
font_key: self.font_key,
glyphs: self.text,
@ -366,14 +366,15 @@ impl InlineBoxLineItem {
// Relative adjustment should not affect the rest of line layout, so we can
// do it right before creating the Fragment.
if style.clone_position().is_relative() {
content_rect.start_corner += &relative_adjustement(&style, state.ifc_containing_block);
content_rect.start_corner +=
&relative_adjustement(&style, state.ifc_containing_block).into();
}
let mut fragment = BoxFragment::new(
self.base_fragment_info,
self.style.clone(),
fragments,
content_rect,
content_rect.into(),
padding,
border,
margin,
@ -460,13 +461,13 @@ impl AtomicLineItem {
// The initial `start_corner` of the Fragment is only the PaddingBorderMargin sum start
// offset, which is the sum of the start component of the padding, border, and margin.
// This needs to be added to the calculated block and inline positions.
self.fragment.content_rect.start_corner.inline += state.inline_position;
self.fragment.content_rect.start_corner.inline += state.inline_position.into();
self.fragment.content_rect.start_corner.block +=
self.calculate_block_start(state.line_metrics);
self.calculate_block_start(state.line_metrics).into();
// Make the final result relative to the parent box.
self.fragment.content_rect.start_corner =
&self.fragment.content_rect.start_corner - &state.parent_offset;
&self.fragment.content_rect.start_corner - &state.parent_offset.into();
if self.fragment.style.clone_position().is_relative() {
self.fragment.content_rect.start_corner +=
@ -571,7 +572,7 @@ impl FloatLineItem {
block: state.line_metrics.block_offset + state.parent_offset.block,
};
self.fragment.content_rect.start_corner =
&self.fragment.content_rect.start_corner - &distance_from_parent_to_ifc;
&self.fragment.content_rect.start_corner - &distance_from_parent_to_ifc.into();
self.fragment
}
}

View file

@ -381,13 +381,13 @@ impl LineBlockSizes {
}
}
fn resolve(&self) -> Length {
fn resolve(&self) -> Au {
let height_from_ascent_and_descent = self
.baseline_relative_size_for_line_height
.as_ref()
.map(|size| (size.ascent + size.descent).abs())
.unwrap_or_else(Au::zero);
self.line_height.max(height_from_ascent_and_descent.into())
Au::from(self.line_height).max(height_from_ascent_and_descent)
}
fn max(&self, other: &LineBlockSizes) -> LineBlockSizes {
@ -431,7 +431,7 @@ impl LineBlockSizes {
None => {
// This is the case mentinoned above where there are multiple solutions.
// This code is putting the baseline roughly in the middle of the line.
let leading = Au::from(self.resolve()) -
let leading = self.resolve() -
(self.size_for_baseline_positioning.ascent +
self.size_for_baseline_positioning.descent);
leading.scale_by(0.5) + self.size_for_baseline_positioning.ascent
@ -900,7 +900,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
LineBlockSizes::zero()
};
let resolved_block_advance = effective_block_advance.resolve().into();
let resolved_block_advance = effective_block_advance.resolve();
let mut block_end_position = block_start_position + resolved_block_advance;
if let Some(sequential_layout_state) = self.sequential_layout_state.as_mut() {
// This amount includes both the block size of the line and any extra space
@ -942,7 +942,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
justification_adjustment,
line_metrics: &LineMetrics {
block_offset: block_start_position.into(),
block_size: effective_block_advance.resolve(),
block_size: effective_block_advance.resolve().into(),
baseline_block_offset: baseline_offset,
},
};
@ -973,11 +973,11 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
// the inline start of the line in `calculate_inline_start_for_current_line` so
// we do not need to include it in the `start_corner` of the line's main Fragment.
start_corner: LogicalVec2 {
inline: Length::zero(),
block: block_start_position.into(),
inline: Au::zero(),
block: block_start_position,
},
size: LogicalVec2 {
inline: self.containing_block.inline_size.into(),
inline: self.containing_block.inline_size,
block: effective_block_advance.resolve(),
},
};
@ -1134,8 +1134,8 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
let margin_box = float_item
.fragment
.border_rect()
.inflate(&float_item.fragment.margin.map(|t| (*t).into()));
let inline_size = margin_box.size.inline.max(Length::zero());
.inflate(&float_item.fragment.margin);
let inline_size = margin_box.size.inline.max(Au::zero());
let available_inline_size = match self.current_line.placement_among_floats.get() {
Some(placement_among_floats) => placement_among_floats.size.inline,
@ -1148,7 +1148,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
// parenting in their stacking contexts). Once all the line content is gathered we
// will place them later.
let has_content = self.current_line.has_content || self.current_line_segment.has_content;
let fits_on_line = !has_content || inline_size <= available_inline_size;
let fits_on_line = !has_content || inline_size <= available_inline_size.into();
let needs_placement_later =
self.current_line.has_floats_waiting_to_be_placed || !fits_on_line;
@ -1165,7 +1165,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
// start position.
let new_placement = self.place_line_among_floats(&LogicalVec2 {
inline: line_inline_size_without_trailing_whitespace,
block: self.current_line.max_block_size.resolve(),
block: self.current_line.max_block_size.resolve().into(),
});
self.current_line
.replace_placement_among_floats(new_placement);
@ -1472,7 +1472,8 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
block: self
.current_line_max_block_size_including_nested_containers()
.max(&self.current_line_segment.max_block_size)
.resolve(),
.resolve()
.into(),
};
if self.new_potential_line_size_causes_line_break(&potential_line_size) {
@ -1520,7 +1521,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
if self.current_line.line_items.is_empty() {
let will_break = self.new_potential_line_size_causes_line_break(&LogicalVec2 {
inline: line_inline_size_without_trailing_whitespace,
block: self.current_line_segment.max_block_size.resolve(),
block: self.current_line_segment.max_block_size.resolve().into(),
});
assert!(!will_break);
}
@ -1938,13 +1939,13 @@ impl InlineContainerState {
block_size
.resolve()
.scale_by(FONT_SUBSCRIPT_OFFSET_RATIO)
.px(),
.to_f32_px(),
),
VerticalAlign::Keyword(VerticalAlignKeyword::Super) => -Au::from_f32_px(
block_size
.resolve()
.scale_by(FONT_SUPERSCRIPT_OFFSET_RATIO)
.px(),
.to_f32_px(),
),
VerticalAlign::Keyword(VerticalAlignKeyword::TextTop) => {
child_block_size.size_for_baseline_positioning.ascent - self.font_metrics.ascent
@ -2047,7 +2048,7 @@ impl IndependentFormattingContext {
replaced.base_fragment_info,
replaced.style.clone(),
fragments,
content_rect.into(),
content_rect,
pbm.padding,
pbm.border,
margin,
@ -2136,7 +2137,7 @@ impl IndependentFormattingContext {
non_replaced.base_fragment_info,
non_replaced.style.clone(),
independent_layout.fragments,
content_rect.into(),
content_rect,
pbm.padding,
pbm.border,
margin,
@ -2155,22 +2156,22 @@ impl IndependentFormattingContext {
ifc.process_soft_wrap_opportunity();
}
let size = &pbm_sums.sum().into() + &fragment.content_rect.size;
let size = &pbm_sums.sum() + &fragment.content_rect.size;
let baseline_offset = self
.pick_baseline(&fragment.baselines)
.map(|baseline| pbm_sums.block_start + baseline)
.unwrap_or(size.block.into());
.unwrap_or(size.block);
let (block_sizes, baseline_offset_in_parent) =
self.get_block_sizes_and_baseline_offset(ifc, size.block, baseline_offset);
self.get_block_sizes_and_baseline_offset(ifc, size.block.into(), baseline_offset);
ifc.update_unbreakable_segment_for_new_content(
&block_sizes,
size.inline,
size.inline.into(),
SegmentContentFlags::empty(),
);
ifc.push_line_item_to_unbreakable_segment(LineItem::Atomic(AtomicLineItem {
fragment,
size,
size: size.into(),
positioning_context: child_positioning_context,
baseline_offset_in_parent,
baseline_offset_in_item: baseline_offset,

View file

@ -244,10 +244,10 @@ impl OutsideMarker {
let max_inline_size = flow_layout.fragments.iter().fold(
Length::zero(),
|current_max, fragment| match fragment {
Fragment::Text(text) => current_max.max(text.rect.max_inline_position()),
Fragment::Image(image) => current_max.max(image.rect.max_inline_position()),
Fragment::Text(text) => current_max.max(text.rect.max_inline_position().into()),
Fragment::Image(image) => current_max.max(image.rect.max_inline_position().into()),
Fragment::Positioning(positioning) => {
current_max.max(positioning.rect.max_inline_position())
current_max.max(positioning.rect.max_inline_position().into())
},
Fragment::Box(_) |
Fragment::Float(_) |
@ -286,7 +286,7 @@ impl OutsideMarker {
base_fragment_info,
self.marker_style.clone(),
flow_layout.fragments,
content_rect,
content_rect.into(),
LogicalSides::zero(),
LogicalSides::zero(),
LogicalSides::zero(),
@ -910,7 +910,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
base_fragment_info,
style.clone(),
flow_layout.fragments,
content_rect.into(),
content_rect,
pbm.padding,
pbm.border,
margin,
@ -996,7 +996,7 @@ impl NonReplacedFormattingContext {
self.base_fragment_info,
self.style.clone(),
layout.fragments,
content_rect.into(),
content_rect,
pbm.padding,
pbm.border,
margin,
@ -1248,7 +1248,7 @@ impl NonReplacedFormattingContext {
self.base_fragment_info,
self.style.clone(),
layout.fragments,
content_rect.into(),
content_rect,
pbm.padding,
pbm.border,
margin,
@ -1353,7 +1353,7 @@ fn layout_in_flow_replaced_block_level(
base_fragment_info,
style.clone(),
fragments,
content_rect.into(),
content_rect,
pbm.padding,
pbm.border,
margin,
@ -1668,7 +1668,7 @@ impl PlacementState {
return;
}
let box_block_offset = box_fragment.content_rect.start_corner.block.into();
let box_block_offset = box_fragment.content_rect.start_corner.block;
if let (None, Some(first)) = (self.inflow_baselines.first, box_fragment.baselines.first) {
self.inflow_baselines.first = Some(first + box_block_offset);
}
@ -1700,14 +1700,14 @@ impl PlacementState {
.contains(FragmentFlags::IS_OUTSIDE_LIST_ITEM_MARKER);
if is_outside_marker {
assert!(self.marker_block_size.is_none());
self.marker_block_size = Some(fragment.content_rect.size.block.into());
self.marker_block_size = Some(fragment.content_rect.size.block);
return;
}
let fragment_block_margins = &fragment.block_margins_collapsed_with_children;
let mut fragment_block_size = fragment.padding.block_sum() +
fragment.border.block_sum() +
fragment.content_rect.size.block.into();
fragment.content_rect.size.block;
// We use `last_in_flow_margin_collapses_with_parent_end_margin` to implement
// this quote from https://drafts.csswg.org/css2/#collapsing-margins
@ -1744,7 +1744,7 @@ impl PlacementState {
.adjoin_assign(&fragment_block_margins.start);
}
fragment.content_rect.start_corner.block +=
(self.current_margin.solve() + self.current_block_direction_position).into();
self.current_margin.solve() + self.current_block_direction_position;
if fragment_block_margins.collapsed_through {
// `fragment_block_size` is typically zero when collapsing through,

View file

@ -2,6 +2,7 @@
* 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 atomic_refcell::AtomicRef;
use script_layout_interface::wrapper_traits::{
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
@ -11,7 +12,7 @@ use serde::Serialize;
use servo_arc::Arc;
use style::dom::OpaqueNode;
use style::properties::ComputedValues;
use style::values::computed::{Length, Overflow};
use style::values::computed::Overflow;
use style_traits::CSSPixel;
use webrender_traits::display_list::ScrollSensitivity;
@ -306,12 +307,15 @@ impl BoxTree {
// https://drafts.csswg.org/css-writing-modes/#principal-flow
let physical_containing_block = PhysicalRect::new(
PhysicalPoint::zero(),
PhysicalSize::new(Length::new(viewport.width), Length::new(viewport.height)),
PhysicalSize::new(
Au::from_f32_px(viewport.width),
Au::from_f32_px(viewport.height),
),
);
let initial_containing_block = DefiniteContainingBlock {
size: LogicalVec2 {
inline: physical_containing_block.size.width.into(),
block: physical_containing_block.size.height.into(),
inline: physical_containing_block.size.width,
block: physical_containing_block.size.height,
},
style,
};