mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Auto merge of #19186 - emilio:derive-more-stuff, r=nox
style: Derive more stuff <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19186) <!-- Reviewable:end -->
This commit is contained in:
commit
fad4d7ae49
16 changed files with 171 additions and 260 deletions
|
@ -1315,14 +1315,14 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
LineDirection::Angle(angle) => angle.radians(),
|
LineDirection::Angle(angle) => angle.radians(),
|
||||||
LineDirection::Horizontal(x) => {
|
LineDirection::Horizontal(x) => {
|
||||||
match x {
|
match x {
|
||||||
X::Left => Angle::Degree(270.).radians(),
|
X::Left => Angle::Deg(270.).radians(),
|
||||||
X::Right => Angle::Degree(90.).radians(),
|
X::Right => Angle::Deg(90.).radians(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LineDirection::Vertical(y) => {
|
LineDirection::Vertical(y) => {
|
||||||
match y {
|
match y {
|
||||||
Y::Top => Angle::Degree(0.).radians(),
|
Y::Top => Angle::Deg(0.).radians(),
|
||||||
Y::Bottom => Angle::Degree(180.).radians(),
|
Y::Bottom => Angle::Deg(180.).radians(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LineDirection::Corner(horizontal, vertical) => {
|
LineDirection::Corner(horizontal, vertical) => {
|
||||||
|
|
|
@ -116,9 +116,9 @@ impl From<nsStyleCoord_CalcValue> for LengthOrPercentageOrAuto {
|
||||||
impl From<Angle> for CoordDataValue {
|
impl From<Angle> for CoordDataValue {
|
||||||
fn from(reference: Angle) -> Self {
|
fn from(reference: Angle) -> Self {
|
||||||
match reference {
|
match reference {
|
||||||
Angle::Degree(val) => CoordDataValue::Degree(val),
|
Angle::Deg(val) => CoordDataValue::Degree(val),
|
||||||
Angle::Gradian(val) => CoordDataValue::Grad(val),
|
Angle::Grad(val) => CoordDataValue::Grad(val),
|
||||||
Angle::Radian(val) => CoordDataValue::Radian(val),
|
Angle::Rad(val) => CoordDataValue::Radian(val),
|
||||||
Angle::Turn(val) => CoordDataValue::Turn(val),
|
Angle::Turn(val) => CoordDataValue::Turn(val),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,9 +128,9 @@ impl Angle {
|
||||||
/// Converts Angle struct into (value, unit) pair.
|
/// Converts Angle struct into (value, unit) pair.
|
||||||
pub fn to_gecko_values(&self) -> (f32, nsCSSUnit) {
|
pub fn to_gecko_values(&self) -> (f32, nsCSSUnit) {
|
||||||
match *self {
|
match *self {
|
||||||
Angle::Degree(val) => (val, nsCSSUnit::eCSSUnit_Degree),
|
Angle::Deg(val) => (val, nsCSSUnit::eCSSUnit_Degree),
|
||||||
Angle::Gradian(val) => (val, nsCSSUnit::eCSSUnit_Grad),
|
Angle::Grad(val) => (val, nsCSSUnit::eCSSUnit_Grad),
|
||||||
Angle::Radian(val) => (val, nsCSSUnit::eCSSUnit_Radian),
|
Angle::Rad(val) => (val, nsCSSUnit::eCSSUnit_Radian),
|
||||||
Angle::Turn(val) => (val, nsCSSUnit::eCSSUnit_Turn),
|
Angle::Turn(val) => (val, nsCSSUnit::eCSSUnit_Turn),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,9 +138,9 @@ impl Angle {
|
||||||
/// Converts gecko (value, unit) pair into Angle struct
|
/// Converts gecko (value, unit) pair into Angle struct
|
||||||
pub fn from_gecko_values(value: f32, unit: nsCSSUnit) -> Angle {
|
pub fn from_gecko_values(value: f32, unit: nsCSSUnit) -> Angle {
|
||||||
match unit {
|
match unit {
|
||||||
nsCSSUnit::eCSSUnit_Degree => Angle::Degree(value),
|
nsCSSUnit::eCSSUnit_Degree => Angle::Deg(value),
|
||||||
nsCSSUnit::eCSSUnit_Grad => Angle::Gradian(value),
|
nsCSSUnit::eCSSUnit_Grad => Angle::Grad(value),
|
||||||
nsCSSUnit::eCSSUnit_Radian => Angle::Radian(value),
|
nsCSSUnit::eCSSUnit_Radian => Angle::Rad(value),
|
||||||
nsCSSUnit::eCSSUnit_Turn => Angle::Turn(value),
|
nsCSSUnit::eCSSUnit_Turn => Angle::Turn(value),
|
||||||
_ => panic!("Unexpected unit {:?} for angle", unit),
|
_ => panic!("Unexpected unit {:?} for angle", unit),
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ use style_traits::{CSSPixel, DevicePixel};
|
||||||
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
||||||
use style_traits::viewport::ViewportConstraints;
|
use style_traits::viewport::ViewportConstraints;
|
||||||
use stylesheets::Origin;
|
use stylesheets::Origin;
|
||||||
use values::{CSSFloat, CustomIdent, serialize_dimension};
|
use values::{CSSFloat, CustomIdent};
|
||||||
use values::computed::{self, ToComputedValue};
|
use values::computed::{self, ToComputedValue};
|
||||||
use values::computed::font::FontSize;
|
use values::computed::font::FontSize;
|
||||||
use values::specified::Length;
|
use values::specified::Length;
|
||||||
|
@ -262,13 +262,16 @@ impl PartialEq for Expression {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A resolution.
|
/// A resolution.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||||
pub enum Resolution {
|
pub enum Resolution {
|
||||||
/// Dots per inch.
|
/// Dots per inch.
|
||||||
|
#[css(dimension)]
|
||||||
Dpi(CSSFloat),
|
Dpi(CSSFloat),
|
||||||
/// Dots per pixel.
|
/// Dots per pixel.
|
||||||
|
#[css(dimension)]
|
||||||
Dppx(CSSFloat),
|
Dppx(CSSFloat),
|
||||||
/// Dots per centimeter.
|
/// Dots per centimeter.
|
||||||
|
#[css(dimension)]
|
||||||
Dpcm(CSSFloat),
|
Dpcm(CSSFloat),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,18 +306,6 @@ impl Resolution {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for Resolution {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
|
||||||
where W: fmt::Write,
|
|
||||||
{
|
|
||||||
match *self {
|
|
||||||
Resolution::Dpi(v) => serialize_dimension(v, "dpi", dest),
|
|
||||||
Resolution::Dppx(v) => serialize_dimension(v, "dppx", dest),
|
|
||||||
Resolution::Dpcm(v) => serialize_dimension(v, "dpcm", dest),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A value found or expected in a media expression.
|
/// A value found or expected in a media expression.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum MediaExpressionValue {
|
pub enum MediaExpressionValue {
|
||||||
|
|
|
@ -214,7 +214,7 @@ impl<L: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for TrackBreadth<
|
||||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||||
match *self {
|
match *self {
|
||||||
TrackBreadth::Breadth(ref lop) => lop.to_gecko_style_coord(coord),
|
TrackBreadth::Breadth(ref lop) => lop.to_gecko_style_coord(coord),
|
||||||
TrackBreadth::Flex(fr) => coord.set_value(CoordDataValue::FlexFraction(fr)),
|
TrackBreadth::Fr(fr) => coord.set_value(CoordDataValue::FlexFraction(fr)),
|
||||||
TrackBreadth::Keyword(TrackKeyword::Auto) => coord.set_value(CoordDataValue::Auto),
|
TrackBreadth::Keyword(TrackKeyword::Auto) => coord.set_value(CoordDataValue::Auto),
|
||||||
TrackBreadth::Keyword(TrackKeyword::MinContent) =>
|
TrackBreadth::Keyword(TrackKeyword::MinContent) =>
|
||||||
coord.set_value(CoordDataValue::Enumerated(StyleGridTrackBreadth::MinContent as u32)),
|
coord.set_value(CoordDataValue::Enumerated(StyleGridTrackBreadth::MinContent as u32)),
|
||||||
|
@ -235,7 +235,7 @@ impl<L: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for TrackBreadth<
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
CoordDataValue::FlexFraction(fr) => Some(TrackBreadth::Flex(fr)),
|
CoordDataValue::FlexFraction(fr) => Some(TrackBreadth::Fr(fr)),
|
||||||
CoordDataValue::Auto => Some(TrackBreadth::Keyword(TrackKeyword::Auto)),
|
CoordDataValue::Auto => Some(TrackBreadth::Keyword(TrackKeyword::Auto)),
|
||||||
_ => L::from_gecko_style_coord(coord).map(TrackBreadth::Breadth),
|
_ => L::from_gecko_style_coord(coord).map(TrackBreadth::Breadth),
|
||||||
}
|
}
|
||||||
|
@ -291,9 +291,9 @@ impl GeckoStyleCoordConvertible for Angle {
|
||||||
|
|
||||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||||
match coord.as_value() {
|
match coord.as_value() {
|
||||||
CoordDataValue::Degree(val) => Some(Angle::Degree(val)),
|
CoordDataValue::Degree(val) => Some(Angle::Deg(val)),
|
||||||
CoordDataValue::Grad(val) => Some(Angle::Gradian(val)),
|
CoordDataValue::Grad(val) => Some(Angle::Grad(val)),
|
||||||
CoordDataValue::Radian(val) => Some(Angle::Radian(val)),
|
CoordDataValue::Radian(val) => Some(Angle::Rad(val)),
|
||||||
CoordDataValue::Turn(val) => Some(Angle::Turn(val)),
|
CoordDataValue::Turn(val) => Some(Angle::Turn(val)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,8 @@
|
||||||
//! Computed angles.
|
//! Computed angles.
|
||||||
|
|
||||||
use euclid::Radians;
|
use euclid::Radians;
|
||||||
use std::{f32, f64, fmt};
|
use std::{f32, f64};
|
||||||
use std::f64::consts::PI;
|
use std::f64::consts::PI;
|
||||||
use style_traits::ToCss;
|
|
||||||
use values::CSSFloat;
|
use values::CSSFloat;
|
||||||
use values::animated::{Animate, Procedure};
|
use values::animated::{Animate, Procedure};
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
|
@ -15,23 +14,27 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
/// A computed angle.
|
/// A computed angle.
|
||||||
#[animate(fallback = "Self::animate_fallback")]
|
#[animate(fallback = "Self::animate_fallback")]
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
#[derive(Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
#[derive(Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
#[derive(PartialOrd, ToAnimatedZero)]
|
#[derive(PartialOrd, ToAnimatedZero)]
|
||||||
pub enum Angle {
|
pub enum Angle {
|
||||||
/// An angle with degree unit.
|
/// An angle with degree unit.
|
||||||
Degree(CSSFloat),
|
#[css(dimension)]
|
||||||
|
Deg(CSSFloat),
|
||||||
/// An angle with gradian unit.
|
/// An angle with gradian unit.
|
||||||
Gradian(CSSFloat),
|
#[css(dimension)]
|
||||||
|
Grad(CSSFloat),
|
||||||
/// An angle with radian unit.
|
/// An angle with radian unit.
|
||||||
Radian(CSSFloat),
|
#[css(dimension)]
|
||||||
|
Rad(CSSFloat),
|
||||||
/// An angle with turn unit.
|
/// An angle with turn unit.
|
||||||
|
#[css(dimension)]
|
||||||
Turn(CSSFloat),
|
Turn(CSSFloat),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Angle {
|
impl Angle {
|
||||||
/// Creates a computed `Angle` value from a radian amount.
|
/// Creates a computed `Angle` value from a radian amount.
|
||||||
pub fn from_radians(radians: CSSFloat) -> Self {
|
pub fn from_radians(radians: CSSFloat) -> Self {
|
||||||
Angle::Radian(radians)
|
Angle::Rad(radians)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the amount of radians this angle represents.
|
/// Returns the amount of radians this angle represents.
|
||||||
|
@ -53,17 +56,17 @@ impl Angle {
|
||||||
const RAD_PER_TURN: f64 = PI * 2.0;
|
const RAD_PER_TURN: f64 = PI * 2.0;
|
||||||
|
|
||||||
let radians = match *self {
|
let radians = match *self {
|
||||||
Angle::Degree(val) => val as f64 * RAD_PER_DEG,
|
Angle::Deg(val) => val as f64 * RAD_PER_DEG,
|
||||||
Angle::Gradian(val) => val as f64 * RAD_PER_GRAD,
|
Angle::Grad(val) => val as f64 * RAD_PER_GRAD,
|
||||||
Angle::Turn(val) => val as f64 * RAD_PER_TURN,
|
Angle::Turn(val) => val as f64 * RAD_PER_TURN,
|
||||||
Angle::Radian(val) => val as f64,
|
Angle::Rad(val) => val as f64,
|
||||||
};
|
};
|
||||||
radians.min(f64::MAX).max(f64::MIN)
|
radians.min(f64::MAX).max(f64::MIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an angle that represents a rotation of zero radians.
|
/// Returns an angle that represents a rotation of zero radians.
|
||||||
pub fn zero() -> Self {
|
pub fn zero() -> Self {
|
||||||
Angle::Radian(0.0)
|
Self::from_radians(0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-transitions/#animtype-number>
|
/// <https://drafts.csswg.org/css-transitions/#animtype-number>
|
||||||
|
@ -82,25 +85,6 @@ impl ComputeSquaredDistance for Angle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for Angle {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: fmt::Write,
|
|
||||||
{
|
|
||||||
let mut write = |value: CSSFloat, unit: &str| {
|
|
||||||
value.to_css(dest)?;
|
|
||||||
dest.write_str(unit)
|
|
||||||
};
|
|
||||||
|
|
||||||
match *self {
|
|
||||||
Angle::Degree(val) => write(val, "deg"),
|
|
||||||
Angle::Gradian(val) => write(val, "grad"),
|
|
||||||
Angle::Radian(val) => write(val, "rad"),
|
|
||||||
Angle::Turn(val) => write(val, "turn"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Angle> for Radians<CSSFloat> {
|
impl From<Angle> for Radians<CSSFloat> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(a: Angle) -> Self {
|
fn from(a: Angle) -> Self {
|
||||||
|
|
|
@ -326,12 +326,12 @@ impl ToComputedValue for specified::MozScriptLevel {
|
||||||
let parent = cx.builder.get_parent_font().clone__moz_script_level();
|
let parent = cx.builder.get_parent_font().clone__moz_script_level();
|
||||||
parent as i32 + rel
|
parent as i32 + rel
|
||||||
}
|
}
|
||||||
specified::MozScriptLevel::Absolute(abs) => abs,
|
specified::MozScriptLevel::MozAbsolute(abs) => abs,
|
||||||
};
|
};
|
||||||
cmp::min(int, i8::MAX as i32) as i8
|
cmp::min(int, i8::MAX as i32) as i8
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_computed_value(other: &i8) -> Self {
|
fn from_computed_value(other: &i8) -> Self {
|
||||||
specified::MozScriptLevel::Absolute(*other as i32)
|
specified::MozScriptLevel::MozAbsolute(*other as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use std::{fmt, mem, usize};
|
use std::{fmt, mem, usize};
|
||||||
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
||||||
use values::{CSSFloat, CustomIdent, serialize_dimension};
|
use values::{CSSFloat, CustomIdent};
|
||||||
use values::computed::{Context, ToComputedValue};
|
use values::computed::{Context, ToComputedValue};
|
||||||
use values::specified;
|
use values::specified;
|
||||||
use values::specified::grid::parse_line_names;
|
use values::specified::grid::parse_line_names;
|
||||||
|
@ -143,12 +143,13 @@ add_impls_for_keyword_enum!(TrackKeyword);
|
||||||
/// avoid re-implementing it for the computed type.
|
/// avoid re-implementing it for the computed type.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-grid/#typedef-track-breadth>
|
/// <https://drafts.csswg.org/css-grid/#typedef-track-breadth>
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
pub enum TrackBreadth<L> {
|
pub enum TrackBreadth<L> {
|
||||||
/// The generic type is almost always a non-negative `<length-percentage>`
|
/// The generic type is almost always a non-negative `<length-percentage>`
|
||||||
Breadth(L),
|
Breadth(L),
|
||||||
/// A flex fraction specified in `fr` units.
|
/// A flex fraction specified in `fr` units.
|
||||||
Flex(CSSFloat),
|
#[css(dimension)]
|
||||||
|
Fr(CSSFloat),
|
||||||
/// One of the track-sizing keywords (`auto`, `min-content`, `max-content`)
|
/// One of the track-sizing keywords (`auto`, `min-content`, `max-content`)
|
||||||
Keyword(TrackKeyword),
|
Keyword(TrackKeyword),
|
||||||
}
|
}
|
||||||
|
@ -166,16 +167,6 @@ impl<L> TrackBreadth<L> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: ToCss> ToCss for TrackBreadth<L> {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
TrackBreadth::Breadth(ref lop) => lop.to_css(dest),
|
|
||||||
TrackBreadth::Flex(ref value) => serialize_dimension(*value, "fr", dest),
|
|
||||||
TrackBreadth::Keyword(ref k) => k.to_css(dest),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `<track-size>` type for explicit grid track sizing. Like `<track-breadth>`, this is
|
/// A `<track-size>` type for explicit grid track sizing. Like `<track-breadth>`, this is
|
||||||
/// generic only to avoid code bloat. It only takes `<length-percentage>`
|
/// generic only to avoid code bloat. It only takes `<length-percentage>`
|
||||||
///
|
///
|
||||||
|
@ -212,7 +203,7 @@ impl<L> TrackSize<L> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match *breadth_1 {
|
match *breadth_1 {
|
||||||
TrackBreadth::Flex(_) => false, // should be <inflexible-breadth> at this point
|
TrackBreadth::Fr(_) => false, // should be <inflexible-breadth> at this point
|
||||||
_ => breadth_2.is_fixed(),
|
_ => breadth_2.is_fixed(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -242,7 +233,7 @@ impl<L: ToCss> ToCss for TrackSize<L> {
|
||||||
// According to gecko minmax(auto, <flex>) is equivalent to <flex>,
|
// According to gecko minmax(auto, <flex>) is equivalent to <flex>,
|
||||||
// and both are serialized as <flex>.
|
// and both are serialized as <flex>.
|
||||||
if let TrackBreadth::Keyword(TrackKeyword::Auto) = *min {
|
if let TrackBreadth::Keyword(TrackKeyword::Auto) = *min {
|
||||||
if let TrackBreadth::Flex(_) = *max {
|
if let TrackBreadth::Fr(_) = *max {
|
||||||
return max.to_css(dest);
|
return max.to_css(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,7 +259,7 @@ impl<L: ToComputedValue> ToComputedValue for TrackSize<L> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||||
match *self {
|
match *self {
|
||||||
TrackSize::Breadth(TrackBreadth::Flex(ref f)) => {
|
TrackSize::Breadth(TrackBreadth::Fr(ref f)) => {
|
||||||
// <flex> outside `minmax()` expands to `mimmax(auto, <flex>)`
|
// <flex> outside `minmax()` expands to `mimmax(auto, <flex>)`
|
||||||
// https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-flex
|
// https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-flex
|
||||||
// FIXME(nox): This sounds false, the spec just says that <flex>
|
// FIXME(nox): This sounds false, the spec just says that <flex>
|
||||||
|
@ -276,7 +267,7 @@ impl<L: ToComputedValue> ToComputedValue for TrackSize<L> {
|
||||||
// into `minmax` at computed value time.
|
// into `minmax` at computed value time.
|
||||||
TrackSize::Minmax(
|
TrackSize::Minmax(
|
||||||
TrackBreadth::Keyword(TrackKeyword::Auto),
|
TrackBreadth::Keyword(TrackKeyword::Auto),
|
||||||
TrackBreadth::Flex(f.to_computed_value(context)),
|
TrackBreadth::Fr(f.to_computed_value(context)),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
TrackSize::Breadth(ref b) => {
|
TrackSize::Breadth(ref b) => {
|
||||||
|
|
|
@ -41,14 +41,6 @@ pub fn serialize_percentage<W>(value: CSSFloat, dest: &mut W)
|
||||||
dest.write_str("%")
|
dest.write_str("%")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serialize a value with given unit into dest.
|
|
||||||
pub fn serialize_dimension<W>(value: CSSFloat, unit: &str, dest: &mut W)
|
|
||||||
-> fmt::Result where W: fmt::Write
|
|
||||||
{
|
|
||||||
value.to_css(dest)?;
|
|
||||||
dest.write_str(unit)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convenience void type to disable some properties and values through types.
|
/// Convenience void type to disable some properties and values through types.
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, MallocSizeOf, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, MallocSizeOf, Serialize))]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue, ToCss)]
|
#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue, ToCss)]
|
||||||
|
|
|
@ -57,12 +57,12 @@ impl ToComputedValue for Angle {
|
||||||
impl Angle {
|
impl Angle {
|
||||||
/// Creates an angle with the given value in degrees.
|
/// Creates an angle with the given value in degrees.
|
||||||
pub fn from_degrees(value: CSSFloat, was_calc: bool) -> Self {
|
pub fn from_degrees(value: CSSFloat, was_calc: bool) -> Self {
|
||||||
Angle { value: ComputedAngle::Degree(value), was_calc }
|
Angle { value: ComputedAngle::Deg(value), was_calc }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an angle with the given value in gradians.
|
/// Creates an angle with the given value in gradians.
|
||||||
pub fn from_gradians(value: CSSFloat, was_calc: bool) -> Self {
|
pub fn from_gradians(value: CSSFloat, was_calc: bool) -> Self {
|
||||||
Angle { value: ComputedAngle::Gradian(value), was_calc }
|
Angle { value: ComputedAngle::Grad(value), was_calc }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an angle with the given value in turns.
|
/// Creates an angle with the given value in turns.
|
||||||
|
@ -72,7 +72,7 @@ impl Angle {
|
||||||
|
|
||||||
/// Creates an angle with the given value in radians.
|
/// Creates an angle with the given value in radians.
|
||||||
pub fn from_radians(value: CSSFloat, was_calc: bool) -> Self {
|
pub fn from_radians(value: CSSFloat, was_calc: bool) -> Self {
|
||||||
Angle { value: ComputedAngle::Radian(value), was_calc }
|
Angle { value: ComputedAngle::Rad(value), was_calc }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the amount of radians this angle represents.
|
/// Returns the amount of radians this angle represents.
|
||||||
|
@ -89,7 +89,7 @@ impl Angle {
|
||||||
/// Returns an `Angle` parsed from a `calc()` expression.
|
/// Returns an `Angle` parsed from a `calc()` expression.
|
||||||
pub fn from_calc(radians: CSSFloat) -> Self {
|
pub fn from_calc(radians: CSSFloat) -> Self {
|
||||||
Angle {
|
Angle {
|
||||||
value: ComputedAngle::Radian(radians),
|
value: ComputedAngle::Rad(radians),
|
||||||
was_calc: true,
|
was_calc: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,7 +400,13 @@ impl CalcNode {
|
||||||
NoCalcLength::ServoCharacterWidth(..) => unreachable!(),
|
NoCalcLength::ServoCharacterWidth(..) => unreachable!(),
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
NoCalcLength::Physical(physical) => {
|
NoCalcLength::Physical(physical) => {
|
||||||
ret.mozmm = Some(ret.mozmm.unwrap_or(0.) + physical.0 * factor);
|
use values::specified::length::PhysicalLength;
|
||||||
|
|
||||||
|
match physical {
|
||||||
|
PhysicalLength::Mozmm(mozmm) => {
|
||||||
|
ret.mozmm = Some(ret.mozmm.unwrap_or(0.) + mozmm * factor);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -636,81 +636,31 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
/// Set of variant alternates
|
/// Set of variant alternates
|
||||||
pub enum VariantAlternates {
|
pub enum VariantAlternates {
|
||||||
/// Enables display of stylistic alternates
|
/// Enables display of stylistic alternates
|
||||||
|
#[css(function)]
|
||||||
Stylistic(CustomIdent),
|
Stylistic(CustomIdent),
|
||||||
/// Enables display with stylistic sets
|
/// Enables display with stylistic sets
|
||||||
|
#[css(comma, function, iterable)]
|
||||||
Styleset(Box<[CustomIdent]>),
|
Styleset(Box<[CustomIdent]>),
|
||||||
/// Enables display of specific character variants
|
/// Enables display of specific character variants
|
||||||
|
#[css(comma, function, iterable)]
|
||||||
CharacterVariant(Box<[CustomIdent]>),
|
CharacterVariant(Box<[CustomIdent]>),
|
||||||
/// Enables display of swash glyphs
|
/// Enables display of swash glyphs
|
||||||
|
#[css(function)]
|
||||||
Swash(CustomIdent),
|
Swash(CustomIdent),
|
||||||
/// Enables replacement of default glyphs with ornaments
|
/// Enables replacement of default glyphs with ornaments
|
||||||
|
#[css(function)]
|
||||||
Ornaments(CustomIdent),
|
Ornaments(CustomIdent),
|
||||||
/// Enables display of alternate annotation forms
|
/// Enables display of alternate annotation forms
|
||||||
|
#[css(function)]
|
||||||
Annotation(CustomIdent),
|
Annotation(CustomIdent),
|
||||||
/// Enables display of historical forms
|
/// Enables display of historical forms
|
||||||
HistoricalForms,
|
HistoricalForms,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for VariantAlternates {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
VariantAlternates::Swash(ref atom) => {
|
|
||||||
dest.write_str("swash")?;
|
|
||||||
dest.write_str("(")?;
|
|
||||||
atom.to_css(dest)?;
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
VariantAlternates::Stylistic(ref atom) => {
|
|
||||||
dest.write_str("stylistic")?;
|
|
||||||
dest.write_str("(")?;
|
|
||||||
atom.to_css(dest)?;
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
VariantAlternates::Ornaments(ref atom) => {
|
|
||||||
dest.write_str("ornaments")?;
|
|
||||||
dest.write_str("(")?;
|
|
||||||
atom.to_css(dest)?;
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
VariantAlternates::Annotation(ref atom) => {
|
|
||||||
dest.write_str("annotation")?;
|
|
||||||
dest.write_str("(")?;
|
|
||||||
atom.to_css(dest)?;
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
VariantAlternates::Styleset(ref vec) => {
|
|
||||||
dest.write_str("styleset")?;
|
|
||||||
dest.write_str("(")?;
|
|
||||||
let mut iter = vec.iter();
|
|
||||||
iter.next().unwrap().to_css(dest)?;
|
|
||||||
for c in iter {
|
|
||||||
dest.write_str(", ")?;
|
|
||||||
c.to_css(dest)?;
|
|
||||||
}
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
VariantAlternates::CharacterVariant(ref vec) => {
|
|
||||||
dest.write_str("character-variant")?;
|
|
||||||
dest.write_str("(")?;
|
|
||||||
let mut iter = vec.iter();
|
|
||||||
iter.next().unwrap().to_css(dest)?;
|
|
||||||
for c in iter {
|
|
||||||
dest.write_str(", ")?;
|
|
||||||
c.to_css(dest)?;
|
|
||||||
}
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
VariantAlternates::HistoricalForms => {
|
|
||||||
dest.write_str("historical-forms")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||||
/// List of Variant Alternates
|
/// List of Variant Alternates
|
||||||
pub struct VariantAlternatesList(pub Box<[VariantAlternates]>);
|
pub struct VariantAlternatesList(pub Box<[VariantAlternates]>);
|
||||||
|
@ -1027,33 +977,26 @@ impl Parse for MozScriptMinSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
|
||||||
/// Changes the scriptlevel in effect for the children.
|
/// Changes the scriptlevel in effect for the children.
|
||||||
/// Ref: https://wiki.mozilla.org/MathML:mstyle
|
/// Ref: https://wiki.mozilla.org/MathML:mstyle
|
||||||
///
|
///
|
||||||
/// The main effect of scriptlevel is to control the font size.
|
/// The main effect of scriptlevel is to control the font size.
|
||||||
/// https://www.w3.org/TR/MathML3/chapter3.html#presm.scriptlevel
|
/// https://www.w3.org/TR/MathML3/chapter3.html#presm.scriptlevel
|
||||||
pub enum MozScriptLevel {
|
pub enum MozScriptLevel {
|
||||||
/// Change `font-size` relatively
|
/// Change `font-size` relatively.
|
||||||
Relative(i32),
|
Relative(i32),
|
||||||
/// Change `font-size` absolutely
|
/// Change `font-size` absolutely.
|
||||||
Absolute(i32),
|
///
|
||||||
/// Change `font-size` automatically
|
/// Should only be serialized by presentation attributes, so even though
|
||||||
|
/// serialization for this would look the same as for the `Relative`
|
||||||
|
/// variant, it is unexposed, so no big deal.
|
||||||
|
#[css(function)]
|
||||||
|
MozAbsolute(i32),
|
||||||
|
/// Change `font-size` automatically.
|
||||||
Auto
|
Auto
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for MozScriptLevel {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
MozScriptLevel::Auto => dest.write_str("auto"),
|
|
||||||
MozScriptLevel::Relative(rel) => rel.to_css(dest),
|
|
||||||
// can only be specified by pres attrs; should not
|
|
||||||
// serialize to anything else
|
|
||||||
MozScriptLevel::Absolute(_) => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for MozScriptLevel {
|
impl Parse for MozScriptLevel {
|
||||||
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<MozScriptLevel, ParseError<'i>> {
|
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<MozScriptLevel, ParseError<'i>> {
|
||||||
if let Ok(i) = input.try(|i| i.expect_integer()) {
|
if let Ok(i) = input.try(|i| i.expect_integer()) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl Parse for TrackBreadth<LengthOrPercentage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(f) = input.try(parse_flex) {
|
if let Ok(f) = input.try(parse_flex) {
|
||||||
return Ok(TrackBreadth::Flex(f))
|
return Ok(TrackBreadth::Fr(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackKeyword::parse(input).map(TrackBreadth::Keyword)
|
TrackKeyword::parse(input).map(TrackBreadth::Keyword)
|
||||||
|
|
|
@ -11,15 +11,14 @@ use cssparser::{Parser, Token};
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use font_metrics::FontMetricsQueryResult;
|
use font_metrics::FontMetricsQueryResult;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use std::{cmp, fmt, mem};
|
use std::{cmp, mem};
|
||||||
#[allow(unused_imports)] use std::ascii::AsciiExt;
|
#[allow(unused_imports)] use std::ascii::AsciiExt;
|
||||||
use std::ops::{Add, Mul};
|
use std::ops::{Add, Mul};
|
||||||
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
use style_traits::{ParseError, StyleParseErrorKind};
|
||||||
use style_traits::values::specified::AllowedNumericType;
|
use style_traits::values::specified::AllowedNumericType;
|
||||||
use stylesheets::CssRuleType;
|
use stylesheets::CssRuleType;
|
||||||
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
|
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
|
||||||
use values::{Auto, CSSFloat, Either, None_, Normal};
|
use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal};
|
||||||
use values::{ExtremumLength, serialize_dimension};
|
|
||||||
use values::computed::{self, CSSPixelLength, Context};
|
use values::computed::{self, CSSPixelLength, Context};
|
||||||
use values::generics::NonNegative;
|
use values::generics::NonNegative;
|
||||||
use values::specified::NonNegativeNumber;
|
use values::specified::NonNegativeNumber;
|
||||||
|
@ -52,32 +51,23 @@ pub fn au_to_int_px(au: f32) -> i32 {
|
||||||
(au / AU_PER_PX).round() as i32
|
(au / AU_PER_PX).round() as i32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
/// A font relative length.
|
/// A font relative length.
|
||||||
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub enum FontRelativeLength {
|
pub enum FontRelativeLength {
|
||||||
/// A "em" value: https://drafts.csswg.org/css-values/#em
|
/// A "em" value: https://drafts.csswg.org/css-values/#em
|
||||||
|
#[css(dimension)]
|
||||||
Em(CSSFloat),
|
Em(CSSFloat),
|
||||||
/// A "ex" value: https://drafts.csswg.org/css-values/#ex
|
/// A "ex" value: https://drafts.csswg.org/css-values/#ex
|
||||||
|
#[css(dimension)]
|
||||||
Ex(CSSFloat),
|
Ex(CSSFloat),
|
||||||
/// A "ch" value: https://drafts.csswg.org/css-values/#ch
|
/// A "ch" value: https://drafts.csswg.org/css-values/#ch
|
||||||
|
#[css(dimension)]
|
||||||
Ch(CSSFloat),
|
Ch(CSSFloat),
|
||||||
/// A "rem" value: https://drafts.csswg.org/css-values/#rem
|
/// A "rem" value: https://drafts.csswg.org/css-values/#rem
|
||||||
|
#[css(dimension)]
|
||||||
Rem(CSSFloat)
|
Rem(CSSFloat)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for FontRelativeLength {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
|
||||||
where W: fmt::Write
|
|
||||||
{
|
|
||||||
match *self {
|
|
||||||
FontRelativeLength::Em(length) => serialize_dimension(length, "em", dest),
|
|
||||||
FontRelativeLength::Ex(length) => serialize_dimension(length, "ex", dest),
|
|
||||||
FontRelativeLength::Ch(length) => serialize_dimension(length, "ch", dest),
|
|
||||||
FontRelativeLength::Rem(length) => serialize_dimension(length, "rem", dest)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A source to resolve font-relative units against
|
/// A source to resolve font-relative units against
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum FontBaseSize {
|
pub enum FontBaseSize {
|
||||||
|
@ -206,32 +196,25 @@ impl FontRelativeLength {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
/// A viewport-relative length.
|
/// A viewport-relative length.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-values/#viewport-relative-lengths>
|
/// <https://drafts.csswg.org/css-values/#viewport-relative-lengths>
|
||||||
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub enum ViewportPercentageLength {
|
pub enum ViewportPercentageLength {
|
||||||
/// A vw unit: https://drafts.csswg.org/css-values/#vw
|
/// A vw unit: https://drafts.csswg.org/css-values/#vw
|
||||||
|
#[css(dimension)]
|
||||||
Vw(CSSFloat),
|
Vw(CSSFloat),
|
||||||
/// A vh unit: https://drafts.csswg.org/css-values/#vh
|
/// A vh unit: https://drafts.csswg.org/css-values/#vh
|
||||||
|
#[css(dimension)]
|
||||||
Vh(CSSFloat),
|
Vh(CSSFloat),
|
||||||
/// <https://drafts.csswg.org/css-values/#vmin>
|
/// <https://drafts.csswg.org/css-values/#vmin>
|
||||||
|
#[css(dimension)]
|
||||||
Vmin(CSSFloat),
|
Vmin(CSSFloat),
|
||||||
/// <https://drafts.csswg.org/css-values/#vmax>
|
/// <https://drafts.csswg.org/css-values/#vmax>
|
||||||
|
#[css(dimension)]
|
||||||
Vmax(CSSFloat)
|
Vmax(CSSFloat)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for ViewportPercentageLength {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
ViewportPercentageLength::Vw(length) => serialize_dimension(length, "vw", dest),
|
|
||||||
ViewportPercentageLength::Vh(length) => serialize_dimension(length, "vh", dest),
|
|
||||||
ViewportPercentageLength::Vmin(length) => serialize_dimension(length, "vmin", dest),
|
|
||||||
ViewportPercentageLength::Vmax(length) => serialize_dimension(length, "vmax", dest)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ViewportPercentageLength {
|
impl ViewportPercentageLength {
|
||||||
/// Computes the given viewport-relative length for the given viewport size.
|
/// Computes the given viewport-relative length for the given viewport size.
|
||||||
pub fn to_computed_value(&self, viewport_size: Size2D<Au>) -> CSSPixelLength {
|
pub fn to_computed_value(&self, viewport_size: Size2D<Au>) -> CSSPixelLength {
|
||||||
|
@ -255,7 +238,7 @@ impl ViewportPercentageLength {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// HTML5 "character width", as defined in HTML5 § 14.5.4.
|
/// HTML5 "character width", as defined in HTML5 § 14.5.4.
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub struct CharacterWidth(pub i32);
|
pub struct CharacterWidth(pub i32);
|
||||||
|
|
||||||
impl CharacterWidth {
|
impl CharacterWidth {
|
||||||
|
@ -273,21 +256,28 @@ impl CharacterWidth {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents an absolute length with its unit
|
/// Represents an absolute length with its unit
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub enum AbsoluteLength {
|
pub enum AbsoluteLength {
|
||||||
/// An absolute length in pixels (px)
|
/// An absolute length in pixels (px)
|
||||||
|
#[css(dimension)]
|
||||||
Px(CSSFloat),
|
Px(CSSFloat),
|
||||||
/// An absolute length in inches (in)
|
/// An absolute length in inches (in)
|
||||||
|
#[css(dimension)]
|
||||||
In(CSSFloat),
|
In(CSSFloat),
|
||||||
/// An absolute length in centimeters (cm)
|
/// An absolute length in centimeters (cm)
|
||||||
|
#[css(dimension)]
|
||||||
Cm(CSSFloat),
|
Cm(CSSFloat),
|
||||||
/// An absolute length in millimeters (mm)
|
/// An absolute length in millimeters (mm)
|
||||||
|
#[css(dimension)]
|
||||||
Mm(CSSFloat),
|
Mm(CSSFloat),
|
||||||
/// An absolute length in quarter-millimeters (q)
|
/// An absolute length in quarter-millimeters (q)
|
||||||
|
#[css(dimension)]
|
||||||
Q(CSSFloat),
|
Q(CSSFloat),
|
||||||
/// An absolute length in points (pt)
|
/// An absolute length in points (pt)
|
||||||
|
#[css(dimension)]
|
||||||
Pt(CSSFloat),
|
Pt(CSSFloat),
|
||||||
/// An absolute length in pica (pc)
|
/// An absolute length in pica (pc)
|
||||||
|
#[css(dimension)]
|
||||||
Pc(CSSFloat),
|
Pc(CSSFloat),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,20 +324,6 @@ impl ToComputedValue for AbsoluteLength {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for AbsoluteLength {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
AbsoluteLength::Px(length) => serialize_dimension(length, "px", dest),
|
|
||||||
AbsoluteLength::In(length) => serialize_dimension(length, "in", dest),
|
|
||||||
AbsoluteLength::Cm(length) => serialize_dimension(length, "cm", dest),
|
|
||||||
AbsoluteLength::Mm(length) => serialize_dimension(length, "mm", dest),
|
|
||||||
AbsoluteLength::Q(length) => serialize_dimension(length, "q", dest),
|
|
||||||
AbsoluteLength::Pt(length) => serialize_dimension(length, "pt", dest),
|
|
||||||
AbsoluteLength::Pc(length) => serialize_dimension(length, "pc", dest),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mul<CSSFloat> for AbsoluteLength {
|
impl Mul<CSSFloat> for AbsoluteLength {
|
||||||
type Output = AbsoluteLength;
|
type Output = AbsoluteLength;
|
||||||
|
|
||||||
|
@ -383,19 +359,27 @@ impl Add<AbsoluteLength> for AbsoluteLength {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a physical length (mozmm) based on DPI
|
/// Represents a physical length based on DPI.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
///
|
||||||
#[cfg(feature = "gecko")]
|
/// FIXME(emilio): Unship (https://bugzilla.mozilla.org/show_bug.cgi?id=1416564)
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
|
||||||
#[derive(MallocSizeOf)]
|
#[derive(MallocSizeOf)]
|
||||||
pub struct PhysicalLength(pub CSSFloat);
|
pub enum PhysicalLength {
|
||||||
|
/// A physical length in millimetres.
|
||||||
|
#[css(dimension)]
|
||||||
|
Mozmm(CSSFloat),
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl PhysicalLength {
|
impl PhysicalLength {
|
||||||
fn is_zero(&self) -> bool {
|
/// Checks whether the length value is zero.
|
||||||
self.0 == 0.
|
pub fn is_zero(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
PhysicalLength::Mozmm(v) => v == 0.,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the given character width.
|
/// Computes the given character width.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
pub fn to_computed_value(&self, context: &Context) -> CSSPixelLength {
|
pub fn to_computed_value(&self, context: &Context) -> CSSPixelLength {
|
||||||
use gecko_bindings::bindings;
|
use gecko_bindings::bindings;
|
||||||
use std::f32;
|
use std::f32;
|
||||||
|
@ -408,32 +392,31 @@ impl PhysicalLength {
|
||||||
};
|
};
|
||||||
|
|
||||||
let px_per_physical_inch = au_per_physical_inch / AU_PER_PX;
|
let px_per_physical_inch = au_per_physical_inch / AU_PER_PX;
|
||||||
let pixel = self.0 * px_per_physical_inch * INCH_PER_MM;
|
|
||||||
|
let mm = match *self {
|
||||||
|
PhysicalLength::Mozmm(v) => v,
|
||||||
|
};
|
||||||
|
|
||||||
|
let pixel = mm * px_per_physical_inch * INCH_PER_MM;
|
||||||
CSSPixelLength::new(pixel.min(f32::MAX).max(f32::MIN))
|
CSSPixelLength::new(pixel.min(f32::MAX).max(f32::MIN))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl ToCss for PhysicalLength {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
serialize_dimension(self.0, "mozmm", dest)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl Mul<CSSFloat> for PhysicalLength {
|
impl Mul<CSSFloat> for PhysicalLength {
|
||||||
type Output = PhysicalLength;
|
type Output = Self ;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn mul(self, scalar: CSSFloat) -> PhysicalLength {
|
fn mul(self, scalar: CSSFloat) -> Self {
|
||||||
PhysicalLength(self.0 * scalar)
|
match self {
|
||||||
|
PhysicalLength::Mozmm(v) => PhysicalLength::Mozmm(v * scalar),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `<length>` without taking `calc` expressions into account
|
/// A `<length>` without taking `calc` expressions into account
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-values/#lengths>
|
/// <https://drafts.csswg.org/css-values/#lengths>
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub enum NoCalcLength {
|
pub enum NoCalcLength {
|
||||||
/// An absolute length
|
/// An absolute length
|
||||||
///
|
///
|
||||||
|
@ -454,6 +437,7 @@ pub enum NoCalcLength {
|
||||||
///
|
///
|
||||||
/// This cannot be specified by the user directly and is only generated by
|
/// This cannot be specified by the user directly and is only generated by
|
||||||
/// `Stylist::synthesize_rules_for_legacy_attributes()`.
|
/// `Stylist::synthesize_rules_for_legacy_attributes()`.
|
||||||
|
#[css(function)]
|
||||||
ServoCharacterWidth(CharacterWidth),
|
ServoCharacterWidth(CharacterWidth),
|
||||||
|
|
||||||
/// A physical length (mozmm) based on DPI
|
/// A physical length (mozmm) based on DPI
|
||||||
|
@ -461,24 +445,6 @@ pub enum NoCalcLength {
|
||||||
Physical(PhysicalLength),
|
Physical(PhysicalLength),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for NoCalcLength {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
NoCalcLength::Absolute(length) => length.to_css(dest),
|
|
||||||
NoCalcLength::FontRelative(length) => length.to_css(dest),
|
|
||||||
NoCalcLength::ViewportPercentage(length) => length.to_css(dest),
|
|
||||||
/* This should only be reached from style dumping code */
|
|
||||||
NoCalcLength::ServoCharacterWidth(CharacterWidth(i)) => {
|
|
||||||
dest.write_str("CharWidth(")?;
|
|
||||||
i.to_css(dest)?;
|
|
||||||
dest.write_char(')')
|
|
||||||
}
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
NoCalcLength::Physical(length) => length.to_css(dest),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mul<CSSFloat> for NoCalcLength {
|
impl Mul<CSSFloat> for NoCalcLength {
|
||||||
type Output = NoCalcLength;
|
type Output = NoCalcLength;
|
||||||
|
|
||||||
|
@ -539,7 +505,7 @@ impl NoCalcLength {
|
||||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value)))
|
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value)))
|
||||||
},
|
},
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
"mozmm" => Ok(NoCalcLength::Physical(PhysicalLength(value))),
|
"mozmm" => Ok(NoCalcLength::Physical(PhysicalLength::Mozmm(value))),
|
||||||
_ => Err(())
|
_ => Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,25 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
||||||
let mut identifier = to_css_identifier(variant.ident.as_ref());
|
let mut identifier = to_css_identifier(variant.ident.as_ref());
|
||||||
let variant_attrs = cg::parse_variant_attrs::<CssVariantAttrs>(variant);
|
let variant_attrs = cg::parse_variant_attrs::<CssVariantAttrs>(variant);
|
||||||
let separator = if variant_attrs.comma { ", " } else { " " };
|
let separator = if variant_attrs.comma { ", " } else { " " };
|
||||||
|
|
||||||
|
if variant_attrs.dimension {
|
||||||
|
assert_eq!(bindings.len(), 1);
|
||||||
|
assert!(!variant_attrs.function, "That makes no sense");
|
||||||
|
}
|
||||||
|
|
||||||
let mut expr = if !bindings.is_empty() {
|
let mut expr = if !bindings.is_empty() {
|
||||||
let mut expr = quote! {};
|
let mut expr = quote! {};
|
||||||
|
if variant_attrs.function && variant_attrs.iterable {
|
||||||
|
assert_eq!(bindings.len(), 1);
|
||||||
|
let binding = &bindings[0];
|
||||||
|
expr = quote! {
|
||||||
|
#expr
|
||||||
|
|
||||||
|
for item in #binding.iter() {
|
||||||
|
writer.item(item)?;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
for binding in bindings {
|
for binding in bindings {
|
||||||
where_clause.add_trait_bound(&binding.field.ty);
|
where_clause.add_trait_bound(&binding.field.ty);
|
||||||
expr = quote! {
|
expr = quote! {
|
||||||
|
@ -28,6 +45,8 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
||||||
writer.item(#binding)?;
|
writer.item(#binding)?;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
quote! {{
|
quote! {{
|
||||||
let mut writer = ::style_traits::values::SequenceWriter::new(&mut *dest, #separator);
|
let mut writer = ::style_traits::values::SequenceWriter::new(&mut *dest, #separator);
|
||||||
#expr
|
#expr
|
||||||
|
@ -38,7 +57,18 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
||||||
::std::fmt::Write::write_str(dest, #identifier)
|
::std::fmt::Write::write_str(dest, #identifier)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if variant_attrs.function {
|
|
||||||
|
if variant_attrs.dimension {
|
||||||
|
// FIXME(emilio): Remove when bug 1416564 lands.
|
||||||
|
if identifier == "-mozmm" {
|
||||||
|
identifier = "mozmm".into();
|
||||||
|
}
|
||||||
|
|
||||||
|
expr = quote! {
|
||||||
|
#expr?;
|
||||||
|
::std::fmt::Write::write_str(dest, #identifier)
|
||||||
|
}
|
||||||
|
} else if variant_attrs.function {
|
||||||
identifier.push_str("(");
|
identifier.push_str("(");
|
||||||
expr = quote! {
|
expr = quote! {
|
||||||
::std::fmt::Write::write_str(dest, #identifier)?;
|
::std::fmt::Write::write_str(dest, #identifier)?;
|
||||||
|
@ -89,7 +119,9 @@ struct CssInputAttrs {
|
||||||
#[derive(Default, FromVariant)]
|
#[derive(Default, FromVariant)]
|
||||||
struct CssVariantAttrs {
|
struct CssVariantAttrs {
|
||||||
function: bool,
|
function: bool,
|
||||||
|
iterable: bool,
|
||||||
comma: bool,
|
comma: bool,
|
||||||
|
dimension: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transforms "FooBar" to "foo-bar".
|
/// Transforms "FooBar" to "foo-bar".
|
||||||
|
|
|
@ -24,6 +24,12 @@ use std::fmt::{self, Write};
|
||||||
/// commas, otherwise, by spaces;
|
/// commas, otherwise, by spaces;
|
||||||
/// * if `#[css(function)]` is found on a variant, the variant name gets
|
/// * if `#[css(function)]` is found on a variant, the variant name gets
|
||||||
/// serialised like unit variants and its fields are surrounded by parentheses;
|
/// serialised like unit variants and its fields are surrounded by parentheses;
|
||||||
|
/// * if `#[css(iterable)]` is found on a function variant, that variant needs
|
||||||
|
/// to have a single member, and that member needs to be iterable. The
|
||||||
|
/// iterable will be serialized as the arguments for the function.
|
||||||
|
/// * if `#[css(dimension)]` is found on a variant, that variant needs
|
||||||
|
/// to have a single member. The variant would be serialized as a CSS
|
||||||
|
/// dimension token, like: <member><identifier>.
|
||||||
/// * finally, one can put `#[css(derive_debug)]` on the whole type, to
|
/// * finally, one can put `#[css(derive_debug)]` on the whole type, to
|
||||||
/// implement `Debug` by a single call to `ToCss::to_css`.
|
/// implement `Debug` by a single call to `ToCss::to_css`.
|
||||||
pub trait ToCss {
|
pub trait ToCss {
|
||||||
|
|
|
@ -3171,7 +3171,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(
|
||||||
structs::nsCSSUnit::eCSSUnit_Inch => NoCalcLength::Absolute(AbsoluteLength::In(value)),
|
structs::nsCSSUnit::eCSSUnit_Inch => NoCalcLength::Absolute(AbsoluteLength::In(value)),
|
||||||
structs::nsCSSUnit::eCSSUnit_Centimeter => NoCalcLength::Absolute(AbsoluteLength::Cm(value)),
|
structs::nsCSSUnit::eCSSUnit_Centimeter => NoCalcLength::Absolute(AbsoluteLength::Cm(value)),
|
||||||
structs::nsCSSUnit::eCSSUnit_Millimeter => NoCalcLength::Absolute(AbsoluteLength::Mm(value)),
|
structs::nsCSSUnit::eCSSUnit_Millimeter => NoCalcLength::Absolute(AbsoluteLength::Mm(value)),
|
||||||
structs::nsCSSUnit::eCSSUnit_PhysicalMillimeter => NoCalcLength::Physical(PhysicalLength(value)),
|
structs::nsCSSUnit::eCSSUnit_PhysicalMillimeter => NoCalcLength::Physical(PhysicalLength::Mozmm(value)),
|
||||||
structs::nsCSSUnit::eCSSUnit_Point => NoCalcLength::Absolute(AbsoluteLength::Pt(value)),
|
structs::nsCSSUnit::eCSSUnit_Point => NoCalcLength::Absolute(AbsoluteLength::Pt(value)),
|
||||||
structs::nsCSSUnit::eCSSUnit_Pica => NoCalcLength::Absolute(AbsoluteLength::Pc(value)),
|
structs::nsCSSUnit::eCSSUnit_Pica => NoCalcLength::Absolute(AbsoluteLength::Pc(value)),
|
||||||
structs::nsCSSUnit::eCSSUnit_Quarter => NoCalcLength::Absolute(AbsoluteLength::Q(value)),
|
structs::nsCSSUnit::eCSSUnit_Quarter => NoCalcLength::Absolute(AbsoluteLength::Q(value)),
|
||||||
|
@ -3202,7 +3202,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetNumberValue(
|
||||||
let prop = match_wrap_declared! { long,
|
let prop = match_wrap_declared! { long,
|
||||||
MozScriptSizeMultiplier => value,
|
MozScriptSizeMultiplier => value,
|
||||||
// Gecko uses Number values to signal that it is absolute
|
// Gecko uses Number values to signal that it is absolute
|
||||||
MozScriptLevel => MozScriptLevel::Absolute(value as i32),
|
MozScriptLevel => MozScriptLevel::MozAbsolute(value as i32),
|
||||||
};
|
};
|
||||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||||
decls.push(prop, Importance::Normal, DeclarationSource::CssOm);
|
decls.push(prop, Importance::Normal, DeclarationSource::CssOm);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue