mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Introduce CSSPixelLength and update NonNegativeLength.
First, we define computed::CSSPixelLength which contains a CSSFloat, a pixel value, and then we replace computed::Length with CSSPixelLength. Therefore, the |ComputedValue| of NoCalcLength, AbsoluteLength, FontRelativeLength, ViewportPercentageLength, CharacterWidth, and PhysicalLength is CSSPixelLength. Besides, we drop NonNegativeAu, and replace computed::NonNegativeLength with NonNegative<computed::Length>. (i.e. NonNegative<CSSPixelLength>)
This commit is contained in:
parent
cad3aff508
commit
a949e2a057
40 changed files with 502 additions and 406 deletions
|
@ -14,7 +14,6 @@
|
|||
#![deny(unsafe_code)]
|
||||
|
||||
use ServoArc;
|
||||
use app_units::Au;
|
||||
use block::BlockFlow;
|
||||
use context::{LayoutContext, with_thread_local_font_context};
|
||||
use data::{HAS_NEWLY_CONSTRUCTED_FLOW, LayoutData};
|
||||
|
@ -1852,10 +1851,10 @@ impl ComputedValueUtils for ComputedValues {
|
|||
!padding.padding_right.is_definitely_zero() ||
|
||||
!padding.padding_bottom.is_definitely_zero() ||
|
||||
!padding.padding_left.is_definitely_zero() ||
|
||||
border.border_top_width.0 != Au(0) ||
|
||||
border.border_right_width.0 != Au(0) ||
|
||||
border.border_bottom_width.0 != Au(0) ||
|
||||
border.border_left_width.0 != Au(0)
|
||||
border.border_top_width.px() != 0. ||
|
||||
border.border_right_width.px() != 0. ||
|
||||
border.border_bottom_width.px() != 0. ||
|
||||
border.border_left_width.px() != 0.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1325,6 +1325,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
center.vertical.to_used_value(bounds.size.height));
|
||||
let radius = match *shape {
|
||||
GenericEndingShape::Circle(Circle::Radius(length)) => {
|
||||
let length = Au::from(length);
|
||||
Size2D::new(length, length)
|
||||
},
|
||||
GenericEndingShape::Circle(Circle::Extent(extent)) => {
|
||||
|
@ -1409,11 +1410,11 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
for box_shadow in style.get_effects().box_shadow.0.iter().rev() {
|
||||
let bounds = shadow_bounds(
|
||||
&absolute_bounds.translate(&Vector2D::new(
|
||||
box_shadow.base.horizontal,
|
||||
box_shadow.base.vertical,
|
||||
Au::from(box_shadow.base.horizontal),
|
||||
Au::from(box_shadow.base.vertical),
|
||||
)),
|
||||
box_shadow.base.blur.0,
|
||||
box_shadow.spread,
|
||||
Au::from(box_shadow.base.blur),
|
||||
Au::from(box_shadow.spread),
|
||||
);
|
||||
|
||||
// TODO(pcwalton): Multiple border radii; elliptical border radii.
|
||||
|
@ -1426,9 +1427,10 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
base: base,
|
||||
box_bounds: *absolute_bounds,
|
||||
color: box_shadow.base.color.unwrap_or(style.get_color().color).to_gfx_color(),
|
||||
offset: Vector2D::new(box_shadow.base.horizontal, box_shadow.base.vertical),
|
||||
blur_radius: box_shadow.base.blur.0,
|
||||
spread_radius: box_shadow.spread,
|
||||
offset: Vector2D::new(Au::from(box_shadow.base.horizontal),
|
||||
Au::from(box_shadow.base.vertical)),
|
||||
blur_radius: Au::from(box_shadow.base.blur),
|
||||
spread_radius: Au::from(box_shadow.spread),
|
||||
border_radius: model::specified_border_radius(style.get_border()
|
||||
.border_top_left_radius,
|
||||
absolute_bounds.size).width,
|
||||
|
@ -1596,7 +1598,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
clip: &Rect<Au>) {
|
||||
use style::values::Either;
|
||||
|
||||
let width = style.get_outline().outline_width.0;
|
||||
let width = Au::from(style.get_outline().outline_width);
|
||||
if width == Au(0) {
|
||||
return
|
||||
}
|
||||
|
@ -1610,7 +1612,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
// Outlines are not accounted for in the dimensions of the border box, so adjust the
|
||||
// absolute bounds.
|
||||
let mut bounds = *bounds;
|
||||
let offset = width + style.get_outline().outline_offset;
|
||||
let offset = width + Au::from(style.get_outline().outline_offset);
|
||||
bounds.origin.x = bounds.origin.x - offset;
|
||||
bounds.origin.y = bounds.origin.y - offset;
|
||||
bounds.size.width = bounds.size.width + offset + offset;
|
||||
|
@ -2139,8 +2141,8 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
for shadow in text_shadows.iter().rev() {
|
||||
state.add_display_item(DisplayItem::PushTextShadow(box PushTextShadowDisplayItem {
|
||||
base: base.clone(),
|
||||
blur_radius: shadow.blur.0,
|
||||
offset: Vector2D::new(shadow.horizontal, shadow.vertical),
|
||||
blur_radius: Au::from(shadow.blur),
|
||||
offset: Vector2D::new(Au::from(shadow.horizontal), Au::from(shadow.vertical)),
|
||||
color: shadow.color.unwrap_or(self.style().get_color().color).to_gfx_color(),
|
||||
}));
|
||||
}
|
||||
|
@ -2690,11 +2692,13 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
|
|||
}
|
||||
|
||||
let clip_origin = Point2D::new(stacking_relative_border_box.origin.x +
|
||||
style_clip_rect.left.unwrap_or(Au(0)),
|
||||
style_clip_rect.left.map(Au::from).unwrap_or(Au(0)),
|
||||
stacking_relative_border_box.origin.y +
|
||||
style_clip_rect.top.unwrap_or(Au(0)));
|
||||
let right = style_clip_rect.right.unwrap_or(stacking_relative_border_box.size.width);
|
||||
let bottom = style_clip_rect.bottom.unwrap_or(stacking_relative_border_box.size.height);
|
||||
style_clip_rect.top.map(Au::from).unwrap_or(Au(0)));
|
||||
let right = style_clip_rect.right.map(Au::from)
|
||||
.unwrap_or(stacking_relative_border_box.size.width);
|
||||
let bottom = style_clip_rect.bottom.map(Au::from)
|
||||
.unwrap_or(stacking_relative_border_box.size.height);
|
||||
let clip_size = Size2D::new(right - clip_origin.x, bottom - clip_origin.y);
|
||||
|
||||
// We use the node id to create scroll roots for overflow properties, so we
|
||||
|
|
|
@ -2574,14 +2574,16 @@ impl Fragment {
|
|||
|
||||
// Box shadows cause us to draw outside our border box.
|
||||
for box_shadow in &self.style().get_effects().box_shadow.0 {
|
||||
let offset = Vector2D::new(box_shadow.base.horizontal, box_shadow.base.vertical);
|
||||
let inflation = box_shadow.spread + box_shadow.base.blur.0 * BLUR_INFLATION_FACTOR;
|
||||
let offset = Vector2D::new(Au::from(box_shadow.base.horizontal),
|
||||
Au::from(box_shadow.base.vertical));
|
||||
let inflation = Au::from(box_shadow.spread) +
|
||||
Au::from(box_shadow.base.blur) * BLUR_INFLATION_FACTOR;
|
||||
overflow.paint = overflow.paint.union(&border_box.translate(&offset)
|
||||
.inflate(inflation, inflation))
|
||||
}
|
||||
|
||||
// Outlines cause us to draw outside our border box.
|
||||
let outline_width = self.style.get_outline().outline_width.0;
|
||||
let outline_width = Au::from(self.style.get_outline().outline_width);
|
||||
if outline_width != Au(0) {
|
||||
overflow.paint = overflow.paint.union(&border_box.inflate(outline_width,
|
||||
outline_width))
|
||||
|
@ -2880,7 +2882,7 @@ impl Fragment {
|
|||
transform_origin.vertical
|
||||
.to_used_value(stacking_relative_border_box.size.height)
|
||||
.to_f32_px();
|
||||
let transform_origin_z = transform_origin.depth.to_f32_px();
|
||||
let transform_origin_z = transform_origin.depth.px();
|
||||
|
||||
let pre_transform = Transform3D::create_translation(transform_origin_x,
|
||||
transform_origin_y,
|
||||
|
@ -2913,7 +2915,7 @@ impl Fragment {
|
|||
-perspective_origin.y,
|
||||
0.0);
|
||||
|
||||
let perspective_matrix = TransformList::create_perspective_matrix(length);
|
||||
let perspective_matrix = TransformList::create_perspective_matrix(length.px());
|
||||
|
||||
Some(pre_transform.pre_mul(&perspective_matrix).pre_mul(&post_transform))
|
||||
}
|
||||
|
|
|
@ -97,15 +97,16 @@ impl Flow for MulticolFlow {
|
|||
{
|
||||
let column_style = self.block_flow.fragment.style.get_column();
|
||||
|
||||
let column_gap = match column_style.column_gap {
|
||||
Either::First(len) => len.0,
|
||||
Either::Second(_normal) => self.block_flow.fragment.style.get_font().font_size.0,
|
||||
};
|
||||
let column_gap = Au::from(match column_style.column_gap {
|
||||
Either::First(len) => len,
|
||||
Either::Second(_normal) => self.block_flow.fragment.style.get_font().font_size,
|
||||
});
|
||||
|
||||
let mut column_count;
|
||||
if let Either::First(column_width) = column_style.column_width {
|
||||
let column_width = Au::from(column_width);
|
||||
column_count =
|
||||
max(1, (content_inline_size + column_gap).0 / (column_width.0 + column_gap).0);
|
||||
max(1, (content_inline_size + column_gap).0 / (column_width + column_gap).0);
|
||||
if let Either::First(specified_column_count) = column_style.column_count {
|
||||
column_count = min(column_count, specified_column_count.0 as i32);
|
||||
}
|
||||
|
|
|
@ -450,10 +450,14 @@ impl FragmentBorderBoxIterator for FragmentLocatingFragmentIterator {
|
|||
border_left_width: left_width,
|
||||
..
|
||||
} = *fragment.style.get_border();
|
||||
self.client_rect.origin.y = top_width.0.to_px();
|
||||
self.client_rect.origin.x = left_width.0.to_px();
|
||||
self.client_rect.size.width = (border_box.size.width - left_width.0 - right_width.0).to_px();
|
||||
self.client_rect.size.height = (border_box.size.height - top_width.0 - bottom_width.0).to_px();
|
||||
let (left_width, right_width) = (left_width.px(), right_width.px());
|
||||
let (top_width, bottom_width) = (top_width.px(), bottom_width.px());
|
||||
self.client_rect.origin.y = top_width as i32;
|
||||
self.client_rect.origin.x = left_width as i32;
|
||||
self.client_rect.size.width =
|
||||
(border_box.size.width.to_f32_px() - left_width - right_width) as i32;
|
||||
self.client_rect.size.height =
|
||||
(border_box.size.height.to_f32_px() - top_width - bottom_width) as i32;
|
||||
}
|
||||
|
||||
fn should_process(&mut self, fragment: &Fragment) -> bool {
|
||||
|
@ -476,10 +480,12 @@ impl FragmentBorderBoxIterator for UnioningFragmentScrollAreaIterator {
|
|||
border_left_width: left_border,
|
||||
..
|
||||
} = *fragment.style.get_border();
|
||||
let right_padding = (border_box.size.width - right_border.0 - left_border.0).to_px();
|
||||
let bottom_padding = (border_box.size.height - bottom_border.0 - top_border.0).to_px();
|
||||
let top_padding = top_border.0.to_px();
|
||||
let left_padding = left_border.0.to_px();
|
||||
let (left_border, right_border) = (left_border.px(), right_border.px());
|
||||
let (top_border, bottom_border) = (top_border.px(), bottom_border.px());
|
||||
let right_padding = (border_box.size.width.to_f32_px() - right_border - left_border) as i32;
|
||||
let bottom_padding = (border_box.size.height.to_f32_px() - bottom_border - top_border) as i32;
|
||||
let top_padding = top_border as i32;
|
||||
let left_padding = left_border as i32;
|
||||
|
||||
match self.level {
|
||||
Some(start_level) if level <= start_level => { self.is_child = false; }
|
||||
|
|
|
@ -28,7 +28,7 @@ use style::logical_geometry::LogicalSize;
|
|||
use style::properties::ComputedValues;
|
||||
use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW};
|
||||
use style::values::CSSFloat;
|
||||
use style::values::computed::{LengthOrPercentageOrAuto, NonNegativeAu};
|
||||
use style::values::computed::{LengthOrPercentageOrAuto, NonNegativeLength};
|
||||
use table_row::{self, CellIntrinsicInlineSize, CollapsedBorder, CollapsedBorderProvenance};
|
||||
use table_row::TableRowFlow;
|
||||
use table_wrapper::TableLayout;
|
||||
|
@ -191,8 +191,8 @@ impl TableFlow {
|
|||
border_collapse::T::separate => style.get_inheritedtable().border_spacing,
|
||||
border_collapse::T::collapse => {
|
||||
border_spacing::T {
|
||||
horizontal: NonNegativeAu::zero(),
|
||||
vertical: NonNegativeAu::zero(),
|
||||
horizontal: NonNegativeLength::zero(),
|
||||
vertical: NonNegativeLength::zero(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ impl TableFlow {
|
|||
if num_columns == 0 {
|
||||
return Au(0);
|
||||
}
|
||||
self.spacing().horizontal.0 * (num_columns as i32 + 1)
|
||||
Au::from(self.spacing().horizontal) * (num_columns as i32 + 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -471,7 +471,7 @@ impl Flow for TableFlow {
|
|||
fn assign_block_size(&mut self, _: &LayoutContext) {
|
||||
debug!("assign_block_size: assigning block_size for table");
|
||||
let vertical_spacing = self.spacing().vertical.0;
|
||||
self.block_flow.assign_block_size_for_table_like_flow(vertical_spacing)
|
||||
self.block_flow.assign_block_size_for_table_like_flow(Au::from(vertical_spacing))
|
||||
}
|
||||
|
||||
fn compute_stacking_relative_position(&mut self, layout_context: &LayoutContext) {
|
||||
|
|
|
@ -26,7 +26,7 @@ use style::computed_values::{border_collapse, border_spacing, border_top_style};
|
|||
use style::logical_geometry::{LogicalSize, PhysicalSide, WritingMode};
|
||||
use style::properties::ComputedValues;
|
||||
use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW};
|
||||
use style::values::computed::{Color, LengthOrPercentageOrAuto, NonNegativeAu};
|
||||
use style::values::computed::{Color, LengthOrPercentageOrAuto, NonNegativeLength};
|
||||
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt};
|
||||
use table_cell::{CollapsedBordersForCell, TableCellFlow};
|
||||
|
||||
|
@ -94,8 +94,8 @@ impl TableRowFlow {
|
|||
column_computed_inline_sizes: Vec::new(),
|
||||
incoming_rowspan: Vec::new(),
|
||||
spacing: border_spacing::T {
|
||||
horizontal: NonNegativeAu::zero(),
|
||||
vertical: NonNegativeAu::zero(),
|
||||
horizontal: NonNegativeLength::zero(),
|
||||
vertical: NonNegativeLength::zero(),
|
||||
},
|
||||
table_writing_mode: writing_mode,
|
||||
preliminary_collapsed_borders: CollapsedBordersForRow::new(),
|
||||
|
@ -396,7 +396,7 @@ impl Flow for TableRowFlow {
|
|||
None => break,
|
||||
};
|
||||
column_computed_inline_size.size = column_computed_inline_size.size +
|
||||
extra_column_computed_inline_size.size + self.spacing.horizontal.0;
|
||||
extra_column_computed_inline_size.size + Au::from(self.spacing.horizontal);
|
||||
col += 1;
|
||||
}
|
||||
|
||||
|
@ -625,7 +625,7 @@ impl CollapsedBorder {
|
|||
-> CollapsedBorder {
|
||||
CollapsedBorder {
|
||||
style: css_style.get_border().border_top_style,
|
||||
width: css_style.get_border().border_top_width.0,
|
||||
width: Au::from(css_style.get_border().border_top_width),
|
||||
color: css_style.get_border().border_top_color,
|
||||
provenance: provenance,
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ impl CollapsedBorder {
|
|||
-> CollapsedBorder {
|
||||
CollapsedBorder {
|
||||
style: css_style.get_border().border_right_style,
|
||||
width: css_style.get_border().border_right_width.0,
|
||||
width: Au::from(css_style.get_border().border_right_width),
|
||||
color: css_style.get_border().border_right_color,
|
||||
provenance: provenance,
|
||||
}
|
||||
|
@ -649,7 +649,7 @@ impl CollapsedBorder {
|
|||
-> CollapsedBorder {
|
||||
CollapsedBorder {
|
||||
style: css_style.get_border().border_bottom_style,
|
||||
width: css_style.get_border().border_bottom_width.0,
|
||||
width: Au::from(css_style.get_border().border_bottom_width),
|
||||
color: css_style.get_border().border_bottom_color,
|
||||
provenance: provenance,
|
||||
}
|
||||
|
@ -661,7 +661,7 @@ impl CollapsedBorder {
|
|||
-> CollapsedBorder {
|
||||
CollapsedBorder {
|
||||
style: css_style.get_border().border_left_style,
|
||||
width: css_style.get_border().border_left_width.0,
|
||||
width: Au::from(css_style.get_border().border_left_width),
|
||||
color: css_style.get_border().border_left_color,
|
||||
provenance: provenance,
|
||||
}
|
||||
|
@ -827,7 +827,7 @@ fn set_inline_position_of_child_flow(
|
|||
let column_inline_size = column_computed_inline_sizes[*column_index].size;
|
||||
let border_inline_size = match *border_collapse_info {
|
||||
Some(_) => Au(0), // FIXME: Make collapsed borders account for colspan/rowspan.
|
||||
None => border_spacing.horizontal.0,
|
||||
None => Au::from(border_spacing.horizontal),
|
||||
};
|
||||
if reverse_column_order {
|
||||
*inline_end_margin_edge += column_inline_size + border_inline_size;
|
||||
|
@ -882,9 +882,9 @@ fn set_inline_position_of_child_flow(
|
|||
None => {
|
||||
// Take spacing into account.
|
||||
if reverse_column_order {
|
||||
*inline_end_margin_edge += border_spacing.horizontal.0;
|
||||
*inline_end_margin_edge += Au::from(border_spacing.horizontal);
|
||||
} else {
|
||||
*inline_start_margin_edge += border_spacing.horizontal.0;
|
||||
*inline_start_margin_edge += Au::from(border_spacing.horizontal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use std::iter::{IntoIterator, Iterator, Peekable};
|
|||
use style::computed_values::{border_collapse, border_spacing};
|
||||
use style::logical_geometry::LogicalSize;
|
||||
use style::properties::ComputedValues;
|
||||
use style::values::computed::NonNegativeAu;
|
||||
use style::values::computed::NonNegativeLength;
|
||||
use table::{ColumnIntrinsicInlineSize, InternalTable, TableLikeFlow};
|
||||
|
||||
/// A table formatting context.
|
||||
|
@ -57,8 +57,8 @@ impl TableRowGroupFlow {
|
|||
block_flow: BlockFlow::from_fragment(fragment),
|
||||
column_intrinsic_inline_sizes: Vec::new(),
|
||||
spacing: border_spacing::T {
|
||||
horizontal: NonNegativeAu::zero(),
|
||||
vertical: NonNegativeAu::zero(),
|
||||
horizontal: NonNegativeLength::zero(),
|
||||
vertical: NonNegativeLength::zero(),
|
||||
},
|
||||
collapsed_inline_direction_border_widths_for_table: Vec::new(),
|
||||
collapsed_block_direction_border_widths_for_table: Vec::new(),
|
||||
|
@ -163,7 +163,7 @@ impl Flow for TableRowGroupFlow {
|
|||
|
||||
fn assign_block_size(&mut self, _: &LayoutContext) {
|
||||
debug!("assign_block_size: assigning block_size for table_rowgroup");
|
||||
self.block_flow.assign_block_size_for_table_like_flow(self.spacing.vertical.0)
|
||||
self.block_flow.assign_block_size_for_table_like_flow(Au::from(self.spacing.vertical))
|
||||
}
|
||||
|
||||
fn compute_stacking_relative_position(&mut self, layout_context: &LayoutContext) {
|
||||
|
|
|
@ -289,9 +289,10 @@ impl TextRunScanner {
|
|||
// example, `finally` with a wide `letter-spacing` renders as `f i n a l l y` and not
|
||||
// `fi n a l l y`.
|
||||
let mut flags = ShapingFlags::empty();
|
||||
match letter_spacing.value() {
|
||||
Some(&Au(0)) | None => {}
|
||||
Some(_) => flags.insert(IGNORE_LIGATURES_SHAPING_FLAG),
|
||||
if let Some(v) = letter_spacing.value() {
|
||||
if v.px() != 0. {
|
||||
flags.insert(IGNORE_LIGATURES_SHAPING_FLAG);
|
||||
}
|
||||
}
|
||||
if text_rendering == text_rendering::T::optimizespeed {
|
||||
flags.insert(IGNORE_LIGATURES_SHAPING_FLAG);
|
||||
|
@ -301,7 +302,7 @@ impl TextRunScanner {
|
|||
flags.insert(KEEP_ALL_FLAG);
|
||||
}
|
||||
let options = ShapingOptions {
|
||||
letter_spacing: letter_spacing.value().cloned(),
|
||||
letter_spacing: letter_spacing.value().cloned().map(Au::from),
|
||||
word_spacing: word_spacing,
|
||||
script: Script::Common,
|
||||
flags: flags,
|
||||
|
@ -446,11 +447,11 @@ pub fn font_metrics_for_style(font_context: &mut FontContext, font_style: ::Serv
|
|||
|
||||
/// Returns the line block-size needed by the given computed style and font size.
|
||||
pub fn line_height_from_style(style: &ComputedValues, metrics: &FontMetrics) -> Au {
|
||||
let font_size = style.get_font().font_size.0;
|
||||
let font_size = Au::from(style.get_font().font_size);
|
||||
match style.get_inheritedtext().line_height {
|
||||
LineHeight::Normal => metrics.line_gap,
|
||||
LineHeight::Normal => Au::from(metrics.line_gap),
|
||||
LineHeight::Number(l) => font_size.scale_by(l.0),
|
||||
LineHeight::Length(l) => l.0
|
||||
LineHeight::Length(l) => Au::from(l)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ impl ToFilterOps for Vec<Filter> {
|
|||
let mut result = Vec::with_capacity(self.len());
|
||||
for filter in self.iter() {
|
||||
match *filter {
|
||||
GenericFilter::Blur(radius) => result.push(webrender_api::FilterOp::Blur(radius.0.to_f32_px())),
|
||||
GenericFilter::Blur(radius) => result.push(webrender_api::FilterOp::Blur(radius.px())),
|
||||
GenericFilter::Brightness(amount) => result.push(webrender_api::FilterOp::Brightness(amount.0)),
|
||||
GenericFilter::Contrast(amount) => result.push(webrender_api::FilterOp::Contrast(amount.0)),
|
||||
GenericFilter::Grayscale(amount) => result.push(webrender_api::FilterOp::Grayscale(amount.0)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue