initial import
[vuplus_webkit] / Source / WebCore / svg / SVGGlyphRefElement.cpp
1 /*
2  * Copyright (C) 2011 Leo Yang <leoyang@webkit.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "config.h"
21
22 #if ENABLE(SVG) && ENABLE(SVG_FONTS)
23 #include "SVGGlyphRefElement.h"
24
25 #include "SVGGlyphElement.h"
26 #include "SVGNames.h"
27 #include "SVGParserUtilities.h"
28 #include "XLinkNames.h"
29 #include <wtf/text/AtomicString.h>
30
31 namespace WebCore {
32
33 // Animated property definitions
34 DEFINE_ANIMATED_STRING(SVGGlyphRefElement, XLinkNames::hrefAttr, Href, href)
35
36 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGGlyphRefElement)
37     REGISTER_LOCAL_ANIMATED_PROPERTY(href)
38     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledElement)
39 END_REGISTER_ANIMATED_PROPERTIES
40
41 inline SVGGlyphRefElement::SVGGlyphRefElement(const QualifiedName& tagName, Document* document)
42     : SVGStyledElement(tagName, document)
43     , m_x(0)
44     , m_y(0)
45     , m_dx(0)
46     , m_dy(0)
47 {
48     ASSERT(hasTagName(SVGNames::glyphRefTag));
49     registerAnimatedPropertiesForSVGGlyphRefElement();
50 }
51
52 PassRefPtr<SVGGlyphRefElement> SVGGlyphRefElement::create(const QualifiedName& tagName, Document* document)
53 {
54     return adoptRef(new SVGGlyphRefElement(tagName, document));
55 }
56
57 bool SVGGlyphRefElement::hasValidGlyphElement(String& glyphName) const
58 {
59     // FIXME: We only support xlink:href so far.
60     // https://bugs.webkit.org/show_bug.cgi?id=64787
61     Element* element = targetElementFromIRIString(fastGetAttribute(XLinkNames::hrefAttr), document(), &glyphName);
62     if (!element || !element->hasTagName(SVGNames::glyphTag))
63         return false;
64     return true;
65 }
66
67 void SVGGlyphRefElement::parseMappedAttribute(Attribute* attr)
68 {
69     const UChar* startPtr = attr->value().characters();
70     const UChar* endPtr = startPtr + attr->value().length();
71
72     // FIXME: We need some error handling here.
73     if (attr->name() == SVGNames::xAttr)
74         parseNumber(startPtr, endPtr, m_x);
75     else if (attr->name() == SVGNames::yAttr)
76         parseNumber(startPtr, endPtr, m_y);
77     else if (attr->name() == SVGNames::dxAttr)
78         parseNumber(startPtr, endPtr, m_dx);
79     else if (attr->name() == SVGNames::dyAttr)
80         parseNumber(startPtr, endPtr, m_dy);
81     else {
82         if (SVGURIReference::parseMappedAttribute(attr))
83             return;
84         SVGStyledElement::parseMappedAttribute(attr);
85     }
86 }
87
88 const AtomicString& SVGGlyphRefElement::glyphRef() const
89 {
90     return fastGetAttribute(SVGNames::glyphRefAttr);
91 }
92
93 void SVGGlyphRefElement::setGlyphRef(const AtomicString&, ExceptionCode&)
94 {
95     // FIXME: Set and honor attribute change.
96     // https://bugs.webkit.org/show_bug.cgi?id=64787
97 }
98
99 void SVGGlyphRefElement::setX(float x, ExceptionCode&)
100 {
101     // FIXME: Honor attribute change.
102     // https://bugs.webkit.org/show_bug.cgi?id=64787
103     m_x = x;
104 }
105
106 void SVGGlyphRefElement::setY(float y , ExceptionCode&)
107 {
108     // FIXME: Honor attribute change.
109     // https://bugs.webkit.org/show_bug.cgi?id=64787
110     m_y = y;
111 }
112
113 void SVGGlyphRefElement::setDx(float dx, ExceptionCode&)
114 {
115     // FIXME: Honor attribute change.
116     // https://bugs.webkit.org/show_bug.cgi?id=64787
117     m_dx = dx;
118 }
119
120 void SVGGlyphRefElement::setDy(float dy, ExceptionCode&)
121 {
122     // FIXME: Honor attribute change.
123     // https://bugs.webkit.org/show_bug.cgi?id=64787
124     m_dy = dy;
125 }
126
127 }
128
129 #endif