#ifndef TransformState_h
#define TransformState_h
#include "platform/geometry/FloatPoint.h"
#include "platform/geometry/FloatQuad.h"
#include "platform/geometry/IntSize.h"
#include "platform/geometry/LayoutSize.h"
#include "platform/transforms/AffineTransform.h"
#include "platform/transforms/TransformationMatrix.h"
#include "wtf/OwnPtr.h"
namespace WebCore {
class PLATFORM_EXPORT TransformState {
public:
enum TransformDirection { ApplyTransformDirection, UnapplyInverseTransformDirection };
enum TransformAccumulation { FlattenTransform, AccumulateTransform };
TransformState(TransformDirection mappingDirection, const FloatPoint& p, const FloatQuad& quad)
: m_lastPlanarPoint(p)
, m_lastPlanarQuad(quad)
, m_accumulatingTransform(false)
, m_mapPoint(true)
, m_mapQuad(true)
, m_direction(mappingDirection)
{
}
TransformState(TransformDirection mappingDirection, const FloatPoint& p)
: m_lastPlanarPoint(p)
, m_accumulatingTransform(false)
, m_mapPoint(true)
, m_mapQuad(false)
, m_direction(mappingDirection)
{
}
TransformState(TransformDirection mappingDirection, const FloatQuad& quad)
: m_lastPlanarQuad(quad)
, m_accumulatingTransform(false)
, m_mapPoint(false)
, m_mapQuad(true)
, m_direction(mappingDirection)
{
}
TransformState(const TransformState& other) { *this = other; }
TransformState& operator=(const TransformState&);
void setQuad(const FloatQuad& quad)
{
ASSERT(!m_mapPoint);
m_accumulatedOffset = LayoutSize();
m_lastPlanarQuad = quad;
}
void move(LayoutUnit x, LayoutUnit y, TransformAccumulation accumulate = FlattenTransform)
{
move(LayoutSize(x, y), accumulate);
}
void move(const LayoutSize&, TransformAccumulation = FlattenTransform);
void applyTransform(const AffineTransform& transformFromContainer, TransformAccumulation = FlattenTransform, bool* wasClamped = 0);
void applyTransform(const TransformationMatrix& transformFromContainer, TransformAccumulation = FlattenTransform, bool* wasClamped = 0);
void flatten(bool* wasClamped = 0);
FloatPoint lastPlanarPoint() const { return m_lastPlanarPoint; }
FloatQuad lastPlanarQuad() const { return m_lastPlanarQuad; }
FloatPoint mappedPoint(bool* wasClamped = 0) const;
FloatQuad mappedQuad(bool* wasClamped = 0) const;
private:
void translateTransform(const LayoutSize&);
void translateMappedCoordinates(const LayoutSize&);
void flattenWithTransform(const TransformationMatrix&, bool* wasClamped);
void applyAccumulatedOffset();
FloatPoint m_lastPlanarPoint;
FloatQuad m_lastPlanarQuad;
OwnPtr<TransformationMatrix> m_accumulatedTransform;
LayoutSize m_accumulatedOffset;
bool m_accumulatingTransform;
bool m_mapPoint, m_mapQuad;
TransformDirection m_direction;
};
}
#endif