Calculate source-size length as a float
authoryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2015 06:50:57 +0000 (06:50 +0000)
committeryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2015 06:50:57 +0000 (06:50 +0000)
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183984 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-1x-expected.txt
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-1x.html
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-2x-expected.txt
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-2x.html
Source/WebCore/ChangeLog
Source/WebCore/css/SourceSizeList.cpp
Source/WebCore/css/SourceSizeList.h
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/parser/HTMLPreloadScanner.cpp
Source/WebCore/html/parser/HTMLSrcsetParser.cpp
Source/WebCore/html/parser/HTMLSrcsetParser.h

index d0a3f4b..4a02314 100644 (file)
@@ -1,3 +1,18 @@
+2015-05-07  Yoav Weiss  <yoav@yoav.ws>
+
+        Calculate source-size length as a float
+        https://bugs.webkit.org/show_bug.cgi?id=144766
+
+        Reviewed by Dean Jackson.
+
+        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:
+
 2015-05-07  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r183895.
index 166e3f5..85b3ddb 100644 (file)
@@ -27,7 +27,9 @@ PASS document.getElementById("half_size").clientWidth is (window.innerWidth/2)
 PASS currentSrcFileName("half_size") is "image-set-2x.png"
 PASS document.getElementById("infitisimal_sizes").clientWidth is (window.innerWidth/100)
 PASS currentSrcFileName("infitisimal_sizes") is "image-set-2x.png"
+PASS document.getElementById("fractional_sizes").clientWidth is 799
+PASS currentSrcFileName("fractional_sizes") is "image-set-2x.png"
 PASS successfullyParsed is true
 
 TEST COMPLETE
-              
+               
index c6a3f69..d0cbb37 100644 (file)
@@ -35,6 +35,8 @@
         shouldBe('currentSrcFileName("half_size")', '"image-set-2x.png"');
         shouldBe('document.getElementById("infitisimal_sizes").clientWidth', '(window.innerWidth/100)');
         shouldBe('currentSrcFileName("infitisimal_sizes")', '"image-set-2x.png"');
+        shouldBe('document.getElementById("fractional_sizes").clientWidth', '799');
+        shouldBe('currentSrcFileName("fractional_sizes")', '"image-set-2x.png"');
     }, false);
 </script>
 <img id="simple" src="" sizes="(max-width: 300px) 400px, 800px" srcset="../../../hidpi/resources/image-set-1x.png 400w, ../../../hidpi/resources/image-set-2x.png 800w">
@@ -56,3 +58,4 @@
 <!-- The intrinsic size should be identical to the 'sizes' value -->
 <img id="half_size" sizes="50vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
 <img id="infitisimal_sizes" sizes="1vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
+<img id="fractional_sizes" sizes="99.875vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
index 12114bb..1eb39dd 100644 (file)
@@ -22,7 +22,8 @@ PASS document.getElementById("half_size").clientWidth is (window.innerWidth/2)
 PASS currentSrcFileName("half_size") is "image-set-2x.png"
 PASS document.getElementById("infitisimal_sizes").clientWidth is (window.innerWidth/100)
 PASS currentSrcFileName("infitisimal_sizes") is "image-set-2x.png"
+PASS currentSrcFileName("fractional_sizes") is "image-set-4x.png?1599"
 PASS successfullyParsed is true
 
 TEST COMPLETE
-            
+             
index 089121a..4bcb213 100644 (file)
@@ -35,6 +35,7 @@
         shouldBe('currentSrcFileName("half_size")', '"image-set-2x.png"');
         shouldBe('document.getElementById("infitisimal_sizes").clientWidth', '(window.innerWidth/100)');
         shouldBe('currentSrcFileName("infitisimal_sizes")', '"image-set-2x.png"');
+        shouldBe('currentSrcFileName("fractional_sizes")', '"image-set-4x.png?1599"');
     }
 </script>
 <img id="simple" src="" sizes="(max-width: 300px) 400px, 800px" srcset="../../../hidpi/resources/image-set-1x.png 400w, ../../../hidpi/resources/image-set-2x.png 800w">
@@ -53,3 +54,4 @@
 <!-- The intrinsic size should be identical to the 'sizes' value -->
 <img id="half_size" sizes="50vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
 <img id="infitisimal_sizes" sizes="1vw" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
+<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,">
index 623a400..347d029 100644 (file)
@@ -1,3 +1,30 @@
+2015-05-07  Yoav Weiss  <yoav@yoav.ws>
+
+        Calculate source-size length as a float
+        https://bugs.webkit.org/show_bug.cgi?id=144766
+
+        Reviewed by Dean Jackson.
+
+        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:
+
 2015-05-07  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r183895.
