This source file includes following definitions.
- scopingNodeFor
- addRulesFromSheet
- collectFeaturesTo
- resetAuthorStyle
- keyframeStylesForAnimation
- addKeyframeStyle
- collectMatchingAuthorRules
- matchPageRules
- collectViewportRulesTo
#include "config.h"
#include "core/css/resolver/ScopedStyleResolver.h"
#include "HTMLNames.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/PageRuleCollector.h"
#include "core/css/RuleFeature.h"
#include "core/css/StyleRule.h"
#include "core/css/StyleSheetContents.h"
#include "core/css/resolver/StyleResolver.h"
#include "core/css/resolver/ViewportStyleResolver.h"
#include "core/dom/Document.h"
#include "core/dom/shadow/ElementShadow.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/html/HTMLStyleElement.h"
namespace WebCore {
ContainerNode* ScopedStyleResolver::scopingNodeFor(Document& document, const CSSStyleSheet* sheet)
{
ASSERT(sheet);
Document* sheetDocument = sheet->ownerDocument();
if (!sheetDocument)
return 0;
Node* ownerNode = sheet->ownerNode();
if (!isHTMLStyleElement(ownerNode))
return &document;
HTMLStyleElement& styleElement = toHTMLStyleElement(*ownerNode);
if (!styleElement.scoped()) {
if (styleElement.isInShadowTree())
return styleElement.containingShadowRoot();
return &document;
}
ContainerNode* parent = styleElement.parentNode();
if (!parent)
return 0;
return (parent->isElementNode() || parent->isShadowRoot()) ? parent : 0;
}
void ScopedStyleResolver::addRulesFromSheet(CSSStyleSheet* cssSheet, const MediaQueryEvaluator& medium, StyleResolver* resolver)
{
m_authorStyleSheets.append(cssSheet);
StyleSheetContents* sheet = cssSheet->contents();
AddRuleFlags addRuleFlags = resolver->document().securityOrigin()->canRequest(sheet->baseURL()) ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState;
const RuleSet& ruleSet = sheet->ensureRuleSet(medium, addRuleFlags);
resolver->addMediaQueryResults(ruleSet.viewportDependentMediaQueryResults());
resolver->processScopedRules(ruleSet, sheet->baseURL(), &m_scopingNode);
}
void ScopedStyleResolver::collectFeaturesTo(RuleFeatureSet& features, HashSet<const StyleSheetContents*>& visitedSharedStyleSheetContents)
{
for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) {
StyleSheetContents* contents = m_authorStyleSheets[i]->contents();
if (contents->hasOneClient() || visitedSharedStyleSheetContents.add(contents).isNewEntry)
features.add(contents->ruleSet().features());
}
}
void ScopedStyleResolver::resetAuthorStyle()
{
m_authorStyleSheets.clear();
m_keyframesRuleMap.clear();
}
const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(const StringImpl* animationName)
{
if (m_keyframesRuleMap.isEmpty())
return 0;
KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(animationName);
if (it == m_keyframesRuleMap.end())
return 0;
return it->value.get();
}
void ScopedStyleResolver::addKeyframeStyle(PassRefPtrWillBeRawPtr<StyleRuleKeyframes> rule)
{
AtomicString s(rule->name());
if (rule->isVendorPrefixed()) {
KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(rule->name().impl());
if (it == m_keyframesRuleMap.end())
m_keyframesRuleMap.set(s.impl(), rule);
else if (it->value->isVendorPrefixed())
m_keyframesRuleMap.set(s.impl(), rule);
} else {
m_keyframesRuleMap.set(s.impl(), rule);
}
}
void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& collector, bool includeEmptyRules, bool applyAuthorStyles, CascadeScope cascadeScope, CascadeOrder cascadeOrder)
{
const ContainerNode* scopingNode = &m_scopingNode;
unsigned behaviorAtBoundary = SelectorChecker::DoesNotCrossBoundary;
if (!applyAuthorStyles)
behaviorAtBoundary |= SelectorChecker::ScopeContainsLastMatchedElement;
if (m_scopingNode.isShadowRoot()) {
scopingNode = toShadowRoot(m_scopingNode).host();
behaviorAtBoundary |= SelectorChecker::ScopeIsShadowHost;
}
for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) {
MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet(), includeEmptyRules, scopingNode, applyAuthorStyles, i, m_authorStyleSheets[i]);
collector.collectMatchingRules(matchRequest, collector.matchedResult().ranges.authorRuleRange(), static_cast<SelectorChecker::BehaviorAtBoundary>(behaviorAtBoundary), cascadeScope, cascadeOrder);
}
}
void ScopedStyleResolver::matchPageRules(PageRuleCollector& collector)
{
ASSERT(m_scopingNode.isDocumentNode());
for (size_t i = 0; i < m_authorStyleSheets.size(); ++i)
collector.matchPageRules(&m_authorStyleSheets[i]->contents()->ruleSet());
}
void ScopedStyleResolver::collectViewportRulesTo(StyleResolver* resolver) const
{
if (!m_scopingNode.isDocumentNode())
return;
for (size_t i = 0; i < m_authorStyleSheets.size(); ++i)
resolver->viewportStyleResolver()->collectViewportRules(&m_authorStyleSheets[i]->contents()->ruleSet(), ViewportStyleResolver::AuthorOrigin);
}
}