OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) | 174 void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) |
175 { | 175 { |
176 ASSERT(!cssSheet.disabled()); | 176 ASSERT(!cssSheet.disabled()); |
177 if (cssSheet.mediaQueries() && !m_medium->eval(cssSheet.mediaQueries(), &m_v
iewportDependentMediaQueryResults)) | 177 if (cssSheet.mediaQueries() && !m_medium->eval(cssSheet.mediaQueries(), &m_v
iewportDependentMediaQueryResults)) |
178 return; | 178 return; |
179 | 179 |
180 TreeScope* treeScope = ScopedStyleResolver::treeScopeFor(document(), &cssShe
et); | 180 TreeScope* treeScope = ScopedStyleResolver::treeScopeFor(document(), &cssShe
et); |
181 if (!treeScope) | 181 if (!treeScope) |
182 return; | 182 return; |
183 | 183 |
184 ScopedStyleResolver& resolver = treeScope->ensureScopedStyleResolver(); | 184 unsigned index = treeScope->ensureScopedStyleResolver().appendCSSStyleSheet(
&cssSheet); |
185 document().styleEngine()->addScopedStyleResolver(&resolver); | |
186 unsigned index = resolver.appendCSSStyleSheet(&cssSheet); | |
187 | |
188 addRulesFromSheet(cssSheet, treeScope, index); | 185 addRulesFromSheet(cssSheet, treeScope, index); |
189 } | 186 } |
190 | 187 |
191 void StyleResolver::addRulesFromSheet(CSSStyleSheet& cssSheet, TreeScope* treeSc
ope, unsigned index) | 188 void StyleResolver::addRulesFromSheet(CSSStyleSheet& cssSheet, TreeScope* treeSc
ope, unsigned index) |
192 { | 189 { |
193 StyleSheetContents* sheet = cssSheet.contents(); | 190 StyleSheetContents* sheet = cssSheet.contents(); |
194 AddRuleFlags addRuleFlags = document().securityOrigin()->canRequest(sheet->b
aseURL()) ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState; | 191 AddRuleFlags addRuleFlags = document().securityOrigin()->canRequest(sheet->b
aseURL()) ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState; |
195 const RuleSet& ruleSet = sheet->ensureRuleSet(*m_medium, addRuleFlags); | 192 const RuleSet& ruleSet = sheet->ensureRuleSet(*m_medium, addRuleFlags); |
196 | 193 |
197 addMediaQueryResults(ruleSet.viewportDependentMediaQueryResults()); | 194 addMediaQueryResults(ruleSet.viewportDependentMediaQueryResults()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // Need to recreate RuleFeatureSet. | 229 // Need to recreate RuleFeatureSet. |
233 m_features.clear(); | 230 m_features.clear(); |
234 m_siblingRuleSet.clear(); | 231 m_siblingRuleSet.clear(); |
235 m_uncommonAttributeRuleSet.clear(); | 232 m_uncommonAttributeRuleSet.clear(); |
236 m_needCollectFeatures = true; | 233 m_needCollectFeatures = true; |
237 } | 234 } |
238 | 235 |
239 void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet
* parentStyleSheet, unsigned parentIndex, ContainerNode& scope) | 236 void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet
* parentStyleSheet, unsigned parentIndex, ContainerNode& scope) |
240 { | 237 { |
241 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> > keyframesRul
es = authorRules.keyframesRules(); | 238 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> > keyframesRul
es = authorRules.keyframesRules(); |
242 ScopedStyleResolver* resolver = &scope.treeScope().ensureScopedStyleResolver
(); | 239 ScopedStyleResolver& resolver = scope.treeScope().ensureScopedStyleResolver(
); |
243 document().styleEngine()->addScopedStyleResolver(resolver); | |
244 for (unsigned i = 0; i < keyframesRules.size(); ++i) | 240 for (unsigned i = 0; i < keyframesRules.size(); ++i) |
245 resolver->addKeyframeStyle(keyframesRules[i]); | 241 resolver.addKeyframeStyle(keyframesRules[i]); |
246 | 242 |
247 m_treeBoundaryCrossingRules.addTreeBoundaryCrossingRules(authorRules, parent
StyleSheet, parentIndex, scope); | 243 m_treeBoundaryCrossingRules.addTreeBoundaryCrossingRules(authorRules, parent
StyleSheet, parentIndex, scope); |
248 | 244 |
249 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo
r the moment. | 245 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo
r the moment. |
250 if (scope.isDocumentNode()) { | 246 if (scope.isDocumentNode()) { |
251 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> > fontFaceR
ules = authorRules.fontFaceRules(); | 247 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> > fontFaceR
ules = authorRules.fontFaceRules(); |
252 for (unsigned i = 0; i < fontFaceRules.size(); ++i) | 248 for (unsigned i = 0; i < fontFaceRules.size(); ++i) |
253 addFontFaceRule(m_document, document().styleEngine()->fontSelector()
, fontFaceRules[i]); | 249 addFontFaceRule(m_document, document().styleEngine()->fontSelector()
, fontFaceRules[i]); |
254 if (fontFaceRules.size()) | 250 if (fontFaceRules.size()) |
255 invalidateMatchedPropertiesCache(); | 251 invalidateMatchedPropertiesCache(); |
256 } | 252 } |
257 } | 253 } |
258 | 254 |
259 void StyleResolver::resetAuthorStyle(TreeScope& treeScope) | 255 void StyleResolver::resetAuthorStyle(TreeScope& treeScope) |
260 { | 256 { |
261 ScopedStyleResolver* resolver = treeScope.scopedStyleResolver(); | 257 ScopedStyleResolver* resolver = treeScope.scopedStyleResolver(); |
262 if (!resolver) | 258 if (!resolver) |
263 return; | 259 return; |
264 | 260 |
265 m_treeBoundaryCrossingRules.reset(&treeScope.rootNode()); | 261 m_treeBoundaryCrossingRules.reset(&treeScope.rootNode()); |
266 | |
267 resolver->resetAuthorStyle(); | 262 resolver->resetAuthorStyle(); |
268 resetRuleFeatures(); | 263 resetRuleFeatures(); |
269 if (treeScope.rootNode().isDocumentNode()) | 264 if (treeScope.rootNode().isDocumentNode()) |
270 return; | 265 return; |
271 | 266 |
272 // resolver is going to be freed below. | 267 // resolver is going to be freed below. |
273 document().styleEngine()->removeScopedStyleResolver(resolver); | |
274 treeScope.clearScopedStyleResolver(); | 268 treeScope.clearScopedStyleResolver(); |
275 } | 269 } |
276 | 270 |
277 static PassOwnPtrWillBeRawPtr<RuleSet> makeRuleSet(const WillBeHeapVector<RuleFe
ature>& rules) | 271 static PassOwnPtrWillBeRawPtr<RuleSet> makeRuleSet(const WillBeHeapVector<RuleFe
ature>& rules) |
278 { | 272 { |
279 size_t size = rules.size(); | 273 size_t size = rules.size(); |
280 if (!size) | 274 if (!size) |
281 return nullptr; | 275 return nullptr; |
282 OwnPtrWillBeRawPtr<RuleSet> ruleSet = RuleSet::create(); | 276 OwnPtrWillBeRawPtr<RuleSet> ruleSet = RuleSet::create(); |
283 for (size_t i = 0; i < size; ++i) | 277 for (size_t i = 0; i < size; ++i) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 388 |
395 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec
tor, includeEmptyRules); | 389 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec
tor, includeEmptyRules); |
396 collector.sortAndTransferMatchedRules(); | 390 collector.sortAndTransferMatchedRules(); |
397 } | 391 } |
398 | 392 |
399 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col
lector, bool includeEmptyRules) | 393 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col
lector, bool includeEmptyRules) |
400 { | 394 { |
401 collector.clearMatchedRules(); | 395 collector.clearMatchedRules(); |
402 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; | 396 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; |
403 | 397 |
404 if (document().styleEngine()->hasOnlyScopedResolverForDocument()) { | 398 if (document().styleEngine()->onlyDocumentHasStyles()) { |
405 document().scopedStyleResolver()->collectMatchingAuthorRules(collector,
includeEmptyRules, ignoreCascadeScope); | 399 ScopedStyleResolver* resolver = document().scopedStyleResolver(); |
| 400 if (!resolver) |
| 401 return; |
| 402 // If we have no resolver for a document, the document has no styles. |
| 403 // We don't need to see any rules (including treeboundary crossing ones)
. |
| 404 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, ignor
eCascadeScope); |
406 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co
llector, includeEmptyRules); | 405 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co
llector, includeEmptyRules); |
407 collector.sortAndTransferMatchedRules(); | 406 collector.sortAndTransferMatchedRules(); |
408 return; | 407 return; |
409 } | 408 } |
410 | 409 |
411 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers; | 410 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers; |
412 resolveScopedStyles(element, resolvers); | 411 resolveScopedStyles(element, resolvers); |
413 | 412 |
414 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad
owTree; | 413 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad
owTree; |
415 collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree); | 414 collectScopedResolversForHostedShadowTrees(element, resolversInShadowTree); |
416 if (!resolversInShadowTree.isEmpty()) { | 415 if (!resolversInShadowTree.isEmpty()) { |
417 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res
olvers, resolversInShadowTree); | 416 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res
olvers, resolversInShadowTree); |
418 return; | 417 return; |
419 } | 418 } |
420 | 419 |
421 if (resolvers.isEmpty()) | 420 if (!resolvers.isEmpty()) { |
422 return; | 421 CascadeScope cascadeScope = 0; |
423 | 422 CascadeOrder cascadeOrder = resolvers.size(); |
424 CascadeScope cascadeScope = 0; | 423 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) { |
425 CascadeOrder cascadeOrder = resolvers.size(); | 424 ScopedStyleResolver* resolver = resolvers.at(i); |
426 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) { | 425 // FIXME: Need to clarify how to treat style scoped. |
427 ScopedStyleResolver* resolver = resolvers.at(i); | 426 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, c
ascadeScope++, resolver->treeScope() == element->treeScope() && resolver->treeSc
ope().rootNode().isShadowRoot() ? 0 : cascadeOrder); |
428 // FIXME: Need to clarify how to treat style scoped. | 427 } |
429 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, casca
deScope++, resolver->treeScope() == element->treeScope() && resolver->treeScope(
).rootNode().isShadowRoot() ? 0 : cascadeOrder); | |
430 } | 428 } |
431 | 429 |
432 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec
tor, includeEmptyRules); | 430 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec
tor, includeEmptyRules); |
433 collector.sortAndTransferMatchedRules(); | 431 collector.sortAndTransferMatchedRules(); |
434 } | 432 } |
435 | 433 |
436 void StyleResolver::matchUARules(ElementRuleCollector& collector) | 434 void StyleResolver::matchUARules(ElementRuleCollector& collector) |
437 { | 435 { |
438 collector.setMatchingUARules(true); | 436 collector.setMatchingUARules(true); |
439 | 437 |
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 visitor->trace(m_uncommonAttributeRuleSet); | 1613 visitor->trace(m_uncommonAttributeRuleSet); |
1616 visitor->trace(m_watchedSelectorsRules); | 1614 visitor->trace(m_watchedSelectorsRules); |
1617 visitor->trace(m_treeBoundaryCrossingRules); | 1615 visitor->trace(m_treeBoundaryCrossingRules); |
1618 visitor->trace(m_styleSharingLists); | 1616 visitor->trace(m_styleSharingLists); |
1619 visitor->trace(m_pendingStyleSheets); | 1617 visitor->trace(m_pendingStyleSheets); |
1620 visitor->trace(m_document); | 1618 visitor->trace(m_document); |
1621 #endif | 1619 #endif |
1622 } | 1620 } |
1623 | 1621 |
1624 } // namespace blink | 1622 } // namespace blink |
OLD | NEW |