summaryrefslogtreecommitdiff
path: root/Source/WebCore/css/WebKitCSSMatrix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/css/WebKitCSSMatrix.cpp')
-rw-r--r--Source/WebCore/css/WebKitCSSMatrix.cpp151
1 files changed, 86 insertions, 65 deletions
diff --git a/Source/WebCore/css/WebKitCSSMatrix.cpp b/Source/WebCore/css/WebKitCSSMatrix.cpp
index 4f53657f8..1cb766688 100644
--- a/Source/WebCore/css/WebKitCSSMatrix.cpp
+++ b/Source/WebCore/css/WebKitCSSMatrix.cpp
@@ -27,7 +27,9 @@
#include "WebKitCSSMatrix.h"
#include "CSSParser.h"
+#include "CSSPrimitiveValue.h"
#include "CSSPropertyNames.h"
+#include "CSSToLengthConversionData.h"
#include "CSSValueKeywords.h"
#include "ExceptionCode.h"
#include "StyleProperties.h"
@@ -36,77 +38,79 @@
namespace WebCore {
-WebKitCSSMatrix::WebKitCSSMatrix(const TransformationMatrix& m)
- : m_matrix(m)
+inline WebKitCSSMatrix::WebKitCSSMatrix(const TransformationMatrix& matrix)
+ : m_matrix(matrix)
{
}
-WebKitCSSMatrix::WebKitCSSMatrix(const String& s, ExceptionCode& ec)
+Ref<WebKitCSSMatrix> WebKitCSSMatrix::create(const TransformationMatrix& matrix)
{
- setMatrixValue(s, ec);
+ return adoptRef(*new WebKitCSSMatrix(matrix));
+}
+
+ExceptionOr<Ref<WebKitCSSMatrix>> WebKitCSSMatrix::create(const String& string)
+{
+ auto result = adoptRef(*new WebKitCSSMatrix);
+ auto setMatrixValueResult = result->setMatrixValue(string);
+ if (setMatrixValueResult.hasException())
+ return setMatrixValueResult.releaseException();
+ return WTFMove(result);
}
WebKitCSSMatrix::~WebKitCSSMatrix()
{
}
-void WebKitCSSMatrix::setMatrixValue(const String& string, ExceptionCode& ec)
+ExceptionOr<void> WebKitCSSMatrix::setMatrixValue(const String& string)
{
if (string.isEmpty())
- return;
-
- RefPtr<MutableStyleProperties> styleDeclaration = MutableStyleProperties::create();
- if (CSSParser::parseValue(styleDeclaration.get(), CSSPropertyWebkitTransform, string, true, CSSStrictMode, 0)) {
- // Convert to TransformOperations. This can fail if a property
- // requires style (i.e., param uses 'ems' or 'exs')
- RefPtr<CSSValue> value = styleDeclaration->getPropertyCSSValue(CSSPropertyWebkitTransform);
-
- // Check for a "none" or empty transform. In these cases we can use the default identity matrix.
- if (!value || (value->isPrimitiveValue() && (toCSSPrimitiveValue(value.get()))->getValueID() == CSSValueNone))
- return;
-
- TransformOperations operations;
- if (!transformsForValue(0, 0, value.get(), operations)) {
- ec = SYNTAX_ERR;
- return;
- }
-
- // Convert transform operations to a TransformationMatrix. This can fail
- // if a param has a percentage ('%')
- TransformationMatrix t;
- for (unsigned i = 0; i < operations.operations().size(); ++i) {
- if (operations.operations()[i].get()->apply(t, IntSize(0, 0))) {
- ec = SYNTAX_ERR;
- return;
- }
- }
-
- // set the matrix
- m_matrix = t;
- } else // There is something there but parsing failed.
- ec = SYNTAX_ERR;
+ return { };
+
+ auto styleDeclaration = MutableStyleProperties::create();
+ if (CSSParser::parseValue(styleDeclaration, CSSPropertyTransform, string, true, HTMLStandardMode) == CSSParser::ParseResult::Error)
+ return Exception { SYNTAX_ERR };
+
+ // Convert to TransformOperations. This can fail if a property requires style (i.e., param uses 'ems' or 'exs')
+ auto value = styleDeclaration->getPropertyCSSValue(CSSPropertyTransform);
+
+ // Check for a "none" or empty transform. In these cases we can use the default identity matrix.
+ if (!value || (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).valueID() == CSSValueNone))
+ return { };
+
+ TransformOperations operations;
+ if (!transformsForValue(*value, CSSToLengthConversionData(), operations))
+ return Exception { SYNTAX_ERR };
+
+ // Convert transform operations to a TransformationMatrix. This can fail if a parameter has a percentage ('%').
+ TransformationMatrix matrix;
+ for (auto& operation : operations.operations()) {
+ if (operation->apply(matrix, IntSize(0, 0)))
+ return Exception { SYNTAX_ERR };
+ }
+ m_matrix = matrix;
+ return { };
}
// Perform a concatenation of the matrices (this * secondMatrix)
-PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::multiply(WebKitCSSMatrix* secondMatrix) const
+RefPtr<WebKitCSSMatrix> WebKitCSSMatrix::multiply(WebKitCSSMatrix* secondMatrix) const
{
if (!secondMatrix)
- return 0;
+ return nullptr;
- return WebKitCSSMatrix::create(TransformationMatrix(m_matrix).multiply(secondMatrix->m_matrix));
+ auto matrix = create(m_matrix);
+ matrix->m_matrix.multiply(secondMatrix->m_matrix);
+ return WTFMove(matrix);
}
-PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::inverse(ExceptionCode& ec) const
+ExceptionOr<Ref<WebKitCSSMatrix>> WebKitCSSMatrix::inverse() const
{
- if (!m_matrix.isInvertible()) {
- ec = NOT_SUPPORTED_ERR;
- return 0;
- }
-
- return WebKitCSSMatrix::create(m_matrix.inverse());
+ auto inverse = m_matrix.inverse();
+ if (!inverse)
+ return Exception { NOT_SUPPORTED_ERR };
+ return create(inverse.value());
}
-PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::translate(double x, double y, double z) const
+Ref<WebKitCSSMatrix> WebKitCSSMatrix::translate(double x, double y, double z) const
{
if (std::isnan(x))
x = 0;
@@ -114,10 +118,13 @@ PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::translate(double x, double y, doubl
y = 0;
if (std::isnan(z))
z = 0;
- return WebKitCSSMatrix::create(TransformationMatrix(m_matrix).translate3d(x, y, z));
+
+ auto matrix = create(m_matrix);
+ matrix->m_matrix.translate3d(x, y, z);
+ return matrix;
}
-PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::scale(double scaleX, double scaleY, double scaleZ) const
+Ref<WebKitCSSMatrix> WebKitCSSMatrix::scale(double scaleX, double scaleY, double scaleZ) const
{
if (std::isnan(scaleX))
scaleX = 1;
@@ -125,10 +132,13 @@ PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::scale(double scaleX, double scaleY,
scaleY = scaleX;
if (std::isnan(scaleZ))
scaleZ = 1;
- return WebKitCSSMatrix::create(TransformationMatrix(m_matrix).scale3d(scaleX, scaleY, scaleZ));
+
+ auto matrix = create(m_matrix);
+ matrix->m_matrix.scale3d(scaleX, scaleY, scaleZ);
+ return matrix;
}
-PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::rotate(double rotX, double rotY, double rotZ) const
+Ref<WebKitCSSMatrix> WebKitCSSMatrix::rotate(double rotX, double rotY, double rotZ) const
{
if (std::isnan(rotX))
rotX = 0;
@@ -143,10 +153,13 @@ PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::rotate(double rotX, double rotY, do
rotY = 0;
if (std::isnan(rotZ))
rotZ = 0;
- return WebKitCSSMatrix::create(TransformationMatrix(m_matrix).rotate3d(rotX, rotY, rotZ));
+
+ auto matrix = create(m_matrix);
+ matrix->m_matrix.rotate3d(rotX, rotY, rotZ);
+ return matrix;
}
-PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::rotateAxisAngle(double x, double y, double z, double angle) const
+Ref<WebKitCSSMatrix> WebKitCSSMatrix::rotateAxisAngle(double x, double y, double z, double angle) const
{
if (std::isnan(x))
x = 0;
@@ -158,34 +171,42 @@ PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::rotateAxisAngle(double x, double y,
angle = 0;
if (x == 0 && y == 0 && z == 0)
z = 1;
- return WebKitCSSMatrix::create(TransformationMatrix(m_matrix).rotate3d(x, y, z, angle));
+
+ auto matrix = create(m_matrix);
+ matrix->m_matrix.rotate3d(x, y, z, angle);
+ return matrix;
}
-PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::skewX(double angle) const
+Ref<WebKitCSSMatrix> WebKitCSSMatrix::skewX(double angle) const
{
if (std::isnan(angle))
angle = 0;
- return WebKitCSSMatrix::create(TransformationMatrix(m_matrix).skewX(angle));
+
+ auto matrix = create(m_matrix);
+ matrix->m_matrix.skewX(angle);
+ return matrix;
}
-PassRefPtr<WebKitCSSMatrix> WebKitCSSMatrix::skewY(double angle) const
+Ref<WebKitCSSMatrix> WebKitCSSMatrix::skewY(double angle) const
{
if (std::isnan(angle))
angle = 0;
- return WebKitCSSMatrix::create(TransformationMatrix(m_matrix).skewY(angle));
+
+ auto matrix = create(m_matrix);
+ matrix->m_matrix.skewY(angle);
+ return matrix;
}
String WebKitCSSMatrix::toString() const
{
// FIXME - Need to ensure valid CSS floating point values (https://bugs.webkit.org/show_bug.cgi?id=20674)
if (m_matrix.isAffine())
- return String::format("matrix(%f, %f, %f, %f, %f, %f)",
- m_matrix.a(), m_matrix.b(), m_matrix.c(), m_matrix.d(), m_matrix.e(), m_matrix.f());
+ return String::format("matrix(%f, %f, %f, %f, %f, %f)", m_matrix.a(), m_matrix.b(), m_matrix.c(), m_matrix.d(), m_matrix.e(), m_matrix.f());
return String::format("matrix3d(%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f)",
- m_matrix.m11(), m_matrix.m12(), m_matrix.m13(), m_matrix.m14(),
- m_matrix.m21(), m_matrix.m22(), m_matrix.m23(), m_matrix.m24(),
- m_matrix.m31(), m_matrix.m32(), m_matrix.m33(), m_matrix.m34(),
- m_matrix.m41(), m_matrix.m42(), m_matrix.m43(), m_matrix.m44());
+ m_matrix.m11(), m_matrix.m12(), m_matrix.m13(), m_matrix.m14(),
+ m_matrix.m21(), m_matrix.m22(), m_matrix.m23(), m_matrix.m24(),
+ m_matrix.m31(), m_matrix.m32(), m_matrix.m33(), m_matrix.m34(),
+ m_matrix.m41(), m_matrix.m42(), m_matrix.m43(), m_matrix.m44());
}
} // namespace WebCore