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 Apple Inc. All | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All |
| 6 * rights reserved. | 6 * rights reserved. |
| 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 10 * (http://www.torchmobile.com/) | 10 * (http://www.torchmobile.com/) |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 void RuleSet::AddToRuleSet(const AtomicString& key, | 140 void RuleSet::AddToRuleSet(const AtomicString& key, |
| 141 PendingRuleMap& map, | 141 PendingRuleMap& map, |
| 142 const RuleData& rule_data) { | 142 const RuleData& rule_data) { |
| 143 Member<HeapLinkedStack<RuleData>>& rules = | 143 Member<HeapLinkedStack<RuleData>>& rules = |
| 144 map.insert(key, nullptr).stored_value->value; | 144 map.insert(key, nullptr).stored_value->value; |
| 145 if (!rules) | 145 if (!rules) |
| 146 rules = new HeapLinkedStack<RuleData>; | 146 rules = new HeapLinkedStack<RuleData>; |
| 147 rules->Push(rule_data); | 147 rules->Push(rule_data); |
| 148 } | 148 } |
| 149 | 149 |
| 150 static void ExtractValuesforSelector(const CSSSelector* selector, | 150 static void ExtractSelectorValues(const CSSSelector* selector, |
| 151 AtomicString& id, | 151 AtomicString& id, |
| 152 AtomicString& class_name, | 152 AtomicString& class_name, |
| 153 AtomicString& custom_pseudo_element_name, | 153 AtomicString& custom_pseudo_element_name, |
| 154 AtomicString& tag_name) { | 154 AtomicString& tag_name, |
| 155 CSSSelector::PseudoType& pseudoType) { | |
|
rune
2017/05/10 08:46:02
camelCase?
| |
| 155 switch (selector->Match()) { | 156 switch (selector->Match()) { |
| 156 case CSSSelector::kId: | 157 case CSSSelector::kId: |
| 157 id = selector->Value(); | 158 id = selector->Value(); |
| 158 break; | 159 break; |
| 159 case CSSSelector::kClass: | 160 case CSSSelector::kClass: |
| 160 class_name = selector->Value(); | 161 class_name = selector->Value(); |
| 161 break; | 162 break; |
| 162 case CSSSelector::kTag: | 163 case CSSSelector::kTag: |
| 163 if (selector->TagQName().LocalName() != g_star_atom) | 164 if (selector->TagQName().LocalName() != g_star_atom) |
| 164 tag_name = selector->TagQName().LocalName(); | 165 tag_name = selector->TagQName().LocalName(); |
| 165 break; | 166 break; |
| 167 case CSSSelector::kPseudoClass: | |
| 168 case CSSSelector::kPseudoElement: | |
| 169 case CSSSelector::kPagePseudoClass: | |
| 170 // Must match the cases in RuleSet::FindBestRuleSetAndAdd. | |
| 171 switch (selector->GetPseudoType()) { | |
| 172 case CSSSelector::kPseudoCue: | |
| 173 case CSSSelector::kPseudoLink: | |
| 174 case CSSSelector::kPseudoVisited: | |
| 175 case CSSSelector::kPseudoAnyLink: | |
| 176 case CSSSelector::kPseudoFocus: | |
| 177 case CSSSelector::kPseudoPlaceholder: | |
| 178 case CSSSelector::kPseudoHost: | |
| 179 case CSSSelector::kPseudoHostContext: | |
| 180 pseudoType = selector->GetPseudoType(); | |
| 181 break; | |
| 182 case CSSSelector::kPseudoWebKitCustomElement: | |
| 183 case CSSSelector::kPseudoBlinkInternalElement: | |
| 184 custom_pseudo_element_name = selector->Value(); | |
| 185 break; | |
| 186 default: | |
| 187 break; | |
| 188 } | |
| 166 default: | 189 default: |
| 167 break; | 190 break; |
| 168 } | 191 } |
| 169 if (selector->GetPseudoType() == CSSSelector::kPseudoWebKitCustomElement || | |
| 170 selector->GetPseudoType() == CSSSelector::kPseudoBlinkInternalElement) | |
| 171 custom_pseudo_element_name = selector->Value(); | |
| 172 } | 192 } |
| 173 | 193 |
| 174 bool RuleSet::FindBestRuleSetAndAdd(const CSSSelector& component, | 194 bool RuleSet::FindBestRuleSetAndAdd(const CSSSelector& component, |
| 175 RuleData& rule_data) { | 195 RuleData& rule_data) { |
| 176 AtomicString id; | 196 AtomicString id; |
| 177 AtomicString class_name; | 197 AtomicString class_name; |
| 178 AtomicString custom_pseudo_element_name; | 198 AtomicString custom_pseudo_element_name; |
| 179 AtomicString tag_name; | 199 AtomicString tag_name; |
| 200 CSSSelector::PseudoType pseudoType = CSSSelector::kPseudoUnknown; | |
|
rune
2017/05/10 08:46:02
camelCase?
| |
| 180 | 201 |
| 181 #ifndef NDEBUG | 202 #ifndef NDEBUG |
| 182 all_rules_.push_back(rule_data); | 203 all_rules_.push_back(rule_data); |
| 183 #endif | 204 #endif |
| 184 | 205 |
| 185 const CSSSelector* it = &component; | 206 const CSSSelector* it = &component; |
| 186 for (; it && it->Relation() == CSSSelector::kSubSelector; | 207 for (; it && it->Relation() == CSSSelector::kSubSelector; |
| 187 it = it->TagHistory()) | 208 it = it->TagHistory()) { |
| 188 ExtractValuesforSelector(it, id, class_name, custom_pseudo_element_name, | 209 ExtractSelectorValues(it, id, class_name, custom_pseudo_element_name, |
| 189 tag_name); | 210 tag_name, pseudoType); |
| 190 if (it) | 211 } |
| 191 ExtractValuesforSelector(it, id, class_name, custom_pseudo_element_name, | 212 if (it) { |
| 192 tag_name); | 213 ExtractSelectorValues(it, id, class_name, custom_pseudo_element_name, |
| 214 tag_name, pseudoType); | |
| 215 } | |
| 193 | 216 |
| 194 // Prefer rule sets in order of most likely to apply infrequently. | 217 // Prefer rule sets in order of most likely to apply infrequently. |
| 195 if (!id.IsEmpty()) { | 218 if (!id.IsEmpty()) { |
| 196 AddToRuleSet(id, EnsurePendingRules()->id_rules, rule_data); | 219 AddToRuleSet(id, EnsurePendingRules()->id_rules, rule_data); |
| 197 return true; | 220 return true; |
| 198 } | 221 } |
| 222 | |
| 199 if (!class_name.IsEmpty()) { | 223 if (!class_name.IsEmpty()) { |
| 200 AddToRuleSet(class_name, EnsurePendingRules()->class_rules, rule_data); | 224 AddToRuleSet(class_name, EnsurePendingRules()->class_rules, rule_data); |
| 201 return true; | 225 return true; |
| 202 } | 226 } |
| 227 | |
| 203 if (!custom_pseudo_element_name.IsEmpty()) { | 228 if (!custom_pseudo_element_name.IsEmpty()) { |
| 204 // Custom pseudos come before ids and classes in the order of tagHistory, | 229 // Custom pseudos come before ids and classes in the order of tagHistory, |
| 205 // and have a relation of ShadowPseudo between them. Therefore we should | 230 // and have a relation of ShadowPseudo between them. Therefore we should |
| 206 // never be a situation where extractValuesforSelector finsd id and | 231 // never be a situation where ExtractSelectorValues finds id and |
| 207 // className in addition to custom pseudo. | 232 // className in addition to custom pseudo. |
| 208 DCHECK(id.IsEmpty()); | 233 DCHECK(id.IsEmpty()); |
| 209 DCHECK(class_name.IsEmpty()); | 234 DCHECK(class_name.IsEmpty()); |
| 210 AddToRuleSet(custom_pseudo_element_name, | 235 AddToRuleSet(custom_pseudo_element_name, |
| 211 EnsurePendingRules()->shadow_pseudo_element_rules, rule_data); | 236 EnsurePendingRules()->shadow_pseudo_element_rules, rule_data); |
| 212 return true; | 237 return true; |
| 213 } | 238 } |
| 214 | 239 |
| 215 switch (component.GetPseudoType()) { | 240 switch (pseudoType) { |
|
rune
2017/05/10 08:46:02
So, if I read this correctly:
"[attr]:visited" wi
| |
| 216 case CSSSelector::kPseudoCue: | 241 case CSSSelector::kPseudoCue: |
| 217 cue_pseudo_rules_.push_back(rule_data); | 242 cue_pseudo_rules_.push_back(rule_data); |
| 218 return true; | 243 return true; |
| 219 case CSSSelector::kPseudoLink: | 244 case CSSSelector::kPseudoLink: |
| 220 case CSSSelector::kPseudoVisited: | 245 case CSSSelector::kPseudoVisited: |
| 221 case CSSSelector::kPseudoAnyLink: | 246 case CSSSelector::kPseudoAnyLink: |
| 222 link_pseudo_class_rules_.push_back(rule_data); | 247 link_pseudo_class_rules_.push_back(rule_data); |
| 223 return true; | 248 return true; |
| 224 case CSSSelector::kPseudoFocus: | 249 case CSSSelector::kPseudoFocus: |
| 225 focus_pseudo_class_rules_.push_back(rule_data); | 250 focus_pseudo_class_rules_.push_back(rule_data); |
|
rune
2017/05/10 08:46:02
You say that you remove the html.css ":focus" rule
| |
| 226 return true; | 251 return true; |
| 227 case CSSSelector::kPseudoPlaceholder: | 252 case CSSSelector::kPseudoPlaceholder: |
| 228 placeholder_pseudo_rules_.push_back(rule_data); | 253 placeholder_pseudo_rules_.push_back(rule_data); |
| 229 return true; | 254 return true; |
| 255 case CSSSelector::kPseudoHost: | |
| 256 case CSSSelector::kPseudoHostContext: | |
| 257 shadow_host_rules_.push_back(rule_data); | |
| 258 return true; | |
| 230 default: | 259 default: |
| 231 break; | 260 break; |
| 232 } | 261 } |
| 233 | 262 |
| 234 if (!tag_name.IsEmpty()) { | 263 if (!tag_name.IsEmpty()) { |
| 235 AddToRuleSet(tag_name, EnsurePendingRules()->tag_rules, rule_data); | 264 AddToRuleSet(tag_name, EnsurePendingRules()->tag_rules, rule_data); |
| 236 return true; | 265 return true; |
| 237 } | 266 } |
| 238 | 267 |
| 239 if (component.IsHostPseudoClass()) { | |
| 240 shadow_host_rules_.push_back(rule_data); | |
| 241 return true; | |
| 242 } | |
| 243 | |
| 244 return false; | 268 return false; |
| 245 } | 269 } |
| 246 | 270 |
| 247 void RuleSet::AddRule(StyleRule* rule, | 271 void RuleSet::AddRule(StyleRule* rule, |
| 248 unsigned selector_index, | 272 unsigned selector_index, |
| 249 AddRuleFlags add_rule_flags) { | 273 AddRuleFlags add_rule_flags) { |
| 250 RuleData rule_data(rule, selector_index, rule_count_++, add_rule_flags); | 274 RuleData rule_data(rule, selector_index, rule_count_++, add_rule_flags); |
| 251 if (features_.CollectFeaturesFromRuleData(rule_data) == | 275 if (features_.CollectFeaturesFromRuleData(rule_data) == |
| 252 RuleFeatureSet::kSelectorNeverMatches) | 276 RuleFeatureSet::kSelectorNeverMatches) |
| 253 return; | 277 return; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } | 455 } |
| 432 | 456 |
| 433 #ifndef NDEBUG | 457 #ifndef NDEBUG |
| 434 void RuleSet::Show() const { | 458 void RuleSet::Show() const { |
| 435 for (const auto& rule : all_rules_) | 459 for (const auto& rule : all_rules_) |
| 436 rule.Selector().Show(); | 460 rule.Selector().Show(); |
| 437 } | 461 } |
| 438 #endif | 462 #endif |
| 439 | 463 |
| 440 } // namespace blink | 464 } // namespace blink |
| OLD | NEW |