| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 void StyleResolver::resetRuleFeatures() | 240 void StyleResolver::resetRuleFeatures() |
| 241 { | 241 { |
| 242 // Need to recreate RuleFeatureSet. | 242 // Need to recreate RuleFeatureSet. |
| 243 m_features.clear(); | 243 m_features.clear(); |
| 244 m_siblingRuleSet.clear(); | 244 m_siblingRuleSet.clear(); |
| 245 m_uncommonAttributeRuleSet.clear(); | 245 m_uncommonAttributeRuleSet.clear(); |
| 246 m_needCollectFeatures = true; | 246 m_needCollectFeatures = true; |
| 247 } | 247 } |
| 248 | 248 |
| 249 void StyleResolver::addTreeBoundaryCrossingRules(const WillBeHeapVector<MinimalR
uleData>& rules, ContainerNode* scope) | 249 void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet
* parentStyleSheet, ContainerNode* scope) |
| 250 { | |
| 251 for (unsigned i = 0; i < rules.size(); ++i) { | |
| 252 const MinimalRuleData& info = rules[i]; | |
| 253 m_treeBoundaryCrossingRules.addRule(info.m_rule, info.m_selectorIndex, s
cope, info.m_flags); | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 void StyleResolver::processScopedRules(const RuleSet& authorRules, const KURL& s
heetBaseURL, ContainerNode* scope) | |
| 258 { | 250 { |
| 259 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> > keyframesRul
es = authorRules.keyframesRules(); | 251 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> > keyframesRul
es = authorRules.keyframesRules(); |
| 260 for (unsigned i = 0; i < keyframesRules.size(); ++i) | 252 for (unsigned i = 0; i < keyframesRules.size(); ++i) |
| 261 ensureScopedStyleResolver(scope)->addKeyframeStyle(keyframesRules[i]); | 253 ensureScopedStyleResolver(scope)->addKeyframeStyle(keyframesRules[i]); |
| 262 | 254 |
| 263 addTreeBoundaryCrossingRules(authorRules.treeBoundaryCrossingRules(), scope)
; | 255 m_treeBoundaryCrossingRules.addTreeBoundaryCrossingRules(authorRules, scope,
parentStyleSheet); |
| 264 | 256 |
| 265 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo
r the moment. | 257 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo
r the moment. |
| 266 if (!scope || scope->isDocumentNode()) { | 258 if (!scope || scope->isDocumentNode()) { |
| 267 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> > fontFaceR
ules = authorRules.fontFaceRules(); | 259 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> > fontFaceR
ules = authorRules.fontFaceRules(); |
| 268 for (unsigned i = 0; i < fontFaceRules.size(); ++i) | 260 for (unsigned i = 0; i < fontFaceRules.size(); ++i) |
| 269 addFontFaceRule(&m_document, document().styleEngine()->fontSelector(
), fontFaceRules[i]); | 261 addFontFaceRule(&m_document, document().styleEngine()->fontSelector(
), fontFaceRules[i]); |
| 270 if (fontFaceRules.size()) | 262 if (fontFaceRules.size()) |
| 271 invalidateMatchedPropertiesCache(); | 263 invalidateMatchedPropertiesCache(); |
| 272 } else { | |
| 273 addTreeBoundaryCrossingRules(authorRules.shadowDistributedRules(), scope
); | |
| 274 } | 264 } |
| 275 } | 265 } |
| 276 | 266 |
| 277 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode) | 267 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode) |
| 278 { | 268 { |
| 279 // FIXME: When chanking scoped attribute, scopingNode's hasScopedHTMLStyleCh
ild has been already modified. | 269 // FIXME: When chanking scoped attribute, scopingNode's hasScopedHTMLStyleCh
ild has been already modified. |
| 280 // So we cannot use hasScopedHTMLStyleChild flag here. | 270 // So we cannot use hasScopedHTMLStyleChild flag here. |
| 281 ScopedStyleResolver* resolver = scopingNode ? m_styleTree.lookupScopedStyleR
esolverFor(scopingNode) : m_styleTree.scopedStyleResolverForDocument(); | 271 ScopedStyleResolver* resolver = scopingNode ? m_styleTree.lookupScopedStyleR
esolverFor(scopingNode) : m_styleTree.scopedStyleResolverForDocument(); |
| 282 if (!resolver) | 272 if (!resolver) |
| 283 return; | 273 return; |
| 284 | 274 |
| 285 treeBoundaryCrossingRules().reset(scopingNode); | 275 m_treeBoundaryCrossingRules.reset(scopingNode); |
| 286 | 276 |
| 287 resolver->resetAuthorStyle(); | 277 resolver->resetAuthorStyle(); |
| 288 resetRuleFeatures(); | 278 resetRuleFeatures(); |
| 289 if (!scopingNode) | 279 if (!scopingNode) |
| 290 return; | 280 return; |
| 291 | 281 |
| 292 m_styleTree.remove(scopingNode); | 282 m_styleTree.remove(scopingNode); |
| 293 } | 283 } |
| 294 | 284 |
| 295 static PassOwnPtrWillBeRawPtr<RuleSet> makeRuleSet(const Vector<RuleFeature>& ru
les) | 285 static PassOwnPtrWillBeRawPtr<RuleSet> makeRuleSet(const Vector<RuleFeature>& ru
les) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 void StyleResolver::popParentShadowRoot(const ShadowRoot& shadowRoot) | 382 void StyleResolver::popParentShadowRoot(const ShadowRoot& shadowRoot) |
| 393 { | 383 { |
| 394 ASSERT(shadowRoot.host()); | 384 ASSERT(shadowRoot.host()); |
| 395 m_styleTree.popStyleCache(shadowRoot); | 385 m_styleTree.popStyleCache(shadowRoot); |
| 396 } | 386 } |
| 397 | 387 |
| 398 StyleResolver::~StyleResolver() | 388 StyleResolver::~StyleResolver() |
| 399 { | 389 { |
| 400 } | 390 } |
| 401 | 391 |
| 402 inline void StyleResolver::collectTreeBoundaryCrossingRules(Element* element, El
ementRuleCollector& collector, bool includeEmptyRules) | |
| 403 { | |
| 404 if (m_treeBoundaryCrossingRules.isEmpty()) | |
| 405 return; | |
| 406 | |
| 407 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); | |
| 408 | |
| 409 // When comparing rules declared in outer treescopes, outer's rules win. | |
| 410 CascadeOrder outerCascadeOrder = m_treeBoundaryCrossingRules.size() + m_tree
BoundaryCrossingRules.size(); | |
| 411 // When comparing rules declared in inner treescopes, inner's rules win. | |
| 412 CascadeOrder innerCascadeOrder = m_treeBoundaryCrossingRules.size(); | |
| 413 | |
| 414 for (DocumentOrderedList::iterator it = m_treeBoundaryCrossingRules.begin();
it != m_treeBoundaryCrossingRules.end(); ++it) { | |
| 415 const ContainerNode* scopingNode = toContainerNode(*it); | |
| 416 | |
| 417 if (ShadowRoot* shadowRoot = scopingNode->containingShadowRoot()) { | |
| 418 if (!shadowRoot->isActiveForStyling()) | |
| 419 continue; | |
| 420 } | |
| 421 | |
| 422 RuleSet* ruleSet = m_treeBoundaryCrossingRules.ruleSetScopedBy(scopingNo
de); | |
| 423 unsigned boundaryBehavior = SelectorChecker::ScopeContainsLastMatchedEle
ment; | |
| 424 bool isInnerTreeScope = element->treeScope().isInclusiveAncestorOf(scopi
ngNode->treeScope()); | |
| 425 | |
| 426 // If a given scoping node is a shadow root and a given element is in a
descendant tree of tree hosted by | |
| 427 // the scoping node's shadow host, we should use ScopeIsShadowHost. | |
| 428 if (scopingNode && scopingNode->isShadowRoot()) { | |
| 429 if (element->isInDescendantTreeOf(toShadowRoot(scopingNode)->host())
) | |
| 430 boundaryBehavior |= SelectorChecker::ScopeIsShadowHost; | |
| 431 scopingNode = toShadowRoot(scopingNode)->host(); | |
| 432 } | |
| 433 | |
| 434 CascadeOrder cascadeOrder = isInnerTreeScope ? innerCascadeOrder : outer
CascadeOrder; | |
| 435 | |
| 436 collector.collectMatchingRules(MatchRequest(ruleSet, includeEmptyRules,
scopingNode), ruleRange, static_cast<SelectorChecker::BehaviorAtBoundary>(bounda
ryBehavior), ignoreCascadeScope, cascadeOrder); | |
| 437 ++innerCascadeOrder; | |
| 438 --outerCascadeOrder; | |
| 439 } | |
| 440 } | |
| 441 | |
| 442 static inline bool applyAuthorStylesOf(const Element* element) | 392 static inline bool applyAuthorStylesOf(const Element* element) |
| 443 { | 393 { |
| 444 return element->treeScope().applyAuthorStyles() || (element->shadow() && ele
ment->shadow()->applyAuthorStyles()); | 394 return element->treeScope().applyAuthorStyles() || (element->shadow() && ele
ment->shadow()->applyAuthorStyles()); |
| 445 } | 395 } |
| 446 | 396 |
| 447 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC
ollector& collector, bool includeEmptyRules, Vector<ScopedStyleResolver*, 8>& re
solvers, Vector<ScopedStyleResolver*, 8>& resolversInShadowTree) | 397 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC
ollector& collector, bool includeEmptyRules, Vector<ScopedStyleResolver*, 8>& re
solvers, Vector<ScopedStyleResolver*, 8>& resolversInShadowTree) |
| 448 { | 398 { |
| 449 collector.clearMatchedRules(); | 399 collector.clearMatchedRules(); |
| 450 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; | 400 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; |
| 451 | 401 |
| 452 CascadeScope cascadeScope = 0; | 402 CascadeScope cascadeScope = 0; |
| 453 CascadeOrder cascadeOrder = 0; | 403 CascadeOrder cascadeOrder = 0; |
| 454 bool applyAuthorStyles = applyAuthorStylesOf(element); | 404 bool applyAuthorStyles = applyAuthorStylesOf(element); |
| 455 | 405 |
| 456 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j) | 406 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j) |
| 457 resolversInShadowTree.at(j)->collectMatchingAuthorRules(collector, inclu
deEmptyRules, applyAuthorStyles, cascadeScope, cascadeOrder++); | 407 resolversInShadowTree.at(j)->collectMatchingAuthorRules(collector, inclu
deEmptyRules, applyAuthorStyles, cascadeScope, cascadeOrder++); |
| 458 | 408 |
| 459 if (resolvers.isEmpty() || resolvers.first()->treeScope() != element->treeSc
ope()) | 409 if (resolvers.isEmpty() || resolvers.first()->treeScope() != element->treeSc
ope()) |
| 460 ++cascadeScope; | 410 ++cascadeScope; |
| 461 cascadeOrder += resolvers.size(); | 411 cascadeOrder += resolvers.size(); |
| 462 for (unsigned i = 0; i < resolvers.size(); ++i) | 412 for (unsigned i = 0; i < resolvers.size(); ++i) |
| 463 resolvers.at(i)->collectMatchingAuthorRules(collector, includeEmptyRules
, applyAuthorStyles, cascadeScope++, --cascadeOrder); | 413 resolvers.at(i)->collectMatchingAuthorRules(collector, includeEmptyRules
, applyAuthorStyles, cascadeScope++, --cascadeOrder); |
| 464 | 414 |
| 465 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | 415 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec
tor, includeEmptyRules); |
| 466 collector.sortAndTransferMatchedRules(); | 416 collector.sortAndTransferMatchedRules(); |
| 467 } | 417 } |
| 468 | 418 |
| 469 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col
lector, bool includeEmptyRules) | 419 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col
lector, bool includeEmptyRules) |
| 470 { | 420 { |
| 471 collector.clearMatchedRules(); | 421 collector.clearMatchedRules(); |
| 472 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; | 422 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; |
| 473 | 423 |
| 474 bool applyAuthorStyles = applyAuthorStylesOf(element); | 424 bool applyAuthorStyles = applyAuthorStylesOf(element); |
| 475 if (m_styleTree.hasOnlyScopedResolverForDocument()) { | 425 if (m_styleTree.hasOnlyScopedResolverForDocument()) { |
| 476 m_styleTree.scopedStyleResolverForDocument()->collectMatchingAuthorRules
(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope); | 426 m_styleTree.scopedStyleResolverForDocument()->collectMatchingAuthorRules
(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope); |
| 477 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | 427 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co
llector, includeEmptyRules); |
| 478 collector.sortAndTransferMatchedRules(); | 428 collector.sortAndTransferMatchedRules(); |
| 479 return; | 429 return; |
| 480 } | 430 } |
| 481 | 431 |
| 482 Vector<ScopedStyleResolver*, 8> resolvers; | 432 Vector<ScopedStyleResolver*, 8> resolvers; |
| 483 m_styleTree.resolveScopedStyles(element, resolvers); | 433 m_styleTree.resolveScopedStyles(element, resolvers); |
| 484 | 434 |
| 485 Vector<ScopedStyleResolver*, 8> resolversInShadowTree; | 435 Vector<ScopedStyleResolver*, 8> resolversInShadowTree; |
| 486 m_styleTree.collectScopedResolversForHostedShadowTrees(element, resolversInS
hadowTree); | 436 m_styleTree.collectScopedResolversForHostedShadowTrees(element, resolversInS
hadowTree); |
| 487 if (!resolversInShadowTree.isEmpty()) { | 437 if (!resolversInShadowTree.isEmpty()) { |
| 488 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res
olvers, resolversInShadowTree); | 438 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res
olvers, resolversInShadowTree); |
| 489 return; | 439 return; |
| 490 } | 440 } |
| 491 | 441 |
| 492 if (resolvers.isEmpty()) | 442 if (resolvers.isEmpty()) |
| 493 return; | 443 return; |
| 494 | 444 |
| 495 CascadeScope cascadeScope = 0; | 445 CascadeScope cascadeScope = 0; |
| 496 CascadeOrder cascadeOrder = resolvers.size(); | 446 CascadeOrder cascadeOrder = resolvers.size(); |
| 497 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) { | 447 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) { |
| 498 ScopedStyleResolver* resolver = resolvers.at(i); | 448 ScopedStyleResolver* resolver = resolvers.at(i); |
| 499 // FIXME: Need to clarify how to treat style scoped. | 449 // FIXME: Need to clarify how to treat style scoped. |
| 500 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply
AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r
esolver->scopingNode().isShadowRoot() ? 0 : cascadeOrder); | 450 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply
AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r
esolver->scopingNode().isShadowRoot() ? 0 : cascadeOrder); |
| 501 } | 451 } |
| 502 | 452 |
| 503 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | 453 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec
tor, includeEmptyRules); |
| 504 collector.sortAndTransferMatchedRules(); | 454 collector.sortAndTransferMatchedRules(); |
| 505 } | 455 } |
| 506 | 456 |
| 507 void StyleResolver::matchWatchSelectorRules(ElementRuleCollector& collector) | 457 void StyleResolver::matchWatchSelectorRules(ElementRuleCollector& collector) |
| 508 { | 458 { |
| 509 if (!m_watchedSelectorsRules) | 459 if (!m_watchedSelectorsRules) |
| 510 return; | 460 return; |
| 511 | 461 |
| 512 collector.clearMatchedRules(); | 462 collector.clearMatchedRules(); |
| 513 collector.matchedResult().ranges.lastUserRule = collector.matchedResult().ma
tchedProperties.size() - 1; | 463 collector.matchedResult().ranges.lastUserRule = collector.matchedResult().ma
tchedProperties.size() - 1; |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 visitor->trace(m_keyframesRuleMap); | 1379 visitor->trace(m_keyframesRuleMap); |
| 1430 visitor->trace(m_viewportDependentMediaQueryResults); | 1380 visitor->trace(m_viewportDependentMediaQueryResults); |
| 1431 visitor->trace(m_viewportStyleResolver); | 1381 visitor->trace(m_viewportStyleResolver); |
| 1432 visitor->trace(m_siblingRuleSet); | 1382 visitor->trace(m_siblingRuleSet); |
| 1433 visitor->trace(m_uncommonAttributeRuleSet); | 1383 visitor->trace(m_uncommonAttributeRuleSet); |
| 1434 visitor->trace(m_watchedSelectorsRules); | 1384 visitor->trace(m_watchedSelectorsRules); |
| 1435 visitor->trace(m_treeBoundaryCrossingRules); | 1385 visitor->trace(m_treeBoundaryCrossingRules); |
| 1436 } | 1386 } |
| 1437 | 1387 |
| 1438 } // namespace WebCore | 1388 } // namespace WebCore |
| OLD | NEW |