OSDN Git Service

Merge Webkit at r70949: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / svg / SVGTRefElement.cpp
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 inline SVGTRefElement::SVGTRefElement(const QualifiedName& tagName, Document* document)
36     : SVGTextPositioningElement(tagName, document)
37 {
38 }
39
40 PassRefPtr<SVGTRefElement> SVGTRefElement::create(const QualifiedName& tagName, Document* document)
41 {
42     return adoptRef(new SVGTRefElement(tagName, document));
43 }
44
45 void SVGTRefElement::updateReferencedText()
46 {
47     Element* target = document()->getElementById(SVGURIReference::getTarget(href()));
48     String textContent;
49     if (target && target->isSVGElement())
50         textContent = static_cast<SVGElement*>(target)->textContent();
51     ExceptionCode ignore = 0;
52     setTextContent(textContent, ignore);
53 }
54
55 void SVGTRefElement::parseMappedAttribute(Attribute* attr)
56 {
57     if (SVGURIReference::parseMappedAttribute(attr)) {
58         updateReferencedText();
59         return;
60     }
61
62     SVGTextPositioningElement::parseMappedAttribute(attr);
63 }
64
65 void SVGTRefElement::svgAttributeChanged(const QualifiedName& attrName)
66 {
67     SVGTextPositioningElement::svgAttributeChanged(attrName);
68
69     if (!renderer())
70         return;
71
72     if (SVGURIReference::isKnownAttribute(attrName))
73         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer());
74 }
75
76 void SVGTRefElement::synchronizeProperty(const QualifiedName& attrName)
77 {
78     SVGTextPositioningElement::synchronizeProperty(attrName);
79
80     if (attrName == anyQName() || SVGURIReference::isKnownAttribute(attrName))
81         synchronizeHref();
82 }
83
84 bool SVGTRefElement::childShouldCreateRenderer(Node* child) const
85 {
86     if (child->isTextNode() || child->hasTagName(SVGNames::tspanTag) ||
87         child->hasTagName(SVGNames::trefTag))
88         return true;
89     return false;
90 }
91
92 RenderObject* SVGTRefElement::createRenderer(RenderArena* arena, RenderStyle*)
93 {
94     return new (arena) RenderSVGInline(this);
95 }
96
97 }
98
99 #endif // ENABLE(SVG)