https://bugs.webkit.org/show_bug.cgi?id=80322
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Mar 2012 01:36:29 +0000 (01:36 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Mar 2012 01:36:29 +0000 (01:36 +0000)
commit02a2046c97e760be614eefcca698b9b69f09055c
treeae00075579532fe5ee1db3e2c2bbb5900b8a9c5e
parentf377e05987b2ba334f3e003c113a6f03a093f096
https://bugs.webkit.org/show_bug.cgi?id=80322
Implement image-set

Reviewed by Dean Jackson.

Source/WebCore:

This initial implementation of -webkit-image-set.
http://lists.w3.org/Archives/Public/www-style/2012Feb/1103.html
The idea behind the feature is to allow authors to provide multiple variants
of the same image at differing resolutions, and to allow the User Agent to
choose the resource that is most appropriate at the time. This patch will
choose the most appropriate image based on device scale factor.

CSSImageSetValue inherits from CSSValueList and behaves a lot like
CSSImageValue.
* WebCore.xcodeproj/project.pbxproj:
* css/CSSImageSetValue.h: Added.
(WebCore):
(CSSImageSetValue):
(WebCore::CSSImageSetValue::create):
(WebCore::CSSImageSetValue::isPending):
(ImageWithScale):
(WebCore::CSSImageSetValue::compareByScaleFactor):
* css/CSSImageSetValue.cpp: Added.
(WebCore):
(WebCore::CSSImageSetValue::CSSImageSetValue):
(WebCore::CSSImageSetValue::~CSSImageSetValue):
(WebCore::CSSImageSetValue::cachedOrPendingImageSet):
(WebCore::CSSImageSetValue::customCssText):

fillImageSet() iterates through the value list and turns the information into
a sorted Vector of ImageWithScales (which is a struct containing image URLs
and scale factors).
(WebCore::CSSImageSetValue::fillImageSet):

cachedImageSet() finds which image is most appropriate based on the device
scale factor, and it loads only that image. In the future, additional scale
factors will be taken into account.
(WebCore::CSSImageSetValue::bestImageForScaleFactor):
(WebCore::CSSImageSetValue::cachedImageSet):

parseImageSet() is called everywhere in the CSSParser that a regular image or
generated image can be found.
* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseContent):
(WebCore::CSSParser::parseFillImage):
(WebCore::CSSParser::parseBorderImage):
(WebCore):
(WebCore::CSSParser::parseImageSet):
* css/CSSParser.h:

Since CSSImageSetValue is implemented as a value list,
ApplyPropertyFillLayer::applyValue() needs to be more specific when it's
looking for a list of multiple URLs.
* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyFillLayer::applyValue):

Handle image-set as a valid image value.
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::collectMatchingRulesForList):
* css/CSSStyleSelector.h:
(CSSStyleSelector):
* css/CSSValue.cpp:
(WebCore::CSSValue::cssText):
(WebCore::CSSValue::destroy):
* css/CSSValue.h:
(CSSValue):
(WebCore::CSSValue::isImageSetValue):

computeIntrinsicDimensions() now takes an optional scaleFactor parameter that represents the author-enforced "intrinsic" scale factor of the image.
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::computeIntrinsicDimensions):
* loader/cache/CachedImage.h:
(CachedImage):
* platform/graphics/GeneratedImage.h:
(GeneratedImage):
* platform/graphics/GeneratorGeneratedImage.cpp:
(WebCore::GeneratedImage::computeIntrinsicDimensions):
* platform/graphics/Image.cpp:
(WebCore::Image::computeIntrinsicDimensions):
* platform/graphics/Image.h:
(Image):
* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::PDFDocumentImage::computeIntrinsicDimensions):
* platform/graphics/cg/PDFDocumentImage.h:
(PDFDocumentImage):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::computeIntrinsicDimensions):
* svg/graphics/SVGImage.h:
(SVGImage):

