Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 * along with this library; see the file COPYING.LIB. If not, write to | 24 * along with this library; see the file COPYING.LIB. If not, write to |
| 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 26 * Boston, MA 02110-1301, USA. | 26 * Boston, MA 02110-1301, USA. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "core/css/ElementRuleCollector.h" | 30 #include "core/css/ElementRuleCollector.h" |
| 31 | 31 |
| 32 #include "core/css/CSSRuleList.h" | 32 #include "core/css/CSSRuleList.h" |
| 33 #include "core/css/CSSSelector.h" | 33 #include "core/css/CSSSelector.h" |
| 34 #include "core/css/CSSStyleRule.h" | |
| 34 #include "core/css/SelectorCheckerFastPath.h" | 35 #include "core/css/SelectorCheckerFastPath.h" |
| 35 #include "core/css/SiblingTraversalStrategies.h" | 36 #include "core/css/SiblingTraversalStrategies.h" |
| 36 #include "core/css/StylePropertySet.h" | 37 #include "core/css/StylePropertySet.h" |
| 37 #include "core/css/resolver/StyleResolver.h" | 38 #include "core/css/resolver/StyleResolver.h" |
| 38 #include "core/dom/shadow/ShadowRoot.h" | 39 #include "core/dom/shadow/ShadowRoot.h" |
| 39 #include "core/rendering/RenderRegion.h" | 40 #include "core/rendering/RenderRegion.h" |
| 40 | 41 |
| 41 namespace WebCore { | 42 namespace WebCore { |
| 42 | 43 |
| 43 ElementRuleCollector::ElementRuleCollector(const ElementResolveContext& context, | 44 ElementRuleCollector::ElementRuleCollector(const ElementResolveContext& context, |
| 44 const SelectorFilter& filter, RenderStyle* style) | 45 const SelectorFilter& filter, RenderStyle* style, ShouldIncludeStyleSheetInC SSOMWrapper includeStyleSheet) |
| 45 : m_context(context) | 46 : m_context(context) |
| 46 , m_selectorFilter(filter) | 47 , m_selectorFilter(filter) |
| 47 , m_style(style) | 48 , m_style(style) |
| 48 , m_regionForStyling(0) | 49 , m_regionForStyling(0) |
| 49 , m_pseudoStyleRequest(NOPSEUDO) | 50 , m_pseudoStyleRequest(NOPSEUDO) |
| 50 , m_mode(SelectorChecker::ResolvingStyle) | 51 , m_mode(SelectorChecker::ResolvingStyle) |
| 51 , m_canUseFastReject(m_selectorFilter.parentStackIsConsistent(context.parent Node())) | 52 , m_canUseFastReject(m_selectorFilter.parentStackIsConsistent(context.parent Node())) |
| 52 , m_sameOriginOnly(false) | 53 , m_sameOriginOnly(false) |
| 53 , m_matchingUARules(false) | 54 , m_matchingUARules(false) |
| 55 , m_includeStyleSheet(includeStyleSheet) | |
| 54 { } | 56 { } |
| 55 | 57 |
| 56 ElementRuleCollector::~ElementRuleCollector() | 58 ElementRuleCollector::~ElementRuleCollector() |
| 57 { | 59 { |
| 58 } | 60 } |
| 59 | 61 |
| 60 MatchResult& ElementRuleCollector::matchedResult() | 62 MatchResult& ElementRuleCollector::matchedResult() |
| 61 { | 63 { |
| 62 return m_result; | 64 return m_result; |
| 63 } | 65 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 for (unsigned i = 0; i < size; ++i) { | 173 for (unsigned i = 0; i < size; ++i) { |
| 172 const CSSSelector* regionSelector = matchRequest.ruleSet->m_regionSelect orsAndRuleSets.at(i).selector; | 174 const CSSSelector* regionSelector = matchRequest.ruleSet->m_regionSelect orsAndRuleSets.at(i).selector; |
| 173 if (checkRegionSelector(regionSelector, toElement(m_regionForStyling->no de()))) { | 175 if (checkRegionSelector(regionSelector, toElement(m_regionForStyling->no de()))) { |
| 174 RuleSet* regionRules = matchRequest.ruleSet->m_regionSelectorsAndRul eSets.at(i).ruleSet.get(); | 176 RuleSet* regionRules = matchRequest.ruleSet->m_regionSelectorsAndRul eSets.at(i).ruleSet.get(); |
| 175 ASSERT(regionRules); | 177 ASSERT(regionRules); |
| 176 collectMatchingRules(MatchRequest(regionRules, matchRequest.includeE mptyRules, matchRequest.scope), ruleRange, behaviorAtBoundary, cascadeScope, cas cadeOrder); | 178 collectMatchingRules(MatchRequest(regionRules, matchRequest.includeE mptyRules, matchRequest.scope), ruleRange, behaviorAtBoundary, cascadeScope, cas cadeOrder); |
| 177 } | 179 } |
| 178 } | 180 } |
| 179 } | 181 } |
| 180 | 182 |
| 183 | |
| 184 static CSSStyleSheet* findStyleSheet(StyleEngine* styleEngine, StyleRule* rule) | |
| 185 { | |
| 186 // FIXME: StyleEngine has a bunch of different accessors for StyleSheet list s, is this the only one we need to care about? | |
| 187 const Vector<RefPtr<CSSStyleSheet> >& stylesheets = styleEngine->activeAutho rStyleSheets(); | |
| 188 for (size_t i = 0; i < stylesheets.size(); ++i) { | |
| 189 CSSStyleSheet* sheet = stylesheets[i].get(); | |
| 190 for (unsigned j = 0; j < sheet->length(); ++j) { | |
| 191 CSSRule* cssRule = sheet->item(j); | |
| 192 if (cssRule->type() != CSSRule::STYLE_RULE) | |
| 193 continue; | |
| 194 CSSStyleRule* cssStyleRule = toCSSStyleRule(cssRule); | |
| 195 if (cssStyleRule->styleRule() == rule) | |
| 196 return sheet; | |
| 197 } | |
| 198 } | |
| 199 return 0; | |
| 200 } | |
| 201 | |
| 202 void ElementRuleCollector::appendCSSOMWrapperForRule(StyleRule* rule) | |
| 203 { | |
| 204 // FIXME: There should be no codepath that creates a CSSOMWrapper without a parent stylesheet or rule because | |
| 205 // then that codepath can lead to the CSSStyleSheet contents not getting cor rectly copied when the rule is modified | |
| 206 // through the wrapper (e.g. rule.selectorText="div"). Right now, the inspec tor uses the pointers for identity though, | |
| 207 // so calling CSSStyleSheet->willMutateRules breaks the inspector. | |
| 208 CSSStyleSheet* sheet = m_includeStyleSheet == IncludeStyleSheetInCSSOMWrappe r ? findStyleSheet(m_context.element()->document().styleEngine(), rule) : 0; | |
| 209 // We need to call willMutateRules so that the StyleSheetContents are copy-o n-writed before we create the CSSOMWrappers. | |
| 210 // Otherwise, if the sheet is modified through the regular CSSOM, the CSSOMW rappers created here won't be updated | |
| 211 // to point to the new copied StyleRules. An alternate solution would be to update all the CSSOMWrappers when | |
| 212 // the stylesheet is modified. | |
| 213 if (sheet) { | |
| 214 sheet->willMutateRules(); | |
| 215 sheet->didMutateRules(); | |
|
esprehn
2013/10/28 23:54:08
I think you're supposed to call didMutateRules at
ojan
2013/10/28 23:59:58
This function doesn't actually mutate the rules th
| |
| 216 } | |
| 217 RefPtr<CSSRule> cssRule = rule->createCSSOMWrapper(sheet); | |
| 218 if (sheet) | |
| 219 sheet->registerExtraChildRuleCSSOMWrapper(cssRule); | |
| 220 ensureRuleList()->rules().append(cssRule); | |
| 221 } | |
| 222 | |
| 181 void ElementRuleCollector::sortAndTransferMatchedRules() | 223 void ElementRuleCollector::sortAndTransferMatchedRules() |
| 182 { | 224 { |
| 183 if (!m_matchedRules || m_matchedRules->isEmpty()) | 225 if (!m_matchedRules || m_matchedRules->isEmpty()) |
| 184 return; | 226 return; |
| 185 | 227 |
| 186 sortMatchedRules(); | 228 sortMatchedRules(); |
| 187 | 229 |
| 188 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; | 230 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; |
| 189 if (m_mode == SelectorChecker::CollectingRules) { | 231 if (m_mode == SelectorChecker::CollectingRules) { |
| 190 for (unsigned i = 0; i < matchedRules.size(); ++i) | 232 for (unsigned i = 0; i < matchedRules.size(); ++i) { |
| 191 ensureRuleList()->rules().append(matchedRules[i].ruleData()->rule()- >createCSSOMWrapper()); | 233 appendCSSOMWrapperForRule(matchedRules[i].ruleData()->rule()); |
| 234 } | |
| 192 return; | 235 return; |
| 193 } | 236 } |
| 194 | 237 |
| 195 // Now transfer the set of matched rules over to our list of declarations. | 238 // Now transfer the set of matched rules over to our list of declarations. |
| 196 for (unsigned i = 0; i < matchedRules.size(); i++) { | 239 for (unsigned i = 0; i < matchedRules.size(); i++) { |
| 197 // FIXME: Matching should not modify the style directly. | 240 // FIXME: Matching should not modify the style directly. |
| 198 const RuleData* ruleData = matchedRules[i].ruleData(); | 241 const RuleData* ruleData = matchedRules[i].ruleData(); |
| 199 if (m_style && ruleData->containsUncommonAttributeSelector()) | 242 if (m_style && ruleData->containsUncommonAttributeSelector()) |
| 200 m_style->setUnique(); | 243 m_style->setUnique(); |
| 201 m_result.addMatchedProperties(ruleData->rule()->properties(), ruleData-> rule(), ruleData->linkMatchType(), ruleData->propertyWhitelistType(m_matchingUAR ules)); | 244 m_result.addMatchedProperties(ruleData->rule()->properties(), ruleData-> rule(), ruleData->linkMatchType(), ruleData->propertyWhitelistType(m_matchingUAR ules)); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 // information about "scope". | 364 // information about "scope". |
| 322 int firstRuleIndex = -1, lastRuleIndex = -1; | 365 int firstRuleIndex = -1, lastRuleIndex = -1; |
| 323 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); | 366 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
| 324 // FIXME: Verify whether it's ok to ignore CascadeScope here. | 367 // FIXME: Verify whether it's ok to ignore CascadeScope here. |
| 325 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Stay sWithinTreeScope); | 368 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Stay sWithinTreeScope); |
| 326 | 369 |
| 327 return m_matchedRules && !m_matchedRules->isEmpty(); | 370 return m_matchedRules && !m_matchedRules->isEmpty(); |
| 328 } | 371 } |
| 329 | 372 |
| 330 } // namespace WebCore | 373 } // namespace WebCore |
| OLD | NEW |