summaryrefslogtreecommitdiff
path: root/Source/WebCore/svg/SVGMatrix.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/svg/SVGMatrix.h')
-rw-r--r--Source/WebCore/svg/SVGMatrix.h320
1 files changed, 242 insertions, 78 deletions
diff --git a/Source/WebCore/svg/SVGMatrix.h b/Source/WebCore/svg/SVGMatrix.h
index e48ae003e..14247331d 100644
--- a/Source/WebCore/svg/SVGMatrix.h
+++ b/Source/WebCore/svg/SVGMatrix.h
@@ -1,132 +1,296 @@
/*
- * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
*
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef SVGMatrix_h
-#define SVGMatrix_h
+#pragma once
-#if ENABLE(SVG)
-#include "AffineTransform.h"
-#include "SVGException.h"
+#include "ExceptionCode.h"
+#include "SVGMatrixValue.h"
+#include "SVGPropertyTearOff.h"
namespace WebCore {
-typedef int ExceptionCode;
-
-// Only used in the bindings.
-class SVGMatrix : public AffineTransform {
+class SVGMatrix : public SVGPropertyTearOff<SVGMatrixValue> {
public:
- SVGMatrix() { }
- SVGMatrix(const AffineTransform& other)
- : AffineTransform(other)
+ static Ref<SVGMatrix> create(SVGAnimatedProperty& animatedProperty, SVGPropertyRole role, SVGMatrixValue& value)
+ {
+ return adoptRef(*new SVGMatrix(animatedProperty, role, value));
+ }
+
+ static Ref<SVGMatrix> create(const SVGMatrixValue& initialValue = { })
+ {
+ return adoptRef(*new SVGMatrix(initialValue));
+ }
+
+ static Ref<SVGMatrix> create(const SVGMatrixValue* initialValue)
+ {
+ return adoptRef(*new SVGMatrix(initialValue));
+ }
+
+ template<typename T> static ExceptionOr<Ref<SVGMatrix>> create(ExceptionOr<T>&& initialValue)
+ {
+ if (initialValue.hasException())
+ return initialValue.releaseException();
+ return create(initialValue.releaseReturnValue());
+ }
+
+ double a()
+ {
+ return propertyReference().a();
+ }
+
+ ExceptionOr<void> setA(double value)
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ propertyReference().setA(value);
+ commitChange();
+
+ return { };
+ }
+
+ double b()
{
+ return propertyReference().b();
}
- SVGMatrix(double a, double b, double c, double d, double e, double f)
- : AffineTransform(a, b, c, d, e, f)
+ ExceptionOr<void> setB(double value)
{
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ propertyReference().setB(value);
+ commitChange();
+
+ return { };
}
- SVGMatrix translate(double tx, double ty)
+ double c()
{
- AffineTransform copy = *this;
- copy.translate(tx, ty);
- return static_cast<SVGMatrix>(copy);
+ return propertyReference().c();
}
- SVGMatrix scale(double s)
+ ExceptionOr<void> setC(double value)
{
- AffineTransform copy = *this;
- copy.scale(s, s);
- return static_cast<SVGMatrix>(copy);
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ propertyReference().setC(value);
+ commitChange();
+
+ return { };
}
- SVGMatrix scaleNonUniform(double sx, double sy)
+ double d()
{
- AffineTransform copy = *this;
- copy.scale(sx, sy);
- return static_cast<SVGMatrix>(copy);
+ return propertyReference().d();
}
- SVGMatrix rotate(double d)
+ ExceptionOr<void> setD(double value)
{
- AffineTransform copy = *this;
- copy.rotate(d);
- return static_cast<SVGMatrix>(copy);
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ propertyReference().setD(value);
+ commitChange();
+
+ return { };
}
- SVGMatrix flipX()
+ double e()
{
- AffineTransform copy = *this;
- copy.flipX();
- return static_cast<SVGMatrix>(copy);
+ return propertyReference().e();
}
- SVGMatrix flipY()
+ ExceptionOr<void> setE(double value)
{
- AffineTransform copy = *this;
- copy.flipY();
- return static_cast<SVGMatrix>(copy);
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ propertyReference().setE(value);
+ commitChange();
+
+ return { };
}
- SVGMatrix skewX(double angle)
+ double f()
{
- AffineTransform copy = *this;
- copy.skewX(angle);
- return static_cast<SVGMatrix>(copy);
+ return propertyReference().f();
}
- SVGMatrix skewY(double angle)
+ ExceptionOr<void> setF(double value)
{
- AffineTransform copy = *this;
- copy.skewY(angle);
- return static_cast<SVGMatrix>(copy);
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ propertyReference().setF(value);
+ commitChange();
+
+ return { };
}
- SVGMatrix multiply(const SVGMatrix& other)
+ ExceptionOr<Ref<SVGMatrix>> multiply(SVGMatrix& secondMatrix)
{
- AffineTransform copy = *this;
- copy *= static_cast<const AffineTransform&>(other);
- return static_cast<SVGMatrix>(copy);
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().multiply(secondMatrix.propertyReference());
+ commitChange();
+
+ return SVGMatrix::create(result);
+ }
+
+ ExceptionOr<Ref<SVGMatrix>> inverse()
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().inverse();
+ if (result.hasException())
+ return result.releaseException();
+
+ commitChange();
+ return SVGMatrix::create(result.releaseReturnValue());
}
- SVGMatrix inverse(ExceptionCode& ec) const
+ ExceptionOr<Ref<SVGMatrix>> translate(float x, float y)
{
- AffineTransform transform = AffineTransform::inverse();
- if (!isInvertible())
- ec = SVGException::SVG_MATRIX_NOT_INVERTABLE;
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().translate(x, y);
+ commitChange();
- return transform;
+ return SVGMatrix::create(result);
}
- SVGMatrix rotateFromVector(double x, double y, ExceptionCode& ec)
+ ExceptionOr<Ref<SVGMatrix>> scale(float scaleFactor)
{
- if (!x || !y)
- ec = SVGException::SVG_INVALID_VALUE_ERR;
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().scale(scaleFactor);
+ commitChange();
- AffineTransform copy = *this;
- copy.rotateFromVector(x, y);
- return static_cast<SVGMatrix>(copy);
+ return SVGMatrix::create(result);
}
+ ExceptionOr<Ref<SVGMatrix>> scaleNonUniform(float scaleFactorX, float scaleFactorY)
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().scaleNonUniform(scaleFactorX, scaleFactorY);
+ commitChange();
+
+ return SVGMatrix::create(result);
+ }
+
+ ExceptionOr<Ref<SVGMatrix>> rotate(float angle)
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().rotate(angle);
+ commitChange();
+
+ return SVGMatrix::create(result);
+ }
+
+ ExceptionOr<Ref<SVGMatrix>> rotateFromVector(float x, float y)
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().rotateFromVector(x, y);
+ if (result.hasException())
+ return result.releaseException();
+
+ commitChange();
+ return SVGMatrix::create(result.releaseReturnValue());
+ }
+
+ ExceptionOr<Ref<SVGMatrix>> flipX()
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().flipX();
+ commitChange();
+
+ return SVGMatrix::create(result);
+ }
+
+ ExceptionOr<Ref<SVGMatrix>> flipY()
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().flipY();
+ commitChange();
+
+ return SVGMatrix::create(result);
+ }
+
+ ExceptionOr<Ref<SVGMatrix>> skewX(float angle)
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().skewX(angle);
+ commitChange();
+
+ return SVGMatrix::create(result);
+ }
+
+ ExceptionOr<Ref<SVGMatrix>> skewY(float angle)
+ {
+ if (isReadOnly())
+ return Exception { NO_MODIFICATION_ALLOWED_ERR };
+
+ auto result = propertyReference().skewY(angle);
+ commitChange();
+
+ return SVGMatrix::create(result);
+ }
+
+protected:
+ SVGMatrix(SVGAnimatedProperty& animatedProperty, SVGPropertyRole role, SVGMatrixValue& value)
+ : SVGPropertyTearOff<SVGMatrixValue>(&animatedProperty, role, value)
+ {
+ }
+
+ explicit SVGMatrix(const SVGMatrixValue& initialValue)
+ : SVGPropertyTearOff<SVGMatrixValue>(initialValue)
+ {
+ }
+
+ explicit SVGMatrix(const SVGMatrixValue* initialValue)
+ : SVGPropertyTearOff<SVGMatrixValue>(initialValue)
+ {
+ }
};
} // namespace WebCore
-
-#endif // ENABLE(SVG)
-#endif