OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007 Rob Buis | 2 * Copyright (C) 2006, 2007 Rob Buis |
3 * Copyright (C) 2008 Apple, Inc. All rights reserved. | 3 * Copyright (C) 2008 Apple, Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 void StyleElement::process(Element* element) | 108 void StyleElement::process(Element* element) |
109 { | 109 { |
110 if (!element || !element->inDocument()) | 110 if (!element || !element->inDocument()) |
111 return; | 111 return; |
112 createSheet(element, element->textFromChildren()); | 112 createSheet(element, element->textFromChildren()); |
113 } | 113 } |
114 | 114 |
115 void StyleElement::clearSheet() | 115 void StyleElement::clearSheet() |
116 { | 116 { |
117 ASSERT(m_sheet); | 117 ASSERT(m_sheet); |
| 118 |
118 m_sheet.release()->clearOwnerNode(); | 119 m_sheet.release()->clearOwnerNode(); |
119 } | 120 } |
120 | 121 |
121 void StyleElement::createSheet(Element* e, const String& text) | 122 void StyleElement::createSheet(Element* e, const String& text) |
122 { | 123 { |
123 ASSERT(e); | 124 ASSERT(e); |
124 ASSERT(e->inDocument()); | 125 ASSERT(e->inDocument()); |
125 Document& document = e->document(); | 126 Document& document = e->document(); |
126 if (m_sheet) { | 127 if (m_sheet) { |
127 if (m_sheet->isLoading()) | 128 if (m_sheet->isLoading()) |
128 document.styleEngine()->removePendingSheet(e); | 129 document.styleEngine()->removePendingSheet(e); |
129 clearSheet(); | 130 clearSheet(); |
130 } | 131 } |
131 | 132 |
132 // If type is empty or CSS, this is a CSS style sheet. | 133 // If type is empty or CSS, this is a CSS style sheet. |
133 const AtomicString& type = this->type(); | 134 const AtomicString& type = this->type(); |
134 bool passesContentSecurityPolicyChecks = document.contentSecurityPolicy()->a
llowStyleNonce(e->fastGetAttribute(HTMLNames::nonceAttr)) || document.contentSec
urityPolicy()->allowInlineStyle(e->document().url(), m_startPosition.m_line); | 135 bool passesContentSecurityPolicyChecks = document.contentSecurityPolicy()->a
llowStyleNonce(e->fastGetAttribute(HTMLNames::nonceAttr)) || document.contentSec
urityPolicy()->allowInlineStyle(e->document().url(), m_startPosition.m_line); |
135 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { | 136 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { |
136 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); | 137 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); |
137 | 138 |
138 MediaQueryEvaluator screenEval("screen", true); | 139 MediaQueryEvaluator screenEval("screen", true); |
139 MediaQueryEvaluator printEval("print", true); | 140 MediaQueryEvaluator printEval("print", true); |
140 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { | 141 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { |
141 document.styleEngine()->addPendingSheet(); | |
142 m_loading = true; | 142 m_loading = true; |
143 | |
144 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; | 143 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; |
145 m_sheet = CSSStyleSheet::createInline(e, KURL(), startPosition, docu
ment.inputEncoding()); | 144 m_sheet = StyleEngine::createSheet(e, text, startPosition, m_created
ByParser); |
146 m_sheet->setMediaQueries(mediaQueries.release()); | 145 m_sheet->setMediaQueries(mediaQueries.release()); |
147 m_sheet->setTitle(e->title()); | |
148 m_sheet->contents()->parseStringAtPosition(text, startPosition, m_cr
eatedByParser); | |
149 | |
150 m_loading = false; | 146 m_loading = false; |
151 } | 147 } |
152 } | 148 } |
153 | 149 |
154 if (m_sheet) | 150 if (m_sheet) |
155 m_sheet->contents()->checkLoaded(); | 151 m_sheet->contents()->checkLoadedFor(e); |
156 } | 152 } |
157 | 153 |
158 bool StyleElement::isLoading() const | 154 bool StyleElement::isLoading() const |
159 { | 155 { |
160 if (m_loading) | 156 if (m_loading) |
161 return true; | 157 return true; |
162 return m_sheet ? m_sheet->isLoading() : false; | 158 return m_sheet ? m_sheet->isLoading() : false; |
163 } | 159 } |
164 | 160 |
165 bool StyleElement::sheetLoaded(Document& document) | 161 bool StyleElement::sheetLoaded(Document& document) |
166 { | 162 { |
167 if (isLoading()) | 163 if (isLoading()) |
168 return false; | 164 return false; |
169 | 165 |
170 document.styleEngine()->removePendingSheet(m_sheet->ownerNode()); | 166 document.styleEngine()->removePendingSheet(m_sheet->ownerNode()); |
171 return true; | 167 return true; |
172 } | 168 } |
173 | 169 |
174 void StyleElement::startLoadingDynamicSheet(Document& document) | 170 void StyleElement::startLoadingDynamicSheet(Document& document) |
175 { | 171 { |
176 document.styleEngine()->addPendingSheet(); | 172 document.styleEngine()->addPendingSheet(); |
177 } | 173 } |
178 | 174 |
179 } | 175 } |
OLD | NEW |