Support the ch unit from css3-values
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 21:18:49 +0000 (21:18 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 21:18:49 +0000 (21:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=85755

Patch by Lamarque V. Souza <Lamarque.Souza@basyskom.com> on 2013-02-14
Reviewed by David Hyatt.

Original patch by Sumedha Widyadharma <sumedha.widyadharma@basyskom.com>.

Source/WebCore:

Test: fast/css/css3-ch-unit.html

* css/CSSCalculationValue.cpp:
(WebCore::unitCategory):
* css/CSSGrammar.y.in:
* css/CSSParser.cpp:
(WebCore::CSSParser::validUnit):
(WebCore::CSSParser::createPrimitiveNumericValue):
(WebCore::CSSParser::parseValidPrimitive):
(WebCore::CSSParser::detectNumberToken):
* css/CSSParserValues.cpp:
(WebCore::CSSParserValue::createCSSValue):
* css/CSSPrimitiveValue.cpp:
(WebCore::isValidCSSUnitTypeForDoubleConversion):
(WebCore::CSSPrimitiveValue::cleanup):
(WebCore::CSSPrimitiveValue::computeLengthDouble):
(WebCore::CSSPrimitiveValue::customCssText):
(WebCore::CSSPrimitiveValue::cloneForCSSOM):
* css/CSSPrimitiveValue.h:
(WebCore::CSSPrimitiveValue::isFontRelativeLength):
(WebCore::CSSPrimitiveValue::isLength):
* platform/graphics/FontMetrics.h:
(WebCore::FontMetrics::FontMetrics):
(WebCore::FontMetrics::zeroWidth):
(WebCore::FontMetrics::setZeroWidth):
(FontMetrics):
(WebCore::FontMetrics::hasZeroWidth):
(WebCore::FontMetrics::setHasZeroWidth):
* platform/graphics/SimpleFontData.cpp:
(WebCore::SimpleFontData::platformGlyphInit):
* platform/graphics/SimpleFontData.h:
(WebCore::SimpleFontData::zeroGlyph):
(WebCore::SimpleFontData::setZeroGlyph):
(SimpleFontData):
* platform/graphics/qt/SimpleFontDataQt.cpp:
(WebCore::SimpleFontData::platformInit):

LayoutTests:

* fast/css/css3-ch-unit-expected.txt: Added.
* fast/css/css3-ch-unit.html: Added.

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

14 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/css3-ch-unit-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/css3-ch-unit.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSCalculationValue.cpp
Source/WebCore/css/CSSGrammar.y.in
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParserValues.cpp
Source/WebCore/css/CSSPrimitiveValue.cpp
Source/WebCore/css/CSSPrimitiveValue.h
Source/WebCore/platform/graphics/FontMetrics.h
Source/WebCore/platform/graphics/SimpleFontData.cpp
Source/WebCore/platform/graphics/SimpleFontData.h
Source/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp

index 1afe1031f67aaf2ded55f6ae408b99e98c138cd7..8117d72974592e7bfd7ee4d37529ba3844abbd32 100644 (file)
@@ -1,3 +1,15 @@
+2013-02-14  Lamarque V. Souza  <Lamarque.Souza@basyskom.com>
+
+        Support the ch unit from css3-values
+        https://bugs.webkit.org/show_bug.cgi?id=85755
+
+        Reviewed by David Hyatt.
+
+        Original patch by Sumedha Widyadharma <sumedha.widyadharma@basyskom.com>.
+
+        * fast/css/css3-ch-unit-expected.txt: Added.
+        * fast/css/css3-ch-unit.html: Added.
+
 2013-02-14  Philip Rogers  <pdr@google.com>
 
         Prevent inconsistent firstChild during document destruction
diff --git a/LayoutTests/fast/css/css3-ch-unit-expected.txt b/LayoutTests/fast/css/css3-ch-unit-expected.txt
new file mode 100644 (file)
index 0000000..f87dc94
--- /dev/null
@@ -0,0 +1,52 @@
+This is a test to make sure ch units work as intended.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.getElementById("box_mono_zero").clientWidth is 0
+PASS document.getElementById("box_mono_four1").clientWidth is document.getElementById("box_mono_four2").clientWidth
+PASS document.getElementById("box_monofallthrough_four1").clientWidth is document.getElementById("box_monofallthrough_four2").clientWidth
+PASS document.getElementById("mono_box_alphalen1").clientWidth is document.getElementById("mono_box_alphalen2").clientWidth
+PASS document.getElementById("box_one").clientWidth * 26 is document.getElementById("box_alphalen").clientWidth
+PASS document.getElementById("arial_box_one").clientWidth * 26 is document.getElementById("arial_box_alphalen").clientWidth
+PASS document.getElementById("helvetica_box_one").clientWidth * 26 is document.getElementById("helvetica_box_alphalen").clientWidth
+PASS document.getElementById("times_box_one").clientWidth * 4 is document.getElementById("box_times_four").clientWidth
+PASS document.getElementById("arial_box_one").clientWidth * 4 is document.getElementById("box_arial_four").clientWidth
+PASS document.getElementById("helvetica_box_one").clientWidth * 4 is document.getElementById("box_helvetica_four").clientWidth
+PASS document.getElementById("ref_box_arial_one").clientWidth is >= document.getElementById("box_arial_one").clientWidth
+PASS document.getElementById("ref_box_times_one").clientWidth is >= document.getElementById("box_times_one").clientWidth
+PASS document.getElementById("ref_box_sansserif_one").clientWidth is >= document.getElementById("box_sansserif_one").clientWidth
+PASS w1 !== w2 || h1 !== h2 is false
+PASS ps1h > ps2h && ps1h > ps3h is true
+PASS document.getElementById("box_mono_one").clientWidth is document.getElementById("box_mono").clientWidth
+PASS successfullyParsed is true
+
+TEST COMPLETE
+This is a test to make sure ch units work as intended. You should not see anything red on this page.
+
+Only 'PASS' should be visible:
+PASS
+PASS
+PASS
+PASS
+The whole lower case alphabet should be readable:
+abcdefghijklmnopqrstuvwxyz
+abcdefghijklmnopqrstuvwxyz
+abcdefghijklmnopqrstuvwxyz
+abcdefghijklmnopqrstuvwxyz
+abcdefghijklmnopqrstuvwxyz
+Four zeroes should be visible, nothing else:
+0000
+0000
+0000 There should be more than one green '|' visible (non-monospaced fonts):
+|||0|||
+|||0|||
+|||0|||
+This box has a 20px font size. The last two '0's should be the same size.
+0
+0
+0
+I'm a pseudo selected first line, I should be bigger than the rest.
+I'm the second line.
+Last in line. But one day... the throne will be mine!
+0
diff --git a/LayoutTests/fast/css/css3-ch-unit.html b/LayoutTests/fast/css/css3-ch-unit.html
new file mode 100644 (file)
index 0000000..050425c
--- /dev/null
@@ -0,0 +1,184 @@
+<!doctype html>
+<html>
+<head>
+<style type="text/css" title="teste">
+    .box {
+        margin: 0px;
+        padding: 0px;
+        overflow: hidden;
+    }
+    .border { border:1px solid black; }
+
+    /* font family classes */
+    .mono { font-family: monospace; }
+    .monofallthrough { font-family: nonexistant, monospace; }
+    .serif { font-family: serif; }
+    .sans-serif { font-family: sans-serif; }
+    .courier { font-family: courier; }
+    .arial { font-family: arial; }
+    .times { font-family: times; }
+    .helvetica { font-family: helvetica; }
+
+    /* ch-length containers */
+    .one { width: 1ch; }
+    .four { width: 4ch; }
+    .zero { width: 0ch; }
+    .alphalen { width: 26ch; }
+
+    /* font sizes for the relative size test */
+    .large { font-size:20px; }
+    .relative { font-size:1ch; }
+
+    /* pass/fail colors */
+    .pass { color: green; }
+    .fail { color: red; }
+
+    /* pseudo-elements */
+    #pseudo{
+        font-size:2ch;
+    }
+    #pseudo:first-line {
+        font-size:3ch;
+    }
+    #pseudo span:last-child {
+        font-size:1ch;
+    }
+</style>
+<script src="../js/resources/js-test-pre.js"></script>
+<script type="text/javascript">
+</script>
+</head>
+<body id="body">
+    <p>This is a test to make sure ch units work as intended. You should not see <b>anything</b> red on this page.</p>
+    Only 'PASS' should be visible:
+    <div id="box_mono_zero" class="box mono zero"></div>
+    <script type="text/javascript">
+        description("This is a test to make sure ch units work as intended.")
+        shouldEvaluateTo('document.getElementById("box_mono_zero").clientWidth', "0");
+    </script>
+
+    <div id="box_mono_four1" class="box mono four"><span class="pass">PASS</span><span class="fail">FAIL</span></div>
+    <div id="box_mono_four2" class="box mono four"><span class="pass">PASS</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("box_mono_four1").clientWidth', 'document.getElementById("box_mono_four2").clientWidth');
+    </script>
+
+    <div id="box_monofallthrough_four1" class="box monofallthrough four"><span class="pass">PASS</span><span class="fail">FAIL</span></div>
+    <div id="box_monofallthrough_four2" class="box monofallthrough four"><span class="pass">PASS</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("box_monofallthrough_four1").clientWidth', 'document.getElementById("box_monofallthrough_four2").clientWidth');
+    </script>
+
+    The whole lower case alphabet should be readable:
+    <div id="mono_box_alphalen1" class="mono box alphalen"><span class="pass">abcdefghijklmnopqrstuvwxyz</span><span class="fail">FAIL</span></div>
+    <div id="mono_box_alphalen2" class="mono box alphalen"><span class="pass">abcdefghijklmnopqrstuvwxyz</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("mono_box_alphalen1").clientWidth', 'document.getElementById("mono_box_alphalen2").clientWidth');
+    </script>
+
+    <div id="box_one" class="box one"></div>
+    <div id="box_alphalen" class="box alphalen"><span class="pass">abcdefghijklmnopqrstuvwxyz</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("box_one").clientWidth * 26', 'document.getElementById("box_alphalen").clientWidth');
+    </script>
+
+    <div id="arial_box_one" class="arial box one"></div>
+    <div id="arial_box_alphalen" class="arial box alphalen"><span class="pass">abcdefghijklmnopqrstuvwxyz</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("arial_box_one").clientWidth * 26', 'document.getElementById("arial_box_alphalen").clientWidth');
+    </script>
+
+    <div id="helvetica_box_one" class="helvetica box one"></div>
+    <div id="helvetica_box_alphalen" class="helvetica box alphalen"><span class="pass">abcdefghijklmnopqrstuvwxyz</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("helvetica_box_one").clientWidth * 26', 'document.getElementById("helvetica_box_alphalen").clientWidth');
+    </script>
+
+    Four zeroes should be visible, nothing else:
+    <div id="times_box_one" class="times box one"></div>
+    <div id="box_times_four" class="box times four"><span class="pass">0000</span><span class="fail">FAIL</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("times_box_one").clientWidth * 4', 'document.getElementById("box_times_four").clientWidth');
+    </script>
+
+    <div id="box_arial_four" class="box arial four"><span class="pass">0000</span><span class="fail">FAIL</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("arial_box_one").clientWidth * 4', 'document.getElementById("box_arial_four").clientWidth');
+    </script>
+
+    <div id="box_helvetica_four" class="box helvetica four"><span class="pass">0000</span><span class="fail">FAIL</span></div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("helvetica_box_one").clientWidth * 4', 'document.getElementById("box_helvetica_four").clientWidth');
+    </script>
+
+    There should be more than one green '|' visible (non-monospaced fonts):
+    <div id="box_arial_one" class="box arial one"><span class="pass">|</span><span class="pass">||0</span><span class="fail">||||</span></div>
+    <div id="ref_box_arial_one" class="box arial" style="display:inline-block"><span class="pass">|</span><span class="pass">||</span></div>
+    <script type="text/javascript">
+        shouldBeGreaterThanOrEqual('document.getElementById("ref_box_arial_one").clientWidth', 'document.getElementById("box_arial_one").clientWidth');
+    </script>
+
+    <div id="box_times_one" class="box times one"><span class="pass">|</span><span class="pass">||0</span><span class="fail">||||</span></div>
+    <div id="ref_box_times_one" class="box times" style="display:inline-block"><span class="pass">|</span><span class="pass">||</span></div>
+    <script type="text/javascript">
+        shouldBeGreaterThanOrEqual('document.getElementById("ref_box_times_one").clientWidth', 'document.getElementById("box_times_one").clientWidth');
+    </script>
+
+    <div id="box_sansserif_one" class="box sansserif one"><span class="pass">|</span><span class="pass">||0</span><span class="fail">||||</span></div>
+    <div id="ref_box_sansserif_one" class="box times" style="display:inline-block"><span class="pass">|</span><span class="pass">||</span></div>
+    <script type="text/javascript">
+        shouldBeGreaterThanOrEqual('document.getElementById("ref_box_sansserif_one").clientWidth', 'document.getElementById("box_sansserif_one").clientWidth');
+    </script>
+
+    <div class="border">
+        This box has a 20px font size.
+        The last two '0's should be the same size.
+        <div class="large pass">
+            <div id="reference" class="one">0</div>
+            <div id="forcedsmall" class="box one">0</div>
+            <div id="chsmall" class="box one relative">0</div>
+        </div>
+        <script type="text/javascript">
+            var ref = document.getElementById("reference");
+            var refWidth = ref.clientWidth;
+            var small = document.getElementById("forcedsmall");
+            small.style.fontSize = refWidth +"px";
+            var w1 = small.clientWidth;
+            var h1 = small.clientHeight;
+            var chsmall = document.getElementById("chsmall");
+            var w2 = chsmall.clientWidth;
+            var h2 = chsmall.clientHeight;
+            shouldBeFalse("w1 !== w2 || h1 !== h2");
+        </script>
+    </div>
+    <div id="pseudo">
+        <span id="ps1">I'm a pseudo selected first line, I should be bigger than the rest.</span><br>
+        <span id="ps2">I'm the second line.</span><br>
+        <span id="ps3">Last in line. But one day... the throne will be mine!</span>
+    </div>
+    <script>
+        var ps1h = document.getElementById('ps1').offsetHeight;
+        var ps2h = document.getElementById('ps2').offsetHeight;
+        var ps3h = document.getElementById('ps3').offsetHeight;
+        shouldBeTrue("ps1h > ps2h && ps1h > ps3h");
+    </script>
+
+    <div id="box_mono_one" class="box mono one"></div>
+    <div id="box_mono" class="box mono" style="display:inline-block">0</div>
+    <script type="text/javascript">
+        shouldEvaluateTo('document.getElementById("box_mono_one").clientWidth', 'document.getElementById("box_mono").clientWidth');
+    </script>
+    <script src="../js/resources/js-test-post.js"></script>
+    <script>
+        // Text with '<span class="fail">' must not appear in DumpRenderTree's output, only when opening this file in a web browser.
+        if (window.testRunner) {
+            var CSSRules = 'rules';
+            for (var i = 0; i < document.styleSheets[0][CSSRules].length; ++i)
+                if (document.styleSheets[0][CSSRules][i].selectorText === ".fail") {
+                    document.styleSheets[0][CSSRules][i].style['display'] = 'none';
+                    break;
+                }
+        }
+    </script>
+</body>
+</html>
index e20d14d5fe7743146f00d1834d88355fef19cc70..f8d507f27cafbd3e4289ecac93c01ac1e23d7005 100644 (file)
@@ -1,3 +1,49 @@
+2013-02-14  Lamarque V. Souza  <Lamarque.Souza@basyskom.com>
+
+        Support the ch unit from css3-values
+        https://bugs.webkit.org/show_bug.cgi?id=85755
+
+        Reviewed by David Hyatt.
+
+        Original patch by Sumedha Widyadharma <sumedha.widyadharma@basyskom.com>.
+
+        Test: fast/css/css3-ch-unit.html
+
+        * css/CSSCalculationValue.cpp:
+        (WebCore::unitCategory):
+        * css/CSSGrammar.y.in:
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::validUnit):
+        (WebCore::CSSParser::createPrimitiveNumericValue):
+        (WebCore::CSSParser::parseValidPrimitive):
+        (WebCore::CSSParser::detectNumberToken):
+        * css/CSSParserValues.cpp:
+        (WebCore::CSSParserValue::createCSSValue):
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::isValidCSSUnitTypeForDoubleConversion):
+        (WebCore::CSSPrimitiveValue::cleanup):
+        (WebCore::CSSPrimitiveValue::computeLengthDouble):
+        (WebCore::CSSPrimitiveValue::customCssText):
+        (WebCore::CSSPrimitiveValue::cloneForCSSOM):
+        * css/CSSPrimitiveValue.h:
+        (WebCore::CSSPrimitiveValue::isFontRelativeLength):
+        (WebCore::CSSPrimitiveValue::isLength):
+        * platform/graphics/FontMetrics.h:
+        (WebCore::FontMetrics::FontMetrics):
+        (WebCore::FontMetrics::zeroWidth):
+        (WebCore::FontMetrics::setZeroWidth):
+        (FontMetrics):
+        (WebCore::FontMetrics::hasZeroWidth):
+        (WebCore::FontMetrics::setHasZeroWidth):
+        * platform/graphics/SimpleFontData.cpp:
+        (WebCore::SimpleFontData::platformGlyphInit):
+        * platform/graphics/SimpleFontData.h:
+        (WebCore::SimpleFontData::zeroGlyph):
+        (WebCore::SimpleFontData::setZeroGlyph):
+        (SimpleFontData):
+        * platform/graphics/qt/SimpleFontDataQt.cpp:
+        (WebCore::SimpleFontData::platformInit):
+
 2013-02-14  David Kilzer  <ddkilzer@apple.com>
 
         [Mac] Clean up WARNING_CFLAGS
