| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
| 4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 ScopedStyleResolver* ScopedStyleResolver::parent() const | 49 ScopedStyleResolver* ScopedStyleResolver::parent() const |
| 50 { | 50 { |
| 51 for (TreeScope* scope = treeScope().parentTreeScope(); scope; scope = scope-
>parentTreeScope()) { | 51 for (TreeScope* scope = treeScope().parentTreeScope(); scope; scope = scope-
>parentTreeScope()) { |
| 52 if (ScopedStyleResolver* resolver = scope->scopedStyleResolver()) | 52 if (ScopedStyleResolver* resolver = scope->scopedStyleResolver()) |
| 53 return resolver; | 53 return resolver; |
| 54 } | 54 } |
| 55 return nullptr; | 55 return nullptr; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void ScopedStyleResolver::addKeyframeRules(const RuleSet& ruleSet) | 58 void ScopedStyleResolver::addKeyframeRules(const RuleSet& ruleSet, CSSStyleSheet
* styleSheet) |
| 59 { | 59 { |
| 60 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes>> keyframesRule
s = ruleSet.keyframesRules(); | 60 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes>> keyframesRule
s = ruleSet.keyframesRules(); |
| 61 for (unsigned i = 0; i < keyframesRules.size(); ++i) | 61 for (unsigned i = 0; i < keyframesRules.size(); ++i) |
| 62 addKeyframeStyle(keyframesRules[i]); | 62 addKeyframeStyle(keyframesRules[i], styleSheet); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void ScopedStyleResolver::addFontFaceRules(const RuleSet& ruleSet) | 65 void ScopedStyleResolver::addFontFaceRules(const RuleSet& ruleSet) |
| 66 { | 66 { |
| 67 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo
r the moment. | 67 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo
r the moment. |
| 68 if (!treeScope().rootNode().isDocumentNode()) | 68 if (!treeScope().rootNode().isDocumentNode()) |
| 69 return; | 69 return; |
| 70 | 70 |
| 71 Document& document = treeScope().document(); | 71 Document& document = treeScope().document(); |
| 72 CSSFontSelector* cssFontSelector = document.styleEngine().fontSelector(); | 72 CSSFontSelector* cssFontSelector = document.styleEngine().fontSelector(); |
| 73 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace>> fontFaceRules
= ruleSet.fontFaceRules(); | 73 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace>> fontFaceRules
= ruleSet.fontFaceRules(); |
| 74 for (auto& fontFaceRule : fontFaceRules) { | 74 for (auto& fontFaceRule : fontFaceRules) { |
| 75 if (RefPtrWillBeRawPtr<FontFace> fontFace = FontFace::create(&document,
fontFaceRule)) | 75 if (RefPtrWillBeRawPtr<FontFace> fontFace = FontFace::create(&document,
fontFaceRule)) |
| 76 cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule,
fontFace); | 76 cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule,
fontFace); |
| 77 } | 77 } |
| 78 if (fontFaceRules.size()) | 78 if (fontFaceRules.size()) |
| 79 document.styleResolver()->invalidateMatchedPropertiesCache(); | 79 document.styleResolver()->invalidateMatchedPropertiesCache(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ScopedStyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet, const Med
iaQueryEvaluator& medium) | 82 void ScopedStyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet, const Med
iaQueryEvaluator& medium) |
| 83 { | 83 { |
| 84 unsigned index = m_authorStyleSheets.size(); | 84 unsigned index = m_authorStyleSheets.size(); |
| 85 m_authorStyleSheets.append(&cssSheet); | 85 m_authorStyleSheets.append(&cssSheet); |
| 86 StyleSheetContents* sheet = cssSheet.contents(); | 86 StyleSheetContents* sheet = cssSheet.contents(); |
| 87 AddRuleFlags addRuleFlags = treeScope().document().securityOrigin()->canRequ
est(sheet->baseURL()) ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState; | 87 AddRuleFlags addRuleFlags = treeScope().document().securityOrigin()->canRequ
est(sheet->baseURL()) ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState; |
| 88 const RuleSet& ruleSet = sheet->ensureRuleSet(medium, addRuleFlags); | 88 const RuleSet& ruleSet = sheet->ensureRuleSet(medium, addRuleFlags); |
| 89 | 89 |
| 90 addKeyframeRules(ruleSet); | 90 addKeyframeRules(ruleSet, &cssSheet); |
| 91 addFontFaceRules(ruleSet); | 91 addFontFaceRules(ruleSet); |
| 92 addTreeBoundaryCrossingRules(ruleSet, &cssSheet, index); | 92 addTreeBoundaryCrossingRules(ruleSet, &cssSheet, index); |
| 93 treeScope().document().styleResolver()->addMediaQueryResults(ruleSet.viewpor
tDependentMediaQueryResults()); | 93 treeScope().document().styleResolver()->addMediaQueryResults(ruleSet.viewpor
tDependentMediaQueryResults()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ScopedStyleResolver::collectFeaturesTo(RuleFeatureSet& features, HashSet<co
nst StyleSheetContents*>& visitedSharedStyleSheetContents) const | 96 void ScopedStyleResolver::collectFeaturesTo(RuleFeatureSet& features, HashSet<co
nst StyleSheetContents*>& visitedSharedStyleSheetContents) const |
| 97 { | 97 { |
| 98 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { | 98 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { |
| 99 ASSERT(m_authorStyleSheets[i]->ownerNode()); | 99 ASSERT(m_authorStyleSheets[i]->ownerNode()); |
| 100 StyleSheetContents* contents = m_authorStyleSheets[i]->contents(); | 100 StyleSheetContents* contents = m_authorStyleSheets[i]->contents(); |
| 101 if (contents->hasOneClient() || visitedSharedStyleSheetContents.add(cont
ents).isNewEntry) | 101 if (contents->hasOneClient() || visitedSharedStyleSheetContents.add(cont
ents).isNewEntry) |
| 102 features.add(contents->ruleSet().features()); | 102 features.add(contents->ruleSet().features()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 if (!m_treeBoundaryCrossingRuleSet) | 105 if (!m_treeBoundaryCrossingRuleSet) |
| 106 return; | 106 return; |
| 107 | 107 |
| 108 for (const auto& rules : *m_treeBoundaryCrossingRuleSet) | 108 for (const auto& rules : *m_treeBoundaryCrossingRuleSet) |
| 109 features.add(rules->m_ruleSet->features()); | 109 features.add(rules->m_ruleSet->features()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void ScopedStyleResolver::resetAuthorStyle() | 112 void ScopedStyleResolver::resetAuthorStyle() |
| 113 { | 113 { |
| 114 m_authorStyleSheets.clear(); | 114 m_authorStyleSheets.clear(); |
| 115 m_keyframesRuleMap.clear(); | 115 m_keyframesRuleMap.clear(); |
| 116 m_keyframesStyleSheetMap.clear(); |
| 116 m_treeBoundaryCrossingRuleSet = nullptr; | 117 m_treeBoundaryCrossingRuleSet = nullptr; |
| 117 } | 118 } |
| 118 | 119 |
| 119 StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(const String
Impl* animationName) | 120 StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(const String
Impl* animationName) |
| 120 { | 121 { |
| 121 if (m_keyframesRuleMap.isEmpty()) | 122 if (m_keyframesRuleMap.isEmpty()) |
| 122 return nullptr; | 123 return nullptr; |
| 123 | 124 |
| 124 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(animationName); | 125 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(animationName); |
| 125 if (it == m_keyframesRuleMap.end()) | 126 if (it == m_keyframesRuleMap.end()) |
| 126 return nullptr; | 127 return nullptr; |
| 127 | 128 |
| 128 return it->value.get(); | 129 return it->value.get(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void ScopedStyleResolver::addKeyframeStyle(PassRefPtrWillBeRawPtr<StyleRuleKeyfr
ames> rule) | 132 CSSStyleSheet* ScopedStyleResolver::styleSheetForAnimation(const StringImpl* ani
mationName) |
| 133 { |
| 134 if (m_keyframesStyleSheetMap.isEmpty()) |
| 135 return nullptr; |
| 136 |
| 137 WillBeHeapHashMap<const StringImpl*, CSSStyleSheet*>::iterator it = m_keyfra
mesStyleSheetMap.find(animationName); |
| 138 if (it == m_keyframesStyleSheetMap.end()) |
| 139 return nullptr; |
| 140 |
| 141 return it->value; |
| 142 } |
| 143 |
| 144 void ScopedStyleResolver::addKeyframeStyle(PassRefPtrWillBeRawPtr<StyleRuleKeyfr
ames> rule, CSSStyleSheet* styleSheet) |
| 132 { | 145 { |
| 133 AtomicString s(rule->name()); | 146 AtomicString s(rule->name()); |
| 134 | 147 |
| 135 if (rule->isVendorPrefixed()) { | 148 if (rule->isVendorPrefixed()) { |
| 136 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(s.impl()); | 149 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(s.impl()); |
| 137 if (it == m_keyframesRuleMap.end()) | 150 if (it == m_keyframesRuleMap.end()) { |
| 138 m_keyframesRuleMap.set(s.impl(), rule); | 151 m_keyframesRuleMap.set(s.impl(), rule); |
| 139 else if (it->value->isVendorPrefixed()) | 152 m_keyframesStyleSheetMap.set(s.impl(), styleSheet); |
| 153 } else if (it->value->isVendorPrefixed()) { |
| 140 m_keyframesRuleMap.set(s.impl(), rule); | 154 m_keyframesRuleMap.set(s.impl(), rule); |
| 155 m_keyframesStyleSheetMap.set(s.impl(), styleSheet); |
| 156 } |
| 141 } else { | 157 } else { |
| 142 m_keyframesRuleMap.set(s.impl(), rule); | 158 m_keyframesRuleMap.set(s.impl(), rule); |
| 159 m_keyframesStyleSheetMap.set(s.impl(), styleSheet); |
| 143 } | 160 } |
| 144 } | 161 } |
| 145 | 162 |
| 146 void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& colle
ctor, bool includeEmptyRules, CascadeOrder cascadeOrder) | 163 void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& colle
ctor, bool includeEmptyRules, CascadeOrder cascadeOrder) |
| 147 { | 164 { |
| 148 ASSERT(!collector.scopeContainsLastMatchedElement()); | 165 ASSERT(!collector.scopeContainsLastMatchedElement()); |
| 149 collector.setScopeContainsLastMatchedElement(true); | 166 collector.setScopeContainsLastMatchedElement(true); |
| 150 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { | 167 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { |
| 151 ASSERT(m_authorStyleSheets[i]->ownerNode()); | 168 ASSERT(m_authorStyleSheets[i]->ownerNode()); |
| 152 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet()
, includeEmptyRules, &m_scope->rootNode(), m_authorStyleSheets[i], i); | 169 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet()
, includeEmptyRules, &m_scope->rootNode(), m_authorStyleSheets[i], i); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 m_treeBoundaryCrossingRuleSet->append(RuleSubSet::create(parentStyleSheet, s
heetIndex, ruleSetForScope.release())); | 246 m_treeBoundaryCrossingRuleSet->append(RuleSubSet::create(parentStyleSheet, s
heetIndex, ruleSetForScope.release())); |
| 230 } | 247 } |
| 231 | 248 |
| 232 DEFINE_TRACE(ScopedStyleResolver::RuleSubSet) | 249 DEFINE_TRACE(ScopedStyleResolver::RuleSubSet) |
| 233 { | 250 { |
| 234 visitor->trace(m_parentStyleSheet); | 251 visitor->trace(m_parentStyleSheet); |
| 235 visitor->trace(m_ruleSet); | 252 visitor->trace(m_ruleSet); |
| 236 } | 253 } |
| 237 | 254 |
| 238 } // namespace blink | 255 } // namespace blink |
| OLD | NEW |