void reportMediaQueryWarningIfNeeded(Document* document, const MediaQuerySet* mediaQuerySet) { if (!mediaQuerySet || !document) return; auto& mediaQueries = mediaQuerySet->queryVector(); const size_t queryCount = mediaQueries.size(); if (!queryCount) return; for (size_t i = 0; i < queryCount; ++i) { const MediaQuery* query = mediaQueries[i].get(); String mediaType = query->mediaType(); if (!query->ignored() && !equalIgnoringCase(mediaType, "print")) { auto& expressions = query->expressions(); for (size_t j = 0; j < expressions.size(); ++j) { const MediaQueryExp* exp = expressions.at(j).get(); if (exp->mediaFeature() == MediaFeatureNames::resolutionMediaFeature || exp->mediaFeature() == MediaFeatureNames::max_resolutionMediaFeature || exp->mediaFeature() == MediaFeatureNames::min_resolutionMediaFeature) { CSSValue* cssValue = exp->value(); if (cssValue && cssValue->isPrimitiveValue()) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssValue); if (primitiveValue->isDotsPerInch() || primitiveValue->isDotsPerCentimeter()) addResolutionWarningMessageToConsole(document, mediaQuerySet->mediaText(), primitiveValue); } } } } } }
static void addResolutionWarningMessageToConsole(Document& document, const String& serializedExpression, const CSSPrimitiveValue& value) { static NeverDestroyed<String> mediaQueryMessage(ASCIILiteral("Consider using 'dppx' units instead of '%replacementUnits%', as in CSS '%replacementUnits%' means dots-per-CSS-%lengthUnit%, not dots-per-physical-%lengthUnit%, so does not correspond to the actual '%replacementUnits%' of a screen. In media query expression: ")); static NeverDestroyed<String> mediaValueDPI(ASCIILiteral("dpi")); static NeverDestroyed<String> mediaValueDPCM(ASCIILiteral("dpcm")); static NeverDestroyed<String> lengthUnitInch(ASCIILiteral("inch")); static NeverDestroyed<String> lengthUnitCentimeter(ASCIILiteral("centimeter")); String message; if (value.isDotsPerInch()) message = mediaQueryMessage.get().replace("%replacementUnits%", mediaValueDPI).replace("%lengthUnit%", lengthUnitInch); else if (value.isDotsPerCentimeter()) message = mediaQueryMessage.get().replace("%replacementUnits%", mediaValueDPCM).replace("%lengthUnit%", lengthUnitCentimeter); else ASSERT_NOT_REACHED(); message.append(serializedExpression); document.addConsoleMessage(MessageSource::CSS, MessageLevel::Debug, message); }