index 5faa8f6058c0b5c9dbd36ed8a90cf108a11a3ee1..239c99d2c4ff2381386f50ed5930b788416aa454 100644 (file)
@@ -67,6 +67,7 @@ static CalculationCategory unitCategory(CSSPrimitiveValue::UnitTypes type)
     case CSSPrimitiveValue::CSS_PT:
     case CSSPrimitiveValue::CSS_PC:
     case CSSPrimitiveValue::CSS_REMS:
+    case CSSPrimitiveValue::CSS_CHS:
         return CalcLength;
 #if ENABLE(CSS_VARIABLES)
     case CSSPrimitiveValue::CSS_VARIABLE_NAME:
index f464e603713e71cffe5eeb7966ada25717620b32..689bc77c21797f78bec1951e9ba8fec0c3f5b2b9 100644 (file)
@@ -62,9 +62,9 @@ static inline int cssyyerror(void*, const char*)
 %}
 
 #if ENABLE_SHADOW_DOM
-%expect 67
+%expect 68
 #else
-%expect 66
+%expect 67
 #endif
 
 %nonassoc LOWEST_PREC
@@ -151,6 +151,7 @@ static inline int cssyyerror(void*, const char*)
 #endif
 
 %token <number> REMS
+%token <number> CHS
 %token <number> QEMS
 %token <number> EMS
 %token <number> EXS
