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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #endif | 61 #endif |
62 } | 62 } |
63 | 63 |
64 void StyleElement::processStyleSheet(Document& document, Element* element) | 64 void StyleElement::processStyleSheet(Document& document, Element* element) |
65 { | 65 { |
66 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); | 66 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); |
67 ASSERT(element); | 67 ASSERT(element); |
68 ASSERT(element->inDocument()); | 68 ASSERT(element->inDocument()); |
69 | 69 |
70 m_registeredAsCandidate = true; | 70 m_registeredAsCandidate = true; |
71 document.styleEngine()->addStyleSheetCandidateNode(element, m_createdByParse
r); | 71 document.styleEngine().addStyleSheetCandidateNode(element, m_createdByParser
); |
72 if (m_createdByParser) | 72 if (m_createdByParser) |
73 return; | 73 return; |
74 | 74 |
75 process(element); | 75 process(element); |
76 } | 76 } |
77 | 77 |
78 void StyleElement::insertedInto(Element* element, ContainerNode* insertionPoint) | 78 void StyleElement::insertedInto(Element* element, ContainerNode* insertionPoint) |
79 { | 79 { |
80 if (!insertionPoint->inDocument() || !element->isInShadowTree()) | 80 if (!insertionPoint->inDocument() || !element->isInShadowTree()) |
81 return; | 81 return; |
82 if (ShadowRoot* scope = element->containingShadowRoot()) | 82 if (ShadowRoot* scope = element->containingShadowRoot()) |
83 scope->registerScopedHTMLStyleChild(); | 83 scope->registerScopedHTMLStyleChild(); |
84 } | 84 } |
85 | 85 |
86 void StyleElement::removedFrom(Element* element, ContainerNode* insertionPoint) | 86 void StyleElement::removedFrom(Element* element, ContainerNode* insertionPoint) |
87 { | 87 { |
88 if (!insertionPoint->inDocument()) | 88 if (!insertionPoint->inDocument()) |
89 return; | 89 return; |
90 | 90 |
91 ShadowRoot* shadowRoot = element->containingShadowRoot(); | 91 ShadowRoot* shadowRoot = element->containingShadowRoot(); |
92 if (!shadowRoot) | 92 if (!shadowRoot) |
93 shadowRoot = insertionPoint->containingShadowRoot(); | 93 shadowRoot = insertionPoint->containingShadowRoot(); |
94 | 94 |
95 if (shadowRoot) | 95 if (shadowRoot) |
96 shadowRoot->unregisterScopedHTMLStyleChild(); | 96 shadowRoot->unregisterScopedHTMLStyleChild(); |
97 | 97 |
98 Document& document = element->document(); | 98 Document& document = element->document(); |
99 if (m_registeredAsCandidate) { | 99 if (m_registeredAsCandidate) { |
100 document.styleEngine()->removeStyleSheetCandidateNode(element, shadowRoo
t ? *toTreeScope(shadowRoot) : toTreeScope(document)); | 100 document.styleEngine().removeStyleSheetCandidateNode(element, shadowRoot
? *toTreeScope(shadowRoot) : toTreeScope(document)); |
101 m_registeredAsCandidate = false; | 101 m_registeredAsCandidate = false; |
102 } | 102 } |
103 | 103 |
104 RefPtrWillBeRawPtr<StyleSheet> removedSheet = m_sheet.get(); | 104 RefPtrWillBeRawPtr<StyleSheet> removedSheet = m_sheet.get(); |
105 | 105 |
106 if (m_sheet) | 106 if (m_sheet) |
107 clearSheet(element); | 107 clearSheet(element); |
108 if (removedSheet) | 108 if (removedSheet) |
109 document.removedStyleSheet(removedSheet.get(), AnalyzedStyleUpdate); | 109 document.removedStyleSheet(removedSheet.get(), AnalyzedStyleUpdate); |
110 } | 110 } |
111 | 111 |
112 void StyleElement::clearDocumentData(Document& document, Element* element) | 112 void StyleElement::clearDocumentData(Document& document, Element* element) |
113 { | 113 { |
114 if (m_sheet) | 114 if (m_sheet) |
115 m_sheet->clearOwnerNode(); | 115 m_sheet->clearOwnerNode(); |
116 | 116 |
117 if (element->inDocument()) { | 117 if (element->inDocument()) { |
118 // HTMLLinkElement in shadow tree is not supported. | 118 // HTMLLinkElement in shadow tree is not supported. |
119 TreeScope& treeScope = isHTMLStyleElement(element) || isSVGStyleElement(
element) ? element->treeScope() : element->document(); | 119 TreeScope& treeScope = isHTMLStyleElement(element) || isSVGStyleElement(
element) ? element->treeScope() : element->document(); |
120 document.styleEngine()->removeStyleSheetCandidateNode(element, treeScope
); | 120 document.styleEngine().removeStyleSheetCandidateNode(element, treeScope)
; |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 void StyleElement::childrenChanged(Element* element) | 124 void StyleElement::childrenChanged(Element* element) |
125 { | 125 { |
126 ASSERT(element); | 126 ASSERT(element); |
127 if (m_createdByParser) | 127 if (m_createdByParser) |
128 return; | 128 return; |
129 | 129 |
130 process(element); | 130 process(element); |
(...skipping 11 matching lines...) Expand all Loading... |
142 if (!element || !element->inDocument()) | 142 if (!element || !element->inDocument()) |
143 return; | 143 return; |
144 createSheet(element, element->textFromChildren()); | 144 createSheet(element, element->textFromChildren()); |
145 } | 145 } |
146 | 146 |
147 void StyleElement::clearSheet(Element* ownerElement) | 147 void StyleElement::clearSheet(Element* ownerElement) |
148 { | 148 { |
149 ASSERT(m_sheet); | 149 ASSERT(m_sheet); |
150 | 150 |
151 if (ownerElement && m_sheet->isLoading()) | 151 if (ownerElement && m_sheet->isLoading()) |
152 ownerElement->document().styleEngine()->removePendingSheet(ownerElement)
; | 152 ownerElement->document().styleEngine().removePendingSheet(ownerElement); |
153 | 153 |
154 m_sheet.release()->clearOwnerNode(); | 154 m_sheet.release()->clearOwnerNode(); |
155 } | 155 } |
156 | 156 |
157 static bool shouldBypassMainWorldCSP(Element* element) | 157 static bool shouldBypassMainWorldCSP(Element* element) |
158 { | 158 { |
159 // Main world CSP is bypassed within an isolated world. | 159 // Main world CSP is bypassed within an isolated world. |
160 LocalFrame* frame = element->document().frame(); | 160 LocalFrame* frame = element->document().frame(); |
161 if (frame && frame->script().shouldBypassMainWorldCSP()) | 161 if (frame && frame->script().shouldBypassMainWorldCSP()) |
162 return true; | 162 return true; |
(...skipping 23 matching lines...) Expand all Loading... |
186 // If type is empty or CSS, this is a CSS style sheet. | 186 // If type is empty or CSS, this is a CSS style sheet. |
187 const AtomicString& type = this->type(); | 187 const AtomicString& type = this->type(); |
188 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { | 188 if (isCSS(e, type) && passesContentSecurityPolicyChecks) { |
189 RefPtrWillBeRawPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(m
edia()); | 189 RefPtrWillBeRawPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(m
edia()); |
190 | 190 |
191 MediaQueryEvaluator screenEval("screen", true); | 191 MediaQueryEvaluator screenEval("screen", true); |
192 MediaQueryEvaluator printEval("print", true); | 192 MediaQueryEvaluator printEval("print", true); |
193 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { | 193 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { |
194 m_loading = true; | 194 m_loading = true; |
195 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; | 195 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; |
196 m_sheet = document.styleEngine()->createSheet(e, text, startPosition
, m_createdByParser); | 196 m_sheet = document.styleEngine().createSheet(e, text, startPosition,
m_createdByParser); |
197 m_sheet->setMediaQueries(mediaQueries.release()); | 197 m_sheet->setMediaQueries(mediaQueries.release()); |
198 m_loading = false; | 198 m_loading = false; |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 if (m_sheet) | 202 if (m_sheet) |
203 m_sheet->contents()->checkLoaded(); | 203 m_sheet->contents()->checkLoaded(); |
204 } | 204 } |
205 | 205 |
206 bool StyleElement::isLoading() const | 206 bool StyleElement::isLoading() const |
207 { | 207 { |
208 if (m_loading) | 208 if (m_loading) |
209 return true; | 209 return true; |
210 return m_sheet ? m_sheet->isLoading() : false; | 210 return m_sheet ? m_sheet->isLoading() : false; |
211 } | 211 } |
212 | 212 |
213 bool StyleElement::sheetLoaded(Document& document) | 213 bool StyleElement::sheetLoaded(Document& document) |
214 { | 214 { |
215 if (isLoading()) | 215 if (isLoading()) |
216 return false; | 216 return false; |
217 | 217 |
218 document.styleEngine()->removePendingSheet(m_sheet->ownerNode()); | 218 document.styleEngine().removePendingSheet(m_sheet->ownerNode()); |
219 return true; | 219 return true; |
220 } | 220 } |
221 | 221 |
222 void StyleElement::startLoadingDynamicSheet(Document& document) | 222 void StyleElement::startLoadingDynamicSheet(Document& document) |
223 { | 223 { |
224 document.styleEngine()->addPendingSheet(); | 224 document.styleEngine().addPendingSheet(); |
225 } | 225 } |
226 | 226 |
227 DEFINE_TRACE(StyleElement) | 227 DEFINE_TRACE(StyleElement) |
228 { | 228 { |
229 visitor->trace(m_sheet); | 229 visitor->trace(m_sheet); |
230 } | 230 } |
231 | 231 |
232 } | 232 } |
OLD | NEW |