Update HTMLPreloadScanner to handle img srcset
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Aug 2013 01:13:15 +0000 (01:13 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Aug 2013 01:13:15 +0000 (01:13 +0000)
commit00cd51166e13ba1cca1bf8992c027e5e68039143
treedc49f54696b4d0ea868fc7caf510c2b0ddc016e4
parent5055e2e81eeaab851b5c112003af0a6e0ef75d1d
Update HTMLPreloadScanner to handle img srcset
https://bugs.webkit.org/show_bug.cgi?id=119360

Reviewed by Sam Weinig.

This patch is a merge of similar patches from Yoav Weiss <yoav@yoav.ws>
and Dean Jackson.

Source/WebCore:

Test: fast/preloader/image-srcset.html

* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseAttribute): Move srcset parsing into
HTMLParserIdioms, and call it when we hit src or srcset.
* html/HTMLImageElement.h: Remove code that was moved to HTMLParserIdioms.

* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::pumpTokenizer): Pass device scale into preloader.
(WebCore::HTMLDocumentParser::insert):

* html/parser/HTMLPreloadScanner.cpp:
(WebCore::TokenPreloadScanner::StartTagScanner::StartTagScanner): Takes device scale as a parameter.
(WebCore::TokenPreloadScanner::StartTagScanner::processAttributes): Resolve between src and srcSet if necessary.
(WebCore::TokenPreloadScanner::StartTagScanner::processAttribute): Add support for srcset attribute.
(WebCore::TokenPreloadScanner::StartTagScanner::setUrlToLoad): New flag to indicate if we should
replace any existing value.
(WebCore::TokenPreloadScanner::TokenPreloadScanner): Takes device scale.
(WebCore::TokenPreloadScanner::scanCommon): Pass device scale.
(WebCore::HTMLPreloadScanner::HTMLPreloadScanner):
* html/parser/HTMLPreloadScanner.h: New attribute to constructor for device scale. New member
variable on TokenPreloadScanner that holds the srcset value.

* html/parser/HTMLParserIdioms.cpp:
(WebCore::ImageWithScale::operator==): Used for sorting.
(WebCore::compareByScaleFactor): Used for sorting.
(WebCore::bestFitSourceForImageAttributes): New method that takes the code from HTMLImageElement
for parsing src and srcset attributes, and finding the best match.
* html/parser/HTMLParserIdioms.h:

LayoutTests:

New test to make sure the HTML preloader takes the
value of srcset if available.

* fast/preloader/image-srcset-expected.txt: Added.
* fast/preloader/image-srcset.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@153733 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/preloader/image-srcset-expected.txt [new file with mode: 0644]
LayoutTests/fast/preloader/image-srcset.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/parser/HTMLDocumentParser.cpp
Source/WebCore/html/parser/HTMLParserIdioms.cpp
Source/WebCore/html/parser/HTMLParserIdioms.h
Source/WebCore/html/parser/HTMLPreloadScanner.cpp
Source/WebCore/html/parser/HTMLPreloadScanner.h