Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2001 Dirk Mueller (mueller (at) kde.org)
      5  * Copyright (C) 2003, 2010 Apple Inc. All rights reserved.
      6  *           (C) 2007 Rob Buis (buis (at) kde.org)
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  */
     23 
     24 #include "config.h"
     25 #include "HTMLStyleElement.h"
     26 
     27 #include "Attribute.h"
     28 #include "Document.h"
     29 #include "HTMLNames.h"
     30 #include "ScriptEventListener.h"
     31 #include "ScriptableDocumentParser.h"
     32 
     33 
     34 namespace WebCore {
     35 
     36 using namespace HTMLNames;
     37 
     38 inline HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser)
     39     : HTMLElement(tagName, document)
     40     , StyleElement(document, createdByParser)
     41 {
     42     ASSERT(hasTagName(styleTag));
     43 }
     44 
     45 HTMLStyleElement::~HTMLStyleElement()
     46 {
     47     if (m_sheet)
     48         m_sheet->clearOwnerNode();
     49 }
     50 
     51 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(const QualifiedName& tagName, Document* document, bool createdByParser)
     52 {
     53     return adoptRef(new HTMLStyleElement(tagName, document, createdByParser));
     54 }
     55 
     56 void HTMLStyleElement::parseMappedAttribute(Attribute* attr)
     57 {
     58     if (attr->name() == titleAttr && m_sheet)
     59         m_sheet->setTitle(attr->value());
     60     else if (attr->name() == onbeforeprocessAttr)
     61         setAttributeEventListener(eventNames().beforeprocessEvent, createAttributeEventListener(this, attr));
     62     else
     63         HTMLElement::parseMappedAttribute(attr);
     64 }
     65 
     66 void HTMLStyleElement::finishParsingChildren()
     67 {
     68     StyleElement::finishParsingChildren(this);
     69     HTMLElement::finishParsingChildren();
     70 }
     71 
     72 void HTMLStyleElement::insertedIntoDocument()
     73 {
     74     HTMLElement::insertedIntoDocument();
     75     StyleElement::insertedIntoDocument(document(), this);
     76 }
     77 
     78 void HTMLStyleElement::removedFromDocument()
     79 {
     80     HTMLElement::removedFromDocument();
     81     StyleElement::removedFromDocument(document(), this);
     82 }
     83 
     84 void HTMLStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
     85 {
     86     StyleElement::childrenChanged(this);
     87     HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
     88 }
     89 
     90 const AtomicString& HTMLStyleElement::media() const
     91 {
     92     return getAttribute(mediaAttr);
     93 }
     94 
     95 const AtomicString& HTMLStyleElement::type() const
     96 {
     97     return getAttribute(typeAttr);
     98 }
     99 
    100 void HTMLStyleElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
    101 {
    102     HTMLElement::addSubresourceAttributeURLs(urls);
    103 
    104     if (StyleSheet* styleSheet = const_cast<HTMLStyleElement*>(this)->sheet())
    105         styleSheet->addSubresourceStyleURLs(urls);
    106 }
    107 
    108 bool HTMLStyleElement::disabled() const
    109 {
    110     StyleSheet* styleSheet = sheet();
    111     if (!styleSheet)
    112         return false;
    113 
    114     return styleSheet->disabled();
    115 }
    116 
    117 void HTMLStyleElement::setDisabled(bool setDisabled)
    118 {
    119     if (StyleSheet* styleSheet = sheet())
    120         styleSheet->setDisabled(setDisabled);
    121 }
    122 
    123 }
    124