From 32d5e24922e47322bf67c100fa4c178bc9b430f4 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 5 May 2015 17:34:01 +0200 Subject: [PATCH 1/7] Replace Au-related free functions in util::geometry with Au methods. --- components/gfx/platform/freetype/font.rs | 11 +++-- components/gfx/platform/macos/font.rs | 4 +- components/gfx/text/text_run.rs | 4 +- components/layout/block.rs | 10 ++--- components/layout/display_list_builder.rs | 14 +++--- components/layout/fragment.rs | 12 +++--- components/layout/inline.rs | 12 +++--- components/layout/table_wrapper.rs | 5 +-- components/script/dom/htmlimageelement.rs | 5 +-- components/script/dom/window.rs | 8 ++-- components/script/script_task.rs | 5 +-- components/util/geometry.rs | 52 ++++------------------- 12 files changed, 50 insertions(+), 92 deletions(-) diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index 2d4b760294f..00b0e1f6c02 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -7,7 +7,6 @@ extern crate freetype; use font::{FontHandleMethods, FontMetrics, FontTableMethods}; use font::{FontTableTag, FractionalPixel}; use util::geometry::Au; -use util::geometry; use util::str::c_str_to_string; use platform::font_context::FontContextHandle; use text::glyph::GlyphId; @@ -225,9 +224,9 @@ impl FontHandleMethods for FontHandle { let height = self.font_units_to_au(face.height as f64); let leading = height - (ascent + descent); - let mut strikeout_size = geometry::from_pt(0.0); - let mut strikeout_offset = geometry::from_pt(0.0); - let mut x_height = geometry::from_pt(0.0); + let mut strikeout_size = Au(0); + let mut strikeout_offset = Au(0); + let mut x_height = Au(0); unsafe { let os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2) as *mut TT_OS2; let valid = !os2.is_null() && (*os2).version != 0xffff; @@ -258,7 +257,7 @@ impl FontHandleMethods for FontHandle { line_gap: height, }; - debug!("Font metrics (@{} pt): {:?}", geometry::to_pt(em_size), metrics); + debug!("Font metrics (@{}px): {:?}", em_size.to_frac32_px(), metrics); return metrics; } @@ -297,6 +296,6 @@ impl<'a> FontHandle { // If this isn't true then we're scaling one of the axes wrong assert!(metrics.x_ppem == metrics.y_ppem); - return geometry::from_frac_px(value * x_scale); + return Au::from_frac_px(value * x_scale); } } diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index 75115d287be..8f74f99dfbe 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -182,8 +182,8 @@ impl FontHandleMethods for FontHandle { // see also: https://bugs.webkit.org/show_bug.cgi?id=16768 // see also: https://bugreports.qt-project.org/browse/QTBUG-13364 underline_offset: Au::from_pt(self.ctfont.underline_position() as f64), - strikeout_size: geometry::from_pt(0.0), // FIXME(Issue #942) - strikeout_offset: geometry::from_pt(0.0), // FIXME(Issue #942) + strikeout_size: Au(0), // FIXME(Issue #942) + strikeout_offset: Au(0), // FIXME(Issue #942) leading: Au::from_pt(leading), x_height: Au::from_pt(self.ctfont.x_height() as f64), em_size: em_size, diff --git a/components/gfx/text/text_run.rs b/components/gfx/text/text_run.rs index 4e963bf1b28..20c1f8fb4da 100644 --- a/components/gfx/text/text_run.rs +++ b/components/gfx/text/text_run.rs @@ -8,7 +8,7 @@ use platform::font_template::FontTemplateData; use util::geometry::Au; use util::range::Range; use util::vec::{Comparator, FullBinarySearchMethods}; -use std::cmp::Ordering; +use std::cmp::{Ordering, max}; use std::slice::Iter; use std::sync::Arc; use text::glyph::{CharIndex, GlyphStore}; @@ -322,7 +322,7 @@ impl<'a> TextRun { debug!("iterating outer range {:?}", range); self.natural_word_slices_in_range(range).fold(Au(0), |max_piece_width, slice| { debug!("iterated on {:?}[{:?}]", slice.offset, slice.range); - Au::max(max_piece_width, self.advance_for_range(&slice.range)) + max(max_piece_width, self.advance_for_range(&slice.range)) }) } diff --git a/components/layout/block.rs b/components/layout/block.rs index b01a31804b2..718155f495b 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -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); diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index b82852e24e3..67ee428fd72 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -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; @@ -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::>(); let canvas_data = match canvas_fragment_info.renderer { @@ -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_frac32_px(), + (offset.y + border_padding.top).to_frac32_px()), + Size2D(content_size.width.to_frac32_px(), + content_size.height.to_frac32_px())); debug!("finalizing position and size of iframe for {:?},{:?}", iframe_fragment.pipeline_id, diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index ea090ea55ea..9063bc652d2 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -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), }) } @@ -355,7 +355,7 @@ impl ImageFragmentInfo { 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 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; @@ -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) }; diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 82a236ac001..17741e4eadd 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -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 @@ -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), } } } diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index 73e631e2e25..e7e2fd3e37f 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -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)) } } } diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 59c100465c0..760f5942aa0 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -21,7 +21,6 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{document_from_node, Node, NodeTypeId, NodeHelpers, NodeDamage, window_from_node}; use dom::virtualmethods::VirtualMethods; use dom::window::WindowHelpers; -use util::geometry::to_px; use util::str::DOMString; use string_cache::Atom; @@ -188,7 +187,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { fn Width(self) -> u32 { let node: JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); - to_px(rect.size.width) as u32 + rect.size.width.to_px() as u32 } fn SetWidth(self, width: u32) { @@ -199,7 +198,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { fn Height(self) -> u32 { let node: JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); - to_px(rect.size.height) as u32 + rect.size.height.to_px() as u32 } fn SetHeight(self, height: u32) { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 37d79625334..e49f6a1a50e 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -917,10 +917,10 @@ impl Window { } fn should_move_clip_rect(clip_rect: Rect, new_viewport: Rect) -> bool{ - let clip_rect = Rect(Point2D(geometry::to_frac_px(clip_rect.origin.x) as f32, - geometry::to_frac_px(clip_rect.origin.y) as f32), - Size2D(geometry::to_frac_px(clip_rect.size.width) as f32, - geometry::to_frac_px(clip_rect.size.height) as f32)); + let clip_rect = Rect(Point2D(clip_rect.origin.x.to_frac32_px(), + clip_rect.origin.y.to_frac32_px()), + Size2D(clip_rect.size.width.to_frac32_px(), + clip_rect.size.height.to_frac32_px())); // We only need to move the clip rect if the viewport is getting near the edge of // our preexisting clip rect. We use half of the size of the viewport as a heuristic diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 5e776d4db0f..355b9d01210 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -70,7 +70,6 @@ use net_traits::LoadData as NetLoadData; use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask, ImageCacheResult}; use net_traits::storage_task::StorageTask; use string_cache::Atom; -use util::geometry::to_frac_px; use util::str::DOMString; use util::task::{spawn_named, spawn_named_with_send_on_failure}; use util::task_state; @@ -85,7 +84,6 @@ use js::rust::{Runtime, RtUtils}; use url::Url; use libc; -use num::ToPrimitive; use std::any::Any; use std::borrow::ToOwned; use std::cell::{Cell, RefCell}; @@ -1182,8 +1180,7 @@ impl ScriptTask { fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: JSRef) { let node: JSRef = NodeCast::from_ref(node); let rect = node.get_bounding_content_box(); - let point = Point2D(to_frac_px(rect.origin.x).to_f32().unwrap(), - to_frac_px(rect.origin.y).to_f32().unwrap()); + let point = Point2D(rect.origin.x.to_frac32_px(), rect.origin.y.to_frac32_px()); // FIXME(#2003, pcwalton): This is pretty bogus when multiple layers are involved. // Really what needs to happen is that this needs to go through layout to ask which // layer the element belongs to, and have it send the scroll message to the diff --git a/components/util/geometry.rs b/components/util/geometry.rs index 5d7c69d0010..515529ad2f7 100644 --- a/components/util/geometry.rs +++ b/components/util/geometry.rs @@ -210,6 +210,13 @@ impl Au { Au((px.get() * 60f32) as i32) } + /// Rounds this app unit down to the pixel towards zero and returns it. + #[inline] + pub fn to_px(&self) -> isize { + let Au(a) = *self; + (a / 60) as isize + } + /// Rounds this app unit down to the previous (left or top) pixel and returns it. #[inline] pub fn to_prev_px(&self) -> isize { @@ -257,27 +264,13 @@ impl Au { #[inline] pub fn from_pt(pt: f64) -> Au { - from_frac_px(pt_to_px(pt)) + Au::from_frac_px(pt_to_px(pt)) } #[inline] pub fn from_frac_px(px: f64) -> Au { Au((px * 60.) as i32) } - - #[inline] - pub fn min(x: Au, y: Au) -> Au { - let Au(xi) = x; - let Au(yi) = y; - if xi < yi { x } else { y } - } - - #[inline] - pub fn max(x: Au, y: Au) -> Au { - let Au(xi) = x; - let Au(yi) = y; - if xi > yi { x } else { y } - } } // assumes 72 points per inch, and 96 px per inch @@ -290,35 +283,6 @@ pub fn px_to_pt(px: f64) -> f64 { px / 96. * 72. } -pub fn from_frac_px(px: f64) -> Au { - Au((px * 60.) as i32) -} - -pub fn from_px(px: isize) -> Au { - Au::from_px(px) -} - -pub fn to_px(au: Au) -> isize { - let Au(a) = au; - (a / 60) as isize -} - -pub fn to_frac_px(au: Au) -> f32 { - let Au(a) = au; - (a as f32) / 60. -} - -// assumes 72 points per inch, and 96 px per inch -pub fn from_pt(pt: f32) -> Au { - from_px((pt / 72. * 96.) as isize) -} - -// assumes 72 points per inch, and 96 px per inch -pub fn to_pt(au: Au) -> f32 { - let Au(a) = au; - (a as f32) / 60. * 72. / 96. -} - /// Returns true if the rect contains the given point. Points on the top or left sides of the rect /// are considered inside the rectangle, while points on the right or bottom sides of the rect are /// not considered inside the rectangle. From 8b522f2e7d08aaf73429207cbbfd9da915f6d9a5 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 5 May 2015 18:23:29 +0200 Subject: [PATCH 2/7] Rename Au methods with f32/f64 instead of frac32/frac/subpx --- components/gfx/display_list/mod.rs | 6 ++-- components/gfx/filters.rs | 2 +- components/gfx/font_context.rs | 4 +-- components/gfx/paint_context.rs | 30 +++++++++--------- components/gfx/paint_task.rs | 4 +-- components/gfx/platform/freetype/font.rs | 6 ++-- components/gfx/platform/macos/font.rs | 8 ++--- components/gfx/text/glyph.rs | 2 +- components/gfx/text/shaping/harfbuzz.rs | 12 ++++---- components/layout/display_list_builder.rs | 36 +++++++++++----------- components/layout/fragment.rs | 10 +++--- components/layout/inline.rs | 2 +- components/layout/layout_task.rs | 8 ++--- components/layout/model.rs | 6 ++-- components/layout/table.rs | 4 +-- components/layout/table_wrapper.rs | 10 +++--- components/script/dom/htmlanchorelement.rs | 4 +-- components/script/dom/window.rs | 8 ++--- components/script/script_task.rs | 2 +- components/style/media_queries.rs | 4 +-- components/style/properties.mako.rs | 4 +-- components/style/values.rs | 8 ++--- components/util/geometry.rs | 18 +++++------ 23 files changed, 99 insertions(+), 99 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index f3cf053daa8..40416ed9e8d 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -489,9 +489,9 @@ impl StackingContext { point = point - self.bounds.origin; debug_assert!(!topmost_only || result.is_empty()); - let frac_point = self.transform.transform_point(&Point2D(point.x.to_frac32_px(), - point.y.to_frac32_px())); - point = Point2D(Au::from_frac32_px(frac_point.x), Au::from_frac32_px(frac_point.y)); + let frac_point = self.transform.transform_point(&Point2D(point.x.to_f32_px(), + point.y.to_f32_px())); + point = Point2D(Au::from_f32_px(frac_point.x), Au::from_f32_px(frac_point.y)); // Iterate through display items in reverse stacking order. Steps here refer to the // painting steps in CSS 2.1 Appendix E. diff --git a/components/gfx/filters.rs b/components/gfx/filters.rs index 2882adfb323..38db24ec318 100644 --- a/components/gfx/filters.rs +++ b/components/gfx/filters.rs @@ -95,7 +95,7 @@ pub fn create_filters(draw_target: &DrawTarget, } filter::Filter::Blur(amount) => { *accumulated_blur_radius = accumulated_blur_radius.clone() + amount; - let amount = amount.to_frac32_px(); + let amount = amount.to_f32_px(); let blur = draw_target.create_filter(FilterType::GaussianBlur); blur.set_attribute(GaussianBlurAttribute::StdDeviation(amount)); blur.set_input(GaussianBlurInput, &filter); diff --git a/components/gfx/font_context.rs b/components/gfx/font_context.rs index b10a90c0fac..d02d798ca2c 100644 --- a/components/gfx/font_context.rs +++ b/components/gfx/font_context.rs @@ -36,13 +36,13 @@ use azure::scaled_font::FontInfo; #[cfg(any(target_os="linux", target_os = "android"))] fn create_scaled_font(template: &Arc, pt_size: Au) -> ScaledFont { ScaledFont::new(BackendType::Skia, FontInfo::FontData(&template.bytes), - pt_size.to_subpx() as AzFloat) + pt_size.to_f64_px() as AzFloat) } #[cfg(target_os="macos")] fn create_scaled_font(template: &Arc, pt_size: Au) -> ScaledFont { let cgfont = template.ctfont.as_ref().unwrap().copy_to_CGFont(); - ScaledFont::new(BackendType::Skia, &cgfont, pt_size.to_subpx() as AzFloat) + ScaledFont::new(BackendType::Skia, &cgfont, pt_size.to_f64_px() as AzFloat) } static SMALL_CAPS_SCALE_FACTOR: f32 = 0.8; // Matches FireFox (see gfxFont.h) diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 6130cc7a1f7..0aadd9c16b4 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -826,16 +826,16 @@ impl<'a> PaintContext<'a> { let baseline_origin = match text.orientation { Upright => text.baseline_origin, SidewaysLeft => { - let x = text.baseline_origin.x.to_subpx() as AzFloat; - let y = text.baseline_origin.y.to_subpx() as AzFloat; + let x = text.baseline_origin.x.to_f64_px() as AzFloat; + let y = text.baseline_origin.y.to_f64_px() as AzFloat; self.draw_target.set_transform(&draw_target_transform.mul(&Matrix2D::new(0., -1., 1., 0., x, y))); Point2D::zero() } SidewaysRight => { - let x = text.baseline_origin.x.to_subpx() as AzFloat; - let y = text.baseline_origin.y.to_subpx() as AzFloat; + let x = text.baseline_origin.x.to_f64_px() as AzFloat; + let y = text.baseline_origin.y.to_f64_px() as AzFloat; self.draw_target.set_transform(&draw_target_transform.mul(&Matrix2D::new(0., 1., -1., 0., x, y))); @@ -1060,7 +1060,7 @@ impl<'a> PaintContext<'a> { } let blur_filter = self.draw_target.create_filter(FilterType::GaussianBlur); - blur_filter.set_attribute(GaussianBlurAttribute::StdDeviation(blur_radius.to_subpx() as + blur_filter.set_attribute(GaussianBlurAttribute::StdDeviation(blur_radius.to_f64_px() as AzFloat)); blur_filter.set_input(GaussianBlurInput, &temporary_draw_target.draw_target.snapshot()); temporary_draw_target.draw_filter(&self.draw_target, blur_filter); @@ -1104,21 +1104,21 @@ impl<'a> PaintContext<'a> { pub trait ToAzurePoint { fn to_azure_point(&self) -> Point2D; - fn to_subpx_azure_point(&self) -> Point2D; + fn to_f64_px_azure_point(&self) -> Point2D; } impl ToAzurePoint for Point2D { fn to_azure_point(&self) -> Point2D { Point2D(self.x.to_nearest_px() as AzFloat, self.y.to_nearest_px() as AzFloat) } - fn to_subpx_azure_point(&self) -> Point2D { - Point2D(self.x.to_subpx() as AzFloat, self.y.to_subpx() as AzFloat) + fn to_f64_px_azure_point(&self) -> Point2D { + Point2D(self.x.to_f64_px() as AzFloat, self.y.to_f64_px() as AzFloat) } } pub trait ToAzureRect { fn to_azure_rect(&self) -> Rect; - fn to_subpx_azure_rect(&self) -> Rect; + fn to_f64_px_azure_rect(&self) -> Rect; } impl ToAzureRect for Rect { @@ -1127,9 +1127,9 @@ impl ToAzureRect for Rect { self.size.height.to_nearest_px() as AzFloat)) } - fn to_subpx_azure_rect(&self) -> Rect { - Rect(self.origin.to_subpx_azure_point(), Size2D(self.size.width.to_subpx() as AzFloat, - self.size.height.to_subpx() as AzFloat)) + fn to_f64_px_azure_rect(&self) -> Rect { + Rect(self.origin.to_f64_px_azure_point(), Size2D(self.size.width.to_f64_px() as AzFloat, + self.size.height.to_f64_px() as AzFloat)) } } @@ -1241,8 +1241,8 @@ impl ScaledFontExtensionMethods for ScaledFont { let azglyph = struct__AzGlyph { mIndex: glyph.id() as uint32_t, mPosition: struct__AzPoint { - x: (origin.x + glyph_offset.x).to_subpx() as AzFloat, - y: (origin.y + glyph_offset.y).to_subpx() as AzFloat + x: (origin.x + glyph_offset.x).to_f64_px() as AzFloat, + y: (origin.y + glyph_offset.y).to_f64_px() as AzFloat } }; origin = Point2D(origin.x + glyph_advance, origin.y); @@ -1385,7 +1385,7 @@ impl TemporaryDrawTarget { fn from_bounds(main_draw_target: &DrawTarget, bounds: &Rect) -> TemporaryDrawTarget { let draw_target_transform = main_draw_target.get_transform(); let temporary_draw_target_bounds = - draw_target_transform.transform_rect(&bounds.to_subpx_azure_rect()); + draw_target_transform.transform_rect(&bounds.to_f64_px_azure_rect()); let temporary_draw_target_size = Size2D(temporary_draw_target_bounds.size.width.ceil() as i32, temporary_draw_target_bounds.size.height.ceil() as i32); diff --git a/components/gfx/paint_task.rs b/components/gfx/paint_task.rs index fbdfbe82d5d..77adfc3c15b 100644 --- a/components/gfx/paint_task.rs +++ b/components/gfx/paint_task.rs @@ -546,8 +546,8 @@ impl WorkerThread { // Apply a translation to start at the boundaries of the stacking context, since the // layer's origin starts at its overflow rect's origin. let tile_bounds = tile.page_rect.translate( - &Point2D(stacking_context.overflow.origin.x.to_subpx() as AzFloat, - stacking_context.overflow.origin.y.to_subpx() as AzFloat)); + &Point2D(stacking_context.overflow.origin.x.to_f64_px() as AzFloat, + stacking_context.overflow.origin.y.to_f64_px() as AzFloat)); // Apply the translation to paint the tile we want. let matrix: Matrix2D = Matrix2D::identity(); diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index 00b0e1f6c02..f65104aa649 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -257,7 +257,7 @@ impl FontHandleMethods for FontHandle { line_gap: height, }; - debug!("Font metrics (@{}px): {:?}", em_size.to_frac32_px(), metrics); + debug!("Font metrics (@{}px): {:?}", em_size.to_f32_px(), metrics); return metrics; } @@ -268,7 +268,7 @@ impl FontHandleMethods for FontHandle { impl<'a> FontHandle { fn set_char_size(face: FT_Face, pt_size: Au) -> Result<(), ()>{ - let char_width = float_to_fixed_ft((0.5f64 + pt_size.to_subpx()).floor()) as FT_F26Dot6; + let char_width = float_to_fixed_ft((0.5f64 + pt_size.to_f64_px()).floor()) as FT_F26Dot6; unsafe { let result = FT_Set_Char_Size(face, char_width, 0, 0, 0); @@ -296,6 +296,6 @@ impl<'a> FontHandle { // If this isn't true then we're scaling one of the axes wrong assert!(metrics.x_ppem == metrics.y_ppem); - return Au::from_frac_px(value * x_scale); + return Au::from_f64_px(value * x_scale); } } diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index 8f74f99dfbe..f05bad2788f 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -62,7 +62,7 @@ impl FontHandleMethods for FontHandle { pt_size: Option) -> Result { let size = match pt_size { - Some(s) => s.to_subpx(), + Some(s) => s.to_f64_px(), None => 0.0 }; match template.ctfont { @@ -162,7 +162,7 @@ impl FontHandleMethods for FontHandle { let bounding_rect: CGRect = self.ctfont.bounding_box(); let ascent = self.ctfont.ascent() as f64; let descent = self.ctfont.descent() as f64; - let em_size = Au::from_frac_px(self.ctfont.pt_size() as f64); + let em_size = Au::from_f64_px(self.ctfont.pt_size() as f64); let leading = self.ctfont.leading() as f64; let scale = px_to_pt(self.ctfont.pt_size() as f64) / (ascent + descent); @@ -171,7 +171,7 @@ impl FontHandleMethods for FontHandle { let max_advance_width = Au::from_pt(bounding_rect.size.width as f64); let average_advance = self.glyph_index('0') .and_then(|idx| self.glyph_h_advance(idx)) - .map(|advance| Au::from_frac_px(advance)) + .map(|advance| Au::from_f64_px(advance)) .unwrap_or(max_advance_width); let metrics = FontMetrics { @@ -191,7 +191,7 @@ impl FontHandleMethods for FontHandle { descent: Au::from_pt(descent * scale), max_advance: max_advance_width, average_advance: average_advance, - line_gap: Au::from_frac_px(line_gap), + line_gap: Au::from_f64_px(line_gap), }; debug!("Font metrics (@{} pt): {:?}", self.ctfont.pt_size() as f64, metrics); return metrics; diff --git a/components/gfx/text/glyph.rs b/components/gfx/text/glyph.rs index 131ac03d309..0edddf87459 100644 --- a/components/gfx/text/glyph.rs +++ b/components/gfx/text/glyph.rs @@ -728,7 +728,7 @@ impl<'a> GlyphStore { // FIXME(pcwalton): This can overflow for very large font-sizes. let advance = ((entry.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT) + - Au::from_frac_px(space).0 as u32; + Au::from_f64_px(space).0 as u32; entry.value = (entry.value & !GLYPH_ADVANCE_MASK) | (advance << GLYPH_ADVANCE_SHIFT); } diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index 37b20af17ec..6ff6987e752 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -117,10 +117,10 @@ impl ShapedGlyphData { let x_advance = Shaper::fixed_to_float((*pos_info_i).x_advance); let y_advance = Shaper::fixed_to_float((*pos_info_i).y_advance); - let x_offset = Au::from_frac_px(x_offset); - let y_offset = Au::from_frac_px(y_offset); - let x_advance = Au::from_frac_px(x_advance); - let y_advance = Au::from_frac_px(y_advance); + let x_offset = Au::from_f64_px(x_offset); + let y_offset = Au::from_f64_px(y_offset); + let x_advance = Au::from_f64_px(x_advance); + let y_advance = Au::from_f64_px(y_advance); let offset = if x_offset == Au(0) && y_offset == Au(0) && y_advance == Au(0) { None @@ -185,7 +185,7 @@ impl Shaper { let hb_font: *mut hb_font_t = RUST_hb_font_create(hb_face); // Set points-per-em. if zero, performs no hinting in that direction. - let pt_size = font.actual_pt_size.to_subpx(); + let pt_size = font.actual_pt_size.to_f64_px(); RUST_hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint); // Set scaling. Note that this takes 16.16 fixed point. @@ -518,7 +518,7 @@ impl Shaper { advance = advance + options.word_spacing } else if character == '\t' { let tab_size = 8f64; - advance = Au::from_frac_px(tab_size * glyph_space_advance(self.font_and_shaping_options.font)); + advance = Au::from_f64_px(tab_size * glyph_space_advance(self.font_and_shaping_options.font)); } advance diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 67ee428fd72..2794563fd46 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -251,7 +251,7 @@ fn handle_overlapping_radii(size: &Size2D, radii: &BorderRadii) -> 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 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 isize), Au::from_px(image.height as isize)); 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. // @@ -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((offset.x + border_padding.left).to_frac32_px(), - (offset.y + border_padding.top).to_frac32_px()), - Size2D(content_size.width.to_frac32_px(), - content_size.height.to_frac32_px())); + 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, diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 9063bc652d2..13c602b6d41 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -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 diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 17741e4eadd..321a0868469 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -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()); diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index 6557b6c26c7..b98c7f99957 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -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) -> Result { - 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) -> Result { let mut mouse_over_list: Vec = 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(); diff --git a/components/layout/model.rs b/components/layout/model.rs index b4498ff3079..8b4da87cd45 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -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()) } } diff --git a/components/layout/table.rs b/components/layout/table.rs index 76b0ad99a6b..72af04817f2 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -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), diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index e7e2fd3e37f..8a3e368d140 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -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 { diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index 4a46235756e..9ed6b5df5c7 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -135,8 +135,8 @@ impl<'a> Activatable for JSRef<'a, HTMLAnchorElement> { let target_node = NodeCast::to_ref(target).unwrap(); let rect = window_from_node(target_node).root().r().content_box_query(target_node.to_trusted_node_address()); ismap_suffix = Some( - format!("?{},{}", mouse_event.ClientX().to_f32().unwrap() - rect.origin.x.to_frac32_px(), - mouse_event.ClientY().to_f32().unwrap() - rect.origin.y.to_frac32_px()) + format!("?{},{}", mouse_event.ClientX().to_f32().unwrap() - rect.origin.x.to_f32_px(), + mouse_event.ClientY().to_f32().unwrap() - rect.origin.y.to_f32_px()) ) } } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index e49f6a1a50e..5256b975172 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -917,10 +917,10 @@ impl Window { } fn should_move_clip_rect(clip_rect: Rect, new_viewport: Rect) -> bool{ - let clip_rect = Rect(Point2D(clip_rect.origin.x.to_frac32_px(), - clip_rect.origin.y.to_frac32_px()), - Size2D(clip_rect.size.width.to_frac32_px(), - clip_rect.size.height.to_frac32_px())); + let clip_rect = Rect(Point2D(clip_rect.origin.x.to_f32_px(), + clip_rect.origin.y.to_f32_px()), + Size2D(clip_rect.size.width.to_f32_px(), + clip_rect.size.height.to_f32_px())); // We only need to move the clip rect if the viewport is getting near the edge of // our preexisting clip rect. We use half of the size of the viewport as a heuristic diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 355b9d01210..0b703d8f7bd 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -1180,7 +1180,7 @@ impl ScriptTask { fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: JSRef) { let node: JSRef = NodeCast::from_ref(node); let rect = node.get_bounding_content_box(); - let point = Point2D(rect.origin.x.to_frac32_px(), rect.origin.y.to_frac32_px()); + let point = Point2D(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px()); // FIXME(#2003, pcwalton): This is pretty bogus when multiple layers are involved. // Really what needs to happen is that this needs to go through layout to ask which // layer the element belongs to, and have it send the scroll message to the diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs index 7f71d1602a2..8472347721c 100644 --- a/components/style/media_queries.rs +++ b/components/style/media_queries.rs @@ -203,8 +203,8 @@ pub fn parse_media_query_list(input: &mut Parser) -> MediaQueryList { impl MediaQueryList { pub fn evaluate(&self, device: &Device) -> bool { - let viewport_size = Size2D(Au::from_frac32_px(device.viewport_size.width.get()), - Au::from_frac32_px(device.viewport_size.height.get())); + let viewport_size = Size2D(Au::from_f32_px(device.viewport_size.width.get()), + Au::from_f32_px(device.viewport_size.height.get())); // Check if any queries match (OR condition) self.media_queries.iter().any(|mq| { diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index ccf5095c0e8..ef577d083d1 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -3313,8 +3313,8 @@ pub mod longhands { return Err(()) } let (tx, ty) = - (specified::Length::Absolute(Au::from_frac32_px(values[4])), - specified::Length::Absolute(Au::from_frac32_px(values[5]))); + (specified::Length::Absolute(Au::from_f32_px(values[4])), + specified::Length::Absolute(Au::from_f32_px(values[5]))); let (tx, ty) = (specified::LengthAndPercentage::from_length(tx), specified::LengthAndPercentage::from_length(ty)); diff --git a/components/style/values.rs b/components/style/values.rs index 185bfd7280a..88ae4b0417c 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -187,7 +187,7 @@ pub mod specified { pub fn to_computed_value(&self, viewport_size: Size2D) -> Au { macro_rules! to_unit { ($viewport_dimension:expr) => { - $viewport_dimension.to_frac32_px() / 100.0 + $viewport_dimension.to_f32_px() / 100.0 } } @@ -201,7 +201,7 @@ pub mod specified { &ViewportPercentageLength::Vmax(length) => length * to_unit!(cmp::max(viewport_size.width, viewport_size.height)), }; - Au::from_frac32_px(value) + Au::from_f32_px(value) } } @@ -236,7 +236,7 @@ pub mod specified { impl ToCss for Length { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { - &Length::Absolute(length) => write!(dest, "{}px", length.to_frac32_px()), + &Length::Absolute(length) => write!(dest, "{}px", length.to_f32_px()), &Length::FontRelative(length) => length.to_css(dest), &Length::ViewportPercentage(length) => length.to_css(dest), &Length::ServoCharacterWidth(_) @@ -1114,7 +1114,7 @@ pub mod computed { fn mul(self, scalar: CSSFloat) -> LengthAndPercentage { LengthAndPercentage { - length: Au::from_frac32_px(self.length.to_frac32_px() * scalar), + length: Au::from_f32_px(self.length.to_f32_px() * scalar), percentage: self.percentage * scalar, } } diff --git a/components/util/geometry.rs b/components/util/geometry.rs index 515529ad2f7..684b06183f8 100644 --- a/components/util/geometry.rs +++ b/components/util/geometry.rs @@ -115,13 +115,13 @@ pub const MAX_AU: Au = Au(i32::MAX); impl Encodable for Au { fn encode(&self, e: &mut S) -> Result<(), S::Error> { - e.emit_f64(self.to_subpx()) + e.emit_f64(self.to_f64_px()) } } impl fmt::Debug for Au { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}px", self.to_subpx()) + write!(f, "{}px", self.to_f64_px()) }} impl Add for Au { @@ -238,13 +238,13 @@ impl Au { } #[inline] - pub fn to_frac32_px(&self) -> f32 { + pub fn to_f32_px(&self) -> f32 { let Au(s) = *self; (s as f32) / 60f32 } #[inline] - pub fn to_subpx(&self) -> f64 { + pub fn to_f64_px(&self) -> f64 { let Au(s) = *self; (s as f64) / 60f64 } @@ -258,17 +258,17 @@ impl Au { } #[inline] - pub fn from_frac32_px(px: f32) -> Au { + pub fn from_f32_px(px: f32) -> Au { Au((px * 60f32) as i32) } #[inline] pub fn from_pt(pt: f64) -> Au { - Au::from_frac_px(pt_to_px(pt)) + Au::from_f64_px(pt_to_px(pt)) } #[inline] - pub fn from_frac_px(px: f64) -> Au { + pub fn from_f64_px(px: f64) -> Au { Au((px * 60.) as i32) } } @@ -293,7 +293,7 @@ pub fn rect_contains_point>(rect: Rect, point /// A helper function to convert a rect of `f32` pixels to a rect of app units. pub fn f32_rect_to_au_rect(rect: Rect) -> Rect { - Rect(Point2D(Au::from_frac32_px(rect.origin.x), Au::from_frac32_px(rect.origin.y)), - Size2D(Au::from_frac32_px(rect.size.width), Au::from_frac32_px(rect.size.height))) + Rect(Point2D(Au::from_f32_px(rect.origin.x), Au::from_f32_px(rect.origin.y)), + Size2D(Au::from_f32_px(rect.size.width), Au::from_f32_px(rect.size.height))) } From b1ecba9f3d30e2fe832f216f1453ada0750140c7 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 5 May 2015 18:40:00 +0200 Subject: [PATCH 3/7] Use i32 instead of isize in Au methods. --- components/gfx/paint_task.rs | 4 ++-- components/layout/display_list_builder.rs | 4 ++-- components/layout/fragment.rs | 14 +++++++------- components/style/legacy.rs | 4 ++-- components/style/properties.mako.rs | 2 +- components/util/geometry.rs | 18 +++++++++--------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/components/gfx/paint_task.rs b/components/gfx/paint_task.rs index 77adfc3c15b..1a2dcd18f1a 100644 --- a/components/gfx/paint_task.rs +++ b/components/gfx/paint_task.rs @@ -575,8 +575,8 @@ impl WorkerThread { // painted this tile. let color = THREAD_TINT_COLORS[thread_id % THREAD_TINT_COLORS.len()]; paint_context.draw_solid_color(&Rect(Point2D(Au(0), Au(0)), - Size2D(Au::from_px(size.width as isize), - Au::from_px(size.height as isize))), + Size2D(Au::from_px(size.width), + Au::from_px(size.height))), color); } } diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 2794563fd46..7c4ee2b5066 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -353,8 +353,8 @@ impl FragmentDisplayListBuilding for Fragment { // wide. let image_aspect_ratio = (image.width as f64) / (image.height as f64); 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 isize), - Au::from_px(image.height as isize)); + 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) => { diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 13c602b6d41..7b451d608ad 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -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 { let element = node.as_element(); element.get_attr(&ns!(""), name) - .and_then(|string| string.parse::().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,7 +354,7 @@ 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 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); diff --git a/components/style/legacy.rs b/components/style/legacy.rs index f3a66f5138a..1b3cac694c0 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -126,7 +126,7 @@ impl PresentationalHintSynthesis for Stylist { UnsignedIntegerAttribute::CellSpacing) { None => {} Some(length) => { - let width_value = specified::Length::Absolute(Au::from_px(length as isize)); + let width_value = specified::Length::Absolute(Au::from_px(length as i32)); matching_rules_list.push(from_declaration( PropertyDeclaration::BorderSpacing( SpecifiedValue( @@ -204,7 +204,7 @@ impl PresentationalHintSynthesis for Stylist { match element.get_unsigned_integer_attribute(UnsignedIntegerAttribute::Border) { None => {} Some(length) => { - let width_value = specified::Length::Absolute(Au::from_px(length as isize)); + let width_value = specified::Length::Absolute(Au::from_px(length as i32)); matching_rules_list.push(from_declaration( PropertyDeclaration::BorderTopWidth(SpecifiedValue( longhands::border_top_width::SpecifiedValue(width_value))))); diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index ef577d083d1..1b869806c17 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -1681,7 +1681,7 @@ pub mod longhands { use util::geometry::Au; pub type T = Au; } - const MEDIUM_PX: isize = 16; + const MEDIUM_PX: i32 = 16; #[inline] pub fn get_initial_value() -> computed_value::T { Au::from_px(MEDIUM_PX) } diff --git a/components/util/geometry.rs b/components/util/geometry.rs index 684b06183f8..8f40e92e397 100644 --- a/components/util/geometry.rs +++ b/components/util/geometry.rs @@ -201,7 +201,7 @@ impl Au { } #[inline] - pub fn from_px(px: isize) -> Au { + pub fn from_px(px: i32) -> Au { Au((px * 60) as i32) } @@ -212,29 +212,29 @@ impl Au { /// Rounds this app unit down to the pixel towards zero and returns it. #[inline] - pub fn to_px(&self) -> isize { + pub fn to_px(&self) -> i32 { let Au(a) = *self; - (a / 60) as isize + (a / 60) } /// Rounds this app unit down to the previous (left or top) pixel and returns it. #[inline] - pub fn to_prev_px(&self) -> isize { + pub fn to_prev_px(&self) -> i32 { let Au(s) = *self; - ((s as f64) / 60f64).floor() as isize + ((s as f64) / 60f64).floor() as i32 } /// Rounds this app unit up to the next (right or bottom) pixel and returns it. #[inline] - pub fn to_next_px(&self) -> isize { + pub fn to_next_px(&self) -> i32 { let Au(s) = *self; - ((s as f64) / 60f64).ceil() as isize + ((s as f64) / 60f64).ceil() as i32 } #[inline] - pub fn to_nearest_px(&self) -> isize { + pub fn to_nearest_px(&self) -> i32 { let Au(s) = *self; - ((s as f64) / 60f64).round() as isize + ((s as f64) / 60f64).round() as i32 } #[inline] From 4f618c45a51b5ccd84b6114abd8ceebfa6e1811f Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 5 May 2015 18:42:02 +0200 Subject: [PATCH 4/7] Used `foo.0` tuple access notation instead of `let Au(a) = a;` --- components/util/geometry.rs | 48 +++++++++++++------------------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/components/util/geometry.rs b/components/util/geometry.rs index 8f40e92e397..c8f021895fb 100644 --- a/components/util/geometry.rs +++ b/components/util/geometry.rs @@ -129,9 +129,7 @@ impl Add for Au { #[inline] fn add(self, other: Au) -> Au { - let Au(s) = self; - let Au(o) = other; - Au(s.wrapping_add(o)) + Au(self.0.wrapping_add(other.0)) } } @@ -140,9 +138,7 @@ impl Sub for Au { #[inline] fn sub(self, other: Au) -> Au { - let Au(s) = self; - let Au(o) = other; - Au(s.wrapping_sub(o)) + Au(self.0.wrapping_sub(other.0)) } } @@ -152,8 +148,7 @@ impl Mul for Au { #[inline] fn mul(self, other: i32) -> Au { - let Au(s) = self; - Au(s.wrapping_mul(other)) + Au(self.0.wrapping_mul(other)) } } @@ -162,8 +157,7 @@ impl Div for Au { #[inline] fn div(self, other: i32) -> Au { - let Au(s) = self; - Au(s / other) + Au(self.0 / other) } } @@ -172,8 +166,7 @@ impl Rem for Au { #[inline] fn rem(self, other: i32) -> Au { - let Au(s) = self; - Au(s % other) + Au(self.0 % other) } } @@ -182,8 +175,7 @@ impl Neg for Au { #[inline] fn neg(self) -> Au { - let Au(s) = self; - Au(-s) + Au(-self.0) } } @@ -196,8 +188,7 @@ impl Au { #[inline] pub fn scale_by(self, factor: f32) -> Au { - let Au(s) = self; - Au(((s as f32) * factor) as i32) + Au(((self.0 as f32) * factor) as i32) } #[inline] @@ -213,48 +204,41 @@ impl Au { /// Rounds this app unit down to the pixel towards zero and returns it. #[inline] pub fn to_px(&self) -> i32 { - let Au(a) = *self; - (a / 60) + self.0 / 60 } /// Rounds this app unit down to the previous (left or top) pixel and returns it. #[inline] pub fn to_prev_px(&self) -> i32 { - let Au(s) = *self; - ((s as f64) / 60f64).floor() as i32 + ((self.0 as f64) / 60f64).floor() as i32 } /// Rounds this app unit up to the next (right or bottom) pixel and returns it. #[inline] pub fn to_next_px(&self) -> i32 { - let Au(s) = *self; - ((s as f64) / 60f64).ceil() as i32 + ((self.0 as f64) / 60f64).ceil() as i32 } #[inline] pub fn to_nearest_px(&self) -> i32 { - let Au(s) = *self; - ((s as f64) / 60f64).round() as i32 + ((self.0 as f64) / 60f64).round() as i32 } #[inline] pub fn to_f32_px(&self) -> f32 { - let Au(s) = *self; - (s as f32) / 60f32 + (self.0 as f32) / 60f32 } #[inline] pub fn to_f64_px(&self) -> f64 { - let Au(s) = *self; - (s as f64) / 60f64 + (self.0 as f64) / 60f64 } #[inline] pub fn to_snapped(&self) -> Au { - let Au(s) = *self; - let res = s % 60i32; - return if res >= 30i32 { return Au(s - res + 60i32) } - else { return Au(s - res) }; + let res = self.0 % 60i32; + return if res >= 30i32 { return Au(self.0 - res + 60i32) } + else { return Au(self.0 - res) }; } #[inline] From 5f0c55cefb0c24a235ddbba05176c40f4799d007 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 5 May 2015 18:43:12 +0200 Subject: [PATCH 5/7] =?UTF-8?q?Make=20most=20Au=20methods=20take=20self=20?= =?UTF-8?q?by=20value.=20(It=E2=80=99s=20a=20i32=20wrapper.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/util/geometry.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/util/geometry.rs b/components/util/geometry.rs index c8f021895fb..ae149c5162e 100644 --- a/components/util/geometry.rs +++ b/components/util/geometry.rs @@ -203,39 +203,39 @@ impl Au { /// Rounds this app unit down to the pixel towards zero and returns it. #[inline] - pub fn to_px(&self) -> i32 { + pub fn to_px(self) -> i32 { self.0 / 60 } /// Rounds this app unit down to the previous (left or top) pixel and returns it. #[inline] - pub fn to_prev_px(&self) -> i32 { + pub fn to_prev_px(self) -> i32 { ((self.0 as f64) / 60f64).floor() as i32 } /// Rounds this app unit up to the next (right or bottom) pixel and returns it. #[inline] - pub fn to_next_px(&self) -> i32 { + pub fn to_next_px(self) -> i32 { ((self.0 as f64) / 60f64).ceil() as i32 } #[inline] - pub fn to_nearest_px(&self) -> i32 { + pub fn to_nearest_px(self) -> i32 { ((self.0 as f64) / 60f64).round() as i32 } #[inline] - pub fn to_f32_px(&self) -> f32 { + pub fn to_f32_px(self) -> f32 { (self.0 as f32) / 60f32 } #[inline] - pub fn to_f64_px(&self) -> f64 { + pub fn to_f64_px(self) -> f64 { (self.0 as f64) / 60f64 } #[inline] - pub fn to_snapped(&self) -> Au { + pub fn to_snapped(self) -> Au { let res = self.0 % 60i32; return if res >= 30i32 { return Au(self.0 - res + 60i32) } else { return Au(self.0 - res) }; From 6bf830f66384f704b62b642aee8aaad3f1a24633 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 5 May 2015 20:11:26 +0200 Subject: [PATCH 6/7] Remove some unnecessary casts. --- components/gfx/font_context.rs | 4 ++-- components/gfx/paint_context.rs | 18 +++++++++--------- components/gfx/paint_task.rs | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/components/gfx/font_context.rs b/components/gfx/font_context.rs index d02d798ca2c..4ccdfbbc01b 100644 --- a/components/gfx/font_context.rs +++ b/components/gfx/font_context.rs @@ -36,13 +36,13 @@ use azure::scaled_font::FontInfo; #[cfg(any(target_os="linux", target_os = "android"))] fn create_scaled_font(template: &Arc, pt_size: Au) -> ScaledFont { ScaledFont::new(BackendType::Skia, FontInfo::FontData(&template.bytes), - pt_size.to_f64_px() as AzFloat) + pt_size.to_f32_px()) } #[cfg(target_os="macos")] fn create_scaled_font(template: &Arc, pt_size: Au) -> ScaledFont { let cgfont = template.ctfont.as_ref().unwrap().copy_to_CGFont(); - ScaledFont::new(BackendType::Skia, &cgfont, pt_size.to_f64_px() as AzFloat) + ScaledFont::new(BackendType::Skia, &cgfont, pt_size.to_f32_px()) } static SMALL_CAPS_SCALE_FACTOR: f32 = 0.8; // Matches FireFox (see gfxFont.h) diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 0aadd9c16b4..7160a31971b 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -826,16 +826,16 @@ impl<'a> PaintContext<'a> { let baseline_origin = match text.orientation { Upright => text.baseline_origin, SidewaysLeft => { - let x = text.baseline_origin.x.to_f64_px() as AzFloat; - let y = text.baseline_origin.y.to_f64_px() as AzFloat; + let x = text.baseline_origin.x.to_f32_px(); + let y = text.baseline_origin.y.to_f32_px(); self.draw_target.set_transform(&draw_target_transform.mul(&Matrix2D::new(0., -1., 1., 0., x, y))); Point2D::zero() } SidewaysRight => { - let x = text.baseline_origin.x.to_f64_px() as AzFloat; - let y = text.baseline_origin.y.to_f64_px() as AzFloat; + let x = text.baseline_origin.x.to_f32_px(); + let y = text.baseline_origin.y.to_f32_px(); self.draw_target.set_transform(&draw_target_transform.mul(&Matrix2D::new(0., 1., -1., 0., x, y))); @@ -1112,7 +1112,7 @@ impl ToAzurePoint for Point2D { Point2D(self.x.to_nearest_px() as AzFloat, self.y.to_nearest_px() as AzFloat) } fn to_f64_px_azure_point(&self) -> Point2D { - Point2D(self.x.to_f64_px() as AzFloat, self.y.to_f64_px() as AzFloat) + Point2D(self.x.to_f32_px(), self.y.to_f32_px()) } } @@ -1128,8 +1128,8 @@ impl ToAzureRect for Rect { } fn to_f64_px_azure_rect(&self) -> Rect { - Rect(self.origin.to_f64_px_azure_point(), Size2D(self.size.width.to_f64_px() as AzFloat, - self.size.height.to_f64_px() as AzFloat)) + Rect(self.origin.to_f64_px_azure_point(), Size2D(self.size.width.to_f32_px(), + self.size.height.to_f32_px())) } } @@ -1241,8 +1241,8 @@ impl ScaledFontExtensionMethods for ScaledFont { let azglyph = struct__AzGlyph { mIndex: glyph.id() as uint32_t, mPosition: struct__AzPoint { - x: (origin.x + glyph_offset.x).to_f64_px() as AzFloat, - y: (origin.y + glyph_offset.y).to_f64_px() as AzFloat + x: (origin.x + glyph_offset.x).to_f32_px(), + y: (origin.y + glyph_offset.y).to_f32_px(), } }; origin = Point2D(origin.x + glyph_advance, origin.y); diff --git a/components/gfx/paint_task.rs b/components/gfx/paint_task.rs index 1a2dcd18f1a..1ad7bf54006 100644 --- a/components/gfx/paint_task.rs +++ b/components/gfx/paint_task.rs @@ -546,8 +546,8 @@ impl WorkerThread { // Apply a translation to start at the boundaries of the stacking context, since the // layer's origin starts at its overflow rect's origin. let tile_bounds = tile.page_rect.translate( - &Point2D(stacking_context.overflow.origin.x.to_f64_px() as AzFloat, - stacking_context.overflow.origin.y.to_f64_px() as AzFloat)); + &Point2D(stacking_context.overflow.origin.x.to_f32_px(), + stacking_context.overflow.origin.y.to_f32_px())); // Apply the translation to paint the tile we want. let matrix: Matrix2D = Matrix2D::identity(); From 908be6abc2c32f5d6706f938bffb91f94c85d5d5 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 5 May 2015 20:13:30 +0200 Subject: [PATCH 7/7] Rename some to_azure* methods according to what they do. --- components/gfx/display_list/mod.rs | 4 +-- components/gfx/paint_context.rs | 48 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 40416ed9e8d..224da2ca68d 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -420,7 +420,7 @@ impl StackingContext { // Translate the child's overflow region into our coordinate system. let child_stacking_context_overflow = child_stacking_context.overflow.translate(&child_stacking_context.bounds.origin) - .to_azure_rect(); + .to_nearest_azure_rect(); // Intersect that with the current tile boundaries to find the tile boundaries that the // child covers. @@ -428,7 +428,7 @@ impl StackingContext { .unwrap_or(ZERO_AZURE_RECT); // Translate the resulting rect into the child's coordinate system. - tile_subrect.translate(&-child_stacking_context.bounds.to_azure_rect().origin) + tile_subrect.translate(&-child_stacking_context.bounds.to_nearest_azure_rect().origin) } /// Places all nodes containing the point of interest into `result`, topmost first. Respects diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 7160a31971b..24e7f1f7958 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -77,7 +77,7 @@ impl<'a> PaintContext<'a> { pub fn draw_solid_color(&self, bounds: &Rect, color: Color) { self.draw_target.make_current(); - self.draw_target.fill_rect(&bounds.to_azure_rect(), + self.draw_target.fill_rect(&bounds.to_nearest_azure_rect(), PatternRef::Color(&ColorPattern::new(color)), None); } @@ -104,7 +104,7 @@ impl<'a> PaintContext<'a> { } pub fn draw_push_clip(&self, bounds: &Rect) { - let rect = bounds.to_azure_rect(); + let rect = bounds.to_nearest_azure_rect(); let path_builder = self.draw_target.create_path_builder(); let left_top = Point2D(rect.origin.x, rect.origin.y); @@ -147,7 +147,7 @@ impl<'a> PaintContext<'a> { source_format); let source_rect = Rect(Point2D(0.0, 0.0), Size2D(image.width as AzFloat, image.height as AzFloat)); - let dest_rect = bounds.to_azure_rect(); + let dest_rect = bounds.to_nearest_azure_rect(); // TODO(pcwalton): According to CSS-IMAGES-3 § 5.3, nearest-neighbor interpolation is a // conforming implementation of `crisp-edges`, but it is not the best we could do. @@ -616,7 +616,7 @@ impl<'a> PaintContext<'a> { border: &SideOffsets2D, color: Color, dash_size: DashSize) { - let rect = bounds.to_azure_rect(); + let rect = bounds.to_nearest_azure_rect(); let draw_opts = DrawOptions::new(1 as AzFloat, 0 as uint16_t); let border_width = match direction { Direction::Top => border.top, @@ -671,7 +671,7 @@ impl<'a> PaintContext<'a> { border: &SideOffsets2D, radius: &BorderRadii, color: Color) { - let rect = bounds.to_azure_rect(); + let rect = bounds.to_nearest_azure_rect(); self.draw_border_path(&rect, direction, border, radius, color); } @@ -679,7 +679,7 @@ impl<'a> PaintContext<'a> { bounds: &Rect, border: &SideOffsets2D, shrink_factor: f32) -> Rect { - let rect = bounds.to_azure_rect(); + let rect = bounds.to_nearest_azure_rect(); let scaled_border = SideOffsets2D::new(shrink_factor * border.top, shrink_factor * border.right, shrink_factor * border.bottom, @@ -879,11 +879,11 @@ impl<'a> PaintContext<'a> { self.draw_target.make_current(); let stops = self.draw_target.create_gradient_stops(stops, ExtendMode::Clamp); - let pattern = LinearGradientPattern::new(&start_point.to_azure_point(), - &end_point.to_azure_point(), + let pattern = LinearGradientPattern::new(&start_point.to_nearest_azure_point(), + &end_point.to_nearest_azure_point(), stops, &Matrix2D::identity()); - self.draw_target.fill_rect(&bounds.to_azure_rect(), + self.draw_target.fill_rect(&bounds.to_nearest_azure_rect(), PatternRef::LinearGradient(&pattern), None); } @@ -1095,7 +1095,7 @@ impl<'a> PaintContext<'a> { self.draw_push_clip(&clip_region.main); for complex_region in clip_region.complex.iter() { // FIXME(pcwalton): Actually draw a rounded rect. - self.push_rounded_rect_clip(&complex_region.rect.to_azure_rect(), + self.push_rounded_rect_clip(&complex_region.rect.to_nearest_azure_rect(), &complex_region.radii.to_radii_px()) } self.transient_clip = Some(clip_region) @@ -1103,32 +1103,32 @@ impl<'a> PaintContext<'a> { } pub trait ToAzurePoint { + fn to_nearest_azure_point(&self) -> Point2D; fn to_azure_point(&self) -> Point2D; - fn to_f64_px_azure_point(&self) -> Point2D; } impl ToAzurePoint for Point2D { - fn to_azure_point(&self) -> Point2D { + fn to_nearest_azure_point(&self) -> Point2D { Point2D(self.x.to_nearest_px() as AzFloat, self.y.to_nearest_px() as AzFloat) } - fn to_f64_px_azure_point(&self) -> Point2D { + fn to_azure_point(&self) -> Point2D { Point2D(self.x.to_f32_px(), self.y.to_f32_px()) } } pub trait ToAzureRect { + fn to_nearest_azure_rect(&self) -> Rect; fn to_azure_rect(&self) -> Rect; - fn to_f64_px_azure_rect(&self) -> Rect; } impl ToAzureRect for Rect { - fn to_azure_rect(&self) -> Rect { - Rect(self.origin.to_azure_point(), Size2D(self.size.width.to_nearest_px() as AzFloat, + fn to_nearest_azure_rect(&self) -> Rect { + Rect(self.origin.to_nearest_azure_point(), Size2D(self.size.width.to_nearest_px() as AzFloat, self.size.height.to_nearest_px() as AzFloat)) } - fn to_f64_px_azure_rect(&self) -> Rect { - Rect(self.origin.to_f64_px_azure_point(), Size2D(self.size.width.to_f32_px(), + fn to_azure_rect(&self) -> Rect { + Rect(self.origin.to_azure_point(), Size2D(self.size.width.to_f32_px(), self.size.height.to_f32_px())) } } @@ -1306,7 +1306,7 @@ impl DrawTargetExtensions for DrawTarget { // +-----------+ // 3 4 - let (outer_rect, inner_rect) = (outer_rect.to_azure_rect(), inner_rect.to_azure_rect()); + let (outer_rect, inner_rect) = (outer_rect.to_nearest_azure_rect(), inner_rect.to_nearest_azure_rect()); let path_builder = self.create_path_builder(); path_builder.move_to(Point2D(outer_rect.max_x(), outer_rect.origin.y)); // 1 path_builder.line_to(Point2D(outer_rect.origin.x, outer_rect.origin.y)); // 2 @@ -1323,10 +1323,10 @@ impl DrawTargetExtensions for DrawTarget { fn create_rectangular_path(&self, rect: &Rect) -> Path { let path_builder = self.create_path_builder(); - path_builder.move_to(rect.origin.to_azure_point()); - path_builder.line_to(Point2D(rect.max_x(), rect.origin.y).to_azure_point()); - path_builder.line_to(Point2D(rect.max_x(), rect.max_y()).to_azure_point()); - path_builder.line_to(Point2D(rect.origin.x, rect.max_y()).to_azure_point()); + path_builder.move_to(rect.origin.to_nearest_azure_point()); + path_builder.line_to(Point2D(rect.max_x(), rect.origin.y).to_nearest_azure_point()); + path_builder.line_to(Point2D(rect.max_x(), rect.max_y()).to_nearest_azure_point()); + path_builder.line_to(Point2D(rect.origin.x, rect.max_y()).to_nearest_azure_point()); path_builder.finish() } } @@ -1385,7 +1385,7 @@ impl TemporaryDrawTarget { fn from_bounds(main_draw_target: &DrawTarget, bounds: &Rect) -> TemporaryDrawTarget { let draw_target_transform = main_draw_target.get_transform(); let temporary_draw_target_bounds = - draw_target_transform.transform_rect(&bounds.to_f64_px_azure_rect()); + draw_target_transform.transform_rect(&bounds.to_azure_rect()); let temporary_draw_target_size = Size2D(temporary_draw_target_bounds.size.width.ceil() as i32, temporary_draw_target_bounds.size.height.ceil() as i32);