1/* 2 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20#ifndef SVGLengthContext_h 21#define SVGLengthContext_h 22 23#if ENABLE(SVG) 24#include "FloatRect.h" 25#include "SVGUnitTypes.h" 26 27namespace WebCore { 28 29class SVGElement; 30class SVGLength; 31 32typedef int ExceptionCode; 33 34enum SVGLengthType { 35 LengthTypeUnknown = 0, 36 LengthTypeNumber, 37 LengthTypePercentage, 38 LengthTypeEMS, 39 LengthTypeEXS, 40 LengthTypePX, 41 LengthTypeCM, 42 LengthTypeMM, 43 LengthTypeIN, 44 LengthTypePT, 45 LengthTypePC 46}; 47 48enum SVGLengthMode { 49 LengthModeWidth = 0, 50 LengthModeHeight, 51 LengthModeOther 52}; 53 54class SVGLengthContext { 55public: 56 explicit SVGLengthContext(const SVGElement*); 57 58 template<typename T> 59 static FloatRect resolveRectangle(const T* context, SVGUnitTypes::SVGUnitType type, const FloatRect& viewport) 60 { 61 return SVGLengthContext::resolveRectangle(context, type, viewport, context->x(), context->y(), context->width(), context->height()); 62 } 63 64 static FloatRect resolveRectangle(const SVGElement*, SVGUnitTypes::SVGUnitType, const FloatRect& viewport, const SVGLength& x, const SVGLength& y, const SVGLength& width, const SVGLength& height); 65 static FloatPoint resolvePoint(const SVGElement*, SVGUnitTypes::SVGUnitType, const SVGLength& x, const SVGLength& y); 66 static float resolveLength(const SVGElement*, SVGUnitTypes::SVGUnitType, const SVGLength&); 67 68 float convertValueToUserUnits(float, SVGLengthMode, SVGLengthType fromUnit, ExceptionCode&) const; 69 float convertValueFromUserUnits(float, SVGLengthMode, SVGLengthType toUnit, ExceptionCode&) const; 70 71 bool determineViewport(float& width, float& height) const; 72 73private: 74 SVGLengthContext(const SVGElement*, const FloatRect& viewport); 75 76 float convertValueFromUserUnitsToPercentage(float value, SVGLengthMode, ExceptionCode&) const; 77 float convertValueFromPercentageToUserUnits(float value, SVGLengthMode, ExceptionCode&) const; 78 79 float convertValueFromUserUnitsToEMS(float value, ExceptionCode&) const; 80 float convertValueFromEMSToUserUnits(float value, ExceptionCode&) const; 81 82 float convertValueFromUserUnitsToEXS(float value, ExceptionCode&) const; 83 float convertValueFromEXSToUserUnits(float value, ExceptionCode&) const; 84 85 const SVGElement* m_context; 86 FloatRect m_overridenViewport; 87}; 88 89} // namespace WebCore 90 91#endif // ENABLE(SVG) 92#endif // SVGLengthContext_h 93