Source/WebCore/ChangeLog

 12012-06-15 David Barr <davidbarr@chromium.org>
 2
 3 Add from-image to css3-images image-resolution
 4 https://bugs.webkit.org/show_bug.cgi?id=85451
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 The css3-images module is at candidate recommendation.
 9 http://www.w3.org/TR/2012/CR-css3-images-20120417/#the-image-resolution
 10
 11 No new tests; extended fast/css/image-resolution/image-resolution.html
 12
 13 * css/CSSParser.cpp: Accept from-image identifier in image-resolution property.
 14 (WebCore::CSSParser::parseImageResolution): Map CSSValueFromImage to identifier value from cssValuePool.
 15 * css/CSSValueKeywords.in: Add from-image.
 16 * css/StyleBuilder.cpp: Extend ApplyPropertyImageResolution to apply RenderStyle::imageResolutionFlags.
 17 (WebCore::ApplyPropertyImageResolution::applyInheritValue): Apply RenderStyle::imageResolutionFlags.
 18 (WebCore::ApplyPropertyImageResolution::applyInitialValue): Apply RenderStyle::imageResolutionFlags.
 19 (WebCore::ApplyPropertyImageResolution::applyValue): Map CSSValueFromImage to ImageResolutionFromImage.
 20 * rendering/style/RenderStyle.cpp: Include StyleRareInheritedData::m_imageResolutionFlags in style diff.
 21 (WebCore::RenderStyle::diff): Map change in StyleRareInheritedData::m_imageResolutionFlags to StyleDifferenceLayout.
 22 * rendering/style/RenderStyle.h: Add RenderStyle::imageResolutionFlags, RenderStyle::setImageResolutionFlags, RenderStyle::initialImageResolutionFlags.
 23 * rendering/style/RenderStyleConstants.h: Add enum EImageResolution.
 24 * rendering/style/StyleRareInheritedData.cpp: Add StyleRareInheritedData::m_imageResolutionFlags.
 25 (WebCore::StyleRareInheritedData::StyleRareInheritedData): Add m_imageResolutionFlags to default and copy constructor.
 26 (WebCore::StyleRareInheritedData::operator==): Include m_imageResolutionFlags in comparison.
 27 * rendering/style/StyleRareInheritedData.h: Add StyleRareInheritedData::m_imageResolutionFlags.
 28 (StyleRareInheritedData): Add 1-bit field StyleRareInheritedData::m_imageResolutionFlags.
 29
1302012-06-14 David Barr <davidbarr@chromium.org>
231
332 Add dpcm to css3-images image-resolution

Source/WebCore/css/CSSParser.cpp

