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