#ifndef SVGLengthContext_h
#define SVGLengthContext_h
#include "core/svg/SVGUnitTypes.h"
#include "platform/geometry/FloatRect.h"
namespace WebCore {
class ExceptionState;
class SVGElement;
class SVGLength;
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()->currentValue(), context->y()->currentValue(), context->width()->currentValue(), context->height()->currentValue());
    }
    static FloatRect resolveRectangle(const SVGElement*, SVGUnitTypes::SVGUnitType, const FloatRect& viewport, PassRefPtr<SVGLength> x, PassRefPtr<SVGLength> y, PassRefPtr<SVGLength> width, PassRefPtr<SVGLength> height);
    static FloatPoint resolvePoint(const SVGElement*, SVGUnitTypes::SVGUnitType, PassRefPtr<SVGLength> x, PassRefPtr<SVGLength> y);
    static float resolveLength(const SVGElement*, SVGUnitTypes::SVGUnitType, PassRefPtr<SVGLength>);
    float convertValueToUserUnits(float, SVGLengthMode, SVGLengthType fromUnit, ExceptionState&) const;
    float convertValueFromUserUnits(float, SVGLengthMode, SVGLengthType toUnit, ExceptionState&) const;
    bool determineViewport(FloatSize&) const;
private:
    SVGLengthContext(const SVGElement*, const FloatRect& viewport);
    float convertValueFromUserUnitsToPercentage(float value, SVGLengthMode, ExceptionState&) const;
    float convertValueFromPercentageToUserUnits(float value, SVGLengthMode, ExceptionState&) const;
    float convertValueFromUserUnitsToEMS(float value, ExceptionState&) const;
    float convertValueFromEMSToUserUnits(float value, ExceptionState&) const;
    float convertValueFromUserUnitsToEXS(float value, ExceptionState&) const;
    float convertValueFromEXSToUserUnits(float value, ExceptionState&) const;
    const SVGElement* m_context;
    FloatRect m_overridenViewport;
};
} 
#endif