Browse Source

LibWeb: StyleResolver: Keep track of specificity of matched selector

This way it gets easier to compare matches.
Tobias Christiansen 4 years ago
parent
commit
bf9c5ffb3f

+ 1 - 1
Userland/Libraries/LibWeb/CSS/StyleResolver.cpp

@@ -74,7 +74,7 @@ Vector<MatchingRule> StyleResolver::collect_matching_rules(const DOM::Element& e
             size_t selector_index = 0;
             size_t selector_index = 0;
             for (auto& selector : rule.selectors()) {
             for (auto& selector : rule.selectors()) {
                 if (SelectorEngine::matches(selector, element)) {
                 if (SelectorEngine::matches(selector, element)) {
-                    matching_rules.append({ rule, style_sheet_index, rule_index, selector_index });
+                    matching_rules.append({ rule, style_sheet_index, rule_index, selector_index, selector.specificity() });
                     break;
                     break;
                 }
                 }
                 ++selector_index;
                 ++selector_index;

+ 1 - 0
Userland/Libraries/LibWeb/CSS/StyleResolver.h

@@ -18,6 +18,7 @@ struct MatchingRule {
     size_t style_sheet_index { 0 };
     size_t style_sheet_index { 0 };
     size_t rule_index { 0 };
     size_t rule_index { 0 };
     size_t selector_index { 0 };
     size_t selector_index { 0 };
+    u32 specificity { 0 };
 };
 };
 
 
 class StyleResolver {
 class StyleResolver {