CSS word-spacing property does not obey percentages
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jan 2014 00:31:19 +0000 (00:31 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jan 2014 00:31:19 +0000 (00:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126674

Reviewed by Simon Fraser.

Source/WebCore:

One change between CSS2.1 and CSS3 is that the word-spacing CSS property can
take percentages (of the width of the space character) in CSS3. In order to
implement this, the datatype must be changed from a float to a Length, which
can hold percentage values. Then, during layout, we can query the width of
the space character and update the Font's word-spacing value appropriately.
However, the RenderStyle still holds on to the Length (as a rare inherited
value).

Tests: fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font.html
       fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse.html
       fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage.html

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue): Use Font's computed value instead
of style's Length value.
* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue): word-spacing and letter-spacing no longer are
parsed the same way.
* css/DeprecatedStyleBuilder.cpp:
(WebCore::ApplyPropertyWordSpacing::applyValue): Construct a length from a given
CSSValue and set the style's word spacing with it.
(WebCore::ApplyPropertyWordSpacing::createHandler):
(WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder): Use ApplyPropertyWordSpacing.
* page/animation/CSSPropertyAnimation.cpp:
(WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::setLogicalWidthForTextRun): Use Font's computed value instead
of style's Length value.
* rendering/RenderText.cpp:
(WebCore::RenderText::computePreferredLogicalWidths): Ditto.
* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseFor): Opt-out of the SimpleLineLayout
if either the percentage or the length is nonzero.
* rendering/line/BreakingContextInlineHeaders.h:
(WebCore::BreakingContext::handleText): Use Font's computed value instead
of style's Length value.
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::wordSpacing):
(WebCore::RenderStyle::setWordSpacing): Consult the Font's space with to compute
percentage values, but hold on to the original Length.
* rendering/style/RenderStyle.h:
* rendering/style/StyleRareInheritedData.cpp:
* rendering/style/StyleRareInheritedData.h: Hold on to the specified Length

LayoutTests:

See per-file description

* fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font-expected.html: Added.
* fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font.html: Added.
Make sure that if Javascript changes the font after initial layout, that the word-spacing
value gets appropriately updated.
* fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-expected.html: Added.
* fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse-expected.txt: Added.
* fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse.html: Added.
Make sure that the CSSOM yields the correct percentage values when queried.
* fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage.html: Added.
Try some specific values of percentages (-100%, 0%, and 100%).
* css1/text_properties/word_spacing.html: Updated to not disregard percentages
* css2.1/20110323/c541-word-sp-001-expected.html:
* css2.1/20110323/c541-word-sp-001.htm: Ditto
* platform/mac/css1/text_properties/word_spacing-expected.png:
* platform/mac/css1/text_properties/word_spacing-expected.txt: Ditto

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

25 files changed:
LayoutTests/ChangeLog
LayoutTests/css1/text_properties/word_spacing.html
LayoutTests/css2.1/20110323/c541-word-sp-001-expected.html
LayoutTests/css2.1/20110323/c541-word-sp-001.htm
LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font-expected.html [new file with mode: 0644]
LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font.html [new file with mode: 0644]
LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-expected.html [new file with mode: 0644]
LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse-expected.txt [new file with mode: 0644]
LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse.html [new file with mode: 0644]
LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage.html [new file with mode: 0644]
LayoutTests/platform/mac/css1/text_properties/word_spacing-expected.png
LayoutTests/platform/mac/css1/text_properties/word_spacing-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/DeprecatedStyleBuilder.cpp
Source/WebCore/page/animation/CSSPropertyAnimation.cpp
Source/WebCore/rendering/RenderBlockLineLayout.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/SimpleLineLayout.cpp
Source/WebCore/rendering/line/BreakingContextInlineHeaders.h
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/StyleRareInheritedData.cpp
Source/WebCore/rendering/style/StyleRareInheritedData.h

index e0331ca42ced31ae1c33e656516d4469aa463908..dc8eb593e0b1afea643083e4d6d0857e2a476ba0 100644 (file)
@@ -1,3 +1,28 @@
+2014-01-10  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        CSS word-spacing property does not obey percentages
+        https://bugs.webkit.org/show_bug.cgi?id=126674
+
+        Reviewed by Simon Fraser.
+
+        See per-file description
+
+        * fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font-expected.html: Added.
+        * fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font.html: Added.
+        Make sure that if Javascript changes the font after initial layout, that the word-spacing
+        value gets appropriately updated.
+        * fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-expected.html: Added.
+        * fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse-expected.txt: Added.
+        * fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse.html: Added.
+        Make sure that the CSSOM yields the correct percentage values when queried.
+        * fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage.html: Added.
+        Try some specific values of percentages (-100%, 0%, and 100%).
+        * css1/text_properties/word_spacing.html: Updated to not disregard percentages
+        * css2.1/20110323/c541-word-sp-001-expected.html:
+        * css2.1/20110323/c541-word-sp-001.htm: Ditto
+        * platform/mac/css1/text_properties/word_spacing-expected.png:
+        * platform/mac/css1/text_properties/word_spacing-expected.txt: Ditto
+
 2014-01-10  Dean Jackson  <dino@apple.com>
 
         Implement OES texture half float linear
