Introduce CSSPixelLength and update NonNegativeLength.

First, we define computed::CSSPixelLength which contains a CSSFloat, a
pixel value, and then we replace computed::Length with CSSPixelLength.
Therefore, the |ComputedValue| of NoCalcLength, AbsoluteLength,
FontRelativeLength, ViewportPercentageLength, CharacterWidth, and
PhysicalLength is CSSPixelLength.

Besides, we drop NonNegativeAu, and replace computed::NonNegativeLength
with NonNegative<computed::Length>. (i.e. NonNegative<CSSPixelLength>)
This commit is contained in:
Boris Chiou 2017-09-13 14:26:51 +08:00
parent cad3aff508
commit a949e2a057
40 changed files with 502 additions and 406 deletions

View file

@ -61,7 +61,7 @@ use servo_arc::{Arc, RawOffsetArc};
use std::mem::{forget, uninitialized, transmute, zeroed};
use std::{cmp, ops, ptr};
use values::{self, Auto, CustomIdent, Either, KeyframesName, None_};
use values::computed::{NonNegativeAu, ToComputedValue, Percentage};
use values::computed::{NonNegativeLength, ToComputedValue, Percentage};
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
use computed_values::border_style;
@ -530,13 +530,13 @@ def set_gecko_property(ffi_name, expr):
<%def name="impl_absolute_length(ident, gecko_ffi_name, need_clone=False)">
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
${set_gecko_property(gecko_ffi_name, "v.0")}
${set_gecko_property(gecko_ffi_name, "v.to_i32_au()")}
}
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
% if need_clone:
#[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
Au(self.gecko.${gecko_ffi_name})
Au(self.gecko.${gecko_ffi_name}).into()
}
% endif
</%def>
@ -810,16 +810,16 @@ def set_gecko_property(ffi_name, expr):
}
</%def>
<%def name="impl_non_negative_app_units(ident, gecko_ffi_name, need_clone, inherit_from=None,
round_to_pixels=False)">
<%def name="impl_non_negative_length(ident, gecko_ffi_name, need_clone, inherit_from=None,
round_to_pixels=False)">
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
let value = {
% if round_to_pixels:
let au_per_device_px = Au(self.gecko.mTwipsPerPixel);
round_border_to_device_pixels(v.0, au_per_device_px).0
round_border_to_device_pixels(Au::from(v), au_per_device_px).0
% else:
v.value()
v.0.to_i32_au()
% endif
};
@ -1385,11 +1385,11 @@ fn static_assert() {
<% impl_color("border_%s_color" % side.ident, "(mBorderColor)[%s]" % side.index, need_clone=True) %>
<% impl_non_negative_app_units("border_%s_width" % side.ident,
"mComputedBorder.%s" % side.ident,
inherit_from="mBorder.%s" % side.ident,
need_clone=True,
round_to_pixels=True) %>
<% impl_non_negative_length("border_%s_width" % side.ident,
"mComputedBorder.%s" % side.ident,
inherit_from="mBorder.%s" % side.ident,
need_clone=True,
round_to_pixels=True) %>
pub fn border_${side.ident}_has_nonzero_width(&self) -> bool {
self.gecko.mComputedBorder.${side.ident} != 0
@ -2110,9 +2110,9 @@ fn static_assert() {
}
}
<% impl_non_negative_app_units("outline_width", "mActualOutlineWidth",
inherit_from="mOutlineWidth",
need_clone=True, round_to_pixels=True) %>
<% impl_non_negative_length("outline_width", "mActualOutlineWidth",
inherit_from="mOutlineWidth",
need_clone=True, round_to_pixels=True) %>
% for corner in CORNERS:
<% impl_corner_style_coord("_moz_outline_radius_%s" % corner.ident.replace("_", ""),
@ -2248,15 +2248,15 @@ fn static_assert() {
}
pub fn set_font_size(&mut self, v: longhands::font_size::computed_value::T) {
self.gecko.mSize = v.value();
self.gecko.mScriptUnconstrainedSize = v.value();
self.gecko.mSize = v.0.to_i32_au();
self.gecko.mScriptUnconstrainedSize = v.0.to_i32_au();
}
/// Set font size, taking into account scriptminsize and scriptlevel
/// Returns Some(size) if we have to recompute the script unconstrained size
pub fn apply_font_size(&mut self, v: longhands::font_size::computed_value::T,
parent: &Self,
device: &Device) -> Option<NonNegativeAu> {
device: &Device) -> Option<NonNegativeLength> {
let (adjusted_size, adjusted_unconstrained_size) =
self.calculate_script_level_size(parent, device);
// In this case, we have been unaffected by scriptminsize, ignore it
@ -2266,7 +2266,7 @@ fn static_assert() {
self.fixup_font_min_size(device);
None
} else {
self.gecko.mSize = v.value();
self.gecko.mSize = v.0.to_i32_au();
self.fixup_font_min_size(device);
Some(Au(parent.gecko.mScriptUnconstrainedSize).into())
}
@ -2276,8 +2276,8 @@ fn static_assert() {
unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.pres_context()) }
}
pub fn apply_unconstrained_font_size(&mut self, v: NonNegativeAu) {
self.gecko.mScriptUnconstrainedSize = v.value();
pub fn apply_unconstrained_font_size(&mut self, v: NonNegativeLength) {
self.gecko.mScriptUnconstrainedSize = v.0.to_i32_au();
}
/// Calculates the constrained and unconstrained font sizes to be inherited
@ -2387,7 +2387,7 @@ fn static_assert() {
///
/// Returns true if the inherited keyword size was actually used
pub fn inherit_font_size_from(&mut self, parent: &Self,
kw_inherited_size: Option<NonNegativeAu>,
kw_inherited_size: Option<NonNegativeLength>,
device: &Device) -> bool {
let (adjusted_size, adjusted_unconstrained_size)
= self.calculate_script_level_size(parent, device);
@ -2413,9 +2413,9 @@ fn static_assert() {
false
} else if let Some(size) = kw_inherited_size {
// Parent element was a keyword-derived size.
self.gecko.mSize = size.value();
self.gecko.mSize = size.0.to_i32_au();
// MathML constraints didn't apply here, so we can ignore this.
self.gecko.mScriptUnconstrainedSize = size.value();
self.gecko.mScriptUnconstrainedSize = size.0.to_i32_au();
self.fixup_font_min_size(device);
true
} else {
@ -3020,7 +3020,7 @@ fn static_assert() {
# First %s substituted with the call to GetArrayItem, the second
# %s substituted with the corresponding variable
css_value_setters = {
"length" : "bindings::Gecko_CSSValue_SetAbsoluteLength(%s, %s.0)",
"length" : "bindings::Gecko_CSSValue_SetPixelLength(%s, %s.px())",
"percentage" : "bindings::Gecko_CSSValue_SetPercentage(%s, %s.0)",
# Note: This is an integer type, but we use it as a percentage value in Gecko, so
# need to cast it to f32.
@ -3122,7 +3122,7 @@ fn static_assert() {
<%
# %s is substituted with the call to GetArrayItem.
css_value_getters = {
"length" : "Au(bindings::Gecko_CSSValue_GetAbsoluteLength(%s))",
"length" : "Length::new(bindings::Gecko_CSSValue_GetNumber(%s))",
"lop" : "%s.get_lop()",
"angle" : "%s.get_angle()",
"number" : "bindings::Gecko_CSSValue_GetNumber(%s)",
@ -3166,7 +3166,7 @@ fn static_assert() {
use properties::longhands::transform::computed_value::ComputedMatrix;
use properties::longhands::transform::computed_value::ComputedOperation;
use properties::longhands::transform::computed_value::T as TransformList;
use values::computed::Percentage;
use values::computed::{Length, Percentage};
let convert_shared_list_to_operations = |value: &structs::nsCSSValue|
-> Vec<ComputedOperation> {
@ -3460,13 +3460,13 @@ fn static_assert() {
pub fn clone_transform_origin(&self) -> longhands::transform_origin::computed_value::T {
use properties::longhands::transform_origin::computed_value::T;
use values::computed::LengthOrPercentage;
use values::computed::{Length, LengthOrPercentage};
T {
horizontal: LengthOrPercentage::from_gecko_style_coord(&self.gecko.mTransformOrigin[0])
.expect("clone for LengthOrPercentage failed"),
vertical: LengthOrPercentage::from_gecko_style_coord(&self.gecko.mTransformOrigin[1])
.expect("clone for LengthOrPercentage failed"),
depth: Au::from_gecko_style_coord(&self.gecko.mTransformOrigin[2])
depth: Length::from_gecko_style_coord(&self.gecko.mTransformOrigin[2])
.expect("clone for Length failed"),
}
}
@ -4205,14 +4205,14 @@ fn static_assert() {
self.gecko.mImageRegion.height = 0;
}
Either::First(rect) => {
self.gecko.mImageRegion.x = rect.left.unwrap_or(Au(0)).0;
self.gecko.mImageRegion.y = rect.top.unwrap_or(Au(0)).0;
self.gecko.mImageRegion.x = rect.left.map(Au::from).unwrap_or(Au(0)).0;
self.gecko.mImageRegion.y = rect.top.map(Au::from).unwrap_or(Au(0)).0;
self.gecko.mImageRegion.height = match rect.bottom {
Some(value) => value.0 - self.gecko.mImageRegion.y,
Some(value) => (Au::from(value) - Au(self.gecko.mImageRegion.y)).0,
None => 0,
};
self.gecko.mImageRegion.width = match rect.right {
Some(value) => value.0 - self.gecko.mImageRegion.x,
Some(value) => (Au::from(value) - Au(self.gecko.mImageRegion.x)).0,
None => 0,
};
}
@ -4234,10 +4234,10 @@ fn static_assert() {
}
Either::First(ClipRect {
top: Some(Au(self.gecko.mImageRegion.y)),
right: Some(Au(self.gecko.mImageRegion.width) + Au(self.gecko.mImageRegion.x)),
bottom: Some(Au(self.gecko.mImageRegion.height) + Au(self.gecko.mImageRegion.y)),
left: Some(Au(self.gecko.mImageRegion.x)),
top: Some(Au(self.gecko.mImageRegion.y).into()),
right: Some(Au(self.gecko.mImageRegion.width + self.gecko.mImageRegion.x).into()),
bottom: Some(Au(self.gecko.mImageRegion.height + self.gecko.mImageRegion.y).into()),
left: Some(Au(self.gecko.mImageRegion.x).into()),
})
}
@ -4293,28 +4293,28 @@ fn static_assert() {
Either::First(rect) => {
self.gecko.mClipFlags = NS_STYLE_CLIP_RECT as u8;
if let Some(left) = rect.left {
self.gecko.mClip.x = left.0;
self.gecko.mClip.x = left.to_i32_au();
} else {
self.gecko.mClip.x = 0;
self.gecko.mClipFlags |= NS_STYLE_CLIP_LEFT_AUTO as u8;
}
if let Some(top) = rect.top {
self.gecko.mClip.y = top.0;
self.gecko.mClip.y = top.to_i32_au();
} else {
self.gecko.mClip.y = 0;
self.gecko.mClipFlags |= NS_STYLE_CLIP_TOP_AUTO as u8;
}
if let Some(bottom) = rect.bottom {
self.gecko.mClip.height = (bottom - Au(self.gecko.mClip.y)).0;
self.gecko.mClip.height = (Au::from(bottom) - Au(self.gecko.mClip.y)).0;
} else {
self.gecko.mClip.height = 1 << 30; // NS_MAXSIZE
self.gecko.mClipFlags |= NS_STYLE_CLIP_BOTTOM_AUTO as u8;
}
if let Some(right) = rect.right {
self.gecko.mClip.width = (right - Au(self.gecko.mClip.x)).0;
self.gecko.mClip.width = (Au::from(right) - Au(self.gecko.mClip.x)).0;
} else {
self.gecko.mClip.width = 1 << 30; // NS_MAXSIZE
self.gecko.mClipFlags |= NS_STYLE_CLIP_RIGHT_AUTO as u8;
@ -4355,28 +4355,28 @@ fn static_assert() {
debug_assert!(self.gecko.mClip.x == 0);
None
} else {
Some(Au(self.gecko.mClip.x))
Some(Au(self.gecko.mClip.x).into())
};
let top = if self.gecko.mClipFlags & NS_STYLE_CLIP_TOP_AUTO as u8 != 0 {
debug_assert!(self.gecko.mClip.y == 0);
None
} else {
Some(Au(self.gecko.mClip.y))
Some(Au(self.gecko.mClip.y).into())
};
let bottom = if self.gecko.mClipFlags & NS_STYLE_CLIP_BOTTOM_AUTO as u8 != 0 {
debug_assert!(self.gecko.mClip.height == 1 << 30); // NS_MAXSIZE
None
} else {
Some(Au(self.gecko.mClip.y + self.gecko.mClip.height))
Some(Au(self.gecko.mClip.y + self.gecko.mClip.height).into())
};
let right = if self.gecko.mClipFlags & NS_STYLE_CLIP_RIGHT_AUTO as u8 != 0 {
debug_assert!(self.gecko.mClip.width == 1 << 30); // NS_MAXSIZE
None
} else {
Some(Au(self.gecko.mClip.x + self.gecko.mClip.width))
Some(Au(self.gecko.mClip.x + self.gecko.mClip.width).into())
};
Either::First(ClipRect { top: top, right: right, bottom: bottom, left: left, })
@ -4430,7 +4430,7 @@ fn static_assert() {
gecko_filter),
% endfor
Blur(length) => fill_filter(NS_STYLE_FILTER_BLUR,
CoordDataValue::Coord(length.value()),
CoordDataValue::Coord(length.0.to_i32_au()),
gecko_filter),
HueRotate(angle) => fill_filter(NS_STYLE_FILTER_HUE_ROTATE,
@ -4498,7 +4498,7 @@ fn static_assert() {
},
% endfor
NS_STYLE_FILTER_BLUR => {
filters.push(Filter::Blur(NonNegativeAu::from_gecko_style_coord(
filters.push(Filter::Blur(NonNegativeLength::from_gecko_style_coord(
&filter.mFilterParameter).unwrap()));
},
NS_STYLE_FILTER_HUE_ROTATE => {
@ -4590,8 +4590,8 @@ fn static_assert() {
skip_longhands="border-spacing">
pub fn set_border_spacing(&mut self, v: longhands::border_spacing::computed_value::T) {
self.gecko.mBorderSpacingCol = v.horizontal.value();
self.gecko.mBorderSpacingRow = v.vertical.value();
self.gecko.mBorderSpacingCol = v.horizontal.0.to_i32_au();
self.gecko.mBorderSpacingRow = v.vertical.0.to_i32_au();
}
pub fn copy_border_spacing_from(&mut self, other: &Self) {
@ -4651,7 +4651,7 @@ fn static_assert() {
// FIXME: Align binary representations and ditch |match| for cast + static_asserts
let en = match v {
LineHeight::Normal => CoordDataValue::Normal,
LineHeight::Length(val) => CoordDataValue::Coord(val.value()),
LineHeight::Length(val) => CoordDataValue::Coord(val.0.to_i32_au()),
LineHeight::Number(val) => CoordDataValue::Factor(val.0),
LineHeight::MozBlockHeight =>
CoordDataValue::Enumerated(structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT),
@ -4682,13 +4682,14 @@ fn static_assert() {
}
pub fn clone_letter_spacing(&self) -> longhands::letter_spacing::computed_value::T {
use values::computed::Length;
use values::generics::text::Spacing;
debug_assert!(
matches!(self.gecko.mLetterSpacing.as_value(),
CoordDataValue::Normal |
CoordDataValue::Coord(_)),
"Unexpected computed value for letter-spacing");
Au::from_gecko_style_coord(&self.gecko.mLetterSpacing).map_or(Spacing::Normal, Spacing::Value)
Length::from_gecko_style_coord(&self.gecko.mLetterSpacing).map_or(Spacing::Normal, Spacing::Value)
}
<%call expr="impl_coord_copy('letter_spacing', 'mLetterSpacing')"></%call>
@ -4798,9 +4799,9 @@ fn static_assert() {
})
}
<%call expr="impl_non_negative_app_units('_webkit_text_stroke_width',
'mWebkitTextStrokeWidth',
need_clone=True)"></%call>
<%call expr="impl_non_negative_length('_webkit_text_stroke_width',
'mWebkitTextStrokeWidth',
need_clone=True)"></%call>
#[allow(non_snake_case)]
pub fn set__moz_tab_size(&mut self, v: longhands::_moz_tab_size::computed_value::T) {
@ -4810,8 +4811,8 @@ fn static_assert() {
Either::Second(non_negative_number) => {
self.gecko.mTabSize.set_value(CoordDataValue::Factor(non_negative_number.0));
}
Either::First(non_negative_au) => {
self.gecko.mTabSize.set(non_negative_au.0);
Either::First(non_negative_length) => {
self.gecko.mTabSize.set(non_negative_length);
}
}
}
@ -5461,8 +5462,8 @@ clip-path
}
}
<% impl_non_negative_app_units("column_rule_width", "mColumnRuleWidth", need_clone=True,
round_to_pixels=True) %>
<% impl_non_negative_length("column_rule_width", "mColumnRuleWidth", need_clone=True,
round_to_pixels=True) %>
</%self:impl_trait>
<%self:impl_trait style_struct_name="Counters"

View file

@ -48,7 +48,7 @@ use values::animated::effects::TextShadowList as AnimatedTextShadowList;
use values::computed::{Angle, BorderCornerRadius, CalcLengthOrPercentage};
use values::computed::{ClipRect, Context, ComputedUrl};
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use values::computed::{LengthOrPercentageOrNone, MaxLength, NonNegativeAu};
use values::computed::{LengthOrPercentageOrNone, MaxLength, NonNegativeLength};
use values::computed::{NonNegativeNumber, Number, NumberOrPercentage, Percentage};
use values::computed::{PositiveIntegerOrAuto, ToComputedValue};
#[cfg(feature = "gecko")] use values::computed::MozLength;
@ -1094,7 +1094,8 @@ impl<H, V> RepeatableListAnimatable for generic_position::Position<H, V>
impl Animate for ClipRect {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
let animate_component = |this: &Option<Au>, other: &Option<Au>| {
use values::computed::Length;
let animate_component = |this: &Option<Length>, other: &Option<Length>| {
match (this.animate(other, procedure)?, procedure) {
(None, Procedure::Interpolate { .. }) => Ok(None),
(None, _) => Err(()),
@ -1244,11 +1245,11 @@ impl Animate for TransformOperation {
) => {
let mut fd_matrix = ComputedMatrix::identity();
let mut td_matrix = ComputedMatrix::identity();
if fd.0 > 0 {
fd_matrix.m34 = -1. / fd.to_f32_px();
if fd.px() > 0. {
fd_matrix.m34 = -1. / fd.px();
}
if td.0 > 0 {
td_matrix.m34 = -1. / td.to_f32_px();
if td.px() > 0. {
td_matrix.m34 = -1. / td.px();
}
Ok(TransformOperation::Matrix(
fd_matrix.animate(&td_matrix, procedure)?,
@ -2327,7 +2328,7 @@ impl ComputeSquaredDistance for TransformOperation {
Ok(
fx.compute_squared_distance(&tx)? +
fy.compute_squared_distance(&ty)? +
fz.to_f64_px().compute_squared_distance(&tz.to_f64_px())?,
fz.compute_squared_distance(&tz)?,
)
},
(
@ -2364,12 +2365,12 @@ impl ComputeSquaredDistance for TransformOperation {
) => {
let mut fd_matrix = ComputedMatrix::identity();
let mut td_matrix = ComputedMatrix::identity();
if fd.0 > 0 {
fd_matrix.m34 = -1. / fd.to_f32_px();
if fd.px() > 0. {
fd_matrix.m34 = -1. / fd.px();
}
if td.0 > 0 {
td_matrix.m34 = -1. / td.to_f32_px();
if td.px() > 0. {
td_matrix.m34 = -1. / td.px();
}
fd_matrix.compute_squared_distance(&td_matrix)
}
@ -2381,8 +2382,8 @@ impl ComputeSquaredDistance for TransformOperation {
&TransformOperation::Perspective(ref p),
) => {
let mut p_matrix = ComputedMatrix::identity();
if p.0 > 0 {
p_matrix.m34 = -1. / p.to_f32_px();
if p.px() > 0. {
p_matrix.m34 = -1. / p.px();
}
p_matrix.compute_squared_distance(&m)
}

View file

@ -42,11 +42,11 @@
${helpers.predefined_type("border-%s-width" % side_name,
"BorderSideWidth",
"::values::computed::NonNegativeAu::from_px(3)",
computed_type="::values::computed::NonNegativeAu",
"::values::computed::NonNegativeLength::new(3.)",
computed_type="::values::computed::NonNegativeLength",
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-width"),
spec=maybe_logical_spec(side, "width"),
animation_value_type="NonNegativeAu",
animation_value_type="NonNegativeLength",
logical=is_logical,
flags="APPLIES_TO_FIRST_LETTER",
allow_quirks=not is_logical)}

View file

@ -620,7 +620,6 @@ ${helpers.predefined_type(
animation_value_type="ComputedValue"
flags="CREATES_STACKING_CONTEXT FIXPOS_CB"
spec="https://drafts.csswg.org/css-transforms/#propdef-transform">
use app_units::Au;
use values::computed::{LengthOrPercentageOrNumber as ComputedLoPoNumber, LengthOrNumber as ComputedLoN};
use values::computed::{LengthOrPercentage as ComputedLoP, Length as ComputedLength};
use values::generics::transform::Matrix;
@ -631,7 +630,6 @@ ${helpers.predefined_type(
use std::fmt;
pub mod computed_value {
use app_units::Au;
use values::CSSFloat;
use values::computed;
use values::computed::{Length, LengthOrPercentage};
@ -673,7 +671,7 @@ ${helpers.predefined_type(
m21: 0.0, m22: 1.0, m23: 0.0, m24: 0.0,
m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0,
m41: LengthOrPercentage::zero(), m42: LengthOrPercentage::zero(),
m43: Au(0), m44: 1.0
m43: Length::new(0.), m44: 1.0
}
}
}
@ -1252,7 +1250,7 @@ ${helpers.predefined_type(
result.push(computed_value::ComputedOperation::Translate(
tx,
computed::length::LengthOrPercentage::zero(),
computed::length::Length::new(0)));
computed::length::Length::new(0.)));
}
SpecifiedOperation::Translate(ref tx, Some(ref ty)) => {
let tx = tx.to_computed_value(context);
@ -1260,21 +1258,21 @@ ${helpers.predefined_type(
result.push(computed_value::ComputedOperation::Translate(
tx,
ty,
computed::length::Length::new(0)));
computed::length::Length::new(0.)));
}
SpecifiedOperation::TranslateX(ref tx) => {
let tx = tx.to_computed_value(context);
result.push(computed_value::ComputedOperation::Translate(
tx,
computed::length::LengthOrPercentage::zero(),
computed::length::Length::new(0)));
computed::length::Length::new(0.)));
}
SpecifiedOperation::TranslateY(ref ty) => {
let ty = ty.to_computed_value(context);
result.push(computed_value::ComputedOperation::Translate(
computed::length::LengthOrPercentage::zero(),
ty,
computed::length::Length::new(0)));
computed::length::Length::new(0.)));
}
SpecifiedOperation::TranslateZ(ref tz) => {
let tz = tz.to_computed_value(context);
@ -1484,6 +1482,7 @@ ${helpers.predefined_type(
// Converts computed LengthOrPercentageOrNumber into computed
// LengthOrPercentage. Number maps into Length
fn lopon_to_lop(value: &ComputedLoPoNumber) -> ComputedLoP {
use app_units::Au;
match *value {
Either::First(number) => ComputedLoP::Length(Au::from_f32_px(number)),
Either::Second(length_or_percentage) => length_or_percentage,
@ -1495,7 +1494,7 @@ ${helpers.predefined_type(
fn lon_to_length(value: &ComputedLoN) -> ComputedLength {
match *value {
Either::First(length) => length,
Either::Second(number) => Au::from_f32_px(number),
Either::Second(number) => ComputedLength::new(number),
}
}
</%helpers:longhand>

View file

@ -39,12 +39,12 @@ ${helpers.single_keyword("column-fill", "balance auto", extra_prefixes="moz",
${helpers.predefined_type("column-rule-width",
"BorderSideWidth",
"::values::computed::NonNegativeAu::from_px(3)",
"::values::computed::NonNegativeLength::new(3.)",
initial_specified_value="specified::BorderSideWidth::Medium",
computed_type="::values::computed::NonNegativeAu",
computed_type="::values::computed::NonNegativeLength",
products="gecko",
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width",
animation_value_type="NonNegativeAu",
animation_value_type="NonNegativeLength",
extra_prefixes="moz")}
// https://drafts.csswg.org/css-multicol-1/#crc

View file

@ -589,7 +589,7 @@ ${helpers.single_keyword_system("font-variant-caps",
}
</%helpers:longhand>
<%helpers:longhand name="font-size" need_clone="True" animation_value_type="NonNegativeAu"
<%helpers:longhand name="font-size" need_clone="True" animation_value_type="NonNegativeLength"
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size">
use app_units::Au;
@ -597,7 +597,7 @@ ${helpers.single_keyword_system("font-variant-caps",
use std::fmt;
use style_traits::ToCss;
use values::FONT_MEDIUM_PX;
use values::computed::NonNegativeAu;
use values::computed::NonNegativeLength;
use values::specified::{AllowQuirks, FontRelativeLength, LengthOrPercentage, NoCalcLength};
use values::specified::length::FontBaseSize;
@ -627,7 +627,7 @@ ${helpers.single_keyword_system("font-variant-caps",
/// go into the ratio, and the remaining units all computed together
/// will go into the offset.
/// See bug 1355707.
Keyword(KeywordSize, f32, NonNegativeAu),
Keyword(KeywordSize, f32, NonNegativeLength),
Smaller,
Larger,
System(SystemFont)
@ -640,8 +640,8 @@ ${helpers.single_keyword_system("font-variant-caps",
}
pub mod computed_value {
use values::computed::NonNegativeAu;
pub type T = NonNegativeAu;
use values::computed::NonNegativeLength;
pub type T = NonNegativeLength;
}
/// CSS font keywords
@ -716,7 +716,7 @@ ${helpers.single_keyword_system("font-variant-caps",
% if product == "servo":
impl ToComputedValue for KeywordSize {
type ComputedValue = NonNegativeAu;
type ComputedValue = NonNegativeLength;
#[inline]
fn to_computed_value(&self, _: &Context) -> computed_value::T {
// https://drafts.csswg.org/css-fonts-3/#font-size-prop
@ -740,7 +740,7 @@ ${helpers.single_keyword_system("font-variant-caps",
}
% else:
impl ToComputedValue for KeywordSize {
type ComputedValue = NonNegativeAu;
type ComputedValue = NonNegativeLength;
#[inline]
fn to_computed_value(&self, cx: &Context) -> computed_value::T {
use gecko_bindings::structs::nsIAtom;
@ -776,7 +776,7 @@ ${helpers.single_keyword_system("font-variant-caps",
let base_size_px = au_to_int_px(base_size as f32);
let html_size = self.html_size() as usize;
if base_size_px >= 9 && base_size_px <= 16 {
NonNegativeAu::from_px(FONT_SIZE_MAPPING[(base_size_px - 9) as usize][html_size])
NonNegativeLength::new(FONT_SIZE_MAPPING[(base_size_px - 9) as usize][html_size] as f32)
} else {
Au(FONT_SIZE_FACTORS[html_size] * base_size / 100).into()
}
@ -811,17 +811,17 @@ ${helpers.single_keyword_system("font-variant-caps",
/// If this value is specified as a ratio of the parent font (em units
/// or percent) return the ratio
pub fn as_font_ratio(&self, context: &Context) -> Option<(f32, NonNegativeAu)> {
pub fn as_font_ratio(&self, context: &Context) -> Option<(f32, NonNegativeLength)> {
match *self {
SpecifiedValue::Length(ref lop) => {
match *lop {
LengthOrPercentage::Percentage(pc) => {
Some((pc.0, Au(0).into()))
Some((pc.0, NonNegativeLength::zero()))
}
LengthOrPercentage::Length(ref nocalc) => {
match *nocalc {
NoCalcLength::FontRelative(FontRelativeLength::Em(em)) => {
Some((em, Au(0).into()))
Some((em, NonNegativeLength::zero()))
}
_ => None,
}
@ -837,7 +837,7 @@ ${helpers.single_keyword_system("font-variant-caps",
// to do here -- Gecko recascades as if the font had changed, we instead track the changes
// and reapply, which means that we carry over old computed ex/ch values whilst Gecko
// recomputes new ones. This is enough of an edge case to not really matter.
let abs = calc.to_computed_value_zoomed(context, FontBaseSize::Custom(Au(0).into()))
let abs = calc.to_computed_value_zoomed(context, FontBaseSize::Custom(Au(0)))
.length_component().into();
Some((ratio, abs))
}
@ -854,7 +854,7 @@ ${helpers.single_keyword_system("font-variant-caps",
&self,
context: &Context,
base_size: FontBaseSize,
) -> NonNegativeAu {
) -> NonNegativeLength {
use values::specified::length::FontRelativeLength;
match *self {
SpecifiedValue::Length(LengthOrPercentage::Length(
@ -867,7 +867,7 @@ ${helpers.single_keyword_system("font-variant-caps",
}
SpecifiedValue::Length(LengthOrPercentage::Length(
NoCalcLength::Absolute(ref l))) => {
context.maybe_zoom_text(l.to_computed_value(context).into())
context.maybe_zoom_text(l.to_computed_value(context)).into()
}
SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => {
l.to_computed_value(context).into()
@ -880,7 +880,8 @@ ${helpers.single_keyword_system("font-variant-caps",
calc.to_used_value(Some(base_size.resolve(context))).unwrap().into()
}
SpecifiedValue::Keyword(ref key, fraction, offset) => {
context.maybe_zoom_text(key.to_computed_value(context).scale_by(fraction) + offset)
let key_len = key.to_computed_value(context).scale_by(fraction) + offset;
context.maybe_zoom_text(key_len.0).into()
}
SpecifiedValue::Smaller => {
FontRelativeLength::Em(1. / LARGER_FONT_SIZE_RATIO)
@ -903,7 +904,7 @@ ${helpers.single_keyword_system("font-variant-caps",
#[inline]
#[allow(missing_docs)]
pub fn get_initial_value() -> computed_value::T {
NonNegativeAu::from_px(FONT_MEDIUM_PX)
NonNegativeLength::new(FONT_MEDIUM_PX as f32)
}
#[inline]
@ -970,7 +971,7 @@ ${helpers.single_keyword_system("font-variant-caps",
#[allow(unused_mut)]
pub fn cascade_specified_font_size(context: &mut Context,
specified_value: &SpecifiedValue,
mut computed: NonNegativeAu) {
mut computed: NonNegativeLength) {
if let SpecifiedValue::Keyword(kw, fraction, offset) = *specified_value {
context.builder.font_size_keyword = Some((kw, fraction, offset));
} else if let Some((ratio, abs)) = specified_value.as_font_ratio(context) {
@ -982,7 +983,7 @@ ${helpers.single_keyword_system("font-variant-caps",
// See bug 1355707
if let Some((kw, fraction, old_abs)) = *context.builder.inherited_font_computation_data() {
context.builder.font_size_keyword =
Some((kw, fraction * ratio, abs + old_abs.0.scale_by(ratio).into()));
Some((kw, fraction * ratio, abs + old_abs.scale_by(ratio)));
} else {
context.builder.font_size_keyword = None;
}
@ -1001,7 +1002,8 @@ ${helpers.single_keyword_system("font-variant-caps",
context.builder.get_font().gecko().mGenericID !=
context.builder.get_parent_font().gecko().mGenericID {
if let Some((kw, ratio, offset)) = context.builder.font_size_keyword {
computed = context.maybe_zoom_text(kw.to_computed_value(context).scale_by(ratio) + offset);
let len = kw.to_computed_value(context).scale_by(ratio) + offset;
computed = context.maybe_zoom_text(len.0).into();
}
}
% endif
@ -1017,7 +1019,7 @@ ${helpers.single_keyword_system("font-variant-caps",
if let Some(parent) = parent_unconstrained {
let new_unconstrained =
specified_value
.to_computed_value_against(context, FontBaseSize::Custom(parent.0));
.to_computed_value_against(context, FontBaseSize::Custom(Au::from(parent)));
context.builder
.mutate_font()
.apply_unconstrained_font_size(new_unconstrained);
@ -1031,7 +1033,8 @@ ${helpers.single_keyword_system("font-variant-caps",
// changes using the font_size_keyword. We also need to do this to
// handle mathml scriptlevel changes
let kw_inherited_size = context.builder.font_size_keyword.map(|(kw, ratio, offset)| {
context.maybe_zoom_text(SpecifiedValue::Keyword(kw, ratio, offset).to_computed_value(context))
let len = SpecifiedValue::Keyword(kw, ratio, offset).to_computed_value(context);
context.maybe_zoom_text(len.0).into()
});
let parent_kw;
let device = context.builder.device;
@ -1058,8 +1061,8 @@ ${helpers.single_keyword_system("font-variant-caps",
// compute to the same value and depends on the font
let computed = context.maybe_zoom_text(
longhands::font_size::get_initial_specified_value()
.to_computed_value(context)
);
.to_computed_value(context).0
).into();
context.builder.mutate_font().set_font_size(computed);
% if product == "gecko":
let device = context.builder.device;
@ -2351,21 +2354,21 @@ ${helpers.single_keyword("-moz-math-variant",
predefined_type="Length" gecko_ffi_name="mScriptMinSize"
spec="Internal (not web-exposed)"
internal="True">
use app_units::Au;
use gecko_bindings::structs::NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT;
use values::specified::length::{AU_PER_PT, FontBaseSize, NoCalcLength};
use values::computed::Length;
use values::specified::length::{AU_PER_PT, AU_PER_PX, FontBaseSize, NoCalcLength};
#[derive(Clone, Debug, PartialEq, ToCss)]
pub struct SpecifiedValue(pub NoCalcLength);
pub mod computed_value {
pub type T = super::Au;
pub type T = ::values::computed::Length;
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
fn to_computed_value(&self, cx: &Context) -> Au {
fn to_computed_value(&self, cx: &Context) -> Length {
// this value is used in the computation of font-size, so
// we use the parent size
let base_size = FontBaseSize::InheritedStyle;
@ -2388,7 +2391,7 @@ ${helpers.single_keyword("-moz-math-variant",
#[inline]
pub fn get_initial_value() -> computed_value::T {
Au((NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT as f32 * AU_PER_PT) as i32)
Length::new(NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT as f32 * (AU_PER_PT / AU_PER_PX))
}
pub fn parse<'i, 't>(_context: &ParserContext, _input: &mut Parser<'i, 't>)

View file

@ -65,7 +65,7 @@ ${helpers.predefined_type(
${helpers.predefined_type(
"stroke-width", "SVGWidth",
"::values::computed::NonNegativeAu::from_px(1).into()",
"::values::computed::NonNegativeLength::new(1.).into()",
products="gecko",
boxed="True",
animation_value_type="::values::computed::SVGWidth",

View file

@ -27,13 +27,13 @@ ${helpers.single_keyword("caption-side", "top bottom",
pub mod computed_value {
use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::NonNegativeAu;
use values::computed::NonNegativeLength;
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToCss)]
pub struct T {
pub horizontal: NonNegativeAu,
pub vertical: NonNegativeAu,
pub horizontal: NonNegativeLength,
pub vertical: NonNegativeLength,
}
impl ToAnimatedZero for T {
@ -68,10 +68,10 @@ ${helpers.single_keyword("caption-side", "top bottom",
#[inline]
pub fn get_initial_value() -> computed_value::T {
use values::computed::NonNegativeAu;
use values::computed::NonNegativeLength as ComputedNonNegativeLength;
computed_value::T {
horizontal: NonNegativeAu::zero(),
vertical: NonNegativeAu::zero(),
horizontal: ComputedNonNegativeLength::zero(),
vertical: ComputedNonNegativeLength::zero(),
}
}

View file

@ -741,9 +741,9 @@ ${helpers.predefined_type(
${helpers.predefined_type("-webkit-text-stroke-width",
"BorderSideWidth",
"::values::computed::NonNegativeAu::from_px(0)",
"::values::computed::NonNegativeLength::new(0.)",
initial_specified_value="specified::BorderSideWidth::Length(specified::Length::zero())",
computed_type="::values::computed::NonNegativeAu",
computed_type="::values::computed::NonNegativeLength",
products="gecko",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width",

View file

@ -69,10 +69,10 @@ ${helpers.predefined_type(
${helpers.predefined_type("outline-width",
"BorderSideWidth",
"::values::computed::NonNegativeAu::from_px(3)",
"::values::computed::NonNegativeLength::new(3.)",
initial_specified_value="specified::BorderSideWidth::Medium",
computed_type="::values::computed::NonNegativeAu",
animation_value_type="NonNegativeAu",
computed_type="::values::computed::NonNegativeLength",
animation_value_type="NonNegativeLength",
spec="https://drafts.csswg.org/css-ui/#propdef-outline-width")}
// The -moz-outline-radius-* properties are non-standard and not on a standards track.
@ -85,6 +85,6 @@ ${helpers.predefined_type("outline-width",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-outline-radius)")}
% endfor
${helpers.predefined_type("outline-offset", "Length", "Au(0)", products="servo gecko",
animation_value_type="ComputedValue",
${helpers.predefined_type("outline-offset", "Length", "::values::computed::Length::new(0.)",
products="servo gecko", animation_value_type="ComputedValue",
spec="https://drafts.csswg.org/css-ui/#propdef-outline-offset")}

View file

@ -44,7 +44,7 @@ use stylesheets::{CssRuleType, Origin, UrlExtraData};
#[cfg(feature = "servo")] use values::Either;
use values::generics::text::LineHeight;
use values::computed;
use values::computed::NonNegativeAu;
use values::computed::NonNegativeLength;
use rule_tree::{CascadeLevel, StrongRuleNode};
use self::computed_value_flags::ComputedValueFlags;
use style_adjuster::StyleAdjuster;
@ -110,7 +110,7 @@ pub trait MaybeBoxed<Out> {
/// When this is Some, we compute font sizes by computing the keyword against
/// the generic font, and then multiplying it by the ratio (as well as adding any
/// absolute offset from calcs)
pub type FontComputationData = Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>;
pub type FontComputationData = Option<(longhands::font_size::KeywordSize, f32, NonNegativeLength)>;
/// Default value for FontComputationData
pub fn default_font_size_keyword() -> FontComputationData {
@ -1690,7 +1690,7 @@ pub mod style_structs {
use std::hash::{Hash, Hasher};
use logical_geometry::WritingMode;
use media_queries::Device;
use values::computed::NonNegativeAu;
use values::computed::NonNegativeLength;
% for style_struct in data.active_style_structs():
% if style_struct.name == "Font":
@ -1790,7 +1790,7 @@ pub mod style_structs {
/// Whether the border-${side} property has nonzero width.
#[allow(non_snake_case)]
pub fn border_${side}_has_nonzero_width(&self) -> bool {
self.border_${side}_width != NonNegativeAu::zero()
self.border_${side}_width != NonNegativeLength::zero()
}
% endfor
% elif style_struct.name == "Font":
@ -1808,7 +1808,7 @@ pub mod style_structs {
/// (Servo does not handle MathML, so this just calls copy_font_size_from)
pub fn inherit_font_size_from(&mut self, parent: &Self,
_: Option<NonNegativeAu>,
_: Option<NonNegativeLength>,
_: &Device) -> bool {
self.copy_font_size_from(parent);
false
@ -1817,19 +1817,19 @@ pub mod style_structs {
pub fn apply_font_size(&mut self,
v: longhands::font_size::computed_value::T,
_: &Self,
_: &Device) -> Option<NonNegativeAu> {
_: &Device) -> Option<NonNegativeLength> {
self.set_font_size(v);
None
}
/// (Servo does not handle MathML, so this does nothing)
pub fn apply_unconstrained_font_size(&mut self, _: NonNegativeAu) {
pub fn apply_unconstrained_font_size(&mut self, _: NonNegativeLength) {
}
% elif style_struct.name == "Outline":
/// Whether the outline-width property is non-zero.
#[inline]
pub fn outline_has_nonzero_width(&self) -> bool {
self.outline_width != NonNegativeAu::zero()
self.outline_width != NonNegativeLength::zero()
}
% elif style_struct.name == "Text":
/// Whether the text decoration has an underline.
@ -2241,10 +2241,10 @@ impl ComputedValuesInner {
pub fn border_width_for_writing_mode(&self, writing_mode: WritingMode) -> LogicalMargin<Au> {
let border_style = self.get_border();
LogicalMargin::from_physical(writing_mode, SideOffsets2D::new(
border_style.border_top_width.0,
border_style.border_right_width.0,
border_style.border_bottom_width.0,
border_style.border_left_width.0,
Au::from(border_style.border_top_width),
Au::from(border_style.border_right_width),
Au::from(border_style.border_bottom_width),
Au::from(border_style.border_left_width),
))
}
@ -2326,7 +2326,7 @@ impl ComputedValuesInner {
}
}
computed_values::transform::ComputedOperation::Translate(_, _, z) => {
if z != Au(0) {
if z.px() != 0. {
return true;
}
}
@ -3407,7 +3407,7 @@ pub fn adjust_border_width(style: &mut StyleBuilder) {
// Like calling to_computed_value, which wouldn't type check.
if style.get_border().clone_border_${side}_style().none_or_hidden() &&
style.get_border().border_${side}_has_nonzero_width() {
style.set_border_${side}_width(NonNegativeAu::zero());
style.set_border_${side}_width(NonNegativeLength::zero());
}
% endfor
}
@ -3431,7 +3431,7 @@ pub fn modify_border_style_for_inline_sides(style: &mut Arc<ComputedValues>,
PhysicalSide::Top => (border.border_top_width, border.border_top_style),
PhysicalSide::Bottom => (border.border_bottom_width, border.border_bottom_style),
};
if current_style == (NonNegativeAu::zero(), BorderStyle::none) {
if current_style == (NonNegativeLength::zero(), BorderStyle::none) {
return;
}
}
@ -3439,19 +3439,19 @@ pub fn modify_border_style_for_inline_sides(style: &mut Arc<ComputedValues>,
let border = Arc::make_mut(&mut style.border);
match side {
PhysicalSide::Left => {
border.border_left_width = NonNegativeAu::zero();
border.border_left_width = NonNegativeLength::zero();
border.border_left_style = BorderStyle::none;
}
PhysicalSide::Right => {
border.border_right_width = NonNegativeAu::zero();
border.border_right_width = NonNegativeLength::zero();
border.border_right_style = BorderStyle::none;
}
PhysicalSide::Bottom => {
border.border_bottom_width = NonNegativeAu::zero();
border.border_bottom_width = NonNegativeLength::zero();
border.border_bottom_style = BorderStyle::none;
}
PhysicalSide::Top => {
border.border_top_width = NonNegativeAu::zero();
border.border_top_width = NonNegativeLength::zero();
border.border_top_style = BorderStyle::none;
}
}