⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 276208 in webkit


Ignore:
Timestamp:
Apr 17, 2021, 3:21:20 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Media queries with max-width greater than 999999999px evaluate to false
https://bugs.webkit.org/show_bug.cgi?id=224097

Patch by Tyler Wilcock <Tyler Wilcock> on 2021-04-17
Reviewed by Darin Adler.

We now evaluate <length> values in media queries with double
Source/WebCore:

precision instead of int precision to match other browsers and pass a WPT.

See similar method in Chromium:
https://github.com/chromium/chromium/blob/09a0b960b27f6e08fbe67ad97e6c4fb55ada383f/third_party/blink/renderer/core/css/media_query_evaluator.cc#L436

Test: fast/media/media-query-lengths-evaluate-with-double-precision.html
and WPT imported/w3c/web-platform-tests/css/mediaqueries/min-width-001.xht

  • css/MediaQueryEvaluator.cpp:

(WebCore::computeLength):
Return Optional<double> rather than int& out-value.

(WebCore::deviceHeightEvaluate):
(WebCore::deviceWidthEvaluate):
(WebCore::heightEvaluate):
(WebCore::widthEvaluate):
Evaluate length values as doubles instead of ints.

LayoutTests:

precision instead of int precision to match other browsers and pass another WPT.

Remove ImageOnlyFailure for imported/w3c/web-platform-tests/css/mediaqueries/min-width-001.xht
because it passes now.

  • fast/media/media-query-lengths-evaluate-with-double-precision-expected.html:

Added.

  • fast/media/media-query-lengths-evaluate-with-double-precision.html:

Added to test properties that WPT min-width-001.xht doesn't
(min-height, device-min-height, device-min-width).

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r276197 r276208  
     12021-04-17  Tyler Wilcock  <twilco.o@protonmail.com>
     2
     3        Media queries with max-width greater than 999999999px evaluate to false
     4        https://bugs.webkit.org/show_bug.cgi?id=224097
     5
     6        Reviewed by Darin Adler.
     7
     8        We now evaluate <length> values in media queries with double
     9        precision instead of int precision to match other browsers and pass another WPT.
     10
     11        * TestExpectations:
     12        Remove ImageOnlyFailure for imported/w3c/web-platform-tests/css/mediaqueries/min-width-001.xht
     13        because it passes now.
     14
     15        * fast/media/media-query-lengths-evaluate-with-double-precision-expected.html:
     16        Added.
     17
     18        * fast/media/media-query-lengths-evaluate-with-double-precision.html:
     19        Added to test properties that WPT min-width-001.xht doesn't
     20        (min-height, device-min-height, device-min-width).
     21
    1222021-04-17  Philippe Normand  <pnormand@igalia.com>
    223
  • trunk/LayoutTests/TestExpectations

    r276182 r276208  
    12531253imported/w3c/web-platform-tests/css/mediaqueries/device-aspect-ratio-005.html [ Skip ]
    12541254
    1255 imported/w3c/web-platform-tests/css/mediaqueries/min-width-001.xht [ ImageOnlyFailure ]
    12561255webkit.org/b/156684 imported/w3c/web-platform-tests/css/mediaqueries/relative-units-001.html [ ImageOnlyFailure ]
    12571256webkit.org/b/156684 imported/w3c/web-platform-tests/css/mediaqueries/mq-calc-005.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r276207 r276208  
     12021-04-17  Tyler Wilcock  <twilco.o@protonmail.com>
     2
     3        Media queries with max-width greater than 999999999px evaluate to false
     4        https://bugs.webkit.org/show_bug.cgi?id=224097
     5
     6        Reviewed by Darin Adler.
     7
     8        We now evaluate <length> values in media queries with double
     9        precision instead of int precision to match other browsers and pass a WPT.
     10
     11        See similar method in Chromium:
     12        https://github.com/chromium/chromium/blob/09a0b960b27f6e08fbe67ad97e6c4fb55ada383f/third_party/blink/renderer/core/css/media_query_evaluator.cc#L436
     13
     14        Test: fast/media/media-query-lengths-evaluate-with-double-precision.html
     15        and WPT imported/w3c/web-platform-tests/css/mediaqueries/min-width-001.xht
     16
     17        * css/MediaQueryEvaluator.cpp:
     18        (WebCore::computeLength):
     19        Return Optional<double> rather than int& out-value.
     20
     21        (WebCore::deviceHeightEvaluate):
     22        (WebCore::deviceWidthEvaluate):
     23        (WebCore::heightEvaluate):
     24        (WebCore::widthEvaluate):
     25        Evaluate `length` values as doubles instead of ints.
     26
    1272021-04-17  Zalan Bujtas  <zalan@apple.com>
    228
  • trunk/Source/WebCore/css/MediaQueryEvaluator.cpp

    r270823 r276208  
    483483}
    484484
    485 static bool computeLength(CSSValue* value, bool strict, const CSSToLengthConversionData& conversionData, int& result)
     485static Optional<double> computeLength(CSSValue* value, bool strict, const CSSToLengthConversionData& conversionData)
    486486{
    487487    if (!is<CSSPrimitiveValue>(value))
    488         return false;
     488        return WTF::nullopt;
    489489
    490490    auto& primitiveValue = downcast<CSSPrimitiveValue>(*value);
    491 
    492491    if (primitiveValue.isNumber()) {
    493         result = primitiveValue.intValue();
    494         return !strict || !result;
    495     }
    496 
    497     if (primitiveValue.isLength()) {
    498         result = primitiveValue.computeLength<int>(conversionData);
    499         return true;
    500     }
    501 
    502     return false;
     492        double value = primitiveValue.doubleValue();
     493        // The only unitless number value allowed in strict mode is zero.
     494        if (strict && value)
     495            return WTF::nullopt;
     496        return value;
     497    }
     498
     499    if (primitiveValue.isLength())
     500        return primitiveValue.computeLength<double>(conversionData);
     501
     502    return WTF::nullopt;
    503503}
    504504
     
    509509    if (!value)
    510510        return true;
    511     int length;
     511    auto length = computeLength(value, !frame.document()->inQuirksMode(), conversionData);
     512    if (!length)
     513        return false;
     514
    512515    auto height = frame.mainFrame().screenSize().height();
    513     if (!computeLength(value, !frame.document()->inQuirksMode(), conversionData, length))
    514         return false;
    515 
    516     LOG_WITH_STREAM(MediaQueries, stream << "  deviceHeightEvaluate: query " << op << " height " << length << ", actual height " << height << " result: " << compareValue(height, length, op));
    517 
    518     return compareValue(height, length, op);
     516    LOG_WITH_STREAM(MediaQueries, stream << "  deviceHeightEvaluate: query " << op << " height " << *length << ", actual height " << height << " result: " << compareValue(height, *length, op));
     517    return compareValue(height, *length, op);
    519518}
    520519
     
    525524    if (!value)
    526525        return true;
    527     int length;
     526    auto length = computeLength(value, !frame.document()->inQuirksMode(), conversionData);
     527    if (!length)
     528        return false;
     529
    528530    auto width = frame.mainFrame().screenSize().width();
    529     if (!computeLength(value, !frame.document()->inQuirksMode(), conversionData, length))
    530         return false;
    531 
    532     LOG_WITH_STREAM(MediaQueries, stream << "  deviceWidthEvaluate: query " << op << " width " << length << ", actual width " << width << " result: " << compareValue(width, length, op));
    533 
    534     return compareValue(width, length, op);
     531    LOG_WITH_STREAM(MediaQueries, stream << "  deviceWidthEvaluate: query " << op << " width " << *length << ", actual width " << width << " result: " << compareValue(width, *length, op));
     532    return compareValue(width, *length, op);
    535533}
    536534
     
    543541    if (!value)
    544542        return height;
     543
     544    auto length = computeLength(value, !frame.document()->inQuirksMode(), conversionData);
     545    if (!length)
     546        return false;
     547
    545548    if (auto* renderView = frame.document()->renderView())
    546549        height = adjustForAbsoluteZoom(height, *renderView);
    547550
    548     int length;
    549     if (!computeLength(value, !frame.document()->inQuirksMode(), conversionData, length))
    550         return false;
    551 
    552     LOG_WITH_STREAM(MediaQueries, stream << "  heightEvaluate: query " << op << " height " << length << ", actual height " << height << " result: " << compareValue(height, length, op));
    553 
    554     return compareValue(height, length, op);
     551    LOG_WITH_STREAM(MediaQueries, stream << "  heightEvaluate: query " << op << " height " << *length << ", actual height " << height << " result: " << compareValue(height, *length, op));
     552    return compareValue(height, *length, op);
    555553}
    556554
     
    563561    if (!value)
    564562        return width;
     563
     564    auto length = computeLength(value, !frame.document()->inQuirksMode(), conversionData);
     565    if (!length)
     566        return false;
     567
    565568    if (auto* renderView = frame.document()->renderView())
    566569        width = adjustForAbsoluteZoom(width, *renderView);
    567570
    568     int length;
    569     if (!computeLength(value, !frame.document()->inQuirksMode(), conversionData, length))
    570         return false;
    571 
    572     LOG_WITH_STREAM(MediaQueries, stream << "  widthEvaluate: query " << op << " width " << length << ", actual width " << width << " result: " << compareValue(width, length, op));
    573 
    574     return compareValue(width, length, op);
     571    LOG_WITH_STREAM(MediaQueries, stream << "  widthEvaluate: query " << op << " width " << *length << ", actual width " << width << " result: " << compareValue(width, *length, op));
     572    return compareValue(width, *length, op);
    575573}
    576574
Note: See TracChangeset for help on using the changeset viewer.