Inherits from StyleImage and returns a scaled size for imageSize() and
computeIntrinsicDimensions().
* rendering/style/StyleCachedImageSet.cpp: Added.
(WebCore):
(WebCore::StyleCachedImageSet::StyleCachedImageSet):
(WebCore::StyleCachedImageSet::cssValue):
(WebCore::StyleCachedImageSet::canRender):
(WebCore::StyleCachedImageSet::isLoaded):
(WebCore::StyleCachedImageSet::errorOccurred):
(WebCore::StyleCachedImageSet::imageSize):
(WebCore::StyleCachedImageSet::imageHasRelativeWidth):
(WebCore::StyleCachedImageSet::imageHasRelativeHeight):
(WebCore::StyleCachedImageSet::computeIntrinsicDimensions):
(WebCore::StyleCachedImageSet::usesImageContainerSize):
(WebCore::StyleCachedImageSet::setContainerSizeForRenderer):
(WebCore::StyleCachedImageSet::addClient):
(WebCore::StyleCachedImageSet::removeClient):
(WebCore::StyleCachedImageSet::image):
* rendering/style/StyleCachedImageSet.h: Added.
(WebCore):
(StyleCachedImageSet):
(WebCore::StyleCachedImageSet::create):
(WebCore::StyleCachedImageSet::data):
(WebCore::StyleCachedImageSet::cachedImage):

Handle image-set.
* rendering/style/StyleImage.h:
(WebCore::StyleImage::isCachedImageSet):
(WebCore::StyleImage::StyleImage):
(StyleImage):
* rendering/style/StylePendingImage.h:
(StylePendingImage):
(WebCore::StylePendingImage::cssImageSetValue):

Source/WTF:

For the time being, image-set is opt-in since the implementation is
incomplete.

Add an ENABLE flag for image-set.
* wtf/Platform.h:

LayoutTests:

