Add dpi to css3-images image-resolution
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jun 2012 13:04:21 +0000 (13:04 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jun 2012 13:04:21 +0000 (13:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=85439

Patch by David Barr <davidbarr@chromium.org> on 2012-06-13
Reviewed by Tony Chang.

Source/WebCore:

No new tests; extended fast/css/image-resolution/image-resolution.html

* css/CSSGrammar.y:
* css/CSSParser.cpp:
(WebCore::CSSParser::validUnit):
(WebCore::CSSParser::createPrimitiveNumericValue):
(WebCore::unitFromString):
(WebCore::CSSParser::parseValidPrimitive):
(WebCore::CSSParser::detectNumberToken):
* css/CSSPrimitiveValue.cpp:
(WebCore::isValidCSSUnitTypeForDoubleConversion):
(WebCore::unitCategory):
(WebCore::conversionToCanonicalUnitsScaleFactor):
(WebCore::CSSPrimitiveValue::customCssText):
(WebCore::CSSPrimitiveValue::cloneForCSSOM):
* css/CSSPrimitiveValue.h:

LayoutTests:

* fast/css/image-resolution/image-resolution-expected.txt:
* fast/css/image-resolution/image-resolution.html:

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

LayoutTests/ChangeLog
LayoutTests/fast/css/image-resolution/image-resolution-expected.txt
LayoutTests/fast/css/image-resolution/image-resolution.html
Source/WebCore/ChangeLog
Source/WebCore/css/CSSGrammar.y
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSPrimitiveValue.cpp
Source/WebCore/css/CSSPrimitiveValue.h

index 9c3f606..de937e7 100644 (file)
@@ -1,3 +1,13 @@
+2012-06-13  David Barr  <davidbarr@chromium.org>
+
+        Add dpi to css3-images image-resolution
+        https://bugs.webkit.org/show_bug.cgi?id=85439
+
+        Reviewed by Tony Chang.
+
+        * fast/css/image-resolution/image-resolution-expected.txt:
+        * fast/css/image-resolution/image-resolution.html:
+
 2012-06-13  Qi Zhang  <qi.2.zhang@nokia.com>
 
         [Qt] Add configure test for zlib and set WTF_USE_ZLIB if found
index 1a1f664..c4bdec2 100644 (file)
@@ -21,6 +21,40 @@ TEST "4dppx"
 PASS img.style.cssText is "image-resolution: 4dppx; "
 PASS img.offsetWidth is 4
 PASS img.offsetHeight is 4
+TEST "0dpi"
+PASS img.style.cssText is ""
+TEST "96dpi"
+PASS img.style.cssText is "image-resolution: 96dpi; "
+PASS img.offsetWidth is 16
+PASS img.offsetHeight is 16
+TEST "192dpi"
+PASS img.style.cssText is "image-resolution: 192dpi; "
+PASS img.offsetWidth is 8
+PASS img.offsetHeight is 8
+TEST "288dpi"
+PASS img.style.cssText is "image-resolution: 288dpi; "
+PASS img.offsetWidth is 5
+PASS img.offsetHeight is 5
+TEST "384dpi"
+PASS img.style.cssText is "image-resolution: 384dpi; "
+PASS img.offsetWidth is 4
+PASS img.offsetHeight is 4
+TEST "150dpi"
+PASS img.style.cssText is "image-resolution: 150dpi; "
+PASS img.offsetWidth is 10
+PASS img.offsetHeight is 10
+TEST "300dpi"
+PASS img.style.cssText is "image-resolution: 300dpi; "
+PASS img.offsetWidth is 5
+PASS img.offsetHeight is 5
+TEST "450dpi"
+PASS img.style.cssText is "image-resolution: 450dpi; "
+PASS img.offsetWidth is 3
+PASS img.offsetHeight is 3
+TEST "600dpi"
+PASS img.style.cssText is "image-resolution: 600dpi; "
+PASS img.offsetWidth is 2
+PASS img.offsetHeight is 2
 TEST ""
 PASS img.style.cssText is ""
 PASS successfullyParsed is true
index ecb5d27..f802db7 100644 (file)
@@ -59,7 +59,9 @@ description('Apply image-resolution property to a fixed image (' + dimensions +
 var img = document.createElement('img');
 img.src = imgUrl;
 
-var resolutions = ['0dppx', '1dppx', '2dppx', '3dppx', '4dppx', ''];
+var resolutions = ['0dppx', '1dppx', '2dppx', '3dppx', '4dppx',
+                   '0dpi', '96dpi', '192dpi', '288dpi', '384dpi',
+                   '150dpi', '300dpi', '450dpi', '600dpi', ''];
 
 img.onload = function() {
     resolutions.forEach(function(test) {
index 10e27c9..e46a126 100644 (file)
@@ -1,3 +1,27 @@
+2012-06-13  David Barr  <davidbarr@chromium.org>
+
+        Add dpi to css3-images image-resolution
+        https://bugs.webkit.org/show_bug.cgi?id=85439
+
+        Reviewed by Tony Chang.
+
+        No new tests; extended fast/css/image-resolution/image-resolution.html
+
+        * css/CSSGrammar.y:
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::validUnit):
+        (WebCore::CSSParser::createPrimitiveNumericValue):
+        (WebCore::unitFromString):
+        (WebCore::CSSParser::parseValidPrimitive):
+        (WebCore::CSSParser::detectNumberToken):
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::isValidCSSUnitTypeForDoubleConversion):
+        (WebCore::unitCategory):
+        (WebCore::conversionToCanonicalUnitsScaleFactor):
+        (WebCore::CSSPrimitiveValue::customCssText):
+        (WebCore::CSSPrimitiveValue::cloneForCSSOM):
+        * css/CSSPrimitiveValue.h:
+
 2012-06-13  Li Yin  <li.yin@intel.com>
 
         FileAPI: type should be converted to be lower case in Blob constructor.
index 688c995..bf6fc41 100644 (file)
@@ -101,7 +101,7 @@ static int cssyylex(YYSTYPE* yylval, void* parser)
 
 %}
 
-%expect 61
+%expect 62
 
 %nonassoc LOWEST_PREC
 
@@ -195,6 +195,7 @@ static int cssyylex(YYSTYPE* yylval, void* parser)
 %token <number> VH
 %token <number> VMIN
 %token <number> DPPX
+%token <number> DPI
 
 %token <string> URI
 %token <string> FUNCTION
@@ -1497,6 +1498,7 @@ unary_term:
   | VH maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VH; }
   | VMIN maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VMIN; }
   | DPPX maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPPX; }
