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