index a1d70798adf74eda3137aed1b7e1c5ffd49d7c5f..1631dc4496737f861f04b3239b7444358aba8929 100644 (file)
@@ -16,8 +16,7 @@
 .seven {word-spacing: 1ex;}
 .eight {word-spacing: 5px;}
 .nine {word-spacing: normal;}
-.ten {word-spacing: 300%;}
-.eleven {word-spacing: -0.2em;}
+.ten {word-spacing: -0.2em;}
 </STYLE>
 
 </HEAD>
@@ -32,8 +31,7 @@
 .seven {word-spacing: 1ex;}
 .eight {word-spacing: 5px;}
 .nine {word-spacing: normal;}
-.ten {word-spacing: 300%;}
-.eleven {word-spacing: -0.2em;}
+.ten {word-spacing: -0.2em;}
 
 </PRE>
 <HR>
@@ -62,9 +60,6 @@ This words in this sentence should have extra space between them.
 This words in this sentence should have extra space between them, but the last few words in the sentence <SPAN class="nine">should have normal spacing</SPAN>.
 </P>
 <P class="ten">
-This sentence should have normal word-spacing, since percentage values are not allowed on this property.
-</P>
-<P class="eleven">
 This words in this sentence should have reduced space between them, since negative values are allowed on this property.
 </P>
 
@@ -100,9 +95,6 @@ This words in this sentence should have extra space between them.
 This words in this sentence should have extra space between them, but the last few words in the sentence <SPAN class="nine">should have normal spacing</SPAN>.
 </P>
 <P class="ten">
-This sentence should have normal word-spacing, since percentage values are not allowed on this property.
-</P>
-<P class="eleven">
 This words in this sentence should have reduced space between them, since negative values are allowed on this property.
 </P>
 </TD></TR></TABLE></BODY>
index a4e66c643ec949f8f49fe0733f1e9b32f5e0ce6b..66e8b3a997b5a6c4662ffe256232f0dd0aaa8247 100644 (file)
@@ -29,7 +29,7 @@
 
   <p>There should be a stripy pattern of yellow and aqua below (each vertical stripe should be straight and unbroken).</p>
 
-  <div><img src="support/swatch-yellow.png" width="50" height="150" alt="Image download support must be enabled" class="left-and-right-sides"><img src="support/swatch-yellow.png" width="50" height="150" alt="Image download support must be enabled" class="central"><img src="support/swatch-yellow.png" width="25" height="150" alt="Image download support must be enabled" class="central"><img src="support/swatch-yellow.png" width="25" height="150" alt="Image download support must be enabled" class="left-and-right-sides"></div>
+  <div><img src="support/swatch-yellow.png" width="50" height="125" alt="Image download support must be enabled" class="left-and-right-sides"><img src="support/swatch-yellow.png" width="50" height="125" alt="Image download support must be enabled" class="central"><img src="support/swatch-yellow.png" width="25" height="125" alt="Image download support must be enabled" class="central"><img src="support/swatch-yellow.png" width="25" height="125" alt="Image download support must be enabled" class="left-and-right-sides"></div>
 
  </body>
-</html>
\ No newline at end of file
+</html>
index 3d741dae57ea5fe7904bc2ce22ecbd989eb1cc66..2a2cffa39c7926c3aa8ba378516c866d5a06f91c 100644 (file)
@@ -12,8 +12,7 @@
    div { font: 25px/1 Ahem; width: 12em; background: yellow; color: aqua; margin: 0 0 0 2em; }
    .eight {word-spacing: 25px;}
    .nine {word-spacing: normal;}
-   .ten {word-spacing: 300%;}
-   .eleven {word-spacing: -1em;}
+   .ten {word-spacing: -1em;}
    .fill { color: yellow; }
   </style>
   <link rel="help" href="http://www.w3.org/TR/CSS21/text.html#spacing-props" title="16.4 Letter and word spacing: the 'letter-spacing' and 'word-spacing' properties">
@@ -24,7 +23,6 @@
   <div class="test">x&nbsp;&nbsp;x&nbsp;&nbsp;xx&nbsp;xx</div>
   <div class="test">x&nbsp;&nbsp;x&nbsp;&nbsp;xx&nbsp;xx</div>
   <div class="eight"> x x <span class="nine">xx xx</span> </div>
-  <div class="ten"> x&nbsp; x &nbsp;xx xx </div>
-  <div class="eleven"> x&nbsp; &nbsp;<span class="nine"> &nbsp;</span>x&nbsp;&nbsp;<span class="fill">xx</span> xx&nbsp; <span class="fill">x</span>xx </div>
+  <div class="ten"> x&nbsp; &nbsp;<span class="nine"> &nbsp;</span>x&nbsp;&nbsp;<span class="fill">xx</span> xx&nbsp; <span class="fill">x</span>xx </div>
  </body>
