|
1 /* |
|
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
|
5 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. |
|
6 * (C) 2007 Rob Buis (buis@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 "ScriptableDocumentParser.h" |
|
31 #include "ScriptEventListener.h" |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 using namespace HTMLNames; |
|
36 |
|
37 inline HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser) |
|
38 : HTMLElement(tagName, document) |
|
39 , m_loading(false) |
|
40 , m_createdByParser(createdByParser) |
|
41 , m_startLineNumber(0) |
|
42 { |
|
43 ASSERT(hasTagName(styleTag)); |
|
44 if (createdByParser && document && document->scriptableDocumentParser()) |
|
45 m_startLineNumber = document->scriptableDocumentParser()->lineNumber(); |
|
46 } |
|
47 |
|
48 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(const QualifiedName& tagName, Document* document, bool createdByParser) |
|
49 { |
|
50 return adoptRef(new HTMLStyleElement(tagName, document, createdByParser)); |
|
51 } |
|
52 |
|
53 void HTMLStyleElement::parseMappedAttribute(Attribute* attr) |
|
54 { |
|
55 if (attr->name() == titleAttr && m_sheet) |
|
56 m_sheet->setTitle(attr->value()); |
|
57 else if (attr->name() == onbeforeprocessAttr) |
|
58 setAttributeEventListener(eventNames().beforeprocessEvent, createAttributeEventListener(this, attr)); |
|
59 else |
|
60 HTMLElement::parseMappedAttribute(attr); |
|
61 } |
|
62 |
|
63 void HTMLStyleElement::finishParsingChildren() |
|
64 { |
|
65 StyleElement::process(this, m_startLineNumber); |
|
66 StyleElement::sheet(this); |
|
67 m_createdByParser = false; |
|
68 HTMLElement::finishParsingChildren(); |
|
69 } |
|
70 |
|
71 void HTMLStyleElement::insertedIntoDocument() |
|
72 { |
|
73 HTMLElement::insertedIntoDocument(); |
|
74 |
|
75 document()->addStyleSheetCandidateNode(this, m_createdByParser); |
|
76 if (!m_createdByParser) |
|
77 StyleElement::insertedIntoDocument(document(), this); |
|
78 } |
|
79 |
|
80 void HTMLStyleElement::removedFromDocument() |
|
81 { |
|
82 HTMLElement::removedFromDocument(); |
|
83 document()->removeStyleSheetCandidateNode(this); |
|
84 StyleElement::removedFromDocument(document()); |
|
85 } |
|
86 |
|
87 void HTMLStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) |
|
88 { |
|
89 if (!changedByParser) |
|
90 StyleElement::process(this, 0); |
|
91 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); |
|
92 } |
|
93 |
|
94 StyleSheet* HTMLStyleElement::sheet() |
|
95 { |
|
96 return StyleElement::sheet(this); |
|
97 } |
|
98 |
|
99 bool HTMLStyleElement::isLoading() const |
|
100 { |
|
101 if (m_loading) |
|
102 return true; |
|
103 if (!m_sheet) |
|
104 return false; |
|
105 return static_cast<CSSStyleSheet *>(m_sheet.get())->isLoading(); |
|
106 } |
|
107 |
|
108 bool HTMLStyleElement::sheetLoaded() |
|
109 { |
|
110 if (!isLoading()) { |
|
111 document()->removePendingSheet(); |
|
112 return true; |
|
113 } |
|
114 return false; |
|
115 } |
|
116 |
|
117 const AtomicString& HTMLStyleElement::media() const |
|
118 { |
|
119 return getAttribute(mediaAttr); |
|
120 } |
|
121 |
|
122 const AtomicString& HTMLStyleElement::type() const |
|
123 { |
|
124 return getAttribute(typeAttr); |
|
125 } |
|
126 |
|
127 void HTMLStyleElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const |
|
128 { |
|
129 HTMLElement::addSubresourceAttributeURLs(urls); |
|
130 |
|
131 if (StyleSheet* styleSheet = const_cast<HTMLStyleElement*>(this)->sheet()) |
|
132 styleSheet->addSubresourceStyleURLs(urls); |
|
133 } |
|
134 |
|
135 } |