1/* 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 * Copyright (C) 2006 Apple Inc. All rights reserved. 5 * Copyright (C) 2009 Cameron McCormack <cam@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#include "core/svg/SVGStyleElement.h" 25 26#include "core/css/CSSStyleSheet.h" 27#include "wtf/StdLibExtras.h" 28 29namespace WebCore { 30 31inline SVGStyleElement::SVGStyleElement(Document& document, bool createdByParser) 32 : SVGElement(SVGNames::styleTag, document) 33 , StyleElement(&document, createdByParser) 34 , m_svgLoadEventTimer(this, &SVGElement::svgLoadEventTimerFired) 35{ 36 ScriptWrappable::init(this); 37} 38 39SVGStyleElement::~SVGStyleElement() 40{ 41 StyleElement::clearDocumentData(document(), this); 42} 43 44PassRefPtr<SVGStyleElement> SVGStyleElement::create(Document& document, bool createdByParser) 45{ 46 return adoptRef(new SVGStyleElement(document, createdByParser)); 47} 48 49bool SVGStyleElement::disabled() const 50{ 51 if (!m_sheet) 52 return false; 53 54 return m_sheet->disabled(); 55} 56 57void SVGStyleElement::setDisabled(bool setDisabled) 58{ 59 if (CSSStyleSheet* styleSheet = sheet()) 60 styleSheet->setDisabled(setDisabled); 61} 62 63const AtomicString& SVGStyleElement::type() const 64{ 65 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css", AtomicString::ConstructFromLiteral)); 66 const AtomicString& n = getAttribute(SVGNames::typeAttr); 67 return n.isNull() ? defaultValue : n; 68} 69 70void SVGStyleElement::setType(const AtomicString& type) 71{ 72 setAttribute(SVGNames::typeAttr, type); 73} 74 75const AtomicString& SVGStyleElement::media() const 76{ 77 DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("all", AtomicString::ConstructFromLiteral)); 78 const AtomicString& n = fastGetAttribute(SVGNames::mediaAttr); 79 return n.isNull() ? defaultValue : n; 80} 81 82void SVGStyleElement::setMedia(const AtomicString& media) 83{ 84 setAttribute(SVGNames::mediaAttr, media); 85} 86 87String SVGStyleElement::title() const 88{ 89 return fastGetAttribute(SVGNames::titleAttr); 90} 91 92void SVGStyleElement::setTitle(const AtomicString& title) 93{ 94 setAttribute(SVGNames::titleAttr, title); 95} 96 97bool SVGStyleElement::isSupportedAttribute(const QualifiedName& attrName) 98{ 99 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 100 if (supportedAttributes.isEmpty()) 101 supportedAttributes.add(SVGNames::titleAttr); 102 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 103} 104 105void SVGStyleElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 106{ 107 if (!isSupportedAttribute(name)) { 108 SVGElement::parseAttribute(name, value); 109 return; 110 } 111 112 if (name == SVGNames::titleAttr) { 113 if (m_sheet) 114 m_sheet->setTitle(value); 115 return; 116 } 117 118 ASSERT_NOT_REACHED(); 119} 120 121void SVGStyleElement::finishParsingChildren() 122{ 123 StyleElement::finishParsingChildren(this); 124 SVGElement::finishParsingChildren(); 125} 126 127Node::InsertionNotificationRequest SVGStyleElement::insertedInto(ContainerNode* rootParent) 128{ 129 SVGElement::insertedInto(rootParent); 130 return InsertionShouldCallDidNotifySubtreeInsertions; 131} 132 133void SVGStyleElement::didNotifySubtreeInsertionsToDocument() 134{ 135 StyleElement::processStyleSheet(document(), this); 136} 137 138void SVGStyleElement::removedFrom(ContainerNode* rootParent) 139{ 140 SVGElement::removedFrom(rootParent); 141 if (rootParent->inDocument()) 142 StyleElement::removedFromDocument(document(), this); 143} 144 145void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 146{ 147 SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 148 StyleElement::childrenChanged(this); 149} 150 151} 152