| 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 RefPtr<CSSRule> cssRule = rule->createCSSOMWrapper(sheet); |
| 210 if (sheet) |
| 211 sheet->registerExtraChildRuleCSSOMWrapper(cssRule); |
| 212 ensureRuleList()->rules().append(cssRule); |
| 213 } |
| 214 |
| 181 void ElementRuleCollector::sortAndTransferMatchedRules() | 215 void ElementRuleCollector::sortAndTransferMatchedRules() |
| 182 { | 216 { |
| 183 if (!m_matchedRules || m_matchedRules->isEmpty()) | 217 if (!m_matchedRules || m_matchedRules->isEmpty()) |
| 184 return; | 218 return; |
| 185 | 219 |
| 186 sortMatchedRules(); | 220 sortMatchedRules(); |
| 187 | 221 |
| 188 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; | 222 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; |
| 189 if (m_mode == SelectorChecker::CollectingRules) { | 223 if (m_mode == SelectorChecker::CollectingRules) { |
| 190 for (unsigned i = 0; i < matchedRules.size(); ++i) | 224 for (unsigned i = 0; i < matchedRules.size(); ++i) { |
| 191 ensureRuleList()->rules().append(matchedRules[i].ruleData()->rule()-
>createCSSOMWrapper()); | 225 appendCSSOMWrapperForRule(matchedRules[i].ruleData()->rule()); |
| 226 } |
| 192 return; | 227 return; |
| 193 } | 228 } |
| 194 | 229 |
| 195 // Now transfer the set of matched rules over to our list of declarations. | 230 // Now transfer the set of matched rules over to our list of declarations. |
| 196 for (unsigned i = 0; i < matchedRules.size(); i++) { | 231 for (unsigned i = 0; i < matchedRules.size(); i++) { |
| 197 // FIXME: Matching should not modify the style directly. | 232 // FIXME: Matching should not modify the style directly. |
| 198 const RuleData* ruleData = matchedRules[i].ruleData(); | 233 const RuleData* ruleData = matchedRules[i].ruleData(); |
| 199 if (m_style && ruleData->containsUncommonAttributeSelector()) | 234 if (m_style && ruleData->containsUncommonAttributeSelector()) |
| 200 m_style->setUnique(); | 235 m_style->setUnique(); |
| 201 m_result.addMatchedProperties(ruleData->rule()->properties(), ruleData->
rule(), ruleData->linkMatchType(), ruleData->propertyWhitelistType(m_matchingUAR
ules)); | 236 m_result.addMatchedProperties(ruleData->rule()->properties(), ruleData->
rule(), ruleData->linkMatchType(), ruleData->propertyWhitelistType(m_matchingUAR
ules)); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // information about "scope". | 357 // information about "scope". |
| 323 int firstRuleIndex = -1, lastRuleIndex = -1; | 358 int firstRuleIndex = -1, lastRuleIndex = -1; |
| 324 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); | 359 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
| 325 // FIXME: Verify whether it's ok to ignore CascadeScope here. | 360 // FIXME: Verify whether it's ok to ignore CascadeScope here. |
| 326 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Stay
sWithinTreeScope); | 361 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Stay
sWithinTreeScope); |
| 327 | 362 |
| 328 return m_matchedRules && !m_matchedRules->isEmpty(); | 363 return m_matchedRules && !m_matchedRules->isEmpty(); |
| 329 } | 364 } |
| 330 | 365 |
| 331 } // namespace WebCore | 366 } // namespace WebCore |
| OLD | NEW |