Add support for HTMLImageElement's sizes attribute
authoryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jun 2014 04:07:08 +0000 (04:07 +0000)
committeryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jun 2014 04:07:08 +0000 (04:07 +0000)
commite81a2240bb123570f0105cce9e0dce156fc57754
treeb2912c0690d1abf5019282497c88a7b041e3fcad
parent82ef5e69f83c1f870e92e046555a9f2ba0727faf
Add support for HTMLImageElement's sizes attribute
https://bugs.webkit.org/show_bug.cgi?id=133620

Reviewed by Dean Jackson.

.:
Added an ENABLE_PICTURE_SIZES compile flag.

* Source/cmake/WebKitFeatures.cmake:
* Source/cmakeconfig.h.cmake:

Source/JavaScriptCore:
Added an ENABLE_PICTURE_SIZES compile flag.

* Configurations/FeatureDefines.xcconfig:

Source/WebCore:
Tests: fast/dom/HTMLImageElement/sizes/image-sizes-1x.html
       fast/dom/HTMLImageElement/sizes/image-sizes-2x.html
       fast/dom/HTMLImageElement/sizes/image-sizes-js-change.html
       fast/dom/HTMLImageElement/sizes/image-sizes-js-innerhtml.html
       http/tests/loading/sizes/preload-image-sizes-2x.html
       http/tests/loading/sizes/preload-image-sizes.html

This patch adds support for HTMLImageElement's sizes attribute and the
related srcset extended syntax as defined in
http://picture.responsiveimages.org/.
This sizes attribute syntax is added to the CSSGrammar and parsed by
the CSSParser.
The SourceSizeList class is generated by the parser, and used to get
the final source size.
HTMLImageElement and HTMLPreloadScanner send this value to
HTMLSrcsetParser.
HTMLSrcsetParser uses this value in order to pick the right resource.

* CMakeLists.txt: Added css/SourceSizeList.cpp.
* Configurations/FeatureDefines.xcconfig: Added the PICTURE_SIZES flag.
* WebCore.vcxproj/WebCore.vcxproj: Added css/SourceSizeList.*.
* WebCore.vcxproj/WebCore.vcxproj.filters: Added css/SourceSizeList.*.
* WebCore.xcodeproj/project.pbxproj: Added css/SourceSizeList.*.
* css/CSSGrammar.y.in: Added 4 grammar rules that define a Media condition,
Source size list, Source size length and source size.
* css/CSSParser.cpp:
(WebCore::CSSParser::parseSizesAttribute): Parse the sizes attribute.
(WebCore::CSSParser::detectAtToken): Set the token to SIZESATTR.
* css/CSSParser.h:
* css/SourceSizeList.cpp: Added. Defined the SourceSize and SourceSizeList classes.
(WebCore::SourceSize::match):
(WebCore::computeLength):
(WebCore::defaultValue):
(WebCore::SourceSize::length):
(WebCore::SourceSizeList::parseSizesAttribute):
(WebCore::SourceSizeList::getEffectiveSize):
* css/SourceSizeList.h: Added.
(WebCore::SourceSize::SourceSize):
(WebCore::SourceSizeList::append):
* html/HTMLImageElement.cpp: Integrated sizes attribute parsing and added currentSrc.
(WebCore::HTMLImageElement::setBestFitURLAndDPRFromImageCandidate):
(WebCore::HTMLImageElement::parseAttribute):
(WebCore::HTMLImageElement::currentSrc):
* html/HTMLImageElement.h:
* html/HTMLImageElement.idl:
* html/parser/HTMLDocumentParser.cpp: Added information required for sizes parsing to
HTMLPreloadScanner calls.
(WebCore::HTMLDocumentParser::pumpTokenizer):
(WebCore::HTMLDocumentParser::insert):
(WebCore::HTMLDocumentParser::append):
(WebCore::HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan):
* html/parser/HTMLPreloadScanner.cpp: Integrated sizes attribute parsing.
(WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):
(WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
(WebCore::TokenPreloadScanner::scan):
(WebCore::HTMLPreloadScanner::scan):
* html/parser/HTMLPreloadScanner.h:
* html/parser/HTMLSrcsetParser.cpp: Added 'w' descriptor parsing sizes based normalization.
(WebCore::parseDescriptors):
(WebCore::pickBestImageCandidate):
(WebCore::bestFitSourceForImageAttributes):
* html/parser/HTMLSrcsetParser.h:

Source/WebKit/mac:
Added an ENABLE_PICTURE_SIZES compile flag.

* Configurations/FeatureDefines.xcconfig:

Source/WebKit2:
Added an ENABLE_PICTURE_SIZES compile flag.

* Configurations/FeatureDefines.xcconfig:

Tools:
Added an ENABLE_PICTURE_SIZES compile flag.

* Scripts/webkitperl/FeatureList.pm:

LayoutTests:
These layout tests check that the sizes attribute and the related
srcset syntax are well supported, that the right resource is displayed,
that the currentSrc attribute is well supported and also that the right
resource is preloaded.

* fast/dom/HTMLImageElement/resources/currentSrcHelper.js: Added.
(fileName):
(currentSrcFileName):
* fast/dom/HTMLImageElement/resources/image-set-4x.png: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-1x-expected.txt: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-1x.html: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-2x-expected.txt: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-2x.html: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-js-change-expected.txt: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-js-change.html: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-js-innerhtml-expected.txt: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-js-innerhtml.html: Added.
* http/tests/loading/sizes/preload-image-sizes-2x-expected.txt: Added.
* http/tests/loading/sizes/preload-image-sizes-2x.html: Added.
* http/tests/loading/sizes/preload-image-sizes-expected.txt: Added.
* http/tests/loading/sizes/preload-image-sizes.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170576 268f45cc-cd09-0410-ab3c-d52691b4dbfc
47 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/dom/HTMLImageElement/resources/currentSrcHelper.js [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/resources/image-set-4x.png [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-1x-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-1x.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-2x-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-2x.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-js-change-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-js-change.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-js-innerhtml-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-js-innerhtml.html [new file with mode: 0644]
LayoutTests/http/tests/loading/sizes/preload-image-sizes-2x-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/loading/sizes/preload-image-sizes-2x.html [new file with mode: 0644]
LayoutTests/http/tests/loading/sizes/preload-image-sizes-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/loading/sizes/preload-image-sizes.html [new file with mode: 0644]
LayoutTests/resources/srcset-helper.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/Configurations/FeatureDefines.xcconfig
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Configurations/FeatureDefines.xcconfig
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSGrammar.y.in
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParser.h
Source/WebCore/css/SourceSizeList.cpp [new file with mode: 0644]
Source/WebCore/css/SourceSizeList.h [new file with mode: 0644]
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/HTMLImageElement.idl
Source/WebCore/html/parser/HTMLDocumentParser.cpp
Source/WebCore/html/parser/HTMLPreloadScanner.cpp
Source/WebCore/html/parser/HTMLPreloadScanner.h
Source/WebCore/html/parser/HTMLSrcsetParser.cpp
Source/WebCore/html/parser/HTMLSrcsetParser.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Configurations/FeatureDefines.xcconfig
Source/WebKit2/ChangeLog
Source/WebKit2/Configurations/FeatureDefines.xcconfig
Source/cmake/WebKitFeatures.cmake
Source/cmakeconfig.h.cmake
Tools/ChangeLog
Tools/Scripts/webkitperl/FeatureList.pm