Skip to content
  • dino@apple.com's avatar
    Implement img element's srcset attribute · 8d0305d7
    dino@apple.com authored
    https://bugs.webkit.org/show_bug.cgi?id=110252
    
    Patch by Romain Perier <romain.perier@gmail.com> on 2013-08-01
    Reviewed by Dean Jackson.
    
    Source/WebCore:
    
    Tests: fast/hidpi/image-srcset-simple.html
           fast/hidpi/image-srcset-src-selection.html
           fast/hidpi/image-srcset-simple.html
           fast/hidpi/image-srcset-src-selection.html
           fast/hidpi/image-srcset-only-src-attribute.html
           fast/hidpi/image-srcset-same-alternative-for-both-attributes.html
           fast/hidpi/image-srcset-invalid-inputs.html
           fast/hidpi/image-srcset-invalid-inputs-except-one.html
           fast/hidpi/image-srcset-invalid-inputs-correct-src.html
           fast/hidpi/image-srcset-change-dynamically-from-js.html
           fast/hidpi/image-srcset-remove-dynamically-from-js.html
    
    * html/HTMLAttributeNames.in: Add srcset attribute.
    * html/HTMLImageElement.cpp:
    (WebCore::HTMLImageElement::HTMLImageElement):
    Adding initialization for new variables member.
    (WebCore::HTMLImageElement::imageSourceURL):
    Override this method to return the choosen image transparently to the ImageLoader.
    (WebCore::HTMLImageElement::updateBestImageForScaleFactor):
    New method to select the good image candidate dependending on the scale factor. This method is separated from
    parsing because it will be useful for selecting a new image candidate on the fly if the device scale factor changes.
    (WebCore::HTMLImageElement::updateImagesFromSrcSet):
    New method for parsing the srcset attribute and build a list of images with the corresponding scale factor.
    (WebCore::HTMLImageElement::parseAttribute):
    Adding support for processing the image candidates, select the good one and call ImageLoader for rendering.
    * html/HTMLImageElement.h:
    - Adding new methods declarations.
    - Adding new type definition.
    - Adding new variable member to store the URL of the choosen image.
    - Adding new variable member to store the index of the src image.
    - Adding new Vector to store the list of images after parsing.
    * html/HTMLImageElement.idl: Adding srcset attribute for the differents existing bidings.
    
    LayoutTests:
    
    * fast/hidpi/image-srcset-simple.html: Ensures that the good image
    is selected from srcset by the user agent according to the choosen scale factor.
    * fast/hidpi/image-srcset-src-selection.html: Ensures that the image
    from the src attribute is collected by the parsing algorithm and selected by the user agent
    when no other candidate matches the scale factor.
    * fast/hidpi/image-srcset-only-src-attribute.html: Ensures that the algorithms used for srcset
    does not change the behaviour of the src attribute when the srcset attribute is not defined,
    even using scale factor greater than 1.
    * fast/hidpi/image-srcset-same-alternative-for-both-attributes.html: Ensures that the good image
    is selected by the user agent when src and srcset contain an image with a scale factor of 1.
    * fast/hidpi/image-srcset-invalid-inputs.html: Ensures that the parsing and the selection
    algorithms support invalid inputs. Theses ones are simply ignored.
    * fast/hidpi/image-srcset-invalid-inputs-except-one.html: Ensures that a valid image
    is selected even if this one is part of a set containing invalid inputs.
    * fast/hidpi/image-srcset-invalid-inputs-correct-src.html: Ensures that the image from
    the src attribute is choosen when srcset contains only invalid inputs, this selection
    should not depend on the scale factor.
    * fast/hidpi/image-srcset-change-dynamically-from-js.html: Ensures that src and srcset attributes
    can be changed dynamically from javascript.
    * fast/hidpi/image-srcset-remove-dynamically-from-js.html: Ensures that src attribute
    can be removed dynamically from javascript.
    * platform/mac/fast/hidpi/image-srcset-simple-expected.png:
    * platform/mac/fast/hidpi/image-srcset-simple-expected.txt:
    * platform/mac/fast/hidpi/image-srcset-src-selection-expected.png:
    * platform/mac/fast/hidpi/image-srcset-src-selection-expected.txt:
    * platform/mac/fast/hidpi/image-srcset-only-src-attribute-expected.png:
    * platform/mac/fast/hidpi/image-srcset-only-src-attribute-expected.txt:
    * platform/mac/fast/hidpi/image-srcset-same-alternative-for-both-attributes-expected.png:
    * platform/mac/fast/hidpi/image-srcset-same-alternative-for-both-attributes-expected.txt:
    * platform/mac/fast/hidpi/image-srcset-invalid-inputs-expected.png:
    * platform/mac/fast/hidpi/image-srcset-invalid-inputs-expected.txt:
    * platform/mac/fast/hidpi/image-srcset-invalid-inputs-except-one-expected.png:
    * platform/mac/fast/hidpi/image-srcset-invalid-inputs-except-one-expected.txt:
    * platform/mac/fast/hidpi/image-srcset-invalid-inputs-correct-src-expected.png:
    * platform/mac/fast/hidpi/image-srcset-invalid-inputs-correct-src-expected.txt:
    * platform/mac/fast/hidpi/image-srcset-change-dynamically-from-js-expected.png:
    * platform/mac/fast/hidpi/image-srcset-change-dynamically-from-js-expected.txt:
    * platform/mac/fast/hidpi/image-srcset-remove-dynamically-from-js-expected.png:
    * platform/mac/fast/hidpi/image-srcset-remove-dynamically-from-js-expected.txt:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153624 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    8d0305d7