Support CSS3 Images values for the image-rendering property
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Jan 2016 23:31:38 +0000 (23:31 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Jan 2016 23:31:38 +0000 (23:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=153556

Reviewed by Dean Jackson.

Source/WebCore:

CSS3 Images has the following values for image-rendering:
    auto, crisp-edges, pixelated

The old code supported:
    optimizeSpeed, optimizeQuality, -webkit-crisp-edges, -webkit-optimize-contrast

Add support for the new values without prefixes. Map -webkit-crisp-edges to crisp-edges,
and -webkit-optimize-contrast to crisp-edges. Support pixelated which behaves like
crisp-edges (a low quality scale).

The spec says that optimizeQuality should behave like 'auto', but that would be
a behavior change since ImageQualityController::shouldPaintAtLowQuality() currently
uses it as a trigger to avoid low quality scaling, so don't change that for now.

No new tests, covered by fast/css/script-tests/image-rendering-parsing.js

* css/CSSParser.cpp:
(WebCore::isValidKeywordPropertyAndValue):
* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::operator EImageRendering):
* css/CSSValueKeywords.in:
* rendering/ImageQualityController.cpp:
(WebCore::ImageQualityController::shouldPaintAtLowQuality):
* rendering/RenderHTMLCanvas.cpp:
(WebCore::RenderHTMLCanvas::paintReplaced):
* rendering/style/RenderStyleConstants.h:
* rendering/style/StyleRareInheritedData.h: Need another bit.

Source/WebInspectorUI:

Add "crisp-edges", "pixelated" to the suggestions for image-rendering.

* UserInterface/Models/CSSKeywordCompletions.js:

LayoutTests:

Update for new values. Add a new SVG shape-rendering test which would have
detected a bug I caused with an earlier patch.

* fast/css/image-rendering-parsing-expected.txt:
* fast/css/script-tests/image-rendering-parsing.js:
* svg/css/script-tests/shape-rendering-parsing.js: Added.
* svg/css/shape-rendering-parsing.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195699 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/image-rendering-parsing-expected.txt
LayoutTests/fast/css/script-tests/image-rendering-parsing.js
LayoutTests/svg/css/script-tests/shape-rendering-parsing.js [new file with mode: 0644]
LayoutTests/svg/css/shape-rendering-parsing-expected.txt [new file with mode: 0644]
LayoutTests/svg/css/shape-rendering-parsing.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/rendering/ImageQualityController.cpp
Source/WebCore/rendering/RenderHTMLCanvas.cpp
Source/WebCore/rendering/style/RenderStyleConstants.h
Source/WebCore/rendering/style/StyleRareInheritedData.h
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js

index 952c9a7..b3139f5 100644 (file)
@@ -1,3 +1,18 @@
+2016-01-27  Simon Fraser  <simon.fraser@apple.com>
+
+        Support CSS3 Images values for the image-rendering property
+        https://bugs.webkit.org/show_bug.cgi?id=153556
+
+        Reviewed by Dean Jackson.
+
+        Update for new values. Add a new SVG shape-rendering test which would have
+        detected a bug I caused with an earlier patch.
+
+        * fast/css/image-rendering-parsing-expected.txt:
+        * fast/css/script-tests/image-rendering-parsing.js:
+        * svg/css/script-tests/shape-rendering-parsing.js: Added.
+        * svg/css/shape-rendering-parsing.html: Added.
+
 2016-01-27  Brady Eidson  <beidson@apple.com>
 
         Modern IDB: Fix many Index tests.
index c62336b..06ceb50 100644 (file)
@@ -7,11 +7,17 @@ PASS div.style.getPropertyCSSValue('image-rendering').cssValueType is CSSValue.C
 PASS div.style.getPropertyValue('image-rendering') is "auto"
 PASS getComputedStyle(div).getPropertyValue('image-rendering') is "auto"
 PASS div.style.getPropertyCSSValue('image-rendering').cssValueType is CSSValue.CSS_PRIMITIVE_VALUE
+PASS div.style.getPropertyValue('image-rendering') is "crisp-edges"
+PASS getComputedStyle(div).getPropertyValue('image-rendering') is "crisp-edges"
+PASS div.style.getPropertyCSSValue('image-rendering').cssValueType is CSSValue.CSS_PRIMITIVE_VALUE
+PASS div.style.getPropertyValue('image-rendering') is "pixelated"
+PASS getComputedStyle(div).getPropertyValue('image-rendering') is "pixelated"
+PASS div.style.getPropertyCSSValue('image-rendering').cssValueType is CSSValue.CSS_PRIMITIVE_VALUE
 PASS div.style.getPropertyValue('image-rendering') is "-webkit-crisp-edges"
-PASS getComputedStyle(div).getPropertyValue('image-rendering') is "-webkit-crisp-edges"
+PASS getComputedStyle(div).getPropertyValue('image-rendering') is "crisp-edges"
 PASS div.style.getPropertyCSSValue('image-rendering').cssValueType is CSSValue.CSS_PRIMITIVE_VALUE
 PASS div.style.getPropertyValue('image-rendering') is "-webkit-optimize-contrast"
-PASS getComputedStyle(div).getPropertyValue('image-rendering') is "-webkit-crisp-edges"
+PASS getComputedStyle(div).getPropertyValue('image-rendering') is "crisp-edges"
 PASS div.style.getPropertyCSSValue('image-rendering').cssValueType is CSSValue.CSS_PRIMITIVE_VALUE
 PASS div.style.getPropertyValue('image-rendering') is "optimizespeed"
 PASS getComputedStyle(div).getPropertyValue('image-rendering') is "optimizespeed"
index 7d2a83b..1fb3c65 100644 (file)
@@ -14,8 +14,10 @@ function testImageRendering(value, computedValue)
 }
 
 testImageRendering('auto', 'auto');
