1 /* 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis (at) kde.org> 4 * 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. 9 * 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. 14 * 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. 19 */ 20 21 #ifndef SVGTextContentElement_h 22 #define SVGTextContentElement_h 23 24 #include "core/svg/SVGAnimatedBoolean.h" 25 #include "core/svg/SVGAnimatedEnumeration.h" 26 #include "core/svg/SVGAnimatedLength.h" 27 #include "core/svg/SVGExternalResourcesRequired.h" 28 #include "core/svg/SVGGraphicsElement.h" 29 30 namespace WebCore { 31 32 class ExceptionState; 33 34 enum SVGLengthAdjustType { 35 SVGLengthAdjustUnknown, 36 SVGLengthAdjustSpacing, 37 SVGLengthAdjustSpacingAndGlyphs 38 }; 39 40 template<> 41 struct SVGPropertyTraits<SVGLengthAdjustType> { 42 static unsigned highestEnumValue() { return SVGLengthAdjustSpacingAndGlyphs; } 43 44 static String toString(SVGLengthAdjustType type) 45 { 46 switch (type) { 47 case SVGLengthAdjustUnknown: 48 return emptyString(); 49 case SVGLengthAdjustSpacing: 50 return "spacing"; 51 case SVGLengthAdjustSpacingAndGlyphs: 52 return "spacingAndGlyphs"; 53 } 54 55 ASSERT_NOT_REACHED(); 56 return emptyString(); 57 } 58 59 static SVGLengthAdjustType fromString(const String& value) 60 { 61 if (value == "spacingAndGlyphs") 62 return SVGLengthAdjustSpacingAndGlyphs; 63 if (value == "spacing") 64 return SVGLengthAdjustSpacing; 65 return SVGLengthAdjustUnknown; 66 } 67 }; 68 69 class SVGTextContentElement : public SVGGraphicsElement, 70 public SVGExternalResourcesRequired { 71 public: 72 // Forward declare enumerations in the W3C naming scheme, for IDL generation. 73 enum { 74 LENGTHADJUST_UNKNOWN = SVGLengthAdjustUnknown, 75 LENGTHADJUST_SPACING = SVGLengthAdjustSpacing, 76 LENGTHADJUST_SPACINGANDGLYPHS = SVGLengthAdjustSpacingAndGlyphs 77 }; 78 79 unsigned getNumberOfChars(); 80 float getComputedTextLength(); 81 float getSubStringLength(unsigned charnum, unsigned nchars, ExceptionState&); 82 SVGPoint getStartPositionOfChar(unsigned charnum, ExceptionState&); 83 SVGPoint getEndPositionOfChar(unsigned charnum, ExceptionState&); 84 SVGRect getExtentOfChar(unsigned charnum, ExceptionState&); 85 float getRotationOfChar(unsigned charnum, ExceptionState&); 86 int getCharNumAtPosition(const SVGPoint&); 87 void selectSubString(unsigned charnum, unsigned nchars, ExceptionState&); 88 89 static SVGTextContentElement* elementFromRenderer(RenderObject*); 90 91 // textLength is not declared using the standard DECLARE_ANIMATED_LENGTH macro 92 // as its getter needs special handling (return getComputedTextLength(), instead of m_textLength). 93 SVGLength& specifiedTextLength() { return m_specifiedTextLength; } 94 PassRefPtr<SVGAnimatedLength> textLength(); 95 static const SVGPropertyInfo* textLengthPropertyInfo(); 96 97 protected: 98 SVGTextContentElement(const QualifiedName&, Document&); 99 100 virtual bool isValid() const { return SVGTests::isValid(); } 101 102 bool isSupportedAttribute(const QualifiedName&); 103 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 104 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE; 105 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE; 106 virtual void svgAttributeChanged(const QualifiedName&); 107 108 virtual bool selfHasRelativeLengths() const; 109 110 private: 111 virtual bool isTextContent() const { return true; } 112 113 // Custom 'textLength' property 114 static void synchronizeTextLength(SVGElement* contextElement); 115 static PassRefPtr<SVGAnimatedProperty> lookupOrCreateTextLengthWrapper(SVGElement* contextElement); 116 mutable SVGSynchronizableAnimatedProperty<SVGLength> m_textLength; 117 SVGLength m_specifiedTextLength; 118 119 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGTextContentElement) 120 DECLARE_ANIMATED_ENUMERATION(LengthAdjust, lengthAdjust, SVGLengthAdjustType) 121 DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) 122 END_DECLARE_ANIMATED_PROPERTIES 123 }; 124 125 inline bool isSVGTextContentElement(const Node& node) 126 { 127 return node.isSVGElement() && toSVGElement(node).isTextContent(); 128 } 129 130 DEFINE_NODE_TYPE_CASTS_WITH_FUNCTION(SVGTextContentElement); 131 132 } // namespace WebCore 133 134 #endif 135