mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Replace Au-related free functions in util::geometry with Au methods.
This commit is contained in:
parent
49aed6555d
commit
32d5e24922
12 changed files with 50 additions and 92 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,7 +967,7 @@ 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)),
|
||||
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,7 +397,7 @@ impl LineBreaker {
|
|||
|
||||
fn new_block_size_for_line(&self, new_fragment: &Fragment, layout_context: &LayoutContext)
|
||||
-> Au {
|
||||
Au::max(self.pending_line.bounds.size.block,
|
||||
max(self.pending_line.bounds.size.block,
|
||||
self.new_inline_metrics_for_line(new_fragment, layout_context).block_size())
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
block_size_above_baseline: 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),
|
||||
depth_below_baseline: max(self.depth_below_baseline, other.depth_below_baseline),
|
||||
ascent: max(self.ascent, other.ascent),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_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
|
||||
|
|
|
@ -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_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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue