Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an animated value for SvgLengthOrPercentageOrNumber. #18198

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Rename Type name of SvgLengthOrPercentageOrNumber

  • Loading branch information
mantaroh committed Sep 1, 2017
commit f009cb9616a8f868d99436ab205307b2055e121c
@@ -2292,8 +2292,12 @@ impl From<NonNegativeNumber> for NumberOrPercentage {
impl From<LengthOrPercentage> for NumberOrPercentage {
fn from(lop: LengthOrPercentage) -> NumberOrPercentage {
match lop {
LengthOrPercentage::Length(len) => NumberOrPercentage::Number(len.to_f32_px()),
LengthOrPercentage::Percentage(p) => NumberOrPercentage::Percentage(p),
LengthOrPercentage::Length(len) => {
NumberOrPercentage::Number(len.to_f32_px())
},
LengthOrPercentage::Percentage(p) => {
NumberOrPercentage::Percentage(p)
},
LengthOrPercentage::Calc(_) => {
panic!("We dont't expected calc interpolation for SvgLengthOrPercentageOrNumber");
},
@@ -2307,31 +2311,33 @@ impl From<Number> for NumberOrPercentage {
}
}

fn convert_to_number_or_percentage<LengthOrPercentageType, NumberType>(
from: SvgLengthOrPercentageOrNumber<LengthOrPercentageType, NumberType>)
fn convert_to_number_or_percentage<L, N>(from: SvgLengthOrPercentageOrNumber<L, N>)
-> NumberOrPercentage
where LengthOrPercentageType: Into<NumberOrPercentage>,
NumberType: Into<NumberOrPercentage>
where
L: Into<NumberOrPercentage>,
N: Into<NumberOrPercentage>
{
match from {
SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => {
SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) =>
{
lop.into()
}
SvgLengthOrPercentageOrNumber::Number(num) => {
SvgLengthOrPercentageOrNumber::Number(num) =>
{
num.into()
}
}
}

fn convert_from_number_or_percentage<LengthOrPercentageType, NumberType>(
from: NumberOrPercentage)
-> SvgLengthOrPercentageOrNumber<LengthOrPercentageType, NumberType>
where LengthOrPercentageType: From<LengthOrPercentage>,
NumberType: From<Number>
fn convert_from_number_or_percentage<L, N>(from: NumberOrPercentage)
-> SvgLengthOrPercentageOrNumber<L, N>
where
L: From<LengthOrPercentage>,
N: From<Number>
{
match from {
NumberOrPercentage::Number(num) =>
SvgLengthOrPercentageOrNumber::Number(num.into()),
SvgLengthOrPercentageOrNumber::Number(From::from(num)),
NumberOrPercentage::Percentage(p) =>
SvgLengthOrPercentageOrNumber::LengthOrPercentage(
(LengthOrPercentage::Percentage(p)).into())
@@ -106,11 +106,11 @@ impl<ColorType: Parse, UrlPaintServer: Parse> Parse for SVGPaint<ColorType, UrlP
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, ToAnimatedValue)]
#[derive(ToAnimatedZero, ToComputedValue, ToCss)]
pub enum SvgLengthOrPercentageOrNumber<LengthOrPercentage, Number> {
pub enum SvgLengthOrPercentageOrNumber<L, N> {
/// <length> | <percentage>
LengthOrPercentage(LengthOrPercentage),
LengthOrPercentage(L),
/// <number>
Number(Number),
Number(N),
}

impl<L, N> ComputeSquaredDistance for SvgLengthOrPercentageOrNumber<L, N>
@@ -149,15 +149,15 @@ impl<L, N> ComputeSquaredDistance for SvgLengthOrPercentageOrNumber<L, N>
}
}

impl<LengthOrPercentageType, NumberType> SvgLengthOrPercentageOrNumber<LengthOrPercentageType, NumberType>
where LengthOrPercentage: From<LengthOrPercentageType>,
LengthOrPercentageType: Copy
impl<L, N> SvgLengthOrPercentageOrNumber<L, N>
where
L: Into<LengthOrPercentage> + Copy
{
/// return true if this struct has calc value.
pub fn has_calc(&self) -> bool {
match self {
&SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => {
match LengthOrPercentage::from(lop) {
match lop.into() {
LengthOrPercentage::Calc(_) => true,
_ => false,
}
@@ -169,15 +169,14 @@ impl<LengthOrPercentageType, NumberType> SvgLengthOrPercentageOrNumber<LengthOrP

/// Parsing the SvgLengthOrPercentageOrNumber. At first, we need to parse number
/// since prevent converting to the length.
impl <LengthOrPercentageType: Parse, NumberType: Parse> Parse for
SvgLengthOrPercentageOrNumber<LengthOrPercentageType, NumberType> {
impl <L: Parse, N: Parse> Parse for SvgLengthOrPercentageOrNumber<L, N> {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
if let Ok(num) = input.try(|i| NumberType::parse(context, i)) {
if let Ok(num) = input.try(|i| N::parse(context, i)) {
return Ok(SvgLengthOrPercentageOrNumber::Number(num));
}

if let Ok(lop) = input.try(|i| LengthOrPercentageType::parse(context, i)) {
if let Ok(lop) = input.try(|i| L::parse(context, i)) {
return Ok(SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop));
}
Err(StyleParseError::UnspecifiedError.into())
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.