-testImageRendering('-webkit-crisp-edges', '-webkit-crisp-edges');
-testImageRendering('-webkit-optimize-contrast', '-webkit-crisp-edges');
+testImageRendering('crisp-edges', 'crisp-edges');
+testImageRendering('pixelated', 'pixelated');
+testImageRendering('-webkit-crisp-edges', 'crisp-edges');
+testImageRendering('-webkit-optimize-contrast', 'crisp-edges');
 testImageRendering('optimizespeed', 'optimizespeed');
 testImageRendering('optimizequality', 'optimizequality');
 
diff --git a/LayoutTests/svg/css/script-tests/shape-rendering-parsing.js b/LayoutTests/svg/css/script-tests/shape-rendering-parsing.js
new file mode 100644 (file)
index 0000000..f0c8374
--- /dev/null
@@ -0,0 +1,24 @@
+description("Tests the parsing of shape-rendering property values")
+createSVGTestCase();
+
+var group = createSVGElement("g");
+rootSVGElement.appendChild(group);
+
+// Test initial value of font-length.
+shouldBeEqualToString("document.defaultView.getComputedStyle(group, null).shapeRendering", "auto");
+
+group.setAttribute("shape-rendering", "crispEdges");
+shouldBeEqualToString("document.defaultView.getComputedStyle(group, null).shapeRendering", "crispedges");
+
+group.setAttribute("shape-rendering", "crispedges");
+shouldBeEqualToString("document.defaultView.getComputedStyle(group, null).shapeRendering", "crispedges");
+
+group.setAttribute("shape-rendering", "optimizeSpeed");
+shouldBeEqualToString("document.defaultView.getComputedStyle(group, null).shapeRendering", "optimizespeed");
+
+group.setAttribute("shape-rendering", "geometricPrecision");
+shouldBeEqualToString("document.defaultView.getComputedStyle(group, null).shapeRendering", "geometricprecision");
+
+var successfullyParsed = true;
+
+completeTest();
diff --git a/LayoutTests/svg/css/shape-rendering-parsing-expected.txt b/LayoutTests/svg/css/shape-rendering-parsing-expected.txt
new file mode 100644 (file)
index 0000000..9b2190d
--- /dev/null
@@ -0,0 +1,14 @@
+Tests the parsing of shape-rendering property values
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.defaultView.getComputedStyle(group, null).shapeRendering is "auto"
+PASS document.defaultView.getComputedStyle(group, null).shapeRendering is "crispedges"
+PASS document.defaultView.getComputedStyle(group, null).shapeRendering is "crispedges"
+PASS document.defaultView.getComputedStyle(group, null).shapeRendering is "optimizespeed"
+PASS document.defaultView.getComputedStyle(group, null).shapeRendering is "geometricprecision"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/css/shape-rendering-parsing.html b/LayoutTests/svg/css/shape-rendering-parsing.html
new file mode 100644 (file)
index 0000000..5aa0c03
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../svg/dynamic-updates/resources/SVGTestCase.js"></script>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/shape-rendering-parsing.js"></script>
+</body>
+</html>
index a1de966..f958286 100644 (file)
@@ -1,3 +1,39 @@
+2016-01-27  Simon Fraser  <simon.fraser@apple.com>
+
+        Support CSS3 Images values for the image-rendering property
+        https://bugs.webkit.org/show_bug.cgi?id=153556
+
+        Reviewed by Dean Jackson.
+
+        CSS3 Images has the following values for image-rendering:
+            auto, crisp-edges, pixelated
+
+        The old code supported:
+            optimizeSpeed, optimizeQuality, -webkit-crisp-edges, -webkit-optimize-contrast
+
+        Add support for the new values without prefixes. Map -webkit-crisp-edges to crisp-edges,
+        and -webkit-optimize-contrast to crisp-edges. Support pixelated which behaves like 
+        crisp-edges (a low quality scale).
+
+        The spec says that optimizeQuality should behave like 'auto', but that would be
+        a behavior change since ImageQualityController::shouldPaintAtLowQuality() currently
+        uses it as a trigger to avoid low quality scaling, so don't change that for now.
+
+        No new tests, covered by fast/css/script-tests/image-rendering-parsing.js
+
+        * css/CSSParser.cpp:
+        (WebCore::isValidKeywordPropertyAndValue):
+        * css/CSSPrimitiveValueMappings.h:
+        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+        (WebCore::CSSPrimitiveValue::operator EImageRendering):
+        * css/CSSValueKeywords.in:
+        * rendering/ImageQualityController.cpp:
+        (WebCore::ImageQualityController::shouldPaintAtLowQuality):
+        * rendering/RenderHTMLCanvas.cpp:
+        (WebCore::RenderHTMLCanvas::paintReplaced):
+        * rendering/style/RenderStyleConstants.h:
+        * rendering/style/StyleRareInheritedData.h: Need another bit.
+
 2016-01-27  Anders Carlsson  <andersca@apple.com>
 
         Add WebKitAdditions extension points to WebCore, WebKit and WebKitLegacy
