Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: third_party/WebKit/Source/core/css/RuleSet.cpp

Issue 2873123002: Put unqualified pseudos into the more specific rulesets. (Closed)
Patch Set: comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/css/RuleSet.cpp
diff --git a/third_party/WebKit/Source/core/css/RuleSet.cpp b/third_party/WebKit/Source/core/css/RuleSet.cpp
index ad60c3d74f44f7416acbfc93a7a4e15c8a7e726f..9481d3377666d99c4a27f66f1fc5dff3951323c9 100644
--- a/third_party/WebKit/Source/core/css/RuleSet.cpp
+++ b/third_party/WebKit/Source/core/css/RuleSet.cpp
@@ -147,11 +147,12 @@ void RuleSet::AddToRuleSet(const AtomicString& key,
rules->Push(rule_data);
}
-static void ExtractValuesforSelector(const CSSSelector* selector,
- AtomicString& id,
- AtomicString& class_name,
- AtomicString& custom_pseudo_element_name,
- AtomicString& tag_name) {
+static void ExtractSelectorValues(const CSSSelector* selector,
+ AtomicString& id,
+ AtomicString& class_name,
+ AtomicString& custom_pseudo_element_name,
+ AtomicString& tag_name,
+ CSSSelector::PseudoType& pseudoType) {
rune 2017/05/10 08:46:02 camelCase?
switch (selector->Match()) {
case CSSSelector::kId:
id = selector->Value();
@@ -163,12 +164,31 @@ static void ExtractValuesforSelector(const CSSSelector* selector,
if (selector->TagQName().LocalName() != g_star_atom)
tag_name = selector->TagQName().LocalName();
break;
+ case CSSSelector::kPseudoClass:
+ case CSSSelector::kPseudoElement:
+ case CSSSelector::kPagePseudoClass:
+ // Must match the cases in RuleSet::FindBestRuleSetAndAdd.
+ switch (selector->GetPseudoType()) {
+ case CSSSelector::kPseudoCue:
+ case CSSSelector::kPseudoLink:
+ case CSSSelector::kPseudoVisited:
+ case CSSSelector::kPseudoAnyLink:
+ case CSSSelector::kPseudoFocus:
+ case CSSSelector::kPseudoPlaceholder:
+ case CSSSelector::kPseudoHost:
+ case CSSSelector::kPseudoHostContext:
+ pseudoType = selector->GetPseudoType();
+ break;
+ case CSSSelector::kPseudoWebKitCustomElement:
+ case CSSSelector::kPseudoBlinkInternalElement:
+ custom_pseudo_element_name = selector->Value();
+ break;
+ default:
+ break;
+ }
default:
break;
}
- if (selector->GetPseudoType() == CSSSelector::kPseudoWebKitCustomElement ||
- selector->GetPseudoType() == CSSSelector::kPseudoBlinkInternalElement)
- custom_pseudo_element_name = selector->Value();
}
bool RuleSet::FindBestRuleSetAndAdd(const CSSSelector& component,
@@ -177,6 +197,7 @@ bool RuleSet::FindBestRuleSetAndAdd(const CSSSelector& component,
AtomicString class_name;
AtomicString custom_pseudo_element_name;
AtomicString tag_name;
+ CSSSelector::PseudoType pseudoType = CSSSelector::kPseudoUnknown;
rune 2017/05/10 08:46:02 camelCase?
#ifndef NDEBUG
all_rules_.push_back(rule_data);
@@ -184,26 +205,30 @@ bool RuleSet::FindBestRuleSetAndAdd(const CSSSelector& component,
const CSSSelector* it = &component;
for (; it && it->Relation() == CSSSelector::kSubSelector;
- it = it->TagHistory())
- ExtractValuesforSelector(it, id, class_name, custom_pseudo_element_name,
- tag_name);
- if (it)
- ExtractValuesforSelector(it, id, class_name, custom_pseudo_element_name,
- tag_name);
+ it = it->TagHistory()) {
+ ExtractSelectorValues(it, id, class_name, custom_pseudo_element_name,
+ tag_name, pseudoType);
+ }
+ if (it) {
+ ExtractSelectorValues(it, id, class_name, custom_pseudo_element_name,
+ tag_name, pseudoType);
+ }
// Prefer rule sets in order of most likely to apply infrequently.
if (!id.IsEmpty()) {
AddToRuleSet(id, EnsurePendingRules()->id_rules, rule_data);
return true;
}
+
if (!class_name.IsEmpty()) {
AddToRuleSet(class_name, EnsurePendingRules()->class_rules, rule_data);
return true;
}
+
if (!custom_pseudo_element_name.IsEmpty()) {
// Custom pseudos come before ids and classes in the order of tagHistory,
// and have a relation of ShadowPseudo between them. Therefore we should
- // never be a situation where extractValuesforSelector finsd id and
+ // never be a situation where ExtractSelectorValues finds id and
// className in addition to custom pseudo.
DCHECK(id.IsEmpty());
DCHECK(class_name.IsEmpty());
@@ -212,7 +237,7 @@ bool RuleSet::FindBestRuleSetAndAdd(const CSSSelector& component,
return true;
}
- switch (component.GetPseudoType()) {
+ switch (pseudoType) {
rune 2017/05/10 08:46:02 So, if I read this correctly: "[attr]:visited" wi
case CSSSelector::kPseudoCue:
cue_pseudo_rules_.push_back(rule_data);
return true;
@@ -227,6 +252,10 @@ bool RuleSet::FindBestRuleSetAndAdd(const CSSSelector& component,
case CSSSelector::kPseudoPlaceholder:
placeholder_pseudo_rules_.push_back(rule_data);
return true;
+ case CSSSelector::kPseudoHost:
+ case CSSSelector::kPseudoHostContext:
+ shadow_host_rules_.push_back(rule_data);
+ return true;
default:
break;
}
@@ -236,11 +265,6 @@ bool RuleSet::FindBestRuleSetAndAdd(const CSSSelector& component,
return true;
}
- if (component.IsHostPseudoClass()) {
- shadow_host_rules_.push_back(rule_data);
- return true;
- }
-
return false;
}
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698