• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006 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 "SVGTRefElement.h"
25 
26 #include "RenderSVGInline.h"
27 #include "RenderSVGResource.h"
28 #include "SVGDocument.h"
29 #include "SVGNames.h"
30 #include "Text.h"
31 #include "XLinkNames.h"
32 
33 namespace WebCore {
34 
35 // Animated property definitions
DEFINE_ANIMATED_STRING(SVGTRefElement,XLinkNames::hrefAttr,Href,href)36 DEFINE_ANIMATED_STRING(SVGTRefElement, XLinkNames::hrefAttr, Href, href)
37 
38 inline SVGTRefElement::SVGTRefElement(const QualifiedName& tagName, Document* document)
39     : SVGTextPositioningElement(tagName, document)
40 {
41 }
42 
create(const QualifiedName & tagName,Document * document)43 PassRefPtr<SVGTRefElement> SVGTRefElement::create(const QualifiedName& tagName, Document* document)
44 {
45     return adoptRef(new SVGTRefElement(tagName, document));
46 }
47 
updateReferencedText()48 void SVGTRefElement::updateReferencedText()
49 {
50     Element* target = document()->getElementById(SVGURIReference::getTarget(href()));
51     String textContent;
52     if (target && target->isSVGElement())
53         textContent = static_cast<SVGElement*>(target)->textContent();
54     ExceptionCode ignore = 0;
55     setTextContent(textContent, ignore);
56 }
57 
parseMappedAttribute(Attribute * attr)58 void SVGTRefElement::parseMappedAttribute(Attribute* attr)
59 {
60     if (SVGURIReference::parseMappedAttribute(attr)) {
61         updateReferencedText();
62         return;
63     }
64 
65     SVGTextPositioningElement::parseMappedAttribute(attr);
66 }
67 
svgAttributeChanged(const QualifiedName & attrName)68 void SVGTRefElement::svgAttributeChanged(const QualifiedName& attrName)
69 {
70     SVGTextPositioningElement::svgAttributeChanged(attrName);
71 
72     if (!renderer())
73         return;
74 
75     if (SVGURIReference::isKnownAttribute(attrName))
76         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer());
77 }
78 
synchronizeProperty(const QualifiedName & attrName)79 void SVGTRefElement::synchronizeProperty(const QualifiedName& attrName)
80 {
81     SVGTextPositioningElement::synchronizeProperty(attrName);
82 
83     if (attrName == anyQName() || SVGURIReference::isKnownAttribute(attrName))
84         synchronizeHref();
85 }
86 
attributeToPropertyTypeMap()87 AttributeToPropertyTypeMap& SVGTRefElement::attributeToPropertyTypeMap()
88 {
89     DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
90     return s_attributeToPropertyTypeMap;
91 }
92 
fillAttributeToPropertyTypeMap()93 void SVGTRefElement::fillAttributeToPropertyTypeMap()
94 {
95     AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
96 
97     SVGTextPositioningElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
98     attributeToPropertyTypeMap.set(XLinkNames::hrefAttr, AnimatedString);
99 }
100 
createRenderer(RenderArena * arena,RenderStyle *)101 RenderObject* SVGTRefElement::createRenderer(RenderArena* arena, RenderStyle*)
102 {
103     return new (arena) RenderSVGInline(this);
104 }
105 
childShouldCreateRenderer(Node * child) const106 bool SVGTRefElement::childShouldCreateRenderer(Node* child) const
107 {
108     if (child->isTextNode())
109         return true;
110 
111     return false;
112 }
113 
rendererIsNeeded(RenderStyle * style)114 bool SVGTRefElement::rendererIsNeeded(RenderStyle* style)
115 {
116     if (parentNode()
117         && (parentNode()->hasTagName(SVGNames::aTag)
118 #if ENABLE(SVG_FONTS)
119             || parentNode()->hasTagName(SVGNames::altGlyphTag)
120 #endif
121             || parentNode()->hasTagName(SVGNames::textTag)
122             || parentNode()->hasTagName(SVGNames::textPathTag)
123             || parentNode()->hasTagName(SVGNames::tspanTag)))
124         return StyledElement::rendererIsNeeded(style);
125 
126     return false;
127 }
128 
129 }
130 
131 #endif // ENABLE(SVG)
132