1 /* 2 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox (at) kde.org> 3 2004, 2005, 2006, 2007 Rob Buis <buis (at) kde.org> 4 Copyright (C) 2006 Apple Computer, Inc. 5 Copyright (C) 2009 Cameron McCormack <cam (at) mcc.id.au> 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) 26 #include "SVGStyleElement.h" 27 28 #include "CSSStyleSheet.h" 29 #include "Document.h" 30 #include "ExceptionCode.h" 31 #include "MappedAttribute.h" 32 #include "SVGNames.h" 33 #include <wtf/StdLibExtras.h> 34 35 namespace WebCore { 36 37 using namespace SVGNames; 38 39 SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* doc, bool createdByParser) 40 : SVGElement(tagName, doc) 41 , SVGLangSpace() 42 , m_createdByParser(createdByParser) 43 { 44 } 45 46 const AtomicString& SVGStyleElement::type() const 47 { 48 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css")); 49 const AtomicString& n = getAttribute(SVGNames::typeAttr); 50 return n.isNull() ? defaultValue : n; 51 } 52 53 void SVGStyleElement::setType(const AtomicString& type, ExceptionCode& ec) 54 { 55 setAttribute(SVGNames::typeAttr, type, ec); 56 } 57 58 const AtomicString& SVGStyleElement::media() const 59 { 60 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("all")); 61 const AtomicString& n = getAttribute(SVGNames::mediaAttr); 62 return n.isNull() ? defaultValue : n; 63 } 64 65 void SVGStyleElement::setMedia(const AtomicString& media, ExceptionCode& ec) 66 { 67 setAttribute(SVGNames::mediaAttr, media, ec); 68 } 69 70 String SVGStyleElement::title() const 71 { 72 return getAttribute(SVGNames::titleAttr); 73 } 74 75 void SVGStyleElement::setTitle(const AtomicString& title, ExceptionCode& ec) 76 { 77 setAttribute(SVGNames::titleAttr, title, ec); 78 } 79 80 void SVGStyleElement::parseMappedAttribute(MappedAttribute* attr) 81 { 82 if (attr->name() == SVGNames::titleAttr && m_sheet) 83 m_sheet->setTitle(attr->value()); 84 else { 85 if (SVGLangSpace::parseMappedAttribute(attr)) 86 return; 87 SVGElement::parseMappedAttribute(attr); 88 } 89 } 90 91 void SVGStyleElement::finishParsingChildren() 92 { 93 StyleElement::sheet(this); 94 m_createdByParser = false; 95 SVGElement::finishParsingChildren(); 96 } 97 98 void SVGStyleElement::insertedIntoDocument() 99 { 100 SVGElement::insertedIntoDocument(); 101 document()->addStyleSheetCandidateNode(this, m_createdByParser); 102 if (!m_createdByParser) 103 StyleElement::insertedIntoDocument(document(), this); 104 } 105 106 void SVGStyleElement::removedFromDocument() 107 { 108 SVGElement::removedFromDocument(); 109 if (document()->renderer()) 110 document()->removeStyleSheetCandidateNode(this); 111 StyleElement::removedFromDocument(document()); 112 } 113 114 void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 115 { 116 SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 117 StyleElement::process(this); 118 } 119 120 StyleSheet* SVGStyleElement::sheet() 121 { 122 return StyleElement::sheet(this); 123 } 124 125 bool SVGStyleElement::sheetLoaded() 126 { 127 document()->removePendingSheet(); 128 return true; 129 } 130 131 } 132 133 // vim:ts=4:noet 134 #endif // ENABLE(SVG) 135