index 88be5a7..ad77ae7 100644 (file)
@@ -706,9 +706,10 @@ static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int
         if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique)
             return true;
         break;
-    case CSSPropertyImageRendering: // auto | optimizeSpeed | optimizeQuality | -webkit-crisp-edges | -webkit-optimize-contrast
+    case CSSPropertyImageRendering: // auto | optimizeSpeed | optimizeQuality | -webkit-crisp-edges | -webkit-optimize-contrast | crisp-edges | pixelated
+        // optimizeSpeed and optimizeQuality are deprecated; a user agent must accept them as valid values but must treat them as having the same behavior as pixelated and auto respectively.
         if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizequality
-            || valueID == CSSValueWebkitCrispEdges || valueID == CSSValueWebkitOptimizeContrast)
+            || valueID == CSSValueWebkitCrispEdges || valueID == CSSValueWebkitOptimizeContrast || valueID == CSSValueCrispEdges || valueID == CSSValuePixelated)
             return true;
         break;
     case CSSPropertyListStylePosition: // inside | outside | inherit
index 52838d5..67aad2b 100644 (file)
@@ -4321,16 +4321,19 @@ template<> inline CSSPrimitiveValue::operator EBorderFit() const
     return BorderFitLines;
 }
 
-template<> inline CSSPrimitiveValue::CSSPrimitiveValue(EImageRendering e)
+template<> inline CSSPrimitiveValue::CSSPrimitiveValue(EImageRendering imageRendering)
     : CSSValue(PrimitiveClass)
 {
     m_primitiveUnitType = CSS_VALUE_ID;
-    switch (e) {
+    switch (imageRendering) {
     case ImageRenderingAuto:
         m_value.valueID = CSSValueAuto;
         break;
     case ImageRenderingCrispEdges:
-        m_value.valueID = CSSValueWebkitCrispEdges;
+        m_value.valueID = CSSValueCrispEdges;
+        break;
+    case ImageRenderingPixelated:
+        m_value.valueID = CSSValuePixelated;
         break;
     case ImageRenderingOptimizeSpeed:
         m_value.valueID = CSSValueOptimizespeed;
@@ -4349,8 +4352,11 @@ template<> inline CSSPrimitiveValue::operator EImageRendering() const
     case CSSValueAuto:
         return ImageRenderingAuto;
     case CSSValueWebkitOptimizeContrast:
+    case CSSValueCrispEdges:
     case CSSValueWebkitCrispEdges:
         return ImageRenderingCrispEdges;
+    case CSSValuePixelated:
+        return ImageRenderingPixelated;
     case CSSValueOptimizespeed:
         return ImageRenderingOptimizeSpeed;
     case CSSValueOptimizequality:
index 860c474..ae5ec2c 100644 (file)
@@ -1050,8 +1050,10 @@ off
 
 // image-rendering
 // auto
-// optimizeSpeed
-optimizeQuality
+// optimizeSpeed (deprecated)
+optimizeQuality // ( deprecated)
+crisp-edges
+pixelated
 -webkit-crisp-edges
 -webkit-optimize-contrast
 
index a0c2114..be0d94a 100644 (file)
@@ -109,9 +109,10 @@ bool ImageQualityController::shouldPaintAtLowQuality(GraphicsContext& context, R
     switch (object->style().imageRendering()) {
     case ImageRenderingOptimizeSpeed:
     case ImageRenderingCrispEdges:
+    case ImageRenderingPixelated:
         return true;
     case ImageRenderingOptimizeQuality:
-        return false;
+        return false; // FIXME: CSS 3 Images says that optimizeQuality should behave like 'auto', but that prevents authors from overriding this low quality rendering behavior.
     case ImageRenderingAuto:
         break;
     }
index eee7440..37b588f 100644 (file)
@@ -84,7 +84,7 @@ void RenderHTMLCanvas::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& pa
             page->addRelevantRepaintedObject(this, intersection(replacedContentRect, contentBoxRect));
     }
 
-    bool useLowQualityScale = style().imageRendering() == ImageRenderingCrispEdges || style().imageRendering() == ImageRenderingOptimizeSpeed;
+    bool useLowQualityScale = style().imageRendering() == ImageRenderingCrispEdges || style().imageRendering() == ImageRenderingPixelated || style().imageRendering() == ImageRenderingOptimizeSpeed;
     canvasElement().paint(context, replacedContentRect, useLowQualityScale);
 }
 
index 37bb969..4bbb008 100644 (file)
@@ -593,7 +593,13 @@ enum class TextOrientation { Mixed, Upright, Sideways };
 
 enum TextOverflow { TextOverflowClip = 0, TextOverflowEllipsis };
 
-enum EImageRendering { ImageRenderingAuto = 0, ImageRenderingOptimizeSpeed, ImageRenderingOptimizeQuality, ImageRenderingCrispEdges };
+enum EImageRendering {
+    ImageRenderingAuto = 0,
+    ImageRenderingOptimizeSpeed,
+    ImageRenderingOptimizeQuality,
+    ImageRenderingCrispEdges,
+    ImageRenderingPixelated
+};
 
 enum ImageResolutionSource { ImageResolutionSpecified = 0, ImageResolutionFromImage };
 
index bf4021f..a52e718 100644 (file)
@@ -110,7 +110,7 @@ public:
 #if ENABLE(CSS_IMAGE_ORIENTATION)
     unsigned m_imageOrientation : 4; // ImageOrientationEnum
 #endif
-    unsigned m_imageRendering : 2; // EImageRendering
+    unsigned m_imageRendering : 3; // EImageRendering
     unsigned m_lineSnap : 2; // LineSnap
     unsigned m_lineAlign : 1; // LineAlign
 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
index c8c8317..fa755c4 100644 (file)
@@ -1,3 +1,14 @@
+2016-01-27  Simon Fraser  <simon.fraser@apple.com>
+
+        Support CSS3 Images values for the image-rendering property
+        https://bugs.webkit.org/show_bug.cgi?id=153556
+
+        Reviewed by Dean Jackson.
+
+        Add "crisp-edges", "pixelated" to the suggestions for image-rendering.
+
+        * UserInterface/Models/CSSKeywordCompletions.js:
+
 2016-01-26  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Remove unused FramesLarge.png variants, only the smaller Frames icon is used for the Rendering Frames timeline
index cbf6851..77df1f6 100644 (file)
@@ -392,7 +392,7 @@ WebInspector.CSSKeywordCompletions._propertyKeywordMap = {
         "flex", "inline-flex", "-webkit-grid", "-webkit-inline-grid"
     ],
     "image-rendering": [
-        "auto", "optimizeSpeed", "optimizeQuality", "-webkit-crisp-edges", "-webkit-optimize-contrast"
+        "auto", "optimizeSpeed", "optimizeQuality", "-webkit-crisp-edges", "-webkit-optimize-contrast", "crisp-edges", "pixelated"
     ],
     "alignment-baseline": [
         "baseline", "middle", "auto", "before-edge", "after-edge", "central", "text-before-edge", "text-after-edge",