-</html>
\ No newline at end of file
+</html>
diff --git a/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font-expected.html b/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font-expected.html
new file mode 100644 (file)
index 0000000..1284de0
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div id="cont" style="font-family: Courier New;">
+<div style="word-spacing: -100%;">word1 word2</div>
+<div style="word-spacing: 0px;">word1 word2</div>
+<div style="word-spacing: 100%;">word1 word2</div>
+</div>
+</script>
+</body>
+</html>
+
diff --git a/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font.html b/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font.html
new file mode 100644 (file)
index 0000000..2ee8d25
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div id="cont">
+<div style="word-spacing: -100%;">word1 word2</div>
+<div style="word-spacing: 0px;">word1 word2</div>
+<div style="word-spacing: 100%;">word1 word2</div>
+</div>
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+window.setTimeout(function() {
+    var cont = document.getElementById("cont");
+    cont.setAttribute("style", "font-family: Courier New;");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}, 0);
+</script>
+</body>
+</html>
+
diff --git a/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-expected.html b/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-expected.html
new file mode 100644 (file)
index 0000000..b8f54f7
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div>word1word2</div>
+<div>word1&nbsp;word2</div>
+<div>word1&nbsp;&nbsp;word2</div>
+</body>
+</html>
diff --git a/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse-expected.txt b/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse-expected.txt
new file mode 100644 (file)
index 0000000..152baad
--- /dev/null
@@ -0,0 +1,9 @@
+PASS cssRule.type is cssRule.STYLE_RULE
+PASS declaration.length is 1
+PASS declaration.getPropertyValue('word-spacing') is "100%"
+PASS cssRule.type is cssRule.STYLE_RULE
+PASS declaration.length is 1
+PASS declaration.getPropertyValue('word-spacing') is "100.5%"
+PASS cssRule.type is cssRule.STYLE_RULE
+PASS declaration.length is 0
+
diff --git a/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse.html b/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse.html
new file mode 100644 (file)
index 0000000..24aa5c2
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+  <script type="text/javascript">
+    function testPercentageIsValid(stylesheet, percentage) {
+      cssRule = stylesheet.cssRules.item(0);
+      shouldBe("cssRule.type", "cssRule.STYLE_RULE");
+      declaration = cssRule.style;
+      shouldBe("declaration.length", "1");
+      shouldBe("declaration.getPropertyValue('word-spacing')", '"' + percentage.toString() + '%' + '"');
+      stylesheet.deleteRule(0);
+    }
+
+    function testInvalidRule(stylesheet) {
+      cssRule = stylesheet.cssRules.item(0);
+      shouldBe("cssRule.type", "cssRule.STYLE_RULE");
+      declaration = cssRule.style;
+      shouldBe("declaration.length", "0");
+      stylesheet.deleteRule(0);
+    }
+
+    var styleElement = document.createElement("style");
+    document.head.appendChild(styleElement);
+    stylesheet = styleElement.sheet;
+
+    stylesheet.insertRule(".p { word-spacing: 100%; }", 0);
+    testPercentageIsValid(stylesheet, 100);
+
+    stylesheet.insertRule(".p { word-spacing: 100.5%; }", 0);
+    testPercentageIsValid(stylesheet, 100.5);
+
+    stylesheet.insertRule(".p { word-spacing: garbage%; }", 0);
+    testInvalidRule(stylesheet);
+  </script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage.html b/LayoutTests/fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage.html
new file mode 100644 (file)
index 0000000..0965254
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<div style="word-spacing: -100%">word1 word2</div>
+<div style="word-spacing: 0%">word1 word2</div>
+<div style="word-spacing: 100%">word1 word2</div>
+</body>
+</html>
index 342bc9cc2b1716721336834ea960abc6cafb8c7e..7f887c06e0cfeff613d3fff33e74dfa28acd0864 100644 (file)
Binary files a/LayoutTests/platform/mac/css1/text_properties/word_spacing-expected.png and b/LayoutTests/platform/mac/css1/text_properties/word_spacing-expected.png differ
index 6c18f929fb32dec9da1bf08314145ff2f98a11b2..fa108e6ddb6a5995146c4480029ac4efca6b3945 100644 (file)
@@ -1,13 +1,13 @@
-layer at (0,0) size 785x997
+layer at (0,0) size 785x914
   RenderView at (0,0) size 785x600
