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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 { | 396 { |
397 ASSERT(shadowRoot.host()); | 397 ASSERT(shadowRoot.host()); |
398 m_styleTree.popStyleCache(shadowRoot); | 398 m_styleTree.popStyleCache(shadowRoot); |
399 } | 399 } |
400 | 400 |
401 StyleResolver::~StyleResolver() | 401 StyleResolver::~StyleResolver() |
402 { | 402 { |
403 m_viewportStyleResolver->clearDocument(); | 403 m_viewportStyleResolver->clearDocument(); |
404 } | 404 } |
405 | 405 |
406 inline void StyleResolver::collectTreeBoundaryCrossingRules(Element* element, El
ementRuleCollector& collector, bool includeEmptyRules) | 406 inline void StyleResolver::collectTreeBoundaryCrossingRules(Element* element, El
ementRuleCollector& collector, bool includeEmptyRules, CascadeOrder cascadeOrder
) |
407 { | 407 { |
408 if (m_treeBoundaryCrossingRules.isEmpty()) | 408 if (m_treeBoundaryCrossingRules.isEmpty()) |
409 return; | 409 return; |
410 | 410 |
411 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); | 411 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); |
412 | 412 |
413 CascadeOrder cascadeOrder = 0; | |
414 | |
415 DocumentOrderedList::iterator it = m_treeBoundaryCrossingRules.end(); | 413 DocumentOrderedList::iterator it = m_treeBoundaryCrossingRules.end(); |
416 while (it != m_treeBoundaryCrossingRules.begin()) { | 414 while (it != m_treeBoundaryCrossingRules.begin()) { |
417 --it; | 415 --it; |
418 const ContainerNode* scopingNode = toContainerNode(*it); | 416 const ContainerNode* scopingNode = toContainerNode(*it); |
419 RuleSet* ruleSet = m_treeBoundaryCrossingRules.ruleSetScopedBy(scopingNo
de); | 417 RuleSet* ruleSet = m_treeBoundaryCrossingRules.ruleSetScopedBy(scopingNo
de); |
420 unsigned boundaryBehavior = SelectorChecker::ScopeContainsLastMatchedEle
ment; | 418 unsigned boundaryBehavior = SelectorChecker::ScopeContainsLastMatchedEle
ment; |
421 | 419 |
422 // If a given scoping node is a shadow root and a given element is in a
descendant tree of tree hosted by | 420 CascadeOrder orderForRule; |
423 // the scoping node's shadow host, we should use ScopeIsShadowHost. | 421 |
| 422 // If a given scoping node is a shadow root and a given element is in a
descendant tree of tree |
| 423 // hosted by the scoping node's shadow host, we should use ScopeIsShadow
Host. |
424 if (scopingNode && scopingNode->isShadowRoot()) { | 424 if (scopingNode && scopingNode->isShadowRoot()) { |
425 if (element->isInDescendantTreeOf(toShadowRoot(scopingNode)->host())
) | 425 if (element->isInDescendantTreeOf(toShadowRoot(scopingNode)->host())
) { |
426 boundaryBehavior |= SelectorChecker::ScopeIsShadowHost; | 426 boundaryBehavior |= SelectorChecker::ScopeIsShadowHost; |
| 427 orderForRule = cascadeOrder; |
| 428 } else { |
| 429 orderForRule = 0; |
| 430 } |
427 scopingNode = toShadowRoot(scopingNode)->host(); | 431 scopingNode = toShadowRoot(scopingNode)->host(); |
| 432 } else { |
| 433 orderForRule = scopingNode->containsIncludingShadowDOM(element) ? ca
scadeOrder : 0; |
428 } | 434 } |
429 collector.collectMatchingRules(MatchRequest(ruleSet, includeEmptyRules,
scopingNode), ruleRange, static_cast<SelectorChecker::BehaviorAtBoundary>(bounda
ryBehavior), ignoreCascadeScope, cascadeOrder++); | 435 collector.collectMatchingRules(MatchRequest(ruleSet, includeEmptyRules,
scopingNode), ruleRange, static_cast<SelectorChecker::BehaviorAtBoundary>(bounda
ryBehavior), ignoreCascadeScope, orderForRule); |
430 } | 436 } |
431 } | 437 } |
432 | 438 |
433 static inline bool applyAuthorStylesOf(const Element* element) | 439 static inline bool applyAuthorStylesOf(const Element* element) |
434 { | 440 { |
435 return element->treeScope().applyAuthorStyles() || (element->shadow() && ele
ment->shadow()->applyAuthorStyles()); | 441 return element->treeScope().applyAuthorStyles() || (element->shadow() && ele
ment->shadow()->applyAuthorStyles()); |
436 } | 442 } |
437 | 443 |
438 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC
ollector& collector, bool includeEmptyRules, Vector<ScopedStyleResolver*, 8>& re
solvers, Vector<ScopedStyleResolver*, 8>& resolversInShadowTree) | |
439 { | |
440 collector.clearMatchedRules(); | |
441 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; | |
442 | |
443 CascadeScope cascadeScope = 0; | |
444 CascadeOrder cascadeOrder = 0; | |
445 bool applyAuthorStyles = applyAuthorStylesOf(element); | |
446 | |
447 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j) | |
448 resolversInShadowTree.at(j)->collectMatchingAuthorRules(collector, inclu
deEmptyRules, applyAuthorStyles, cascadeScope, cascadeOrder++); | |
449 | |
450 if (resolvers.isEmpty() || resolvers.first()->treeScope() != element->treeSc
ope()) | |
451 ++cascadeScope; | |
452 cascadeOrder += resolvers.size(); | |
453 for (unsigned i = 0; i < resolvers.size(); ++i) | |
454 resolvers.at(i)->collectMatchingAuthorRules(collector, includeEmptyRules
, applyAuthorStyles, cascadeScope++, --cascadeOrder); | |
455 | |
456 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | |
457 collector.sortAndTransferMatchedRules(); | |
458 } | |
459 | |
460 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col
lector, bool includeEmptyRules) | 444 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col
lector, bool includeEmptyRules) |
461 { | 445 { |
462 collector.clearMatchedRules(); | 446 collector.clearMatchedRules(); |
463 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; | 447 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; |
464 | 448 |
465 bool applyAuthorStyles = applyAuthorStylesOf(element); | 449 bool applyAuthorStyles = applyAuthorStylesOf(element); |
466 if (m_styleTree.hasOnlyScopedResolverForDocument()) { | 450 if (m_styleTree.hasOnlyScopedResolverForDocument()) { |
467 m_styleTree.scopedStyleResolverForDocument()->collectMatchingAuthorRules
(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope); | 451 m_styleTree.scopedStyleResolverForDocument()->collectMatchingAuthorRules
(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope); |
468 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | 452 // Use 2 for CascadeOrder, because there is only one scopedStyleResolver
, i.e. |
| 453 // resolvers.size() == 1 and resolvers.size() + 1 == 2. |
| 454 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules,
2); |
469 collector.sortAndTransferMatchedRules(); | 455 collector.sortAndTransferMatchedRules(); |
470 return; | 456 return; |
471 } | 457 } |
472 | 458 |
473 Vector<ScopedStyleResolver*, 8> resolvers; | 459 Vector<ScopedStyleResolver*, 8> resolvers; |
474 m_styleTree.resolveScopedStyles(element, resolvers); | 460 m_styleTree.resolveScopedStyles(element, resolvers); |
475 | |
476 Vector<ScopedStyleResolver*, 8> resolversInShadowTree; | |
477 m_styleTree.collectScopedResolversForHostedShadowTrees(element, resolversInS
hadowTree); | |
478 if (!resolversInShadowTree.isEmpty()) { | |
479 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res
olvers, resolversInShadowTree); | |
480 return; | |
481 } | |
482 | |
483 if (resolvers.isEmpty()) | 461 if (resolvers.isEmpty()) |
484 return; | 462 return; |
485 | |
486 CascadeScope cascadeScope = 0; | 463 CascadeScope cascadeScope = 0; |
487 CascadeOrder cascadeOrder = resolvers.size(); | 464 CascadeOrder cascadeOrder = resolvers.size(); |
488 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) { | 465 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) { |
489 ScopedStyleResolver* resolver = resolvers.at(i); | 466 ScopedStyleResolver* resolver = resolvers.at(i); |
| 467 CascadeOrder resolverOrder = resolver->treeScope() == element->treeScope
() && resolver->scopingNode().isShadowRoot() ? 0 : cascadeOrder; |
490 // FIXME: Need to clarify how to treat style scoped. | 468 // FIXME: Need to clarify how to treat style scoped. |
491 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply
AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r
esolver->scopingNode().isShadowRoot() ? 0 : cascadeOrder); | 469 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply
AuthorStyles, cascadeScope, resolverOrder); |
| 470 if (resolver->crossingScopeBoundary(element)) |
| 471 ++cascadeScope; |
492 } | 472 } |
493 | 473 |
494 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | 474 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules, reso
lvers.size() + 1); |
495 collector.sortAndTransferMatchedRules(); | 475 collector.sortAndTransferMatchedRules(); |
496 } | 476 } |
497 | 477 |
498 void StyleResolver::matchWatchSelectorRules(ElementRuleCollector& collector) | 478 void StyleResolver::matchWatchSelectorRules(ElementRuleCollector& collector) |
499 { | 479 { |
500 if (!m_watchedSelectorsRules) | 480 if (!m_watchedSelectorsRules) |
501 return; | 481 return; |
502 | 482 |
503 collector.clearMatchedRules(); | 483 collector.clearMatchedRules(); |
504 collector.matchedResult().ranges.lastUserRule = collector.matchedResult().ma
tchedProperties.size() - 1; | 484 collector.matchedResult().ranges.lastUserRule = collector.matchedResult().ma
tchedProperties.size() - 1; |
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 bool StyleResolver::mediaQueryAffectedByViewportChange() const | 1494 bool StyleResolver::mediaQueryAffectedByViewportChange() const |
1515 { | 1495 { |
1516 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) { | 1496 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) { |
1517 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio
n) != m_viewportDependentMediaQueryResults[i]->m_result) | 1497 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio
n) != m_viewportDependentMediaQueryResults[i]->m_result) |
1518 return true; | 1498 return true; |
1519 } | 1499 } |
1520 return false; | 1500 return false; |
1521 } | 1501 } |
1522 | 1502 |
1523 } // namespace WebCore | 1503 } // namespace WebCore |
OLD | NEW |