@@ -1751,6 +1752,7 @@ unary_term:
       if (parser->m_styleSheet)
           parser->m_styleSheet->parserSetUsesRemUnits(true);
   }
+  | CHS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_CHS; }
   | VW maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VW; }
   | VH maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VH; }
   | VMIN maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VMIN; }
index 088959d53beeaabfe2e31e30a108c765ea724775..8bfec5a2aa5a4b472088374f677ff56ec25e5455 100644 (file)
@@ -1601,6 +1601,7 @@ bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, CSSParserMode
     case CSSParserValue::Q_EMS:
     case CSSPrimitiveValue::CSS_EMS:
     case CSSPrimitiveValue::CSS_REMS:
+    case CSSPrimitiveValue::CSS_CHS:
     case CSSPrimitiveValue::CSS_EXS:
     case CSSPrimitiveValue::CSS_PX:
     case CSSPrimitiveValue::CSS_CM:
@@ -1656,12 +1657,12 @@ inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSP
 
 #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY)
     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_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
         || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
         || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM));
 #else
     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_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
         || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX));
 #endif
     return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
@@ -1718,7 +1719,7 @@ inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(int identifi
         return createPrimitiveStringValue(value);
     if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
         return createPrimitiveNumericValue(value);
-    if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS)
+    if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
         return createPrimitiveNumericValue(value);
     if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
         return createPrimitiveNumericValue(value);
