This source file includes following definitions.
- m_contextTransform
- value
- mutableValue
- commitChange
- translate
- scale
- scaleNonUniform
- rotate
- flipX
- flipY
- skewX
- skewY
- multiply
- inverse
- rotateFromVector
#include "config.h"
#include "core/svg/SVGMatrixTearOff.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGTransformTearOff.h"
namespace WebCore {
SVGMatrixTearOff::SVGMatrixTearOff(const AffineTransform& staticValue)
: m_staticValue(staticValue)
, m_contextTransform(0)
{
ScriptWrappable::init(this);
}
SVGMatrixTearOff::SVGMatrixTearOff(SVGTransformTearOff* transform)
: m_contextTransform(transform)
{
ASSERT(transform);
ScriptWrappable::init(this);
}
SVGMatrixTearOff::~SVGMatrixTearOff()
{
}
const AffineTransform& SVGMatrixTearOff::value() const
{
return m_contextTransform ? m_contextTransform->target()->matrix() : m_staticValue;
}
AffineTransform* SVGMatrixTearOff::mutableValue()
{
return m_contextTransform ? m_contextTransform->target()->mutableMatrix() : &m_staticValue;
}
void SVGMatrixTearOff::commitChange()
{
if (!m_contextTransform)
return;
m_contextTransform->target()->onMatrixChange();
m_contextTransform->commitChange();
}
#define DEFINE_SETTER(ATTRIBUTE) \
void SVGMatrixTearOff::set##ATTRIBUTE(double f, ExceptionState& exceptionState) \
{ \
if (m_contextTransform && m_contextTransform->isImmutable()) { \
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); \
return; \
} \
mutableValue()->set##ATTRIBUTE(f); \
commitChange(); \
}
DEFINE_SETTER(A);
DEFINE_SETTER(B);
DEFINE_SETTER(C);
DEFINE_SETTER(D);
DEFINE_SETTER(E);
DEFINE_SETTER(F);
#undef DEFINE_SETTER
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::translate(double tx, double ty)
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
matrix->mutableValue()->translate(tx, ty);
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::scale(double s)
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
matrix->mutableValue()->scale(s, s);
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::scaleNonUniform(double sx, double sy)
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
matrix->mutableValue()->scale(sx, sy);
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::rotate(double d)
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
matrix->mutableValue()->rotate(d);
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::flipX()
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
matrix->mutableValue()->flipX();
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::flipY()
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
matrix->mutableValue()->flipY();
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::skewX(double angle)
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
matrix->mutableValue()->skewX(angle);
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::skewY(double angle)
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
matrix->mutableValue()->skewY(angle);
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::multiply(PassRefPtr<SVGMatrixTearOff> other)
{
RefPtr<SVGMatrixTearOff> matrix = create(value());
*matrix->mutableValue() *= other->value();
return matrix.release();
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::inverse(ExceptionState& exceptionState)
{
AffineTransform transform = value().inverse();
if (!value().isInvertible())
exceptionState.throwDOMException(InvalidStateError, "The matrix is not invertible.");
return create(transform);
}
PassRefPtr<SVGMatrixTearOff> SVGMatrixTearOff::rotateFromVector(double x, double y, ExceptionState& exceptionState)
{
if (!x || !y)
exceptionState.throwDOMException(InvalidAccessError, "Arguments cannot be zero.");
AffineTransform copy = value();
copy.rotateFromVector(x, y);
return create(copy);
}
}