Home | History | Annotate | Download | only in svg
      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/SVGGraphicsElement.h"
     28 #include "core/svg/SVGPointTearOff.h"
     29 
     30 namespace WebCore {
     31 
     32 class ExceptionState;
     33 
     34 enum SVGLengthAdjustType {
     35     SVGLengthAdjustUnknown,
     36     SVGLengthAdjustSpacing,
     37     SVGLengthAdjustSpacingAndGlyphs
     38 };
     39 template<> const SVGEnumerationStringEntries& getStaticStringEntries<SVGLengthAdjustType>();
     40 
     41 class SVGTextContentElement : public SVGGraphicsElement {
     42 public:
     43     // Forward declare enumerations in the W3C naming scheme, for IDL generation.
     44     enum {
     45         LENGTHADJUST_UNKNOWN = SVGLengthAdjustUnknown,
     46         LENGTHADJUST_SPACING = SVGLengthAdjustSpacing,
     47         LENGTHADJUST_SPACINGANDGLYPHS = SVGLengthAdjustSpacingAndGlyphs
     48     };
     49 
     50     unsigned getNumberOfChars();
     51     float getComputedTextLength();
     52     float getSubStringLength(unsigned charnum, unsigned nchars, ExceptionState&);
     53     PassRefPtr<SVGPointTearOff> getStartPositionOfChar(unsigned charnum, ExceptionState&);
     54     PassRefPtr<SVGPointTearOff> getEndPositionOfChar(unsigned charnum, ExceptionState&);
     55     PassRefPtr<SVGRectTearOff> getExtentOfChar(unsigned charnum, ExceptionState&);
     56     float getRotationOfChar(unsigned charnum, ExceptionState&);
     57     int getCharNumAtPosition(PassRefPtr<SVGPointTearOff>, ExceptionState&);
     58     void selectSubString(unsigned charnum, unsigned nchars, ExceptionState&);
     59 
     60     static SVGTextContentElement* elementFromRenderer(RenderObject*);
     61 
     62     SVGAnimatedLength* textLength() { return m_textLength.get(); }
     63     bool textLengthIsSpecifiedByUser() { return m_textLengthIsSpecifiedByUser; }
     64     SVGAnimatedEnumeration<SVGLengthAdjustType>* lengthAdjust() { return m_lengthAdjust.get(); }
     65 
     66 protected:
     67     SVGTextContentElement(const QualifiedName&, Document&);
     68 
     69     bool isSupportedAttribute(const QualifiedName&);
     70     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
     71     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE FINAL;
     72     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE FINAL;
     73     virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
     74 
     75     virtual bool selfHasRelativeLengths() const OVERRIDE;
     76 
     77 private:
     78     virtual bool isTextContent() const OVERRIDE FINAL { return true; }
     79 
     80     RefPtr<SVGAnimatedLength> m_textLength;
     81     bool m_textLengthIsSpecifiedByUser;
     82     RefPtr<SVGAnimatedEnumeration<SVGLengthAdjustType> > m_lengthAdjust;
     83 };
     84 
     85 inline bool isSVGTextContentElement(const Node& node)
     86 {
     87     return node.isSVGElement() && toSVGElement(node).isTextContent();
     88 }
     89 
     90 DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGTextContentElement);
     91 
     92 } // namespace WebCore
     93 
     94 #endif
     95