1/*
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 * Copyright (C) 2008 Apple Inc. All rights reserved.
5 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB.  If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#include "config.h"
24
25#if ENABLE(SVG_FONTS)
26#include "SVGAltGlyphElement.h"
27
28#include "ExceptionCode.h"
29#include "NodeRenderingContext.h"
30#include "RenderInline.h"
31#include "RenderSVGTSpan.h"
32#include "SVGAltGlyphDefElement.h"
33#include "SVGGlyphElement.h"
34#include "SVGNames.h"
35#include "XLinkNames.h"
36
37namespace WebCore {
38
39// Animated property definitions
40DEFINE_ANIMATED_STRING(SVGAltGlyphElement, XLinkNames::hrefAttr, Href, href)
41
42BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGAltGlyphElement)
43    REGISTER_LOCAL_ANIMATED_PROPERTY(href)
44    REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTextPositioningElement)
45END_REGISTER_ANIMATED_PROPERTIES
46
47inline SVGAltGlyphElement::SVGAltGlyphElement(const QualifiedName& tagName, Document* document)
48    : SVGTextPositioningElement(tagName, document)
49{
50    ASSERT(hasTagName(SVGNames::altGlyphTag));
51    registerAnimatedPropertiesForSVGAltGlyphElement();
52}
53
54PassRefPtr<SVGAltGlyphElement> SVGAltGlyphElement::create(const QualifiedName& tagName, Document* document)
55{
56    return adoptRef(new SVGAltGlyphElement(tagName, document));
57}
58
59void SVGAltGlyphElement::setGlyphRef(const AtomicString&, ExceptionCode& ec)
60{
61    ec = NO_MODIFICATION_ALLOWED_ERR;
62}
63
64const AtomicString& SVGAltGlyphElement::glyphRef() const
65{
66    return fastGetAttribute(SVGNames::glyphRefAttr);
67}
68
69void SVGAltGlyphElement::setFormat(const AtomicString&, ExceptionCode& ec)
70{
71    ec = NO_MODIFICATION_ALLOWED_ERR;
72}
73
74const AtomicString& SVGAltGlyphElement::format() const
75{
76    return fastGetAttribute(SVGNames::formatAttr);
77}
78
79bool SVGAltGlyphElement::childShouldCreateRenderer(const NodeRenderingContext& childContext) const
80{
81    if (childContext.node()->isTextNode())
82        return true;
83    return false;
84}
85
86RenderObject* SVGAltGlyphElement::createRenderer(RenderArena* arena, RenderStyle*)
87{
88    return new (arena) RenderSVGTSpan(this);
89}
90
91bool SVGAltGlyphElement::hasValidGlyphElements(Vector<String>& glyphNames) const
92{
93    String target;
94    Element* element = targetElementFromIRIString(getAttribute(XLinkNames::hrefAttr), document(), &target);
95    if (!element)
96        return false;
97
98    if (element->hasTagName(SVGNames::glyphTag)) {
99        glyphNames.append(target);
100        return true;
101    }
102
103    if (element->hasTagName(SVGNames::altGlyphDefTag)
104        && static_cast<SVGAltGlyphDefElement*>(element)->hasValidGlyphElements(glyphNames))
105        return true;
106
107    return false;
108}
109
110}
111
112#endif // ENABLE(SVG)
113