void DocumentRuleSets::appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>& styleSheets, MediaQueryEvaluator* medium, InspectorCSSOMWrappers& inspectorCSSOMWrappers, StyleResolver* resolver) { // This handles sheets added to the end of the stylesheet list only. In other cases the style resolver // needs to be reconstructed. To handle insertions too the rule order numbers would need to be updated. for (auto& cssSheet : styleSheets) { ASSERT(!cssSheet->disabled()); if (cssSheet->mediaQueries() && !medium->eval(cssSheet->mediaQueries(), resolver)) continue; m_authorStyle->addRulesFromSheet(cssSheet->contents(), *medium, resolver); inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet.get()); } m_authorStyle->shrinkToFit(); collectFeatures(); }
// underListItem denotes that at least one of the ancesters is <li> element. void collectFeatures(Element& root, WebDistillabilityFeatures& features, bool underListItem = false) { for (Node& node : NodeTraversal::childrenOf(root)) { bool isListItem = false; if (!node.isElementNode()) { continue; } features.elementCount++; Element& element = toElement(node); if (element.hasTagName(aTag)) { features.anchorCount++; } else if (element.hasTagName(formTag)) { features.formCount++; } else if (element.hasTagName(inputTag)) { const HTMLInputElement& input = toHTMLInputElement(element); if (input.type() == InputTypeNames::text) { features.textInputCount++; } else if (input.type() == InputTypeNames::password) { features.passwordInputCount++; } } else if (element.hasTagName(pTag) || element.hasTagName(preTag)) { if (element.hasTagName(pTag)) { features.pCount++; } else { features.preCount++; } if (!underListItem && isGoodForScoring(features, element)) { unsigned length = textContentLengthSaturated(element); if (length >= kParagraphLengthThreshold) { features.mozScore += sqrt(length - kParagraphLengthThreshold); features.mozScore = std::min(features.mozScore, kMozScoreSaturation); } features.mozScoreAllSqrt += sqrt(length); features.mozScoreAllSqrt = std::min(features.mozScoreAllSqrt, kMozScoreAllSqrtSaturation); features.mozScoreAllLinear += length; features.mozScoreAllLinear = std::min(features.mozScoreAllLinear, kMozScoreAllLinearSaturation); } } else if (element.hasTagName(liTag)) { isListItem = true; } collectFeatures(element, features, underListItem || isListItem); } }