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 
     25 #if ENABLE(SVG)
     26 #include "SVGStyleElement.h"
     27 
     28 #include "Attribute.h"
     29 #include "CSSStyleSheet.h"
     30 #include "Document.h"
     31 #include "ExceptionCode.h"
     32 #include "SVGNames.h"
     33 #include <wtf/StdLibExtras.h>
     34 
     35 namespace WebCore {
     36 
     37 inline SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser)
     38     : SVGElement(tagName, document)
     39     , StyleElement(document, createdByParser)
     40 {
     41 }
     42 
     43 SVGStyleElement::~SVGStyleElement()
     44 {
     45     if (m_sheet)
     46         m_sheet->clearOwnerNode();
     47 }
     48 
     49 PassRefPtr<SVGStyleElement> SVGStyleElement::create(const QualifiedName& tagName, Document* document, bool createdByParser)
     50 {
     51     return adoptRef(new SVGStyleElement(tagName, document, createdByParser));
     52 }
     53 
     54 const AtomicString& SVGStyleElement::type() const
     55 {
     56     DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("text/css"));
     57     const AtomicString& n = getAttribute(SVGNames::typeAttr);
     58     return n.isNull() ? defaultValue : n;
     59 }
     60 
     61 void SVGStyleElement::setType(const AtomicString& type, ExceptionCode& ec)
     62 {
     63     setAttribute(SVGNames::typeAttr, type, ec);
     64 }
     65 
     66 const AtomicString& SVGStyleElement::media() const
     67 {
     68     DEFINE_STATIC_LOCAL(const AtomicString, defaultValue, ("all"));
     69     const AtomicString& n = getAttribute(SVGNames::mediaAttr);
     70     return n.isNull() ? defaultValue : n;
     71 }
     72 
     73 void SVGStyleElement::setMedia(const AtomicString& media, ExceptionCode& ec)
     74 {
     75     setAttribute(SVGNames::mediaAttr, media, ec);
     76 }
     77 
     78 String SVGStyleElement::title() const
     79 {
     80     return getAttribute(SVGNames::titleAttr);
     81 }
     82 
     83 void SVGStyleElement::setTitle(const AtomicString& title, ExceptionCode& ec)
     84 {
     85     setAttribute(SVGNames::titleAttr, title, ec);
     86 }
     87 
     88 void SVGStyleElement::parseMappedAttribute(Attribute* attr)
     89 {
     90     if (attr->name() == SVGNames::titleAttr && m_sheet)
     91         m_sheet->setTitle(attr->value());
     92     else {
     93         if (SVGLangSpace::parseMappedAttribute(attr))
     94             return;
     95         SVGElement::parseMappedAttribute(attr);
     96     }
     97 }
     98 
     99 void SVGStyleElement::finishParsingChildren()
    100 {
    101     StyleElement::finishParsingChildren(this);
    102     SVGElement::finishParsingChildren();
    103 }
    104 
    105 void SVGStyleElement::insertedIntoDocument()
    106 {
    107     SVGElement::insertedIntoDocument();
    108     StyleElement::insertedIntoDocument(document(), this);
    109 }
    110 
    111 void SVGStyleElement::removedFromDocument()
    112 {
    113     SVGElement::removedFromDocument();
    114     StyleElement::removedFromDocument(document(), this);
    115 }
    116 
    117 void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
    118 {
    119     StyleElement::childrenChanged(this);
    120     SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
    121 }
    122 
    123 }
    124 
    125 #endif // ENABLE(SVG)
    126