@@ -9913,6 +9914,8 @@ inline void CSSParser::detectNumberToken(CharacterType* type, int length)
     case 'c':
         if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'm'))
             m_token = CMS;
+        else if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'h'))
+            m_token = CHS;
         return;
 
     case 'd':
index f0e5f3cff576dfc0d63da66dd26ae05dfab81cd0..7448f17219e8f3993156154c9d059231aea7207e 100644 (file)
@@ -114,6 +114,7 @@ PassRefPtr<CSSValue> CSSParserValue::createCSSValue()
     case CSSPrimitiveValue::CSS_VMAX:
     case CSSPrimitiveValue::CSS_TURN:
     case CSSPrimitiveValue::CSS_REMS:
+    case CSSPrimitiveValue::CSS_CHS:
         return CSSPrimitiveValue::create(fValue, primitiveUnit);
     case CSSPrimitiveValue::CSS_UNKNOWN:
     case CSSPrimitiveValue::CSS_DIMENSION:
index b3cee010a9a325b0fb70ad931a90edebb5fa2f76..84d6874da080188c170a503030def8e023f5d165 100644 (file)
@@ -88,6 +88,7 @@ static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit
     case CSSPrimitiveValue::CSS_PX:
     case CSSPrimitiveValue::CSS_RAD:
     case CSSPrimitiveValue::CSS_REMS:
+    case CSSPrimitiveValue::CSS_CHS:
     case CSSPrimitiveValue::CSS_S:
     case CSSPrimitiveValue::CSS_TURN:
     case CSSPrimitiveValue::CSS_VW:
@@ -425,6 +426,7 @@ void CSSPrimitiveValue::cleanup()
     case CSS_EMS:
     case CSS_EXS:
     case CSS_REMS:
+    case CSS_CHS:
     case CSS_PX:
     case CSS_CM:
     case CSS_MM:
@@ -545,6 +547,9 @@ double CSSPrimitiveValue::computeLengthDouble(RenderStyle* style, RenderStyle* r
             else
                 factor = 1.0;
             break;
+        case CSS_CHS:
+            factor = style->fontMetrics().zeroWidth();
+            break;
         case CSS_PX:
             factor = 1.0;
             break;
@@ -902,6 +907,9 @@ String CSSPrimitiveValue::customCssText() const
         case CSS_REMS:
             text = formatNumber(m_value.num, "rem");
             break;
+        case CSS_CHS:
+            text = formatNumber(m_value.num, "ch");
+            break;
         case CSS_PX:
             text = formatNumber(m_value.num, "px");
             break;
@@ -1229,6 +1237,7 @@ PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::cloneForCSSOM() const
     case CSS_EMS:
     case CSS_EXS:
     case CSS_REMS:
+    case CSS_CHS:
     case CSS_PX:
     case CSS_CM:
     case CSS_MM:
index 5fb406272527cff1edde3d0de3b862a9dd31bb80..18d23fae7b00b17534c74fc0727ba057c020f9be 100644 (file)
@@ -116,22 +116,23 @@ public:
         // These are from CSS3 Values and Units, but that isn't a finished standard yet
         CSS_TURN = 107,
         CSS_REMS = 108,
+        CSS_CHS = 109,
 
         // This is used internally for counter names (as opposed to counter values)
-        CSS_COUNTER_NAME = 109,
+        CSS_COUNTER_NAME = 110,
 
         // This is used by the CSS Exclusions draft
-        CSS_SHAPE = 110,
+        CSS_SHAPE = 111,
 
         // Used by border images.
-        CSS_QUAD = 111,
+        CSS_QUAD = 112,
 
-        CSS_CALC = 112,
-        CSS_CALC_PERCENTAGE_WITH_NUMBER = 113,
-        CSS_CALC_PERCENTAGE_WITH_LENGTH = 114,
+        CSS_CALC = 113,
+        CSS_CALC_PERCENTAGE_WITH_NUMBER = 114,
+        CSS_CALC_PERCENTAGE_WITH_LENGTH = 115,
 
 #if ENABLE(CSS_VARIABLES)
-        CSS_VARIABLE_NAME = 115,
+        CSS_VARIABLE_NAME = 116,
 #endif
     };
 