@@PassRefPtr<CSSValue> CSSParser::parseImageResolution(CSSParserValueList* valueLi
68856885{
68866886 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
68876887 bool haveResolution = false;
 6888 bool haveFromImage = false;
68886889
68896890 CSSParserValue* value = valueList->current();
68906891 while (value) {
6891  if (!haveResolution && validUnit(value, FResolution | FNonNeg) && value->fValue > 0) {
 6892 if (!haveFromImage && value->id == CSSValueFromImage) {
 6893 list->append(cssValuePool().createIdentifierValue(value->id));
 6894 haveFromImage = true;
 6895 } else if (!haveResolution && validUnit(value, FResolution | FNonNeg) && value->fValue > 0) {
68926896 list->append(createPrimitiveNumericValue(value));
68936897 haveResolution = true;
68946898 } else

Source/WebCore/css/CSSValueKeywords.in

@@filter-box
924924detached
925925#endif // CSS_SHADERS
926926#endif // CSS_FILTERS
 927
 928#if defined(ENABLE_CSS_IMAGE_RESOLUTION) && ENABLE_CSS_IMAGE_RESOLUTION
 929from-image
 930#endif

Source/WebCore/css/StyleBuilder.cpp

@@class ApplyPropertyImageResolution {
17721772public:
17731773 static void applyInheritValue(StyleResolver* styleResolver)
17741774 {
 1775 ApplyPropertyDefaultBase<ImageResolution, &RenderStyle::imageResolutionFlags, ImageResolution, &RenderStyle::setImageResolutionFlags, ImageResolution, &RenderStyle::initialImageResolutionFlags>::applyInheritValue(styleResolver);
17751776 ApplyPropertyDefaultBase<float, &RenderStyle::imageResolution, float, &RenderStyle::setImageResolution, float, &RenderStyle::initialImageResolution>::applyInheritValue(styleResolver);
17761777 }
17771778
17781779 static void applyInitialValue(StyleResolver* styleResolver)
17791780 {
 1781 ApplyPropertyDefaultBase<ImageResolution, &RenderStyle::imageResolutionFlags, ImageResolution, &RenderStyle::setImageResolutionFlags, ImageResolution, &RenderStyle::initialImageResolutionFlags>::applyInitialValue(styleResolver);
17801782 ApplyPropertyDefaultBase<float, &RenderStyle::imageResolution, float, &RenderStyle::setImageResolution, float, &RenderStyle::initialImageResolution>::applyInitialValue(styleResolver);
17811783 }
17821784

@@public:
17851787 if (!value->isValueList())
17861788 return;
17871789 CSSValueList* valueList = static_cast<CSSValueList*>(value);
 1790 ImageResolution flags = RenderStyle::initialImageResolutionFlags();
 1791 double resolution = RenderStyle::initialImageResolution();
17881792 for (size_t i = 0; i < valueList->length(); i++) {
17891793 CSSValue* item = valueList->itemWithoutBoundsCheck(i);
17901794 if (!item->isPrimitiveValue())
17911795 continue;
17921796 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(item);
1793  styleResolver->style()->setImageResolution(primitiveValue->getDoubleValue(CSSPrimitiveValue::CSS_DPPX));
 1797 if (primitiveValue->getIdent() == CSSValueFromImage)
 1798 flags = ImageResolutionFromImage;
 1799 else
 1800 resolution = primitiveValue->getDoubleValue(CSSPrimitiveValue::CSS_DPPX);
17941801 }
 1802 styleResolver->style()->setImageResolutionFlags(flags);
 1803 styleResolver->style()->setImageResolution(resolution);
17951804 }
17961805
17971806 static PropertyHandler createHandler()

Source/WebCore/rendering/style/RenderStyle.cpp

@@StyleDifference RenderStyle::diff(const RenderStyle* other, unsigned& changedCon
473473 || rareInheritedData->m_lineBoxContain != other->rareInheritedData->m_lineBoxContain
474474 || rareInheritedData->m_lineGrid != other->rareInheritedData->m_lineGrid
475475#if ENABLE(CSS_IMAGE_RESOLUTION)
 476 || rareInheritedData->m_imageResolutionFlags != other->rareInheritedData->m_imageResolutionFlags
476477 || rareInheritedData->m_imageResolution != other->rareInheritedData->m_imageResolution
477478#endif
478479 || rareInheritedData->m_lineSnap != other->rareInheritedData->m_lineSnap

Source/WebCore/rendering/style/RenderStyle.h

@@public:
982982 EImageRendering imageRendering() const { return static_cast<EImageRendering>(rareInheritedData->m_imageRendering); }
983983
984984#if ENABLE(CSS_IMAGE_RESOLUTION)
 985 ImageResolution imageResolutionFlags() const { return static_cast<ImageResolution>(rareInheritedData->m_imageResolutionFlags); }
985986 float imageResolution() const { return rareInheritedData->m_imageResolution; }
986987#endif
987988

@@public:
11521153 void setImageRendering(EImageRendering v) { SET_VAR(rareInheritedData, m_imageRendering, v) }
11531154
11541155#if ENABLE(CSS_IMAGE_RESOLUTION)
 1156 void setImageResolutionFlags(ImageResolution v) { SET_VAR(rareInheritedData, m_imageResolutionFlags, v) }
11551157 void setImageResolution(float f) { SET_VAR(rareInheritedData, m_imageResolution, f) }
11561158#endif
11571159

@@public:
16641666 static TextEmphasisPosition initialTextEmphasisPosition() { return TextEmphasisPositionOver; }
16651667 static LineBoxContain initialLineBoxContain() { return LineBoxContainBlock | LineBoxContainInline | LineBoxContainReplaced; }
16661668 static EImageRendering initialImageRendering() { return ImageRenderingAuto; }
 1669 static ImageResolution initialImageResolutionFlags() { return ImageResolutionNoFlags; }
16671670 static float initialImageResolution() { return 1; }
16681671 static StyleImage* initialBorderImageSource() { return 0; }
16691672 static StyleImage* initialMaskBoxImageSource() { return 0; }

Source/WebCore/rendering/style/RenderStyleConstants.h

@@enum TextOverflow { TextOverflowClip = 0, TextOverflowEllipsis };
454454
455455enum EImageRendering { ImageRenderingAuto, ImageRenderingOptimizeSpeed, ImageRenderingOptimizeQuality, ImageRenderingOptimizeContrast };
456456
 457enum ImageResolution { ImageResolutionNoFlags = 0, ImageResolutionFromImage };
 458
457459enum Order { LogicalOrder = 0, VisualOrder };
458460
459461enum RegionOverflow { AutoRegionOverflow, BreakRegionOverflow };

Source/WebCore/rendering/style/StyleRareInheritedData.cpp

@@StyleRareInheritedData::StyleRareInheritedData()
5858#if ENABLE(OVERFLOW_SCROLLING)
5959 , useTouchOverflowScrolling(RenderStyle::initialUseTouchOverflowScrolling())
6060#endif
 61#if ENABLE(CSS_IMAGE_RESOLUTION)
 62 , m_imageResolutionFlags(RenderStyle::initialImageResolutionFlags())
 63#endif
6164 , hyphenationLimitBefore(-1)
6265 , hyphenationLimitAfter(-1)
6366 , hyphenationLimitLines(-1)

@@StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
113116#if ENABLE(OVERFLOW_SCROLLING)
114117 , useTouchOverflowScrolling(o.useTouchOverflowScrolling)
115118#endif
 119#if ENABLE(CSS_IMAGE_RESOLUTION)
 120 , m_imageResolutionFlags(o.m_imageResolutionFlags)
 121#endif
116122 , hyphenationString(o.hyphenationString)
117123 , hyphenationLimitBefore(o.hyphenationLimitBefore)
118124 , hyphenationLimitAfter(o.hyphenationLimitAfter)

@@bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
195201 && m_lineGrid == o.m_lineGrid
196202 && m_imageRendering == o.m_imageRendering
197203#if ENABLE(CSS_IMAGE_RESOLUTION)
 204 && m_imageResolutionFlags == o.m_imageResolutionFlags
198205 && m_imageResolution == o.m_imageResolution
199206#endif
200207 && m_lineSnap == o.m_lineSnap

Source/WebCore/rendering/style/StyleRareInheritedData.h

@@public:
101101#if ENABLE(OVERFLOW_SCROLLING)
102102 unsigned useTouchOverflowScrolling: 1;
103103#endif
 104#if ENABLE(CSS_IMAGE_RESOLUTION)
 105 unsigned m_imageResolutionFlags : 1; // ImageResolution
 106#endif
104107
105108 AtomicString hyphenationString;
106109 short hyphenationLimitBefore;

LayoutTests/ChangeLog

 12012-06-15 David Barr <davidbarr@chromium.org>
 2
 3 Add from-image to css3-images image-resolution
 4 https://bugs.webkit.org/show_bug.cgi?id=85451
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * fast/css/image-resolution/image-resolution-expected.txt:
 9 * fast/css/image-resolution/image-resolution.html:
 10
1112012-06-14 David Barr <davidbarr@chromium.org>
212
313 Add dpcm to css3-images image-resolution

LayoutTests/fast/css/image-resolution/image-resolution-expected.txt

1 Apply image-resolution property to a fixed image (16x16@0.75dppx).
 1Apply image-resolution property to a fixed image (16x16).
22
33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
44

@@PASS img.offsetWidth is 4
7575PASS img.offsetHeight is 4
7676TEST ""
7777PASS img.style.cssText is ""
 78TEST "0dppx from-image"
 79PASS img.style.cssText is ""
 80TEST "from-image 0dppx"
 81PASS img.style.cssText is ""
 82TEST "1dppx from-image"
 83PASS img.style.cssText is "image-resolution: 1dppx from-image; "
 84PASS img.offsetWidth is 16
 85PASS img.offsetHeight is 16
 86TEST "from-image 1dppx"
 87PASS img.style.cssText is "image-resolution: from-image 1dppx; "
 88PASS img.offsetWidth is 16
 89PASS img.offsetHeight is 16
 90TEST "2dppx from-image"
 91PASS img.style.cssText is "image-resolution: 2dppx from-image; "
 92PASS img.offsetWidth is 8
 93PASS img.offsetHeight is 8
 94TEST "from-image 2dppx"
 95PASS img.style.cssText is "image-resolution: from-image 2dppx; "
 96PASS img.offsetWidth is 8
 97PASS img.offsetHeight is 8
 98TEST "3dppx from-image"
 99PASS img.style.cssText is "image-resolution: 3dppx from-image; "
 100PASS img.offsetWidth is 5
 101PASS img.offsetHeight is 5
 102TEST "from-image 3dppx"
 103PASS img.style.cssText is "image-resolution: from-image 3dppx; "
 104PASS img.offsetWidth is 5
 105PASS img.offsetHeight is 5
 106TEST "4dppx from-image"
 107PASS img.style.cssText is "image-resolution: 4dppx from-image; "
 108PASS img.offsetWidth is 4
 109PASS img.offsetHeight is 4
 110TEST "from-image 4dppx"
 111PASS img.style.cssText is "image-resolution: from-image 4dppx; "
 112PASS img.offsetWidth is 4
 113PASS img.offsetHeight is 4
 114TEST "0dpi from-image"
 115PASS img.style.cssText is ""
 116TEST "from-image 0dpi"
 117PASS img.style.cssText is ""
 118TEST "96dpi from-image"
 119PASS img.style.cssText is "image-resolution: 96dpi from-image; "
 120PASS img.offsetWidth is 16
 121PASS img.offsetHeight is 16
 122TEST "from-image 96dpi"
 123PASS img.style.cssText is "image-resolution: from-image 96dpi; "
 124PASS img.offsetWidth is 16
 125PASS img.offsetHeight is 16
 126TEST "192dpi from-image"
 127PASS img.style.cssText is "image-resolution: 192dpi from-image; "
 128PASS img.offsetWidth is 8
 129PASS img.offsetHeight is 8
 130TEST "from-image 192dpi"
 131PASS img.style.cssText is "image-resolution: from-image 192dpi; "
 132PASS img.offsetWidth is 8
 133PASS img.offsetHeight is 8
 134TEST "288dpi from-image"
 135PASS img.style.cssText is "image-resolution: 288dpi from-image; "
 136PASS img.offsetWidth is 5
 137PASS img.offsetHeight is 5
 138TEST "from-image 288dpi"
 139PASS img.style.cssText is "image-resolution: from-image 288dpi; "
 140PASS img.offsetWidth is 5
 141PASS img.offsetHeight is 5
 142TEST "384dpi from-image"
 143PASS img.style.cssText is "image-resolution: 384dpi from-image; "
 144PASS img.offsetWidth is 4
 145PASS img.offsetHeight is 4
 146TEST "from-image 384dpi"
 147PASS img.style.cssText is "image-resolution: from-image 384dpi; "
 148PASS img.offsetWidth is 4
 149PASS img.offsetHeight is 4
 150TEST "150dpi from-image"
 151PASS img.style.cssText is "image-resolution: 150dpi from-image; "
 152PASS img.offsetWidth is 10
 153PASS img.offsetHeight is 10
 154TEST "from-image 150dpi"
 155PASS img.style.cssText is "image-resolution: from-image 150dpi; "
 156PASS img.offsetWidth is 10
 157PASS img.offsetHeight is 10
 158TEST "300dpi from-image"
 159PASS img.style.cssText is "image-resolution: 300dpi from-image; "
 160PASS img.offsetWidth is 5
 161PASS img.offsetHeight is 5
 162TEST "from-image 300dpi"
 163PASS img.style.cssText is "image-resolution: from-image 300dpi; "
 164PASS img.offsetWidth is 5
 165PASS img.offsetHeight is 5
 166TEST "450dpi from-image"
 167PASS img.style.cssText is "image-resolution: 450dpi from-image; "
 168PASS img.offsetWidth is 3
 169PASS img.offsetHeight is 3
 170TEST "from-image 450dpi"
 171PASS img.style.cssText is "image-resolution: from-image 450dpi; "
 172PASS img.offsetWidth is 3
 173PASS img.offsetHeight is 3
 174TEST "600dpi from-image"
 175PASS img.style.cssText is "image-resolution: 600dpi from-image; "
 176PASS img.offsetWidth is 2
 177PASS img.offsetHeight is 2
 178TEST "from-image 600dpi"
 179PASS img.style.cssText is "image-resolution: from-image 600dpi; "
 180PASS img.offsetWidth is 2
 181PASS img.offsetHeight is 2
 182TEST "0dpcm from-image"
 183PASS img.style.cssText is ""
 184TEST "from-image 0dpcm"
 185PASS img.style.cssText is ""
 186TEST "37.7dpcm from-image"
 187PASS img.style.cssText is "image-resolution: 37.7dpcm from-image; "
 188PASS img.offsetWidth is 16
 189PASS img.offsetHeight is 16
 190TEST "from-image 37.7dpcm"
 191PASS img.style.cssText is "image-resolution: from-image 37.7dpcm; "
 192PASS img.offsetWidth is 16
 193PASS img.offsetHeight is 16
 194TEST "75.5dpcm from-image"
 195PASS img.style.cssText is "image-resolution: 75.5dpcm from-image; "
 196PASS img.offsetWidth is 8
 197PASS img.offsetHeight is 8
 198TEST "from-image 75.5dpcm"
 199PASS img.style.cssText is "image-resolution: from-image 75.5dpcm; "
 200PASS img.offsetWidth is 8
 201PASS img.offsetHeight is 8
 202TEST "113.3dpcm from-image"
 203PASS img.style.cssText is "image-resolution: 113.3dpcm from-image; "
 204PASS img.offsetWidth is 5
 205PASS img.offsetHeight is 5
 206TEST "from-image 113.3dpcm"
 207PASS img.style.cssText is "image-resolution: from-image 113.3dpcm; "
 208PASS img.offsetWidth is 5
 209PASS img.offsetHeight is 5
 210TEST "151.1dpcm from-image"
 211PASS img.style.cssText is "image-resolution: 151.1dpcm from-image; "
 212PASS img.offsetWidth is 4
 213PASS img.offsetHeight is 4
 214TEST "from-image 151.1dpcm"
 215PASS img.style.cssText is "image-resolution: from-image 151.1dpcm; "
 216PASS img.offsetWidth is 4
 217PASS img.offsetHeight is 4
 218TEST "from-image"
 219PASS img.style.cssText is "image-resolution: from-image; "
 220PASS img.offsetWidth is 16
 221PASS img.offsetHeight is 16
78222PASS successfullyParsed is true
79223
80224TEST COMPLETE

LayoutTests/fast/css/image-resolution/image-resolution.html

@@function computeResolution(resolution, imgResolutionDppx)
3939 else if (unit === 'dpcm')
4040 dppx = value / (cssPxPerIn / cmPerIn);
4141 }
42  if (fromImage)
 42 if (fromImage && imgResolutionDppx)
4343 dppx = imgResolutionDppx;
4444 if (snap)
4545 dppx = Math.floor(dppx);

@@function computeResolution(resolution, imgResolutionDppx)
4848 return dppx;
4949}
5050
 51function permute2(rule) {
 52 var s = rule.trim().split(' ');
 53 if (s.length == 1)
 54 return s;
 55 return [s.join(' '), [s[1], s[0]].join(' ')];
 56}
 57
 58function generateTests(resolutions) {
 59 var tests = resolutions.slice();
 60 resolutions.forEach(function(resolution) {
 61 tests.push.apply(tests, permute2(resolution + ' from-image'));
 62 });
 63 return tests;
 64}
 65
5166var imgUrl = '../../images/resources/green.jpg';
5267var imgWidthPx = 16;
5368var imgHeightPx = 16;
54 var imgResolutionDppx = 72 / 96;
55 var dimensions = imgWidthPx + 'x' + imgHeightPx + '@' + imgResolutionDppx + 'dppx';
 69var imgResolutionDppx = 0; /* Embedded image resolution data not plumbed yet. */
 70var dimensions = imgWidthPx + 'x' + imgHeightPx;
5671
5772description('Apply image-resolution property to a fixed image (' + dimensions + ').');
5873

@@var resolutions = ['0dppx', '1dppx', '2dppx', '3dppx', '4dppx',
6580 '0dpcm', '37.7dpcm', '75.5dpcm', '113.3dpcm', '151.1dpcm', ''];
6681
6782img.onload = function() {
68  resolutions.forEach(function(test) {
 83 generateTests(resolutions).forEach(function(test) {
6984 var dppx = computeResolution(test, imgResolutionDppx);
7085 img.style.imageResolution = '';
7186 img.style.imageResolution = test;