mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Implement Servo_ParseTransformIntoMatrix.
DOMMatrix needs to convert a specified transform list into a matrix, so we could rewrite to_transform_3d_matrix by generics for both specified and computed transform lists. Besides, we have to update the test case because we use Transform3D<f64> to compute the matrix, instead of Transform3D<f32>, so the result will be the same as that in Gecko. Using 0.3 may cause floating point issue because (0.3f32 as f64) is not equal to 0.3 (i.e. floating point precision issue), so using 0.25 instead.
This commit is contained in:
parent
ac6e04ebfb
commit
3a38e815ec
16 changed files with 450 additions and 238 deletions
|
@ -95,6 +95,13 @@ impl Angle {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsRef<ComputedAngle> for Angle {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &ComputedAngle {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for Angle {
|
||||
/// Parses an angle according to CSS-VALUES § 6.1.
|
||||
fn parse<'i, 't>(
|
||||
|
|
|
@ -63,6 +63,10 @@ pub enum CalcUnit {
|
|||
}
|
||||
|
||||
/// A struct to hold a simplified `<length>` or `<percentage>` expression.
|
||||
///
|
||||
/// In some cases, e.g. DOMMatrix, we support calc(), but reject all the relative lengths, and
|
||||
/// to_computed_pixel_length_without_context() handles this case. Therefore, if you want to add a
|
||||
/// new field, please make sure this function work properly.
|
||||
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq)]
|
||||
#[allow(missing_docs)]
|
||||
pub struct CalcLengthOrPercentage {
|
||||
|
|
|
@ -463,6 +463,15 @@ impl NoCalcLength {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get a px value without context.
|
||||
#[inline]
|
||||
pub fn to_computed_pixel_length_without_context(&self) -> Result<CSSFloat, ()> {
|
||||
match *self {
|
||||
NoCalcLength::Absolute(len) => Ok(len.to_px()),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an absolute length from a px value.
|
||||
#[inline]
|
||||
pub fn from_px(px_value: CSSFloat) -> NoCalcLength {
|
||||
|
|
|
@ -270,6 +270,20 @@ impl ToCss for Number {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Number> for f32 {
|
||||
#[inline]
|
||||
fn from(n: Number) -> Self {
|
||||
n.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Number> for f64 {
|
||||
#[inline]
|
||||
fn from(n: Number) -> Self {
|
||||
n.get() as f64
|
||||
}
|
||||
}
|
||||
|
||||
/// A Number which is >= 0.0.
|
||||
pub type NonNegativeNumber = NonNegative<Number>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue