Skip to content

Commit

Permalink
Introduce CSSPixelLength and update NonNegativeLength.
Browse files Browse the repository at this point in the history
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>)
  • Loading branch information
BorisChiou committed Sep 13, 2017
1 parent cad3aff commit a949e2a
Show file tree
Hide file tree
Showing 40 changed files with 501 additions and 405 deletions.
10 changes: 5 additions & 5 deletions components/gfx/font_context.rs
Expand Up @@ -118,7 +118,7 @@ impl FontContext {

let layout_font_group_cache_key = LayoutFontGroupCacheKey {
pointer: style.clone(),
size: style.font_size.0,
size: Au::from(style.font_size),
};
if let Some(ref cached_font_group) = self.layout_font_group_cache.get(
&layout_font_group_cache_key) {
Expand Down Expand Up @@ -148,7 +148,7 @@ impl FontContext {
Some(ref cached_font_ref) => {
let cached_font = (*cached_font_ref).borrow();
if cached_font.descriptor == desc &&
cached_font.requested_pt_size == style.font_size.0 &&
cached_font.requested_pt_size == Au::from(style.font_size) &&
cached_font.variant == style.font_variant_caps {
fonts.push((*cached_font_ref).clone());
cache_hit = true;
Expand All @@ -166,7 +166,7 @@ impl FontContext {
Some(template_info) => {
let layout_font = self.create_layout_font(template_info.font_template,
desc.clone(),
style.font_size.0,
Au::from(style.font_size),
style.font_variant_caps,
template_info.font_key);
let font = match layout_font {
Expand Down Expand Up @@ -199,7 +199,7 @@ impl FontContext {
for cached_font_entry in &self.fallback_font_cache {
let cached_font = cached_font_entry.font.borrow();
if cached_font.descriptor == desc &&
cached_font.requested_pt_size == style.font_size.0 &&
cached_font.requested_pt_size == Au::from(style.font_size) &&
cached_font.variant == style.font_variant_caps {
fonts.push(cached_font_entry.font.clone());
cache_hit = true;
Expand All @@ -211,7 +211,7 @@ impl FontContext {
let template_info = self.font_cache_thread.last_resort_font_template(desc.clone());
let layout_font = self.create_layout_font(template_info.font_template,
desc.clone(),
style.font_size.0,
Au::from(style.font_size),
style.font_variant_caps,
template_info.font_key);
match layout_font {
Expand Down
9 changes: 4 additions & 5 deletions components/layout/construct.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
}
}

Expand Down
34 changes: 19 additions & 15 deletions components/layout/display_list_builder.rs
Expand Up @@ -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)) => {
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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;
Expand Down Expand Up @@ -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(),
}));
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions components/layout/fragment.rs
Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down
11 changes: 6 additions & 5 deletions components/layout/multicol.rs
Expand Up @@ -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);
}
Expand Down
22 changes: 14 additions & 8 deletions components/layout/query.rs
Expand Up @@ -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 {
Expand All @@ -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; }
Expand Down
10 changes: 5 additions & 5 deletions components/layout/table.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
}
}
}
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 11 additions & 11 deletions components/layout/table_row.rs
Expand Up @@ -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};

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit a949e2a

Please sign in to comment.