@@ -162,13 +163,16 @@ public:
     bool isFontIndependentLength() const { return m_primitiveUnitType >= CSS_PX && m_primitiveUnitType <= CSS_PC; }
     bool isFontRelativeLength() const
     {
-        return m_primitiveUnitType == CSS_EMS || m_primitiveUnitType == CSS_EXS || m_primitiveUnitType == CSS_REMS;
+        return m_primitiveUnitType == CSS_EMS
+            || m_primitiveUnitType == CSS_EXS
+            || m_primitiveUnitType == CSS_REMS
+            || m_primitiveUnitType == CSS_CHS;
     }
     bool isIdent() const { return m_primitiveUnitType == CSS_IDENT; }
     bool isLength() const
     {
         unsigned short type = primitiveType();
-        return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS;
+        return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type == CSS_CHS;
     }
     bool isNumber() const { return primitiveType() == CSS_NUMBER; }
     bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; }
index 7981d8eead53ad8eb92ffe7561341784fecbfe35..5142ffe2537821b8c84b6a9a7f6d88dde8ea5d4d 100644 (file)
@@ -36,7 +36,9 @@ public:
         , m_lineGap(0)
         , m_lineSpacing(0)
         , m_xHeight(0)
+        , m_zeroWidth(0)
         , m_hasXHeight(false)
