Auto merge of #5951 - SimonSapin:au-cleanup, r=mbrubeck

Fix #5943.

r? @mbrubeck

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5951)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-05-05 15:08:12 -05:00
commit 1721cf45ed
27 changed files with 190 additions and 248 deletions

View file

@ -933,7 +933,7 @@ impl BlockFlow {
if is_root {
let screen_size = LogicalSize::from_physical(self.fragment.style.writing_mode,
layout_context.shared.screen_size);
block_size = Au::max(screen_size.block, block_size)
block_size = max(screen_size.block, block_size)
}
if is_root || self.formatting_context_type() != FormattingContextType::None ||
@ -1478,11 +1478,11 @@ impl Flow for BlockFlow {
child_base.intrinsic_inline_sizes.minimum_inline_size);
if child_base.flags.contains(CLEARS_LEFT) {
left_float_width = Au::max(left_float_width, left_float_width_accumulator);
left_float_width = max(left_float_width, left_float_width_accumulator);
left_float_width_accumulator = Au(0)
}
if child_base.flags.contains(CLEARS_RIGHT) {
right_float_width = Au::max(right_float_width, right_float_width_accumulator);
right_float_width = max(right_float_width, right_float_width_accumulator);
right_float_width_accumulator = Au(0)
}
@ -1509,8 +1509,8 @@ impl Flow for BlockFlow {
// FIXME(pcwalton): This should consider all float descendants, not just children.
// FIXME(pcwalton): This is not well-spec'd; INTRINSIC specifies to do this, but CSS-SIZING
// says not to. In practice, Gecko and WebKit both do this.
left_float_width = Au::max(left_float_width, left_float_width_accumulator);
right_float_width = Au::max(right_float_width, right_float_width_accumulator);
left_float_width = max(left_float_width, left_float_width_accumulator);
right_float_width = max(right_float_width, right_float_width_accumulator);
computation.content_intrinsic_sizes.preferred_inline_size =
max(computation.content_intrinsic_sizes.preferred_inline_size,
left_float_width + right_float_width);

View file

@ -52,7 +52,7 @@ use style::values::computed::{Image, LinearGradient, LengthOrPercentage, LengthO
use style::values::specified::{AngleOrCorner, HorizontalDirection, VerticalDirection};
use url::Url;
use util::cursor::Cursor;
use util::geometry::{self, Au, ZERO_POINT, to_px, to_frac_px};
use util::geometry::{Au, ZERO_POINT};
use util::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode};
use util::opts;
@ -251,7 +251,7 @@ fn handle_overlapping_radii(size: &Size2D<Au>, radii: &BorderRadii<Au>) -> Borde
if required <= edge_length {
1.0
} else {
edge_length.to_frac32_px() / required.to_frac32_px()
edge_length.to_f32_px() / required.to_f32_px()
}
}
@ -352,18 +352,18 @@ impl FragmentDisplayListBuilding for Fragment {
// If `image_aspect_ratio` < `bounds_aspect_ratio`, the image is tall; otherwise, it is
// wide.
let image_aspect_ratio = (image.width as f64) / (image.height as f64);
let bounds_aspect_ratio = bounds.size.width.to_subpx() / bounds.size.height.to_subpx();
let intrinsic_size = Size2D(Au::from_px(image.width as isize),
Au::from_px(image.height as isize));
let bounds_aspect_ratio = bounds.size.width.to_f64_px() / bounds.size.height.to_f64_px();
let intrinsic_size = Size2D(Au::from_px(image.width as i32),
Au::from_px(image.height as i32));
match (style.get_background().background_size.clone(),
image_aspect_ratio < bounds_aspect_ratio) {
(background_size::T::Contain, false) | (background_size::T::Cover, true) => {
Size2D(bounds.size.width,
Au::from_frac_px(bounds.size.width.to_subpx() / image_aspect_ratio))
Au::from_f64_px(bounds.size.width.to_f64_px() / image_aspect_ratio))
}
(background_size::T::Contain, true) | (background_size::T::Cover, false) => {
Size2D(Au::from_frac_px(bounds.size.height.to_subpx() * image_aspect_ratio),
Size2D(Au::from_f64_px(bounds.size.height.to_f64_px() * image_aspect_ratio),
bounds.size.height)
}
@ -373,7 +373,7 @@ impl FragmentDisplayListBuilding for Fragment {
}), _) => {
let width = MaybeAuto::from_style(width, bounds.size.width)
.specified_or_default(intrinsic_size.width);
Size2D(width, Au::from_frac_px(width.to_subpx() / image_aspect_ratio))
Size2D(width, Au::from_f64_px(width.to_f64_px() / image_aspect_ratio))
}
(background_size::T::Explicit(background_size::ExplicitSize {
@ -382,7 +382,7 @@ impl FragmentDisplayListBuilding for Fragment {
}), _) => {
let height = MaybeAuto::from_style(height, bounds.size.height)
.specified_or_default(intrinsic_size.height);
Size2D(Au::from_frac_px(height.to_subpx() * image_aspect_ratio), height)
Size2D(Au::from_f64_px(height.to_f64_px() * image_aspect_ratio), height)
}
(background_size::T::Explicit(background_size::ExplicitSize {
@ -501,10 +501,10 @@ impl FragmentDisplayListBuilding for Fragment {
// between the starting point and the ending point.
let delta = match gradient.angle_or_corner {
AngleOrCorner::Angle(angle) => {
Point2D(Au::from_frac32_px(angle.radians().sin() *
absolute_bounds.size.width.to_frac32_px() / 2.0),
Au::from_frac32_px(-angle.radians().cos() *
absolute_bounds.size.height.to_frac32_px() / 2.0))
Point2D(Au::from_f32_px(angle.radians().sin() *
absolute_bounds.size.width.to_f32_px() / 2.0),
Au::from_f32_px(-angle.radians().cos() *
absolute_bounds.size.height.to_f32_px() / 2.0))
}
AngleOrCorner::Corner(horizontal, vertical) => {
let x_factor = match horizontal {
@ -521,8 +521,8 @@ impl FragmentDisplayListBuilding for Fragment {
};
// This is the length of the gradient line.
let length = Au::from_frac32_px(
(delta.x.to_frac32_px() * 2.0).hypot(delta.y.to_frac32_px() * 2.0));
let length = Au::from_f32_px(
(delta.x.to_f32_px() * 2.0).hypot(delta.y.to_f32_px() * 2.0));
// Determine the position of each stop per CSS-IMAGES § 3.4.
//
@ -1025,9 +1025,9 @@ impl FragmentDisplayListBuilding for Fragment {
}
SpecificFragmentInfo::Canvas(ref canvas_fragment_info) => {
let width = canvas_fragment_info.replaced_image_fragment_info
.computed_inline_size.map_or(0, |w| to_px(w) as usize);
.computed_inline_size.map_or(0, |w| w.to_px() as usize);
let height = canvas_fragment_info.replaced_image_fragment_info
.computed_block_size.map_or(0, |h| to_px(h) as usize);
.computed_block_size.map_or(0, |h| h.to_px() as usize);
let (sender, receiver) = channel::<Vec<u8>>();
let canvas_data = match canvas_fragment_info.renderer {
@ -1080,9 +1080,9 @@ impl FragmentDisplayListBuilding for Fragment {
let transform_origin = self.style().get_effects().transform_origin;
let transform_origin =
Point2D(model::specified(transform_origin.horizontal,
border_box.size.width).to_frac32_px(),
border_box.size.width).to_f32_px(),
model::specified(transform_origin.vertical,
border_box.size.height).to_frac32_px());
border_box.size.height).to_f32_px());
let transform = self.style().get_effects().transform
.unwrap_or(ComputedMatrix::identity()).to_gfx_matrix(&border_box.size);
@ -1117,10 +1117,10 @@ impl FragmentDisplayListBuilding for Fragment {
layout_context: &LayoutContext) {
let border_padding = (self.border_padding).to_physical(self.style.writing_mode);
let content_size = self.content_box().size.to_physical(self.style.writing_mode);
let iframe_rect = Rect(Point2D(geometry::to_frac_px(offset.x + border_padding.left) as f32,
geometry::to_frac_px(offset.y + border_padding.top) as f32),
Size2D(geometry::to_frac_px(content_size.width) as f32,
geometry::to_frac_px(content_size.height) as f32));
let iframe_rect = Rect(Point2D((offset.x + border_padding.left).to_f32_px(),
(offset.y + border_padding.top).to_f32_px()),
Size2D(content_size.width.to_f32_px(),
content_size.height.to_f32_px()));
debug!("finalizing position and size of iframe for {:?},{:?}",
iframe_fragment.pipeline_id,

View file

@ -47,7 +47,7 @@ use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::{LengthOrPercentageOrNone};
use text::TextRunScanner;
use url::Url;
use util::geometry::{self, Au, ZERO_POINT};
use util::geometry::{Au, ZERO_POINT};
use util::logical_geometry::{LogicalRect, LogicalSize, LogicalMargin, WritingMode};
use util::range::*;
use util::str::is_whitespace;
@ -213,9 +213,9 @@ fn clamp_size(size: Au,
let min_size = model::specified(min_size, container_inline_size);
let max_size = model::specified_or_none(max_size, container_inline_size);
Au::max(min_size, match max_size {
max(min_size, match max_size {
None => size,
Some(max_size) => Au::min(size, max_size),
Some(max_size) => min(size, max_size),
})
}
@ -271,8 +271,8 @@ impl CanvasFragmentInfo {
pub fn new(node: &ThreadSafeLayoutNode) -> CanvasFragmentInfo {
CanvasFragmentInfo {
replaced_image_fragment_info: ReplacedImageFragmentInfo::new(node,
Some(Au::from_px(node.get_canvas_width() as isize)),
Some(Au::from_px(node.get_canvas_height() as isize))),
Some(Au::from_px(node.get_canvas_width() as i32)),
Some(Au::from_px(node.get_canvas_height() as i32))),
renderer: node.get_renderer().map(|rec| Arc::new(Mutex::new(rec))),
}
}
@ -309,8 +309,8 @@ impl ImageFragmentInfo {
fn convert_length(node: &ThreadSafeLayoutNode, name: &Atom) -> Option<Au> {
let element = node.as_element();
element.get_attr(&ns!(""), name)
.and_then(|string| string.parse::<isize>().ok())
.map(|pixels| Au::from_px(pixels))
.and_then(|string| string.parse().ok())
.map(Au::from_px)
}
let image = url.and_then(|url| layout_context.get_or_request_image(url));
@ -331,7 +331,7 @@ impl ImageFragmentInfo {
image.height
} else {
image.width
} as isize)
} as i32)
}
None => Au(0)
}
@ -345,7 +345,7 @@ impl ImageFragmentInfo {
image.width
} else {
image.height
} as isize)
} as i32)
}
None => Au(0)
}
@ -354,8 +354,8 @@ impl ImageFragmentInfo {
/// Tile an image
pub fn tile_image(position: &mut Au, size: &mut Au,
virtual_position: Au, image_size: u32) {
let image_size = image_size as isize;
let delta_pixels = geometry::to_px(virtual_position - *position);
let image_size = image_size as i32;
let delta_pixels = (virtual_position - *position).to_px();
let tile_count = (delta_pixels + image_size - 1) / image_size;
let offset = Au::from_px(image_size * tile_count);
let new_position = virtual_position - offset;
@ -451,8 +451,8 @@ impl ReplacedImageFragmentInfo {
if intrinsic_height == Au(0) {
intrinsic_width
} else {
let ratio = intrinsic_width.to_frac32_px() /
intrinsic_height.to_frac32_px();
let ratio = intrinsic_width.to_f32_px() /
intrinsic_height.to_f32_px();
let specified_height = ReplacedImageFragmentInfo::style_length(
style_block_size,
@ -466,7 +466,7 @@ impl ReplacedImageFragmentInfo {
style_min_block_size,
style_max_block_size,
Au(0));
Au::from_frac32_px(specified_height.to_frac32_px() * ratio)
Au::from_f32_px(specified_height.to_f32_px() * ratio)
}
},
MaybeAuto::Specified(w) => w,
@ -503,8 +503,8 @@ impl ReplacedImageFragmentInfo {
MaybeAuto::Auto => {
let intrinsic_width = fragment_inline_size;
let intrinsic_height = fragment_block_size;
let scale = intrinsic_width.to_frac32_px() / inline_size.to_frac32_px();
Au::from_frac32_px(intrinsic_height.to_frac32_px() / scale)
let scale = intrinsic_width.to_f32_px() / inline_size.to_f32_px();
Au::from_f32_px(intrinsic_height.to_f32_px() / scale)
},
MaybeAuto::Specified(h) => {
h
@ -967,8 +967,8 @@ impl Fragment {
let flags = self.quantities_included_in_intrinsic_inline_size();
let style = self.style();
let specified = if flags.contains(INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED) {
Au::max(model::specified(style.min_inline_size(), Au(0)),
MaybeAuto::from_style(style.content_inline_size(), Au(0)).specified_or_zero())
max(model::specified(style.min_inline_size(), Au(0)),
MaybeAuto::from_style(style.content_inline_size(), Au(0)).specified_or_zero())
} else {
Au(0)
};

View file

@ -397,8 +397,8 @@ impl LineBreaker {
fn new_block_size_for_line(&self, new_fragment: &Fragment, layout_context: &LayoutContext)
-> Au {
Au::max(self.pending_line.bounds.size.block,
self.new_inline_metrics_for_line(new_fragment, layout_context).block_size())
max(self.pending_line.bounds.size.block,
self.new_inline_metrics_for_line(new_fragment, layout_context).block_size())
}
/// Computes the position of a line that has only the provided fragment. Returns the bounding
@ -966,7 +966,7 @@ impl InlineFlow {
}
// Then distribute all the space across the expansion opportunities.
let space_per_expansion_opportunity = slack_inline_size.to_subpx() /
let space_per_expansion_opportunity = slack_inline_size.to_f64_px() /
(expansion_opportunities as f64);
for fragment_index in line.range.each_index() {
let fragment = fragments.get_mut(fragment_index.to_usize());
@ -1589,10 +1589,10 @@ impl InlineMetrics {
pub fn max(&self, other: &InlineMetrics) -> InlineMetrics {
InlineMetrics {
block_size_above_baseline: Au::max(self.block_size_above_baseline,
other.block_size_above_baseline),
depth_below_baseline: Au::max(self.depth_below_baseline, other.depth_below_baseline),
ascent: Au::max(self.ascent, other.ascent),
block_size_above_baseline: max(self.block_size_above_baseline,
other.block_size_above_baseline),
depth_below_baseline: max(self.depth_below_baseline, other.depth_below_baseline),
ascent: max(self.ascent, other.ascent),
}
}
}

View file

@ -851,8 +851,8 @@ impl LayoutTask {
// http://www.w3.org/TR/css-device-adapt/#actual-viewport
let viewport_size = data.window_size.initial_viewport;
let old_screen_size = rw_data.screen_size;
let current_screen_size = Size2D(Au::from_frac32_px(viewport_size.width.get()),
Au::from_frac32_px(viewport_size.height.get()));
let current_screen_size = Size2D(Au::from_f32_px(viewport_size.width.get()),
Au::from_f32_px(viewport_size.height.get()));
rw_data.screen_size = current_screen_size;
// Handle conditions where the entire flow tree is invalid.
@ -1096,7 +1096,7 @@ impl LayoutRPC for LayoutRPCImpl {
/// Requests the node containing the point of interest.
fn hit_test(&self, _: TrustedNodeAddress, point: Point2D<f32>) -> Result<HitTestResponse, ()> {
let point = Point2D(Au::from_frac32_px(point.x), Au::from_frac32_px(point.y));
let point = Point2D(Au::from_f32_px(point.x), Au::from_f32_px(point.y));
let resp = {
let &LayoutRPCImpl(ref rw_data) = self;
let rw_data = rw_data.lock().unwrap();
@ -1123,7 +1123,7 @@ impl LayoutRPC for LayoutRPCImpl {
fn mouse_over(&self, _: TrustedNodeAddress, point: Point2D<f32>)
-> Result<MouseOverResponse, ()> {
let mut mouse_over_list: Vec<DisplayItemMetadata> = vec!();
let point = Point2D(Au::from_frac32_px(point.x), Au::from_frac32_px(point.y));
let point = Point2D(Au::from_f32_px(point.x), Au::from_f32_px(point.y));
{
let &LayoutRPCImpl(ref rw_data) = self;
let rw_data = rw_data.lock().unwrap();

View file

@ -434,8 +434,8 @@ impl ToGfxMatrix for ComputedMatrix {
self.m12 as f32,
self.m21 as f32,
self.m22 as f32,
self.m31.to_au(containing_size.width).to_frac32_px(),
self.m32.to_au(containing_size.height).to_frac32_px())
self.m31.to_au(containing_size.width).to_f32_px(),
self.m32.to_au(containing_size.height).to_f32_px())
}
}
@ -446,7 +446,7 @@ trait ToAu {
impl ToAu for LengthAndPercentage {
#[inline]
fn to_au(&self, containing_size: Au) -> Au {
self.length + Au::from_frac32_px(self.percentage * containing_size.to_frac32_px())
self.length + Au::from_f32_px(self.percentage * containing_size.to_f32_px())
}
}

View file

@ -430,8 +430,8 @@ impl Flow for TableFlow {
// if there are any, or among all the columns if all are specified.
self.column_computed_inline_sizes.clear();
if num_unspecified_inline_sizes == 0 {
let ratio = content_inline_size.to_frac32_px() /
total_column_inline_size.to_frac32_px();
let ratio = content_inline_size.to_f32_px() /
total_column_inline_size.to_f32_px();
for column_inline_size in self.column_intrinsic_inline_sizes.iter() {
self.column_computed_inline_sizes.push(ColumnComputedInlineSize {
size: column_inline_size.minimum_length.scale_by(ratio),

View file

@ -590,7 +590,7 @@ impl SelectedAutoLayoutCandidateGuess {
/// Computes the weight needed to linearly interpolate `middle` between two guesses `low` and
/// `high` as specified by INTRINSIC § 4.3.
fn weight(low: Au, middle: Au, high: Au) -> CSSFloat {
(middle - low).to_frac32_px() / (high - low).to_frac32_px()
(middle - low).to_f32_px() / (high - low).to_f32_px()
}
/// Linearly interpolates between two guesses, as specified by INTRINSIC § 4.3.
@ -653,9 +653,9 @@ impl ExcessInlineSizeDistributionInfo {
// do?
if !column_intrinsic_inline_size.constrained &&
column_intrinsic_inline_size.percentage == 0.0 {
column_intrinsic_inline_size.preferred.to_frac32_px() /
column_intrinsic_inline_size.preferred.to_f32_px() /
self.preferred_inline_size_of_nonconstrained_columns_with_no_percentage
.to_frac32_px()
.to_f32_px()
} else {
0.0
}
@ -663,8 +663,8 @@ impl ExcessInlineSizeDistributionInfo {
1.0 / (self.count_of_nonconstrained_columns_with_no_percentage as CSSFloat)
} else if self.preferred_inline_size_of_constrained_columns_with_no_percentage >
Au(0) {
column_intrinsic_inline_size.preferred.to_frac32_px() /
self.preferred_inline_size_of_constrained_columns_with_no_percentage.to_frac32_px()
column_intrinsic_inline_size.preferred.to_f32_px() /
self.preferred_inline_size_of_constrained_columns_with_no_percentage.to_f32_px()
} else if self.total_percentage > 0.0 {
column_intrinsic_inline_size.percentage / self.total_percentage
} else {
@ -695,11 +695,10 @@ fn initial_computed_inline_size(block: &mut BlockFlow,
containing_block_inline_size);
match inline_size_from_style {
MaybeAuto::Auto => {
MaybeAuto::Specified(Au::max(containing_block_inline_size,
minimum_width_of_all_columns))
MaybeAuto::Specified(max(containing_block_inline_size, minimum_width_of_all_columns))
}
MaybeAuto::Specified(inline_size_from_style) => {
MaybeAuto::Specified(Au::max(inline_size_from_style, minimum_width_of_all_columns))
MaybeAuto::Specified(max(inline_size_from_style, minimum_width_of_all_columns))
}
}
}