<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[197519] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/197519">197519</a></dd>
<dt>Author</dt> <dd>hyatt@apple.com</dd>
<dt>Date</dt> <dd>2016-03-03 13:49:32 -0800 (Thu, 03 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add support for the &quot;last&quot; value of hanging-punctuation
https://bugs.webkit.org/show_bug.cgi?id=154977

Reviewed by Darin Adler and Simon Fraser.

Source/WebCore:

New tests in fast/text.

This patch adds support for the new &quot;last&quot; value and also fixes up both
&quot;first&quot; and &quot;last&quot; to work with leading and trailing whitespace that ends
up getting collapsed away.

* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::inlineAncestorHasStartBorderPaddingOrMargin):
(WebCore::inlineAncestorHasEndBorderPaddingOrMargin):
(WebCore::isLastInFlowRun):
(WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment):
* rendering/RenderText.cpp:
(WebCore::isHangablePunctuationAtLineEnd):
(WebCore::RenderText::hangablePunctuationStartWidth):
(WebCore::RenderText::hangablePunctuationEndWidth):
(WebCore::RenderText::firstCharacterIndexStrippingSpaces):
(WebCore::RenderText::lastCharacterIndexStrippingSpaces):
(WebCore::RenderText::trimmedPrefWidths):
* rendering/RenderText.h:
* rendering/line/BreakingContext.h:
(WebCore::BreakingContext::handleText):

LayoutTests:

* fast/text/hanging-punctuation-first-and-last-together-expected.html: Added.
* fast/text/hanging-punctuation-first-and-last-together.html: Added.
* fast/text/hanging-punctuation-first-ws-expected.html: Added.
* fast/text/hanging-punctuation-first-ws.html: Added.
* fast/text/hanging-punctuation-last-expected.html: Added.
* fast/text/hanging-punctuation-last-rtl-expected.html: Added.
* fast/text/hanging-punctuation-last-rtl.html: Added.
* fast/text/hanging-punctuation-last-ws-expected.html: Added.
* fast/text/hanging-punctuation-last-ws.html: Added.
* fast/text/hanging-punctuation-last.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockFlowcpp">trunk/Source/WebCore/rendering/RenderBlockFlow.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockLineLayoutcpp">trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderTextcpp">trunk/Source/WebCore/rendering/RenderText.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderTexth">trunk/Source/WebCore/rendering/RenderText.h</a></li>
<li><a href="#trunkSourceWebCorerenderinglineBreakingContexth">trunk/Source/WebCore/rendering/line/BreakingContext.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationfirstandlasttogetherexpectedhtml">trunk/LayoutTests/fast/text/hanging-punctuation-first-and-last-together-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationfirstandlasttogetherhtml">trunk/LayoutTests/fast/text/hanging-punctuation-first-and-last-together.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationfirstwsexpectedhtml">trunk/LayoutTests/fast/text/hanging-punctuation-first-ws-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationfirstwshtml">trunk/LayoutTests/fast/text/hanging-punctuation-first-ws.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationlastexpectedhtml">trunk/LayoutTests/fast/text/hanging-punctuation-last-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationlastrtlexpectedhtml">trunk/LayoutTests/fast/text/hanging-punctuation-last-rtl-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationlastrtlhtml">trunk/LayoutTests/fast/text/hanging-punctuation-last-rtl.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationlastwsexpectedhtml">trunk/LayoutTests/fast/text/hanging-punctuation-last-ws-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationlastwshtml">trunk/LayoutTests/fast/text/hanging-punctuation-last-ws.html</a></li>
<li><a href="#trunkLayoutTestsfasttexthangingpunctuationlasthtml">trunk/LayoutTests/fast/text/hanging-punctuation-last.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (197518 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-03 21:46:07 UTC (rev 197518)
+++ trunk/LayoutTests/ChangeLog        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-03-03  Dave Hyatt  &lt;hyatt@apple.com&gt;
+
+        Add support for the &quot;last&quot; value of hanging-punctuation
+        https://bugs.webkit.org/show_bug.cgi?id=154977
+
+        Reviewed by Darin Adler and Simon Fraser.
+
+        * fast/text/hanging-punctuation-first-and-last-together-expected.html: Added.
+        * fast/text/hanging-punctuation-first-and-last-together.html: Added.
+        * fast/text/hanging-punctuation-first-ws-expected.html: Added.
+        * fast/text/hanging-punctuation-first-ws.html: Added.
+        * fast/text/hanging-punctuation-last-expected.html: Added.
+        * fast/text/hanging-punctuation-last-rtl-expected.html: Added.
+        * fast/text/hanging-punctuation-last-rtl.html: Added.
+        * fast/text/hanging-punctuation-last-ws-expected.html: Added.
+        * fast/text/hanging-punctuation-last-ws.html: Added.
+        * fast/text/hanging-punctuation-last.html: Added.
+
</ins><span class="cx"> 2016-03-03  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         storage/indexeddb/delete-in-upgradeneeded-close-in-open-success.html flaky on mac-wk2.
</span></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationfirstandlasttogetherexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-first-and-last-together-expected.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-first-and-last-together-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-first-and-last-together-expected.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+&lt;head&gt;
+    &lt;style&gt;
+        body { font-family: 'Ahem'; color:green }
+        .hang { margin:1em; border:1px solid black }
+        &lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div style=&quot;float:left&quot; class=&quot;hang&quot;&gt;&lt;div style=&quot;margin: 0 -1em&quot;&gt;(Hang test)&lt;/div&gt;&lt;/div&gt;
+    &lt;div style=&quot;clear:both&quot;&gt;
+        &lt;div class=&quot;hang&quot; style=&quot;width:10em; text-align:justify;&quot;&gt;&lt;span style=&quot;margin:0 -1em&quot;&gt;(This should hang.&lt;br&gt;(This should also hang.)&lt;/span&gt;&lt;/div&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationfirstandlasttogetherhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-first-and-last-together.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-first-and-last-together.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-first-and-last-together.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+&lt;head&gt;
+&lt;style&gt;
+    body { font-family: 'Ahem'; color:green }
+    .hang { hanging-punctuation: first last; margin:1em; border:1px solid black }
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:left&quot; class=&quot;hang&quot;&gt;(Hang test)&lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+&lt;div class=&quot;hang&quot; style=&quot;width:10em; text-align:justify;&quot;&gt;(This should hang.&lt;br&gt;(This should also hang.)&lt;/div&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationfirstwsexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-first-ws-expected.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-first-ws-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-first-ws-expected.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+&lt;head&gt;
+&lt;style&gt;
+    body { font-family: 'Ahem'; color:green }
+    .hang { text-indent: -1em; margin:1em }
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:left&quot; class=&quot;hang&quot;&gt;(Hang test)&lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+&lt;div class=&quot;hang&quot;&gt;(This should hang.&lt;br&gt;(This should not.&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:300px;&quot;&gt;(This should hang and justifybecause and now were fine.&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:300px;&quot;&gt;&lt;span&gt;(&lt;/span&gt;This should hang.&lt;/div&gt;
+&lt;div style=&quot;margin-left:1em; text-align:justify; width:300px;&quot;&gt;&lt;span style=&quot;border-left:1em solid blue&quot;&gt;(&lt;/span&gt;This should not hang.&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-indent:1em; text-align:justify; width:300px;&quot;&gt;(This should hang into the text-indent.&lt;/div&gt;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationfirstwshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-first-ws.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-first-ws.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-first-ws.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+&lt;head&gt;
+&lt;style&gt;
+    body { font-family: 'Ahem'; color:green }
+    .hang { hanging-punctuation: first; margin:1em }
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:left&quot; class=&quot;hang&quot;&gt;    (Hang test)&lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+&lt;div class=&quot;hang&quot;&gt;    (This should hang.&lt;br&gt;(This should not.&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:300px;&quot;&gt;   (This should hang and justifybecause and now were fine.&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:300px;&quot;&gt;   &lt;span&gt;   (&lt;/span&gt;This should hang.&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:300px;&quot;&gt;   &lt;span style=&quot;border-left:1em solid blue&quot;&gt;  (&lt;/span&gt;This should not hang.&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-indent:2em; text-align:justify; width:300px;&quot;&gt;   (This should hang into the text-indent.&lt;/div&gt;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationlastexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-last-expected.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-last-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-last-expected.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;head&gt;
+    &lt;style&gt;
+    body { font-family: 'Ahem'; color:green }
+    .hang { margin:1em }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:left;&quot; class=&quot;hang&quot;&gt;(Hang test)&lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;width:5em&quot;&gt;No.&lt;br&gt;Yes.)&lt;/div&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:5em;&quot;&gt;Yes &lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;No. &lt;span style=&quot;border-right:1em solid blue&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationlastrtlexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-last-rtl-expected.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-last-rtl-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-last-rtl-expected.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;head&gt;
+    &lt;style&gt;
+        body { font-family: 'Ahem'; color:green; direction:rtl }
+    .hang { margin:1em }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:right;&quot; class=&quot;hang&quot;&gt;(Hang test)&lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;width:5em&quot;&gt;No.&lt;br&gt;Yes.)&lt;/div&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:5em;&quot;&gt;Yes &lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;No. &lt;span style=&quot;border-left:1em solid blue&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationlastrtlhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-last-rtl.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-last-rtl.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-last-rtl.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+&lt;head&gt;
+&lt;style&gt;
+    body { font-family: 'Ahem'; color:green; direction:rtl }
+    .hang { hanging-punctuation: last; margin:1em }
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:right;&quot; class=&quot;hang&quot;&gt;(Hang test)&lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+&lt;div class=&quot;hang&quot; style=&quot;width:4em&quot;
+    &gt;No.&lt;br&gt;Yes.)&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;Yes &lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;No. &lt;span style=&quot;border-left:1em solid blue&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationlastwsexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-last-ws-expected.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-last-ws-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-last-ws-expected.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;head&gt;
+    &lt;style&gt;
+    body { font-family: 'Ahem'; color:green }
+    .hang { margin:1em }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:left;&quot; class=&quot;hang&quot;&gt;(Hang test)&lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;width:5em&quot;&gt;No.&lt;br&gt;Yes.)&lt;/div&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:5em;&quot;&gt;Yes &lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
+    &lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;No. &lt;span style=&quot;border-right:1em solid blue&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationlastwshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-last-ws.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-last-ws.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-last-ws.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;head&gt;
+&lt;style&gt;
+    body { font-family: 'Ahem'; color:green }
+    .hang { hanging-punctuation: last; margin:1em }
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:left;&quot; class=&quot;hang&quot;&gt;(Hang test)  &lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+&lt;div class=&quot;hang&quot; style=&quot;width:4em&quot;&gt;No.&lt;br&gt;Yes.)  &lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;Yes &lt;span&gt;) &lt;/span&gt;&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;No. &lt;span style=&quot;border-right:1em solid blue&quot;&gt;) &lt;/span&gt;  &lt;/div&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttexthangingpunctuationlasthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/hanging-punctuation-last.html (0 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/hanging-punctuation-last.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/hanging-punctuation-last.html        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+&lt;head&gt;
+&lt;style&gt;
+    body { font-family: 'Ahem'; color:green }
+    .hang { hanging-punctuation: last; margin:1em }
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;float:left;&quot; class=&quot;hang&quot;&gt;(Hang test)&lt;/div&gt;
+&lt;div style=&quot;clear:both&quot;&gt;
+&lt;div class=&quot;hang&quot; style=&quot;width:4em&quot;
+    &gt;No.&lt;br&gt;Yes.)&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;Yes &lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
+&lt;div class=&quot;hang&quot; style=&quot;text-align:justify; width:4em;&quot;&gt;No. &lt;span style=&quot;border-right:1em solid blue&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197518 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-03 21:46:07 UTC (rev 197518)
+++ trunk/Source/WebCore/ChangeLog        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2016-03-03  Dave Hyatt  &lt;hyatt@apple.com&gt;
+
+        Add support for the &quot;last&quot; value of hanging-punctuation
+        https://bugs.webkit.org/show_bug.cgi?id=154977
+
+        Reviewed by Darin Adler and Simon Fraser.
+
+        New tests in fast/text.
+
+        This patch adds support for the new &quot;last&quot; value and also fixes up both
+        &quot;first&quot; and &quot;last&quot; to work with leading and trailing whitespace that ends
+        up getting collapsed away.
+
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths):
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::inlineAncestorHasStartBorderPaddingOrMargin):
+        (WebCore::inlineAncestorHasEndBorderPaddingOrMargin):
+        (WebCore::isLastInFlowRun):
+        (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment):
+        * rendering/RenderText.cpp:
+        (WebCore::isHangablePunctuationAtLineEnd):
+        (WebCore::RenderText::hangablePunctuationStartWidth):
+        (WebCore::RenderText::hangablePunctuationEndWidth):
+        (WebCore::RenderText::firstCharacterIndexStrippingSpaces):
+        (WebCore::RenderText::lastCharacterIndexStrippingSpaces):
+        (WebCore::RenderText::trimmedPrefWidths):
+        * rendering/RenderText.h:
+        * rendering/line/BreakingContext.h:
+        (WebCore::BreakingContext::handleText):
+
</ins><span class="cx"> 2016-03-03  Andy Estes  &lt;aestes@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Adopt CFNetwork storage partitioning SPI
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockFlowcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (197518 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp        2016-03-03 21:46:07 UTC (rev 197518)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -4065,6 +4065,9 @@
</span><span class="cx">     bool isPrevChildInlineFlow = false;
</span><span class="cx">     bool shouldBreakLineAfterText = false;
</span><span class="cx">     bool canHangPunctuationAtStart = styleToUse.hangingPunctuation() &amp; FirstHangingPunctuation;
</span><ins>+    bool canHangPunctuationAtEnd = styleToUse.hangingPunctuation() &amp; LastHangingPunctuation;
+    RenderText* lastText = nullptr;
+
</ins><span class="cx">     bool addedStartPunctuationHang = false;
</span><span class="cx">     
</span><span class="cx">     while (RenderObject* child = childIterator.next()) {
</span><span class="lines">@@ -4111,6 +4114,7 @@
</span><span class="cx">             float childMax = 0;
</span><span class="cx"> 
</span><span class="cx">             if (!child-&gt;isText()) {
</span><ins>+                lastText = nullptr;
</ins><span class="cx">                 if (child-&gt;isLineBreakOpportunity()) {
</span><span class="cx">                     minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin);
</span><span class="cx">                     inlineMin = 0;
</span><span class="lines">@@ -4217,6 +4221,7 @@
</span><span class="cx">                 if (!child-&gt;isFloating()) {
</span><span class="cx">                     stripFrontSpaces = false;
</span><span class="cx">                     trailingSpaceChild = nullptr;
</span><ins>+                    lastText = nullptr;
</ins><span class="cx">                 }
</span><span class="cx">             } else if (is&lt;RenderText&gt;(*child)) {
</span><span class="cx">                 // Case (3). Text.
</span><span class="lines">@@ -4234,6 +4239,7 @@
</span><span class="cx">                 float beginMin, endMin;
</span><span class="cx">                 bool beginWS, endWS;
</span><span class="cx">                 float beginMax, endMax;
</span><ins>+                bool strippingBeginWS = stripFrontSpaces;
</ins><span class="cx">                 renderText.trimmedPrefWidths(inlineMax, beginMin, beginWS, endMin, endWS,
</span><span class="cx">                                      hasBreakableChar, hasBreak, beginMax, endMax,
</span><span class="cx">                                      childMin, childMax, stripFrontSpaces);
</span><span class="lines">@@ -4246,6 +4252,8 @@
</span><span class="cx">                     }
</span><span class="cx">                     continue;
</span><span class="cx">                 }
</span><ins>+                
+                lastText = &amp;renderText;
</ins><span class="cx"> 
</span><span class="cx">                 if (stripFrontSpaces)
</span><span class="cx">                     trailingSpaceChild = child;
</span><span class="lines">@@ -4276,7 +4284,8 @@
</span><span class="cx">                 
</span><span class="cx">                 // See if we have a hanging punctuation situation at the start.
</span><span class="cx">                 if (canHangPunctuationAtStart &amp;&amp; !addedStartPunctuationHang) {
</span><del>-                    float hangStartWidth = renderText.hangablePunctuationStartWidth();
</del><ins>+                    unsigned startIndex = strippingBeginWS ? renderText.firstCharacterIndexStrippingSpaces() : 0;
+                    float hangStartWidth = renderText.hangablePunctuationStartWidth(startIndex);
</ins><span class="cx">                     childMin -= hangStartWidth;
</span><span class="cx">                     beginMin -= hangStartWidth;
</span><span class="cx">                     childMax -= hangStartWidth;
</span><span class="lines">@@ -4349,6 +4358,13 @@
</span><span class="cx"> 
</span><span class="cx">     if (styleToUse.collapseWhiteSpace())
</span><span class="cx">         stripTrailingSpace(inlineMax, inlineMin, trailingSpaceChild);
</span><ins>+    
+    if (canHangPunctuationAtEnd &amp;&amp; lastText &amp;&amp; lastText-&gt;textLength() &gt; 0) {
+        unsigned endIndex = trailingSpaceChild == lastText ? lastText-&gt;lastCharacterIndexStrippingSpaces() : lastText-&gt;textLength() - 1;
+        float endHangWidth = lastText-&gt;hangablePunctuationEndWidth(endIndex);
+        inlineMin -= endHangWidth;
+        inlineMax -= endHangWidth;
+    }
</ins><span class="cx"> 
</span><span class="cx">     minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin);
</span><span class="cx">     maxLogicalWidth = preferredWidth(maxLogicalWidth, inlineMax);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockLineLayoutcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp (197518 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp        2016-03-03 21:46:07 UTC (rev 197518)
+++ trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -817,6 +817,17 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool inlineAncestorHasEndBorderPaddingOrMargin(const RenderBlockFlow&amp; block, const InlineBox&amp; box)
+{
+    bool isLTR = block.style().isLeftToRightDirection();
+    for (auto* currentBox = box.parent(); currentBox; currentBox = currentBox-&gt;parent()) {
+        if ((isLTR &amp;&amp; currentBox-&gt;marginBorderPaddingLogicalRight() &gt; 0)
+            || (!isLTR &amp;&amp; currentBox-&gt;marginBorderPaddingLogicalLeft() &gt; 0))
+            return true;
+    }
+    return false;
+}
+    
</ins><span class="cx"> static bool isLastInFlowRun(BidiRun&amp; runToCheck)
</span><span class="cx"> {
</span><span class="cx">     for (auto* run = runToCheck.next(); run; run = run-&gt;next()) {
</span><span class="lines">@@ -833,6 +844,7 @@
</span><span class="cx"> {
</span><span class="cx">     bool needsWordSpacing = false;
</span><span class="cx">     bool canHangPunctuationAtStart = style().hangingPunctuation() &amp; FirstHangingPunctuation;
</span><ins>+    bool canHangPunctuationAtEnd = style().hangingPunctuation() &amp; LastHangingPunctuation;
</ins><span class="cx">     bool isLTR = style().isLeftToRightDirection();
</span><span class="cx">     float totalLogicalWidth = lineBox-&gt;getFlowSpacingLogicalWidth();
</span><span class="cx">     unsigned expansionOpportunityCount = 0;
</span><span class="lines">@@ -852,13 +864,22 @@
</span><span class="cx">             auto&amp; textBox = downcast&lt;InlineTextBox&gt;(*run-&gt;box());
</span><span class="cx">             if (canHangPunctuationAtStart &amp;&amp; lineInfo.isFirstLine() &amp;&amp; (isLTR || isLastInFlowRun(*run))
</span><span class="cx">                 &amp;&amp; !inlineAncestorHasStartBorderPaddingOrMargin(*this, *run-&gt;box())) {
</span><del>-                float hangStartWidth = renderText.hangablePunctuationStartWidth();
</del><ins>+                float hangStartWidth = renderText.hangablePunctuationStartWidth(run-&gt;m_start);
</ins><span class="cx">                 availableLogicalWidth += hangStartWidth;
</span><span class="cx">                 if (style().isLeftToRightDirection())
</span><span class="cx">                     logicalLeft -= hangStartWidth;
</span><span class="cx">                 canHangPunctuationAtStart = false;
</span><span class="cx">             }
</span><span class="cx">             
</span><ins>+            if (canHangPunctuationAtEnd &amp;&amp; lineInfo.isLastLine() &amp;&amp; run-&gt;m_stop &gt; 0 &amp;&amp; (!isLTR || isLastInFlowRun(*run))
+                &amp;&amp; !inlineAncestorHasEndBorderPaddingOrMargin(*this, *run-&gt;box())) {
+                float hangEndWidth = renderText.hangablePunctuationEndWidth(run-&gt;m_stop - 1);
+                availableLogicalWidth += hangEndWidth;
+                if (!style().isLeftToRightDirection())
+                    logicalLeft -= hangEndWidth;
+                canHangPunctuationAtEnd = false;
+            }
+            
</ins><span class="cx">             if (textAlign == JUSTIFY &amp;&amp; run != trailingSpaceRun) {
</span><span class="cx">                 ExpansionBehavior expansionBehavior = expansionBehaviorForInlineTextBox(*this, textBox, previousRun, run-&gt;next(), textAlign, isAfterExpansion);
</span><span class="cx">                 applyExpansionBehavior(textBox, expansionBehavior);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderTextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderText.cpp (197518 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderText.cpp        2016-03-03 21:46:07 UTC (rev 197518)
+++ trunk/Source/WebCore/rendering/RenderText.cpp        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -512,22 +512,75 @@
</span><span class="cx">     return U_GET_GC_MASK(c) &amp; (U_GC_PE_MASK | U_GC_PI_MASK | U_GC_PF_MASK);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-float RenderText::hangablePunctuationStartWidth() const
</del><ins>+float RenderText::hangablePunctuationStartWidth(unsigned index) const
</ins><span class="cx"> {
</span><span class="cx">     if (!textLength())
</span><span class="cx">         return 0;
</span><span class="cx">     
</span><span class="cx">     ASSERT(m_text);
</span><span class="cx">     StringImpl&amp; text = *m_text.impl();
</span><del>-    if (!isHangablePunctuationAtLineStart(text[0]))
</del><ins>+    
+    if (!isHangablePunctuationAtLineStart(text[index]))
</ins><span class="cx">         return 0;
</span><del>-    
</del><ins>+
</ins><span class="cx">     const RenderStyle&amp; style = this-&gt;style();
</span><span class="cx">     const FontCascade&amp; font = style.fontCascade();
</span><span class="cx">         
</span><span class="cx">     return widthFromCache(font, 0, 1, 0, 0, 0, style);
</span><span class="cx"> }
</span><ins>+
+float RenderText::hangablePunctuationEndWidth(unsigned index) const
+{
+    if (!textLength())
+        return 0;
</ins><span class="cx">     
</span><ins>+    ASSERT(m_text);
+    StringImpl&amp; text = *m_text.impl();
+
+    if (!isHangablePunctuationAtLineEnd(text[index]))
+        return 0;
+    
+    const RenderStyle&amp; style = this-&gt;style();
+    const FontCascade&amp; font = style.fontCascade();
+    
+    return widthFromCache(font, 0, 1, 0, 0, 0, style);
+}
+
+unsigned RenderText::firstCharacterIndexStrippingSpaces() const
+{
+    if (!style().collapseWhiteSpace())
+        return 0;
+    
+    ASSERT(m_text);
+    StringImpl&amp; text = *m_text.impl();
+    
+    unsigned i = 0;
+    for ( ; i &lt; textLength(); ++i) {
+        if (text[i] != ' ' &amp;&amp; (text[i] != '\n' || style().preserveNewline()) &amp;&amp; text[i] != '\t')
+            break;
+    }
+    return i;
+}
+
+unsigned RenderText::lastCharacterIndexStrippingSpaces() const
+{
+    if (!textLength())
+        return 0;
+
+    if (!style().collapseWhiteSpace())
+        return textLength() - 1;
+    
+    ASSERT(m_text);
+    StringImpl&amp; text = *m_text.impl();
+    
+    int i = textLength() - 1;
+    for ( ; i  &gt;= 0; --i) {
+        if (text[i] != ' ' &amp;&amp; (text[i] != '\n' || style().preserveNewline()) &amp;&amp; text[i] != '\t')
+            break;
+    }
+    return i;
+}
+
</ins><span class="cx"> void RenderText::trimmedPrefWidths(float leadWidth,
</span><span class="cx">                                    float&amp; beginMinW, bool&amp; beginWS,
</span><span class="cx">                                    float&amp; endMinW, bool&amp; endWS,
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderTexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderText.h (197518 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderText.h        2016-03-03 21:46:07 UTC (rev 197518)
+++ trunk/Source/WebCore/rendering/RenderText.h        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -102,7 +102,10 @@
</span><span class="cx">                            bool&amp; hasBreakableChar, bool&amp; hasBreak,
</span><span class="cx">                            float&amp; beginMaxW, float&amp; endMaxW,
</span><span class="cx">                            float&amp; minW, float&amp; maxW, bool&amp; stripFrontSpaces);
</span><del>-    float hangablePunctuationStartWidth() const;
</del><ins>+    float hangablePunctuationStartWidth(unsigned index) const;
+    float hangablePunctuationEndWidth(unsigned index) const;
+    unsigned firstCharacterIndexStrippingSpaces() const;
+    unsigned lastCharacterIndexStrippingSpaces() const;
</ins><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT virtual IntRect linesBoundingBox() const;
</span><span class="cx">     LayoutRect linesVisualOverflowBoundingBox() const;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderinglineBreakingContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/line/BreakingContext.h (197518 => 197519)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/line/BreakingContext.h        2016-03-03 21:46:07 UTC (rev 197518)
+++ trunk/Source/WebCore/rendering/line/BreakingContext.h        2016-03-03 21:49:32 UTC (rev 197519)
</span><span class="lines">@@ -738,7 +738,8 @@
</span><span class="cx">     bool isFixedPitch = font.isFixedPitch();
</span><span class="cx">     bool canHyphenate = style.hyphens() == HyphensAuto &amp;&amp; WebCore::canHyphenate(style.locale());
</span><span class="cx">     bool canHangPunctuationAtStart = style.hangingPunctuation() &amp; FirstHangingPunctuation;
</span><del>-    
</del><ins>+    bool canHangPunctuationAtEnd = style.hangingPunctuation() &amp; LastHangingPunctuation;
+    int endPunctuationIndex = canHangPunctuationAtEnd &amp;&amp; m_collapseWhiteSpace ? renderText.lastCharacterIndexStrippingSpaces() : renderText.textLength() - 1;
</ins><span class="cx">     unsigned lastSpace = m_current.offset();
</span><span class="cx">     float wordSpacing = m_currentStyle-&gt;fontCascade().wordSpacing();
</span><span class="cx">     float lastSpaceWordSpacing = 0;
</span><span class="lines">@@ -788,9 +789,16 @@
</span><span class="cx">         UChar c = m_current.current();
</span><span class="cx">         m_currentCharacterIsSpace = c == ' ' || c == '\t' || (!m_preservesNewline &amp;&amp; (c == '\n'));
</span><span class="cx"> 
</span><del>-        if (canHangPunctuationAtStart &amp;&amp; !m_current.offset() &amp;&amp; m_width.isFirstLine() &amp;&amp; !m_width.committedWidth() &amp;&amp; !wrapW &amp;&amp; !m_current.offset())
-            m_width.addUncommittedWidth(-renderText.hangablePunctuationStartWidth());
-            
</del><ins>+        if (canHangPunctuationAtStart &amp;&amp; m_width.isFirstLine() &amp;&amp; !m_width.committedWidth() &amp;&amp; !wrapW &amp;&amp; !inlineLogicalWidth(m_current.renderer(), true, false)) {
+            m_width.addUncommittedWidth(-renderText.hangablePunctuationStartWidth(m_current.offset()));
+            canHangPunctuationAtStart = false;
+        }
+        
+        if (canHangPunctuationAtEnd &amp;&amp; !m_nextObject &amp;&amp; (int)m_current.offset() == endPunctuationIndex &amp;&amp; !inlineLogicalWidth(m_current.renderer(), false, true)) {
+            m_width.addUncommittedWidth(-renderText.hangablePunctuationEndWidth(endPunctuationIndex));
+            canHangPunctuationAtStart = false;
+        }
+
</ins><span class="cx">         if (!m_collapseWhiteSpace || !m_currentCharacterIsSpace)
</span><span class="cx">             m_lineInfo.setEmpty(false, &amp;m_block, &amp;m_width);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>