Bug 1241575 - Use transform property syntax to parse WebKitCSSMatrix transform list. r=heycam
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/WebKitCSSMatrixBinding.h"
|
||||
#include "nsCSSParser.h"
|
||||
#include "nsStyleTransformMatrix.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@@ -56,11 +58,58 @@ WebKitCSSMatrix*
|
||||
WebKitCSSMatrix::SetMatrixValue(const nsAString& aTransformList,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
DOMMatrix::SetMatrixValue(aTransformList, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
// An empty string is a no-op.
|
||||
if (aTransformList.IsEmpty()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
nsCSSValue value;
|
||||
nsCSSParser parser;
|
||||
bool parseSuccess = parser.ParseTransformProperty(aTransformList,
|
||||
true,
|
||||
value);
|
||||
if (!parseSuccess) {
|
||||
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// A value of "none" results in a 2D identity matrix.
|
||||
if (value.GetUnit() == eCSSUnit_None) {
|
||||
mMatrix3D = nullptr;
|
||||
mMatrix2D = new gfx::Matrix();
|
||||
return this;
|
||||
}
|
||||
|
||||
// A value other than a transform-list is a syntax error.
|
||||
if (value.GetUnit() != eCSSUnit_SharedList) {
|
||||
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RuleNodeCacheConditions dummy;
|
||||
nsStyleTransformMatrix::TransformReferenceBox dummyBox;
|
||||
bool contains3dTransform = false;
|
||||
gfx::Matrix4x4 transform = nsStyleTransformMatrix::ReadTransforms(
|
||||
value.GetSharedListValue()->mHead,
|
||||
nullptr, nullptr, dummy, dummyBox,
|
||||
nsPresContext::AppUnitsPerCSSPixel(),
|
||||
&contains3dTransform);
|
||||
|
||||
if (!contains3dTransform) {
|
||||
mMatrix3D = nullptr;
|
||||
mMatrix2D = new gfx::Matrix();
|
||||
|
||||
SetA(transform._11);
|
||||
SetB(transform._12);
|
||||
SetC(transform._21);
|
||||
SetD(transform._22);
|
||||
SetE(transform._41);
|
||||
SetF(transform._42);
|
||||
} else {
|
||||
mMatrix3D = new gfx::Matrix4x4(transform);
|
||||
mMatrix2D = nullptr;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user