index 65691ff..5fd1535 100644 (file)
@@ -34,7 +34,7 @@ namespace WebCore {
 
 #if !ENABLE(PICTURE_SIZES)
 
-unsigned parseSizesAttribute(StringView, RenderView*, Frame*)
+float parseSizesAttribute(StringView, RenderView*, Frame*)
 {
     return 0;
 }
@@ -56,28 +56,28 @@ static bool match(std::unique_ptr<MediaQueryExp>&& expression, RenderStyle& styl
     return mediaQueryEvaluator.eval(mediaQuerySet.get());
 }
 
-static unsigned defaultLength(RenderStyle& style, RenderView* view)
+static float defaultLength(RenderStyle& style, RenderView* view)
 {
-    return CSSPrimitiveValue::create(100, CSSPrimitiveValue::CSS_VW)->computeLength<unsigned>(CSSToLengthConversionData(&style, &style, view));
+    return CSSPrimitiveValue::create(100, CSSPrimitiveValue::CSS_VW)->computeLength<float>(CSSToLengthConversionData(&style, &style, view));
 }
 
-static unsigned computeLength(CSSValue* value, RenderStyle& style, RenderView* view)
+static float computeLength(CSSValue* value, RenderStyle& style, RenderView* view)
 {
     CSSToLengthConversionData conversionData(&style, &style, view);
     if (is<CSSPrimitiveValue>(value)) {
         CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(*value);
         if (!primitiveValue.isLength())
             return defaultLength(style, view);
-        return primitiveValue.computeLength<unsigned>(conversionData);
+        return primitiveValue.computeLength<float>(conversionData);
     }
     if (is<CSSCalcValue>(value)) {
         Length length(downcast<CSSCalcValue>(*value).createCalculationValue(conversionData));
-        return CSSPrimitiveValue::create(length, &style)->computeLength<unsigned>(conversionData);
+        return CSSPrimitiveValue::create(length, &style)->computeLength<float>(conversionData);
     }
     return defaultLength(style, view);
 }
 
-unsigned parseSizesAttribute(StringView sizesAttribute, RenderView* view, Frame* frame)
+float parseSizesAttribute(StringView sizesAttribute, RenderView* view, Frame* frame)
 {
     if (!view)
         return 0;
index 4f71a69..e1aef97 100644 (file)
@@ -28,7 +28,7 @@ namespace WebCore {
 class Frame;
 class RenderView;
 
-unsigned parseSizesAttribute(StringView sizesAttribute, RenderView*, Frame*);
+float parseSizesAttribute(StringView sizesAttribute, RenderView*, Frame*);
 
 } // namespace WebCore
 
index 62ea6fc..f864050 100644 (file)
@@ -142,7 +142,7 @@ void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
         if (is<RenderImage>(renderer()))
             downcast<RenderImage>(*renderer()).updateAltText();
     } else if (name == srcAttr || name == srcsetAttr) {
-        unsigned sourceSize = parseSizesAttribute(fastGetAttribute(sizesAttr).string(), document().renderView(), document().frame());
+        float sourceSize = parseSizesAttribute(fastGetAttribute(sizesAttr).string(), document().renderView(), document().frame());
         ImageCandidate candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), sourceSize);
         setBestFitURLAndDPRFromImageCandidate(candidate);
         m_imageLoader.updateFromElementIgnoringPreviousError();
index d9f64f5..e3f1da5 100644 (file)
@@ -111,7 +111,7 @@ public:
 
         // Resolve between src and srcSet if we have them and the tag is img.
         if (m_tagId == TagId::Img && !m_srcSetAttribute.isEmpty()) {
-            unsigned sourceSize = 0;
+            float sourceSize = 0;
 #if ENABLE(PICTURE_SIZES)
             sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame());
 #else
index b5acefa..3490fb4 100644 (file)
@@ -229,7 +229,7 @@ Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(StringView attrib
         return parseImageCandidatesFromSrcsetAttribute<UChar>(attribute.characters16(), attribute.length());
 }
 
-static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<ImageCandidate>& imageCandidates, unsigned sourceSize)
+static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<ImageCandidate>& imageCandidates, float sourceSize)
 {
 #if !ENABLE(PICTURE_SIZES)
     UNUSED_PARAM(sourceSize);
@@ -243,7 +243,7 @@ static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<Ima
     for (auto& candidate : imageCandidates) {
 #if ENABLE(PICTURE_SIZES)
         if (candidate.resourceWidth > 0) {
-            candidate.density = static_cast<float>(candidate.resourceWidth) / static_cast<float>(sourceSize);
+            candidate.density = static_cast<float>(candidate.resourceWidth) / sourceSize;
             ignoreSrc = true;
         } else
 #endif
@@ -274,7 +274,7 @@ static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<Ima
     return imageCandidates[winner];
 }
 
-ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, unsigned sourceSize)
+ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, float sourceSize)
 {
     if (srcsetAttribute.isNull()) {
         if (srcAttribute.isNull())
index df9486d..f6d3900 100644 (file)
@@ -98,7 +98,7 @@ struct ImageCandidate {
     OriginAttribute originAttribute;
 };
 
-ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, unsigned sourceSize);
+ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, float sourceSize);
 
 Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(StringView attribute);