WebCore/svg/SVGTextPositioningElement.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2     Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
       
     3                   2004, 2005, 2006, 2007, 2008 Rob Buis <buis@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 #include "config.h"
       
    22 
       
    23 #if ENABLE(SVG)
       
    24 #include "SVGTextPositioningElement.h"
       
    25 
       
    26 #include "Attribute.h"
       
    27 #include "RenderObject.h"
       
    28 #include "RenderSVGResource.h"
       
    29 #include "SVGLengthList.h"
       
    30 #include "SVGNames.h"
       
    31 #include "SVGNumberList.h"
       
    32 
       
    33 namespace WebCore {
       
    34 
       
    35 SVGTextPositioningElement::SVGTextPositioningElement(const QualifiedName& tagName, Document* doc)
       
    36     : SVGTextContentElement(tagName, doc)
       
    37     , m_x(SVGLengthList::create(SVGNames::xAttr))
       
    38     , m_y(SVGLengthList::create(SVGNames::yAttr))
       
    39     , m_dx(SVGLengthList::create(SVGNames::dxAttr))
       
    40     , m_dy(SVGLengthList::create(SVGNames::dyAttr))
       
    41     , m_rotate(SVGNumberList::create(SVGNames::rotateAttr))
       
    42 {
       
    43 }
       
    44 
       
    45 SVGTextPositioningElement::~SVGTextPositioningElement()
       
    46 {
       
    47 }
       
    48 
       
    49 void SVGTextPositioningElement::parseMappedAttribute(Attribute* attr)
       
    50 {
       
    51     if (attr->name() == SVGNames::xAttr)
       
    52         xBaseValue()->parse(attr->value(), LengthModeWidth);
       
    53     else if (attr->name() == SVGNames::yAttr)
       
    54         yBaseValue()->parse(attr->value(), LengthModeHeight);
       
    55     else if (attr->name() == SVGNames::dxAttr)
       
    56         dxBaseValue()->parse(attr->value(), LengthModeWidth);
       
    57     else if (attr->name() == SVGNames::dyAttr)
       
    58         dyBaseValue()->parse(attr->value(), LengthModeHeight);
       
    59     else if (attr->name() == SVGNames::rotateAttr)
       
    60         rotateBaseValue()->parse(attr->value());
       
    61     else
       
    62         SVGTextContentElement::parseMappedAttribute(attr);
       
    63 }
       
    64 
       
    65 void SVGTextPositioningElement::svgAttributeChanged(const QualifiedName& attrName)
       
    66 {
       
    67     SVGTextContentElement::svgAttributeChanged(attrName);
       
    68 
       
    69     if (attrName == SVGNames::xAttr
       
    70         || attrName == SVGNames::yAttr
       
    71         || attrName == SVGNames::dxAttr
       
    72         || attrName == SVGNames::dyAttr)
       
    73         updateRelativeLengthsInformation();
       
    74 
       
    75     if (!renderer())
       
    76         return;
       
    77 
       
    78     if (isKnownAttribute(attrName))
       
    79         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer());
       
    80 }
       
    81 
       
    82 void SVGTextPositioningElement::synchronizeProperty(const QualifiedName& attrName)
       
    83 {
       
    84     SVGTextContentElement::synchronizeProperty(attrName);
       
    85 
       
    86     if (attrName == anyQName()) {
       
    87         synchronizeX();
       
    88         synchronizeY();
       
    89         synchronizeDx();
       
    90         synchronizeDy();
       
    91         synchronizeRotate();
       
    92         return;
       
    93     }
       
    94 
       
    95     if (attrName == SVGNames::xAttr)
       
    96         synchronizeX();
       
    97     else if (attrName == SVGNames::yAttr)
       
    98         synchronizeY();
       
    99     else if (attrName == SVGNames::dxAttr)
       
   100         synchronizeDx();
       
   101     else if (attrName == SVGNames::dyAttr)
       
   102         synchronizeDy();
       
   103     else if (attrName == SVGNames::rotateAttr)
       
   104         synchronizeRotate();
       
   105 }
       
   106 
       
   107 bool SVGTextPositioningElement::isKnownAttribute(const QualifiedName& attrName)
       
   108 {
       
   109     return (attrName.matches(SVGNames::xAttr) ||
       
   110             attrName.matches(SVGNames::yAttr) ||
       
   111             attrName.matches(SVGNames::dxAttr) ||
       
   112             attrName.matches(SVGNames::dyAttr) ||
       
   113             attrName.matches(SVGNames::rotateAttr) ||
       
   114             SVGTextContentElement::isKnownAttribute(attrName));
       
   115 }
       
   116 
       
   117 static inline bool listContainsRelativeValue(SVGLengthList* list)
       
   118 {
       
   119     if (!list)
       
   120         return false;
       
   121 
       
   122     ExceptionCode ec = 0;
       
   123     int length = list->numberOfItems();
       
   124     for (int i = 0; i < length; ++i) {
       
   125         SVGLength length(list->getItem(i, ec));
       
   126         ASSERT(!ec);
       
   127 
       
   128         if (length.isRelative())
       
   129             return true;
       
   130     }
       
   131 
       
   132     return false;
       
   133 }
       
   134 
       
   135 bool SVGTextPositioningElement::selfHasRelativeLengths() const
       
   136 {
       
   137     if (SVGTextContentElement::selfHasRelativeLengths())
       
   138         return true;
       
   139     if (listContainsRelativeValue(x()))
       
   140         return true;
       
   141     if (listContainsRelativeValue(y()))
       
   142         return true;
       
   143     if (listContainsRelativeValue(dx()))
       
   144         return true;
       
   145     if (listContainsRelativeValue(dy()))
       
   146         return true;
       
   147     return false;
       
   148 }
       
   149 
       
   150 }
       
   151 
       
   152 #endif // ENABLE(SVG)