| 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 25 matching lines...) Expand all Loading... |
| 36 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 36 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 37 #include "sky/engine/core/rendering/style/RenderStyle.h" | 37 #include "sky/engine/core/rendering/style/RenderStyle.h" |
| 38 #include "sky/engine/core/rendering/style/StyleInheritedData.h" | 38 #include "sky/engine/core/rendering/style/StyleInheritedData.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 ElementRuleCollector::ElementRuleCollector(const ElementResolveContext& context, | 42 ElementRuleCollector::ElementRuleCollector(const ElementResolveContext& context, |
| 43 RenderStyle* style) | 43 RenderStyle* style) |
| 44 : m_context(context) | 44 : m_context(context) |
| 45 , m_style(style) | 45 , m_style(style) |
| 46 , m_matchingUARules(false) | |
| 47 { } | 46 { } |
| 48 | 47 |
| 49 ElementRuleCollector::~ElementRuleCollector() | 48 ElementRuleCollector::~ElementRuleCollector() |
| 50 { | 49 { |
| 51 } | 50 } |
| 52 | 51 |
| 53 MatchResult& ElementRuleCollector::matchedResult() | 52 MatchResult& ElementRuleCollector::matchedResult() |
| 54 { | 53 { |
| 55 return m_result; | 54 return m_result; |
| 56 } | 55 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 74 if (!propertySet) | 73 if (!propertySet) |
| 75 return; | 74 return; |
| 76 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); | 75 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); |
| 77 if (m_result.ranges.firstAuthorRule == -1) | 76 if (m_result.ranges.firstAuthorRule == -1) |
| 78 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; | 77 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; |
| 79 m_result.addMatchedProperties(propertySet); | 78 m_result.addMatchedProperties(propertySet); |
| 80 if (!isCacheable) | 79 if (!isCacheable) |
| 81 m_result.isCacheable = false; | 80 m_result.isCacheable = false; |
| 82 } | 81 } |
| 83 | 82 |
| 84 static bool rulesApplicableInCurrentTreeScope(const Element* element, const Cont
ainerNode* scopingNode) | |
| 85 { | |
| 86 TreeScope& treeScope = element->treeScope(); | |
| 87 return !scopingNode || | |
| 88 treeScope == scopingNode->treeScope() || | |
| 89 SelectorChecker::isHostInItsShadowTree(*element, scopingNode); | |
| 90 } | |
| 91 | |
| 92 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, CascadeOrder cascadeOrder) | 83 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest
, RuleRange& ruleRange, CascadeOrder cascadeOrder) |
| 93 { | 84 { |
| 94 ASSERT(matchRequest.ruleSet); | 85 ASSERT(matchRequest.ruleSet); |
| 95 ASSERT(m_context.element()); | 86 ASSERT(m_context.element()); |
| 96 | 87 |
| 97 Element& element = *m_context.element(); | 88 Element& element = *m_context.element(); |
| 98 | 89 |
| 99 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match
Request.scope)) | |
| 100 return; | |
| 101 | |
| 102 // We need to collect the rules for id, class, tag, and everything else into
a buffer and | 90 // We need to collect the rules for id, class, tag, and everything else into
a buffer and |
| 103 // then sort the buffer. | 91 // then sort the buffer. |
| 104 if (element.hasID()) | 92 if (element.hasID()) |
| 105 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), cascadeOrder, matchRequest, ruleRange); | 93 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS
tyleResolution()), cascadeOrder, matchRequest, ruleRange); |
| 106 if (element.isStyledElement() && element.hasClass()) { | 94 if (element.isStyledElement() && element.hasClass()) { |
| 107 for (size_t i = 0; i < element.classNames().size(); ++i) | 95 for (size_t i = 0; i < element.classNames().size(); ++i) |
| 108 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), cascadeOrder, matchRequest, ruleRange); | 96 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element
.classNames()[i]), cascadeOrder, matchRequest, ruleRange); |
| 109 } | 97 } |
| 110 | 98 |
| 111 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), cascadeOrder, matchRequest, ruleRange); | 99 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName
()), cascadeOrder, matchRequest, ruleRange); |
| 112 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeO
rder, matchRequest, ruleRange); | 100 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeO
rder, matchRequest, ruleRange); |
| 113 } | 101 } |
| 114 | 102 |
| 103 void ElementRuleCollector::collectMatchingHostRules(const MatchRequest& matchReq
uest, RuleRange& ruleRange, CascadeOrder cascadeOrder) |
| 104 { |
| 105 collectMatchingRulesForList(matchRequest.ruleSet->hostRules(), cascadeOrder,
matchRequest, ruleRange); |
| 106 } |
| 107 |
| 115 void ElementRuleCollector::sortAndTransferMatchedRules() | 108 void ElementRuleCollector::sortAndTransferMatchedRules() |
| 116 { | 109 { |
| 117 if (!m_matchedRules || m_matchedRules->isEmpty()) | 110 if (!m_matchedRules || m_matchedRules->isEmpty()) |
| 118 return; | 111 return; |
| 119 | 112 |
| 120 sortMatchedRules(); | 113 sortMatchedRules(); |
| 121 | 114 |
| 122 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; | 115 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; |
| 123 | 116 |
| 124 // Now transfer the set of matched rules over to our list of declarations. | 117 // Now transfer the set of matched rules over to our list of declarations. |
| 125 for (unsigned i = 0; i < matchedRules.size(); i++) { | 118 for (unsigned i = 0; i < matchedRules.size(); i++) { |
| 126 const RuleData* ruleData = matchedRules[i].ruleData(); | 119 const RuleData* ruleData = matchedRules[i].ruleData(); |
| 127 m_result.addMatchedProperties(&ruleData->rule()->properties()); | 120 m_result.addMatchedProperties(&ruleData->rule()->properties()); |
| 128 } | 121 } |
| 129 } | 122 } |
| 130 | 123 |
| 131 inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const Co
ntainerNode* scope) | 124 inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData) |
| 132 { | 125 { |
| 133 SelectorChecker checker(*m_context.element()); | 126 SelectorChecker checker(*m_context.element()); |
| 134 if (checker.match(ruleData.selector(), scope)) { | 127 if (checker.match(ruleData.selector())) { |
| 135 if (checker.matchedAttributeSelector()) | 128 if (checker.matchedAttributeSelector()) |
| 136 m_style->setUnique(); | 129 m_style->setUnique(); |
| 137 if (checker.matchedFocusSelector()) | 130 if (checker.matchedFocusSelector()) |
| 138 m_style->setAffectedByFocus(); | 131 m_style->setAffectedByFocus(); |
| 139 if (checker.matchedHoverSelector()) | 132 if (checker.matchedHoverSelector()) |
| 140 m_style->setAffectedByHover(); | 133 m_style->setAffectedByHover(); |
| 141 if (checker.matchedActiveSelector()) | 134 if (checker.matchedActiveSelector()) |
| 142 m_style->setAffectedByActive(); | 135 m_style->setAffectedByActive(); |
| 143 return true; | 136 return true; |
| 144 } | 137 } |
| 145 return false; | 138 return false; |
| 146 } | 139 } |
| 147 | 140 |
| 148 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad
eOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) | 141 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad
eOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) |
| 149 { | 142 { |
| 150 StyleRule* rule = ruleData.rule(); | 143 StyleRule* rule = ruleData.rule(); |
| 151 if (ruleMatches(ruleData, matchRequest.scope)) { | 144 if (ruleMatches(ruleData)) { |
| 152 // If the rule has no properties to apply, then ignore it in the non-deb
ug mode. | 145 // If the rule has no properties to apply, then ignore it in the non-deb
ug mode. |
| 153 const StylePropertySet& properties = rule->properties(); | 146 const StylePropertySet& properties = rule->properties(); |
| 154 if (properties.isEmpty()) | 147 if (properties.isEmpty()) |
| 155 return; | 148 return; |
| 156 | 149 |
| 157 // Update our first/last rule indices in the matched rules array. | 150 // Update our first/last rule indices in the matched rules array. |
| 158 ++ruleRange.lastRuleIndex; | 151 ++ruleRange.lastRuleIndex; |
| 159 if (ruleRange.firstRuleIndex == -1) | 152 if (ruleRange.firstRuleIndex == -1) |
| 160 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; | 153 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; |
| 161 | 154 |
| 162 // Add this rule to our list of matched rules. | 155 // Add this rule to our list of matched rules. |
| 163 addMatchedRule(&ruleData, cascadeOrder, matchRequest.styleSheetIndex, ma
tchRequest.styleSheet); | 156 addMatchedRule(&ruleData, cascadeOrder, matchRequest.styleSheetIndex, ma
tchRequest.styleSheet); |
| 164 } | 157 } |
| 165 } | 158 } |
| 166 | 159 |
| 167 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu
le& matchedRule2) | 160 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu
le& matchedRule2) |
| 168 { | 161 { |
| 169 return matchedRule1.position() < matchedRule2.position(); | 162 return matchedRule1.position() < matchedRule2.position(); |
| 170 } | 163 } |
| 171 | 164 |
| 172 void ElementRuleCollector::sortMatchedRules() | 165 void ElementRuleCollector::sortMatchedRules() |
| 173 { | 166 { |
| 174 ASSERT(m_matchedRules); | 167 ASSERT(m_matchedRules); |
| 175 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); | 168 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); |
| 176 } | 169 } |
| 177 | 170 |
| 178 } // namespace blink | 171 } // namespace blink |
| OLD | NEW |