* fast/css/image-set-parsing-expected.txt: Added.
* fast/css/image-set-parsing-invalid-expected.txt: Added.
* fast/css/image-set-parsing-invalid.html: Added.
* fast/css/image-set-parsing.html: Added.
* fast/css/script-tests/image-set-parsing-invalid.js: Added.
(testInvalidImageSet):
* fast/css/script-tests/image-set-parsing.js: Added.
(jsWrapperClass):
(shouldBeType):
(testImageSetRule):
* fast/hidpi/image-set-as-background.html: Added.
* fast/hidpi/image-set-background-repeat-without-size.html: Added.
* fast/hidpi/image-set-background-repeat.html: Added.
* fast/hidpi/image-set-border-image-simple.html: Added.
* fast/hidpi/image-set-out-of-order.html: Added.
* fast/hidpi/image-set-simple.html: Added.
* fast/hidpi/image-set-without-specified-width.html: Added.
* fast/hidpi/resources: Added.
* fast/hidpi/resources/blue-100-px-square.png: Added.
* fast/hidpi/resources/deleteButton-2x.png: Added.
* fast/hidpi/resources/deleteButton.png: Added.
* fast/hidpi/resources/red-200-px-square.png: Added.
* platform/efl/Skipped:
* platform/gtk/Skipped:
* platform/mac/fast/hidpi/image-set-as-background-expected.png: Added.
* platform/mac/fast/hidpi/image-set-as-background-expected.txt: Added.
* platform/mac/fast/hidpi/image-set-background-repeat-expected.png: Added.
* platform/mac/fast/hidpi/image-set-background-repeat-expected.txt: Added.
* platform/mac/fast/hidpi/image-set-background-repeat-without-size-expected.png: Added.
* platform/mac/fast/hidpi/image-set-background-repeat-without-size-expected.txt: Added.
* platform/mac/fast/hidpi/image-set-border-image-simple-expected.png: Added.
* platform/mac/fast/hidpi/image-set-border-image-simple-expected.txt: Added.
* platform/mac/fast/hidpi/image-set-out-of-order-expected.png: Added.
* platform/mac/fast/hidpi/image-set-out-of-order-expected.txt: Added.
* platform/mac/fast/hidpi/image-set-simple-expected.png: Added.
* platform/mac/fast/hidpi/image-set-simple-expected.txt: Added.
* platform/mac/fast/hidpi/image-set-without-specified-width-expected.png: Added.
* platform/mac/fast/hidpi/image-set-without-specified-width-expected.txt: Added.
* platform/qt/Skipped:
* platform/win/Skipped:
* platform/wincairo/Skipped:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@111637 268f45cc-cd09-0410-ab3c-d52691b4dbfc
71 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/image-set-parsing-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/image-set-parsing-invalid-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/image-set-parsing-invalid.html [new file with mode: 0644]
LayoutTests/fast/css/image-set-parsing.html [new file with mode: 0644]
LayoutTests/fast/css/script-tests/image-set-parsing-invalid.js [new file with mode: 0644]
LayoutTests/fast/css/script-tests/image-set-parsing.js [new file with mode: 0644]
LayoutTests/fast/hidpi/image-set-as-background.html [new file with mode: 0644]
LayoutTests/fast/hidpi/image-set-background-repeat-without-size.html [new file with mode: 0644]
LayoutTests/fast/hidpi/image-set-background-repeat.html [new file with mode: 0644]
LayoutTests/fast/hidpi/image-set-border-image-simple.html [new file with mode: 0644]
LayoutTests/fast/hidpi/image-set-out-of-order.html [new file with mode: 0644]
LayoutTests/fast/hidpi/image-set-simple.html [new file with mode: 0644]
LayoutTests/fast/hidpi/image-set-without-specified-width.html [new file with mode: 0644]
LayoutTests/fast/hidpi/resources/blue-100-px-square.png [new file with mode: 0644]
LayoutTests/fast/hidpi/resources/deleteButton-2x.png [new file with mode: 0644]
LayoutTests/fast/hidpi/resources/deleteButton.png [new file with mode: 0644]
LayoutTests/fast/hidpi/resources/green-200-px-square.png [new file with mode: 0644]
LayoutTests/platform/chromium/test_expectations.txt
LayoutTests/platform/efl/Skipped
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/fast/hidpi/broken-image-icon-hidpi-expected.png
LayoutTests/platform/mac/fast/hidpi/broken-image-with-size-hidpi-expected.png
LayoutTests/platform/mac/fast/hidpi/clip-text-in-hidpi-expected.png
LayoutTests/platform/mac/fast/hidpi/focus-rings-expected.png
LayoutTests/platform/mac/fast/hidpi/image-set-as-background-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-as-background-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-background-repeat-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-background-repeat-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-background-repeat-without-size-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-background-repeat-without-size-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-border-image-simple-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-border-image-simple-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-out-of-order-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-out-of-order-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-simple-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-simple-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-without-specified-width-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/image-set-without-specified-width-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/hidpi/resize-corner-hidpi-expected.png
LayoutTests/platform/mac/fast/hidpi/video-controls-in-hidpi-expected.png
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
LayoutTests/platform/wincairo/Skipped
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSImageSetValue.cpp [new file with mode: 0644]
Source/WebCore/css/CSSImageSetValue.h [new file with mode: 0644]
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParser.h
Source/WebCore/css/CSSStyleApplyProperty.cpp
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/css/CSSStyleSelector.h
Source/WebCore/css/CSSValue.cpp
Source/WebCore/css/CSSValue.h
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedImage.h
Source/WebCore/platform/graphics/GeneratedImage.h
Source/WebCore/platform/graphics/GeneratorGeneratedImage.cpp
Source/WebCore/platform/graphics/Image.cpp
Source/WebCore/platform/graphics/Image.h
Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp
Source/WebCore/platform/graphics/cg/PDFDocumentImage.h
Source/WebCore/rendering/style/StyleCachedImageSet.cpp [new file with mode: 0644]
Source/WebCore/rendering/style/StyleCachedImageSet.h [new file with mode: 0644]
Source/WebCore/rendering/style/StyleImage.h
Source/WebCore/rendering/style/StylePendingImage.h
Source/WebCore/svg/graphics/SVGImage.cpp
Source/WebCore/svg/graphics/SVGImage.h