mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Replace old transform code with new generic code
This commit is contained in:
parent
5ce2966bda
commit
6631594e28
10 changed files with 210 additions and 1268 deletions
|
@ -291,7 +291,7 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.as_block().fragment.establishes_stacking_context() ||
|
if !self.as_block().fragment.establishes_stacking_context() ||
|
||||||
self.as_block().fragment.style.get_box().transform.0.is_none() {
|
self.as_block().fragment.style.get_box().transform.0.is_empty() {
|
||||||
overflow.translate(&position.origin.to_vector());
|
overflow.translate(&position.origin.to_vector());
|
||||||
return overflow;
|
return overflow;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2500,7 +2500,7 @@ impl Fragment {
|
||||||
|
|
||||||
/// Returns true if this fragment has a filter, transform, or perspective property set.
|
/// Returns true if this fragment has a filter, transform, or perspective property set.
|
||||||
pub fn has_filter_transform_or_perspective(&self) -> bool {
|
pub fn has_filter_transform_or_perspective(&self) -> bool {
|
||||||
self.style().get_box().transform.0.is_some() ||
|
!self.style().get_box().transform.0.is_empty() ||
|
||||||
!self.style().get_effects().filter.0.is_empty() ||
|
!self.style().get_effects().filter.0.is_empty() ||
|
||||||
self.style().get_box().perspective != Either::Second(values::None_)
|
self.style().get_box().perspective != Either::Second(values::None_)
|
||||||
}
|
}
|
||||||
|
@ -2560,7 +2560,7 @@ impl Fragment {
|
||||||
_ => return self.style().get_position().z_index.integer_or(0),
|
_ => return self.style().get_position().z_index.integer_or(0),
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.style().get_box().transform.0.is_some() {
|
if !self.style().get_box().transform.0.is_empty() {
|
||||||
return self.style().get_position().z_index.integer_or(0);
|
return self.style().get_position().z_index.integer_or(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2901,9 +2901,9 @@ fn static_assert() {
|
||||||
single_patterns = ["m%s: %s" % (str(a / 4 + 1) + str(a % 4 + 1), b + str(a + 1)) for (a, b)
|
single_patterns = ["m%s: %s" % (str(a / 4 + 1) + str(a % 4 + 1), b + str(a + 1)) for (a, b)
|
||||||
in enumerate(items)]
|
in enumerate(items)]
|
||||||
if name == "Matrix":
|
if name == "Matrix":
|
||||||
pattern = "(ComputedMatrix { %s })" % ", ".join(single_patterns)
|
pattern = "(Matrix3D { %s })" % ", ".join(single_patterns)
|
||||||
else:
|
else:
|
||||||
pattern = "(ComputedMatrixWithPercents { %s })" % ", ".join(single_patterns)
|
pattern = "(Matrix3D { %s })" % ", ".join(single_patterns)
|
||||||
elif keyword == "interpolatematrix":
|
elif keyword == "interpolatematrix":
|
||||||
pattern = " { from_list: ref list1, to_list: ref list2, progress: percentage3 }"
|
pattern = " { from_list: ref list1, to_list: ref list2, progress: percentage3 }"
|
||||||
elif keyword == "accumulatematrix":
|
elif keyword == "accumulatematrix":
|
||||||
|
@ -2921,15 +2921,17 @@ fn static_assert() {
|
||||||
# need to cast it to f32.
|
# need to cast it to f32.
|
||||||
"integer_to_percentage" : "bindings::Gecko_CSSValue_SetPercentage(%s, %s as f32)",
|
"integer_to_percentage" : "bindings::Gecko_CSSValue_SetPercentage(%s, %s as f32)",
|
||||||
"lop" : "%s.set_lop(%s)",
|
"lop" : "%s.set_lop(%s)",
|
||||||
|
"lopon" : "set_lopon(%s, %s)",
|
||||||
|
"lon" : "set_lon(%s, %s)",
|
||||||
"angle" : "%s.set_angle(%s)",
|
"angle" : "%s.set_angle(%s)",
|
||||||
"number" : "bindings::Gecko_CSSValue_SetNumber(%s, %s)",
|
"number" : "bindings::Gecko_CSSValue_SetNumber(%s, %s)",
|
||||||
# Note: We use nsCSSValueSharedList here, instead of nsCSSValueList_heap
|
# Note: We use nsCSSValueSharedList here, instead of nsCSSValueList_heap
|
||||||
# because this function is not called on the main thread and
|
# because this function is not called on the main thread and
|
||||||
# nsCSSValueList_heap is not thread safe.
|
# nsCSSValueList_heap is not thread safe.
|
||||||
"list" : "%s.set_shared_list(%s.0.as_ref().unwrap().into_iter().map(&convert_to_ns_css_value));",
|
"list" : "%s.set_shared_list(%s.0.iter().map(&convert_to_ns_css_value));",
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
longhands::transform::computed_value::ComputedOperation::${name}${pattern} => {
|
::values::generics::transform::TransformOperation::${name}${pattern} => {
|
||||||
bindings::Gecko_CSSValue_SetFunction(gecko_value, ${len(items) + 1});
|
bindings::Gecko_CSSValue_SetFunction(gecko_value, ${len(items) + 1});
|
||||||
bindings::Gecko_CSSValue_SetKeyword(
|
bindings::Gecko_CSSValue_SetKeyword(
|
||||||
bindings::Gecko_CSSValue_GetArrayItem(gecko_value, 0),
|
bindings::Gecko_CSSValue_GetArrayItem(gecko_value, 0),
|
||||||
|
@ -2937,7 +2939,7 @@ fn static_assert() {
|
||||||
);
|
);
|
||||||
% for index, item in enumerate(items):
|
% for index, item in enumerate(items):
|
||||||
% if item == "list":
|
% if item == "list":
|
||||||
debug_assert!(${item}${index + 1}.0.is_some());
|
debug_assert!(!${item}${index + 1}.0.is_empty());
|
||||||
% endif
|
% endif
|
||||||
${css_value_setters[item] % (
|
${css_value_setters[item] % (
|
||||||
"bindings::Gecko_CSSValue_GetArrayItem(gecko_value, %d)" % (index + 1),
|
"bindings::Gecko_CSSValue_GetArrayItem(gecko_value, %d)" % (index + 1),
|
||||||
|
@ -2948,9 +2950,9 @@ fn static_assert() {
|
||||||
</%def>
|
</%def>
|
||||||
fn set_single_transform_function(servo_value: &longhands::transform::computed_value::ComputedOperation,
|
fn set_single_transform_function(servo_value: &longhands::transform::computed_value::ComputedOperation,
|
||||||
gecko_value: &mut structs::nsCSSValue /* output */) {
|
gecko_value: &mut structs::nsCSSValue /* output */) {
|
||||||
use properties::longhands::transform::computed_value::ComputedMatrix;
|
|
||||||
use properties::longhands::transform::computed_value::ComputedMatrixWithPercents;
|
|
||||||
use properties::longhands::transform::computed_value::ComputedOperation;
|
use properties::longhands::transform::computed_value::ComputedOperation;
|
||||||
|
use values::computed::{Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrNumber};
|
||||||
|
use values::generics::transform::Matrix3D;
|
||||||
|
|
||||||
let convert_to_ns_css_value = |item: &ComputedOperation| -> structs::nsCSSValue {
|
let convert_to_ns_css_value = |item: &ComputedOperation| -> structs::nsCSSValue {
|
||||||
let mut value = structs::nsCSSValue::null();
|
let mut value = structs::nsCSSValue::null();
|
||||||
|
@ -2958,20 +2960,36 @@ fn static_assert() {
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
|
|
||||||
|
unsafe fn set_lopon(css: &mut structs::nsCSSValue, lopon: LengthOrPercentageOrNumber) {
|
||||||
|
let lop = match lopon {
|
||||||
|
Either::First(number) => LengthOrPercentage::Length(Length::new(number)),
|
||||||
|
Either::Second(lop) => lop,
|
||||||
|
};
|
||||||
|
css.set_lop(lop);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn set_lon(css: &mut structs::nsCSSValue, lopon: LengthOrNumber) {
|
||||||
|
let length = match lopon {
|
||||||
|
Either::Second(number) => Length::new(number),
|
||||||
|
Either::First(l) => l,
|
||||||
|
};
|
||||||
|
bindings::Gecko_CSSValue_SetPixelLength(css, length.px())
|
||||||
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
match *servo_value {
|
match *servo_value {
|
||||||
${transform_function_arm("Matrix", "matrix3d", ["number"] * 16)}
|
${transform_function_arm("Matrix3D", "matrix3d", ["number"] * 16)}
|
||||||
${transform_function_arm("MatrixWithPercents", "matrix3d", ["number"] * 12 + ["lop"] * 2
|
${transform_function_arm("PrefixedMatrix3D", "matrix3d", ["number"] * 12 + ["lopon"] * 2
|
||||||
+ ["length"] + ["number"])}
|
+ ["lon"] + ["number"])}
|
||||||
${transform_function_arm("Skew", "skew", ["angle"] * 2)}
|
${transform_function_arm("Translate3D", "translate3d", ["lop", "lop", "length"])}
|
||||||
${transform_function_arm("Translate", "translate3d", ["lop", "lop", "length"])}
|
${transform_function_arm("Scale3D", "scale3d", ["number"] * 3)}
|
||||||
${transform_function_arm("Scale", "scale3d", ["number"] * 3)}
|
${transform_function_arm("Rotate3D", "rotate3d", ["number"] * 3 + ["angle"])}
|
||||||
${transform_function_arm("Rotate", "rotate3d", ["number"] * 3 + ["angle"])}
|
|
||||||
${transform_function_arm("Perspective", "perspective", ["length"])}
|
${transform_function_arm("Perspective", "perspective", ["length"])}
|
||||||
${transform_function_arm("InterpolateMatrix", "interpolatematrix",
|
${transform_function_arm("InterpolateMatrix", "interpolatematrix",
|
||||||
["list"] * 2 + ["percentage"])}
|
["list"] * 2 + ["percentage"])}
|
||||||
${transform_function_arm("AccumulateMatrix", "accumulatematrix",
|
${transform_function_arm("AccumulateMatrix", "accumulatematrix",
|
||||||
["list"] * 2 + ["integer_to_percentage"])}
|
["list"] * 2 + ["integer_to_percentage"])}
|
||||||
|
_ => unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2994,15 +3012,13 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_transform(&mut self, other: longhands::transform::computed_value::T) {
|
pub fn set_transform(&mut self, other: longhands::transform::computed_value::T) {
|
||||||
let vec = if let Some(v) = other.0 {
|
if other.0.is_empty() {
|
||||||
v
|
|
||||||
} else {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
self.gecko.mSpecifiedTransform.clear();
|
self.gecko.mSpecifiedTransform.clear();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
Self::convert_transform(&vec, &mut self.gecko.mSpecifiedTransform);
|
Self::convert_transform(&other.0, &mut self.gecko.mSpecifiedTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_transform_from(&mut self, other: &Self) {
|
pub fn copy_transform_from(&mut self, other: &Self) {
|
||||||
|
@ -3023,7 +3039,7 @@ fn static_assert() {
|
||||||
"number" : "bindings::Gecko_CSSValue_GetNumber(%s)",
|
"number" : "bindings::Gecko_CSSValue_GetNumber(%s)",
|
||||||
"percentage" : "Percentage(bindings::Gecko_CSSValue_GetPercentage(%s))",
|
"percentage" : "Percentage(bindings::Gecko_CSSValue_GetPercentage(%s))",
|
||||||
"percentage_to_integer" : "bindings::Gecko_CSSValue_GetPercentage(%s) as i32",
|
"percentage_to_integer" : "bindings::Gecko_CSSValue_GetPercentage(%s) as i32",
|
||||||
"list" : "TransformList(Some(convert_shared_list_to_operations(%s)))",
|
"list" : "Transform(convert_shared_list_to_operations(%s))",
|
||||||
}
|
}
|
||||||
pre_symbols = "("
|
pre_symbols = "("
|
||||||
post_symbols = ")"
|
post_symbols = ")"
|
||||||
|
@ -3033,7 +3049,7 @@ fn static_assert() {
|
||||||
pre_symbols = " {"
|
pre_symbols = " {"
|
||||||
post_symbols = "}"
|
post_symbols = "}"
|
||||||
elif keyword == "matrix3d":
|
elif keyword == "matrix3d":
|
||||||
pre_symbols = "(ComputedMatrix {"
|
pre_symbols = "(Matrix3D {"
|
||||||
post_symbols = "})"
|
post_symbols = "})"
|
||||||
field_names = None
|
field_names = None
|
||||||
if keyword == "interpolatematrix":
|
if keyword == "interpolatematrix":
|
||||||
|
@ -3042,7 +3058,7 @@ fn static_assert() {
|
||||||
field_names = ["from_list", "to_list", "count"]
|
field_names = ["from_list", "to_list", "count"]
|
||||||
%>
|
%>
|
||||||
structs::nsCSSKeyword::eCSSKeyword_${keyword} => {
|
structs::nsCSSKeyword::eCSSKeyword_${keyword} => {
|
||||||
ComputedOperation::${name}${pre_symbols}
|
::values::generics::transform::TransformOperation::${name}${pre_symbols}
|
||||||
% for index, item in enumerate(items):
|
% for index, item in enumerate(items):
|
||||||
% if keyword == "matrix3d":
|
% if keyword == "matrix3d":
|
||||||
m${index / 4 + 1}${index % 4 + 1}:
|
m${index / 4 + 1}${index % 4 + 1}:
|
||||||
|
@ -3058,10 +3074,10 @@ fn static_assert() {
|
||||||
</%def>
|
</%def>
|
||||||
fn clone_single_transform_function(gecko_value: &structs::nsCSSValue)
|
fn clone_single_transform_function(gecko_value: &structs::nsCSSValue)
|
||||||
-> longhands::transform::computed_value::ComputedOperation {
|
-> longhands::transform::computed_value::ComputedOperation {
|
||||||
use properties::longhands::transform::computed_value::ComputedMatrix;
|
|
||||||
use properties::longhands::transform::computed_value::ComputedOperation;
|
use properties::longhands::transform::computed_value::ComputedOperation;
|
||||||
use properties::longhands::transform::computed_value::T as TransformList;
|
|
||||||
use values::computed::{Length, Percentage};
|
use values::computed::{Length, Percentage};
|
||||||
|
use values::generics::transform::Matrix3D;
|
||||||
|
use values::generics::transform::Transform;
|
||||||
|
|
||||||
let convert_shared_list_to_operations = |value: &structs::nsCSSValue|
|
let convert_shared_list_to_operations = |value: &structs::nsCSSValue|
|
||||||
-> Vec<ComputedOperation> {
|
-> Vec<ComputedOperation> {
|
||||||
|
@ -3081,59 +3097,33 @@ fn static_assert() {
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
use gecko_bindings::structs::nsCSSKeyword;
|
|
||||||
use values::computed::Angle;
|
|
||||||
|
|
||||||
let get_array_angle = || -> Angle {
|
|
||||||
bindings::Gecko_CSSValue_GetArrayItemConst(gecko_value, 1).get_angle()
|
|
||||||
};
|
|
||||||
|
|
||||||
match transform_function {
|
match transform_function {
|
||||||
${computed_operation_arm("Matrix", "matrix3d", ["number"] * 16)}
|
${computed_operation_arm("Matrix3D", "matrix3d", ["number"] * 16)}
|
||||||
${computed_operation_arm("Skew", "skew", ["angle"] * 2)}
|
${computed_operation_arm("Translate3D", "translate3d", ["lop", "lop", "length"])}
|
||||||
${computed_operation_arm("Translate", "translate3d", ["lop", "lop", "length"])}
|
${computed_operation_arm("Scale3D", "scale3d", ["number"] * 3)}
|
||||||
${computed_operation_arm("Scale", "scale3d", ["number"] * 3)}
|
${computed_operation_arm("Rotate3D", "rotate3d", ["number"] * 3 + ["angle"])}
|
||||||
${computed_operation_arm("Rotate", "rotate3d", ["number"] * 3 + ["angle"])}
|
|
||||||
${computed_operation_arm("Perspective", "perspective", ["length"])}
|
${computed_operation_arm("Perspective", "perspective", ["length"])}
|
||||||
${computed_operation_arm("InterpolateMatrix", "interpolatematrix",
|
${computed_operation_arm("InterpolateMatrix", "interpolatematrix",
|
||||||
["list"] * 2 + ["percentage"])}
|
["list"] * 2 + ["percentage"])}
|
||||||
${computed_operation_arm("AccumulateMatrix", "accumulatematrix",
|
${computed_operation_arm("AccumulateMatrix", "accumulatematrix",
|
||||||
["list"] * 2 + ["percentage_to_integer"])}
|
["list"] * 2 + ["percentage_to_integer"])}
|
||||||
// FIXME: Bug 1391145 will introduce new types for these keywords. For now, we
|
|
||||||
// temporarily don't use |computed_operation_arm| because these are special cases
|
|
||||||
// for compositor animations when we use Gecko style backend on the main thread,
|
|
||||||
// and I don't want to add too many special cases in |computed_operation_arm|.
|
|
||||||
//
|
|
||||||
// Note: Gecko only converts translate and scale into the corresponding primitive
|
|
||||||
// functions, so we still need to handle the following functions.
|
|
||||||
nsCSSKeyword::eCSSKeyword_skewx => {
|
|
||||||
ComputedOperation::Skew(get_array_angle(), Angle::zero())
|
|
||||||
},
|
|
||||||
nsCSSKeyword::eCSSKeyword_skewy => {
|
|
||||||
ComputedOperation::Skew(Angle::zero(), get_array_angle())
|
|
||||||
},
|
|
||||||
nsCSSKeyword::eCSSKeyword_rotatex => {
|
|
||||||
ComputedOperation::Rotate(1.0, 0.0, 0.0, get_array_angle())
|
|
||||||
},
|
|
||||||
nsCSSKeyword::eCSSKeyword_rotatey => {
|
|
||||||
ComputedOperation::Rotate(0.0, 1.0, 0.0, get_array_angle())
|
|
||||||
},
|
|
||||||
nsCSSKeyword::eCSSKeyword_rotatez | nsCSSKeyword::eCSSKeyword_rotate => {
|
|
||||||
ComputedOperation::Rotate(0.0, 0.0, 1.0, get_array_angle())
|
|
||||||
},
|
|
||||||
_ => panic!("{:?} is not an acceptable transform function", transform_function),
|
_ => panic!("{:?} is not an acceptable transform function", transform_function),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn clone_transform(&self) -> longhands::transform::computed_value::T {
|
pub fn clone_transform(&self) -> longhands::transform::computed_value::T {
|
||||||
|
use values::generics::transform::Transform;
|
||||||
|
|
||||||
if self.gecko.mSpecifiedTransform.mRawPtr.is_null() {
|
if self.gecko.mSpecifiedTransform.mRawPtr.is_null() {
|
||||||
return longhands::transform::computed_value::T(None);
|
return Transform(vec!());
|
||||||
}
|
}
|
||||||
let list = unsafe { (*self.gecko.mSpecifiedTransform.to_safe().get()).mHead.as_ref() };
|
let list = unsafe { (*self.gecko.mSpecifiedTransform.to_safe().get()).mHead.as_ref() };
|
||||||
Self::clone_transform_from_list(list)
|
Self::clone_transform_from_list(list)
|
||||||
}
|
}
|
||||||
pub fn clone_transform_from_list(list: Option< &structs::root::nsCSSValueList>)
|
pub fn clone_transform_from_list(list: Option< &structs::root::nsCSSValueList>)
|
||||||
-> longhands::transform::computed_value::T {
|
-> longhands::transform::computed_value::T {
|
||||||
|
use values::generics::transform::Transform;
|
||||||
|
|
||||||
let result = match list {
|
let result = match list {
|
||||||
Some(list) => {
|
Some(list) => {
|
||||||
let vec: Vec<_> = list
|
let vec: Vec<_> = list
|
||||||
|
@ -3151,7 +3141,7 @@ fn static_assert() {
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
longhands::transform::computed_value::T(result)
|
Transform(result.unwrap_or(vec!()))
|
||||||
}
|
}
|
||||||
|
|
||||||
${impl_transition_time_value('delay', 'Delay')}
|
${impl_transition_time_value('delay', 'Delay')}
|
||||||
|
|
|
@ -18,9 +18,8 @@ use properties::longhands::font_weight::computed_value::T as FontWeight;
|
||||||
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use properties::longhands::font_variation_settings::computed_value::T as FontVariationSettings;
|
use properties::longhands::font_variation_settings::computed_value::T as FontVariationSettings;
|
||||||
use properties::longhands::transform::computed_value::ComputedMatrix;
|
use properties::longhands::transform::computed_value::ComputedOperation as ComputedTransformOperation;
|
||||||
use properties::longhands::transform::computed_value::ComputedOperation as TransformOperation;
|
use properties::longhands::transform::computed_value::T as ComputedTransform;
|
||||||
use properties::longhands::transform::computed_value::T as TransformList;
|
|
||||||
use properties::longhands::visibility::computed_value::T as Visibility;
|
use properties::longhands::visibility::computed_value::T as Visibility;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use properties::PropertyId;
|
use properties::PropertyId;
|
||||||
|
@ -28,7 +27,6 @@ use properties::{LonghandId, ShorthandId};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[cfg(feature = "gecko")] use hash::FnvHashMap;
|
#[cfg(feature = "gecko")] use hash::FnvHashMap;
|
||||||
|
@ -46,7 +44,8 @@ use values::computed::{LengthOrPercentageOrNone, MaxLength};
|
||||||
use values::computed::{NonNegativeNumber, Number, NumberOrPercentage, Percentage};
|
use values::computed::{NonNegativeNumber, Number, NumberOrPercentage, Percentage};
|
||||||
use values::computed::length::NonNegativeLengthOrPercentage;
|
use values::computed::length::NonNegativeLengthOrPercentage;
|
||||||
use values::computed::ToComputedValue;
|
use values::computed::ToComputedValue;
|
||||||
use values::computed::transform::DirectionVector;
|
use values::computed::transform::{DirectionVector, Matrix3D};
|
||||||
|
use values::generics::transform::{Transform, TransformOperation};
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
#[cfg(feature = "gecko")] use values::generics::FontSettings as GenericFontSettings;
|
#[cfg(feature = "gecko")] use values::generics::FontSettings as GenericFontSettings;
|
||||||
#[cfg(feature = "gecko")] use values::generics::FontSettingTag as GenericFontSettingTag;
|
#[cfg(feature = "gecko")] use values::generics::FontSettingTag as GenericFontSettingTag;
|
||||||
|
@ -1014,60 +1013,6 @@ impl ToAnimatedZero for ClipRect {
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build an equivalent 'identity transform function list' based
|
|
||||||
/// on an existing transform list.
|
|
||||||
/// <http://dev.w3.org/csswg/css-transforms/#none-transform-animation>
|
|
||||||
impl ToAnimatedZero for TransformOperation {
|
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
|
||||||
match *self {
|
|
||||||
TransformOperation::Matrix(..) => {
|
|
||||||
Ok(TransformOperation::Matrix(ComputedMatrix::identity()))
|
|
||||||
},
|
|
||||||
TransformOperation::MatrixWithPercents(..) => {
|
|
||||||
// FIXME(nox): Should be MatrixWithPercents value.
|
|
||||||
Ok(TransformOperation::Matrix(ComputedMatrix::identity()))
|
|
||||||
},
|
|
||||||
TransformOperation::Skew(sx, sy) => {
|
|
||||||
Ok(TransformOperation::Skew(
|
|
||||||
sx.to_animated_zero()?,
|
|
||||||
sy.to_animated_zero()?,
|
|
||||||
))
|
|
||||||
},
|
|
||||||
TransformOperation::Translate(ref tx, ref ty, ref tz) => {
|
|
||||||
Ok(TransformOperation::Translate(
|
|
||||||
tx.to_animated_zero()?,
|
|
||||||
ty.to_animated_zero()?,
|
|
||||||
tz.to_animated_zero()?,
|
|
||||||
))
|
|
||||||
},
|
|
||||||
TransformOperation::Scale(..) => {
|
|
||||||
Ok(TransformOperation::Scale(1.0, 1.0, 1.0))
|
|
||||||
},
|
|
||||||
TransformOperation::Rotate(x, y, z, a) => {
|
|
||||||
let (x, y, z, _) = TransformList::get_normalized_vector_and_angle(x, y, z, a);
|
|
||||||
Ok(TransformOperation::Rotate(x, y, z, Angle::zero()))
|
|
||||||
},
|
|
||||||
TransformOperation::Perspective(..) |
|
|
||||||
TransformOperation::AccumulateMatrix { .. } |
|
|
||||||
TransformOperation::InterpolateMatrix { .. } => {
|
|
||||||
// Perspective: We convert a perspective function into an equivalent
|
|
||||||
// ComputedMatrix, and then decompose/interpolate/recompose these matrices.
|
|
||||||
// AccumulateMatrix/InterpolateMatrix: We do interpolation on
|
|
||||||
// AccumulateMatrix/InterpolateMatrix by reading it as a ComputedMatrix
|
|
||||||
// (with layout information), and then do matrix interpolation.
|
|
||||||
//
|
|
||||||
// Therefore, we use an identity matrix to represent the identity transform list.
|
|
||||||
// http://dev.w3.org/csswg/css-transforms/#identity-transform-function
|
|
||||||
//
|
|
||||||
// FIXME(nox): This does not actually work, given the impl of
|
|
||||||
// Animate for TransformOperation bails out if the two given
|
|
||||||
// values are dissimilar.
|
|
||||||
Ok(TransformOperation::Matrix(ComputedMatrix::identity()))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn animate_multiplicative_factor(
|
fn animate_multiplicative_factor(
|
||||||
this: CSSFloat,
|
this: CSSFloat,
|
||||||
other: CSSFloat,
|
other: CSSFloat,
|
||||||
|
@ -1077,14 +1022,14 @@ fn animate_multiplicative_factor(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <http://dev.w3.org/csswg/css-transforms/#interpolation-of-transforms>
|
/// <http://dev.w3.org/csswg/css-transforms/#interpolation-of-transforms>
|
||||||
impl Animate for TransformOperation {
|
impl Animate for ComputedTransformOperation {
|
||||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(
|
(
|
||||||
&TransformOperation::Matrix(ref this),
|
&TransformOperation::Matrix3D(ref this),
|
||||||
&TransformOperation::Matrix(ref other),
|
&TransformOperation::Matrix3D(ref other),
|
||||||
) => {
|
) => {
|
||||||
Ok(TransformOperation::Matrix(
|
Ok(TransformOperation::Matrix3D(
|
||||||
this.animate(other, procedure)?,
|
this.animate(other, procedure)?,
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
|
@ -1098,40 +1043,40 @@ impl Animate for TransformOperation {
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
&TransformOperation::Translate(ref fx, ref fy, ref fz),
|
&TransformOperation::Translate3D(ref fx, ref fy, ref fz),
|
||||||
&TransformOperation::Translate(ref tx, ref ty, ref tz),
|
&TransformOperation::Translate3D(ref tx, ref ty, ref tz),
|
||||||
) => {
|
) => {
|
||||||
Ok(TransformOperation::Translate(
|
Ok(TransformOperation::Translate3D(
|
||||||
fx.animate(tx, procedure)?,
|
fx.animate(tx, procedure)?,
|
||||||
fy.animate(ty, procedure)?,
|
fy.animate(ty, procedure)?,
|
||||||
fz.animate(tz, procedure)?,
|
fz.animate(tz, procedure)?,
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
&TransformOperation::Scale(ref fx, ref fy, ref fz),
|
&TransformOperation::Scale3D(ref fx, ref fy, ref fz),
|
||||||
&TransformOperation::Scale(ref tx, ref ty, ref tz),
|
&TransformOperation::Scale3D(ref tx, ref ty, ref tz),
|
||||||
) => {
|
) => {
|
||||||
Ok(TransformOperation::Scale(
|
Ok(TransformOperation::Scale3D(
|
||||||
animate_multiplicative_factor(*fx, *tx, procedure)?,
|
animate_multiplicative_factor(*fx, *tx, procedure)?,
|
||||||
animate_multiplicative_factor(*fy, *ty, procedure)?,
|
animate_multiplicative_factor(*fy, *ty, procedure)?,
|
||||||
animate_multiplicative_factor(*fz, *tz, procedure)?,
|
animate_multiplicative_factor(*fz, *tz, procedure)?,
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
&TransformOperation::Rotate(fx, fy, fz, fa),
|
&TransformOperation::Rotate3D(fx, fy, fz, fa),
|
||||||
&TransformOperation::Rotate(tx, ty, tz, ta),
|
&TransformOperation::Rotate3D(tx, ty, tz, ta),
|
||||||
) => {
|
) => {
|
||||||
let (fx, fy, fz, fa) =
|
let (fx, fy, fz, fa) =
|
||||||
TransformList::get_normalized_vector_and_angle(fx, fy, fz, fa);
|
ComputedTransform::get_normalized_vector_and_angle(fx, fy, fz, fa);
|
||||||
let (tx, ty, tz, ta) =
|
let (tx, ty, tz, ta) =
|
||||||
TransformList::get_normalized_vector_and_angle(tx, ty, tz, ta);
|
ComputedTransform::get_normalized_vector_and_angle(tx, ty, tz, ta);
|
||||||
if (fx, fy, fz) == (tx, ty, tz) {
|
if (fx, fy, fz) == (tx, ty, tz) {
|
||||||
let ia = fa.animate(&ta, procedure)?;
|
let ia = fa.animate(&ta, procedure)?;
|
||||||
Ok(TransformOperation::Rotate(fx, fy, fz, ia))
|
Ok(TransformOperation::Rotate3D(fx, fy, fz, ia))
|
||||||
} else {
|
} else {
|
||||||
let matrix_f = rotate_to_matrix(fx, fy, fz, fa);
|
let matrix_f = rotate_to_matrix(fx, fy, fz, fa);
|
||||||
let matrix_t = rotate_to_matrix(tx, ty, tz, ta);
|
let matrix_t = rotate_to_matrix(tx, ty, tz, ta);
|
||||||
Ok(TransformOperation::Matrix(
|
Ok(TransformOperation::Matrix3D(
|
||||||
matrix_f.animate(&matrix_t, procedure)?,
|
matrix_f.animate(&matrix_t, procedure)?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -1140,15 +1085,15 @@ impl Animate for TransformOperation {
|
||||||
&TransformOperation::Perspective(ref fd),
|
&TransformOperation::Perspective(ref fd),
|
||||||
&TransformOperation::Perspective(ref td),
|
&TransformOperation::Perspective(ref td),
|
||||||
) => {
|
) => {
|
||||||
let mut fd_matrix = ComputedMatrix::identity();
|
let mut fd_matrix = Matrix3D::identity();
|
||||||
let mut td_matrix = ComputedMatrix::identity();
|
let mut td_matrix = Matrix3D::identity();
|
||||||
if fd.px() > 0. {
|
if fd.px() > 0. {
|
||||||
fd_matrix.m34 = -1. / fd.px();
|
fd_matrix.m34 = -1. / fd.px();
|
||||||
}
|
}
|
||||||
if td.px() > 0. {
|
if td.px() > 0. {
|
||||||
td_matrix.m34 = -1. / td.px();
|
td_matrix.m34 = -1. / td.px();
|
||||||
}
|
}
|
||||||
Ok(TransformOperation::Matrix(
|
Ok(TransformOperation::Matrix3D(
|
||||||
fd_matrix.animate(&td_matrix, procedure)?,
|
fd_matrix.animate(&td_matrix, procedure)?,
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
|
@ -1157,12 +1102,12 @@ impl Animate for TransformOperation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_matched_operation(first: &TransformOperation, second: &TransformOperation) -> bool {
|
fn is_matched_operation(first: &ComputedTransformOperation, second: &ComputedTransformOperation) -> bool {
|
||||||
match (first, second) {
|
match (first, second) {
|
||||||
(&TransformOperation::Matrix(..),
|
(&TransformOperation::Matrix(..),
|
||||||
&TransformOperation::Matrix(..)) |
|
&TransformOperation::Matrix(..)) |
|
||||||
(&TransformOperation::MatrixWithPercents(..),
|
(&TransformOperation::PrefixedMatrix(..),
|
||||||
&TransformOperation::MatrixWithPercents(..)) |
|
&TransformOperation::PrefixedMatrix(..)) |
|
||||||
(&TransformOperation::Skew(..),
|
(&TransformOperation::Skew(..),
|
||||||
&TransformOperation::Skew(..)) |
|
&TransformOperation::Skew(..)) |
|
||||||
(&TransformOperation::Translate(..),
|
(&TransformOperation::Translate(..),
|
||||||
|
@ -1179,12 +1124,12 @@ fn is_matched_operation(first: &TransformOperation, second: &TransformOperation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://www.w3.org/TR/css-transforms-1/#Rotate3dDefined>
|
/// <https://www.w3.org/TR/css-transforms-1/#Rotate3dDefined>
|
||||||
fn rotate_to_matrix(x: f32, y: f32, z: f32, a: Angle) -> ComputedMatrix {
|
fn rotate_to_matrix(x: f32, y: f32, z: f32, a: Angle) -> Matrix3D {
|
||||||
let half_rad = a.radians() / 2.0;
|
let half_rad = a.radians() / 2.0;
|
||||||
let sc = (half_rad).sin() * (half_rad).cos();
|
let sc = (half_rad).sin() * (half_rad).cos();
|
||||||
let sq = (half_rad).sin().powi(2);
|
let sq = (half_rad).sin().powi(2);
|
||||||
|
|
||||||
ComputedMatrix {
|
Matrix3D {
|
||||||
m11: 1.0 - 2.0 * (y * y + z * z) * sq,
|
m11: 1.0 - 2.0 * (y * y + z * z) * sq,
|
||||||
m12: 2.0 * (x * y * sq + z * sc),
|
m12: 2.0 * (x * y * sq + z * sc),
|
||||||
m13: 2.0 * (x * z * sq - y * sc),
|
m13: 2.0 * (x * z * sq - y * sc),
|
||||||
|
@ -1214,7 +1159,7 @@ fn rotate_to_matrix(x: f32, y: f32, z: f32, a: Angle) -> ComputedMatrix {
|
||||||
// FIXME: We use custom derive for ComputeSquaredDistance. However, If possible, we should convert
|
// FIXME: We use custom derive for ComputeSquaredDistance. However, If possible, we should convert
|
||||||
// the InnerMatrix2D into types with physical meaning. This custom derive computes the squared
|
// the InnerMatrix2D into types with physical meaning. This custom derive computes the squared
|
||||||
// distance from each matrix item, and this makes the result different from that in Gecko if we
|
// distance from each matrix item, and this makes the result different from that in Gecko if we
|
||||||
// have skew factor in the ComputedMatrix.
|
// have skew factor in the Matrix3D.
|
||||||
pub struct InnerMatrix2D {
|
pub struct InnerMatrix2D {
|
||||||
pub m11: CSSFloat, pub m12: CSSFloat,
|
pub m11: CSSFloat, pub m12: CSSFloat,
|
||||||
pub m21: CSSFloat, pub m22: CSSFloat,
|
pub m21: CSSFloat, pub m22: CSSFloat,
|
||||||
|
@ -1324,7 +1269,7 @@ impl ComputeSquaredDistance for MatrixDecomposed2D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Animate for ComputedMatrix {
|
impl Animate for Matrix3D {
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||||
if self.is_3d() || other.is_3d() {
|
if self.is_3d() || other.is_3d() {
|
||||||
|
@ -1332,7 +1277,7 @@ impl Animate for ComputedMatrix {
|
||||||
let decomposed_to = decompose_3d_matrix(*other);
|
let decomposed_to = decompose_3d_matrix(*other);
|
||||||
match (decomposed_from, decomposed_to) {
|
match (decomposed_from, decomposed_to) {
|
||||||
(Ok(this), Ok(other)) => {
|
(Ok(this), Ok(other)) => {
|
||||||
Ok(ComputedMatrix::from(this.animate(&other, procedure)?))
|
Ok(Matrix3D::from(this.animate(&other, procedure)?))
|
||||||
},
|
},
|
||||||
// Matrices can be undecomposable due to couple reasons, e.g.,
|
// Matrices can be undecomposable due to couple reasons, e.g.,
|
||||||
// non-invertible matrices. In this case, we should report Err
|
// non-invertible matrices. In this case, we should report Err
|
||||||
|
@ -1342,7 +1287,7 @@ impl Animate for ComputedMatrix {
|
||||||
} else {
|
} else {
|
||||||
let this = MatrixDecomposed2D::from(*self);
|
let this = MatrixDecomposed2D::from(*self);
|
||||||
let other = MatrixDecomposed2D::from(*other);
|
let other = MatrixDecomposed2D::from(*other);
|
||||||
Ok(ComputedMatrix::from(this.animate(&other, procedure)?))
|
Ok(Matrix3D::from(this.animate(&other, procedure)?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1355,7 +1300,7 @@ impl Animate for ComputedMatrix {
|
||||||
};
|
};
|
||||||
match (from, to) {
|
match (from, to) {
|
||||||
(Ok(from), Ok(to)) => {
|
(Ok(from), Ok(to)) => {
|
||||||
Ok(ComputedMatrix::from(from.animate(&to, procedure)?))
|
Ok(Matrix3D::from(from.animate(&to, procedure)?))
|
||||||
},
|
},
|
||||||
// Matrices can be undecomposable due to couple reasons, e.g.,
|
// Matrices can be undecomposable due to couple reasons, e.g.,
|
||||||
// non-invertible matrices. In this case, we should report Err here,
|
// non-invertible matrices. In this case, we should report Err here,
|
||||||
|
@ -1365,7 +1310,7 @@ impl Animate for ComputedMatrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComputeSquaredDistance for ComputedMatrix {
|
impl ComputeSquaredDistance for Matrix3D {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||||
|
@ -1392,10 +1337,10 @@ impl ComputeSquaredDistance for ComputedMatrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ComputedMatrix> for MatrixDecomposed2D {
|
impl From<Matrix3D> for MatrixDecomposed2D {
|
||||||
/// Decompose a 2D matrix.
|
/// Decompose a 2D matrix.
|
||||||
/// <https://drafts.csswg.org/css-transforms/#decomposing-a-2d-matrix>
|
/// <https://drafts.csswg.org/css-transforms/#decomposing-a-2d-matrix>
|
||||||
fn from(matrix: ComputedMatrix) -> MatrixDecomposed2D {
|
fn from(matrix: Matrix3D) -> MatrixDecomposed2D {
|
||||||
let mut row0x = matrix.m11;
|
let mut row0x = matrix.m11;
|
||||||
let mut row0y = matrix.m12;
|
let mut row0y = matrix.m12;
|
||||||
let mut row1x = matrix.m21;
|
let mut row1x = matrix.m21;
|
||||||
|
@ -1456,11 +1401,11 @@ impl From<ComputedMatrix> for MatrixDecomposed2D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MatrixDecomposed2D> for ComputedMatrix {
|
impl From<MatrixDecomposed2D> for Matrix3D {
|
||||||
/// Recompose a 2D matrix.
|
/// Recompose a 2D matrix.
|
||||||
/// <https://drafts.csswg.org/css-transforms/#recomposing-to-a-2d-matrix>
|
/// <https://drafts.csswg.org/css-transforms/#recomposing-to-a-2d-matrix>
|
||||||
fn from(decomposed: MatrixDecomposed2D) -> ComputedMatrix {
|
fn from(decomposed: MatrixDecomposed2D) -> Matrix3D {
|
||||||
let mut computed_matrix = ComputedMatrix::identity();
|
let mut computed_matrix = Matrix3D::identity();
|
||||||
computed_matrix.m11 = decomposed.matrix.m11;
|
computed_matrix.m11 = decomposed.matrix.m11;
|
||||||
computed_matrix.m12 = decomposed.matrix.m12;
|
computed_matrix.m12 = decomposed.matrix.m12;
|
||||||
computed_matrix.m21 = decomposed.matrix.m21;
|
computed_matrix.m21 = decomposed.matrix.m21;
|
||||||
|
@ -1475,7 +1420,7 @@ impl From<MatrixDecomposed2D> for ComputedMatrix {
|
||||||
let cos_angle = angle.cos();
|
let cos_angle = angle.cos();
|
||||||
let sin_angle = angle.sin();
|
let sin_angle = angle.sin();
|
||||||
|
|
||||||
let mut rotate_matrix = ComputedMatrix::identity();
|
let mut rotate_matrix = Matrix3D::identity();
|
||||||
rotate_matrix.m11 = cos_angle;
|
rotate_matrix.m11 = cos_angle;
|
||||||
rotate_matrix.m12 = sin_angle;
|
rotate_matrix.m12 = sin_angle;
|
||||||
rotate_matrix.m21 = -sin_angle;
|
rotate_matrix.m21 = -sin_angle;
|
||||||
|
@ -1494,9 +1439,9 @@ impl From<MatrixDecomposed2D> for ComputedMatrix {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl<'a> From< &'a RawGeckoGfxMatrix4x4> for ComputedMatrix {
|
impl<'a> From< &'a RawGeckoGfxMatrix4x4> for Matrix3D {
|
||||||
fn from(m: &'a RawGeckoGfxMatrix4x4) -> ComputedMatrix {
|
fn from(m: &'a RawGeckoGfxMatrix4x4) -> Matrix3D {
|
||||||
ComputedMatrix {
|
Matrix3D {
|
||||||
m11: m[0], m12: m[1], m13: m[2], m14: m[3],
|
m11: m[0], m12: m[1], m13: m[2], m14: m[3],
|
||||||
m21: m[4], m22: m[5], m23: m[6], m24: m[7],
|
m21: m[4], m22: m[5], m23: m[6], m24: m[7],
|
||||||
m31: m[8], m32: m[9], m33: m[10], m34: m[11],
|
m31: m[8], m32: m[9], m33: m[10], m34: m[11],
|
||||||
|
@ -1506,8 +1451,8 @@ impl<'a> From< &'a RawGeckoGfxMatrix4x4> for ComputedMatrix {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl From<ComputedMatrix> for RawGeckoGfxMatrix4x4 {
|
impl From<Matrix3D> for RawGeckoGfxMatrix4x4 {
|
||||||
fn from(matrix: ComputedMatrix) -> RawGeckoGfxMatrix4x4 {
|
fn from(matrix: Matrix3D) -> RawGeckoGfxMatrix4x4 {
|
||||||
[ matrix.m11, matrix.m12, matrix.m13, matrix.m14,
|
[ matrix.m11, matrix.m12, matrix.m13, matrix.m14,
|
||||||
matrix.m21, matrix.m22, matrix.m23, matrix.m24,
|
matrix.m21, matrix.m22, matrix.m23, matrix.m24,
|
||||||
matrix.m31, matrix.m32, matrix.m33, matrix.m34,
|
matrix.m31, matrix.m32, matrix.m33, matrix.m34,
|
||||||
|
@ -1597,7 +1542,7 @@ impl ComputeSquaredDistance for Quaternion {
|
||||||
|
|
||||||
/// Decompose a 3D matrix.
|
/// Decompose a 3D matrix.
|
||||||
/// <https://drafts.csswg.org/css-transforms/#decomposing-a-3d-matrix>
|
/// <https://drafts.csswg.org/css-transforms/#decomposing-a-3d-matrix>
|
||||||
fn decompose_3d_matrix(mut matrix: ComputedMatrix) -> Result<MatrixDecomposed3D, ()> {
|
fn decompose_3d_matrix(mut matrix: Matrix3D) -> Result<MatrixDecomposed3D, ()> {
|
||||||
// Normalize the matrix.
|
// Normalize the matrix.
|
||||||
if matrix.m44 == 0.0 {
|
if matrix.m44 == 0.0 {
|
||||||
return Err(());
|
return Err(());
|
||||||
|
@ -1635,7 +1580,7 @@ fn decompose_3d_matrix(mut matrix: ComputedMatrix) -> Result<MatrixDecomposed3D,
|
||||||
perspective_matrix = perspective_matrix.inverse().unwrap();
|
perspective_matrix = perspective_matrix.inverse().unwrap();
|
||||||
|
|
||||||
// Transpose perspective_matrix
|
// Transpose perspective_matrix
|
||||||
perspective_matrix = ComputedMatrix {
|
perspective_matrix = Matrix3D {
|
||||||
% for i in range(1, 5):
|
% for i in range(1, 5):
|
||||||
% for j in range(1, 5):
|
% for j in range(1, 5):
|
||||||
m${i}${j}: perspective_matrix.m${j}${i},
|
m${i}${j}: perspective_matrix.m${j}${i},
|
||||||
|
@ -1743,7 +1688,7 @@ fn decompose_3d_matrix(mut matrix: ComputedMatrix) -> Result<MatrixDecomposed3D,
|
||||||
/// Decompose a 2D matrix for Gecko.
|
/// Decompose a 2D matrix for Gecko.
|
||||||
// Use the algorithm from nsStyleTransformMatrix::Decompose2DMatrix() in Gecko.
|
// Use the algorithm from nsStyleTransformMatrix::Decompose2DMatrix() in Gecko.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
fn decompose_2d_matrix(matrix: &ComputedMatrix) -> Result<MatrixDecomposed3D, ()> {
|
fn decompose_2d_matrix(matrix: &Matrix3D) -> Result<MatrixDecomposed3D, ()> {
|
||||||
// The index is column-major, so the equivalent transform matrix is:
|
// The index is column-major, so the equivalent transform matrix is:
|
||||||
// | m11 m21 0 m41 | => | m11 m21 | and translate(m41, m42)
|
// | m11 m21 0 m41 | => | m11 m21 | and translate(m41, m42)
|
||||||
// | m12 m22 0 m42 | | m12 m22 |
|
// | m12 m22 0 m42 | | m12 m22 |
|
||||||
|
@ -1928,11 +1873,11 @@ impl Animate for MatrixDecomposed3D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MatrixDecomposed3D> for ComputedMatrix {
|
impl From<MatrixDecomposed3D> for Matrix3D {
|
||||||
/// Recompose a 3D matrix.
|
/// Recompose a 3D matrix.
|
||||||
/// <https://drafts.csswg.org/css-transforms/#recomposing-to-a-3d-matrix>
|
/// <https://drafts.csswg.org/css-transforms/#recomposing-to-a-3d-matrix>
|
||||||
fn from(decomposed: MatrixDecomposed3D) -> ComputedMatrix {
|
fn from(decomposed: MatrixDecomposed3D) -> Matrix3D {
|
||||||
let mut matrix = ComputedMatrix::identity();
|
let mut matrix = Matrix3D::identity();
|
||||||
|
|
||||||
// Apply perspective
|
// Apply perspective
|
||||||
% for i in range(1, 5):
|
% for i in range(1, 5):
|
||||||
|
@ -1954,7 +1899,7 @@ impl From<MatrixDecomposed3D> for ComputedMatrix {
|
||||||
|
|
||||||
// Construct a composite rotation matrix from the quaternion values
|
// Construct a composite rotation matrix from the quaternion values
|
||||||
// rotationMatrix is a identity 4x4 matrix initially
|
// rotationMatrix is a identity 4x4 matrix initially
|
||||||
let mut rotation_matrix = ComputedMatrix::identity();
|
let mut rotation_matrix = Matrix3D::identity();
|
||||||
rotation_matrix.m11 = 1.0 - 2.0 * (y * y + z * z) as f32;
|
rotation_matrix.m11 = 1.0 - 2.0 * (y * y + z * z) as f32;
|
||||||
rotation_matrix.m12 = 2.0 * (x * y + z * w) as f32;
|
rotation_matrix.m12 = 2.0 * (x * y + z * w) as f32;
|
||||||
rotation_matrix.m13 = 2.0 * (x * z - y * w) as f32;
|
rotation_matrix.m13 = 2.0 * (x * z - y * w) as f32;
|
||||||
|
@ -1968,7 +1913,7 @@ impl From<MatrixDecomposed3D> for ComputedMatrix {
|
||||||
matrix = multiply(rotation_matrix, matrix);
|
matrix = multiply(rotation_matrix, matrix);
|
||||||
|
|
||||||
// Apply skew
|
// Apply skew
|
||||||
let mut temp = ComputedMatrix::identity();
|
let mut temp = Matrix3D::identity();
|
||||||
if decomposed.skew.2 != 0.0 {
|
if decomposed.skew.2 != 0.0 {
|
||||||
temp.m32 = decomposed.skew.2;
|
temp.m32 = decomposed.skew.2;
|
||||||
matrix = multiply(temp, matrix);
|
matrix = multiply(temp, matrix);
|
||||||
|
@ -1998,7 +1943,7 @@ impl From<MatrixDecomposed3D> for ComputedMatrix {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiplication of two 4x4 matrices.
|
// Multiplication of two 4x4 matrices.
|
||||||
fn multiply(a: ComputedMatrix, b: ComputedMatrix) -> ComputedMatrix {
|
fn multiply(a: Matrix3D, b: Matrix3D) -> Matrix3D {
|
||||||
let mut a_clone = a;
|
let mut a_clone = a;
|
||||||
% for i in range(1, 5):
|
% for i in range(1, 5):
|
||||||
% for j in range(1, 5):
|
% for j in range(1, 5):
|
||||||
|
@ -2011,7 +1956,7 @@ fn multiply(a: ComputedMatrix, b: ComputedMatrix) -> ComputedMatrix {
|
||||||
a_clone
|
a_clone
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComputedMatrix {
|
impl Matrix3D {
|
||||||
fn is_3d(&self) -> bool {
|
fn is_3d(&self) -> bool {
|
||||||
self.m13 != 0.0 || self.m14 != 0.0 ||
|
self.m13 != 0.0 || self.m14 != 0.0 ||
|
||||||
self.m23 != 0.0 || self.m24 != 0.0 ||
|
self.m23 != 0.0 || self.m24 != 0.0 ||
|
||||||
|
@ -2046,7 +1991,7 @@ impl ComputedMatrix {
|
||||||
self.m11 * self.m22 * self.m33 * self.m44
|
self.m11 * self.m22 * self.m33 * self.m44
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inverse(&self) -> Option<ComputedMatrix> {
|
fn inverse(&self) -> Option<Matrix3D> {
|
||||||
let mut det = self.determinant();
|
let mut det = self.determinant();
|
||||||
|
|
||||||
if det == 0.0 {
|
if det == 0.0 {
|
||||||
|
@ -2054,7 +1999,7 @@ impl ComputedMatrix {
|
||||||
}
|
}
|
||||||
|
|
||||||
det = 1.0 / det;
|
det = 1.0 / det;
|
||||||
let x = ComputedMatrix {
|
let x = Matrix3D {
|
||||||
m11: det *
|
m11: det *
|
||||||
(self.m23*self.m34*self.m42 - self.m24*self.m33*self.m42 +
|
(self.m23*self.m34*self.m42 - self.m24*self.m33*self.m42 +
|
||||||
self.m24*self.m32*self.m43 - self.m22*self.m34*self.m43 -
|
self.m24*self.m32*self.m43 - self.m22*self.m34*self.m43 -
|
||||||
|
@ -2126,43 +2071,29 @@ impl ComputedMatrix {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-transforms/#interpolation-of-transforms>
|
/// <https://drafts.csswg.org/css-transforms/#interpolation-of-transforms>
|
||||||
impl Animate for TransformList {
|
impl Animate for ComputedTransform {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn animate(
|
fn animate(
|
||||||
&self,
|
&self,
|
||||||
other: &Self,
|
other: &Self,
|
||||||
procedure: Procedure,
|
procedure: Procedure,
|
||||||
) -> Result<Self, ()> {
|
) -> Result<Self, ()> {
|
||||||
if self.0.is_none() && other.0.is_none() {
|
if self.0.is_empty() && other.0.is_empty() {
|
||||||
return Ok(TransformList(None));
|
return Ok(Transform(vec![]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let this = &self.0;
|
||||||
|
let other = &other.0;
|
||||||
|
|
||||||
if procedure == Procedure::Add {
|
if procedure == Procedure::Add {
|
||||||
let this = self.0.as_ref().map_or(&[][..], |l| l);
|
|
||||||
let other = other.0.as_ref().map_or(&[][..], |l| l);
|
|
||||||
let result = this.iter().chain(other).cloned().collect::<Vec<_>>();
|
let result = this.iter().chain(other).cloned().collect::<Vec<_>>();
|
||||||
return Ok(TransformList(if result.is_empty() {
|
return Ok(Transform(result));
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(result)
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let this = if self.0.is_some() {
|
|
||||||
Cow::Borrowed(self)
|
|
||||||
} else {
|
|
||||||
Cow::Owned(other.to_animated_zero()?)
|
|
||||||
};
|
|
||||||
let other = if other.0.is_some() {
|
|
||||||
Cow::Borrowed(other)
|
|
||||||
} else {
|
|
||||||
Cow::Owned(self.to_animated_zero()?)
|
|
||||||
};
|
|
||||||
|
|
||||||
// For matched transform lists.
|
// For matched transform lists.
|
||||||
{
|
{
|
||||||
let this = (*this).0.as_ref().map_or(&[][..], |l| l);
|
|
||||||
let other = (*other).0.as_ref().map_or(&[][..], |l| l);
|
|
||||||
if this.len() == other.len() {
|
if this.len() == other.len() {
|
||||||
let is_matched_transforms = this.iter().zip(other).all(|(this, other)| {
|
let is_matched_transforms = this.iter().zip(other).all(|(this, other)| {
|
||||||
is_matched_operation(this, other)
|
is_matched_operation(this, other)
|
||||||
|
@ -2173,11 +2104,7 @@ impl Animate for TransformList {
|
||||||
this.animate(other, procedure)
|
this.animate(other, procedure)
|
||||||
}).collect::<Result<Vec<_>, _>>();
|
}).collect::<Result<Vec<_>, _>>();
|
||||||
if let Ok(list) = result {
|
if let Ok(list) = result {
|
||||||
return Ok(TransformList(if list.is_empty() {
|
return Ok(Transform(list));
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(list)
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't animate for a pair of matched transform lists?
|
// Can't animate for a pair of matched transform lists?
|
||||||
|
@ -2193,18 +2120,18 @@ impl Animate for TransformList {
|
||||||
match procedure {
|
match procedure {
|
||||||
Procedure::Add => Err(()),
|
Procedure::Add => Err(()),
|
||||||
Procedure::Interpolate { progress } => {
|
Procedure::Interpolate { progress } => {
|
||||||
Ok(TransformList(Some(vec![TransformOperation::InterpolateMatrix {
|
Ok(Transform(vec![TransformOperation::InterpolateMatrix {
|
||||||
from_list: this.into_owned(),
|
from_list: Transform(this.clone()),
|
||||||
to_list: other.into_owned(),
|
to_list: Transform(other.clone()),
|
||||||
progress: Percentage(progress as f32),
|
progress: Percentage(progress as f32),
|
||||||
}])))
|
}]))
|
||||||
},
|
},
|
||||||
Procedure::Accumulate { count } => {
|
Procedure::Accumulate { count } => {
|
||||||
Ok(TransformList(Some(vec![TransformOperation::AccumulateMatrix {
|
Ok(Transform(vec![TransformOperation::AccumulateMatrix {
|
||||||
from_list: this.into_owned(),
|
from_list: Transform(this.clone()),
|
||||||
to_list: other.into_owned(),
|
to_list: Transform(other.clone()),
|
||||||
count: cmp::min(count, i32::max_value() as u64) as i32,
|
count: cmp::min(count, i32::max_value() as u64) as i32,
|
||||||
}])))
|
}]))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2214,12 +2141,12 @@ impl Animate for TransformList {
|
||||||
// to trace the distance travelled by a point as its transform is interpolated between the two
|
// to trace the distance travelled by a point as its transform is interpolated between the two
|
||||||
// lists. That, however, proves to be quite complicated so we take a simple approach for now.
|
// lists. That, however, proves to be quite complicated so we take a simple approach for now.
|
||||||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1318591#c0.
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1318591#c0.
|
||||||
impl ComputeSquaredDistance for TransformOperation {
|
impl ComputeSquaredDistance for ComputedTransformOperation {
|
||||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(
|
(
|
||||||
&TransformOperation::Matrix(ref this),
|
&TransformOperation::Matrix3D(ref this),
|
||||||
&TransformOperation::Matrix(ref other),
|
&TransformOperation::Matrix3D(ref other),
|
||||||
) => {
|
) => {
|
||||||
this.compute_squared_distance(other)
|
this.compute_squared_distance(other)
|
||||||
},
|
},
|
||||||
|
@ -2233,8 +2160,8 @@ impl ComputeSquaredDistance for TransformOperation {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
&TransformOperation::Translate(ref fx, ref fy, ref fz),
|
&TransformOperation::Translate3D(ref fx, ref fy, ref fz),
|
||||||
&TransformOperation::Translate(ref tx, ref ty, ref tz),
|
&TransformOperation::Translate3D(ref tx, ref ty, ref tz),
|
||||||
) => {
|
) => {
|
||||||
// We don't want to require doing layout in order to calculate the result, so
|
// We don't want to require doing layout in order to calculate the result, so
|
||||||
// drop the percentage part. However, dropping percentage makes us impossible to
|
// drop the percentage part. However, dropping percentage makes us impossible to
|
||||||
|
@ -2262,8 +2189,8 @@ impl ComputeSquaredDistance for TransformOperation {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
&TransformOperation::Scale(ref fx, ref fy, ref fz),
|
&TransformOperation::Scale3D(ref fx, ref fy, ref fz),
|
||||||
&TransformOperation::Scale(ref tx, ref ty, ref tz),
|
&TransformOperation::Scale3D(ref tx, ref ty, ref tz),
|
||||||
) => {
|
) => {
|
||||||
Ok(
|
Ok(
|
||||||
fx.compute_squared_distance(&tx)? +
|
fx.compute_squared_distance(&tx)? +
|
||||||
|
@ -2272,13 +2199,13 @@ impl ComputeSquaredDistance for TransformOperation {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
&TransformOperation::Rotate(fx, fy, fz, fa),
|
&TransformOperation::Rotate3D(fx, fy, fz, fa),
|
||||||
&TransformOperation::Rotate(tx, ty, tz, ta),
|
&TransformOperation::Rotate3D(tx, ty, tz, ta),
|
||||||
) => {
|
) => {
|
||||||
let (fx, fy, fz, angle1) =
|
let (fx, fy, fz, angle1) =
|
||||||
TransformList::get_normalized_vector_and_angle(fx, fy, fz, fa);
|
ComputedTransform::get_normalized_vector_and_angle(fx, fy, fz, fa);
|
||||||
let (tx, ty, tz, angle2) =
|
let (tx, ty, tz, angle2) =
|
||||||
TransformList::get_normalized_vector_and_angle(tx, ty, tz, ta);
|
ComputedTransform::get_normalized_vector_and_angle(tx, ty, tz, ta);
|
||||||
if (fx, fy, fz) == (tx, ty, tz) {
|
if (fx, fy, fz) == (tx, ty, tz) {
|
||||||
angle1.compute_squared_distance(&angle2)
|
angle1.compute_squared_distance(&angle2)
|
||||||
} else {
|
} else {
|
||||||
|
@ -2293,8 +2220,8 @@ impl ComputeSquaredDistance for TransformOperation {
|
||||||
&TransformOperation::Perspective(ref fd),
|
&TransformOperation::Perspective(ref fd),
|
||||||
&TransformOperation::Perspective(ref td),
|
&TransformOperation::Perspective(ref td),
|
||||||
) => {
|
) => {
|
||||||
let mut fd_matrix = ComputedMatrix::identity();
|
let mut fd_matrix = Matrix3D::identity();
|
||||||
let mut td_matrix = ComputedMatrix::identity();
|
let mut td_matrix = Matrix3D::identity();
|
||||||
if fd.px() > 0. {
|
if fd.px() > 0. {
|
||||||
fd_matrix.m34 = -1. / fd.px();
|
fd_matrix.m34 = -1. / fd.px();
|
||||||
}
|
}
|
||||||
|
@ -2306,12 +2233,12 @@ impl ComputeSquaredDistance for TransformOperation {
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
&TransformOperation::Perspective(ref p),
|
&TransformOperation::Perspective(ref p),
|
||||||
&TransformOperation::Matrix(ref m),
|
&TransformOperation::Matrix3D(ref m),
|
||||||
) | (
|
) | (
|
||||||
&TransformOperation::Matrix(ref m),
|
&TransformOperation::Matrix3D(ref m),
|
||||||
&TransformOperation::Perspective(ref p),
|
&TransformOperation::Perspective(ref p),
|
||||||
) => {
|
) => {
|
||||||
let mut p_matrix = ComputedMatrix::identity();
|
let mut p_matrix = Matrix3D::identity();
|
||||||
if p.px() > 0. {
|
if p.px() > 0. {
|
||||||
p_matrix.m34 = -1. / p.px();
|
p_matrix.m34 = -1. / p.px();
|
||||||
}
|
}
|
||||||
|
@ -2322,11 +2249,11 @@ impl ComputeSquaredDistance for TransformOperation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComputeSquaredDistance for TransformList {
|
impl ComputeSquaredDistance for ComputedTransform {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||||
let list1 = self.0.as_ref().map_or(&[][..], |l| l);
|
let list1 = &self.0;
|
||||||
let list2 = other.0.as_ref().map_or(&[][..], |l| l);
|
let list2 = &other.0;
|
||||||
|
|
||||||
let squared_dist: Result<SquaredDistance, _> = list1.iter().zip_longest(list2).map(|it| {
|
let squared_dist: Result<SquaredDistance, _> = list1.iter().zip_longest(list2).map(|it| {
|
||||||
match it {
|
match it {
|
||||||
|
@ -2342,28 +2269,14 @@ impl ComputeSquaredDistance for TransformList {
|
||||||
// Roll back to matrix interpolation if there is any Err(()) in the transform lists, such
|
// Roll back to matrix interpolation if there is any Err(()) in the transform lists, such
|
||||||
// as mismatched transform functions.
|
// as mismatched transform functions.
|
||||||
if let Err(_) = squared_dist {
|
if let Err(_) = squared_dist {
|
||||||
let matrix1: ComputedMatrix = self.to_transform_3d_matrix(None).ok_or(())?.into();
|
let matrix1: Matrix3D = self.to_transform_3d_matrix(None).ok_or(())?.into();
|
||||||
let matrix2: ComputedMatrix = other.to_transform_3d_matrix(None).ok_or(())?.into();
|
let matrix2: Matrix3D = other.to_transform_3d_matrix(None).ok_or(())?.into();
|
||||||
return matrix1.compute_squared_distance(&matrix2);
|
return matrix1.compute_squared_distance(&matrix2);
|
||||||
}
|
}
|
||||||
squared_dist
|
squared_dist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToAnimatedZero for TransformList {
|
|
||||||
#[inline]
|
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
|
||||||
match self.0 {
|
|
||||||
None => Ok(TransformList(None)),
|
|
||||||
Some(ref list) => {
|
|
||||||
Ok(TransformList(Some(
|
|
||||||
list.iter().map(|op| op.to_animated_zero()).collect::<Result<Vec<_>, _>>()?
|
|
||||||
)))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Animated SVGPaint
|
/// Animated SVGPaint
|
||||||
pub type IntermediateSVGPaint = SVGPaint<AnimatedRGBA, ComputedUrl>;
|
pub type IntermediateSVGPaint = SVGPaint<AnimatedRGBA, ComputedUrl>;
|
||||||
|
|
||||||
|
|
|
@ -571,533 +571,28 @@ ${helpers.predefined_type(
|
||||||
animation_value_type="ComputedValue"
|
animation_value_type="ComputedValue"
|
||||||
flags="CREATES_STACKING_CONTEXT FIXPOS_CB"
|
flags="CREATES_STACKING_CONTEXT FIXPOS_CB"
|
||||||
spec="https://drafts.csswg.org/css-transforms/#propdef-transform">
|
spec="https://drafts.csswg.org/css-transforms/#propdef-transform">
|
||||||
use values::computed::{LengthOrPercentageOrNumber as ComputedLoPoNumber, LengthOrNumber as ComputedLoN};
|
use values::generics::transform::Transform;
|
||||||
use values::computed::{LengthOrPercentage as ComputedLoP, Length as ComputedLength};
|
|
||||||
use values::generics::transform::Matrix;
|
|
||||||
use values::specified::{Angle, Integer, Length, LengthOrPercentage};
|
|
||||||
use values::specified::{LengthOrNumber, LengthOrPercentageOrNumber as LoPoNumber, Number};
|
|
||||||
use style_traits::ToCss;
|
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::CSSFloat;
|
pub use values::computed::transform::Transform as T;
|
||||||
use values::computed;
|
pub use values::computed::transform::TransformOperation as ComputedOperation;
|
||||||
use values::computed::{Length, LengthOrPercentage};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
pub struct ComputedMatrix {
|
|
||||||
pub m11: CSSFloat, pub m12: CSSFloat, pub m13: CSSFloat, pub m14: CSSFloat,
|
|
||||||
pub m21: CSSFloat, pub m22: CSSFloat, pub m23: CSSFloat, pub m24: CSSFloat,
|
|
||||||
pub m31: CSSFloat, pub m32: CSSFloat, pub m33: CSSFloat, pub m34: CSSFloat,
|
|
||||||
pub m41: CSSFloat, pub m42: CSSFloat, pub m43: CSSFloat, pub m44: CSSFloat,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
pub struct ComputedMatrixWithPercents {
|
|
||||||
pub m11: CSSFloat, pub m12: CSSFloat, pub m13: CSSFloat, pub m14: CSSFloat,
|
|
||||||
pub m21: CSSFloat, pub m22: CSSFloat, pub m23: CSSFloat, pub m24: CSSFloat,
|
|
||||||
pub m31: CSSFloat, pub m32: CSSFloat, pub m33: CSSFloat, pub m34: CSSFloat,
|
|
||||||
pub m41: LengthOrPercentage, pub m42: LengthOrPercentage,
|
|
||||||
pub m43: Length, pub m44: CSSFloat,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputedMatrix {
|
|
||||||
pub fn identity() -> ComputedMatrix {
|
|
||||||
ComputedMatrix {
|
|
||||||
m11: 1.0, m12: 0.0, m13: 0.0, m14: 0.0,
|
|
||||||
m21: 0.0, m22: 1.0, m23: 0.0, m24: 0.0,
|
|
||||||
m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0,
|
|
||||||
m41: 0.0, m42: 0.0, m43: 0.0, m44: 1.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputedMatrixWithPercents {
|
|
||||||
pub fn identity() -> ComputedMatrixWithPercents {
|
|
||||||
ComputedMatrixWithPercents {
|
|
||||||
m11: 1.0, m12: 0.0, m13: 0.0, m14: 0.0,
|
|
||||||
m21: 0.0, m22: 1.0, m23: 0.0, m24: 0.0,
|
|
||||||
m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0,
|
|
||||||
m41: LengthOrPercentage::zero(), m42: LengthOrPercentage::zero(),
|
|
||||||
m43: Length::new(0.), m44: 1.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
pub enum ComputedOperation {
|
|
||||||
Matrix(ComputedMatrix),
|
|
||||||
// For `-moz-transform` matrix and matrix3d.
|
|
||||||
MatrixWithPercents(ComputedMatrixWithPercents),
|
|
||||||
Skew(computed::Angle, computed::Angle),
|
|
||||||
Translate(computed::LengthOrPercentage,
|
|
||||||
computed::LengthOrPercentage,
|
|
||||||
computed::Length),
|
|
||||||
Scale(CSSFloat, CSSFloat, CSSFloat),
|
|
||||||
Rotate(CSSFloat, CSSFloat, CSSFloat, computed::Angle),
|
|
||||||
Perspective(computed::Length),
|
|
||||||
// For mismatched transform lists.
|
|
||||||
// A vector of |ComputedOperation| could contain an |InterpolateMatrix| and other
|
|
||||||
// |ComputedOperation|s, and multiple nested |InterpolateMatrix|s is acceptable.
|
|
||||||
// e.g.
|
|
||||||
// [ InterpolateMatrix { from_list: [ InterpolateMatrix { ... },
|
|
||||||
// Scale(...) ],
|
|
||||||
// to_list: [ AccumulateMatrix { from_list: ...,
|
|
||||||
// to_list: [ InterpolateMatrix,
|
|
||||||
// ... ],
|
|
||||||
// count: ... } ],
|
|
||||||
// progress: ... } ]
|
|
||||||
InterpolateMatrix { from_list: T,
|
|
||||||
to_list: T,
|
|
||||||
progress: computed::Percentage },
|
|
||||||
// For accumulate operation of mismatched transform lists.
|
|
||||||
AccumulateMatrix { from_list: T,
|
|
||||||
to_list: T,
|
|
||||||
count: computed::Integer },
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
pub struct T(pub Option<Vec<ComputedOperation>>);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describes a single parsed
|
pub use values::specified::transform::Transform as SpecifiedValue;
|
||||||
/// [Transform Function](https://drafts.csswg.org/css-transforms/#typedef-transform-function).
|
pub use values::specified::transform::TransformOperation as SpecifiedOperation;
|
||||||
///
|
|
||||||
/// Multiple transform functions compose a transformation.
|
|
||||||
///
|
|
||||||
/// Some transformations can be expressed by other more general functions.
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
pub enum SpecifiedOperation {
|
|
||||||
/// Represents a 2D 2x3 matrix.
|
|
||||||
Matrix(Matrix<Number>),
|
|
||||||
/// Represents a 3D 4x4 matrix with percentage and length values.
|
|
||||||
/// For `moz-transform`.
|
|
||||||
PrefixedMatrix(Matrix<Number, LoPoNumber>),
|
|
||||||
/// Represents a 3D 4x4 matrix.
|
|
||||||
Matrix3D {
|
|
||||||
m11: Number, m12: Number, m13: Number, m14: Number,
|
|
||||||
m21: Number, m22: Number, m23: Number, m24: Number,
|
|
||||||
m31: Number, m32: Number, m33: Number, m34: Number,
|
|
||||||
m41: Number, m42: Number, m43: Number, m44: Number,
|
|
||||||
},
|
|
||||||
/// Represents a 3D 4x4 matrix with percentage and length values.
|
|
||||||
/// For `moz-transform`.
|
|
||||||
PrefixedMatrix3D {
|
|
||||||
m11: Number, m12: Number, m13: Number, m14: Number,
|
|
||||||
m21: Number, m22: Number, m23: Number, m24: Number,
|
|
||||||
m31: Number, m32: Number, m33: Number, m34: Number,
|
|
||||||
m41: LoPoNumber, m42: LoPoNumber, m43: LengthOrNumber, m44: Number,
|
|
||||||
},
|
|
||||||
/// A 2D skew.
|
|
||||||
///
|
|
||||||
/// If the second angle is not provided it is assumed zero.
|
|
||||||
Skew(Angle, Option<Angle>),
|
|
||||||
SkewX(Angle),
|
|
||||||
SkewY(Angle),
|
|
||||||
Translate(LengthOrPercentage, Option<LengthOrPercentage>),
|
|
||||||
TranslateX(LengthOrPercentage),
|
|
||||||
TranslateY(LengthOrPercentage),
|
|
||||||
TranslateZ(Length),
|
|
||||||
Translate3D(LengthOrPercentage, LengthOrPercentage, Length),
|
|
||||||
/// A 2D scaling factor.
|
|
||||||
///
|
|
||||||
/// `scale(2)` is parsed as `Scale(Number::new(2.0), None)` and is equivalent to
|
|
||||||
/// writing `scale(2, 2)` (`Scale(Number::new(2.0), Some(Number::new(2.0)))`).
|
|
||||||
///
|
|
||||||
/// Negative values are allowed and flip the element.
|
|
||||||
Scale(Number, Option<Number>),
|
|
||||||
ScaleX(Number),
|
|
||||||
ScaleY(Number),
|
|
||||||
ScaleZ(Number),
|
|
||||||
Scale3D(Number, Number, Number),
|
|
||||||
/// Describes a 2D Rotation.
|
|
||||||
///
|
|
||||||
/// In a 3D scene `rotate(angle)` is equivalent to `rotateZ(angle)`.
|
|
||||||
Rotate(Angle),
|
|
||||||
/// Rotation in 3D space around the x-axis.
|
|
||||||
RotateX(Angle),
|
|
||||||
/// Rotation in 3D space around the y-axis.
|
|
||||||
RotateY(Angle),
|
|
||||||
/// Rotation in 3D space around the z-axis.
|
|
||||||
RotateZ(Angle),
|
|
||||||
/// Rotation in 3D space.
|
|
||||||
///
|
|
||||||
/// Generalization of rotateX, rotateY and rotateZ.
|
|
||||||
Rotate3D(Number, Number, Number, Angle),
|
|
||||||
/// Specifies a perspective projection matrix.
|
|
||||||
///
|
|
||||||
/// Part of CSS Transform Module Level 2 and defined at
|
|
||||||
/// [§ 13.1. 3D Transform Function](https://drafts.csswg.org/css-transforms-2/#funcdef-perspective).
|
|
||||||
///
|
|
||||||
/// The value must be greater than or equal to zero.
|
|
||||||
Perspective(specified::Length),
|
|
||||||
/// A intermediate type for interpolation of mismatched transform lists.
|
|
||||||
InterpolateMatrix { from_list: SpecifiedValue,
|
|
||||||
to_list: SpecifiedValue,
|
|
||||||
progress: computed::Percentage },
|
|
||||||
/// A intermediate type for accumulation of mismatched transform lists.
|
|
||||||
AccumulateMatrix { from_list: SpecifiedValue,
|
|
||||||
to_list: SpecifiedValue,
|
|
||||||
count: Integer },
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
|
||||||
fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
// TODO(pcwalton)
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for SpecifiedOperation {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
SpecifiedOperation::Matrix(ref m) => m.to_css(dest),
|
|
||||||
SpecifiedOperation::PrefixedMatrix(ref m) => m.to_css(dest),
|
|
||||||
SpecifiedOperation::Matrix3D {
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
m41, m42, m43, m44,
|
|
||||||
} => {
|
|
||||||
serialize_function!(dest, matrix3d(
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
m41, m42, m43, m44,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::PrefixedMatrix3D {
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
ref m41, ref m42, ref m43, m44,
|
|
||||||
} => {
|
|
||||||
serialize_function!(dest, matrix3d(
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
m41, m42, m43, m44,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Skew(ax, None) => {
|
|
||||||
serialize_function!(dest, skew(ax))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Skew(ax, Some(ay)) => {
|
|
||||||
serialize_function!(dest, skew(ax, ay))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::SkewX(angle) => {
|
|
||||||
serialize_function!(dest, skewX(angle))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::SkewY(angle) => {
|
|
||||||
serialize_function!(dest, skewY(angle))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Translate(ref tx, None) => {
|
|
||||||
serialize_function!(dest, translate(tx))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Translate(ref tx, Some(ref ty)) => {
|
|
||||||
serialize_function!(dest, translate(tx, ty))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::TranslateX(ref tx) => {
|
|
||||||
serialize_function!(dest, translateX(tx))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::TranslateY(ref ty) => {
|
|
||||||
serialize_function!(dest, translateY(ty))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::TranslateZ(ref tz) => {
|
|
||||||
serialize_function!(dest, translateZ(tz))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Translate3D(ref tx, ref ty, ref tz) => {
|
|
||||||
serialize_function!(dest, translate3d(tx, ty, tz))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Scale(factor, None) => {
|
|
||||||
serialize_function!(dest, scale(factor))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Scale(sx, Some(sy)) => {
|
|
||||||
serialize_function!(dest, scale(sx, sy))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::ScaleX(sx) => {
|
|
||||||
serialize_function!(dest, scaleX(sx))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::ScaleY(sy) => {
|
|
||||||
serialize_function!(dest, scaleY(sy))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::ScaleZ(sz) => {
|
|
||||||
serialize_function!(dest, scaleZ(sz))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Scale3D(sx, sy, sz) => {
|
|
||||||
serialize_function!(dest, scale3d(sx, sy, sz))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Rotate(theta) => {
|
|
||||||
serialize_function!(dest, rotate(theta))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::RotateX(theta) => {
|
|
||||||
serialize_function!(dest, rotateX(theta))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::RotateY(theta) => {
|
|
||||||
serialize_function!(dest, rotateY(theta))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::RotateZ(theta) => {
|
|
||||||
serialize_function!(dest, rotateZ(theta))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Rotate3D(x, y, z, theta) => {
|
|
||||||
serialize_function!(dest, rotate3d(x, y, z, theta))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Perspective(ref length) => {
|
|
||||||
serialize_function!(dest, perspective(length))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::InterpolateMatrix { ref from_list, ref to_list, progress } => {
|
|
||||||
serialize_function!(dest, interpolatematrix(from_list, to_list, progress))
|
|
||||||
}
|
|
||||||
SpecifiedOperation::AccumulateMatrix { ref from_list, ref to_list, count } => {
|
|
||||||
serialize_function!(dest, accumulatematrix(from_list, to_list, count))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
pub struct SpecifiedValue(Vec<SpecifiedOperation>);
|
|
||||||
|
|
||||||
impl ToCss for SpecifiedValue {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
|
|
||||||
if self.0.is_empty() {
|
|
||||||
return dest.write_str("none")
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut first = true;
|
|
||||||
for operation in &self.0 {
|
|
||||||
if !first {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
}
|
|
||||||
first = false;
|
|
||||||
operation.to_css(dest)?
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
computed_value::T(None)
|
Transform(vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow unitless zero angle for rotate() and skew() to align with gecko
|
|
||||||
fn parse_internal<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
prefixed: bool,
|
|
||||||
) -> Result<SpecifiedValue,ParseError<'i>> {
|
|
||||||
use style_traits::{Separator, Space};
|
|
||||||
|
|
||||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
|
||||||
return Ok(SpecifiedValue(Vec::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(SpecifiedValue(Space::parse(input, |input| {
|
|
||||||
let function = input.expect_function()?.clone();
|
|
||||||
input.parse_nested_block(|input| {
|
|
||||||
let result = match_ignore_ascii_case! { &function,
|
|
||||||
"matrix" => {
|
|
||||||
let a = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let b = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let c = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let d = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
if !prefixed {
|
|
||||||
// Standard matrix parsing.
|
|
||||||
let e = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let f = specified::parse_number(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Matrix(Matrix { a, b, c, d, e, f }))
|
|
||||||
} else {
|
|
||||||
// Non-standard prefixed matrix parsing for -moz-transform.
|
|
||||||
let e = LoPoNumber::parse(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let f = LoPoNumber::parse(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::PrefixedMatrix(Matrix { a, b, c, d, e, f }))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"matrix3d" => {
|
|
||||||
let m11 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m12 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m13 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m14 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m21 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m22 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m23 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m24 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m31 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m32 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m33 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m34 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
if !prefixed {
|
|
||||||
// Standard matrix3d parsing.
|
|
||||||
let m41 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m42 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m43 = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m44 = specified::parse_number(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Matrix3D {
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
m41, m42, m43, m44,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// Non-standard prefixed matrix parsing for -moz-transform.
|
|
||||||
let m41 = LoPoNumber::parse(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m42 = LoPoNumber::parse(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m43 = LengthOrNumber::parse(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let m44 = specified::parse_number(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::PrefixedMatrix3D {
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
m41, m42, m43, m44,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"translate" => {
|
|
||||||
let sx = specified::LengthOrPercentage::parse(context, input)?;
|
|
||||||
if input.try(|input| input.expect_comma()).is_ok() {
|
|
||||||
let sy = specified::LengthOrPercentage::parse(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Translate(sx, Some(sy)))
|
|
||||||
} else {
|
|
||||||
Ok(SpecifiedOperation::Translate(sx, None))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"translatex" => {
|
|
||||||
let tx = specified::LengthOrPercentage::parse(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::TranslateX(tx))
|
|
||||||
},
|
|
||||||
"translatey" => {
|
|
||||||
let ty = specified::LengthOrPercentage::parse(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::TranslateY(ty))
|
|
||||||
},
|
|
||||||
"translatez" => {
|
|
||||||
let tz = specified::Length::parse(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::TranslateZ(tz))
|
|
||||||
},
|
|
||||||
"translate3d" => {
|
|
||||||
let tx = specified::LengthOrPercentage::parse(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let ty = specified::LengthOrPercentage::parse(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let tz = specified::Length::parse(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Translate3D(tx, ty, tz))
|
|
||||||
},
|
|
||||||
"scale" => {
|
|
||||||
let sx = specified::parse_number(context, input)?;
|
|
||||||
if input.try(|input| input.expect_comma()).is_ok() {
|
|
||||||
let sy = specified::parse_number(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Scale(sx, Some(sy)))
|
|
||||||
} else {
|
|
||||||
Ok(SpecifiedOperation::Scale(sx, None))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"scalex" => {
|
|
||||||
let sx = specified::parse_number(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::ScaleX(sx))
|
|
||||||
},
|
|
||||||
"scaley" => {
|
|
||||||
let sy = specified::parse_number(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::ScaleY(sy))
|
|
||||||
},
|
|
||||||
"scalez" => {
|
|
||||||
let sz = specified::parse_number(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::ScaleZ(sz))
|
|
||||||
},
|
|
||||||
"scale3d" => {
|
|
||||||
let sx = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let sy = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let sz = specified::parse_number(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Scale3D(sx, sy, sz))
|
|
||||||
},
|
|
||||||
"rotate" => {
|
|
||||||
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Rotate(theta))
|
|
||||||
},
|
|
||||||
"rotatex" => {
|
|
||||||
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::RotateX(theta))
|
|
||||||
},
|
|
||||||
"rotatey" => {
|
|
||||||
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::RotateY(theta))
|
|
||||||
},
|
|
||||||
"rotatez" => {
|
|
||||||
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::RotateZ(theta))
|
|
||||||
},
|
|
||||||
"rotate3d" => {
|
|
||||||
let ax = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let ay = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let az = specified::parse_number(context, input)?;
|
|
||||||
input.expect_comma()?;
|
|
||||||
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
// TODO(gw): Check that the axis can be normalized.
|
|
||||||
Ok(SpecifiedOperation::Rotate3D(ax, ay, az, theta))
|
|
||||||
},
|
|
||||||
"skew" => {
|
|
||||||
let ax = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
if input.try(|input| input.expect_comma()).is_ok() {
|
|
||||||
let ay = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Skew(ax, Some(ay)))
|
|
||||||
} else {
|
|
||||||
Ok(SpecifiedOperation::Skew(ax, None))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"skewx" => {
|
|
||||||
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::SkewX(theta))
|
|
||||||
},
|
|
||||||
"skewy" => {
|
|
||||||
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::SkewY(theta))
|
|
||||||
},
|
|
||||||
"perspective" => {
|
|
||||||
let d = specified::Length::parse_non_negative(context, input)?;
|
|
||||||
Ok(SpecifiedOperation::Perspective(d))
|
|
||||||
},
|
|
||||||
_ => Err(()),
|
|
||||||
};
|
|
||||||
result
|
|
||||||
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function.clone())))
|
|
||||||
})
|
|
||||||
})?))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses `transform` property.
|
/// Parses `transform` property.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<SpecifiedValue,ParseError<'i>> {
|
-> Result<SpecifiedValue,ParseError<'i>> {
|
||||||
parse_internal(context, input, false)
|
SpecifiedValue::parse_internal(context, input, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses `-moz-transform` property. This prefixed property also accepts LengthOrPercentage
|
/// Parses `-moz-transform` property. This prefixed property also accepts LengthOrPercentage
|
||||||
|
@ -1105,341 +600,7 @@ ${helpers.predefined_type(
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parse_prefixed<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse_prefixed<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<SpecifiedValue,ParseError<'i>> {
|
-> Result<SpecifiedValue,ParseError<'i>> {
|
||||||
parse_internal(context, input, true)
|
SpecifiedValue::parse_internal(context, input, true)
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
|
||||||
type ComputedValue = computed_value::T;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
|
||||||
if self.0.is_empty() {
|
|
||||||
return computed_value::T(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut result = vec!();
|
|
||||||
for operation in &self.0 {
|
|
||||||
match *operation {
|
|
||||||
SpecifiedOperation::Matrix(Matrix { a, b, c, d, e, f }) => {
|
|
||||||
let mut comp = computed_value::ComputedMatrix::identity();
|
|
||||||
comp.m11 = a.to_computed_value(context);
|
|
||||||
comp.m12 = b.to_computed_value(context);
|
|
||||||
comp.m21 = c.to_computed_value(context);
|
|
||||||
comp.m22 = d.to_computed_value(context);
|
|
||||||
comp.m41 = e.to_computed_value(context);
|
|
||||||
comp.m42 = f.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Matrix(comp));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::PrefixedMatrix(Matrix { a, b, c, d, ref e, ref f }) => {
|
|
||||||
let mut comp = computed_value::ComputedMatrixWithPercents::identity();
|
|
||||||
comp.m11 = a.to_computed_value(context);
|
|
||||||
comp.m12 = b.to_computed_value(context);
|
|
||||||
comp.m21 = c.to_computed_value(context);
|
|
||||||
comp.m22 = d.to_computed_value(context);
|
|
||||||
comp.m41 = lopon_to_lop(&e.to_computed_value(context));
|
|
||||||
comp.m42 = lopon_to_lop(&f.to_computed_value(context));
|
|
||||||
result.push(computed_value::ComputedOperation::MatrixWithPercents(comp));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Matrix3D {
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
ref m41, ref m42, ref m43, m44 } => {
|
|
||||||
let comp = computed_value::ComputedMatrix {
|
|
||||||
m11: m11.to_computed_value(context),
|
|
||||||
m12: m12.to_computed_value(context),
|
|
||||||
m13: m13.to_computed_value(context),
|
|
||||||
m14: m14.to_computed_value(context),
|
|
||||||
m21: m21.to_computed_value(context),
|
|
||||||
m22: m22.to_computed_value(context),
|
|
||||||
m23: m23.to_computed_value(context),
|
|
||||||
m24: m24.to_computed_value(context),
|
|
||||||
m31: m31.to_computed_value(context),
|
|
||||||
m32: m32.to_computed_value(context),
|
|
||||||
m33: m33.to_computed_value(context),
|
|
||||||
m34: m34.to_computed_value(context),
|
|
||||||
m41: m41.to_computed_value(context),
|
|
||||||
m42: m42.to_computed_value(context),
|
|
||||||
m43: m43.to_computed_value(context),
|
|
||||||
m44: m44.to_computed_value(context),
|
|
||||||
};
|
|
||||||
result.push(computed_value::ComputedOperation::Matrix(comp));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::PrefixedMatrix3D {
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
ref m41, ref m42, ref m43, m44 } => {
|
|
||||||
let comp = computed_value::ComputedMatrixWithPercents {
|
|
||||||
m11: m11.to_computed_value(context),
|
|
||||||
m12: m12.to_computed_value(context),
|
|
||||||
m13: m13.to_computed_value(context),
|
|
||||||
m14: m14.to_computed_value(context),
|
|
||||||
m21: m21.to_computed_value(context),
|
|
||||||
m22: m22.to_computed_value(context),
|
|
||||||
m23: m23.to_computed_value(context),
|
|
||||||
m24: m24.to_computed_value(context),
|
|
||||||
m31: m31.to_computed_value(context),
|
|
||||||
m32: m32.to_computed_value(context),
|
|
||||||
m33: m33.to_computed_value(context),
|
|
||||||
m34: m34.to_computed_value(context),
|
|
||||||
m41: lopon_to_lop(&m41.to_computed_value(context)),
|
|
||||||
m42: lopon_to_lop(&m42.to_computed_value(context)),
|
|
||||||
m43: lon_to_length(&m43.to_computed_value(context)),
|
|
||||||
m44: m44.to_computed_value(context),
|
|
||||||
};
|
|
||||||
result.push(computed_value::ComputedOperation::MatrixWithPercents(comp));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Translate(ref tx, None) => {
|
|
||||||
let tx = tx.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Translate(
|
|
||||||
tx,
|
|
||||||
computed::length::LengthOrPercentage::zero(),
|
|
||||||
computed::length::Length::new(0.)));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Translate(ref tx, Some(ref ty)) => {
|
|
||||||
let tx = tx.to_computed_value(context);
|
|
||||||
let ty = ty.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Translate(
|
|
||||||
tx,
|
|
||||||
ty,
|
|
||||||
computed::length::Length::new(0.)));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::TranslateX(ref tx) => {
|
|
||||||
let tx = tx.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Translate(
|
|
||||||
tx,
|
|
||||||
computed::length::LengthOrPercentage::zero(),
|
|
||||||
computed::length::Length::new(0.)));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::TranslateY(ref ty) => {
|
|
||||||
let ty = ty.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Translate(
|
|
||||||
computed::length::LengthOrPercentage::zero(),
|
|
||||||
ty,
|
|
||||||
computed::length::Length::new(0.)));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::TranslateZ(ref tz) => {
|
|
||||||
let tz = tz.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Translate(
|
|
||||||
computed::length::LengthOrPercentage::zero(),
|
|
||||||
computed::length::LengthOrPercentage::zero(),
|
|
||||||
tz));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Translate3D(ref tx, ref ty, ref tz) => {
|
|
||||||
let tx = tx.to_computed_value(context);
|
|
||||||
let ty = ty.to_computed_value(context);
|
|
||||||
let tz = tz.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Translate(tx, ty, tz));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Scale(factor, None) => {
|
|
||||||
let factor = factor.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Scale(factor, factor, 1.0));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Scale(sx, Some(sy)) => {
|
|
||||||
let sx = sx.to_computed_value(context);
|
|
||||||
let sy = sy.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Scale(sx, sy, 1.0));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::ScaleX(sx) => {
|
|
||||||
let sx = sx.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Scale(sx, 1.0, 1.0));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::ScaleY(sy) => {
|
|
||||||
let sy = sy.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Scale(1.0, sy, 1.0));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::ScaleZ(sz) => {
|
|
||||||
let sz = sz.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Scale(1.0, 1.0, sz));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Scale3D(sx, sy, sz) => {
|
|
||||||
let sx = sx.to_computed_value(context);
|
|
||||||
let sy = sy.to_computed_value(context);
|
|
||||||
let sz = sz.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Scale(sx, sy, sz));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Rotate(theta) => {
|
|
||||||
let theta = theta.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Rotate(0.0, 0.0, 1.0, theta));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::RotateX(theta) => {
|
|
||||||
let theta = theta.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Rotate(1.0, 0.0, 0.0, theta));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::RotateY(theta) => {
|
|
||||||
let theta = theta.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Rotate(0.0, 1.0, 0.0, theta));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::RotateZ(theta) => {
|
|
||||||
let theta = theta.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Rotate(0.0, 0.0, 1.0, theta));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Rotate3D(ax, ay, az, theta) => {
|
|
||||||
let ax = ax.to_computed_value(context);
|
|
||||||
let ay = ay.to_computed_value(context);
|
|
||||||
let az = az.to_computed_value(context);
|
|
||||||
let theta = theta.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Rotate(ax, ay, az, theta));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Skew(theta_x, None) => {
|
|
||||||
let theta_x = theta_x.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Skew(theta_x, computed::Angle::zero()));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Skew(theta_x, Some(theta_y)) => {
|
|
||||||
let theta_x = theta_x.to_computed_value(context);
|
|
||||||
let theta_y = theta_y.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Skew(theta_x, theta_y));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::SkewX(theta_x) => {
|
|
||||||
let theta_x = theta_x.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Skew(theta_x, computed::Angle::zero()));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::SkewY(theta_y) => {
|
|
||||||
let theta_y = theta_y.to_computed_value(context);
|
|
||||||
result.push(computed_value::ComputedOperation::Skew(computed::Angle::zero(), theta_y));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::Perspective(ref d) => {
|
|
||||||
result.push(computed_value::ComputedOperation::Perspective(d.to_computed_value(context)));
|
|
||||||
}
|
|
||||||
SpecifiedOperation::InterpolateMatrix { ref from_list, ref to_list, progress } => {
|
|
||||||
result.push(computed_value::ComputedOperation::InterpolateMatrix {
|
|
||||||
from_list: from_list.to_computed_value(context),
|
|
||||||
to_list: to_list.to_computed_value(context),
|
|
||||||
progress: progress
|
|
||||||
});
|
|
||||||
}
|
|
||||||
SpecifiedOperation::AccumulateMatrix { ref from_list, ref to_list, count } => {
|
|
||||||
result.push(computed_value::ComputedOperation::AccumulateMatrix {
|
|
||||||
from_list: from_list.to_computed_value(context),
|
|
||||||
to_list: to_list.to_computed_value(context),
|
|
||||||
count: count.value()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
computed_value::T(Some(result))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
|
||||||
SpecifiedValue(computed.0.as_ref().map(|computed| {
|
|
||||||
let mut result = vec![];
|
|
||||||
for operation in computed {
|
|
||||||
match *operation {
|
|
||||||
computed_value::ComputedOperation::Matrix(ref computed) => {
|
|
||||||
result.push(SpecifiedOperation::Matrix3D {
|
|
||||||
m11: Number::from_computed_value(&computed.m11),
|
|
||||||
m12: Number::from_computed_value(&computed.m12),
|
|
||||||
m13: Number::from_computed_value(&computed.m13),
|
|
||||||
m14: Number::from_computed_value(&computed.m14),
|
|
||||||
m21: Number::from_computed_value(&computed.m21),
|
|
||||||
m22: Number::from_computed_value(&computed.m22),
|
|
||||||
m23: Number::from_computed_value(&computed.m23),
|
|
||||||
m24: Number::from_computed_value(&computed.m24),
|
|
||||||
m31: Number::from_computed_value(&computed.m31),
|
|
||||||
m32: Number::from_computed_value(&computed.m32),
|
|
||||||
m33: Number::from_computed_value(&computed.m33),
|
|
||||||
m34: Number::from_computed_value(&computed.m34),
|
|
||||||
m41: Number::from_computed_value(&computed.m41),
|
|
||||||
m42: Number::from_computed_value(&computed.m42),
|
|
||||||
m43: Number::from_computed_value(&computed.m43),
|
|
||||||
m44: Number::from_computed_value(&computed.m44),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
computed_value::ComputedOperation::MatrixWithPercents(ref computed) => {
|
|
||||||
result.push(SpecifiedOperation::PrefixedMatrix3D {
|
|
||||||
m11: Number::from_computed_value(&computed.m11),
|
|
||||||
m12: Number::from_computed_value(&computed.m12),
|
|
||||||
m13: Number::from_computed_value(&computed.m13),
|
|
||||||
m14: Number::from_computed_value(&computed.m14),
|
|
||||||
m21: Number::from_computed_value(&computed.m21),
|
|
||||||
m22: Number::from_computed_value(&computed.m22),
|
|
||||||
m23: Number::from_computed_value(&computed.m23),
|
|
||||||
m24: Number::from_computed_value(&computed.m24),
|
|
||||||
m31: Number::from_computed_value(&computed.m31),
|
|
||||||
m32: Number::from_computed_value(&computed.m32),
|
|
||||||
m33: Number::from_computed_value(&computed.m33),
|
|
||||||
m34: Number::from_computed_value(&computed.m34),
|
|
||||||
m41: Either::Second(LengthOrPercentage::from_computed_value(&computed.m41)),
|
|
||||||
m42: Either::Second(LengthOrPercentage::from_computed_value(&computed.m42)),
|
|
||||||
m43: LengthOrNumber::from_computed_value(&Either::First(computed.m43)),
|
|
||||||
m44: Number::from_computed_value(&computed.m44),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
computed_value::ComputedOperation::Translate(ref tx, ref ty, ref tz) => {
|
|
||||||
// XXXManishearth we lose information here; perhaps we should try to
|
|
||||||
// recover the original function? Not sure if this can be observed.
|
|
||||||
result.push(SpecifiedOperation::Translate3D(
|
|
||||||
ToComputedValue::from_computed_value(tx),
|
|
||||||
ToComputedValue::from_computed_value(ty),
|
|
||||||
ToComputedValue::from_computed_value(tz)));
|
|
||||||
}
|
|
||||||
computed_value::ComputedOperation::Scale(ref sx, ref sy, ref sz) => {
|
|
||||||
result.push(SpecifiedOperation::Scale3D(
|
|
||||||
Number::from_computed_value(sx),
|
|
||||||
Number::from_computed_value(sy),
|
|
||||||
Number::from_computed_value(sz)));
|
|
||||||
}
|
|
||||||
computed_value::ComputedOperation::Rotate(ref ax, ref ay, ref az, ref theta) => {
|
|
||||||
result.push(SpecifiedOperation::Rotate3D(
|
|
||||||
Number::from_computed_value(ax),
|
|
||||||
Number::from_computed_value(ay),
|
|
||||||
Number::from_computed_value(az),
|
|
||||||
specified::Angle::from_computed_value(theta)));
|
|
||||||
}
|
|
||||||
computed_value::ComputedOperation::Skew(ref theta_x, ref theta_y) => {
|
|
||||||
result.push(SpecifiedOperation::Skew(
|
|
||||||
specified::Angle::from_computed_value(theta_x),
|
|
||||||
Some(specified::Angle::from_computed_value(theta_y))))
|
|
||||||
}
|
|
||||||
computed_value::ComputedOperation::Perspective(ref d) => {
|
|
||||||
result.push(SpecifiedOperation::Perspective(
|
|
||||||
ToComputedValue::from_computed_value(d)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
computed_value::ComputedOperation::InterpolateMatrix { ref from_list,
|
|
||||||
ref to_list,
|
|
||||||
progress } => {
|
|
||||||
result.push(SpecifiedOperation::InterpolateMatrix {
|
|
||||||
from_list: SpecifiedValue::from_computed_value(from_list),
|
|
||||||
to_list: SpecifiedValue::from_computed_value(to_list),
|
|
||||||
progress: progress
|
|
||||||
});
|
|
||||||
}
|
|
||||||
computed_value::ComputedOperation::AccumulateMatrix { ref from_list,
|
|
||||||
ref to_list,
|
|
||||||
count } => {
|
|
||||||
result.push(SpecifiedOperation::AccumulateMatrix {
|
|
||||||
from_list: SpecifiedValue::from_computed_value(from_list),
|
|
||||||
to_list: SpecifiedValue::from_computed_value(to_list),
|
|
||||||
count: Integer::new(count)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}).unwrap_or(Vec::new()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Converts computed LengthOrPercentageOrNumber into computed
|
|
||||||
// LengthOrPercentage. Number maps into Length (pixel unit)
|
|
||||||
fn lopon_to_lop(value: &ComputedLoPoNumber) -> ComputedLoP {
|
|
||||||
match *value {
|
|
||||||
Either::First(number) => ComputedLoP::Length(ComputedLength::new(number)),
|
|
||||||
Either::Second(length_or_percentage) => length_or_percentage,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Converts computed LengthOrNumber into computed Length.
|
|
||||||
// Number maps into Length.
|
|
||||||
fn lon_to_length(value: &ComputedLoN) -> ComputedLength {
|
|
||||||
match *value {
|
|
||||||
Either::First(length) => length,
|
|
||||||
Either::Second(number) => ComputedLength::new(number),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
|
|
|
@ -2410,30 +2410,30 @@ impl ComputedValuesInner {
|
||||||
/// Whether given this transform value, the compositor would require a
|
/// Whether given this transform value, the compositor would require a
|
||||||
/// layer.
|
/// layer.
|
||||||
pub fn transform_requires_layer(&self) -> bool {
|
pub fn transform_requires_layer(&self) -> bool {
|
||||||
|
use values::generics::transform::TransformOperation;
|
||||||
// Check if the transform matrix is 2D or 3D
|
// Check if the transform matrix is 2D or 3D
|
||||||
if let Some(ref transform_list) = self.get_box().transform.0 {
|
for transform in &self.get_box().transform.0 {
|
||||||
for transform in transform_list {
|
match *transform {
|
||||||
match *transform {
|
TransformOperation::Perspective(..) => {
|
||||||
computed_values::transform::ComputedOperation::Perspective(..) => {
|
return true;
|
||||||
|
}
|
||||||
|
TransformOperation::Matrix3D(m) => {
|
||||||
|
// See http://dev.w3.org/csswg/css-transforms/#2d-matrix
|
||||||
|
if m.m31 != 0.0 || m.m32 != 0.0 ||
|
||||||
|
m.m13 != 0.0 || m.m23 != 0.0 ||
|
||||||
|
m.m43 != 0.0 || m.m14 != 0.0 ||
|
||||||
|
m.m24 != 0.0 || m.m34 != 0.0 ||
|
||||||
|
m.m33 != 1.0 || m.m44 != 1.0 {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
computed_values::transform::ComputedOperation::Matrix(m) => {
|
|
||||||
// See http://dev.w3.org/csswg/css-transforms/#2d-matrix
|
|
||||||
if m.m31 != 0.0 || m.m32 != 0.0 ||
|
|
||||||
m.m13 != 0.0 || m.m23 != 0.0 ||
|
|
||||||
m.m43 != 0.0 || m.m14 != 0.0 ||
|
|
||||||
m.m24 != 0.0 || m.m34 != 0.0 ||
|
|
||||||
m.m33 != 1.0 || m.m44 != 1.0 {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
computed_values::transform::ComputedOperation::Translate(_, _, z) => {
|
|
||||||
if z.px() != 0. {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
TransformOperation::Translate3D(_, _, z) |
|
||||||
|
TransformOperation::TranslateZ(z) => {
|
||||||
|
if z.px() != 0. {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use euclid::{Rect, Transform3D, Vector3D};
|
use euclid::{Rect, Transform3D, Vector3D};
|
||||||
use properties::longhands::transform::computed_value::{ComputedOperation, ComputedMatrix};
|
|
||||||
use properties::longhands::transform::computed_value::T as TransformList;
|
|
||||||
use std::f32;
|
use std::f32;
|
||||||
use super::{CSSFloat, Either};
|
use super::{CSSFloat, Either};
|
||||||
use values::animated::ToAnimatedZero;
|
use values::animated::ToAnimatedZero;
|
||||||
|
@ -45,29 +43,6 @@ impl TransformOrigin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ComputedMatrix> for Transform3D<CSSFloat> {
|
|
||||||
#[inline]
|
|
||||||
fn from(m: ComputedMatrix) -> Self {
|
|
||||||
Transform3D::row_major(
|
|
||||||
m.m11, m.m12, m.m13, m.m14,
|
|
||||||
m.m21, m.m22, m.m23, m.m24,
|
|
||||||
m.m31, m.m32, m.m33, m.m34,
|
|
||||||
m.m41, m.m42, m.m43, m.m44)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Transform3D<CSSFloat>> for ComputedMatrix {
|
|
||||||
#[inline]
|
|
||||||
fn from(m: Transform3D<CSSFloat>) -> Self {
|
|
||||||
ComputedMatrix {
|
|
||||||
m11: m.m11, m12: m.m12, m13: m.m13, m14: m.m14,
|
|
||||||
m21: m.m21, m22: m.m22, m23: m.m23, m24: m.m24,
|
|
||||||
m31: m.m31, m32: m.m32, m33: m.m33, m34: m.m34,
|
|
||||||
m41: m.m41, m42: m.m42, m43: m.m43, m44: m.m44
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// computed value of matrix3d()
|
/// computed value of matrix3d()
|
||||||
pub type Matrix3D = GenericMatrix3D<Number>;
|
pub type Matrix3D = GenericMatrix3D<Number>;
|
||||||
/// computed value of matrix3d() in -moz-transform
|
/// computed value of matrix3d() in -moz-transform
|
||||||
|
@ -141,6 +116,18 @@ impl From<Matrix3D> for Transform3D<CSSFloat> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Transform3D<CSSFloat>> for Matrix3D {
|
||||||
|
#[inline]
|
||||||
|
fn from(m: Transform3D<CSSFloat>) -> Self {
|
||||||
|
Matrix3D {
|
||||||
|
m11: m.m11, m12: m.m12, m13: m.m13, m14: m.m14,
|
||||||
|
m21: m.m21, m22: m.m22, m23: m.m23, m24: m.m24,
|
||||||
|
m31: m.m31, m32: m.m32, m33: m.m33, m34: m.m34,
|
||||||
|
m41: m.m41, m42: m.m42, m43: m.m43, m44: m.m44
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Matrix> for Transform3D<CSSFloat> {
|
impl From<Matrix> for Transform3D<CSSFloat> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(m: Matrix) -> Self {
|
fn from(m: Matrix) -> Self {
|
||||||
|
@ -152,118 +139,6 @@ impl From<Matrix> for Transform3D<CSSFloat> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TransformList {
|
|
||||||
/// Return the equivalent 3d matrix of this transform list.
|
|
||||||
/// If |reference_box| is None, we will drop the percent part from translate because
|
|
||||||
/// we can resolve it without the layout info.
|
|
||||||
pub fn to_transform_3d_matrix(&self, reference_box: Option<&Rect<Au>>)
|
|
||||||
-> Option<Transform3D<CSSFloat>> {
|
|
||||||
let mut transform = Transform3D::identity();
|
|
||||||
let list = match self.0.as_ref() {
|
|
||||||
Some(list) => list,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let extract_pixel_length = |lop: &LengthOrPercentage| {
|
|
||||||
match *lop {
|
|
||||||
LengthOrPercentage::Length(px) => px.px(),
|
|
||||||
LengthOrPercentage::Percentage(_) => 0.,
|
|
||||||
LengthOrPercentage::Calc(calc) => calc.length().px(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for operation in list {
|
|
||||||
let matrix = match *operation {
|
|
||||||
ComputedOperation::Rotate(ax, ay, az, theta) => {
|
|
||||||
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
|
||||||
let (ax, ay, az, theta) =
|
|
||||||
Self::get_normalized_vector_and_angle(ax, ay, az, theta);
|
|
||||||
Transform3D::create_rotation(ax, ay, az, theta.into())
|
|
||||||
}
|
|
||||||
ComputedOperation::Perspective(d) => {
|
|
||||||
Self::create_perspective_matrix(d.px())
|
|
||||||
}
|
|
||||||
ComputedOperation::Scale(sx, sy, sz) => {
|
|
||||||
Transform3D::create_scale(sx, sy, sz)
|
|
||||||
}
|
|
||||||
ComputedOperation::Translate(tx, ty, tz) => {
|
|
||||||
let (tx, ty) = match reference_box {
|
|
||||||
Some(relative_border_box) => {
|
|
||||||
(tx.to_pixel_length(relative_border_box.size.width).px(),
|
|
||||||
ty.to_pixel_length(relative_border_box.size.height).px())
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
// If we don't have reference box, we cannot resolve the used value,
|
|
||||||
// so only retrieve the length part. This will be used for computing
|
|
||||||
// distance without any layout info.
|
|
||||||
(extract_pixel_length(&tx), extract_pixel_length(&ty))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let tz = tz.px();
|
|
||||||
Transform3D::create_translation(tx, ty, tz)
|
|
||||||
}
|
|
||||||
ComputedOperation::Matrix(m) => {
|
|
||||||
m.into()
|
|
||||||
}
|
|
||||||
ComputedOperation::MatrixWithPercents(_) => {
|
|
||||||
// `-moz-transform` is not implemented in Servo yet.
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
ComputedOperation::Skew(theta_x, theta_y) => {
|
|
||||||
Transform3D::create_skew(theta_x.into(), theta_y.into())
|
|
||||||
}
|
|
||||||
ComputedOperation::InterpolateMatrix { .. } |
|
|
||||||
ComputedOperation::AccumulateMatrix { .. } => {
|
|
||||||
// TODO: Convert InterpolateMatrix/AccmulateMatrix into a valid Transform3D by
|
|
||||||
// the reference box and do interpolation on these two Transform3D matrices.
|
|
||||||
// Both Gecko and Servo don't support this for computing distance, and Servo
|
|
||||||
// doesn't support animations on InterpolateMatrix/AccumulateMatrix, so
|
|
||||||
// return None.
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
transform = transform.pre_mul(&matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(transform)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the transform matrix from a perspective length.
|
|
||||||
#[inline]
|
|
||||||
pub fn create_perspective_matrix(d: CSSFloat) -> Transform3D<f32> {
|
|
||||||
// TODO(gw): The transforms spec says that perspective length must
|
|
||||||
// be positive. However, there is some confusion between the spec
|
|
||||||
// and browser implementations as to handling the case of 0 for the
|
|
||||||
// perspective value. Until the spec bug is resolved, at least ensure
|
|
||||||
// that a provided perspective value of <= 0.0 doesn't cause panics
|
|
||||||
// and behaves as it does in other browsers.
|
|
||||||
// See https://lists.w3.org/Archives/Public/www-style/2016Jan/0020.html for more details.
|
|
||||||
if d <= 0.0 {
|
|
||||||
Transform3D::identity()
|
|
||||||
} else {
|
|
||||||
Transform3D::create_perspective(d)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the normalized direction vector and its angle for Rotate3D.
|
|
||||||
pub fn get_normalized_vector_and_angle(x: f32, y: f32, z: f32, angle: Angle)
|
|
||||||
-> (f32, f32, f32, Angle) {
|
|
||||||
use euclid::approxeq::ApproxEq;
|
|
||||||
use euclid::num::Zero;
|
|
||||||
let vector = DirectionVector::new(x, y, z);
|
|
||||||
if vector.square_length().approx_eq(&f32::zero()) {
|
|
||||||
// https://www.w3.org/TR/css-transforms-1/#funcdef-rotate3d
|
|
||||||
// A direction vector that cannot be normalized, such as [0, 0, 0], will cause the
|
|
||||||
// rotation to not be applied, so we use identity matrix (i.e. rotate3d(0, 0, 1, 0)).
|
|
||||||
(0., 0., 1., Angle::zero())
|
|
||||||
} else {
|
|
||||||
let vector = vector.normalize();
|
|
||||||
(vector.x, vector.y, vector.z, angle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Build an equivalent 'identity transform function list' based
|
/// Build an equivalent 'identity transform function list' based
|
||||||
/// on an existing transform list.
|
/// on an existing transform list.
|
||||||
/// http://dev.w3.org/csswg/css-transforms/#none-transform-animation
|
/// http://dev.w3.org/csswg/css-transforms/#none-transform-animation
|
||||||
|
@ -345,7 +220,7 @@ impl ToAnimatedZero for TransformOperation {
|
||||||
Ok(GenericTransformOperation::ScaleZ(1.0))
|
Ok(GenericTransformOperation::ScaleZ(1.0))
|
||||||
},
|
},
|
||||||
GenericTransformOperation::Rotate3D(x, y, z, a) => {
|
GenericTransformOperation::Rotate3D(x, y, z, a) => {
|
||||||
let (x, y, z, _) = TransformList::get_normalized_vector_and_angle(x, y, z, a);
|
let (x, y, z, _) = Transform::get_normalized_vector_and_angle(x, y, z, a);
|
||||||
Ok(GenericTransformOperation::Rotate3D(x, y, z, Angle::zero()))
|
Ok(GenericTransformOperation::Rotate3D(x, y, z, Angle::zero()))
|
||||||
},
|
},
|
||||||
GenericTransformOperation::RotateX(_) => {
|
GenericTransformOperation::RotateX(_) => {
|
||||||
|
@ -377,6 +252,16 @@ impl ToAnimatedZero for TransformOperation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl ToAnimatedZero for Transform {
|
||||||
|
#[inline]
|
||||||
|
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||||
|
Ok(GenericTransform(
|
||||||
|
self.0.iter().map(|op| op.to_animated_zero()).collect::<Result<Vec<_>, _>>()?
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Transform {
|
impl Transform {
|
||||||
/// Return the equivalent 3d matrix of this transform list.
|
/// Return the equivalent 3d matrix of this transform list.
|
||||||
/// If |reference_box| is None, we will drop the percent part from translate because
|
/// If |reference_box| is None, we will drop the percent part from translate because
|
||||||
|
@ -567,4 +452,3 @@ impl Transform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,7 @@ pub struct Matrix<T, U = T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[derive(Clone, Copy, Debug, ToComputedValue, PartialEq)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
pub struct Matrix3D<T, U = T, V = T> {
|
pub struct Matrix3D<T, U = T, V = T> {
|
||||||
pub m11: T, pub m12: T, pub m13: T, pub m14: T,
|
pub m11: T, pub m12: T, pub m13: T, pub m14: T,
|
||||||
pub m21: T, pub m22: T, pub m23: T, pub m24: T,
|
pub m21: T, pub m22: T, pub m23: T, pub m24: T,
|
||||||
|
@ -149,9 +147,7 @@ impl TimingKeyword {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
#[derive(ToComputedValue)]
|
#[derive(ToComputedValue)]
|
||||||
/// A single operation in the list of a `transform` value
|
/// A single operation in the list of a `transform` value
|
||||||
pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrNumber, LengthOrPercentage, LoPoNumber> {
|
pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrNumber, LengthOrPercentage, LoPoNumber> {
|
||||||
|
@ -247,9 +243,7 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrNumber, Leng
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Animate, ToComputedValue)]
|
#[derive(Animate, ToComputedValue)]
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
/// A value of the `transform` property
|
/// A value of the `transform` property
|
||||||
pub struct Transform<T>(pub Vec<T>);
|
pub struct Transform<T>(pub Vec<T>);
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ impl Transform {
|
||||||
Ok(GenericTransform(Space::parse(input, |input| {
|
Ok(GenericTransform(Space::parse(input, |input| {
|
||||||
let function = input.expect_function()?.clone();
|
let function = input.expect_function()?.clone();
|
||||||
input.parse_nested_block(|input| {
|
input.parse_nested_block(|input| {
|
||||||
|
let location = input.current_source_location();
|
||||||
let result = match_ignore_ascii_case! { &function,
|
let result = match_ignore_ascii_case! { &function,
|
||||||
"matrix" => {
|
"matrix" => {
|
||||||
let a = specified::parse_number(context, input)?;
|
let a = specified::parse_number(context, input)?;
|
||||||
|
@ -236,7 +237,7 @@ impl Transform {
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
};
|
};
|
||||||
result
|
result
|
||||||
.map_err(|()| StyleParseError::UnexpectedFunction(function.clone()).into())
|
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function.clone())))
|
||||||
})
|
})
|
||||||
})?))
|
})?))
|
||||||
}
|
}
|
||||||
|
|
|
@ -716,13 +716,12 @@ pub extern "C" fn Servo_AnimationValue_GetTransform(
|
||||||
let value = AnimationValue::as_arc(&value);
|
let value = AnimationValue::as_arc(&value);
|
||||||
if let AnimationValue::Transform(ref servo_list) = **value {
|
if let AnimationValue::Transform(ref servo_list) = **value {
|
||||||
let list = unsafe { &mut *list };
|
let list = unsafe { &mut *list };
|
||||||
match servo_list.0 {
|
if servo_list.0.is_empty() {
|
||||||
Some(ref servo_list) => {
|
unsafe {
|
||||||
style_structs::Box::convert_transform(servo_list, list);
|
|
||||||
},
|
|
||||||
None => unsafe {
|
|
||||||
list.set_move(RefPtr::from_addrefed(Gecko_NewNoneTransform()));
|
list.set_move(RefPtr::from_addrefed(Gecko_NewNoneTransform()));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
style_structs::Box::convert_transform(&servo_list.0, list);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic!("The AnimationValue should be transform");
|
panic!("The AnimationValue should be transform");
|
||||||
|
@ -2522,10 +2521,10 @@ pub extern "C" fn Servo_MatrixTransform_Operate(matrix_operator: MatrixTransform
|
||||||
progress: f64,
|
progress: f64,
|
||||||
output: *mut RawGeckoGfxMatrix4x4) {
|
output: *mut RawGeckoGfxMatrix4x4) {
|
||||||
use self::MatrixTransformOperator::{Accumulate, Interpolate};
|
use self::MatrixTransformOperator::{Accumulate, Interpolate};
|
||||||
use style::properties::longhands::transform::computed_value::ComputedMatrix;
|
use style::values::computed::transform::Matrix3D;
|
||||||
|
|
||||||
let from = ComputedMatrix::from(unsafe { from.as_ref() }.expect("not a valid 'from' matrix"));
|
let from = Matrix3D::from(unsafe { from.as_ref() }.expect("not a valid 'from' matrix"));
|
||||||
let to = ComputedMatrix::from(unsafe { to.as_ref() }.expect("not a valid 'to' matrix"));
|
let to = Matrix3D::from(unsafe { to.as_ref() }.expect("not a valid 'to' matrix"));
|
||||||
let result = match matrix_operator {
|
let result = match matrix_operator {
|
||||||
Interpolate => from.animate(&to, Procedure::Interpolate { progress }),
|
Interpolate => from.animate(&to, Procedure::Interpolate { progress }),
|
||||||
Accumulate => from.animate(&to, Procedure::Accumulate { count: progress as u64 }),
|
Accumulate => from.animate(&to, Procedure::Accumulate { count: progress as u64 }),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue