mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
style: 0% values are not skipped when parsing CSS transform
Adds trait ZeroNoPercent to check for values that are 0 (such as 0px) but not 0% Updated test css/css-transforms/animation/translate-interpolation.html and removed unnecessary formatting changes Differential Revision: https://phabricator.services.mozilla.com/D154930
This commit is contained in:
parent
aefbae5f96
commit
12a2c88605
4 changed files with 33 additions and 11 deletions
|
@ -244,6 +244,12 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A trait implementing a function to tell if the number is zero without a percent
|
||||||
|
pub trait ZeroNoPercent {
|
||||||
|
/// So, `0px` should return `true`, but `0%` or `1px` should return `false`
|
||||||
|
fn is_zero_no_percent(&self) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
/// A trait pretty much similar to num_traits::One, but without the need of
|
/// A trait pretty much similar to num_traits::One, but without the need of
|
||||||
/// implementing `Mul`.
|
/// implementing `Mul`.
|
||||||
pub trait One {
|
pub trait One {
|
||||||
|
|
|
@ -30,7 +30,7 @@ use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
use crate::values::generics::{calc, NonNegative};
|
use crate::values::generics::{calc, NonNegative};
|
||||||
use crate::values::specified::length::FontBaseSize;
|
use crate::values::specified::length::FontBaseSize;
|
||||||
use crate::values::{specified, CSSFloat};
|
use crate::values::{specified, CSSFloat};
|
||||||
use crate::Zero;
|
use crate::{Zero, ZeroNoPercent};
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -556,6 +556,13 @@ impl Zero for LengthPercentage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ZeroNoPercent for LengthPercentage {
|
||||||
|
#[inline]
|
||||||
|
fn is_zero_no_percent(&self) -> bool {
|
||||||
|
self.is_definitely_zero() && !self.has_percentage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Serialize for LengthPercentage {
|
impl Serialize for LengthPercentage {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::values::specified::angle::Angle as SpecifiedAngle;
|
||||||
use crate::values::specified::length::Length as SpecifiedLength;
|
use crate::values::specified::length::Length as SpecifiedLength;
|
||||||
use crate::values::specified::length::LengthPercentage as SpecifiedLengthPercentage;
|
use crate::values::specified::length::LengthPercentage as SpecifiedLengthPercentage;
|
||||||
use crate::values::{computed, CSSFloat};
|
use crate::values::{computed, CSSFloat};
|
||||||
use crate::Zero;
|
use crate::{Zero, ZeroNoPercent};
|
||||||
use euclid;
|
use euclid;
|
||||||
use euclid::default::{Rect, Transform3D};
|
use euclid::default::{Rect, Transform3D};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
@ -194,7 +194,7 @@ pub use self::GenericPerspectiveFunction as PerspectiveFunction;
|
||||||
pub enum GenericTransformOperation<Angle, Number, Length, Integer, LengthPercentage>
|
pub enum GenericTransformOperation<Angle, Number, Length, Integer, LengthPercentage>
|
||||||
where
|
where
|
||||||
Angle: Zero,
|
Angle: Zero,
|
||||||
LengthPercentage: Zero,
|
LengthPercentage: Zero + ZeroNoPercent,
|
||||||
Number: PartialEq,
|
Number: PartialEq,
|
||||||
{
|
{
|
||||||
/// Represents a 2D 2x3 matrix.
|
/// Represents a 2D 2x3 matrix.
|
||||||
|
@ -218,7 +218,7 @@ where
|
||||||
#[css(comma, function)]
|
#[css(comma, function)]
|
||||||
Translate(
|
Translate(
|
||||||
LengthPercentage,
|
LengthPercentage,
|
||||||
#[css(skip_if = "Zero::is_zero")] LengthPercentage,
|
#[css(skip_if = "ZeroNoPercent::is_zero_no_percent")] LengthPercentage,
|
||||||
),
|
),
|
||||||
/// translateX(x)
|
/// translateX(x)
|
||||||
#[css(function = "translateX")]
|
#[css(function = "translateX")]
|
||||||
|
@ -327,7 +327,7 @@ impl<Angle, Number, Length, Integer, LengthPercentage>
|
||||||
TransformOperation<Angle, Number, Length, Integer, LengthPercentage>
|
TransformOperation<Angle, Number, Length, Integer, LengthPercentage>
|
||||||
where
|
where
|
||||||
Angle: Zero,
|
Angle: Zero,
|
||||||
LengthPercentage: Zero,
|
LengthPercentage: Zero + ZeroNoPercent,
|
||||||
Number: PartialEq,
|
Number: PartialEq,
|
||||||
{
|
{
|
||||||
/// Check if it is any rotate function.
|
/// Check if it is any rotate function.
|
||||||
|
@ -446,7 +446,7 @@ where
|
||||||
Angle: Zero + ToRadians + Copy,
|
Angle: Zero + ToRadians + Copy,
|
||||||
Number: PartialEq + Copy + Into<f32> + Into<f64>,
|
Number: PartialEq + Copy + Into<f32> + Into<f64>,
|
||||||
Length: ToAbsoluteLength,
|
Length: ToAbsoluteLength,
|
||||||
LoP: Zero + ToAbsoluteLength,
|
LoP: Zero + ToAbsoluteLength + ZeroNoPercent,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_3d(&self) -> bool {
|
fn is_3d(&self) -> bool {
|
||||||
|
@ -810,12 +810,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn y_axis_and_z_axis_are_zero<LengthPercentage: Zero, Length: Zero>(
|
fn y_axis_and_z_axis_are_zero<LengthPercentage: Zero + ZeroNoPercent, Length: Zero>(
|
||||||
_: &LengthPercentage,
|
_: &LengthPercentage,
|
||||||
y: &LengthPercentage,
|
y: &LengthPercentage,
|
||||||
z: &Length,
|
z: &Length,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
y.is_zero() && z.is_zero()
|
y.is_zero_no_percent() && z.is_zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
|
@ -839,7 +839,7 @@ fn y_axis_and_z_axis_are_zero<LengthPercentage: Zero, Length: Zero>(
|
||||||
///
|
///
|
||||||
/// If a 2d translation is specified, the property must serialize with only one
|
/// If a 2d translation is specified, the property must serialize with only one
|
||||||
/// or two values (per usual, if the second value is 0px, the default, it must
|
/// or two values (per usual, if the second value is 0px, the default, it must
|
||||||
/// be omitted when serializing).
|
/// be omitted when serializing; however if 0% is the second value, it is included).
|
||||||
///
|
///
|
||||||
/// If a 3d translation is specified and the value can be expressed as 2d, we treat as 2d and
|
/// If a 3d translation is specified and the value can be expressed as 2d, we treat as 2d and
|
||||||
/// serialize accoringly. Otherwise, we serialize all three values.
|
/// serialize accoringly. Otherwise, we serialize all three values.
|
||||||
|
@ -849,7 +849,7 @@ fn y_axis_and_z_axis_are_zero<LengthPercentage: Zero, Length: Zero>(
|
||||||
/// cbindgen:private-default-tagged-enum-constructor=false
|
/// cbindgen:private-default-tagged-enum-constructor=false
|
||||||
pub enum GenericTranslate<LengthPercentage, Length>
|
pub enum GenericTranslate<LengthPercentage, Length>
|
||||||
where
|
where
|
||||||
LengthPercentage: Zero,
|
LengthPercentage: Zero + ZeroNoPercent,
|
||||||
Length: Zero,
|
Length: Zero,
|
||||||
{
|
{
|
||||||
/// 'none'
|
/// 'none'
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::values::generics::NonNegative;
|
||||||
use crate::values::specified::calc::{self, CalcNode};
|
use crate::values::specified::calc::{self, CalcNode};
|
||||||
use crate::values::specified::NonNegativeNumber;
|
use crate::values::specified::NonNegativeNumber;
|
||||||
use crate::values::CSSFloat;
|
use crate::values::CSSFloat;
|
||||||
use crate::Zero;
|
use crate::{Zero, ZeroNoPercent};
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::{Parser, Token};
|
use cssparser::{Parser, Token};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
@ -1486,6 +1486,15 @@ impl Zero for LengthPercentage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ZeroNoPercent for LengthPercentage {
|
||||||
|
fn is_zero_no_percent(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
LengthPercentage::Percentage(_) => false,
|
||||||
|
_ => self.is_zero(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A specified type for `<length-percentage> | auto`.
|
/// A specified type for `<length-percentage> | auto`.
|
||||||
pub type LengthPercentageOrAuto = generics::LengthPercentageOrAuto<LengthPercentage>;
|
pub type LengthPercentageOrAuto = generics::LengthPercentageOrAuto<LengthPercentage>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue