| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 { | 222 { |
| 223 for (unsigned i = 0; i < styleSheets.size(); ++i) | 223 for (unsigned i = 0; i < styleSheets.size(); ++i) |
| 224 m_pendingStyleSheets.remove(styleSheets[i].get()); | 224 m_pendingStyleSheets.remove(styleSheets[i].get()); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) | 227 void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) |
| 228 { | 228 { |
| 229 ASSERT(!cssSheet.disabled()); | 229 ASSERT(!cssSheet.disabled()); |
| 230 ASSERT(cssSheet.ownerDocument()); | 230 ASSERT(cssSheet.ownerDocument()); |
| 231 ASSERT(cssSheet.ownerNode()); | 231 ASSERT(cssSheet.ownerNode()); |
| 232 ASSERT(isHTMLStyleElement(cssSheet.ownerNode()) || isSVGStyleElement(cssShee
t.ownerNode()) || cssSheet.ownerNode()->treeScope() == cssSheet.ownerDocument())
; | 232 ASSERT(isHTMLStyleElement(cssSheet.ownerNode()) || isSVGStyleElement(cssShee
t.ownerNode()) || cssSheet.ownerNode()->treeScopeOrDocument() == cssSheet.ownerD
ocument()); |
| 233 | 233 |
| 234 if (cssSheet.mediaQueries() && !m_medium->eval(cssSheet.mediaQueries(), &m_v
iewportDependentMediaQueryResults, &m_deviceDependentMediaQueryResults)) | 234 if (cssSheet.mediaQueries() && !m_medium->eval(cssSheet.mediaQueries(), &m_v
iewportDependentMediaQueryResults, &m_deviceDependentMediaQueryResults)) |
| 235 return; | 235 return; |
| 236 | 236 |
| 237 TreeScope* treeScope = &cssSheet.ownerNode()->treeScope(); | 237 TreeScope* treeScope = &cssSheet.ownerNode()->treeScopeOrDocument(); |
| 238 // TODO(rune@opera.com): This is a workaround for crbug.com/559292 | 238 // TODO(rune@opera.com): This is a workaround for crbug.com/559292 |
| 239 // when we're in the middle of removing a subtree with a style element | 239 // when we're in the middle of removing a subtree with a style element |
| 240 // and the treescope has been changed but inDocument and isInShadowTree | 240 // and the treescope has been changed but inDocument and isInShadowTree |
| 241 // are not. | 241 // are not. |
| 242 // | 242 // |
| 243 // This check can be removed when crbug.com/567021 is fixed. | 243 // This check can be removed when crbug.com/567021 is fixed. |
| 244 if (cssSheet.ownerNode()->isInShadowTree() && treeScope->rootNode().isDocume
ntNode()) | 244 if (cssSheet.ownerNode()->isInShadowTree() && treeScope->rootNode().isDocume
ntNode()) |
| 245 return; | 245 return; |
| 246 | 246 |
| 247 // Sheets in the document scope of HTML imports apply to the main document | 247 // Sheets in the document scope of HTML imports apply to the main document |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 return *m_styleSharingLists[depth]; | 381 return *m_styleSharingLists[depth]; |
| 382 } | 382 } |
| 383 | 383 |
| 384 void StyleResolver::clearStyleSharingList() | 384 void StyleResolver::clearStyleSharingList() |
| 385 { | 385 { |
| 386 m_styleSharingLists.resize(0); | 386 m_styleSharingLists.resize(0); |
| 387 } | 387 } |
| 388 | 388 |
| 389 static inline ScopedStyleResolver* scopedResolverFor(const Element& element) | 389 static inline ScopedStyleResolver* scopedResolverFor(const Element& element) |
| 390 { | 390 { |
| 391 // Ideally, returning element->treeScope().scopedStyleResolver() should be | 391 // Ideally, returning element->treeScopeOrDocument().scopedStyleResolver() s
hould be |
| 392 // enough, but ::cue and custom pseudo elements like ::-webkit-meter-bar pie
rce | 392 // enough, but ::cue and custom pseudo elements like ::-webkit-meter-bar pie
rce |
| 393 // through a shadow dom boundary, yet they are not part of m_treeBoundaryCro
ssingScopes. | 393 // through a shadow dom boundary, yet they are not part of m_treeBoundaryCro
ssingScopes. |
| 394 // The assumption here is that these rules only pierce through one boundary
and | 394 // The assumption here is that these rules only pierce through one boundary
and |
| 395 // that the scope of these elements do not have a style resolver due to the
fact | 395 // that the scope of these elements do not have a style resolver due to the
fact |
| 396 // that VTT scopes and UA shadow trees don't have <style> elements. This is | 396 // that VTT scopes and UA shadow trees don't have <style> elements. This is |
| 397 // backed up by the ASSERTs below. | 397 // backed up by the ASSERTs below. |
| 398 // | 398 // |
| 399 // FIXME: Make ::cue and custom pseudo elements part of boundary crossing ru
les | 399 // FIXME: Make ::cue and custom pseudo elements part of boundary crossing ru
les |
| 400 // when moving those rules to ScopedStyleResolver as part of issue 401359. | 400 // when moving those rules to ScopedStyleResolver as part of issue 401359. |
| 401 | 401 |
| 402 TreeScope* treeScope = &element.treeScope(); | 402 TreeScope* treeScope = &element.treeScopeOrDocument(); |
| 403 if (ScopedStyleResolver* resolver = treeScope->scopedStyleResolver()) { | 403 if (ScopedStyleResolver* resolver = treeScope->scopedStyleResolver()) { |
| 404 ASSERT(element.shadowPseudoId().isEmpty()); | 404 ASSERT(element.shadowPseudoId().isEmpty()); |
| 405 ASSERT(!element.isVTTElement()); | 405 ASSERT(!element.isVTTElement()); |
| 406 return resolver; | 406 return resolver; |
| 407 } | 407 } |
| 408 | 408 |
| 409 treeScope = treeScope->parentTreeScope(); | 409 treeScope = treeScope->parentTreeScope(); |
| 410 if (!treeScope) | 410 if (!treeScope) |
| 411 return nullptr; | 411 return nullptr; |
| 412 if (element.shadowPseudoId().isEmpty() && !element.isVTTElement()) | 412 if (element.shadowPseudoId().isEmpty() && !element.isVTTElement()) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 433 } | 433 } |
| 434 | 434 |
| 435 static void matchSlottedRules(const Element& element, ElementRuleCollector& coll
ector) | 435 static void matchSlottedRules(const Element& element, ElementRuleCollector& coll
ector) |
| 436 { | 436 { |
| 437 HTMLSlotElement* slot = element.assignedSlot(); | 437 HTMLSlotElement* slot = element.assignedSlot(); |
| 438 if (!slot) | 438 if (!slot) |
| 439 return; | 439 return; |
| 440 | 440 |
| 441 HeapVector<Member<ScopedStyleResolver>> resolvers; | 441 HeapVector<Member<ScopedStyleResolver>> resolvers; |
| 442 for (; slot; slot = slot->assignedSlot()) { | 442 for (; slot; slot = slot->assignedSlot()) { |
| 443 if (ScopedStyleResolver* resolver = slot->treeScope().scopedStyleResolve
r()) | 443 if (ScopedStyleResolver* resolver = slot->treeScopeOrDocument().scopedSt
yleResolver()) |
| 444 resolvers.append(resolver); | 444 resolvers.append(resolver); |
| 445 } | 445 } |
| 446 for (auto it = resolvers.rbegin(); it != resolvers.rend(); ++it) { | 446 for (auto it = resolvers.rbegin(); it != resolvers.rend(); ++it) { |
| 447 collector.clearMatchedRules(); | 447 collector.clearMatchedRules(); |
| 448 (*it)->collectMatchingTreeBoundaryCrossingRules(collector); | 448 (*it)->collectMatchingTreeBoundaryCrossingRules(collector); |
| 449 collector.sortAndTransferMatchedRules(); | 449 collector.sortAndTransferMatchedRules(); |
| 450 collector.finishAddingAuthorRulesForTreeScope(); | 450 collector.finishAddingAuthorRulesForTreeScope(); |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | 453 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 464 // Inline style is immutable as long as there is no CSSOM wrapper. | 464 // Inline style is immutable as long as there is no CSSOM wrapper. |
| 465 bool isInlineStyleCacheable = !element.inlineStyle()->isMutable(); | 465 bool isInlineStyleCacheable = !element.inlineStyle()->isMutable(); |
| 466 collector.addElementStyleProperties(element.inlineStyle(), isInlineStyle
Cacheable); | 466 collector.addElementStyleProperties(element.inlineStyle(), isInlineStyle
Cacheable); |
| 467 } | 467 } |
| 468 | 468 |
| 469 collector.finishAddingAuthorRulesForTreeScope(); | 469 collector.finishAddingAuthorRulesForTreeScope(); |
| 470 } | 470 } |
| 471 | 471 |
| 472 static bool shouldCheckScope(const Element& element, const Node& scopingNode, bo
ol isInnerTreeScope) | 472 static bool shouldCheckScope(const Element& element, const Node& scopingNode, bo
ol isInnerTreeScope) |
| 473 { | 473 { |
| 474 if (isInnerTreeScope && element.treeScope() != scopingNode.treeScope()) { | 474 if (isInnerTreeScope && element.treeScopeOrDocument() != scopingNode.treeSco
peOrDocument()) { |
| 475 // Check if |element| may be affected by a ::content rule in |scopingNod
e|'s style. | 475 // Check if |element| may be affected by a ::content rule in |scopingNod
e|'s style. |
| 476 // If |element| is a descendant of a shadow host which is ancestral to |
scopingNode|, | 476 // If |element| is a descendant of a shadow host which is ancestral to |
scopingNode|, |
| 477 // the |element| should be included for rule collection. | 477 // the |element| should be included for rule collection. |
| 478 // Skip otherwise. | 478 // Skip otherwise. |
| 479 const TreeScope* scope = &scopingNode.treeScope(); | 479 const TreeScope* scope = &scopingNode.treeScopeOrDocument(); |
| 480 while (scope && scope->parentTreeScope() != &element.treeScope()) | 480 while (scope && scope->parentTreeScope() != &element.treeScopeOrDocument
()) |
| 481 scope = scope->parentTreeScope(); | 481 scope = scope->parentTreeScope(); |
| 482 Element* shadowHost = scope ? scope->rootNode().shadowHost() : nullptr; | 482 Element* shadowHost = scope ? scope->rootNode().shadowHost() : nullptr; |
| 483 return shadowHost && element.isDescendantOf(shadowHost); | 483 return shadowHost && element.isDescendantOf(shadowHost); |
| 484 } | 484 } |
| 485 | 485 |
| 486 // When |element| can be distributed to |scopingNode| via <shadow>, ::conten
t rule can match, | 486 // When |element| can be distributed to |scopingNode| via <shadow>, ::conten
t rule can match, |
| 487 // thus the case should be included. | 487 // thus the case should be included. |
| 488 if (!isInnerTreeScope && scopingNode.parentOrShadowHostNode() == element.tre
eScope().rootNode().parentOrShadowHostNode()) | 488 if (!isInnerTreeScope && scopingNode.parentOrShadowHostNode() == element.tre
eScopeOrDocument().rootNode().parentOrShadowHostNode()) |
| 489 return true; | 489 return true; |
| 490 | 490 |
| 491 // Obviously cases when ancestor scope has /deep/ or ::shadow rule should be
included. | 491 // Obviously cases when ancestor scope has /deep/ or ::shadow rule should be
included. |
| 492 // Skip otherwise. | 492 // Skip otherwise. |
| 493 return scopingNode.treeScope().scopedStyleResolver()->hasDeepOrShadowSelecto
r(); | 493 return scopingNode.treeScopeOrDocument().scopedStyleResolver()->hasDeepOrSha
dowSelector(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 void StyleResolver::matchScopedRules(const Element& element, ElementRuleCollecto
r& collector) | 496 void StyleResolver::matchScopedRules(const Element& element, ElementRuleCollecto
r& collector) |
| 497 { | 497 { |
| 498 // Match rules from treeScopes in the reverse tree-of-trees order, since the | 498 // Match rules from treeScopes in the reverse tree-of-trees order, since the |
| 499 // cascading order for normal rules is such that when comparing rules from | 499 // cascading order for normal rules is such that when comparing rules from |
| 500 // different shadow trees, the rule from the tree which comes first in the | 500 // different shadow trees, the rule from the tree which comes first in the |
| 501 // tree-of-trees order wins. From other treeScopes than the element's own | 501 // tree-of-trees order wins. From other treeScopes than the element's own |
| 502 // scope, only tree-boundary-crossing rules may match. | 502 // scope, only tree-boundary-crossing rules may match. |
| 503 | 503 |
| 504 ScopedStyleResolver* elementScopeResolver = scopedResolverFor(element); | 504 ScopedStyleResolver* elementScopeResolver = scopedResolverFor(element); |
| 505 | 505 |
| 506 if (!document().mayContainV0Shadow()) { | 506 if (!document().mayContainV0Shadow()) { |
| 507 matchSlottedRules(element, collector); | 507 matchSlottedRules(element, collector); |
| 508 matchElementScopeRules(element, elementScopeResolver, collector); | 508 matchElementScopeRules(element, elementScopeResolver, collector); |
| 509 return; | 509 return; |
| 510 } | 510 } |
| 511 | 511 |
| 512 bool matchElementScopeDone = !elementScopeResolver && !element.inlineStyle()
; | 512 bool matchElementScopeDone = !elementScopeResolver && !element.inlineStyle()
; |
| 513 | 513 |
| 514 for (auto it = m_treeBoundaryCrossingScopes.rbegin(); it != m_treeBoundaryCr
ossingScopes.rend(); ++it) { | 514 for (auto it = m_treeBoundaryCrossingScopes.rbegin(); it != m_treeBoundaryCr
ossingScopes.rend(); ++it) { |
| 515 const TreeScope& scope = (*it)->treeScope(); | 515 const TreeScope& scope = (*it)->treeScopeOrDocument(); |
| 516 ScopedStyleResolver* resolver = scope.scopedStyleResolver(); | 516 ScopedStyleResolver* resolver = scope.scopedStyleResolver(); |
| 517 ASSERT(resolver); | 517 ASSERT(resolver); |
| 518 | 518 |
| 519 bool isInnerTreeScope = element.treeScope().isInclusiveAncestorOf(scope)
; | 519 bool isInnerTreeScope = element.treeScopeOrDocument().isInclusiveAncesto
rOf(scope); |
| 520 if (!shouldCheckScope(element, **it, isInnerTreeScope)) | 520 if (!shouldCheckScope(element, **it, isInnerTreeScope)) |
| 521 continue; | 521 continue; |
| 522 | 522 |
| 523 if (!matchElementScopeDone && scope.isInclusiveAncestorOf(element.treeSc
ope())) { | 523 if (!matchElementScopeDone && scope.isInclusiveAncestorOf(element.treeSc
opeOrDocument())) { |
| 524 | 524 |
| 525 matchElementScopeDone = true; | 525 matchElementScopeDone = true; |
| 526 | 526 |
| 527 // At this point, the iterator has either encountered the scope for
the element | 527 // At this point, the iterator has either encountered the scope for
the element |
| 528 // itself (if that scope has boundary-crossing rules), or the iterat
or has moved | 528 // itself (if that scope has boundary-crossing rules), or the iterat
or has moved |
| 529 // to a scope which appears before the element's scope in the tree-o
f-trees order. | 529 // to a scope which appears before the element's scope in the tree-o
f-trees order. |
| 530 // Try to match all rules from the element's scope. | 530 // Try to match all rules from the element's scope. |
| 531 | 531 |
| 532 matchElementScopeRules(element, elementScopeResolver, collector); | 532 matchElementScopeRules(element, elementScopeResolver, collector); |
| 533 if (resolver == elementScopeResolver) { | 533 if (resolver == elementScopeResolver) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 return; | 653 return; |
| 654 | 654 |
| 655 // When comparing rules declared in outer treescopes, outer's rules win. | 655 // When comparing rules declared in outer treescopes, outer's rules win. |
| 656 CascadeOrder outerCascadeOrder = m_treeBoundaryCrossingScopes.size() * 2; | 656 CascadeOrder outerCascadeOrder = m_treeBoundaryCrossingScopes.size() * 2; |
| 657 // When comparing rules declared in inner treescopes, inner's rules win. | 657 // When comparing rules declared in inner treescopes, inner's rules win. |
| 658 CascadeOrder innerCascadeOrder = m_treeBoundaryCrossingScopes.size(); | 658 CascadeOrder innerCascadeOrder = m_treeBoundaryCrossingScopes.size(); |
| 659 | 659 |
| 660 for (const auto& scopingNode : m_treeBoundaryCrossingScopes) { | 660 for (const auto& scopingNode : m_treeBoundaryCrossingScopes) { |
| 661 // Skip rule collection for element when tree boundary crossing rules of
scopingNode's | 661 // Skip rule collection for element when tree boundary crossing rules of
scopingNode's |
| 662 // scope can never apply to it. | 662 // scope can never apply to it. |
| 663 bool isInnerTreeScope = element.treeScope().isInclusiveAncestorOf(scopin
gNode->treeScope()); | 663 bool isInnerTreeScope = element.treeScopeOrDocument().isInclusiveAncesto
rOf(scopingNode->treeScopeOrDocument()); |
| 664 if (!shouldCheckScope(element, *scopingNode, isInnerTreeScope)) | 664 if (!shouldCheckScope(element, *scopingNode, isInnerTreeScope)) |
| 665 continue; | 665 continue; |
| 666 | 666 |
| 667 CascadeOrder cascadeOrder = isInnerTreeScope ? innerCascadeOrder : outer
CascadeOrder; | 667 CascadeOrder cascadeOrder = isInnerTreeScope ? innerCascadeOrder : outer
CascadeOrder; |
| 668 scopingNode->treeScope().scopedStyleResolver()->collectMatchingTreeBound
aryCrossingRules(collector, cascadeOrder); | 668 scopingNode->treeScopeOrDocument().scopedStyleResolver()->collectMatchin
gTreeBoundaryCrossingRules(collector, cascadeOrder); |
| 669 | 669 |
| 670 ++innerCascadeOrder; | 670 ++innerCascadeOrder; |
| 671 --outerCascadeOrder; | 671 --outerCascadeOrder; |
| 672 } | 672 } |
| 673 } | 673 } |
| 674 | 674 |
| 675 PassRefPtr<ComputedStyle> StyleResolver::styleForDocument(Document& document) | 675 PassRefPtr<ComputedStyle> StyleResolver::styleForDocument(Document& document) |
| 676 { | 676 { |
| 677 const LocalFrame* frame = document.frame(); | 677 const LocalFrame* frame = document.frame(); |
| 678 | 678 |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 | 1143 |
| 1144 state.setApplyPropertyToVisitedLinkStyle(false); | 1144 state.setApplyPropertyToVisitedLinkStyle(false); |
| 1145 | 1145 |
| 1146 return true; | 1146 return true; |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 StyleRuleKeyframes* StyleResolver::findKeyframesRule(const Element* element, con
st AtomicString& animationName) | 1149 StyleRuleKeyframes* StyleResolver::findKeyframesRule(const Element* element, con
st AtomicString& animationName) |
| 1150 { | 1150 { |
| 1151 HeapVector<Member<ScopedStyleResolver>, 8> resolvers; | 1151 HeapVector<Member<ScopedStyleResolver>, 8> resolvers; |
| 1152 collectScopedResolversForHostedShadowTrees(*element, resolvers); | 1152 collectScopedResolversForHostedShadowTrees(*element, resolvers); |
| 1153 if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleRe
solver()) | 1153 if (ScopedStyleResolver* scopedResolver = element->treeScopeOrDocument().sco
pedStyleResolver()) |
| 1154 resolvers.append(scopedResolver); | 1154 resolvers.append(scopedResolver); |
| 1155 | 1155 |
| 1156 for (size_t i = 0; i < resolvers.size(); ++i) { | 1156 for (size_t i = 0; i < resolvers.size(); ++i) { |
| 1157 if (StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStylesForA
nimation(animationName.impl())) | 1157 if (StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStylesForA
nimation(animationName.impl())) |
| 1158 return keyframesRule; | 1158 return keyframesRule; |
| 1159 } | 1159 } |
| 1160 return nullptr; | 1160 return nullptr; |
| 1161 } | 1161 } |
| 1162 | 1162 |
| 1163 template <CSSPropertyPriority priority> | 1163 template <CSSPropertyPriority priority> |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 visitor->trace(m_siblingRuleSet); | 1734 visitor->trace(m_siblingRuleSet); |
| 1735 visitor->trace(m_uncommonAttributeRuleSet); | 1735 visitor->trace(m_uncommonAttributeRuleSet); |
| 1736 visitor->trace(m_watchedSelectorsRules); | 1736 visitor->trace(m_watchedSelectorsRules); |
| 1737 visitor->trace(m_treeBoundaryCrossingScopes); | 1737 visitor->trace(m_treeBoundaryCrossingScopes); |
| 1738 visitor->trace(m_styleSharingLists); | 1738 visitor->trace(m_styleSharingLists); |
| 1739 visitor->trace(m_pendingStyleSheets); | 1739 visitor->trace(m_pendingStyleSheets); |
| 1740 visitor->trace(m_document); | 1740 visitor->trace(m_document); |
| 1741 } | 1741 } |
| 1742 | 1742 |
| 1743 } // namespace blink | 1743 } // namespace blink |
| OLD | NEW |