2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef SVGTextContentElement_h
22 #define SVGTextContentElement_h
25 #include "SVGAnimatedBoolean.h"
26 #include "SVGAnimatedEnumeration.h"
27 #include "SVGAnimatedLength.h"
28 #include "SVGExternalResourcesRequired.h"
29 #include "SVGStyledElement.h"
34 enum SVGLengthAdjustType {
35 SVGLengthAdjustUnknown,
36 SVGLengthAdjustSpacing,
37 SVGLengthAdjustSpacingAndGlyphs
41 struct SVGPropertyTraits<SVGLengthAdjustType> {
42 static unsigned highestEnumValue() { return SVGLengthAdjustSpacingAndGlyphs; }
44 static String toString(SVGLengthAdjustType type)
47 case SVGLengthAdjustUnknown:
49 case SVGLengthAdjustSpacing:
51 case SVGLengthAdjustSpacingAndGlyphs:
52 return "spacingAndGlyphs";
59 static SVGLengthAdjustType fromString(const String& value)
61 if (value == "spacingAndGlyphs")
62 return SVGLengthAdjustSpacingAndGlyphs;
63 if (value == "spacing")
64 return SVGLengthAdjustSpacing;
65 return SVGLengthAdjustUnknown;
69 class SVGTextContentElement : public SVGStyledElement,
71 public SVGExternalResourcesRequired {
73 // Forward declare enumerations in the W3C naming scheme, for IDL generation.
75 LENGTHADJUST_UNKNOWN = SVGLengthAdjustUnknown,
76 LENGTHADJUST_SPACING = SVGLengthAdjustSpacing,
77 LENGTHADJUST_SPACINGANDGLYPHS = SVGLengthAdjustSpacingAndGlyphs
80 unsigned getNumberOfChars();
81 float getComputedTextLength();
82 float getSubStringLength(unsigned charnum, unsigned nchars, ExceptionCode&);
83 FloatPoint getStartPositionOfChar(unsigned charnum, ExceptionCode&);
84 FloatPoint getEndPositionOfChar(unsigned charnum, ExceptionCode&);
85 FloatRect getExtentOfChar(unsigned charnum, ExceptionCode&);
86 float getRotationOfChar(unsigned charnum, ExceptionCode&);
87 int getCharNumAtPosition(const FloatPoint&);
88 void selectSubString(unsigned charnum, unsigned nchars, ExceptionCode&);
90 static SVGTextContentElement* elementFromRenderer(RenderObject*);
92 // textLength is not declared using the standard DECLARE_ANIMATED_LENGTH macro
93 // as its getter needs special handling (return getComputedTextLength(), instead of m_textLength).
94 SVGLength& specifiedTextLength() { return m_specifiedTextLength; }
95 PassRefPtr<SVGAnimatedLength> textLengthAnimated();
96 static const SVGPropertyInfo* textLengthPropertyInfo();
99 SVGTextContentElement(const QualifiedName&, Document*);
101 virtual bool isValid() const { return SVGTests::isValid(); }
103 bool isSupportedAttribute(const QualifiedName&);
104 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
105 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
106 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
107 virtual void svgAttributeChanged(const QualifiedName&);
109 virtual bool selfHasRelativeLengths() const;
112 virtual bool isTextContent() const { return true; }
114 // Custom 'textLength' property
115 static void synchronizeTextLength(SVGElement* contextElement);
116 static PassRefPtr<SVGAnimatedProperty> lookupOrCreateTextLengthWrapper(SVGElement* contextElement);
117 mutable SVGSynchronizableAnimatedProperty<SVGLength> m_textLength;
118 SVGLength m_specifiedTextLength;
120 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGTextContentElement)
121 DECLARE_ANIMATED_ENUMERATION(LengthAdjust, lengthAdjust, SVGLengthAdjustType)
122 DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
123 END_DECLARE_ANIMATED_PROPERTIES
126 virtual void synchronizeRequiredFeatures() { SVGTests::synchronizeRequiredFeatures(this); }
127 virtual void synchronizeRequiredExtensions() { SVGTests::synchronizeRequiredExtensions(this); }
128 virtual void synchronizeSystemLanguage() { SVGTests::synchronizeSystemLanguage(this); }
131 inline SVGTextContentElement* toSVGTextContentElement(SVGElement* element)
133 ASSERT_WITH_SECURITY_IMPLICATION(!element || element->isTextContent());
134 return static_cast<SVGTextContentElement*>(element);
137 } // namespace WebCore
139 #endif // ENABLE(SVG)