+  | DPI maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPI; }
   ;
 
 function:
index a478b54..d56857b 100644 (file)
@@ -1369,6 +1369,7 @@ bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, CSSParserMode
         break;
 #if ENABLE(CSS_IMAGE_RESOLUTION)
     case CSSPrimitiveValue::CSS_DPPX:
+    case CSSPrimitiveValue::CSS_DPI:
         b = (unitflags & FResolution);
         break;
 #endif
@@ -1399,7 +1400,7 @@ inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSP
     ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
            || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
            || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMIN)
-           || (value->unit == CSSPrimitiveValue::CSS_DPPX));
+           || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPI));
 #else
     ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
            || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
@@ -1462,6 +1463,8 @@ static int unitFromString(CSSParserValue* value)
 #if ENABLE(CSS_IMAGE_RESOLUTION)
     if (equal(value->string, "dppx"))
         return CSSPrimitiveValue::CSS_DPPX;
+    if (equal(value->string, "dpi"))
+        return CSSPrimitiveValue::CSS_DPI;
 #endif
 
     return 0;
@@ -1517,7 +1520,7 @@ inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(int identifi
     if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMIN)
         return createPrimitiveNumericValue(value);
 #if ENABLE(CSS_IMAGE_RESOLUTION)
-    if (value->unit == CSSPrimitiveValue::CSS_DPPX)
+    if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPI)
         return createPrimitiveNumericValue(value);
 #endif
     if (value->unit >= CSSParserValue::Q_EMS)
@@ -8373,12 +8376,15 @@ inline void CSSParser::detectNumberToken(UChar* type, int length)
         if (length == 3 && isASCIIAlphaCaselessEqual(type[1], 'e') && isASCIIAlphaCaselessEqual(type[2], 'g'))
             m_token = DEGS;
 #if ENABLE(CSS_IMAGE_RESOLUTION)
