23 #include "wtf/Platform.h"
36 SVGViewSpec::SVGViewSpec(
const SVGSVGElement* contextElement)
40 , m_contextElement(contextElement)
44 SVGViewSpec::~SVGViewSpec()
48 void SVGViewSpec::setTransform(
const String& transform)
50 SVGTransformable::parseTransformAttribute(m_transform.get(), transform);
53 void SVGViewSpec::setViewBoxString(
const String& viewBox)
56 const UChar* c = viewBox.characters();
57 const UChar*
end = c + viewBox.length();
58 if (!parseViewBox(c, end, x, y, w, h,
false))
60 setViewBoxBaseValue(FloatRect(x, y, w, h));
63 void SVGViewSpec::setPreserveAspectRatioString(
const String& preserve)
65 const UChar* c = preserve.characters();
66 const UChar* end = c + preserve.length();
67 preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
70 void SVGViewSpec::setViewTargetString(
const String& viewTargetString)
72 m_viewTargetString = viewTargetString;
75 SVGElement* SVGViewSpec::viewTarget()
const
77 return static_cast<SVGElement*
>(m_contextElement->ownerDocument()->getElementById(m_viewTargetString));
80 const SVGElement* SVGViewSpec::contextElement()
const
82 return m_contextElement;
85 static const UChar svgViewSpec[] = {
's',
'v',
'g',
'V',
'i',
'e',
'w'};
86 static const UChar viewBoxSpec[] = {
'v',
'i',
'e',
'w',
'B',
'o',
'x'};
87 static const UChar preserveAspectRatioSpec[] = {
'p',
'r',
'e',
's',
'e',
'r',
'v',
'e',
'A',
's',
'p',
'e',
'c',
't',
'R',
'a',
't',
'i',
'o'};
88 static const UChar transformSpec[] = {
't',
'r',
'a',
'n',
's',
'f',
'o',
'r',
'm'};
89 static const UChar zoomAndPanSpec[] = {
'z',
'o',
'o',
'm',
'A',
'n',
'd',
'P',
'a',
'n'};
90 static const UChar viewTargetSpec[] = {
'v',
'i',
'e',
'w',
'T',
'a',
'r',
'g',
'e',
't'};
92 bool SVGViewSpec::parseViewSpec(
const String& viewSpec)
94 const UChar* currViewSpec = viewSpec.characters();
95 const UChar* end = currViewSpec + viewSpec.length();
97 if (currViewSpec >= end)
100 if (!
skipString(currViewSpec, end, svgViewSpec,
sizeof(svgViewSpec) /
sizeof(UChar)))
103 if (currViewSpec >= end || *currViewSpec !=
'(' )
107 while (currViewSpec < end && *currViewSpec !=
')') {
108 if (*currViewSpec ==
'v') {
109 if (
skipString(currViewSpec, end, viewBoxSpec,
sizeof(viewBoxSpec) /
sizeof(UChar))) {
110 if (currViewSpec >= end || *currViewSpec !=
'(')
114 if (!parseViewBox(currViewSpec, end, x, y, w, h,
false))
116 setViewBoxBaseValue(FloatRect(x, y, w, h));
117 if (currViewSpec >= end || *currViewSpec !=
')')
120 }
else if (
skipString(currViewSpec, end, viewTargetSpec,
sizeof(viewTargetSpec) /
sizeof(UChar))) {
121 if (currViewSpec >= end || *currViewSpec !=
'(')
123 const UChar* viewTargetStart = ++currViewSpec;
124 while (currViewSpec < end && *currViewSpec !=
')')
126 if (currViewSpec >= end)
128 setViewTargetString(
String(viewTargetStart, currViewSpec - viewTargetStart));
132 }
else if (*currViewSpec ==
'z') {
133 if (!
skipString(currViewSpec, end, zoomAndPanSpec,
sizeof(zoomAndPanSpec) /
sizeof(UChar)))
135 if (currViewSpec >= end || *currViewSpec !=
'(')
138 if (!parseZoomAndPan(currViewSpec, end))
140 if (currViewSpec >= end || *currViewSpec !=
')')
143 }
else if (*currViewSpec ==
'p') {
144 if (!
skipString(currViewSpec, end, preserveAspectRatioSpec,
sizeof(preserveAspectRatioSpec) /
sizeof(UChar)))
146 if (currViewSpec >= end || *currViewSpec !=
'(')
149 if (!preserveAspectRatioBaseValue()->parsePreserveAspectRatio(currViewSpec, end,
false))
151 if (currViewSpec >= end || *currViewSpec !=
')')
154 }
else if (*currViewSpec ==
't') {
155 if (!
skipString(currViewSpec, end, transformSpec,
sizeof(transformSpec) /
sizeof(UChar)))
157 if (currViewSpec >= end || *currViewSpec !=
'(')
160 SVGTransformable::parseTransformAttribute(m_transform.get(), currViewSpec, end);
161 if (currViewSpec >= end || *currViewSpec !=
')')
167 if (currViewSpec < end && *currViewSpec ==
';')
171 if (currViewSpec >= end || *currViewSpec !=
')')
179 #endif // ENABLE(SVG)
DOM::QualifiedName transformAttr
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
bool skipString(const QChar *&ptr, const QChar *end, const QChar *name, int length)