+        , m_hasZeroWidth(false)
     {
     }
 
@@ -110,6 +112,16 @@ public:
         return ascent() == other.ascent() && descent() == other.descent() && lineGap() == other.lineGap();
     }
 
+    float zeroWidth() const { return m_zeroWidth; }
+    void setZeroWidth(float zeroWidth)
+    {
+        m_zeroWidth = zeroWidth;
+        m_hasZeroWidth = true;
+    }
+
+    bool hasZeroWidth() const { return m_hasZeroWidth; }
+    void setHasZeroWidth(bool hasZeroWidth) { m_hasZeroWidth = hasZeroWidth; }
+
 private:
     friend class SimpleFontData;
 
@@ -130,7 +142,9 @@ private:
     float m_lineGap;
     float m_lineSpacing;
     float m_xHeight;
+    float m_zeroWidth;
     bool m_hasXHeight;
+    bool m_hasZeroWidth;
 };
 
 static inline float scaleEmToUnits(float x, unsigned unitsPerEm)
index 65194f0120a5f9d9a9b54fa4dcaea3f9c2512c0f..1dded40ebdd4b3308902d9788d6f4d4b7b3c6118 100644 (file)
@@ -113,6 +113,7 @@ void SimpleFontData::platformGlyphInit()
         LOG_ERROR("Failed to get glyph page zero.");
         m_spaceGlyph = 0;
         m_spaceWidth = 0;
+        m_zeroGlyph = 0;
         m_adjustedSpaceWidth = 0;
         determinePitch();
         m_zeroWidthSpaceGlyph = 0;
@@ -129,6 +130,8 @@ void SimpleFontData::platformGlyphInit()
     m_spaceGlyph = glyphPageZero->glyphDataForCharacter(' ').glyph;
     float width = widthForGlyph(m_spaceGlyph);
     m_spaceWidth = width;
+    m_zeroGlyph = glyphPageZero->glyphDataForCharacter('0').glyph;
+    m_fontMetrics.setZeroWidth(widthForGlyph(m_zeroGlyph));
     determinePitch();
     m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(width) : roundf(width);
 
index 97ea5a20190bdf8c411664456fdf861dab5be94d..bd3de670a6ebddb3df19bc7c2932c9f4d413c1dd 100644 (file)
@@ -160,6 +160,8 @@ public:
     Glyph zeroWidthSpaceGlyph() const { return m_zeroWidthSpaceGlyph; }
     void setZeroWidthSpaceGlyph(Glyph spaceGlyph) { m_zeroWidthSpaceGlyph = spaceGlyph; }
     bool isZeroWidthSpaceGlyph(Glyph glyph) const { return glyph == m_zeroWidthSpaceGlyph && glyph; }
+    Glyph zeroGlyph() const { return m_zeroGlyph; }
+    void setZeroGlyph(Glyph zeroGlyph) { m_zeroGlyph = zeroGlyph; }
 
     virtual const SimpleFontData* fontDataForCharacter(UChar32) const;
     virtual bool containsCharacters(const UChar*, int length) const;
@@ -280,6 +282,7 @@ private:
     
     Glyph m_spaceGlyph;
     float m_spaceWidth;
+    Glyph m_zeroGlyph;
     float m_adjustedSpaceWidth;
 
     Glyph m_zeroWidthSpaceGlyph;
index 44099b3eb2c198dc410bd76cf2fd0e26715f0908..dc9ea9223a1b780eb19c90db70fc215dbc36ffd9 100644 (file)
@@ -88,6 +88,10 @@ void SimpleFontData::platformInit()
     QVector<QPointF> advances = rawFont.advancesForGlyphIndexes(indexes);
     float spaceWidth = advances.at(0).x();
 
+    indexes = rawFont.glyphIndexesForString(QLatin1String("0"));
+    advances = rawFont.advancesForGlyphIndexes(indexes);
+    float zeroWidth = advances.at(0).x();
+
     // The line spacing should always be >= (ascent + descent), but this
     // may be false in some cases due to misbehaving platform libraries.
     // Workaround from SimpleFontPango.cpp and SimpleFontFreeType.cpp
@@ -104,6 +108,7 @@ void SimpleFontData::platformInit()
     m_fontMetrics.setLineSpacing(lineSpacing);
     m_fontMetrics.setXHeight(xHeight);
     m_fontMetrics.setLineGap(lineGap);
+    m_fontMetrics.setZeroWidth(zeroWidth);
     m_spaceWidth = spaceWidth;
 }