mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Rename LengthOrPercentage to LengthPercentage.
It does not represent `<length> | <percentage>`, but `<length-percentage>`, so `LengthOrPercentage` is not the right name. This patch is totally autogenerated using: rg 'LengthOrPercentage' servo | cut -d : -f 1 | sort | uniq > files for file in $(cat files); do sed -i "s#LengthOrPercentage#LengthPercentage#g" $file; done Differential Revision: https://phabricator.services.mozilla.com/D15812
This commit is contained in:
parent
4a31509215
commit
daf1f02feb
61 changed files with 709 additions and 702 deletions
|
@ -6,24 +6,24 @@
|
|||
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||
use crate::values::specified::length::NonNegativeLengthOrPercentageOrAuto;
|
||||
use crate::values::specified::length::NonNegativeLengthPercentageOrAuto;
|
||||
use cssparser::Parser;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, ToCss};
|
||||
|
||||
/// A specified value for the `background-size` property.
|
||||
pub type BackgroundSize = GenericBackgroundSize<NonNegativeLengthOrPercentageOrAuto>;
|
||||
pub type BackgroundSize = GenericBackgroundSize<NonNegativeLengthPercentageOrAuto>;
|
||||
|
||||
impl Parse for BackgroundSize {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(width) = input.try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i)) {
|
||||
if let Ok(width) = input.try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) {
|
||||
let height = input
|
||||
.try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i))
|
||||
.unwrap_or(NonNegativeLengthOrPercentageOrAuto::auto());
|
||||
.try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i))
|
||||
.unwrap_or(NonNegativeLengthPercentageOrAuto::auto());
|
||||
return Ok(GenericBackgroundSize::Explicit { width, height });
|
||||
}
|
||||
Ok(try_match_ident_ignore_ascii_case! { input,
|
||||
|
@ -37,8 +37,8 @@ impl BackgroundSize {
|
|||
/// Returns `auto auto`.
|
||||
pub fn auto() -> Self {
|
||||
GenericBackgroundSize::Explicit {
|
||||
width: NonNegativeLengthOrPercentageOrAuto::auto(),
|
||||
height: NonNegativeLengthOrPercentageOrAuto::auto(),
|
||||
width: NonNegativeLengthPercentageOrAuto::auto(),
|
||||
height: NonNegativeLengthPercentageOrAuto::auto(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use crate::values::specified::image::Image;
|
|||
use crate::values::specified::position::{HorizontalPosition, Position, VerticalPosition};
|
||||
use crate::values::specified::url::SpecifiedUrl;
|
||||
use crate::values::specified::SVGPathData;
|
||||
use crate::values::specified::{LengthOrPercentage, NonNegativeLengthOrPercentage};
|
||||
use crate::values::specified::{LengthPercentage, NonNegativeLengthPercentage};
|
||||
use cssparser::Parser;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
|
@ -35,26 +35,26 @@ pub type FloatAreaShape = generic::FloatAreaShape<BasicShape, Image>;
|
|||
pub type BasicShape = generic::BasicShape<
|
||||
HorizontalPosition,
|
||||
VerticalPosition,
|
||||
LengthOrPercentage,
|
||||
NonNegativeLengthOrPercentage,
|
||||
LengthPercentage,
|
||||
NonNegativeLengthPercentage,
|
||||
>;
|
||||
|
||||
/// The specified value of `inset()`
|
||||
pub type InsetRect = generic::InsetRect<LengthOrPercentage, NonNegativeLengthOrPercentage>;
|
||||
pub type InsetRect = generic::InsetRect<LengthPercentage, NonNegativeLengthPercentage>;
|
||||
|
||||
/// A specified circle.
|
||||
pub type Circle =
|
||||
generic::Circle<HorizontalPosition, VerticalPosition, NonNegativeLengthOrPercentage>;
|
||||
generic::Circle<HorizontalPosition, VerticalPosition, NonNegativeLengthPercentage>;
|
||||
|
||||
/// A specified ellipse.
|
||||
pub type Ellipse =
|
||||
generic::Ellipse<HorizontalPosition, VerticalPosition, NonNegativeLengthOrPercentage>;
|
||||
generic::Ellipse<HorizontalPosition, VerticalPosition, NonNegativeLengthPercentage>;
|
||||
|
||||
/// The specified value of `ShapeRadius`
|
||||
pub type ShapeRadius = generic::ShapeRadius<NonNegativeLengthOrPercentage>;
|
||||
pub type ShapeRadius = generic::ShapeRadius<NonNegativeLengthPercentage>;
|
||||
|
||||
/// The specified value of `Polygon`
|
||||
pub type Polygon = generic::Polygon<LengthOrPercentage>;
|
||||
pub type Polygon = generic::Polygon<LengthPercentage>;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn is_clip_path_path_enabled(context: &ParserContext) -> bool {
|
||||
|
@ -200,7 +200,7 @@ impl InsetRect {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let rect = Rect::parse_with(context, input, LengthOrPercentage::parse)?;
|
||||
let rect = Rect::parse_with(context, input, LengthPercentage::parse)?;
|
||||
let round = if input.try(|i| i.expect_ident_matching("round")).is_ok() {
|
||||
Some(BorderRadius::parse(context, input)?)
|
||||
} else {
|
||||
|
@ -316,7 +316,7 @@ impl Parse for ShapeRadius {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(lop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(lop) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) {
|
||||
return Ok(generic::ShapeRadius::Length(lop));
|
||||
}
|
||||
|
||||
|
@ -353,8 +353,8 @@ impl Polygon {
|
|||
|
||||
let buf = input.parse_comma_separated(|i| {
|
||||
Ok(PolygonCoord(
|
||||
LengthOrPercentage::parse(context, i)?,
|
||||
LengthOrPercentage::parse(context, i)?,
|
||||
LengthPercentage::parse(context, i)?,
|
||||
LengthPercentage::parse(context, i)?,
|
||||
))
|
||||
})?;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::values::generics::border::BorderRadius as GenericBorderRadius;
|
|||
use crate::values::generics::border::BorderSpacing as GenericBorderSpacing;
|
||||
use crate::values::generics::rect::Rect;
|
||||
use crate::values::generics::size::Size;
|
||||
use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthOrPercentage};
|
||||
use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthPercentage};
|
||||
use crate::values::specified::{AllowQuirks, NonNegativeNumber, NonNegativeNumberOrPercentage};
|
||||
use cssparser::Parser;
|
||||
use std::fmt::{self, Write};
|
||||
|
@ -79,16 +79,16 @@ pub type BorderImageWidth = Rect<BorderImageSideWidth>;
|
|||
|
||||
/// A specified value for a single side of a `border-image-width` property.
|
||||
pub type BorderImageSideWidth =
|
||||
GenericBorderImageSideWidth<NonNegativeLengthOrPercentage, NonNegativeNumber>;
|
||||
GenericBorderImageSideWidth<NonNegativeLengthPercentage, NonNegativeNumber>;
|
||||
|
||||
/// A specified value for the `border-image-slice` property.
|
||||
pub type BorderImageSlice = GenericBorderImageSlice<NonNegativeNumberOrPercentage>;
|
||||
|
||||
/// A specified value for the `border-radius` property.
|
||||
pub type BorderRadius = GenericBorderRadius<NonNegativeLengthOrPercentage>;
|
||||
pub type BorderRadius = GenericBorderRadius<NonNegativeLengthPercentage>;
|
||||
|
||||
/// A specified value for the `border-*-radius` longhand properties.
|
||||
pub type BorderCornerRadius = GenericBorderCornerRadius<NonNegativeLengthOrPercentage>;
|
||||
pub type BorderCornerRadius = GenericBorderCornerRadius<NonNegativeLengthPercentage>;
|
||||
|
||||
/// A specified value for the `border-spacing` longhand properties.
|
||||
pub type BorderSpacing = GenericBorderSpacing<NonNegativeLength>;
|
||||
|
@ -178,7 +178,7 @@ impl Parse for BorderImageSideWidth {
|
|||
return Ok(GenericBorderImageSideWidth::Auto);
|
||||
}
|
||||
|
||||
if let Ok(len) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(len) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) {
|
||||
return Ok(GenericBorderImageSideWidth::Length(len));
|
||||
}
|
||||
|
||||
|
@ -206,9 +206,9 @@ impl Parse for BorderRadius {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let widths = Rect::parse_with(context, input, NonNegativeLengthOrPercentage::parse)?;
|
||||
let widths = Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)?;
|
||||
let heights = if input.try(|i| i.expect_delim('/')).is_ok() {
|
||||
Rect::parse_with(context, input, NonNegativeLengthOrPercentage::parse)?
|
||||
Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)?
|
||||
} else {
|
||||
widths.clone()
|
||||
};
|
||||
|
@ -227,7 +227,7 @@ impl Parse for BorderCornerRadius {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Size::parse_with(context, input, NonNegativeLengthOrPercentage::parse)
|
||||
Size::parse_with(context, input, NonNegativeLengthPercentage::parse)
|
||||
.map(GenericBorderCornerRadius)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::properties::{PropertyId, ShorthandId};
|
|||
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
|
||||
use crate::values::generics::box_::Perspective as GenericPerspective;
|
||||
use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign;
|
||||
use crate::values::specified::length::{LengthOrPercentage, NonNegativeLength};
|
||||
use crate::values::specified::length::{LengthPercentage, NonNegativeLength};
|
||||
use crate::values::specified::{AllowQuirks, Number};
|
||||
use crate::values::{CustomIdent, KeyframesName};
|
||||
use crate::Atom;
|
||||
|
@ -271,7 +271,7 @@ impl Display {
|
|||
}
|
||||
|
||||
/// A specified value for the `vertical-align` property.
|
||||
pub type VerticalAlign = GenericVerticalAlign<LengthOrPercentage>;
|
||||
pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
|
||||
|
||||
impl Parse for VerticalAlign {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -279,7 +279,7 @@ impl Parse for VerticalAlign {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(lop) =
|
||||
input.try(|i| LengthOrPercentage::parse_quirky(context, i, AllowQuirks::Yes))
|
||||
input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes))
|
||||
{
|
||||
return Ok(GenericVerticalAlign::Length(lop));
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ pub enum CalcUnit {
|
|||
/// `<percentage>`
|
||||
Percentage,
|
||||
/// `<length> | <percentage>`
|
||||
LengthOrPercentage,
|
||||
LengthPercentage,
|
||||
/// `<angle>`
|
||||
Angle,
|
||||
/// `<time>`
|
||||
|
@ -67,7 +67,7 @@ pub enum CalcUnit {
|
|||
/// function work properly.
|
||||
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq)]
|
||||
#[allow(missing_docs)]
|
||||
pub struct CalcLengthOrPercentage {
|
||||
pub struct CalcLengthPercentage {
|
||||
pub clamping_mode: AllowedNumericType,
|
||||
pub absolute: Option<AbsoluteLength>,
|
||||
pub vw: Option<CSSFloat>,
|
||||
|
@ -81,7 +81,7 @@ pub struct CalcLengthOrPercentage {
|
|||
pub percentage: Option<computed::Percentage>,
|
||||
}
|
||||
|
||||
impl ToCss for CalcLengthOrPercentage {
|
||||
impl ToCss for CalcLengthPercentage {
|
||||
/// <https://drafts.csswg.org/css-values/#calc-serialize>
|
||||
///
|
||||
/// FIXME(emilio): Should this simplify away zeros?
|
||||
|
@ -148,7 +148,7 @@ impl ToCss for CalcLengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl SpecifiedValueInfo for CalcLengthOrPercentage {}
|
||||
impl SpecifiedValueInfo for CalcLengthPercentage {}
|
||||
|
||||
impl CalcNode {
|
||||
/// Tries to parse a single element in the expression, that is, a
|
||||
|
@ -176,7 +176,7 @@ impl CalcNode {
|
|||
&Token::Dimension {
|
||||
value, ref unit, ..
|
||||
},
|
||||
CalcUnit::LengthOrPercentage,
|
||||
CalcUnit::LengthPercentage,
|
||||
) => {
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(CalcNode::Length)
|
||||
|
@ -202,7 +202,7 @@ impl CalcNode {
|
|||
.map(CalcNode::Time)
|
||||
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
},
|
||||
(&Token::Percentage { unit_value, .. }, CalcUnit::LengthOrPercentage) |
|
||||
(&Token::Percentage { unit_value, .. }, CalcUnit::LengthPercentage) |
|
||||
(&Token::Percentage { unit_value, .. }, CalcUnit::Percentage) => {
|
||||
return Ok(CalcNode::Percentage(unit_value));
|
||||
},
|
||||
|
@ -299,8 +299,8 @@ impl CalcNode {
|
|||
fn to_length_or_percentage(
|
||||
&self,
|
||||
clamping_mode: AllowedNumericType,
|
||||
) -> Result<CalcLengthOrPercentage, ()> {
|
||||
let mut ret = CalcLengthOrPercentage {
|
||||
) -> Result<CalcLengthPercentage, ()> {
|
||||
let mut ret = CalcLengthPercentage {
|
||||
clamping_mode: clamping_mode,
|
||||
..Default::default()
|
||||
};
|
||||
|
@ -346,7 +346,7 @@ impl CalcNode {
|
|||
/// (this allows adding and substracting into the return value).
|
||||
fn add_length_or_percentage_to(
|
||||
&self,
|
||||
ret: &mut CalcLengthOrPercentage,
|
||||
ret: &mut CalcLengthPercentage,
|
||||
factor: CSSFloat,
|
||||
) -> Result<(), ()> {
|
||||
match *self {
|
||||
|
@ -537,8 +537,8 @@ impl CalcNode {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
clamping_mode: AllowedNumericType,
|
||||
) -> Result<CalcLengthOrPercentage, ParseError<'i>> {
|
||||
Self::parse(context, input, CalcUnit::LengthOrPercentage)?
|
||||
) -> Result<CalcLengthPercentage, ParseError<'i>> {
|
||||
Self::parse(context, input, CalcUnit::LengthPercentage)?
|
||||
.to_length_or_percentage(clamping_mode)
|
||||
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
|
@ -558,7 +558,7 @@ impl CalcNode {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
clamping_mode: AllowedNumericType,
|
||||
) -> Result<CalcLengthOrPercentage, ParseError<'i>> {
|
||||
) -> Result<CalcLengthPercentage, ParseError<'i>> {
|
||||
Self::parse(context, input, CalcUnit::Length)?
|
||||
.to_length_or_percentage(clamping_mode)
|
||||
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
|
|
|
@ -11,7 +11,7 @@ use style_traits::ParseError;
|
|||
|
||||
/// The `width` value type.
|
||||
#[cfg(feature = "servo")]
|
||||
pub type Width = crate::values::specified::NonNegativeLengthOrPercentageOrAuto;
|
||||
pub type Width = crate::values::specified::NonNegativeLengthPercentageOrAuto;
|
||||
|
||||
/// The `width` value type.
|
||||
#[cfg(feature = "gecko")]
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::values::generics::font::{self as generics, FeatureTagValue, FontSetti
|
|||
use crate::values::generics::font::{KeywordSize, VariationValue};
|
||||
use crate::values::generics::NonNegative;
|
||||
use crate::values::specified::length::{FontBaseSize, AU_PER_PT, AU_PER_PX};
|
||||
use crate::values::specified::{AllowQuirks, Angle, Integer, LengthOrPercentage};
|
||||
use crate::values::specified::{AllowQuirks, Angle, Integer, LengthPercentage};
|
||||
use crate::values::specified::{NoCalcLength, Number, Percentage};
|
||||
use crate::values::CustomIdent;
|
||||
use crate::Atom;
|
||||
|
@ -510,7 +510,7 @@ impl ToComputedValue for FontStretch {
|
|||
/// A specified font-size value
|
||||
pub enum FontSize {
|
||||
/// A length; e.g. 10px.
|
||||
Length(LengthOrPercentage),
|
||||
Length(LengthPercentage),
|
||||
/// A keyword value, along with a ratio and absolute offset.
|
||||
/// The ratio in any specified keyword value
|
||||
/// will be 1 (with offset 0), but we cascade keywordness even
|
||||
|
@ -531,8 +531,8 @@ pub enum FontSize {
|
|||
System(SystemFont),
|
||||
}
|
||||
|
||||
impl From<LengthOrPercentage> for FontSize {
|
||||
fn from(other: LengthOrPercentage) -> Self {
|
||||
impl From<LengthPercentage> for FontSize {
|
||||
fn from(other: LengthPercentage) -> Self {
|
||||
FontSize::Length(other)
|
||||
}
|
||||
}
|
||||
|
@ -863,7 +863,7 @@ impl FontSize {
|
|||
};
|
||||
let mut info = None;
|
||||
let size = match *self {
|
||||
FontSize::Length(LengthOrPercentage::Length(NoCalcLength::FontRelative(value))) => {
|
||||
FontSize::Length(LengthPercentage::Length(NoCalcLength::FontRelative(value))) => {
|
||||
if let FontRelativeLength::Em(em) = value {
|
||||
// If the parent font was keyword-derived, this is too.
|
||||
// Tack the em unit onto the factor
|
||||
|
@ -871,22 +871,22 @@ impl FontSize {
|
|||
}
|
||||
value.to_computed_value(context, base_size).into()
|
||||
},
|
||||
FontSize::Length(LengthOrPercentage::Length(NoCalcLength::ServoCharacterWidth(
|
||||
FontSize::Length(LengthPercentage::Length(NoCalcLength::ServoCharacterWidth(
|
||||
value,
|
||||
))) => value.to_computed_value(base_size.resolve(context)).into(),
|
||||
FontSize::Length(LengthOrPercentage::Length(NoCalcLength::Absolute(ref l))) => {
|
||||
FontSize::Length(LengthPercentage::Length(NoCalcLength::Absolute(ref l))) => {
|
||||
context.maybe_zoom_text(l.to_computed_value(context).into())
|
||||
},
|
||||
FontSize::Length(LengthOrPercentage::Length(ref l)) => {
|
||||
FontSize::Length(LengthPercentage::Length(ref l)) => {
|
||||
l.to_computed_value(context).into()
|
||||
},
|
||||
FontSize::Length(LengthOrPercentage::Percentage(pc)) => {
|
||||
FontSize::Length(LengthPercentage::Percentage(pc)) => {
|
||||
// If the parent font was keyword-derived, this is too.
|
||||
// Tack the % onto the factor
|
||||
info = compose_keyword(pc.0);
|
||||
base_size.resolve(context).scale_by(pc.0).into()
|
||||
},
|
||||
FontSize::Length(LengthOrPercentage::Calc(ref calc)) => {
|
||||
FontSize::Length(LengthPercentage::Calc(ref calc)) => {
|
||||
let parent = context.style().get_parent_font().clone_font_size();
|
||||
// if we contain em/% units and the parent was keyword derived, this is too
|
||||
// Extract the ratio/offset and compose it
|
||||
|
@ -964,7 +964,7 @@ impl ToComputedValue for FontSize {
|
|||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed::FontSize) -> Self {
|
||||
FontSize::Length(LengthOrPercentage::Length(
|
||||
FontSize::Length(LengthPercentage::Length(
|
||||
ToComputedValue::from_computed_value(&computed.size.0),
|
||||
))
|
||||
}
|
||||
|
@ -986,7 +986,7 @@ impl FontSize {
|
|||
allow_quirks: AllowQuirks,
|
||||
) -> Result<FontSize, ParseError<'i>> {
|
||||
if let Ok(lop) =
|
||||
input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
input.try(|i| LengthPercentage::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
{
|
||||
return Ok(FontSize::Length(lop));
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ use crate::values::computed;
|
|||
use crate::values::computed::length::CSSPixelLength;
|
||||
use crate::values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint;
|
||||
use crate::values::generics::rect::Rect;
|
||||
use crate::values::specified::length::LengthOrPercentage;
|
||||
use crate::values::specified::length::LengthPercentage;
|
||||
use cssparser::{Parser, Token};
|
||||
use std::fmt;
|
||||
use style_traits::values::SequenceWriter;
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
|
||||
/// A specified type for scroll snap points.
|
||||
pub type ScrollSnapPoint = GenericScrollSnapPoint<LengthOrPercentage>;
|
||||
pub type ScrollSnapPoint = GenericScrollSnapPoint<LengthPercentage>;
|
||||
|
||||
impl Parse for ScrollSnapPoint {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -30,7 +30,7 @@ impl Parse for ScrollSnapPoint {
|
|||
}
|
||||
input.expect_function_matching("repeat")?;
|
||||
let length =
|
||||
input.parse_nested_block(|i| LengthOrPercentage::parse_non_negative(context, i))?;
|
||||
input.parse_nested_block(|i| LengthPercentage::parse_non_negative(context, i))?;
|
||||
Ok(GenericScrollSnapPoint::Repeat(length))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::values::computed::{self, Context, ToComputedValue};
|
|||
use crate::values::generics::grid::{GridTemplateComponent, RepeatCount, TrackBreadth};
|
||||
use crate::values::generics::grid::{LineNameList, TrackKeyword, TrackRepeat, TrackSize};
|
||||
use crate::values::generics::grid::{TrackList, TrackListType, TrackListValue};
|
||||
use crate::values::specified::{Integer, LengthOrPercentage};
|
||||
use crate::values::specified::{Integer, LengthPercentage};
|
||||
use crate::values::{CSSFloat, CustomIdent};
|
||||
use cssparser::{ParseError as CssParseError, Parser, Token};
|
||||
use std::mem;
|
||||
|
@ -27,12 +27,12 @@ pub fn parse_flex<'i, 't>(input: &mut Parser<'i, 't>) -> Result<CSSFloat, ParseE
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for TrackBreadth<LengthOrPercentage> {
|
||||
impl Parse for TrackBreadth<LengthPercentage> {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) {
|
||||
if let Ok(lop) = input.try(|i| LengthPercentage::parse_non_negative(context, i)) {
|
||||
return Ok(TrackBreadth::Breadth(lop));
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ impl Parse for TrackBreadth<LengthOrPercentage> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for TrackSize<LengthOrPercentage> {
|
||||
impl Parse for TrackSize<LengthPercentage> {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
|
@ -56,7 +56,7 @@ impl Parse for TrackSize<LengthOrPercentage> {
|
|||
if input.try(|i| i.expect_function_matching("minmax")).is_ok() {
|
||||
return input.parse_nested_block(|input| {
|
||||
let inflexible_breadth =
|
||||
match input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) {
|
||||
match input.try(|i| LengthPercentage::parse_non_negative(context, i)) {
|
||||
Ok(lop) => TrackBreadth::Breadth(lop),
|
||||
Err(..) => {
|
||||
let keyword = TrackKeyword::parse(input)?;
|
||||
|
@ -74,7 +74,7 @@ impl Parse for TrackSize<LengthOrPercentage> {
|
|||
|
||||
input.expect_function_matching("fit-content")?;
|
||||
let lop =
|
||||
input.parse_nested_block(|i| LengthOrPercentage::parse_non_negative(context, i))?;
|
||||
input.parse_nested_block(|i| LengthPercentage::parse_non_negative(context, i))?;
|
||||
Ok(TrackSize::FitContent(lop))
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ enum RepeatType {
|
|||
Fixed,
|
||||
}
|
||||
|
||||
impl TrackRepeat<LengthOrPercentage, Integer> {
|
||||
impl TrackRepeat<LengthPercentage, Integer> {
|
||||
fn parse_with_repeat_type<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
|
@ -195,7 +195,7 @@ impl TrackRepeat<LengthOrPercentage, Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for TrackList<LengthOrPercentage, Integer> {
|
||||
impl Parse for TrackList<LengthPercentage, Integer> {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
|
@ -293,8 +293,8 @@ impl Parse for TrackList<LengthOrPercentage, Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for TrackList<LengthOrPercentage, Integer> {
|
||||
type ComputedValue = TrackList<computed::LengthOrPercentage, computed::Integer>;
|
||||
impl ToComputedValue for TrackList<LengthPercentage, Integer> {
|
||||
type ComputedValue = TrackList<computed::LengthPercentage, computed::Integer>;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
|
@ -391,7 +391,7 @@ fn allow_grid_template_subgrids() -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
impl Parse for GridTemplateComponent<LengthOrPercentage, Integer> {
|
||||
impl Parse for GridTemplateComponent<LengthPercentage, Integer> {
|
||||
// FIXME: Derive Parse (probably with None_)
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
@ -405,8 +405,8 @@ impl Parse for GridTemplateComponent<LengthOrPercentage, Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl GridTemplateComponent<LengthOrPercentage, Integer> {
|
||||
/// Parses a `GridTemplateComponent<LengthOrPercentage>` except `none` keyword.
|
||||
impl GridTemplateComponent<LengthPercentage, Integer> {
|
||||
/// Parses a `GridTemplateComponent<LengthPercentage>` except `none` keyword.
|
||||
pub fn parse_without_none<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::values::generics::image::{self as generic, Circle, CompatMode, Ellips
|
|||
use crate::values::generics::position::Position as GenericPosition;
|
||||
use crate::values::specified::position::{LegacyPosition, Position, PositionComponent, Side, X, Y};
|
||||
use crate::values::specified::url::SpecifiedImageUrl;
|
||||
use crate::values::specified::{Angle, Color, Length, LengthOrPercentage};
|
||||
use crate::values::specified::{Angle, Color, Length, LengthPercentage};
|
||||
use crate::values::specified::{Number, NumberOrPercentage, Percentage};
|
||||
use crate::values::{Either, None_};
|
||||
use crate::Atom;
|
||||
|
@ -54,13 +54,13 @@ pub type Image = generic::Image<Gradient, MozImageRect, SpecifiedImageUrl>;
|
|||
/// <https://drafts.csswg.org/css-images/#gradients>
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
pub type Gradient =
|
||||
generic::Gradient<LineDirection, Length, LengthOrPercentage, Position, Color, Angle>;
|
||||
generic::Gradient<LineDirection, Length, LengthPercentage, Position, Color, Angle>;
|
||||
|
||||
/// Specified values for a CSS gradient.
|
||||
/// <https://drafts.csswg.org/css-images/#gradients>
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type Gradient =
|
||||
generic::Gradient<LineDirection, Length, LengthOrPercentage, GradientPosition, Color, Angle>;
|
||||
generic::Gradient<LineDirection, Length, LengthPercentage, GradientPosition, Color, Angle>;
|
||||
|
||||
impl SpecifiedValueInfo for Gradient {
|
||||
const SUPPORTED_TYPES: u8 = CssType::GRADIENT;
|
||||
|
@ -88,12 +88,12 @@ impl SpecifiedValueInfo for Gradient {
|
|||
/// A specified gradient kind.
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
pub type GradientKind =
|
||||
generic::GradientKind<LineDirection, Length, LengthOrPercentage, Position, Angle>;
|
||||
generic::GradientKind<LineDirection, Length, LengthPercentage, Position, Angle>;
|
||||
|
||||
/// A specified gradient kind.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type GradientKind =
|
||||
generic::GradientKind<LineDirection, Length, LengthOrPercentage, GradientPosition, Angle>;
|
||||
generic::GradientKind<LineDirection, Length, LengthPercentage, GradientPosition, Angle>;
|
||||
|
||||
/// A specified gradient line direction.
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
|
@ -125,13 +125,13 @@ pub enum GradientPosition {
|
|||
}
|
||||
|
||||
/// A specified ending shape.
|
||||
pub type EndingShape = generic::EndingShape<Length, LengthOrPercentage>;
|
||||
pub type EndingShape = generic::EndingShape<Length, LengthPercentage>;
|
||||
|
||||
/// A specified gradient item.
|
||||
pub type GradientItem = generic::GradientItem<Color, LengthOrPercentage>;
|
||||
pub type GradientItem = generic::GradientItem<Color, LengthPercentage>;
|
||||
|
||||
/// A computed color stop.
|
||||
pub type ColorStop = generic::ColorStop<Color, LengthOrPercentage>;
|
||||
pub type ColorStop = generic::ColorStop<Color, LengthPercentage>;
|
||||
|
||||
/// Specified values for `moz-image-rect`
|
||||
/// -moz-image-rect(<uri>, top, right, bottom, left);
|
||||
|
@ -538,8 +538,8 @@ impl Gradient {
|
|||
&generic::GradientItem::ColorStop(ref b),
|
||||
) => match (&a.position, &b.position) {
|
||||
(
|
||||
&Some(LengthOrPercentage::Percentage(a)),
|
||||
&Some(LengthOrPercentage::Percentage(b)),
|
||||
&Some(LengthPercentage::Percentage(a)),
|
||||
&Some(LengthPercentage::Percentage(b)),
|
||||
) => {
|
||||
return a.0.partial_cmp(&b.0).unwrap_or(Ordering::Equal);
|
||||
},
|
||||
|
@ -698,14 +698,14 @@ impl generic::LineDirection for LineDirection {
|
|||
// These percentage values can also be keywords.
|
||||
let x = match *x {
|
||||
OriginComponent::Center => true,
|
||||
OriginComponent::Length(LengthOrPercentage::Percentage(
|
||||
OriginComponent::Length(LengthPercentage::Percentage(
|
||||
ComputedPercentage(val),
|
||||
)) => val == 0.5,
|
||||
_ => false,
|
||||
};
|
||||
let y = match *y {
|
||||
OriginComponent::Side(Y::Top) => true,
|
||||
OriginComponent::Length(LengthOrPercentage::Percentage(
|
||||
OriginComponent::Length(LengthPercentage::Percentage(
|
||||
ComputedPercentage(val),
|
||||
)) => val == 0.0,
|
||||
_ => false,
|
||||
|
@ -876,8 +876,8 @@ impl EndingShape {
|
|||
}
|
||||
if compat_mode == CompatMode::Modern {
|
||||
let pair: Result<_, ParseError> = input.try(|i| {
|
||||
let x = LengthOrPercentage::parse(context, i)?;
|
||||
let y = LengthOrPercentage::parse(context, i)?;
|
||||
let x = LengthPercentage::parse(context, i)?;
|
||||
let y = LengthPercentage::parse(context, i)?;
|
||||
Ok((x, y))
|
||||
});
|
||||
if let Ok((x, y)) = pair {
|
||||
|
@ -888,11 +888,11 @@ impl EndingShape {
|
|||
ShapeExtent::FarthestCorner,
|
||||
)));
|
||||
}
|
||||
// -moz- prefixed radial gradient doesn't allow EndingShape's Length or LengthOrPercentage
|
||||
// -moz- prefixed radial gradient doesn't allow EndingShape's Length or LengthPercentage
|
||||
// to come before shape keyword. Otherwise it conflicts with <position>.
|
||||
if compat_mode != CompatMode::Moz {
|
||||
if let Ok(length) = input.try(|i| Length::parse(context, i)) {
|
||||
if let Ok(y) = input.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(y) = input.try(|i| LengthPercentage::parse(context, i)) {
|
||||
if compat_mode == CompatMode::Modern {
|
||||
let _ = input.try(|i| i.expect_ident_matching("ellipse"));
|
||||
}
|
||||
|
@ -904,7 +904,7 @@ impl EndingShape {
|
|||
if compat_mode == CompatMode::Modern {
|
||||
let y = input.try(|i| {
|
||||
i.expect_ident_matching("ellipse")?;
|
||||
LengthOrPercentage::parse(context, i)
|
||||
LengthPercentage::parse(context, i)
|
||||
});
|
||||
if let Ok(y) = y {
|
||||
return Ok(generic::EndingShape::Ellipse(Ellipse::Radii(
|
||||
|
@ -920,7 +920,7 @@ impl EndingShape {
|
|||
}
|
||||
input.try(|i| {
|
||||
let x = Percentage::parse(context, i)?;
|
||||
let y = if let Ok(y) = i.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
let y = if let Ok(y) = i.try(|i| LengthPercentage::parse(context, i)) {
|
||||
if compat_mode == CompatMode::Modern {
|
||||
let _ = i.try(|i| i.expect_ident_matching("ellipse"));
|
||||
}
|
||||
|
@ -929,7 +929,7 @@ impl EndingShape {
|
|||
if compat_mode == CompatMode::Modern {
|
||||
i.expect_ident_matching("ellipse")?;
|
||||
}
|
||||
LengthOrPercentage::parse(context, i)?
|
||||
LengthPercentage::parse(context, i)?
|
||||
};
|
||||
Ok(generic::EndingShape::Ellipse(Ellipse::Radii(x.into(), y)))
|
||||
})
|
||||
|
@ -963,7 +963,7 @@ impl GradientItem {
|
|||
loop {
|
||||
input.parse_until_before(Delimiter::Comma, |input| {
|
||||
if seen_stop {
|
||||
if let Ok(hint) = input.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(hint) = input.try(|i| LengthPercentage::parse(context, i)) {
|
||||
seen_stop = false;
|
||||
items.push(generic::GradientItem::InterpolationHint(hint));
|
||||
return Ok(());
|
||||
|
@ -972,7 +972,7 @@ impl GradientItem {
|
|||
|
||||
let stop = ColorStop::parse(context, input)?;
|
||||
|
||||
if let Ok(multi_position) = input.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(multi_position) = input.try(|i| LengthPercentage::parse(context, i)) {
|
||||
let stop_color = stop.color.clone();
|
||||
items.push(generic::GradientItem::ColorStop(stop));
|
||||
items.push(generic::GradientItem::ColorStop(ColorStop {
|
||||
|
@ -1008,7 +1008,7 @@ impl Parse for ColorStop {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(ColorStop {
|
||||
color: Color::parse(context, input)?,
|
||||
position: input.try(|i| LengthOrPercentage::parse(context, i)).ok(),
|
||||
position: input.try(|i| LengthPercentage::parse(context, i)).ok(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ use style_traits::{ParseError, SpecifiedValueInfo, StyleParseErrorKind};
|
|||
|
||||
pub use super::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
pub use super::image::{GradientKind, Image};
|
||||
pub use crate::values::specified::calc::CalcLengthOrPercentage;
|
||||
pub use crate::values::specified::calc::CalcLengthPercentage;
|
||||
|
||||
/// Number of app units per pixel
|
||||
pub const AU_PER_PX: CSSFloat = 60.;
|
||||
|
@ -530,7 +530,7 @@ pub enum Length {
|
|||
/// A calc expression.
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-values/#calc-notation>
|
||||
Calc(Box<CalcLengthOrPercentage>),
|
||||
Calc(Box<CalcLengthPercentage>),
|
||||
}
|
||||
|
||||
impl From<NoCalcLength> for Length {
|
||||
|
@ -736,63 +736,66 @@ impl NonNegativeLength {
|
|||
/// Either a NonNegativeLength or the `auto` keyword.
|
||||
pub type NonNegativeLengthOrAuto = Either<NonNegativeLength, Auto>;
|
||||
|
||||
/// A length or a percentage value.
|
||||
/// A `<length-percentage>` value. This can be either a `<length>`, a
|
||||
/// `<percentage>`, or a combination of both via `calc()`.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-values-4/#typedef-length-percentage
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||
pub enum LengthOrPercentage {
|
||||
pub enum LengthPercentage {
|
||||
Length(NoCalcLength),
|
||||
Percentage(computed::Percentage),
|
||||
Calc(Box<CalcLengthOrPercentage>),
|
||||
Calc(Box<CalcLengthPercentage>),
|
||||
}
|
||||
|
||||
impl From<Length> for LengthOrPercentage {
|
||||
fn from(len: Length) -> LengthOrPercentage {
|
||||
impl From<Length> for LengthPercentage {
|
||||
fn from(len: Length) -> LengthPercentage {
|
||||
match len {
|
||||
Length::NoCalc(l) => LengthOrPercentage::Length(l),
|
||||
Length::Calc(l) => LengthOrPercentage::Calc(l),
|
||||
Length::NoCalc(l) => LengthPercentage::Length(l),
|
||||
Length::Calc(l) => LengthPercentage::Calc(l),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NoCalcLength> for LengthOrPercentage {
|
||||
impl From<NoCalcLength> for LengthPercentage {
|
||||
#[inline]
|
||||
fn from(len: NoCalcLength) -> Self {
|
||||
LengthOrPercentage::Length(len)
|
||||
LengthPercentage::Length(len)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Percentage> for LengthOrPercentage {
|
||||
impl From<Percentage> for LengthPercentage {
|
||||
#[inline]
|
||||
fn from(pc: Percentage) -> Self {
|
||||
if pc.is_calc() {
|
||||
LengthOrPercentage::Calc(Box::new(CalcLengthOrPercentage {
|
||||
LengthPercentage::Calc(Box::new(CalcLengthPercentage {
|
||||
percentage: Some(computed::Percentage(pc.get())),
|
||||
..Default::default()
|
||||
}))
|
||||
} else {
|
||||
LengthOrPercentage::Percentage(computed::Percentage(pc.get()))
|
||||
LengthPercentage::Percentage(computed::Percentage(pc.get()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<computed::Percentage> for LengthOrPercentage {
|
||||
impl From<computed::Percentage> for LengthPercentage {
|
||||
#[inline]
|
||||
fn from(pc: computed::Percentage) -> Self {
|
||||
LengthOrPercentage::Percentage(pc)
|
||||
LengthPercentage::Percentage(pc)
|
||||
}
|
||||
}
|
||||
|
||||
impl LengthOrPercentage {
|
||||
impl LengthPercentage {
|
||||
#[inline]
|
||||
/// Returns a `zero` length.
|
||||
pub fn zero() -> LengthOrPercentage {
|
||||
LengthOrPercentage::Length(NoCalcLength::zero())
|
||||
pub fn zero() -> LengthPercentage {
|
||||
LengthPercentage::Length(NoCalcLength::zero())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns a `0%` value.
|
||||
pub fn zero_percent() -> LengthOrPercentage {
|
||||
LengthOrPercentage::Percentage(computed::Percentage::zero())
|
||||
pub fn zero_percent() -> LengthPercentage {
|
||||
LengthPercentage::Percentage(computed::Percentage::zero())
|
||||
}
|
||||
|
||||
fn parse_internal<'i, 't>(
|
||||
|
@ -810,13 +813,13 @@ impl LengthOrPercentage {
|
|||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) => {
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(LengthOrPercentage::Length)
|
||||
.map(LengthPercentage::Length)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()));
|
||||
},
|
||||
Token::Percentage { unit_value, .. }
|
||||
if num_context.is_ok(context.parsing_mode, unit_value) =>
|
||||
{
|
||||
return Ok(LengthOrPercentage::Percentage(computed::Percentage(
|
||||
return Ok(LengthPercentage::Percentage(computed::Percentage(
|
||||
unit_value,
|
||||
)));
|
||||
}
|
||||
|
@ -827,7 +830,7 @@ impl LengthOrPercentage {
|
|||
{
|
||||
return Err(location.new_unexpected_token_error(token.clone()));
|
||||
} else {
|
||||
return Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value)));
|
||||
return Ok(LengthPercentage::Length(NoCalcLength::from_px(value)));
|
||||
}
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
|
@ -838,7 +841,7 @@ impl LengthOrPercentage {
|
|||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
Ok(LengthOrPercentage::Calc(Box::new(calc)))
|
||||
Ok(LengthPercentage::Calc(Box::new(calc)))
|
||||
}
|
||||
|
||||
/// Parse a non-negative length.
|
||||
|
@ -846,7 +849,7 @@ impl LengthOrPercentage {
|
|||
pub fn parse_non_negative<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<LengthOrPercentage, ParseError<'i>> {
|
||||
) -> Result<LengthPercentage, ParseError<'i>> {
|
||||
Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
|
||||
|
@ -856,7 +859,7 @@ impl LengthOrPercentage {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<LengthOrPercentage, ParseError<'i>> {
|
||||
) -> Result<LengthPercentage, ParseError<'i>> {
|
||||
Self::parse_internal(
|
||||
context,
|
||||
input,
|
||||
|
@ -866,7 +869,7 @@ impl LengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for LengthOrPercentage {
|
||||
impl Parse for LengthPercentage {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
@ -876,7 +879,7 @@ impl Parse for LengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl LengthOrPercentage {
|
||||
impl LengthPercentage {
|
||||
/// Parses a length or a percentage, allowing the unitless length quirk.
|
||||
/// <https://quirks.spec.whatwg.org/#the-unitless-length-quirk>
|
||||
#[inline]
|
||||
|
@ -889,13 +892,13 @@ impl LengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl IsZeroLength for LengthOrPercentage {
|
||||
impl IsZeroLength for LengthPercentage {
|
||||
#[inline]
|
||||
fn is_zero_length(&self) -> bool {
|
||||
match *self {
|
||||
LengthOrPercentage::Length(l) => l.is_zero_length(),
|
||||
LengthOrPercentage::Percentage(p) => p.0 == 0.0,
|
||||
LengthOrPercentage::Calc(_) => false,
|
||||
LengthPercentage::Length(l) => l.is_zero_length(),
|
||||
LengthPercentage::Percentage(p) => p.0 == 0.0,
|
||||
LengthPercentage::Calc(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -903,12 +906,12 @@ impl IsZeroLength for LengthOrPercentage {
|
|||
/// Either a `<length>`, a `<percentage>`, or the `auto` keyword.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||
pub enum LengthOrPercentageOrAuto {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
pub enum LengthPercentageOrAuto {
|
||||
LengthPercentage(LengthPercentage),
|
||||
Auto,
|
||||
}
|
||||
|
||||
impl LengthOrPercentageOrAuto {
|
||||
impl LengthPercentageOrAuto {
|
||||
fn parse_internal<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
|
@ -916,10 +919,10 @@ impl LengthOrPercentageOrAuto {
|
|||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
return Ok(LengthOrPercentageOrAuto::Auto);
|
||||
return Ok(LengthPercentageOrAuto::Auto);
|
||||
}
|
||||
|
||||
Ok(LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::parse_internal(
|
||||
Ok(LengthPercentageOrAuto::LengthPercentage(LengthPercentage::parse_internal(
|
||||
context,
|
||||
input,
|
||||
num_context,
|
||||
|
@ -932,7 +935,7 @@ impl LengthOrPercentageOrAuto {
|
|||
pub fn parse_non_negative<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<LengthOrPercentageOrAuto, ParseError<'i>> {
|
||||
) -> Result<LengthPercentageOrAuto, ParseError<'i>> {
|
||||
Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
|
||||
|
@ -953,18 +956,18 @@ impl LengthOrPercentageOrAuto {
|
|||
|
||||
/// Returns the `auto` value.
|
||||
pub fn auto() -> Self {
|
||||
LengthOrPercentageOrAuto::Auto
|
||||
LengthPercentageOrAuto::Auto
|
||||
}
|
||||
|
||||
/// Returns a value representing a `0` length.
|
||||
pub fn zero() -> Self {
|
||||
LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::zero())
|
||||
LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero())
|
||||
}
|
||||
|
||||
/// Returns a value representing `0%`.
|
||||
#[inline]
|
||||
pub fn zero_percent() -> Self {
|
||||
LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::zero_percent())
|
||||
LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero_percent())
|
||||
}
|
||||
|
||||
/// Parses, with quirks.
|
||||
|
@ -978,7 +981,7 @@ impl LengthOrPercentageOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for LengthOrPercentageOrAuto {
|
||||
impl Parse for LengthPercentageOrAuto {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
@ -988,43 +991,43 @@ impl Parse for LengthOrPercentageOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
/// A wrapper of LengthOrPercentageOrAuto, whose value must be >= 0.
|
||||
pub type NonNegativeLengthOrPercentageOrAuto = NonNegative<LengthOrPercentageOrAuto>;
|
||||
/// A wrapper of LengthPercentageOrAuto, whose value must be >= 0.
|
||||
pub type NonNegativeLengthPercentageOrAuto = NonNegative<LengthPercentageOrAuto>;
|
||||
|
||||
impl IsAuto for NonNegativeLengthOrPercentageOrAuto {
|
||||
impl IsAuto for NonNegativeLengthPercentageOrAuto {
|
||||
#[inline]
|
||||
fn is_auto(&self) -> bool {
|
||||
*self == Self::auto()
|
||||
}
|
||||
}
|
||||
|
||||
impl NonNegativeLengthOrPercentageOrAuto {
|
||||
impl NonNegativeLengthPercentageOrAuto {
|
||||
/// 0
|
||||
#[inline]
|
||||
pub fn zero() -> Self {
|
||||
NonNegative(LengthOrPercentageOrAuto::zero())
|
||||
NonNegative(LengthPercentageOrAuto::zero())
|
||||
}
|
||||
|
||||
/// 0%
|
||||
#[inline]
|
||||
pub fn zero_percent() -> Self {
|
||||
NonNegative(LengthOrPercentageOrAuto::zero_percent())
|
||||
NonNegative(LengthPercentageOrAuto::zero_percent())
|
||||
}
|
||||
|
||||
/// `auto`
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
NonNegative(LengthOrPercentageOrAuto::Auto)
|
||||
NonNegative(LengthPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for NonNegativeLengthOrPercentageOrAuto {
|
||||
impl Parse for NonNegativeLengthPercentageOrAuto {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(NonNegative(LengthOrPercentageOrAuto::parse_non_negative(
|
||||
Ok(NonNegative(LengthPercentageOrAuto::parse_non_negative(
|
||||
context, input,
|
||||
)?))
|
||||
}
|
||||
|
@ -1033,12 +1036,12 @@ impl Parse for NonNegativeLengthOrPercentageOrAuto {
|
|||
/// Either a `<length>`, a `<percentage>`, or the `none` keyword.
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum LengthOrPercentageOrNone {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
pub enum LengthPercentageOrNone {
|
||||
LengthPercentage(LengthPercentage),
|
||||
None,
|
||||
}
|
||||
|
||||
impl LengthOrPercentageOrNone {
|
||||
impl LengthPercentageOrNone {
|
||||
fn parse_internal<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
|
@ -1046,10 +1049,10 @@ impl LengthOrPercentageOrNone {
|
|||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(LengthOrPercentageOrNone::None);
|
||||
return Ok(LengthPercentageOrNone::None);
|
||||
}
|
||||
|
||||
Ok(LengthOrPercentageOrNone::LengthOrPercentage(LengthOrPercentage::parse_internal(
|
||||
Ok(LengthPercentageOrNone::LengthPercentage(LengthPercentage::parse_internal(
|
||||
context,
|
||||
input,
|
||||
num_context,
|
||||
|
@ -1057,7 +1060,7 @@ impl LengthOrPercentageOrNone {
|
|||
)?))
|
||||
}
|
||||
|
||||
/// Parse a non-negative LengthOrPercentageOrNone.
|
||||
/// Parse a non-negative LengthPercentageOrNone.
|
||||
#[inline]
|
||||
pub fn parse_non_negative<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
@ -1066,7 +1069,7 @@ impl LengthOrPercentageOrNone {
|
|||
Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
|
||||
/// Parse a non-negative LengthOrPercentageOrNone, with quirks.
|
||||
/// Parse a non-negative LengthPercentageOrNone, with quirks.
|
||||
#[inline]
|
||||
pub fn parse_non_negative_quirky<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
@ -1082,7 +1085,7 @@ impl LengthOrPercentageOrNone {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for LengthOrPercentageOrNone {
|
||||
impl Parse for LengthPercentageOrNone {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
@ -1092,38 +1095,38 @@ impl Parse for LengthOrPercentageOrNone {
|
|||
}
|
||||
}
|
||||
|
||||
/// A wrapper of LengthOrPercentage, whose value must be >= 0.
|
||||
pub type NonNegativeLengthOrPercentage = NonNegative<LengthOrPercentage>;
|
||||
/// A wrapper of LengthPercentage, whose value must be >= 0.
|
||||
pub type NonNegativeLengthPercentage = NonNegative<LengthPercentage>;
|
||||
|
||||
/// Either a computed NonNegativeLength or the `normal` keyword.
|
||||
pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>;
|
||||
|
||||
/// Either a NonNegativeLengthOrPercentage or the `normal` keyword.
|
||||
pub type NonNegativeLengthOrPercentageOrNormal = Either<NonNegativeLengthOrPercentage, Normal>;
|
||||
/// Either a NonNegativeLengthPercentage or the `normal` keyword.
|
||||
pub type NonNegativeLengthPercentageOrNormal = Either<NonNegativeLengthPercentage, Normal>;
|
||||
|
||||
impl From<NoCalcLength> for NonNegativeLengthOrPercentage {
|
||||
impl From<NoCalcLength> for NonNegativeLengthPercentage {
|
||||
#[inline]
|
||||
fn from(len: NoCalcLength) -> Self {
|
||||
NonNegative::<LengthOrPercentage>(LengthOrPercentage::from(len))
|
||||
NonNegative::<LengthPercentage>(LengthPercentage::from(len))
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for NonNegativeLengthOrPercentage {
|
||||
impl Parse for NonNegativeLengthPercentage {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
LengthOrPercentage::parse_non_negative(context, input)
|
||||
.map(NonNegative::<LengthOrPercentage>)
|
||||
LengthPercentage::parse_non_negative(context, input)
|
||||
.map(NonNegative::<LengthPercentage>)
|
||||
}
|
||||
}
|
||||
|
||||
impl NonNegativeLengthOrPercentage {
|
||||
impl NonNegativeLengthPercentage {
|
||||
#[inline]
|
||||
/// Returns a `zero` length.
|
||||
pub fn zero() -> Self {
|
||||
NonNegative::<LengthOrPercentage>(LengthOrPercentage::zero())
|
||||
NonNegative::<LengthPercentage>(LengthPercentage::zero())
|
||||
}
|
||||
|
||||
/// Parses a length or a percentage, allowing the unitless length quirk.
|
||||
|
@ -1134,8 +1137,8 @@ impl NonNegativeLengthOrPercentage {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
LengthOrPercentage::parse_non_negative_quirky(context, input, allow_quirks)
|
||||
.map(NonNegative::<LengthOrPercentage>)
|
||||
LengthPercentage::parse_non_negative_quirky(context, input, allow_quirks)
|
||||
.map(NonNegative::<LengthPercentage>)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1172,7 +1175,7 @@ impl LengthOrNumber {
|
|||
}
|
||||
|
||||
/// A specified value for `min-width`, `min-height`, `width` or `height` property.
|
||||
pub type MozLength = GenericMozLength<LengthOrPercentageOrAuto>;
|
||||
pub type MozLength = GenericMozLength<LengthPercentageOrAuto>;
|
||||
|
||||
impl Parse for MozLength {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -1195,25 +1198,25 @@ impl MozLength {
|
|||
}
|
||||
|
||||
let length =
|
||||
LengthOrPercentageOrAuto::parse_non_negative_quirky(context, input, allow_quirks)?;
|
||||
Ok(GenericMozLength::LengthOrPercentageOrAuto(length))
|
||||
LengthPercentageOrAuto::parse_non_negative_quirky(context, input, allow_quirks)?;
|
||||
Ok(GenericMozLength::LengthPercentageOrAuto(length))
|
||||
}
|
||||
|
||||
/// Returns `auto`.
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
GenericMozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::auto())
|
||||
GenericMozLength::LengthPercentageOrAuto(LengthPercentageOrAuto::auto())
|
||||
}
|
||||
|
||||
/// Returns `0%`.
|
||||
#[inline]
|
||||
pub fn zero_percent() -> Self {
|
||||
GenericMozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::zero_percent())
|
||||
GenericMozLength::LengthPercentageOrAuto(LengthPercentageOrAuto::zero_percent())
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified value for `max-width` or `max-height` property.
|
||||
pub type MaxLength = GenericMaxLength<LengthOrPercentageOrNone>;
|
||||
pub type MaxLength = GenericMaxLength<LengthPercentageOrNone>;
|
||||
|
||||
impl Parse for MaxLength {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -1236,7 +1239,7 @@ impl MaxLength {
|
|||
}
|
||||
|
||||
let length =
|
||||
LengthOrPercentageOrNone::parse_non_negative_quirky(context, input, allow_quirks)?;
|
||||
Ok(GenericMaxLength::LengthOrPercentageOrNone(length))
|
||||
LengthPercentageOrNone::parse_non_negative_quirky(context, input, allow_quirks)?;
|
||||
Ok(GenericMaxLength::LengthPercentageOrNone(length))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,12 +55,12 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier,
|
|||
pub use self::gecko::ScrollSnapPoint;
|
||||
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
|
||||
pub use self::length::{AbsoluteLength, CalcLengthOrPercentage, CharacterWidth};
|
||||
pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};
|
||||
pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
|
||||
pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength};
|
||||
pub use self::length::{LengthPercentage, LengthPercentageOrAuto};
|
||||
pub use self::length::{LengthPercentageOrNone, MaxLength, MozLength};
|
||||
pub use self::length::{NoCalcLength, ViewportPercentageLength};
|
||||
pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto};
|
||||
pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto};
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::list::ListStyleType;
|
||||
pub use self::list::{QuotePair, Quotes};
|
||||
|
@ -567,20 +567,20 @@ impl Parse for PositiveInteger {
|
|||
}
|
||||
|
||||
/// The specified value of a grid `<track-breadth>`
|
||||
pub type TrackBreadth = GenericTrackBreadth<LengthOrPercentage>;
|
||||
pub type TrackBreadth = GenericTrackBreadth<LengthPercentage>;
|
||||
|
||||
/// The specified value of a grid `<track-size>`
|
||||
pub type TrackSize = GenericTrackSize<LengthOrPercentage>;
|
||||
pub type TrackSize = GenericTrackSize<LengthPercentage>;
|
||||
|
||||
/// The specified value of a grid `<track-list>`
|
||||
/// (could also be `<auto-track-list>` or `<explicit-track-list>`)
|
||||
pub type TrackList = GenericTrackList<LengthOrPercentage, Integer>;
|
||||
pub type TrackList = GenericTrackList<LengthPercentage, Integer>;
|
||||
|
||||
/// The specified value of a `<grid-line>`.
|
||||
pub type GridLine = GenericGridLine<Integer>;
|
||||
|
||||
/// `<grid-template-rows> | <grid-template-columns>`
|
||||
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthOrPercentage, Integer>;
|
||||
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthPercentage, Integer>;
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo)]
|
||||
/// rect(<top>, <left>, <bottom>, <right>) used by clip and image-region
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
use crate::hash::FxHashMap;
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::str::HTML_SPACE_CHARACTERS;
|
||||
use crate::values::computed::LengthOrPercentage as ComputedLengthOrPercentage;
|
||||
use crate::values::computed::LengthPercentage as ComputedLengthPercentage;
|
||||
use crate::values::computed::{Context, Percentage, ToComputedValue};
|
||||
use crate::values::generics::position::Position as GenericPosition;
|
||||
use crate::values::generics::position::ZIndex as GenericZIndex;
|
||||
use crate::values::specified::transform::OriginComponent;
|
||||
use crate::values::specified::{AllowQuirks, Integer, LengthOrPercentage};
|
||||
use crate::values::specified::{AllowQuirks, Integer, LengthPercentage};
|
||||
use crate::values::{Either, None_};
|
||||
use cssparser::Parser;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
|
@ -39,9 +39,9 @@ pub enum PositionComponent<S> {
|
|||
/// `center`
|
||||
Center,
|
||||
/// `<lop>`
|
||||
Length(LengthOrPercentage),
|
||||
Length(LengthPercentage),
|
||||
/// `<side> <lop>?`
|
||||
Side(S, Option<LengthOrPercentage>),
|
||||
Side(S, Option<LengthPercentage>),
|
||||
}
|
||||
|
||||
/// A keyword for the X direction.
|
||||
|
@ -121,7 +121,7 @@ impl Position {
|
|||
}
|
||||
if let Ok(y_keyword) = input.try(Y::parse) {
|
||||
let y_lop = input
|
||||
.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.ok();
|
||||
let x_pos = PositionComponent::Side(x_keyword, lop);
|
||||
let y_pos = PositionComponent::Side(y_keyword, y_lop);
|
||||
|
@ -137,7 +137,7 @@ impl Position {
|
|||
return Ok(Self::new(x_pos, y_pos));
|
||||
}
|
||||
if let Ok(y_lop) =
|
||||
input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
|
||||
input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
{
|
||||
let y_pos = PositionComponent::Length(y_lop);
|
||||
return Ok(Self::new(x_pos, y_pos));
|
||||
|
@ -151,11 +151,11 @@ impl Position {
|
|||
let y_keyword = Y::parse(input)?;
|
||||
let lop_and_x_pos: Result<_, ParseError> = input.try(|i| {
|
||||
let y_lop = i
|
||||
.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.ok();
|
||||
if let Ok(x_keyword) = i.try(X::parse) {
|
||||
let x_lop = i
|
||||
.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.ok();
|
||||
let x_pos = PositionComponent::Side(x_keyword, x_lop);
|
||||
return Ok((y_lop, x_pos));
|
||||
|
@ -231,12 +231,12 @@ impl<S: Parse> PositionComponent<S> {
|
|||
if input.try(|i| i.expect_ident_matching("center")).is_ok() {
|
||||
return Ok(PositionComponent::Center);
|
||||
}
|
||||
if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) {
|
||||
if let Ok(lop) = input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) {
|
||||
return Ok(PositionComponent::Length(lop));
|
||||
}
|
||||
let keyword = S::parse(context, input)?;
|
||||
let lop = input
|
||||
.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.ok();
|
||||
Ok(PositionComponent::Side(keyword, lop))
|
||||
}
|
||||
|
@ -245,25 +245,25 @@ impl<S: Parse> PositionComponent<S> {
|
|||
impl<S> PositionComponent<S> {
|
||||
/// `0%`
|
||||
pub fn zero() -> Self {
|
||||
PositionComponent::Length(LengthOrPercentage::Percentage(Percentage::zero()))
|
||||
PositionComponent::Length(LengthPercentage::Percentage(Percentage::zero()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Side> ToComputedValue for PositionComponent<S> {
|
||||
type ComputedValue = ComputedLengthOrPercentage;
|
||||
type ComputedValue = ComputedLengthPercentage;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
PositionComponent::Center => ComputedLengthOrPercentage::new_percent(Percentage(0.5)),
|
||||
PositionComponent::Center => ComputedLengthPercentage::new_percent(Percentage(0.5)),
|
||||
PositionComponent::Side(ref keyword, None) => {
|
||||
let p = Percentage(if keyword.is_start() { 0. } else { 1. });
|
||||
ComputedLengthOrPercentage::new_percent(p)
|
||||
ComputedLengthPercentage::new_percent(p)
|
||||
},
|
||||
PositionComponent::Side(ref keyword, Some(ref length)) if !keyword.is_start() => {
|
||||
let length = length.to_computed_value(context);
|
||||
let p = Percentage(1. - length.percentage());
|
||||
let l = -length.unclamped_length();
|
||||
ComputedLengthOrPercentage::with_clamping_mode(
|
||||
ComputedLengthPercentage::with_clamping_mode(
|
||||
l,
|
||||
Some(p),
|
||||
length.clamping_mode,
|
||||
|
@ -372,7 +372,7 @@ impl LegacyPosition {
|
|||
}
|
||||
let x_pos = OriginComponent::Side(x_keyword);
|
||||
if let Ok(y_lop) =
|
||||
input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
|
||||
input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
{
|
||||
return Ok(Self::new(x_pos, OriginComponent::Length(y_lop)));
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ impl LegacyPosition {
|
|||
return Ok(Self::new(x_pos, y_pos));
|
||||
}
|
||||
if let Ok(y_lop) =
|
||||
input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
|
||||
input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
{
|
||||
let y_pos = OriginComponent::Length(y_lop);
|
||||
return Ok(Self::new(x_pos, y_pos));
|
||||
|
|
|
@ -8,8 +8,8 @@ use crate::parser::{Parse, ParserContext};
|
|||
use crate::values::generics::svg as generic;
|
||||
use crate::values::specified::color::Color;
|
||||
use crate::values::specified::url::SpecifiedUrl;
|
||||
use crate::values::specified::LengthOrPercentage;
|
||||
use crate::values::specified::{NonNegativeLengthOrPercentage, NonNegativeNumber};
|
||||
use crate::values::specified::LengthPercentage;
|
||||
use crate::values::specified::{NonNegativeLengthPercentage, NonNegativeNumber};
|
||||
use crate::values::specified::{Number, Opacity};
|
||||
use crate::values::CustomIdent;
|
||||
use cssparser::Parser;
|
||||
|
@ -50,11 +50,11 @@ fn parse_context_value<'i, 't, T>(
|
|||
|
||||
/// A value of <length> | <percentage> | <number> for stroke-dashoffset.
|
||||
/// <https://www.w3.org/TR/SVG11/painting.html#StrokeProperties>
|
||||
pub type SvgLengthOrPercentageOrNumber =
|
||||
generic::SvgLengthOrPercentageOrNumber<LengthOrPercentage, Number>;
|
||||
pub type SvgLengthPercentageOrNumber =
|
||||
generic::SvgLengthPercentageOrNumber<LengthPercentage, Number>;
|
||||
|
||||
/// <length> | <percentage> | <number> | context-value
|
||||
pub type SVGLength = generic::SVGLength<SvgLengthOrPercentageOrNumber>;
|
||||
pub type SVGLength = generic::SVGLength<SvgLengthPercentageOrNumber>;
|
||||
|
||||
impl Parse for SVGLength {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -62,25 +62,25 @@ impl Parse for SVGLength {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
input
|
||||
.try(|i| SvgLengthOrPercentageOrNumber::parse(context, i))
|
||||
.try(|i| SvgLengthPercentageOrNumber::parse(context, i))
|
||||
.map(Into::into)
|
||||
.or_else(|_| parse_context_value(input, generic::SVGLength::ContextValue))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SvgLengthOrPercentageOrNumber> for SVGLength {
|
||||
fn from(length: SvgLengthOrPercentageOrNumber) -> Self {
|
||||
impl From<SvgLengthPercentageOrNumber> for SVGLength {
|
||||
fn from(length: SvgLengthPercentageOrNumber) -> Self {
|
||||
generic::SVGLength::Length(length)
|
||||
}
|
||||
}
|
||||
|
||||
/// A value of <length> | <percentage> | <number> for stroke-width/stroke-dasharray.
|
||||
/// <https://www.w3.org/TR/SVG11/painting.html#StrokeProperties>
|
||||
pub type NonNegativeSvgLengthOrPercentageOrNumber =
|
||||
generic::SvgLengthOrPercentageOrNumber<NonNegativeLengthOrPercentage, NonNegativeNumber>;
|
||||
pub type NonNegativeSvgLengthPercentageOrNumber =
|
||||
generic::SvgLengthPercentageOrNumber<NonNegativeLengthPercentage, NonNegativeNumber>;
|
||||
|
||||
/// A non-negative version of SVGLength.
|
||||
pub type SVGWidth = generic::SVGLength<NonNegativeSvgLengthOrPercentageOrNumber>;
|
||||
pub type SVGWidth = generic::SVGLength<NonNegativeSvgLengthPercentageOrNumber>;
|
||||
|
||||
impl Parse for SVGWidth {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -88,20 +88,20 @@ impl Parse for SVGWidth {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
input
|
||||
.try(|i| NonNegativeSvgLengthOrPercentageOrNumber::parse(context, i))
|
||||
.try(|i| NonNegativeSvgLengthPercentageOrNumber::parse(context, i))
|
||||
.map(Into::into)
|
||||
.or_else(|_| parse_context_value(input, generic::SVGLength::ContextValue))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NonNegativeSvgLengthOrPercentageOrNumber> for SVGWidth {
|
||||
fn from(length: NonNegativeSvgLengthOrPercentageOrNumber) -> Self {
|
||||
impl From<NonNegativeSvgLengthPercentageOrNumber> for SVGWidth {
|
||||
fn from(length: NonNegativeSvgLengthPercentageOrNumber) -> Self {
|
||||
generic::SVGLength::Length(length)
|
||||
}
|
||||
}
|
||||
|
||||
/// [ <length> | <percentage> | <number> ]# | context-value
|
||||
pub type SVGStrokeDashArray = generic::SVGStrokeDashArray<NonNegativeSvgLengthOrPercentageOrNumber>;
|
||||
pub type SVGStrokeDashArray = generic::SVGStrokeDashArray<NonNegativeSvgLengthPercentageOrNumber>;
|
||||
|
||||
impl Parse for SVGStrokeDashArray {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -110,7 +110,7 @@ impl Parse for SVGStrokeDashArray {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(values) = input.try(|i| {
|
||||
CommaWithSpace::parse(i, |i| {
|
||||
NonNegativeSvgLengthOrPercentageOrNumber::parse(context, i)
|
||||
NonNegativeSvgLengthPercentageOrNumber::parse(context, i)
|
||||
})
|
||||
}) {
|
||||
Ok(generic::SVGStrokeDashArray::Values(values))
|
||||
|
|
|
@ -16,8 +16,8 @@ use crate::values::generics::text::LineHeight as GenericLineHeight;
|
|||
use crate::values::generics::text::MozTabSize as GenericMozTabSize;
|
||||
use crate::values::generics::text::Spacing;
|
||||
use crate::values::specified::length::{FontRelativeLength, Length};
|
||||
use crate::values::specified::length::{LengthOrPercentage, NoCalcLength};
|
||||
use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthOrPercentage};
|
||||
use crate::values::specified::length::{LengthPercentage, NoCalcLength};
|
||||
use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthPercentage};
|
||||
use crate::values::specified::{AllowQuirks, Integer, NonNegativeNumber, Number};
|
||||
use cssparser::{Parser, Token};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
|
@ -34,10 +34,10 @@ pub type InitialLetter = GenericInitialLetter<Number, Integer>;
|
|||
pub type LetterSpacing = Spacing<Length>;
|
||||
|
||||
/// A specified value for the `word-spacing` property.
|
||||
pub type WordSpacing = Spacing<LengthOrPercentage>;
|
||||
pub type WordSpacing = Spacing<LengthPercentage>;
|
||||
|
||||
/// A specified value for the `line-height` property.
|
||||
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLengthOrPercentage>;
|
||||
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLengthPercentage>;
|
||||
|
||||
impl Parse for InitialLetter {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -70,7 +70,7 @@ impl Parse for WordSpacing {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Spacing::parse_with(context, input, |c, i| {
|
||||
LengthOrPercentage::parse_quirky(c, i, AllowQuirks::Yes)
|
||||
LengthPercentage::parse_quirky(c, i, AllowQuirks::Yes)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ impl Parse for LineHeight {
|
|||
if let Ok(number) = input.try(|i| NonNegativeNumber::parse(context, i)) {
|
||||
return Ok(GenericLineHeight::Number(number));
|
||||
}
|
||||
if let Ok(nlop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(nlop) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) {
|
||||
return Ok(GenericLineHeight::Length(nlop));
|
||||
}
|
||||
let location = input.current_source_location();
|
||||
|
@ -118,15 +118,15 @@ impl ToComputedValue for LineHeight {
|
|||
},
|
||||
GenericLineHeight::Length(ref non_negative_lop) => {
|
||||
let result = match non_negative_lop.0 {
|
||||
LengthOrPercentage::Length(NoCalcLength::Absolute(ref abs)) => {
|
||||
LengthPercentage::Length(NoCalcLength::Absolute(ref abs)) => {
|
||||
context
|
||||
.maybe_zoom_text(abs.to_computed_value(context).into())
|
||||
.0
|
||||
},
|
||||
LengthOrPercentage::Length(ref length) => length.to_computed_value(context),
|
||||
LengthOrPercentage::Percentage(ref p) => FontRelativeLength::Em(p.0)
|
||||
LengthPercentage::Length(ref length) => length.to_computed_value(context),
|
||||
LengthPercentage::Percentage(ref p) => FontRelativeLength::Em(p.0)
|
||||
.to_computed_value(context, FontBaseSize::CurrentStyle),
|
||||
LengthOrPercentage::Calc(ref calc) => {
|
||||
LengthPercentage::Calc(ref calc) => {
|
||||
let computed_calc =
|
||||
calc.to_computed_value_zoomed(context, FontBaseSize::CurrentStyle);
|
||||
let font_relative_length =
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
//! Specified types for CSS values that are related to transformations.
|
||||
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::computed::{Context, LengthOrPercentage as ComputedLengthOrPercentage};
|
||||
use crate::values::computed::{Context, LengthPercentage as ComputedLengthPercentage};
|
||||
use crate::values::computed::{Percentage as ComputedPercentage, ToComputedValue};
|
||||
use crate::values::generics::transform as generic;
|
||||
use crate::values::generics::transform::{Matrix, Matrix3D};
|
||||
use crate::values::specified::position::{Side, X, Y};
|
||||
use crate::values::specified::{self, Angle, Integer, Length, LengthOrPercentage, Number};
|
||||
use crate::values::specified::{self, Angle, Integer, Length, LengthPercentage, Number};
|
||||
use cssparser::Parser;
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
|
||||
|
@ -18,7 +18,7 @@ pub use crate::values::generics::transform::TransformStyle;
|
|||
|
||||
/// A single operation in a specified CSS `transform`
|
||||
pub type TransformOperation =
|
||||
generic::TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage>;
|
||||
generic::TransformOperation<Angle, Number, Length, Integer, LengthPercentage>;
|
||||
|
||||
/// A specified CSS `transform`
|
||||
pub type Transform = generic::Transform<TransformOperation>;
|
||||
|
@ -105,20 +105,20 @@ impl Transform {
|
|||
}))
|
||||
},
|
||||
"translate" => {
|
||||
let sx = specified::LengthOrPercentage::parse(context, input)?;
|
||||
let sx = specified::LengthPercentage::parse(context, input)?;
|
||||
if input.try(|input| input.expect_comma()).is_ok() {
|
||||
let sy = specified::LengthOrPercentage::parse(context, input)?;
|
||||
let sy = specified::LengthPercentage::parse(context, input)?;
|
||||
Ok(generic::TransformOperation::Translate(sx, Some(sy)))
|
||||
} else {
|
||||
Ok(generic::TransformOperation::Translate(sx, None))
|
||||
}
|
||||
},
|
||||
"translatex" => {
|
||||
let tx = specified::LengthOrPercentage::parse(context, input)?;
|
||||
let tx = specified::LengthPercentage::parse(context, input)?;
|
||||
Ok(generic::TransformOperation::TranslateX(tx))
|
||||
},
|
||||
"translatey" => {
|
||||
let ty = specified::LengthOrPercentage::parse(context, input)?;
|
||||
let ty = specified::LengthPercentage::parse(context, input)?;
|
||||
Ok(generic::TransformOperation::TranslateY(ty))
|
||||
},
|
||||
"translatez" => {
|
||||
|
@ -126,9 +126,9 @@ impl Transform {
|
|||
Ok(generic::TransformOperation::TranslateZ(tz))
|
||||
},
|
||||
"translate3d" => {
|
||||
let tx = specified::LengthOrPercentage::parse(context, input)?;
|
||||
let tx = specified::LengthPercentage::parse(context, input)?;
|
||||
input.expect_comma()?;
|
||||
let ty = specified::LengthOrPercentage::parse(context, input)?;
|
||||
let ty = specified::LengthPercentage::parse(context, input)?;
|
||||
input.expect_comma()?;
|
||||
let tz = specified::Length::parse(context, input)?;
|
||||
Ok(generic::TransformOperation::Translate3D(tx, ty, tz))
|
||||
|
@ -236,7 +236,7 @@ pub enum OriginComponent<S> {
|
|||
/// `center`
|
||||
Center,
|
||||
/// `<lop>`
|
||||
Length(LengthOrPercentage),
|
||||
Length(LengthPercentage),
|
||||
/// `<side>`
|
||||
Side(S),
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ where
|
|||
if input.try(|i| i.expect_ident_matching("center")).is_ok() {
|
||||
return Ok(OriginComponent::Center);
|
||||
}
|
||||
if let Ok(lop) = input.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(lop) = input.try(|i| LengthPercentage::parse(context, i)) {
|
||||
return Ok(OriginComponent::Length(lop));
|
||||
}
|
||||
let keyword = S::parse(context, input)?;
|
||||
|
@ -318,17 +318,17 @@ impl<S> ToComputedValue for OriginComponent<S>
|
|||
where
|
||||
S: Side,
|
||||
{
|
||||
type ComputedValue = ComputedLengthOrPercentage;
|
||||
type ComputedValue = ComputedLengthPercentage;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
OriginComponent::Center => {
|
||||
ComputedLengthOrPercentage::new_percent(ComputedPercentage(0.5))
|
||||
ComputedLengthPercentage::new_percent(ComputedPercentage(0.5))
|
||||
},
|
||||
OriginComponent::Length(ref length) => length.to_computed_value(context),
|
||||
OriginComponent::Side(ref keyword) => {
|
||||
let p = ComputedPercentage(if keyword.is_start() { 0. } else { 1. });
|
||||
ComputedLengthOrPercentage::new_percent(p)
|
||||
ComputedLengthPercentage::new_percent(p)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ where
|
|||
impl<S> OriginComponent<S> {
|
||||
/// `0%`
|
||||
pub fn zero() -> Self {
|
||||
OriginComponent::Length(LengthOrPercentage::Percentage(ComputedPercentage::zero()))
|
||||
OriginComponent::Length(LengthPercentage::Percentage(ComputedPercentage::zero()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ impl Parse for Rotate {
|
|||
}
|
||||
|
||||
/// A specified CSS `translate`
|
||||
pub type Translate = generic::Translate<LengthOrPercentage, Length>;
|
||||
pub type Translate = generic::Translate<LengthPercentage, Length>;
|
||||
|
||||
impl Parse for Translate {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -404,8 +404,8 @@ impl Parse for Translate {
|
|||
return Ok(generic::Translate::None);
|
||||
}
|
||||
|
||||
let tx = specified::LengthOrPercentage::parse(context, input)?;
|
||||
if let Ok(ty) = input.try(|i| specified::LengthOrPercentage::parse(context, i)) {
|
||||
let tx = specified::LengthPercentage::parse(context, input)?;
|
||||
if let Ok(ty) = input.try(|i| specified::LengthPercentage::parse(context, i)) {
|
||||
if let Ok(tz) = input.try(|i| specified::Length::parse(context, i)) {
|
||||
// 'translate: <length-percentage> <length-percentage> <length>'
|
||||
return Ok(generic::Translate::Translate3D(tx, ty, tz));
|
||||
|
@ -418,7 +418,7 @@ impl Parse for Translate {
|
|||
// 'translate: <length-percentage> '
|
||||
Ok(generic::Translate::Translate(
|
||||
tx,
|
||||
specified::LengthOrPercentage::zero(),
|
||||
specified::LengthPercentage::zero(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue