<!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>[196782] 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/196782">196782</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2016-02-18 15:48:19 -0800 (Thu, 18 Feb 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Soft hyphen is not shown when it is placed at the end of an inline element
https://bugs.webkit.org/show_bug.cgi?id=153980

Reviewed by David Hyatt.

This patch handles the case when the character at the breaking position does not fit the
line and soft-hyphen, as the first breaking opportunity, is followed by this overflowing character.
(foo&amp;shy;bar where b overflows the line).
In such cases we don't yet have an item in the breaking history so we need to take a look at
the current context instead.

Source/WebCore:

Test: fast/text/soft-hyphen-as-first-breaking-opportunity.html

* rendering/line/BreakingContext.h:
(WebCore::BreakingContext::InlineIteratorHistory::nextBreakablePosition):
(WebCore::BreakingContext::handleText):

LayoutTests:

* fast/text/soft-hyphen-as-first-breaking-opportunity-expected.html: Added.
* fast/text/soft-hyphen-as-first-breaking-opportunity.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="#trunkSourceWebCorerenderinglineBreakingContexth">trunk/Source/WebCore/rendering/line/BreakingContext.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttextsofthyphenasfirstbreakingopportunityexpectedhtml">trunk/LayoutTests/fast/text/soft-hyphen-as-first-breaking-opportunity-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttextsofthyphenasfirstbreakingopportunityhtml">trunk/LayoutTests/fast/text/soft-hyphen-as-first-breaking-opportunity.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (196781 => 196782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-02-18 23:43:57 UTC (rev 196781)
+++ trunk/LayoutTests/ChangeLog        2016-02-18 23:48:19 UTC (rev 196782)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2016-02-18  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+        Soft hyphen is not shown when it is placed at the end of an inline element
+        https://bugs.webkit.org/show_bug.cgi?id=153980
+
+        Reviewed by David Hyatt.
+
+        This patch handles the case when the character at the breaking position does not fit the
+        line and soft-hyphen, as the first breaking opportunity, is followed by this overflowing character.
+        (foo&amp;shy;bar where b overflows the line).
+        In such cases we don't yet have an item in the breaking history so we need to take a look at
+        the current context instead.    
+
+        * fast/text/soft-hyphen-as-first-breaking-opportunity-expected.html: Added.
+        * fast/text/soft-hyphen-as-first-breaking-opportunity.html: Added.
+
</ins><span class="cx"> 2016-02-18  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Rebaseline imported/w3c/web-platform-tests/html/dom/interfaces.html for ios-simulator after r196770
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextsofthyphenasfirstbreakingopportunityexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/soft-hyphen-as-first-breaking-opportunity-expected.html (0 => 196782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/soft-hyphen-as-first-breaking-opportunity-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/soft-hyphen-as-first-breaking-opportunity-expected.html        2016-02-18 23:48:19 UTC (rev 196782)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+&lt;!DOCTYPE HTML&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;This tests that soft-hyphen is placed correctly when it is the first breaking opportunity.&lt;/title&gt;
+&lt;style&gt;
+.wrap {
+    width: 200px;
+    border: 1px solid;
+}
+.soft-hyphen {
+    color: red;
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;h2&gt;No extra element.&lt;/h2&gt;
+&lt;div class=&quot;wrap&quot;&gt;mmmmmmmmmmmmmm-mmmmmmmmmmmmmm
+&lt;/div&gt;
+&lt;h2&gt;Soft hyphen inside a styled span.&lt;/h2&gt;
+&lt;div class=&quot;wrap&quot;&gt;mmmmmmmmmmmmmm&lt;span class=&quot;soft-hyphen&quot;&gt;-&lt;/span&gt;mmmmmmmmmmmmmm
+&lt;/div&gt;
+&lt;h2&gt;Soft hyphen at the end of a styled span with text in it.&lt;/h2&gt;
+&lt;div class=&quot;wrap&quot;&gt;mmmmmmmmmmmmm&lt;span class=&quot;soft-hyphen&quot;&gt;m-&lt;/span&gt;mmmmmmmmmmmmmm
+&lt;/div&gt;
+&lt;h2&gt;Soft hyphen at the start of a styled span with text in it.&lt;/h2&gt;
+&lt;div class=&quot;wrap&quot;&gt;mmmmmmmmmmmmmm&lt;span class=&quot;soft-hyphen&quot;&gt;-m&lt;/span&gt;mmmmmmmmmmmmm
+&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextsofthyphenasfirstbreakingopportunityhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/soft-hyphen-as-first-breaking-opportunity.html (0 => 196782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/soft-hyphen-as-first-breaking-opportunity.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/soft-hyphen-as-first-breaking-opportunity.html        2016-02-18 23:48:19 UTC (rev 196782)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+&lt;!DOCTYPE HTML&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;This tests that soft-hyphen is placed correctly when it is the first breaking opportunity.&lt;/title&gt;
+&lt;style&gt;
+.wrap {
+    width: 200px;
+    border: 1px solid;
+}
+.soft-hyphen {
+    color: red;
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;h2&gt;No extra element.&lt;/h2&gt;
+&lt;div class=&quot;wrap&quot;&gt;mmmmmmmmmmmmmm&amp;shy;mmmmmmmmmmmmmm
+&lt;/div&gt;
+&lt;h2&gt;Soft hyphen inside a styled span.&lt;/h2&gt;
+&lt;div class=&quot;wrap&quot;&gt;mmmmmmmmmmmmmm&lt;span class=&quot;soft-hyphen&quot;&gt;&amp;shy;&lt;/span&gt;mmmmmmmmmmmmmm
+&lt;/div&gt;
+&lt;h2&gt;Soft hyphen at the end of a styled span with text in it.&lt;/h2&gt;
+&lt;div class=&quot;wrap&quot;&gt;mmmmmmmmmmmmm&lt;span class=&quot;soft-hyphen&quot;&gt;m&amp;shy;&lt;/span&gt;mmmmmmmmmmmmmm
+&lt;/div&gt;
+&lt;h2&gt;Soft hyphen at the start of a styled span with text in it.&lt;/h2&gt;
+&lt;div class=&quot;wrap&quot;&gt;mmmmmmmmmmmmmm&lt;span class=&quot;soft-hyphen&quot;&gt;&amp;shy;m&lt;/span&gt;mmmmmmmmmmmmm
+&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (196781 => 196782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-02-18 23:43:57 UTC (rev 196781)
+++ trunk/Source/WebCore/ChangeLog        2016-02-18 23:48:19 UTC (rev 196782)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-02-18  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+        Soft hyphen is not shown when it is placed at the end of an inline element
+        https://bugs.webkit.org/show_bug.cgi?id=153980
+
+        Reviewed by David Hyatt.
+
+        This patch handles the case when the character at the breaking position does not fit the
+        line and soft-hyphen, as the first breaking opportunity, is followed by this overflowing character.
+        (foo&amp;shy;bar where b overflows the line).
+        In such cases we don't yet have an item in the breaking history so we need to take a look at
+        the current context instead.    
+
+        Test: fast/text/soft-hyphen-as-first-breaking-opportunity.html
+
+        * rendering/line/BreakingContext.h:
+        (WebCore::BreakingContext::InlineIteratorHistory::nextBreakablePosition):
+        (WebCore::BreakingContext::handleText):
+
</ins><span class="cx"> 2016-02-18  Andreas Kling  &lt;akling@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fake memory pressure handler should log detailed memory breakdown.
</span></span></pre></div>
<a id="trunkSourceWebCorerenderinglineBreakingContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/line/BreakingContext.h (196781 => 196782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/line/BreakingContext.h        2016-02-18 23:43:57 UTC (rev 196781)
+++ trunk/Source/WebCore/rendering/line/BreakingContext.h        2016-02-18 23:48:19 UTC (rev 196782)
</span><span class="lines">@@ -200,6 +200,7 @@
</span><span class="cx"> 
</span><span class="cx">         RenderObject* renderer() const { return this-&gt;at(0).renderer(); }
</span><span class="cx">         unsigned offset() const { return this-&gt;at(0).offset(); }
</span><ins>+        int nextBreakablePosition() const { return this-&gt;at(0).nextBreakablePosition(); }
</ins><span class="cx">         bool atTextParagraphSeparator() const { return this-&gt;at(0).atTextParagraphSeparator(); }
</span><span class="cx">         UChar previousInSameNode() const { return this-&gt;at(0).previousInSameNode(); }
</span><span class="cx">         const InlineIterator&amp; get(size_t i) const { return this-&gt;at(i); };
</span><span class="lines">@@ -776,6 +777,7 @@
</span><span class="cx">     // Non-zero only when kerning is enabled and TextLayout isn't used, in which case we measure
</span><span class="cx">     // words with their trailing space, then subtract its width.
</span><span class="cx">     HashSet&lt;const Font*&gt; fallbackFonts;
</span><ins>+    UChar lastCharacterFromPreviousRenderText = m_renderTextInfo.lineBreakIterator.lastCharacter();
</ins><span class="cx">     UChar lastCharacter = m_renderTextInfo.lineBreakIterator.lastCharacter();
</span><span class="cx">     UChar secondToLastCharacter = m_renderTextInfo.lineBreakIterator.secondToLastCharacter();
</span><span class="cx">     WordTrailingSpace wordTrailingSpace(renderText, style, textLayout);
</span><span class="lines">@@ -903,8 +905,33 @@
</span><span class="cx">                         m_lineInfo.setPreviousLineBrokeCleanly(true);
</span><span class="cx">                         wordMeasurement.endOffset = m_lineBreakHistory.offset();
</span><span class="cx">                     }
</span><del>-                    if (m_lineBreakHistory.offset() &amp;&amp; downcast&lt;RenderText&gt;(m_lineBreakHistory.renderer()) &amp;&amp; downcast&lt;RenderText&gt;(*m_lineBreakHistory.renderer()).textLength() &amp;&amp; downcast&lt;RenderText&gt;(*m_lineBreakHistory.renderer()).characterAt(m_lineBreakHistory.offset() - 1) == softHyphen &amp;&amp; style.hyphens() != HyphensNone)
-                        hyphenated = true;
</del><ins>+                    // Check if the last breaking position is a soft-hyphen.
+                    if (!hyphenated &amp;&amp; style.hyphens() != HyphensNone) {
+                        Optional&lt;int&gt; lastBreakingPositon;
+                        const RenderObject* rendererAtBreakingPosition = nullptr;
+                        if (m_lineBreakHistory.offset() || m_lineBreakHistory.nextBreakablePosition() &gt; -1) {
+                            lastBreakingPositon = m_lineBreakHistory.offset();
+                            rendererAtBreakingPosition = m_lineBreakHistory.renderer();
+                        } else if (m_current.nextBreakablePosition() &gt; -1 &amp;&amp; (unsigned)m_current.nextBreakablePosition() &lt;= m_current.offset()) {
+                            // We might just be right after the soft-hyphen
+                            lastBreakingPositon = m_current.nextBreakablePosition();
+                            rendererAtBreakingPosition = m_current.renderer();
+                        }
+                        if (lastBreakingPositon) {
+                            Optional&lt;UChar&gt; characterBeforeBreakingPosition;
+                            // When last breaking position points to the start of the current context, we need to look at the last character from
+                            // the previous non-empty text renderer.
+                            if (!lastBreakingPositon.value())
+                                characterBeforeBreakingPosition = lastCharacterFromPreviousRenderText;
+                            else if (is&lt;RenderText&gt;(rendererAtBreakingPosition)) {
+                                const auto&amp; textRenderer = downcast&lt;RenderText&gt;(*rendererAtBreakingPosition);
+                                ASSERT(textRenderer.textLength() &gt; (unsigned)(lastBreakingPositon.value() - 1));
+                                characterBeforeBreakingPosition = textRenderer.characterAt(lastBreakingPositon.value() - 1);
+                            }
+                            if (characterBeforeBreakingPosition)
+                                hyphenated = characterBeforeBreakingPosition.value() == softHyphen;
+                        }
+                    }
</ins><span class="cx">                     if (m_lineBreakHistory.offset() &amp;&amp; m_lineBreakHistory.offset() != (unsigned)wordMeasurement.endOffset &amp;&amp; !wordMeasurement.width) {
</span><span class="cx">                         if (charWidth) {
</span><span class="cx">                             wordMeasurement.endOffset = m_lineBreakHistory.offset();
</span></span></pre>
</div>
</div>

</body>
</html>