示例#1
0
static bool evalResolution(const MediaQueryExpValue& value, MediaFeaturePrefix op, const MediaValues& mediaValues)
{
    // According to MQ4, only 'screen', 'print' and 'speech' may match.
    // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/issues/348
    float actualResolution = 0;

    // This checks the actual media type applied to the document, and we know
    // this method only got called if this media type matches the one defined
    // in the query. Thus, if if the document's media type is "print", the
    // media type of the query will either be "print" or "all".
    if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::screen)) {
        actualResolution = clampTo<float>(mediaValues.devicePixelRatio());
    } else if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::print)) {
        // The resolution of images while printing should not depend on the DPI
        // of the screen. Until we support proper ways of querying this info
        // we use 300px which is considered minimum for current printers.
        actualResolution = 300 / cssPixelsPerInch;
    }

    if (!value.isValid())
        return !!actualResolution;

    if (!value.isValue)
        return false;

    if (value.unit == CSSPrimitiveValue::CSS_NUMBER)
        return compareValue(actualResolution, clampTo<float>(value.value), op);

    if (!CSSPrimitiveValue::isResolution(value.unit))
        return false;

    double canonicalFactor = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(value.unit);
    double dppxFactor = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSPrimitiveValue::CSS_DPPX);
    float valueInDppx = clampTo<float>(value.value * (canonicalFactor / dppxFactor));
    if (CSSPrimitiveValue::isDotsPerCentimeter(value.unit)) {
        // To match DPCM to DPPX values, we limit to 2 decimal points.
        // The http://dev.w3.org/csswg/css3-values/#absolute-lengths recommends
        // "that the pixel unit refer to the whole number of device pixels that best
        // approximates the reference pixel". With that in mind, allowing 2 decimal
        // point precision seems appropriate.
        return compareValue(
            floorf(0.5 + 100 * actualResolution) / 100,
            floorf(0.5 + 100 * valueInDppx) / 100, op);
    }

    return compareValue(actualResolution, valueInDppx, op);
}
示例#2
0
static bool scanMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix, const MediaValues& mediaValues)
{
    // Scan only applies to 'tv' media.
    if (!equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::tv))
        return false;

    if (!value.isValid())
        return true;

    if (!value.isID)
        return false;

    // If a platform interface supplies progressive/interlace info for TVs in the
    // future, it needs to be handled here. For now, assume a modern TV with
    // progressive display.
    return (value.id == CSSValueProgressive);
}