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-2018 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#include "SVGAltGlyphElement.h"
25
26#if ENABLE(SVG_FONTS)
27
28#include "RenderInline.h"
29#include "RenderSVGTSpan.h"
30#include "SVGAltGlyphDefElement.h"
31#include "SVGGlyphElement.h"
32#include "SVGNames.h"
33#include "XLinkNames.h"
34#include <wtf/IsoMallocInlines.h>
35
36namespace WebCore {
37
38WTF_MAKE_ISO_ALLOCATED_IMPL(SVGAltGlyphElement);
39
40inline SVGAltGlyphElement::SVGAltGlyphElement(const QualifiedName& tagName, Document& document)
41 : SVGTextPositioningElement(tagName, document)
42 , SVGURIReference(this)
43{
44 ASSERT(hasTagName(SVGNames::altGlyphTag));
45}
46
47Ref<SVGAltGlyphElement> SVGAltGlyphElement::create(const QualifiedName& tagName, Document& document)
48{
49 return adoptRef(*new SVGAltGlyphElement(tagName, document));
50}
51
52ExceptionOr<void> SVGAltGlyphElement::setGlyphRef(const AtomicString&)
53{
54 return Exception { NoModificationAllowedError };
55}
56
57const AtomicString& SVGAltGlyphElement::glyphRef() const
58{
59 return attributeWithoutSynchronization(SVGNames::glyphRefAttr);
60}
61
62ExceptionOr<void> SVGAltGlyphElement::setFormat(const AtomicString&)
63{
64 return Exception { NoModificationAllowedError };
65}
66
67const AtomicString& SVGAltGlyphElement::format() const
68{
69 return attributeWithoutSynchronization(SVGNames::formatAttr);
70}
71
72bool SVGAltGlyphElement::childShouldCreateRenderer(const Node& child) const
73{
74 return child.isTextNode();
75}
76
77RenderPtr<RenderElement> SVGAltGlyphElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
78{
79 return createRenderer<RenderSVGTSpan>(*this, WTFMove(style));
80}
81
82bool SVGAltGlyphElement::hasValidGlyphElements(Vector<String>& glyphNames) const
83{
84 // No need to support altGlyph referencing another node inside a shadow tree.
85 auto target = targetElementFromIRIString(getAttribute(SVGNames::hrefAttr, XLinkNames::hrefAttr), document());
86
87 if (is<SVGGlyphElement>(target.element)) {
88 glyphNames.append(target.identifier);
89 return true;
90 }
91
92 if (!is<SVGAltGlyphDefElement>(target.element))
93 return false;
94
95 return downcast<SVGAltGlyphDefElement>(*target.element).hasValidGlyphElements(glyphNames);
96}
97
98}
99
100#endif
101