-layer at (0,0) size 785x997
-  RenderBlock {HTML} at (0,0) size 785x997
-    RenderBody {BODY} at (8,8) size 769x981 [bgcolor=#CCCCCC]
+layer at (0,0) size 785x914
+  RenderBlock {HTML} at (0,0) size 785x914
+    RenderBody {BODY} at (8,8) size 769x898 [bgcolor=#CCCCCC]
       RenderBlock {P} at (0,0) size 769x18
         RenderText {#text} at (0,0) size 355x18
           text run at (0,0) width 355: "The style declarations which apply to the text below are:"
-      RenderBlock {PRE} at (0,34) size 769x180
-        RenderText {#text} at (0,0) size 248x180
+      RenderBlock {PRE} at (0,34) size 769x165
+        RenderText {#text} at (0,0) size 232x165
           text run at (0,0) width 216: ".one {word-spacing: 0.3in;}"
           text run at (216,0) width 0: " "
           text run at (0,15) width 216: ".two {word-spacing: 0.5cm;}"
@@ -26,34 +26,32 @@ layer at (0,0) size 785x997
           text run at (216,105) width 0: " "
           text run at (0,120) width 232: ".nine {word-spacing: normal;}"
           text run at (232,120) width 0: " "
-          text run at (0,135) width 208: ".ten {word-spacing: 300%;}"
-          text run at (208,135) width 0: " "
-          text run at (0,150) width 248: ".eleven {word-spacing: -0.2em;}"
-          text run at (248,150) width 0: " "
-          text run at (0,165) width 0: " "
-      RenderBlock {HR} at (0,227) size 769x2 [border: (1px inset #000000)]
-      RenderBlock {P} at (0,245) size 769x18
+          text run at (0,135) width 224: ".ten {word-spacing: -0.2em;}"
+          text run at (224,135) width 0: " "
+          text run at (0,150) width 0: " "
+      RenderBlock {HR} at (0,212) size 769x2 [border: (1px inset #000000)]
+      RenderBlock {P} at (0,230) size 769x18
         RenderText {#text} at (0,0) size 709x18
           text run at (0,0) width 709: "This words in this sentence should have extra space between them."
-      RenderBlock {P} at (0,279) size 769x18
+      RenderBlock {P} at (0,264) size 769x18
         RenderText {#text} at (0,0) size 610x18
           text run at (0,0) width 610: "This words in this sentence should have extra space between them."
-      RenderBlock {P} at (0,313) size 769x18
+      RenderBlock {P} at (0,298) size 769x18
         RenderText {#text} at (0,0) size 610x18
           text run at (0,0) width 610: "This words in this sentence should have extra space between them."
-      RenderBlock {P} at (0,347) size 769x18
+      RenderBlock {P} at (0,332) size 769x18
         RenderText {#text} at (0,0) size 461x18
           text run at (0,0) width 461: "This words in this sentence should have extra space between them."
-      RenderBlock {P} at (0,381) size 769x18
+      RenderBlock {P} at (0,366) size 769x18
         RenderText {#text} at (0,0) size 461x18
           text run at (0,0) width 461: "This words in this sentence should have extra space between them."
-      RenderBlock {P} at (0,415) size 769x18
+      RenderBlock {P} at (0,400) size 769x18
         RenderText {#text} at (0,0) size 581x18
           text run at (0,0) width 581: "This words in this sentence should have extra space between them."
-      RenderBlock {P} at (0,449) size 769x18
+      RenderBlock {P} at (0,434) size 769x18
         RenderText {#text} at (0,0) size 493x18
           text run at (0,0) width 493: "This words in this sentence should have extra space between them."
-      RenderBlock {P} at (0,483) size 769x36
+      RenderBlock {P} at (0,468) size 769x36
         RenderText {#text} at (0,0) size 751x18
           text run at (0,0) width 751: "This words in this sentence should have extra space between them, but the last few words in the sentence"
         RenderInline {SPAN} at (0,0) size 176x18
@@ -61,24 +59,21 @@ layer at (0,0) size 785x997
             text run at (0,18) width 176: "should have normal spacing"
         RenderText {#text} at (176,18) size 4x18
           text run at (176,18) width 4: "."
-      RenderBlock {P} at (0,535) size 769x18
-        RenderText {#text} at (0,0) size 668x18
-          text run at (0,0) width 668: "This sentence should have normal word-spacing, since percentage values are not allowed on this property."
-      RenderBlock {P} at (0,569) size 769x18
+      RenderBlock {P} at (0,520) size 769x18
         RenderText {#text} at (0,0) size 704x18
           text run at (0,0) width 704: "This words in this sentence should have reduced space between them, since negative values are allowed on this property."
-      RenderTable {TABLE} at (0,603) size 769x378 [border: (1px outset #808080)]
-        RenderTableSection {TBODY} at (1,1) size 767x376
+      RenderTable {TABLE} at (0,554) size 769x344 [border: (1px outset #808080)]
+        RenderTableSection {TBODY} at (1,1) size 767x342
           RenderTableRow {TR} at (0,0) size 767x26
             RenderTableCell {TD} at (0,0) size 767x26 [bgcolor=#C0C0C0] [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=2]
               RenderInline {STRONG} at (0,0) size 163x18
                 RenderText {#text} at (4,4) size 163x18
                   text run at (4,4) width 163: "TABLE Testing Section"
-          RenderTableRow {TR} at (0,26) size 767x350
-            RenderTableCell {TD} at (0,188) size 12x26 [bgcolor=#C0C0C0] [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
+          RenderTableRow {TR} at (0,26) size 767x316
+            RenderTableCell {TD} at (0,171) size 12x26 [bgcolor=#C0C0C0] [border: (1px inset #808080)] [r=1 c=0 rs=1 cs=1]
               RenderText {#text} at (4,4) size 4x18
                 text run at (4,4) width 4: " "
-            RenderTableCell {TD} at (12,26) size 755x350 [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
+            RenderTableCell {TD} at (12,26) size 755x316 [border: (1px inset #808080)] [r=1 c=1 rs=1 cs=1]
               RenderBlock {P} at (4,4) size 747x18
                 RenderText {#text} at (0,0) size 709x18
                   text run at (0,0) width 709: "This words in this sentence should have extra space between them."
@@ -110,8 +105,5 @@ layer at (0,0) size 785x997
                 RenderText {#text} at (239,18) size 4x18
                   text run at (239,18) width 4: "."
               RenderBlock {P} at (4,294) size 747x18
-                RenderText {#text} at (0,0) size 668x18
-                  text run at (0,0) width 668: "This sentence should have normal word-spacing, since percentage values are not allowed on this property."
-              RenderBlock {P} at (4,328) size 747x18
                 RenderText {#text} at (0,0) size 704x18
                   text run at (0,0) width 704: "This words in this sentence should have reduced space between them, since negative values are allowed on this property."
index 4ee70dbf2923daac78ef9ad5c6598e48bf982e68..417a565dcfde4b5f67e5796cac4e1c2bb4e4a7b4 100644 (file)
@@ -1,3 +1,54 @@
+2014-01-10  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        CSS word-spacing property does not obey percentages
+        https://bugs.webkit.org/show_bug.cgi?id=126674
+
+        Reviewed by Simon Fraser.
+
+        One change between CSS2.1 and CSS3 is that the word-spacing CSS property can
+        take percentages (of the width of the space character) in CSS3. In order to
+        implement this, the datatype must be changed from a float to a Length, which
+        can hold percentage values. Then, during layout, we can query the width of
+        the space character and update the Font's word-spacing value appropriately.
+        However, the RenderStyle still holds on to the Length (as a rare inherited
+        value).
+
+        Tests: fast/css3-text/css3-word-spacing-percentage/word-spacing-change-font.html
+               fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage-parse.html
+               fast/css3-text/css3-word-spacing-percentage/word-spacing-percentage.html
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::propertyValue): Use Font's computed value instead
+        of style's Length value.
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseValue): word-spacing and letter-spacing no longer are
+        parsed the same way.
+        * css/DeprecatedStyleBuilder.cpp:
+        (WebCore::ApplyPropertyWordSpacing::applyValue): Construct a length from a given
+        CSSValue and set the style's word spacing with it.
+        (WebCore::ApplyPropertyWordSpacing::createHandler):
+        (WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder): Use ApplyPropertyWordSpacing.
+        * page/animation/CSSPropertyAnimation.cpp:
+        (WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::setLogicalWidthForTextRun): Use Font's computed value instead
+        of style's Length value.
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::computePreferredLogicalWidths): Ditto.
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseFor): Opt-out of the SimpleLineLayout
+        if either the percentage or the length is nonzero.
+        * rendering/line/BreakingContextInlineHeaders.h:
+        (WebCore::BreakingContext::handleText): Use Font's computed value instead
+        of style's Length value.
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::wordSpacing):
+        (WebCore::RenderStyle::setWordSpacing): Consult the Font's space with to compute
+        percentage values, but hold on to the original Length.
+        * rendering/style/RenderStyle.h:
+        * rendering/style/StyleRareInheritedData.cpp:
+        * rendering/style/StyleRareInheritedData.h: Hold on to the specified Length
+
 2014-01-10  Simon Fraser  <simon.fraser@apple.com>
 
         Fix the iOS build.
index dbb13c57c1d07cbdc2a3d9cdb3772fa4a650e460..e9414db117ed2933b053d08336c22f0071648f12 100644 (file)
@@ -2512,7 +2512,7 @@ PassRefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propert
         case CSSPropertyWordBreak:
             return cssValuePool().createValue(style->wordBreak());
         case CSSPropertyWordSpacing:
-            return zoomAdjustedPixelValue(style->wordSpacing(), style.get());
+            return zoomAdjustedPixelValue(style->font().wordSpacing(), style.get());
         case CSSPropertyWordWrap:
             return cssValuePool().createValue(style->overflowWrap());
         case CSSPropertyWebkitLineBreak:
index b9d69cf31039bca2464622b465215d22ab10ae92..b706ae296de5ae39954bc0f9e536b5ab82206fcb 100644 (file)
@@ -2142,13 +2142,19 @@ bool CSSParser::parseValue(CSSPropertyID propId, bool important)
         break;
 
     case CSSPropertyLetterSpacing:       // normal | <length> | inherit
-    case CSSPropertyWordSpacing:         // normal | <length> | inherit
         if (id == CSSValueNormal)
             validPrimitive = true;
         else
             validPrimitive = validUnit(value, FLength);
         break;
 
+    case CSSPropertyWordSpacing:         // normal | <length> | <percentage> | inherit
+        if (id == CSSValueNormal)
+            validPrimitive = true;
+        else
+            validPrimitive = validUnit(value, FLength | FPercent);
+        break;
+
     case CSSPropertyTextIndent:
         parsedValue = parseTextIndent();
         break;
index c4d00b8fc9d927acc46572081c4ece5cd8a81eaf..4afb0dbf94cf36f937bb9478f2780163dffb6bc0 100644 (file)
@@ -1535,6 +1535,40 @@ public:
 };
 #endif
 
+class ApplyPropertyWordSpacing {
+public:
+    static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
+    {
+        if (!value->isPrimitiveValue())
+            return;
+
+        CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
+        Length wordSpacing;
+
+        if (primitiveValue->getValueID() == CSSValueNormal)
+            wordSpacing = RenderStyle::initialWordSpacing();
+        else if (primitiveValue->isLength()) {
+            double multiplier = styleResolver->style()->effectiveZoom();
+            if (Frame* frame = styleResolver->document().frame())
+                multiplier *= frame->textZoomFactor();
+            wordSpacing = primitiveValue->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle(), multiplier);
+        } else if (primitiveValue->isPercentage())
+            wordSpacing = Length(primitiveValue->getDoubleValue(), Percent);
+        else if (primitiveValue->isNumber())
+            wordSpacing = Length(primitiveValue->getDoubleValue(), Fixed);
+        else if (primitiveValue->isViewportPercentageLength())
+            wordSpacing = Length(styleResolver->viewportPercentageValue(*primitiveValue, primitiveValue->getDoubleValue()), Fixed);
+        else
+            return;
+        styleResolver->style()->setWordSpacing(wordSpacing);
+    }
+    static PropertyHandler createHandler()
+    {
+        PropertyHandler handler = ApplyPropertyDefaultBase<const Length&, &RenderStyle::wordSpacing, Length, &RenderStyle::setWordSpacing, Length, &RenderStyle::initialWordSpacing>::createHandler();
+        return PropertyHandler(handler.inheritFunction(), handler.initialFunction(), &applyValue);
+    }
+};
+
 class ApplyPropertyPageSize {
 private:
     static Length mmLength(double mm)
@@ -2529,7 +2563,7 @@ DeprecatedStyleBuilder::DeprecatedStyleBuilder()
     setPropertyHandler(CSSPropertyWidows, ApplyPropertyAuto<short, &RenderStyle::widows, &RenderStyle::setWidows, &RenderStyle::hasAutoWidows, &RenderStyle::setHasAutoWidows>::createHandler());
     setPropertyHandler(CSSPropertyWidth, ApplyPropertyLength<&RenderStyle::width, &RenderStyle::setWidth, &RenderStyle::initialSize, AutoEnabled, LegacyIntrinsicEnabled, IntrinsicEnabled, NoneDisabled, UndefinedDisabled>::createHandler());
     setPropertyHandler(CSSPropertyWordBreak, ApplyPropertyDefault<EWordBreak, &RenderStyle::wordBreak, EWordBreak, &RenderStyle::setWordBreak, EWordBreak, &RenderStyle::initialWordBreak>::createHandler());
-    setPropertyHandler(CSSPropertyWordSpacing, ApplyPropertyComputeLength<float, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing, &RenderStyle::initialWordSpacing, NormalEnabled, ThicknessDisabled, SVGZoomEnabled>::createHandler());
+    setPropertyHandler(CSSPropertyWordSpacing, ApplyPropertyWordSpacing::createHandler());
 
     // UAs must treat 'word-wrap' as an alternate name for the 'overflow-wrap' property. So using the same handlers.
     setPropertyHandler(CSSPropertyWordWrap, ApplyPropertyDefault<EOverflowWrap, &RenderStyle::overflowWrap, EOverflowWrap, &RenderStyle::setOverflowWrap, EOverflowWrap, &RenderStyle::initialOverflowWrap>::createHandler());
index 2893768e455da0419284183d2de8a4f1e8f81ed7..09f8dab1f05ac390ec717b6c6d893796a78776f1 100644 (file)
@@ -1213,7 +1213,7 @@ CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap()
         new PropertyWrapper<int>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset),
         new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth),
         new PropertyWrapper<float>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing),
-        new PropertyWrapper<float>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing),
+        new LengthPropertyWrapper<Length>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing),
         new LengthPropertyWrapper<Length>(CSSPropertyTextIndent, &RenderStyle::textIndent, &RenderStyle::setTextIndent),
 
         new PropertyWrapper<float>(CSSPropertyWebkitPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective),
index 5017c365de1e9e6d665aef54aa04b9b7207af128..05677e67f0387c94939d5f2627128588b4b448ac 100644 (file)
@@ -479,7 +479,7 @@ static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* ru
                     &wordMeasurement.fallbackFonts, &overflow);
                 UChar c = renderer->characterAt(wordMeasurement.startOffset);
                 if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t'))
-                    measuredWidth += renderer->style().wordSpacing();
+                    measuredWidth += renderer->style().font().wordSpacing();
             } else
                 measuredWidth += wordMeasurement.width;
             if (!wordMeasurement.fallbackFonts.isEmpty()) {
index 87ee08a90a7e4edb9bf5adcc1c4da905196e29fe..60d7310b26fbd4c735e64acfd08021bcf036fc7f 100644 (file)
@@ -682,8 +682,8 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
     m_hasEndWS = false;
 
     const RenderStyle& style = this->style();
-    const Font& f = style.font(); // FIXME: This ignores first-line.
-    float wordSpacing = style.wordSpacing();
+    const Font& font = style.font(); // FIXME: This ignores first-line.
+    float wordSpacing = font.wordSpacing();
     int len = textLength();
     LazyLineBreakIterator breakIterator(m_text, style.locale());
     bool needsWordSpacing = false;
@@ -696,7 +696,7 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
 
     // Non-zero only when kerning is enabled, in which case we measure words with their trailing
     // space, then subtract its width.
-    float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(RenderBlock::constructTextRun(this, f, &space, 1, style), &fallbackFonts) + wordSpacing : 0;
+    float wordTrailingSpaceWidth = font.typesettingFeatures() & Kerning ? font.width(RenderBlock::constructTextRun(this, font, &space, 1, style), &fallbackFonts) + wordSpacing : 0;
 
     // If automatic hyphenation is allowed, we keep track of the width of the widest word (or word
     // fragment) encountered so far, and only try hyphenating words that are wider.
@@ -760,7 +760,7 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
             lastWordBoundary++;
             continue;
         } else if (c == softHyphen && style.hyphens() != HyphensNone) {
-            currMaxWidth += widthFromCache(f, lastWordBoundary, i - lastWordBoundary, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
+            currMaxWidth += widthFromCache(font, lastWordBoundary, i - lastWordBoundary, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
             if (firstGlyphLeftOverflow < 0)
                 firstGlyphLeftOverflow = glyphOverflow.left;
             lastWordBoundary = i + 1;
@@ -788,23 +788,23 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
             bool isSpace = (j < len) && isSpaceAccordingToStyle(c, style);
             float w;
             if (wordTrailingSpaceWidth && isSpace)
-                w = widthFromCache(f, i, wordLen + 1, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style) - wordTrailingSpaceWidth;
+                w = widthFromCache(font, i, wordLen + 1, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style) - wordTrailingSpaceWidth;
             else {
-                w = widthFromCache(f, i, wordLen, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
+                w = widthFromCache(font, i, wordLen, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
                 if (c == softHyphen && style.hyphens() != HyphensNone)
-                    currMinWidth += hyphenWidth(this, f);
+                    currMinWidth += hyphenWidth(this, font);
             }
 
             if (w > maxWordWidth) {
                 int suffixStart;
-                float maxFragmentWidth = maxWordFragmentWidth(this, style, f, characters() + i, wordLen, minimumPrefixLength, minimumSuffixLength, suffixStart, fallbackFonts, glyphOverflow);
+                float maxFragmentWidth = maxWordFragmentWidth(this, style, font, characters() + i, wordLen, minimumPrefixLength, minimumSuffixLength, suffixStart, fallbackFonts, glyphOverflow);
 
                 if (suffixStart) {
                     float suffixWidth;
                     if (wordTrailingSpaceWidth && isSpace)
-                        suffixWidth = widthFromCache(f, i + suffixStart, wordLen - suffixStart + 1, leadWidth + currMaxWidth, 0, 0, style) - wordTrailingSpaceWidth;
+                        suffixWidth = widthFromCache(font, i + suffixStart, wordLen - suffixStart + 1, leadWidth + currMaxWidth, 0, 0, style) - wordTrailingSpaceWidth;
                     else
-                        suffixWidth = widthFromCache(f, i + suffixStart, wordLen - suffixStart, leadWidth + currMaxWidth, 0, 0, style);
+                        suffixWidth = widthFromCache(font, i + suffixStart, wordLen - suffixStart, leadWidth + currMaxWidth, 0, 0, style);
 
                     maxFragmentWidth = std::max(maxFragmentWidth, suffixWidth);
 
@@ -821,7 +821,7 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
                 if (lastWordBoundary == i)
                     currMaxWidth += w;
                 else
-                    currMaxWidth += widthFromCache(f, lastWordBoundary, j - lastWordBoundary, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
+                    currMaxWidth += widthFromCache(font, lastWordBoundary, j - lastWordBoundary, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
                 lastWordBoundary = j;
             }
 
@@ -872,13 +872,13 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Si
                     m_maxWidth = currMaxWidth;
                 currMaxWidth = 0;
             } else {
-                TextRun run = RenderBlock::constructTextRun(this, f, this, i, 1, style);
+                TextRun run = RenderBlock::constructTextRun(this, font, this, i, 1, style);
                 run.setCharactersLength(len - i);
                 ASSERT(run.charactersLength() >= run.length());
                 run.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
                 run.setXPos(leadWidth + currMaxWidth);
 
-                currMaxWidth += f.width(run, &fallbackFonts);
+                currMaxWidth += font.width(run, &fallbackFonts);
                 glyphOverflow.right = 0;
                 needsWordSpacing = isSpace && !previousCharacterIsSpace && i == len - 1;
             }
index 97072d11fd5082e26f36c799ec7be81e5dd9f885..e6e0fa0850c5c80a8f39d0d5314d7beaedd23b75 100644 (file)
@@ -140,7 +140,7 @@ bool canUseFor(const RenderBlockFlow& flow)
         return false;
     if (!style.textIndent().isZero())
         return false;
-    if (style.wordSpacing() || style.letterSpacing())
+    if (!style.wordSpacing().isZero() || style.letterSpacing())
         return false;
     if (style.textTransform() != TTNONE)
         return false;
index 2d466d5c7b3c9724f3623601d22e11e1f7bf4727..f76db521bf96a30d3f55838fd00b19d2931998e4 100644 (file)
@@ -668,7 +668,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
     bool canHyphenate = style.hyphens() == HyphensAuto && WebCore::canHyphenate(style.locale());
 
     unsigned lastSpace = m_current.offset();
-    float wordSpacing = m_currentStyle->wordSpacing();
+    float wordSpacing = m_currentStyle->font().wordSpacing();
     float lastSpaceWordSpacing = 0;
     float wordSpacingForWordMeasurement = 0;
 
index 4691864834cc500ac4f0912de08cd9cb23ebe5f0..12d9e71f7a6195b23a08cc58d453e556e3414c42 100644 (file)
@@ -1399,7 +1399,7 @@ float RenderStyle::specifiedFontSize() const { return fontDescription().specifie
 float RenderStyle::computedFontSize() const { return fontDescription().computedSize(); }
 int RenderStyle::fontSize() const { return inherited->font.pixelSize(); }
 
-float RenderStyle::wordSpacing() const { return inherited->font.wordSpacing(); }
+const Length& RenderStyle::wordSpacing() const { return rareInheritedData->wordSpacing; }
 float RenderStyle::letterSpacing() const { return inherited->font.letterSpacing(); }
 
 bool RenderStyle::setFontDescription(const FontDescription& v)
@@ -1451,7 +1451,19 @@ int RenderStyle::computedLineHeight(RenderView* renderView) const
     return lh.value();
 }
 
-void RenderStyle::setWordSpacing(float v) { inherited.access()->font.setWordSpacing(v); }
+void RenderStyle::setWordSpacing(Length v)
+{
+    float fontWordSpacing;
+    if (v.isPercent())
+        fontWordSpacing = v.getFloatValue() * font().spaceWidth() / 100;
+    else {
+        ASSERT(v.isFixed());
+        fontWordSpacing = v.getFloatValue();
+    }
+    inherited.access()->font.setWordSpacing(fontWordSpacing);
+    rareInheritedData.access()->wordSpacing = std::move(v);
+}
+
 void RenderStyle::setLetterSpacing(float v) { inherited.access()->font.setLetterSpacing(v); }
 
 void RenderStyle::setFontSize(float size)
index 66b75783ef8572fa704a81303fe0e94f9be76eed..9f1cd99fba01d7171dc9d18569651495463553f9 100644 (file)
@@ -580,7 +580,7 @@ public:
 #else
     TextDecorationStyle textDecorationStyle() const { return TextDecorationStyleSolid; }
 #endif
-    float wordSpacing() const;
+    const Length& wordSpacing() const;
     float letterSpacing() const;
 
     float zoom() const { return visual->m_zoom; }
@@ -1189,7 +1189,7 @@ public:
 
     void setWhiteSpace(EWhiteSpace v) { inherited_flags._white_space = v; }
 
-    void setWordSpacing(float);
+    void setWordSpacing(Length);
     void setLetterSpacing(float);
 
     void clearBackgroundLayers() { m_background.access()->m_background = FillLayer(BackgroundFillLayer); }
@@ -1664,7 +1664,7 @@ public:
     static unsigned short initialColumnRuleWidth() { return 3; }
     static unsigned short initialOutlineWidth() { return 3; }
     static float initialLetterSpacing() { return 0; }
-    static float initialWordSpacing() { return 0; }
+    static Length initialWordSpacing() { return Length(Fixed); }
     static Length initialSize() { return Length(); }
     static Length initialMinSize() { return Length(Fixed); }
     static Length initialMaxSize() { return Length(Undefined); }
index 14aede93c09fe620c17127163312d97b2ecd5463..8f08111e9dc9198e2c27f6582cdaa1e3e28b1979 100644 (file)
@@ -39,7 +39,7 @@ struct SameSizeAsStyleRareInheritedData : public RefCounted<SameSizeAsStyleRareI
     void* ownPtrs[1];
     AtomicString atomicStrings[5];
     void* refPtrs[2];
-    Length lengths[1];
+    Length lengths[2];
     float secondFloat;
     unsigned m_bitfields[2];
 #if ENABLE(CSS3_TEXT_DECORATION) && ENABLE(CSS_IMAGE_ORIENTATION)
index 0e1cb5a28b59de1a6a791108a67590e05f1f2b70..3b40802c38e483a0c0e97765039eb723a3dc2b51 100644 (file)
@@ -75,6 +75,8 @@ public:
     RefPtr<CursorList> cursorData;
     Length indent;
     float m_effectiveZoom;
+    
+    Length wordSpacing;
 
     // Paged media properties.
     short widows;