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 Apple Computer, Inc. 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 "Document.h" 28 #include "HTMLNames.h" 29 #include "MappedAttribute.h" 30 31 namespace WebCore { 32 33 using namespace HTMLNames; 34 35 HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* doc, bool createdByParser) 36 : HTMLElement(tagName, doc) 37 , m_loading(false) 38 , m_createdByParser(createdByParser) 39 { 40 ASSERT(hasTagName(styleTag)); 41 } 42 43 // other stuff... 44 void HTMLStyleElement::parseMappedAttribute(MappedAttribute *attr) 45 { 46 if (attr->name() == mediaAttr) 47 m_media = attr->value().string().lower(); 48 else if (attr->name() == titleAttr && m_sheet) 49 m_sheet->setTitle(attr->value()); 50 else 51 HTMLElement::parseMappedAttribute(attr); 52 } 53 54 void HTMLStyleElement::finishParsingChildren() 55 { 56 StyleElement::process(this); 57 StyleElement::sheet(this); 58 m_createdByParser = false; 59 HTMLElement::finishParsingChildren(); 60 } 61 62 void HTMLStyleElement::insertedIntoDocument() 63 { 64 HTMLElement::insertedIntoDocument(); 65 66 document()->addStyleSheetCandidateNode(this, m_createdByParser); 67 if (!m_createdByParser) 68 StyleElement::insertedIntoDocument(document(), this); 69 } 70 71 void HTMLStyleElement::removedFromDocument() 72 { 73 HTMLElement::removedFromDocument(); 74 document()->removeStyleSheetCandidateNode(this); 75 StyleElement::removedFromDocument(document()); 76 } 77 78 void HTMLStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 79 { 80 if (!changedByParser) 81 StyleElement::process(this); 82 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 83 } 84 85 StyleSheet* HTMLStyleElement::sheet() 86 { 87 return StyleElement::sheet(this); 88 } 89 90 bool HTMLStyleElement::isLoading() const 91 { 92 if (m_loading) 93 return true; 94 if (!m_sheet) 95 return false; 96 return static_cast<CSSStyleSheet *>(m_sheet.get())->isLoading(); 97 } 98 99 bool HTMLStyleElement::sheetLoaded() 100 { 101 if (!isLoading()) { 102 document()->removePendingSheet(); 103 return true; 104 } 105 return false; 106 } 107 108 bool HTMLStyleElement::disabled() const 109 { 110 return !getAttribute(disabledAttr).isNull(); 111 } 112 113 void HTMLStyleElement::setDisabled(bool disabled) 114 { 115 setAttribute(disabledAttr, disabled ? "" : 0); 116 } 117 118 const AtomicString& HTMLStyleElement::media() const 119 { 120 return getAttribute(mediaAttr); 121 } 122 123 void HTMLStyleElement::setMedia(const AtomicString &value) 124 { 125 setAttribute(mediaAttr, value); 126 } 127 128 const AtomicString& HTMLStyleElement::type() const 129 { 130 return getAttribute(typeAttr); 131 } 132 133 void HTMLStyleElement::setType(const AtomicString &value) 134 { 135 setAttribute(typeAttr, value); 136 } 137 138 void HTMLStyleElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const 139 { 140 HTMLElement::addSubresourceAttributeURLs(urls); 141 142 if (StyleSheet* styleSheet = const_cast<HTMLStyleElement*>(this)->sheet()) 143 styleSheet->addSubresourceStyleURLs(urls); 144 } 145 146 } 147