зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #5951 - Clean up the `Au` API (from SimonSapin:au-cleanup); r=mbrubeck
Fix #5943. r? @mbrubeck Source-Repo: https://github.com/servo/servo Source-Revision: 1721cf45ed59306a69f3ade08feca065804c3804
This commit is contained in:
Родитель
ed3b6c3e4f
Коммит
da599fc5b9
|
@ -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
|
||||
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -36,13 +36,13 @@ use azure::scaled_font::FontInfo;
|
|||
#[cfg(any(target_os="linux", target_os = "android"))]
|
||||
fn create_scaled_font(template: &Arc<FontTemplateData>, pt_size: Au) -> ScaledFont {
|
||||
ScaledFont::new(BackendType::Skia, FontInfo::FontData(&template.bytes),
|
||||
pt_size.to_subpx() as AzFloat)
|
||||
pt_size.to_f32_px())
|
||||
}
|
||||
|
||||
#[cfg(target_os="macos")]
|
||||
fn create_scaled_font(template: &Arc<FontTemplateData>, 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_f32_px())
|
||||
}
|
||||
|
||||
static SMALL_CAPS_SCALE_FACTOR: f32 = 0.8; // Matches FireFox (see gfxFont.h)
|
||||
|
|
|
@ -77,7 +77,7 @@ impl<'a> PaintContext<'a> {
|
|||
|
||||
pub fn draw_solid_color(&self, bounds: &Rect<Au>, 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<Au>) {
|
||||
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<f32>,
|
||||
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<f32>,
|
||||
radius: &BorderRadii<AzFloat>,
|
||||
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<Au>,
|
||||
border: &SideOffsets2D<f32>,
|
||||
shrink_factor: f32) -> Rect<f32> {
|
||||
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,
|
||||
|
@ -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_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_subpx() as AzFloat;
|
||||
let y = text.baseline_origin.y.to_subpx() 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)));
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,33 +1103,33 @@ impl<'a> PaintContext<'a> {
|
|||
}
|
||||
|
||||
pub trait ToAzurePoint {
|
||||
fn to_nearest_azure_point(&self) -> Point2D<AzFloat>;
|
||||
fn to_azure_point(&self) -> Point2D<AzFloat>;
|
||||
fn to_subpx_azure_point(&self) -> Point2D<AzFloat>;
|
||||
}
|
||||
|
||||
impl ToAzurePoint for Point2D<Au> {
|
||||
fn to_azure_point(&self) -> Point2D<AzFloat> {
|
||||
fn to_nearest_azure_point(&self) -> Point2D<AzFloat> {
|
||||
Point2D(self.x.to_nearest_px() as AzFloat, self.y.to_nearest_px() as AzFloat)
|
||||
}
|
||||
fn to_subpx_azure_point(&self) -> Point2D<AzFloat> {
|
||||
Point2D(self.x.to_subpx() as AzFloat, self.y.to_subpx() as AzFloat)
|
||||
fn to_azure_point(&self) -> Point2D<AzFloat> {
|
||||
Point2D(self.x.to_f32_px(), self.y.to_f32_px())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToAzureRect {
|
||||
fn to_nearest_azure_rect(&self) -> Rect<AzFloat>;
|
||||
fn to_azure_rect(&self) -> Rect<AzFloat>;
|
||||
fn to_subpx_azure_rect(&self) -> Rect<AzFloat>;
|
||||
}
|
||||
|
||||
impl ToAzureRect for Rect<Au> {
|
||||
fn to_azure_rect(&self) -> Rect<AzFloat> {
|
||||
Rect(self.origin.to_azure_point(), Size2D(self.size.width.to_nearest_px() as AzFloat,
|
||||
fn to_nearest_azure_rect(&self) -> Rect<AzFloat> {
|
||||
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_subpx_azure_rect(&self) -> Rect<AzFloat> {
|
||||
Rect(self.origin.to_subpx_azure_point(), Size2D(self.size.width.to_subpx() as AzFloat,
|
||||
self.size.height.to_subpx() as AzFloat))
|
||||
fn to_azure_rect(&self) -> Rect<AzFloat> {
|
||||
Rect(self.origin.to_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_subpx() as AzFloat,
|
||||
y: (origin.y + glyph_offset.y).to_subpx() 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);
|
||||
|
@ -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<Au>) -> 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<Au>) -> 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_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);
|
||||
|
|
|
@ -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_f32_px(),
|
||||
stacking_context.overflow.origin.y.to_f32_px()));
|
||||
|
||||
// Apply the translation to paint the tile we want.
|
||||
let matrix: Matrix2D<AzFloat> = Matrix2D::identity();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_f32_px(), metrics);
|
||||
return metrics;
|
||||
}
|
||||
|
||||
|
@ -269,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);
|
||||
|
@ -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_f64_px(value * x_scale);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ impl FontHandleMethods for FontHandle {
|
|||
pt_size: Option<Au>)
|
||||
-> Result<FontHandle, ()> {
|
||||
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 {
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
};
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Node> = 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<Node> = 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) {
|
||||
|
|
|
@ -917,10 +917,10 @@ impl Window {
|
|||
}
|
||||
|
||||
fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> 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_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
|
||||
|
|
|
@ -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<Element>) {
|
||||
let node: JSRef<Node> = 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_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
|
||||
|
|
|
@ -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)))));
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
@ -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));
|
||||
|
|
|
@ -187,7 +187,7 @@ pub mod specified {
|
|||
pub fn to_computed_value(&self, viewport_size: Size2D<Au>) -> 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<W>(&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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,13 +115,13 @@ pub const MAX_AU: Au = Au(i32::MAX);
|
|||
|
||||
impl Encodable for Au {
|
||||
fn encode<S: Encoder>(&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 {
|
||||
|
@ -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<i32> 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<i32> 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<i32> 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,12 +188,11 @@ 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]
|
||||
pub fn from_px(px: isize) -> Au {
|
||||
pub fn from_px(px: i32) -> Au {
|
||||
Au((px * 60) as i32)
|
||||
}
|
||||
|
||||
|
@ -210,74 +201,60 @@ 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) -> 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) -> isize {
|
||||
let Au(s) = *self;
|
||||
((s as f64) / 60f64).floor() as isize
|
||||
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) -> isize {
|
||||
let Au(s) = *self;
|
||||
((s as f64) / 60f64).ceil() as isize
|
||||
pub fn to_next_px(self) -> i32 {
|
||||
((self.0 as f64) / 60f64).ceil() as i32
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_nearest_px(&self) -> isize {
|
||||
let Au(s) = *self;
|
||||
((s as f64) / 60f64).round() as isize
|
||||
pub fn to_nearest_px(self) -> i32 {
|
||||
((self.0 as f64) / 60f64).round() as i32
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_frac32_px(&self) -> f32 {
|
||||
let Au(s) = *self;
|
||||
(s as f32) / 60f32
|
||||
pub fn to_f32_px(self) -> f32 {
|
||||
(self.0 as f32) / 60f32
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_subpx(&self) -> f64 {
|
||||
let Au(s) = *self;
|
||||
(s as f64) / 60f64
|
||||
pub fn to_f64_px(self) -> f64 {
|
||||
(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) };
|
||||
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) };
|
||||
}
|
||||
|
||||
#[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 {
|
||||
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)
|
||||
}
|
||||
|
||||
#[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 +267,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.
|
||||
|
@ -329,7 +277,7 @@ pub fn rect_contains_point<T:PartialOrd + Add<T, Output=T>>(rect: Rect<T>, 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<f32>) -> Rect<Au> {
|
||||
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)))
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче