<http://webkit.org/b/133217>
Reviewed by Simon Fraser.
Source/WebCore:
* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::validateTransformOperations):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::getTransformFunctionValue):
- Switch to type-checked casts.
* platform/graphics/transforms/IdentityTransformOperation.h:
* platform/graphics/transforms/Matrix3DTransformOperation.h:
* platform/graphics/transforms/MatrixTransformOperation.h:
* platform/graphics/transforms/PerspectiveTransformOperation.h:
* platform/graphics/transforms/RotateTransformOperation.h:
* platform/graphics/transforms/ScaleTransformOperation.h:
* platform/graphics/transforms/SkewTransformOperation.h:
* platform/graphics/transforms/TranslateTransformOperation.h:
- Add 'final' to class declaration.
- Add 'override' to overridden methods.
- Add type-checked cast via TRANSFORMOPERATION_TYPE_CASTS macro.
- Move implementation of operator==(const TransformOperation&)
from header to source file so it is able to use a type-checked
cast, and switch back to using a reference instead of a
pointer.
- Add or update ASSERT in private constructor to check for
correct OperationType in classes that represent multiple
types.
* platform/graphics/transforms/Matrix3DTransformOperation.cpp:
(WebCore::Matrix3DTransformOperation::operator==): Added.
* platform/graphics/transforms/MatrixTransformOperation.cpp:
(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::MatrixTransformOperation::blend):
- Switch to type-checked casts and use a reference.
* platform/graphics/transforms/PerspectiveTransformOperation.cpp:
(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::PerspectiveTransformOperation::blend):
* platform/graphics/transforms/RotateTransformOperation.cpp:
(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::RotateTransformOperation::blend):
* platform/graphics/transforms/ScaleTransformOperation.cpp:
(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::ScaleTransformOperation::blend):
* platform/graphics/transforms/SkewTransformOperation.cpp:
(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::SkewTransformOperation::blend):
* platform/graphics/transforms/TranslateTransformOperation.cpp:
(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::TranslateTransformOperation::blend):
- Switch to type-checked casts.
* platform/graphics/transforms/TransformOperation.h:
(WebCore::TransformOperation::isRotateTransformOperationType):
(WebCore::TransformOperation::isScaleTransformOperationType):
(WebCore::TransformOperation::isSkewTransformOperationType):
(WebCore::TransformOperation::isTranslateTransformOperationType):
- Add type-checking methods used in constructors and type-checked
casts.
- Define TRANSFORMOPERATION_TYPE_CASTS macro used by subclasses.
Source/WebKit2:
* Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
(IPC::ArgumentCoder<TransformOperations>::encode):
- Switch to type-checked casts.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169320
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2014-05-25 David Kilzer <ddkilzer@apple.com>
+
+ Add type-checked casts for TransformOperations
+ <http://webkit.org/b/133217>
+
+ Reviewed by Simon Fraser.
+
+ * platform/graphics/GraphicsLayer.cpp:
+ (WebCore::GraphicsLayer::validateTransformOperations):
+ * platform/graphics/ca/GraphicsLayerCA.cpp:
+ (WebCore::getTransformFunctionValue):
+ - Switch to type-checked casts.
+
+ * platform/graphics/transforms/IdentityTransformOperation.h:
+ * platform/graphics/transforms/Matrix3DTransformOperation.h:
+ * platform/graphics/transforms/MatrixTransformOperation.h:
+ * platform/graphics/transforms/PerspectiveTransformOperation.h:
+ * platform/graphics/transforms/RotateTransformOperation.h:
+ * platform/graphics/transforms/ScaleTransformOperation.h:
+ * platform/graphics/transforms/SkewTransformOperation.h:
+ * platform/graphics/transforms/TranslateTransformOperation.h:
+ - Add 'final' to class declaration.
+ - Add 'override' to overridden methods.
+ - Add type-checked cast via TRANSFORMOPERATION_TYPE_CASTS macro.
+ - Move implementation of operator==(const TransformOperation&)
+ from header to source file so it is able to use a type-checked
+ cast, and switch back to using a reference instead of a
+ pointer.
+ - Add or update ASSERT in private constructor to check for
+ correct OperationType in classes that represent multiple
+ types.
+
+ * platform/graphics/transforms/Matrix3DTransformOperation.cpp:
+ (WebCore::Matrix3DTransformOperation::operator==): Added.
+
+ * platform/graphics/transforms/MatrixTransformOperation.cpp:
+ (WebCore::Matrix3DTransformOperation::operator==): Added.
+ (WebCore::MatrixTransformOperation::blend):
+ - Switch to type-checked casts and use a reference.
+
+ * platform/graphics/transforms/PerspectiveTransformOperation.cpp:
+ (WebCore::Matrix3DTransformOperation::operator==): Added.
+ (WebCore::PerspectiveTransformOperation::blend):
+ * platform/graphics/transforms/RotateTransformOperation.cpp:
+ (WebCore::Matrix3DTransformOperation::operator==): Added.
+ (WebCore::RotateTransformOperation::blend):
+ * platform/graphics/transforms/ScaleTransformOperation.cpp:
+ (WebCore::Matrix3DTransformOperation::operator==): Added.
+ (WebCore::ScaleTransformOperation::blend):
+ * platform/graphics/transforms/SkewTransformOperation.cpp:
+ (WebCore::Matrix3DTransformOperation::operator==): Added.
+ (WebCore::SkewTransformOperation::blend):
+ * platform/graphics/transforms/TranslateTransformOperation.cpp:
+ (WebCore::Matrix3DTransformOperation::operator==): Added.
+ (WebCore::TranslateTransformOperation::blend):
+ - Switch to type-checked casts.
+
+ * platform/graphics/transforms/TransformOperation.h:
+ (WebCore::TransformOperation::isRotateTransformOperationType):
+ (WebCore::TransformOperation::isScaleTransformOperationType):
+ (WebCore::TransformOperation::isSkewTransformOperationType):
+ (WebCore::TransformOperation::isTranslateTransformOperationType):
+ - Add type-checking methods used in constructors and type-checked
+ casts.
+ - Define TRANSFORMOPERATION_TYPE_CASTS macro used by subclasses.
+
2014-05-25 David Kilzer <ddkilzer@apple.com>
Crash in WebCore::TextResourceDecoder::checkForCSSCharset
type == TransformOperation::ROTATE_Y ||
type == TransformOperation::ROTATE_Z ||
type == TransformOperation::ROTATE_3D) {
- lastRotAngle = static_cast<RotateTransformOperation*>(firstVal.operations().at(j).get())->angle();
+ lastRotAngle = toRotateTransformOperation(firstVal.operations().at(j).get())->angle();
if (maxRotAngle < 0)
maxRotAngle = fabs(lastRotAngle);
for (size_t i = firstIndex + 1; i < valueList.size(); ++i) {
const TransformOperations& val = operationsAt(valueList, i);
- double rotAngle = val.operations().isEmpty() ? 0 : (static_cast<RotateTransformOperation*>(val.operations().at(j).get())->angle());
+ double rotAngle = val.operations().isEmpty() ? 0 : (toRotateTransformOperation(val.operations().at(j).get())->angle());
double diffAngle = fabs(rotAngle - lastRotAngle);
if (diffAngle > maxRotAngle)
maxRotAngle = diffAngle;
case TransformOperation::ROTATE:
case TransformOperation::ROTATE_X:
case TransformOperation::ROTATE_Y:
- value = transformOp ? narrowPrecisionToFloat(deg2rad(static_cast<const RotateTransformOperation*>(transformOp)->angle())) : 0;
+ value = transformOp ? narrowPrecisionToFloat(deg2rad(toRotateTransformOperation(transformOp)->angle())) : 0;
break;
case TransformOperation::SCALE_X:
- value = transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->x()) : 1;
+ value = transformOp ? narrowPrecisionToFloat(toScaleTransformOperation(transformOp)->x()) : 1;
break;
case TransformOperation::SCALE_Y:
- value = transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->y()) : 1;
+ value = transformOp ? narrowPrecisionToFloat(toScaleTransformOperation(transformOp)->y()) : 1;
break;
case TransformOperation::SCALE_Z:
- value = transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->z()) : 1;
+ value = transformOp ? narrowPrecisionToFloat(toScaleTransformOperation(transformOp)->z()) : 1;
break;
case TransformOperation::TRANSLATE_X:
- value = transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->x(size)) : 0;
+ value = transformOp ? narrowPrecisionToFloat(toTranslateTransformOperation(transformOp)->x(size)) : 0;
break;
case TransformOperation::TRANSLATE_Y:
- value = transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->y(size)) : 0;
+ value = transformOp ? narrowPrecisionToFloat(toTranslateTransformOperation(transformOp)->y(size)) : 0;
break;
case TransformOperation::TRANSLATE_Z:
- value = transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->z(size)) : 0;
+ value = transformOp ? narrowPrecisionToFloat(toTranslateTransformOperation(transformOp)->z(size)) : 0;
break;
default:
break;
{
switch (transformType) {
case TransformOperation::SCALE:
- case TransformOperation::SCALE_3D:
- value.setX(transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->x()) : 1);
- value.setY(transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->y()) : 1);
- value.setZ(transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->z()) : 1);
+ case TransformOperation::SCALE_3D: {
+ const ScaleTransformOperation* scaleTransformOp = toScaleTransformOperation(transformOp);
+ value.setX(scaleTransformOp ? narrowPrecisionToFloat(scaleTransformOp->x()) : 1);
+ value.setY(scaleTransformOp ? narrowPrecisionToFloat(scaleTransformOp->y()) : 1);
+ value.setZ(scaleTransformOp ? narrowPrecisionToFloat(scaleTransformOp->z()) : 1);
break;
+ }
case TransformOperation::TRANSLATE:
- case TransformOperation::TRANSLATE_3D:
- value.setX(transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->x(size)) : 0);
- value.setY(transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->y(size)) : 0);
- value.setZ(transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->z(size)) : 0);
+ case TransformOperation::TRANSLATE_3D: {
+ const TranslateTransformOperation* translateTransformOp = toTranslateTransformOperation(transformOp);
+ value.setX(translateTransformOp ? narrowPrecisionToFloat(translateTransformOp->x(size)) : 0);
+ value.setY(translateTransformOp ? narrowPrecisionToFloat(translateTransformOp->y(size)) : 0);
+ value.setZ(translateTransformOp ? narrowPrecisionToFloat(translateTransformOp->z(size)) : 0);
break;
+ }
default:
break;
}
namespace WebCore {
-class IdentityTransformOperation : public TransformOperation {
+class IdentityTransformOperation final : public TransformOperation {
public:
static PassRefPtr<IdentityTransformOperation> create()
{
}
private:
- virtual bool isIdentity() const { return true; }
- virtual OperationType type() const { return IDENTITY; }
- virtual bool isSameType(const TransformOperation& o) const { return o.type() == IDENTITY; }
+ virtual bool isIdentity() const override { return true; }
+ virtual OperationType type() const override { return IDENTITY; }
+ virtual bool isSameType(const TransformOperation& o) const override { return o.type() == IDENTITY; }
- virtual bool operator==(const TransformOperation& o) const
+ virtual bool operator==(const TransformOperation& o) const override
{
return isSameType(o);
}
- virtual bool apply(TransformationMatrix&, const FloatSize&) const
+ virtual bool apply(TransformationMatrix&, const FloatSize&) const override
{
return false;
}
- virtual PassRefPtr<TransformOperation> blend(const TransformOperation*, double, bool = false)
+ virtual PassRefPtr<TransformOperation> blend(const TransformOperation*, double, bool = false) override
{
return this;
}
};
+TRANSFORMOPERATION_TYPE_CASTS(IdentityTransformOperation, type() == TransformOperation::IDENTITY);
+
} // namespace WebCore
#endif // IdentityTransformOperation_h
namespace WebCore {
+bool Matrix3DTransformOperation::operator==(const TransformOperation& o) const
+{
+ if (!isSameType(o))
+ return false;
+ const Matrix3DTransformOperation& m = toMatrix3DTransformOperation(o);
+ return m_matrix == m.m_matrix;
+}
+
PassRefPtr<TransformOperation> Matrix3DTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
namespace WebCore {
-class Matrix3DTransformOperation : public TransformOperation {
+class Matrix3DTransformOperation final : public TransformOperation {
public:
static PassRefPtr<Matrix3DTransformOperation> create(const TransformationMatrix& matrix)
{
TransformationMatrix matrix() const {return m_matrix; }
private:
- virtual bool isIdentity() const { return m_matrix.isIdentity(); }
+ virtual bool isIdentity() const override { return m_matrix.isIdentity(); }
- virtual OperationType type() const { return MATRIX_3D; }
- virtual bool isSameType(const TransformOperation& o) const { return o.type() == MATRIX_3D; }
+ virtual OperationType type() const override { return MATRIX_3D; }
+ virtual bool isSameType(const TransformOperation& o) const override { return o.type() == MATRIX_3D; }
- virtual bool operator==(const TransformOperation& o) const
- {
- if (!isSameType(o))
- return false;
- const Matrix3DTransformOperation* m = static_cast<const Matrix3DTransformOperation*>(&o);
- return m_matrix == m->m_matrix;
- }
+ virtual bool operator==(const TransformOperation&) const override;
- virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
+ virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
{
transform.multiply(TransformationMatrix(m_matrix));
return false;
}
- virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
+ virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
Matrix3DTransformOperation(const TransformationMatrix& mat)
{
TransformationMatrix m_matrix;
};
+TRANSFORMOPERATION_TYPE_CASTS(Matrix3DTransformOperation, type() == TransformOperation::MATRIX_3D);
+
} // namespace WebCore
#endif // Matrix3DTransformOperation_h
namespace WebCore {
+bool MatrixTransformOperation::operator==(const TransformOperation& o) const
+{
+ if (!isSameType(o))
+ return false;
+ const MatrixTransformOperation& m = toMatrixTransformOperation(o);
+ return m_a == m.m_a && m_b == m.m_b && m_c == m.m_c && m_d == m.m_d && m_e == m.m_e && m_f == m.m_f;
+}
+
PassRefPtr<TransformOperation> MatrixTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
TransformationMatrix fromT;
TransformationMatrix toT(m_a, m_b, m_c, m_d, m_e, m_f);
if (from) {
- const MatrixTransformOperation* m = static_cast<const MatrixTransformOperation*>(from);
- fromT.setMatrix(m->m_a, m->m_b, m->m_c, m->m_d, m->m_e, m->m_f);
+ const MatrixTransformOperation& m = toMatrixTransformOperation(*from);
+ fromT.setMatrix(m.m_a, m.m_b, m.m_c, m.m_d, m.m_e, m.m_f);
}
if (blendToIdentity)
namespace WebCore {
-class MatrixTransformOperation : public TransformOperation {
+class MatrixTransformOperation final : public TransformOperation {
public:
static PassRefPtr<MatrixTransformOperation> create(double a, double b, double c, double d, double e, double f)
{
TransformationMatrix matrix() const { return TransformationMatrix(m_a, m_b, m_c, m_d, m_e, m_f); }
private:
- virtual bool isIdentity() const { return m_a == 1 && m_b == 0 && m_c == 0 && m_d == 1 && m_e == 0 && m_f == 0; }
+ virtual bool isIdentity() const override { return m_a == 1 && m_b == 0 && m_c == 0 && m_d == 1 && m_e == 0 && m_f == 0; }
- virtual OperationType type() const { return MATRIX; }
- virtual bool isSameType(const TransformOperation& o) const { return o.type() == MATRIX; }
+ virtual OperationType type() const override { return MATRIX; }
+ virtual bool isSameType(const TransformOperation& o) const override { return o.type() == MATRIX; }
- virtual bool operator==(const TransformOperation& o) const
- {
- if (!isSameType(o))
- return false;
-
- const MatrixTransformOperation* m = static_cast<const MatrixTransformOperation*>(&o);
- return m_a == m->m_a && m_b == m->m_b && m_c == m->m_c && m_d == m->m_d && m_e == m->m_e && m_f == m->m_f;
- }
+ virtual bool operator==(const TransformOperation&) const override;
- virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
+ virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
{
TransformationMatrix matrix(m_a, m_b, m_c, m_d, m_e, m_f);
transform.multiply(matrix);
return false;
}
- virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
+ virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
MatrixTransformOperation(double a, double b, double c, double d, double e, double f)
: m_a(a)
double m_f;
};
+TRANSFORMOPERATION_TYPE_CASTS(MatrixTransformOperation, type() == TransformOperation::MATRIX);
+
} // namespace WebCore
#endif // MatrixTransformOperation_h
namespace WebCore {
+bool PerspectiveTransformOperation::operator==(const TransformOperation& o) const
+{
+ if (!isSameType(o))
+ return false;
+ const PerspectiveTransformOperation& p = toPerspectiveTransformOperation(o);
+ return m_p == p.m_p;
+}
+
PassRefPtr<TransformOperation> PerspectiveTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
return PerspectiveTransformOperation::create(Length(clampToPositiveInteger(p), Fixed));
}
- const PerspectiveTransformOperation* fromOp = static_cast<const PerspectiveTransformOperation*>(from);
+ const PerspectiveTransformOperation* fromOp = toPerspectiveTransformOperation(from);
Length fromP = fromOp ? fromOp->m_p : Length(m_p.type());
Length toP = m_p;
namespace WebCore {
-class PerspectiveTransformOperation : public TransformOperation {
+class PerspectiveTransformOperation final : public TransformOperation {
public:
static PassRefPtr<PerspectiveTransformOperation> create(const Length& p)
{
Length perspective() const { return m_p; }
private:
- virtual bool isIdentity() const { return !floatValueForLength(m_p, 1); }
- virtual OperationType type() const { return PERSPECTIVE; }
- virtual bool isSameType(const TransformOperation& o) const { return o.type() == PERSPECTIVE; }
+ virtual bool isIdentity() const override { return !floatValueForLength(m_p, 1); }
+ virtual OperationType type() const override { return PERSPECTIVE; }
+ virtual bool isSameType(const TransformOperation& o) const override { return o.type() == PERSPECTIVE; }
- virtual bool operator==(const TransformOperation& o) const
- {
- if (!isSameType(o))
- return false;
- const PerspectiveTransformOperation* p = static_cast<const PerspectiveTransformOperation*>(&o);
- return m_p == p->m_p;
- }
+ virtual bool operator==(const TransformOperation&) const override;
- virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
+ virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
{
transform.applyPerspective(floatValueForLength(m_p, 1));
return false;
}
- virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
+ virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
PerspectiveTransformOperation(const Length& p)
: m_p(p)
Length m_p;
};
+TRANSFORMOPERATION_TYPE_CASTS(PerspectiveTransformOperation, type() == TransformOperation::PERSPECTIVE);
+
} // namespace WebCore
#endif // PerspectiveTransformOperation_h
namespace WebCore {
+bool RotateTransformOperation::operator==(const TransformOperation& o) const
+{
+ if (!isSameType(o))
+ return false;
+ const RotateTransformOperation& r = toRotateTransformOperation(o);
+ return m_x == r.m_x && m_y == r.m_y && m_z == r.m_z && m_angle == r.m_angle;
+}
+
PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
if (blendToIdentity)
return RotateTransformOperation::create(m_x, m_y, m_z, m_angle - m_angle * progress, m_type);
- const RotateTransformOperation* fromOp = static_cast<const RotateTransformOperation*>(from);
+ const RotateTransformOperation* fromOp = toRotateTransformOperation(from);
// Optimize for single axis rotation
if (!fromOp || (fromOp->m_x == 0 && fromOp->m_y == 0 && fromOp->m_z == 1) ||
namespace WebCore {
-class RotateTransformOperation : public TransformOperation {
+class RotateTransformOperation final : public TransformOperation {
public:
static PassRefPtr<RotateTransformOperation> create(double angle, OperationType type)
{
double angle() const { return m_angle; }
private:
- virtual bool isIdentity() const { return m_angle == 0; }
+ virtual bool isIdentity() const override { return m_angle == 0; }
- virtual OperationType type() const { return m_type; }
- virtual bool isSameType(const TransformOperation& o) const { return o.type() == m_type; }
+ virtual OperationType type() const override { return m_type; }
+ virtual bool isSameType(const TransformOperation& o) const override { return o.type() == m_type; }
- virtual bool operator==(const TransformOperation& o) const
- {
- if (!isSameType(o))
- return false;
- const RotateTransformOperation* r = static_cast<const RotateTransformOperation*>(&o);
- return m_x == r->m_x && m_y == r->m_y && m_z == r->m_z && m_angle == r->m_angle;
- }
+ virtual bool operator==(const TransformOperation&) const override;
- virtual bool apply(TransformationMatrix& transform, const FloatSize& /*borderBoxSize*/) const
+ virtual bool apply(TransformationMatrix& transform, const FloatSize& /*borderBoxSize*/) const override
{
transform.rotate3d(m_x, m_y, m_z, m_angle);
return false;
}
- virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
+ virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
RotateTransformOperation(double x, double y, double z, double angle, OperationType type)
: m_x(x)
, m_angle(angle)
, m_type(type)
{
- ASSERT(type == ROTATE_X || type == ROTATE_Y || type == ROTATE_Z || type == ROTATE_3D);
+ ASSERT(isRotateTransformOperationType());
}
double m_x;
OperationType m_type;
};
+TRANSFORMOPERATION_TYPE_CASTS(RotateTransformOperation, isRotateTransformOperationType());
+
} // namespace WebCore
#endif // RotateTransformOperation_h
namespace WebCore {
+bool ScaleTransformOperation::operator==(const TransformOperation& o) const
+{
+ if (!isSameType(o))
+ return false;
+ const ScaleTransformOperation& s = toScaleTransformOperation(o);
+ return m_x == s.m_x && m_y == s.m_y && m_z == s.m_z;
+}
+
PassRefPtr<TransformOperation> ScaleTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
WebCore::blend(m_y, 1.0, progress),
WebCore::blend(m_z, 1.0, progress), m_type);
- const ScaleTransformOperation* fromOp = static_cast<const ScaleTransformOperation*>(from);
+ const ScaleTransformOperation* fromOp = toScaleTransformOperation(from);
double fromX = fromOp ? fromOp->m_x : 1.0;
double fromY = fromOp ? fromOp->m_y : 1.0;
double fromZ = fromOp ? fromOp->m_z : 1.0;
namespace WebCore {
-class ScaleTransformOperation : public TransformOperation {
+class ScaleTransformOperation final : public TransformOperation {
public:
static PassRefPtr<ScaleTransformOperation> create(double sx, double sy, OperationType type)
{
double z() const { return m_z; }
private:
- virtual bool isIdentity() const { return m_x == 1 && m_y == 1 && m_z == 1; }
+ virtual bool isIdentity() const override { return m_x == 1 && m_y == 1 && m_z == 1; }
- virtual OperationType type() const { return m_type; }
- virtual bool isSameType(const TransformOperation& o) const { return o.type() == m_type; }
+ virtual OperationType type() const override { return m_type; }
+ virtual bool isSameType(const TransformOperation& o) const override { return o.type() == m_type; }
- virtual bool operator==(const TransformOperation& o) const
- {
- if (!isSameType(o))
- return false;
- const ScaleTransformOperation* s = static_cast<const ScaleTransformOperation*>(&o);
- return m_x == s->m_x && m_y == s->m_y && m_z == s->m_z;
- }
+ virtual bool operator==(const TransformOperation&) const override;
- virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
+ virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
{
transform.scale3d(m_x, m_y, m_z);
return false;
}
- virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
+ virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
ScaleTransformOperation(double sx, double sy, double sz, OperationType type)
: m_x(sx)
, m_z(sz)
, m_type(type)
{
- ASSERT(type == SCALE_X || type == SCALE_Y || type == SCALE_Z || type == SCALE || type == SCALE_3D);
+ ASSERT(isScaleTransformOperationType());
}
double m_x;
OperationType m_type;
};
+TRANSFORMOPERATION_TYPE_CASTS(ScaleTransformOperation, isScaleTransformOperationType());
+
} // namespace WebCore
#endif // ScaleTransformOperation_h
namespace WebCore {
+bool SkewTransformOperation::operator==(const TransformOperation& o) const
+{
+ if (!isSameType(o))
+ return false;
+ const SkewTransformOperation& s = toSkewTransformOperation(o);
+ return m_angleX == s.m_angleX && m_angleY == s.m_angleY;
+}
+
PassRefPtr<TransformOperation> SkewTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
if (blendToIdentity)
return SkewTransformOperation::create(WebCore::blend(m_angleX, 0.0, progress), WebCore::blend(m_angleY, 0.0, progress), m_type);
- const SkewTransformOperation* fromOp = static_cast<const SkewTransformOperation*>(from);
+ const SkewTransformOperation* fromOp = toSkewTransformOperation(from);
double fromAngleX = fromOp ? fromOp->m_angleX : 0;
double fromAngleY = fromOp ? fromOp->m_angleY : 0;
return SkewTransformOperation::create(WebCore::blend(fromAngleX, m_angleX, progress), WebCore::blend(fromAngleY, m_angleY, progress), m_type);
namespace WebCore {
-class SkewTransformOperation : public TransformOperation {
+class SkewTransformOperation final : public TransformOperation {
public:
static PassRefPtr<SkewTransformOperation> create(double angleX, double angleY, OperationType type)
{
double angleY() const { return m_angleY; }
private:
- virtual bool isIdentity() const { return m_angleX == 0 && m_angleY == 0; }
- virtual OperationType type() const { return m_type; }
- virtual bool isSameType(const TransformOperation& o) const { return o.type() == m_type; }
+ virtual bool isIdentity() const override { return m_angleX == 0 && m_angleY == 0; }
+ virtual OperationType type() const override { return m_type; }
+ virtual bool isSameType(const TransformOperation& o) const override { return o.type() == m_type; }
- virtual bool operator==(const TransformOperation& o) const
- {
- if (!isSameType(o))
- return false;
- const SkewTransformOperation* s = static_cast<const SkewTransformOperation*>(&o);
- return m_angleX == s->m_angleX && m_angleY == s->m_angleY;
- }
+ virtual bool operator==(const TransformOperation&) const override;
- virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
+ virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
{
transform.skew(m_angleX, m_angleY);
return false;
}
- virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
+ virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
SkewTransformOperation(double angleX, double angleY, OperationType type)
: m_angleX(angleX)
, m_angleY(angleY)
, m_type(type)
{
+ ASSERT(isSkewTransformOperationType());
}
double m_angleX;
OperationType m_type;
};
+TRANSFORMOPERATION_TYPE_CASTS(SkewTransformOperation, isSkewTransformOperationType());
+
} // namespace WebCore
#endif // SkewTransformOperation_h
opType == MATRIX_3D ||
opType == PERSPECTIVE;
}
+
+ bool isRotateTransformOperationType() const
+ {
+ return type() == ROTATE_X || type() == ROTATE_Y || type() == ROTATE_Z || type() == ROTATE || type() == ROTATE_3D;
+ }
+
+ bool isScaleTransformOperationType() const
+ {
+ return type() == SCALE_X || type() == SCALE_Y || type() == SCALE_Z || type() == SCALE || type() == SCALE_3D;
+ }
+
+ bool isSkewTransformOperationType() const
+ {
+ return type() == SKEW_X || type() == SKEW_Y || type() == SKEW;
+ }
+
+ bool isTranslateTransformOperationType() const
+ {
+ return type() == TRANSLATE_X || type() == TRANSLATE_Y || type() == TRANSLATE_Z || type() == TRANSLATE || type() == TRANSLATE_3D;
+ }
};
+#define TRANSFORMOPERATION_TYPE_CASTS(ToValueTypeName, predicate) \
+ TYPE_CASTS_BASE(ToValueTypeName, WebCore::TransformOperation, value, value->predicate, value.predicate)
+
} // namespace WebCore
#endif // TransformOperation_h
namespace WebCore {
+bool TranslateTransformOperation::operator==(const TransformOperation& o) const
+{
+ if (!isSameType(o))
+ return false;
+ const TranslateTransformOperation& t = toTranslateTransformOperation(o);
+ return m_x == t.m_x && m_y == t.m_y && m_z == t.m_z;
+}
+
PassRefPtr<TransformOperation> TranslateTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
if (blendToIdentity)
return TranslateTransformOperation::create(zeroLength.blend(m_x, progress), zeroLength.blend(m_y, progress), zeroLength.blend(m_z, progress), m_type);
- const TranslateTransformOperation* fromOp = static_cast<const TranslateTransformOperation*>(from);
+ const TranslateTransformOperation* fromOp = toTranslateTransformOperation(from);
Length fromX = fromOp ? fromOp->m_x : zeroLength;
Length fromY = fromOp ? fromOp->m_y : zeroLength;
Length fromZ = fromOp ? fromOp->m_z : zeroLength;
namespace WebCore {
-class TranslateTransformOperation : public TransformOperation {
+class TranslateTransformOperation final : public TransformOperation {
public:
static PassRefPtr<TranslateTransformOperation> create(const Length& tx, const Length& ty, OperationType type)
{
Length z() const { return m_z; }
private:
- virtual bool isIdentity() const { return !floatValueForLength(m_x, 1) && !floatValueForLength(m_y, 1) && !floatValueForLength(m_z, 1); }
+ virtual bool isIdentity() const override { return !floatValueForLength(m_x, 1) && !floatValueForLength(m_y, 1) && !floatValueForLength(m_z, 1); }
- virtual OperationType type() const { return m_type; }
- virtual bool isSameType(const TransformOperation& o) const { return o.type() == m_type; }
+ virtual OperationType type() const override { return m_type; }
+ virtual bool isSameType(const TransformOperation& o) const override { return o.type() == m_type; }
- virtual bool operator==(const TransformOperation& o) const
- {
- if (!isSameType(o))
- return false;
- const TranslateTransformOperation* t = static_cast<const TranslateTransformOperation*>(&o);
- return m_x == t->m_x && m_y == t->m_y && m_z == t->m_z;
- }
+ virtual bool operator==(const TransformOperation&) const override;
- virtual bool apply(TransformationMatrix& transform, const FloatSize& borderBoxSize) const
+ virtual bool apply(TransformationMatrix& transform, const FloatSize& borderBoxSize) const override
{
transform.translate3d(x(borderBoxSize), y(borderBoxSize), z(borderBoxSize));
return m_x.isPercentNotCalculated() || m_y.isPercentNotCalculated();
}
- virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
+ virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
TranslateTransformOperation(const Length& tx, const Length& ty, const Length& tz, OperationType type)
: m_x(tx)
, m_z(tz)
, m_type(type)
{
- ASSERT(type == TRANSLATE_X || type == TRANSLATE_Y || type == TRANSLATE_Z || type == TRANSLATE || type == TRANSLATE_3D);
+ ASSERT(isTranslateTransformOperationType());
}
Length m_x;
OperationType m_type;
};
+TRANSFORMOPERATION_TYPE_CASTS(TranslateTransformOperation, isTranslateTransformOperationType());
+
} // namespace WebCore
#endif // TranslateTransformOperation_h
+2014-05-25 David Kilzer <ddkilzer@apple.com>
+
+ Add type-checked casts for TransformOperations
+ <http://webkit.org/b/133217>
+
+ Reviewed by Simon Fraser.
+
+ * Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
+ (IPC::ArgumentCoder<TransformOperations>::encode):
+ - Switch to type-checked casts.
+
2014-05-25 David Kilzer <ddkilzer@apple.com>
Use type-checking FilterOperation casts in CoordinatedGraphicsArgumentCoders.cpp
case TransformOperation::SCALE:
case TransformOperation::SCALE_Z:
case TransformOperation::SCALE_3D:
- encoder << static_cast<const ScaleTransformOperation*>(operation)->x();
- encoder << static_cast<const ScaleTransformOperation*>(operation)->y();
- encoder << static_cast<const ScaleTransformOperation*>(operation)->z();
+ encoder << toScaleTransformOperation(operation)->x();
+ encoder << toScaleTransformOperation(operation)->y();
+ encoder << toScaleTransformOperation(operation)->z();
break;
case TransformOperation::TRANSLATE_X:
case TransformOperation::TRANSLATE_Y:
case TransformOperation::TRANSLATE:
case TransformOperation::TRANSLATE_Z:
case TransformOperation::TRANSLATE_3D:
- ArgumentCoder<Length>::encode(encoder, static_cast<const TranslateTransformOperation*>(operation)->x());
- ArgumentCoder<Length>::encode(encoder, static_cast<const TranslateTransformOperation*>(operation)->y());
- ArgumentCoder<Length>::encode(encoder, static_cast<const TranslateTransformOperation*>(operation)->z());
+ ArgumentCoder<Length>::encode(encoder, toTranslateTransformOperation(operation)->x());
+ ArgumentCoder<Length>::encode(encoder, toTranslateTransformOperation(operation)->y());
+ ArgumentCoder<Length>::encode(encoder, toTranslateTransformOperation(operation)->z());
break;
case TransformOperation::ROTATE:
case TransformOperation::ROTATE_X:
case TransformOperation::ROTATE_Y:
case TransformOperation::ROTATE_3D:
- encoder << static_cast<const RotateTransformOperation*>(operation)->x();
- encoder << static_cast<const RotateTransformOperation*>(operation)->y();
- encoder << static_cast<const RotateTransformOperation*>(operation)->z();
- encoder << static_cast<const RotateTransformOperation*>(operation)->angle();
+ encoder << toRotateTransformOperation(operation)->x();
+ encoder << toRotateTransformOperation(operation)->y();
+ encoder << toRotateTransformOperation(operation)->z();
+ encoder << toRotateTransformOperation(operation)->angle();
break;
case TransformOperation::SKEW_X:
case TransformOperation::SKEW_Y:
case TransformOperation::SKEW:
- encoder << static_cast<const SkewTransformOperation*>(operation)->angleX();
- encoder << static_cast<const SkewTransformOperation*>(operation)->angleY();
+ encoder << toSkewTransformOperation(operation)->angleX();
+ encoder << toSkewTransformOperation(operation)->angleY();
break;
case TransformOperation::MATRIX:
- ArgumentCoder<TransformationMatrix>::encode(encoder, static_cast<const MatrixTransformOperation*>(operation)->matrix());
+ ArgumentCoder<TransformationMatrix>::encode(encoder, toMatrixTransformOperation(operation)->matrix());
break;
case TransformOperation::MATRIX_3D:
- ArgumentCoder<TransformationMatrix>::encode(encoder, static_cast<const Matrix3DTransformOperation*>(operation)->matrix());
+ ArgumentCoder<TransformationMatrix>::encode(encoder, toMatrix3DTransformOperation(operation)->matrix());
break;
case TransformOperation::PERSPECTIVE:
- ArgumentCoder<Length>::encode(encoder, static_cast<const PerspectiveTransformOperation*>(operation)->perspective());
+ ArgumentCoder<Length>::encode(encoder, toPerspectiveTransformOperation(operation)->perspective());
break;
case TransformOperation::IDENTITY:
break;