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 #include "core/svg/SVGUnitTypes.h" 24 #include "platform/geometry/FloatRect.h" 25 26 namespace WebCore { 27 28 class ExceptionState; 29 class SVGElement; 30 class SVGLength; 31 32 enum SVGLengthType { 33 LengthTypeUnknown = 0, 34 LengthTypeNumber, 35 LengthTypePercentage, 36 LengthTypeEMS, 37 LengthTypeEXS, 38 LengthTypePX, 39 LengthTypeCM, 40 LengthTypeMM, 41 LengthTypeIN, 42 LengthTypePT, 43 LengthTypePC 44 }; 45 46 enum SVGLengthMode { 47 LengthModeWidth = 0, 48 LengthModeHeight, 49 LengthModeOther 50 }; 51 52 class SVGLengthContext { 53 STACK_ALLOCATED(); 54 public: 55 explicit SVGLengthContext(const SVGElement*); 56 57 template<typename T> resolveRectangle(const T * context,SVGUnitTypes::SVGUnitType type,const FloatRect & viewport)58 static FloatRect resolveRectangle(const T* context, SVGUnitTypes::SVGUnitType type, const FloatRect& viewport) 59 { 60 return SVGLengthContext::resolveRectangle(context, type, viewport, context->x()->currentValue(), context->y()->currentValue(), context->width()->currentValue(), context->height()->currentValue()); 61 } 62 63 static FloatRect resolveRectangle(const SVGElement*, SVGUnitTypes::SVGUnitType, const FloatRect& viewport, PassRefPtr<SVGLength> x, PassRefPtr<SVGLength> y, PassRefPtr<SVGLength> width, PassRefPtr<SVGLength> height); 64 static FloatPoint resolvePoint(const SVGElement*, SVGUnitTypes::SVGUnitType, PassRefPtr<SVGLength> x, PassRefPtr<SVGLength> y); 65 static float resolveLength(const SVGElement*, SVGUnitTypes::SVGUnitType, PassRefPtr<SVGLength>); 66 67 float convertValueToUserUnits(float, SVGLengthMode, SVGLengthType fromUnit, ExceptionState&) const; 68 float convertValueFromUserUnits(float, SVGLengthMode, SVGLengthType toUnit, ExceptionState&) const; 69 70 bool determineViewport(FloatSize&) const; 71 72 private: 73 SVGLengthContext(const SVGElement*, const FloatRect& viewport); 74 75 float convertValueFromUserUnitsToPercentage(float value, SVGLengthMode, ExceptionState&) const; 76 float convertValueFromPercentageToUserUnits(float value, SVGLengthMode, ExceptionState&) const; 77 78 float convertValueFromUserUnitsToEMS(float value, ExceptionState&) const; 79 float convertValueFromEMSToUserUnits(float value, ExceptionState&) const; 80 81 float convertValueFromUserUnitsToEXS(float value, ExceptionState&) const; 82 float convertValueFromEXSToUserUnits(float value, ExceptionState&) const; 83 84 RawPtrWillBeMember<const SVGElement> m_context; 85 FloatRect m_overridenViewport; 86 }; 87 88 } // namespace WebCore 89 90 #endif // SVGLengthContext_h 91