-        // There is a discussion about the name of this unit on www-style.
-        // Keep this compile time guard in place until that is resolved.
-        // http://lists.w3.org/Archives/Public/www-style/2012May/0915.html
-        else if (length == 4 && isASCIIAlphaCaselessEqual(type[1], 'p')
-                 && isASCIIAlphaCaselessEqual(type[2], 'p') && isASCIIAlphaCaselessEqual(type[3], 'x'))
-            m_token = DPPX;
+        else if (length > 2 && isASCIIAlphaCaselessEqual(type[1], 'p')) {
+            // There is a discussion about the name of this unit on www-style.
+            // Keep this compile time guard in place until that is resolved.
+            // http://lists.w3.org/Archives/Public/www-style/2012May/0915.html
+            if (length == 4 && isASCIIAlphaCaselessEqual(type[2], 'p') && isASCIIAlphaCaselessEqual(type[3], 'x'))
+                m_token = DPPX;
+            else if (length == 3 && isASCIIAlphaCaselessEqual(type[2], 'i'))
+                m_token = DPI;
+        }
 #endif
         return;
 
index f207f16..b574b64 100644 (file)
@@ -62,6 +62,7 @@ static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit
     case CSSPrimitiveValue:: CSS_DIMENSION:
 #if ENABLE(CSS_IMAGE_RESOLUTION)
     case CSSPrimitiveValue:: CSS_DPPX:
+    case CSSPrimitiveValue:: CSS_DPI:
 #endif
     case CSSPrimitiveValue:: CSS_EMS:
     case CSSPrimitiveValue:: CSS_EXS:
@@ -90,6 +91,7 @@ static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit
     case CSSPrimitiveValue:: CSS_DASHBOARD_REGION:
 #if !ENABLE(CSS_IMAGE_RESOLUTION)
     case CSSPrimitiveValue:: CSS_DPPX:
+    case CSSPrimitiveValue:: CSS_DPI:
 #endif
     case CSSPrimitiveValue:: CSS_IDENT:
     case CSSPrimitiveValue:: CSS_PAIR:
@@ -148,6 +150,7 @@ static CSSPrimitiveValue::UnitCategory unitCategory(CSSPrimitiveValue::UnitTypes
         return CSSPrimitiveValue::UViewportPercentageLength;
 #if ENABLE(CSS_IMAGE_RESOLUTION)
     case CSSPrimitiveValue:: CSS_DPPX:
+    case CSSPrimitiveValue:: CSS_DPI:
         return CSSPrimitiveValue::UResolution;
 #endif
     default:
@@ -570,6 +573,9 @@ static double conversionToCanonicalUnitsScaleFactor(unsigned short unitType)
         case CSSPrimitiveValue::CSS_IN:
             factor = cssPixelsPerInch;
             break;
+        case CSSPrimitiveValue::CSS_DPI:
+            factor = 1 / cssPixelsPerInch;
+            break;
         case CSSPrimitiveValue::CSS_PT:
             factor = cssPixelsPerInch / 72.0;
             break;
@@ -855,6 +861,9 @@ String CSSPrimitiveValue::customCssText() const
         case CSS_DPPX:
             text = formatNumber(m_value.num) + "dppx";
             break;
+        case CSS_DPI:
+            text = formatNumber(m_value.num) + "dpi";
+            break;
 #endif
         case CSS_MM:
             text = formatNumber(m_value.num) + "mm";
@@ -1197,6 +1206,7 @@ PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::cloneForCSSOM() const
     case CSS_VMIN:
 #if ENABLE(CSS_IMAGE_RESOLUTION)
     case CSS_DPPX:
+    case CSS_DPI:
 #endif
         result = CSSPrimitiveValue::create(m_value.num, static_cast<UnitTypes>(m_primitiveUnitType));
         break;
index 02a5b86..6af1a89 100644 (file)
@@ -96,6 +96,7 @@ public:
         CSS_VH = 27,
         CSS_VMIN = 28,
         CSS_DPPX = 29,
+        CSS_DPI = 30,
         CSS_PAIR = 100, // We envision this being exposed as a means of getting computed style values for pairs (border-spacing/radius, background-position, etc.)
         CSS_DASHBOARD_REGION = 101, // FIXME: Dashboard region should not be a primitive value.
         CSS_UNICODE_RANGE = 102,