Changeset 183984 in webkit


Ignore:
Timestamp:
May 7, 2015 11:50:57 PM (9 years ago)
Author:
yoav@yoav.ws
Message:

Calculate source-size length as a float
https://bugs.webkit.org/show_bug.cgi?id=144766

Reviewed by Dean Jackson.

Source/WebCore:

Make sure that the source-size length is calculated as a float,
to align with the spec.

Test: fast/dom/HTMLImageElement/sizes/image-sizes-1x.html

fast/dom/HTMLImageElement/sizes/image-sizes-2x.html

  • css/SourceSizeList.cpp:

(WebCore::parseSizesAttribute):
(WebCore::defaultLength):
(WebCore::computeLength):

  • css/SourceSizeList.h:
  • html/HTMLImageElement.cpp:

(WebCore::HTMLImageElement::parseAttribute):

  • html/parser/HTMLPreloadScanner.cpp:

(WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):

  • html/parser/HTMLSrcsetParser.cpp:

(WebCore::pickBestImageCandidate):
(WebCore::bestFitSourceForImageAttributes):

  • html/parser/HTMLSrcsetParser.h:

LayoutTests:

Add tests that make sure fractional source-size lengths are supported
and are calculated as floats.

  • fast/dom/HTMLImageElement/sizes/image-sizes-1x-expected.txt:
  • fast/dom/HTMLImageElement/sizes/image-sizes-1x.html:
  • fast/dom/HTMLImageElement/sizes/image-sizes-2x-expected.txt:
  • fast/dom/HTMLImageElement/sizes/image-sizes-2x.html:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r183983 r183984  
     12015-05-07  Yoav Weiss  <yoav@yoav.ws>
     2
     3        Calculate source-size length as a float
     4        https://bugs.webkit.org/show_bug.cgi?id=144766
     5
     6        Reviewed by Dean Jackson.
     7
     8        Add tests that make sure fractional source-size lengths are supported
     9        and are calculated as floats.
     10
     11        * fast/dom/HTMLImageElement/sizes/image-sizes-1x-expected.txt:
     12        * fast/dom/HTMLImageElement/sizes/image-sizes-1x.html:
     13        * fast/dom/HTMLImageElement/sizes/image-sizes-2x-expected.txt:
     14        * fast/dom/HTMLImageElement/sizes/image-sizes-2x.html:
     15
    1162015-05-07  Commit Queue  <commit-queue@webkit.org>
    217
  • trunk/LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-1x-expected.txt

    r177772 r183984  
    2828PASS document.getElementById("infitisimal_sizes").clientWidth is (window.innerWidth/100)
    2929PASS currentSrcFileName("infitisimal_sizes") is "image-set-2x.png"
     30PASS document.getElementById("fractional_sizes").clientWidth is 799
     31PASS currentSrcFileName("fractional_sizes") is "image-set-2x.png"
    3032PASS successfullyParsed is true
    3133
    3234TEST COMPLETE
    33              
     35               
  • trunk/LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-1x.html

    r170576 r183984  
    3636        shouldBe('document.getElementById("infitisimal_sizes").clientWidth', '(window.innerWidth/100)');
    3737        shouldBe('currentSrcFileName("infitisimal_sizes")', '"image-set-2x.png"');
     38        shouldBe('document.getElementById("fractional_sizes").clientWidth', '799');
     39        shouldBe('currentSrcFileName("fractional_sizes")', '"image-set-2x.png"');
    3840    }, false);
    3941</script>
     
    5759<img id="half_size" sizes="50vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
    5860<img id="infitisimal_sizes" sizes="1vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
     61<img id="fractional_sizes" sizes="99.875vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
  • trunk/LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-2x-expected.txt

    r177772 r183984  
    2323PASS document.getElementById("infitisimal_sizes").clientWidth is (window.innerWidth/100)
    2424PASS currentSrcFileName("infitisimal_sizes") is "image-set-2x.png"
     25PASS currentSrcFileName("fractional_sizes") is "image-set-4x.png?1599"
    2526PASS successfullyParsed is true
    2627
    2728TEST COMPLETE
    28            
     29             
  • trunk/LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-2x.html

    r178721 r183984  
    3636        shouldBe('document.getElementById("infitisimal_sizes").clientWidth', '(window.innerWidth/100)');
    3737        shouldBe('currentSrcFileName("infitisimal_sizes")', '"image-set-2x.png"');
     38        shouldBe('currentSrcFileName("fractional_sizes")', '"image-set-4x.png?1599"');
    3839    }
    3940</script>
     
    5455<img id="half_size" sizes="50vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
    5556<img id="infitisimal_sizes" sizes="1vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
     57<img id="fractional_sizes" sizes="99.9375vw" srcset="../resources/image-set-4x.png?1598 1598w,../resources/image-set-4x.png?1599 1599w,../resources/image-set-4x.png?1600 1600w,">
  • trunk/Source/WebCore/ChangeLog

    r183983 r183984  
     12015-05-07  Yoav Weiss  <yoav@yoav.ws>
     2
     3        Calculate source-size length as a float
     4        https://bugs.webkit.org/show_bug.cgi?id=144766
     5
     6        Reviewed by Dean Jackson.
     7
     8        Make sure that the source-size length is calculated as a float,
     9        to align with the spec.
     10
     11        Test: fast/dom/HTMLImageElement/sizes/image-sizes-1x.html
     12              fast/dom/HTMLImageElement/sizes/image-sizes-2x.html
     13
     14        * css/SourceSizeList.cpp:
     15        (WebCore::parseSizesAttribute):
     16        (WebCore::defaultLength):
     17        (WebCore::computeLength):
     18        * css/SourceSizeList.h:
     19        * html/HTMLImageElement.cpp:
     20        (WebCore::HTMLImageElement::parseAttribute):
     21        * html/parser/HTMLPreloadScanner.cpp:
     22        (WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):
     23        * html/parser/HTMLSrcsetParser.cpp:
     24        (WebCore::pickBestImageCandidate):
     25        (WebCore::bestFitSourceForImageAttributes):
     26        * html/parser/HTMLSrcsetParser.h:
     27
    1282015-05-07  Commit Queue  <commit-queue@webkit.org>
    229
  • trunk/Source/WebCore/css/SourceSizeList.cpp

    r183948 r183984  
    3535#if !ENABLE(PICTURE_SIZES)
    3636
    37 unsigned parseSizesAttribute(StringView, RenderView*, Frame*)
     37float parseSizesAttribute(StringView, RenderView*, Frame*)
    3838{
    3939    return 0;
     
    5757}
    5858
    59 static unsigned defaultLength(RenderStyle& style, RenderView* view)
     59static float defaultLength(RenderStyle& style, RenderView* view)
    6060{
    61     return CSSPrimitiveValue::create(100, CSSPrimitiveValue::CSS_VW)->computeLength<unsigned>(CSSToLengthConversionData(&style, &style, view));
     61    return CSSPrimitiveValue::create(100, CSSPrimitiveValue::CSS_VW)->computeLength<float>(CSSToLengthConversionData(&style, &style, view));
    6262}
    6363
    64 static unsigned computeLength(CSSValue* value, RenderStyle& style, RenderView* view)
     64static float computeLength(CSSValue* value, RenderStyle& style, RenderView* view)
    6565{
    6666    CSSToLengthConversionData conversionData(&style, &style, view);
     
    6969        if (!primitiveValue.isLength())
    7070            return defaultLength(style, view);
    71         return primitiveValue.computeLength<unsigned>(conversionData);
     71        return primitiveValue.computeLength<float>(conversionData);
    7272    }
    7373    if (is<CSSCalcValue>(value)) {
    7474        Length length(downcast<CSSCalcValue>(*value).createCalculationValue(conversionData));
    75         return CSSPrimitiveValue::create(length, &style)->computeLength<unsigned>(conversionData);
     75        return CSSPrimitiveValue::create(length, &style)->computeLength<float>(conversionData);
    7676    }
    7777    return defaultLength(style, view);
    7878}
    7979
    80 unsigned parseSizesAttribute(StringView sizesAttribute, RenderView* view, Frame* frame)
     80float parseSizesAttribute(StringView sizesAttribute, RenderView* view, Frame* frame)
    8181{
    8282    if (!view)
  • trunk/Source/WebCore/css/SourceSizeList.h

    r179476 r183984  
    2929class RenderView;
    3030
    31 unsigned parseSizesAttribute(StringView sizesAttribute, RenderView*, Frame*);
     31float parseSizesAttribute(StringView sizesAttribute, RenderView*, Frame*);
    3232
    3333} // namespace WebCore
  • trunk/Source/WebCore/html/HTMLImageElement.cpp

    r183160 r183984  
    143143            downcast<RenderImage>(*renderer()).updateAltText();
    144144    } else if (name == srcAttr || name == srcsetAttr) {
    145         unsigned sourceSize = parseSizesAttribute(fastGetAttribute(sizesAttr).string(), document().renderView(), document().frame());
     145        float sourceSize = parseSizesAttribute(fastGetAttribute(sizesAttr).string(), document().renderView(), document().frame());
    146146        ImageCandidate candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), sourceSize);
    147147        setBestFitURLAndDPRFromImageCandidate(candidate);
  • trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp

    r183951 r183984  
    112112        // Resolve between src and srcSet if we have them and the tag is img.
    113113        if (m_tagId == TagId::Img && !m_srcSetAttribute.isEmpty()) {
    114             unsigned sourceSize = 0;
     114            float sourceSize = 0;
    115115#if ENABLE(PICTURE_SIZES)
    116116            sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame());
  • trunk/Source/WebCore/html/parser/HTMLSrcsetParser.cpp

    r173464 r183984  
    230230}
    231231
    232 static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<ImageCandidate>& imageCandidates, unsigned sourceSize)
     232static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<ImageCandidate>& imageCandidates, float sourceSize)
    233233{
    234234#if !ENABLE(PICTURE_SIZES)
     
    244244#if ENABLE(PICTURE_SIZES)
    245245        if (candidate.resourceWidth > 0) {
    246             candidate.density = static_cast<float>(candidate.resourceWidth) / static_cast<float>(sourceSize);
     246            candidate.density = static_cast<float>(candidate.resourceWidth) / sourceSize;
    247247            ignoreSrc = true;
    248248        } else
     
    275275}
    276276
    277 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, unsigned sourceSize)
     277ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, float sourceSize)
    278278{
    279279    if (srcsetAttribute.isNull()) {
  • trunk/Source/WebCore/html/parser/HTMLSrcsetParser.h

    r173464 r183984  
    9999};
    100100
    101 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, unsigned sourceSize);
     101ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, float sourceSize);
    102102
    103103Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(StringView attribute);
Note: See TracChangeset for help on using the changeset viewer.