SVGLengthContext.h [plain text]
#ifndef SVGLengthContext_h
#define SVGLengthContext_h
#include "FloatRect.h"
#include "SVGUnitTypes.h"
namespace WebCore {
class SVGElement;
class SVGLength;
struct Length;
typedef int ExceptionCode;
enum SVGLengthType {
LengthTypeUnknown = 0,
LengthTypeNumber,
LengthTypePercentage,
LengthTypeEMS,
LengthTypeEXS,
LengthTypePX,
LengthTypeCM,
LengthTypeMM,
LengthTypeIN,
LengthTypePT,
LengthTypePC
};
enum SVGLengthMode {
LengthModeWidth = 0,
LengthModeHeight,
LengthModeOther
};
class SVGLengthContext {
public:
explicit SVGLengthContext(const SVGElement*);
template<typename T>
static FloatRect resolveRectangle(const T* context, SVGUnitTypes::SVGUnitType type, const FloatRect& viewport)
{
return SVGLengthContext::resolveRectangle(context, type, viewport, context->x(), context->y(), context->width(), context->height());
}
static FloatRect resolveRectangle(const SVGElement*, SVGUnitTypes::SVGUnitType, const FloatRect& viewport, const SVGLength& x, const SVGLength& y, const SVGLength& width, const SVGLength& height);
static FloatPoint resolvePoint(const SVGElement*, SVGUnitTypes::SVGUnitType, const SVGLength& x, const SVGLength& y);
static float resolveLength(const SVGElement*, SVGUnitTypes::SVGUnitType, const SVGLength&);
float valueForLength(const Length&, SVGLengthMode = LengthModeOther);
float convertValueToUserUnits(float, SVGLengthMode, SVGLengthType fromUnit, ExceptionCode&) const;
float convertValueFromUserUnits(float, SVGLengthMode, SVGLengthType toUnit, ExceptionCode&) const;
bool determineViewport(FloatSize&) const;
private:
SVGLengthContext(const SVGElement*, const FloatRect& viewport);
float convertValueFromUserUnitsToPercentage(float value, SVGLengthMode, ExceptionCode&) const;
float convertValueFromPercentageToUserUnits(float value, SVGLengthMode, ExceptionCode&) const;
float convertValueFromUserUnitsToEMS(float value, ExceptionCode&) const;
float convertValueFromEMSToUserUnits(float value, ExceptionCode&) const;
float convertValueFromUserUnitsToEXS(float value, ExceptionCode&) const;
float convertValueFromEXSToUserUnits(float value, ExceptionCode&) const;
const SVGElement* m_context;
FloatRect m_overridenViewport;
};
}
#endif // SVGLengthContext_h