| 75 | } |
| 76 | |
| 77 | void CSSDocument::populateRuleIndex(AttributeIds& attributeIds, |
| 78 | const Valdi::CSSRuleIndex& ruleIndex, |
| 79 | CSSProcessedRuleIndex& currentRuleIndex) { |
| 80 | populateMapRule(attributeIds, ruleIndex.id_rules(), currentRuleIndex.idRules); |
| 81 | populateMapRule(attributeIds, ruleIndex.class_rules(), currentRuleIndex.classRules); |
| 82 | populateMapRule(attributeIds, ruleIndex.tag_rules(), currentRuleIndex.tagRules); |
| 83 | |
| 84 | for (const auto& attributeRule : ruleIndex.attribute_rules()) { |
| 85 | auto& newAttributeRule = currentRuleIndex.attributeRules.emplace_back(); |
| 86 | newAttributeRule.attribute = toCSSAttribute(attributeIds, attributeRule.attribute()); |
| 87 | newAttributeRule.type = attributeRule.type(); |
| 88 | |
| 89 | // We insert into the monitoredCssAttributes set all attributes that we know can |
| 90 | // impact the resolved rules. To do this we traverse the CSS rule index tree to |
| 91 | // find all the attributes rules. |
| 92 | if (_monitoredCssAttributes == nullptr) { |
| 93 | _monitoredCssAttributes = Valdi::makeShared<FlatSet<AttributeId>>(); |
| 94 | } |
| 95 | _monitoredCssAttributes->emplace(newAttributeRule.attribute.id); |
| 96 | |
| 97 | populateStyleNode(attributeIds, attributeRule.node(), newAttributeRule.styleNode); |
| 98 | } |
| 99 | |
| 100 | if (ruleIndex.has_first_child_rule()) { |
| 101 | currentRuleIndex.firstChildRule = std::make_unique<CSSStyleNode>(); |
| 102 | populateStyleNode(attributeIds, ruleIndex.first_child_rule(), *currentRuleIndex.firstChildRule); |
| 103 | } |
| 104 | |
| 105 | if (ruleIndex.has_last_child_rule()) { |
| 106 | currentRuleIndex.lastChildRule = std::make_unique<CSSStyleNode>(); |
| 107 | populateStyleNode(attributeIds, ruleIndex.last_child_rule(), *currentRuleIndex.lastChildRule); |
| 108 | } |
| 109 | |
| 110 | for (const auto& nthChildRule : ruleIndex.nth_child_rules()) { |
| 111 | auto& newRule = currentRuleIndex.nthChildRules.emplace_back(); |
| 112 | newRule.n = static_cast<int>(nthChildRule.n()); |
| 113 | newRule.offset = static_cast<int>(nthChildRule.offset()); |
| 114 | populateStyleNode(attributeIds, nthChildRule.node(), newRule.node); |
| 115 | } |
| 116 | |
| 117 | if (ruleIndex.has_direct_parent_rules()) { |
| 118 | currentRuleIndex.directParentRules = std::make_unique<CSSProcessedRuleIndex>(); |
| 119 | populateRuleIndex(attributeIds, ruleIndex.direct_parent_rules(), *currentRuleIndex.directParentRules); |
| 120 | } |
| 121 | |
| 122 | if (ruleIndex.has_ancestor_rules()) { |
| 123 | currentRuleIndex.ancestorRules = std::make_unique<CSSProcessedRuleIndex>(); |
| 124 | populateRuleIndex(attributeIds, ruleIndex.ancestor_rules(), *currentRuleIndex.ancestorRules); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | const CSSStyleNode& CSSDocument::getRootNode() const { |
| 129 | return _rootNode; |
nothing calls this directly
no test coverage detected