Bug 1272549 - Part 4: Compute distance for none and a valid transform list. r=birtles

Reuse AddTransformLists to get the identity transform functions to
replace none, and then treat them with another transform list as two matched
ones.

MozReview-Commit-ID: HwdBPCiUivg

--HG--
extra : rebase_source : 552ff668e2ac19dbfcfe2a37894b278f699f0c0b
This commit is contained in:
Boris Chiou 2016-10-03 17:43:20 +08:00
parent 9f7759999b
commit fe6b56e5e8
3 changed files with 59 additions and 8 deletions

View File

@ -701,6 +701,10 @@ StyleAnimationValue::ComputeColorDistance(const RGBAColorData& aStartColor,
return sqrt(diffA * diffA + diffR * diffR + diffG * diffG + diffB * diffB);
}
static nsCSSValueList*
AddTransformLists(double aCoeff1, const nsCSSValueList* aList1,
double aCoeff2, const nsCSSValueList* aList2);
static double
ComputeTransformDistance(nsCSSValue::Array* aArray1,
nsCSSValue::Array* aArray2)
@ -1239,13 +1243,11 @@ StyleAnimationValue::ComputeDistance(nsCSSPropertyID aProperty,
// Both none, nothing happens.
aDistance = 0.0;
} else if (list1->mValue.GetUnit() == eCSSUnit_None) {
// TODO: Implement none transform list in the later patch.
aDistance = 0.0;
return false;
nsAutoPtr<nsCSSValueList> none(AddTransformLists(0, list2, 0, list2));
aDistance = ComputeTransformListDistance(none, list2);
} else if (list2->mValue.GetUnit() == eCSSUnit_None) {
// TODO: Implement none transform list in the later patch.
aDistance = 0.0;
return false;
nsAutoPtr<nsCSSValueList> none(AddTransformLists(0, list1, 0, list1));
aDistance = ComputeTransformListDistance(list1, none);
} else {
const nsCSSValueList *item1 = list1, *item2 = list2;
do {
@ -2497,8 +2499,29 @@ AddTransformLists(double aCoeff1, const nsCSSValueList* aList1,
}
case eCSSKeyword_matrix:
case eCSSKeyword_matrix3d:
case eCSSKeyword_interpolatematrix:
case eCSSKeyword_perspective: {
case eCSSKeyword_perspective:
if (aCoeff1 == 0.0 && aCoeff2 == 0.0) {
// Special case. If both coefficients are 0.0, we should apply an
// identity transform function.
arr = StyleAnimationValue::AppendTransformFunction(tfunc, resultTail);
if (tfunc == eCSSKeyword_rotate3d) {
arr->Item(1).SetFloatValue(0.0, eCSSUnit_Number);
arr->Item(2).SetFloatValue(0.0, eCSSUnit_Number);
arr->Item(3).SetFloatValue(1.0, eCSSUnit_Number);
arr->Item(4).SetFloatValue(0.0, eCSSUnit_Radian);
} else if (tfunc == eCSSKeyword_perspective) {
// The parameter of the identity perspective function is
// positive infinite.
arr->Item(1).SetFloatValue(std::numeric_limits<float>::infinity(),
eCSSUnit_Pixel);
} else {
nsStyleTransformMatrix::SetIdentityMatrix(arr);
}
break;
}
MOZ_FALLTHROUGH;
case eCSSKeyword_interpolatematrix: {
// FIXME: If the matrix contains only numbers then we could decompose
// here.

View File

@ -685,6 +685,32 @@ TransformFunctionOf(const nsCSSValue::Array* aData)
return aData->Item(0).GetKeywordValue();
}
void
SetIdentityMatrix(nsCSSValue::Array* aMatrix)
{
MOZ_ASSERT(aMatrix, "aMatrix should be non-null");
nsCSSKeyword tfunc = TransformFunctionOf(aMatrix);
MOZ_ASSERT(tfunc == eCSSKeyword_matrix ||
tfunc == eCSSKeyword_matrix3d,
"Only accept matrix and matrix3d");
if (tfunc == eCSSKeyword_matrix) {
MOZ_ASSERT(aMatrix->Count() == 7, "Invalid matrix");
Matrix m;
for (size_t i = 0; i < 6; ++i) {
aMatrix->Item(i + 1).SetFloatValue(m.components[i], eCSSUnit_Number);
}
return;
}
MOZ_ASSERT(aMatrix->Count() == 17, "Invalid matrix3d");
Matrix4x4 m;
for (size_t i = 0; i < 16; ++i) {
aMatrix->Item(i + 1).SetFloatValue(m.components[i], eCSSUnit_Number);
}
}
Matrix4x4
ReadTransforms(const nsCSSValueList* aList,
nsStyleContext* aContext,

View File

@ -127,6 +127,8 @@ namespace nsStyleTransformMatrix {
*/
nsCSSKeyword TransformFunctionOf(const nsCSSValue::Array* aData);
void SetIdentityMatrix(nsCSSValue::Array* aMatrix);
float ProcessTranslatePart(const nsCSSValue& aValue,
nsStyleContext* aContext,
nsPresContext* aPresContext,