2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2009 Apple Inc. All rights reserved.
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.
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.
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.
24 #include "core/svg/SVGFontFaceUriElement.h"
26 #include "core/XLinkNames.h"
27 #include "core/css/CSSFontFaceSrcValue.h"
28 #include "core/dom/Document.h"
29 #include "core/fetch/FetchRequest.h"
30 #include "core/fetch/ResourceFetcher.h"
31 #include "core/svg/SVGFontFaceElement.h"
35 using namespace SVGNames;
37 inline SVGFontFaceUriElement::SVGFontFaceUriElement(Document& document)
38 : SVGElement(font_face_uriTag, document)
42 DEFINE_NODE_FACTORY(SVGFontFaceUriElement)
44 SVGFontFaceUriElement::~SVGFontFaceUriElement()
47 m_resource->removeClient(this);
50 PassRefPtrWillBeRawPtr<CSSFontFaceSrcValue> SVGFontFaceUriElement::srcValue() const
52 RefPtrWillBeRawPtr<CSSFontFaceSrcValue> src = CSSFontFaceSrcValue::create(getAttribute(XLinkNames::hrefAttr));
53 AtomicString value(fastGetAttribute(formatAttr));
54 src->setFormat(value.isEmpty() ? AtomicString("svg", AtomicString::ConstructFromLiteral) : value); // Default format
58 void SVGFontFaceUriElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
60 if (name.matches(XLinkNames::hrefAttr))
63 SVGElement::parseAttribute(name, value);
66 void SVGFontFaceUriElement::childrenChanged(const ChildrenChange& change)
68 SVGElement::childrenChanged(change);
70 if (!isSVGFontFaceSrcElement(parentNode()))
73 ContainerNode* grandparent = parentNode()->parentNode();
74 if (isSVGFontFaceElement(grandparent))
75 toSVGFontFaceElement(*grandparent).rebuildFontFace();
78 Node::InsertionNotificationRequest SVGFontFaceUriElement::insertedInto(ContainerNode* rootParent)
81 return SVGElement::insertedInto(rootParent);
84 void SVGFontFaceUriElement::loadFont()
87 m_resource->removeClient(this);
89 const AtomicString& href = getAttribute(XLinkNames::hrefAttr);
91 ResourceFetcher* fetcher = document().fetcher();
92 FetchRequest request(ResourceRequest(document().completeURL(href)), localName());
93 m_resource = fetcher->fetchFont(request);
95 m_resource->addClient(this);
96 m_resource->beginLoadIfNeeded(fetcher);
105 #endif // ENABLE(SVG_FONTS)