<!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>[184308] 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/184308">184308</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2015-05-13 14:58:41 -0700 (Wed, 13 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>REGRESSION(<a href="http://trac.webkit.org/projects/webkit/changeset/183770">r183770</a>): Crash inside WebEditorClient::shouldApplyStyle when applying underline
https://bugs.webkit.org/show_bug.cgi?id=144949
Source/WebCore:

&lt;rdar://problem/20895753&gt;

Reviewed by Darin Adler.

The crash was caused by the variant of applyStyleToSelection that takes EditingStyle passing
a null pointer to shouldApplyStyle when we're only applying text decoration changes so that
m_mutableStyle in the editing style is null. This didn't reproduce in execCommand since we
wouldn't call shouldApplyStyle in that case. It didn't reproduce in my manual testing because
font panel also sets text shadow, which ends up filling up m_mutableStyle.

Fixed the bug by creating a mutable style properties when one is not provided by EditingStyle.
Also fixed the &quot;FIXME&quot; in the function by converting text decoration changes to a corresponding
text decoration value. The values passed to shouldApplyStyle now matches the old behavior prior
to <a href="http://trac.webkit.org/projects/webkit/changeset/183770">r183770</a>.

Test: editing/style/underline-by-user.html

* editing/EditingStyle.cpp:
(WebCore::EditingStyle::styleWithResolvedTextDecorations): Added.
* editing/EditingStyle.h:
* editing/Editor.cpp:
(WebCore::Editor::applyStyleToSelection): Use styleWithResolvedTextDecorations to avoid the crash.

LayoutTests:


Reviewed by Darin Adler.

Added a test that emulates underlining of text by the user. Unlike document.execCommand,
testRunner.execCommand simulates a user initiated editing command and therefore invokes
shouldApplyStyle.

* editing/style/underline-by-user-expected.txt: Added.
* editing/style/underline-by-user.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="#trunkSourceWebCoreeditingEditingStylecpp">trunk/Source/WebCore/editing/EditingStyle.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingEditingStyleh">trunk/Source/WebCore/editing/EditingStyle.h</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorcpp">trunk/Source/WebCore/editing/Editor.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingstyleunderlinebyuserexpectedtxt">trunk/LayoutTests/editing/style/underline-by-user-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingstyleunderlinebyuserhtml">trunk/LayoutTests/editing/style/underline-by-user.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (184307 => 184308)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-05-13 21:37:50 UTC (rev 184307)
+++ trunk/LayoutTests/ChangeLog        2015-05-13 21:58:41 UTC (rev 184308)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-05-13  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        REGRESSION(r183770): Crash inside WebEditorClient::shouldApplyStyle when applying underline
+        https://bugs.webkit.org/show_bug.cgi?id=144949
+
+        Reviewed by Darin Adler.
+
+        Added a test that emulates underlining of text by the user. Unlike document.execCommand,
+        testRunner.execCommand simulates a user initiated editing command and therefore invokes
+        shouldApplyStyle.
+
+        * editing/style/underline-by-user-expected.txt: Added.
+        * editing/style/underline-by-user.html: Added.
+
</ins><span class="cx"> 2015-05-13  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [ES6] Implement String.raw
</span></span></pre></div>
<a id="trunkLayoutTestseditingstyleunderlinebyuserexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/style/underline-by-user-expected.txt (0 => 184308)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/style/underline-by-user-expected.txt                                (rev 0)
+++ trunk/LayoutTests/editing/style/underline-by-user-expected.txt        2015-05-13 21:58:41 UTC (rev 184308)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+This tests user initialized underlining of text. To manually test, underline &quot;hello&quot; below. WebKit should not crash.
+
+hello
</ins></span></pre></div>
<a id="trunkLayoutTestseditingstyleunderlinebyuserhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/style/underline-by-user.html (0 => 184308)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/style/underline-by-user.html                                (rev 0)
+++ trunk/LayoutTests/editing/style/underline-by-user.html        2015-05-13 21:58:41 UTC (rev 184308)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;p&gt;This tests user initialized underlining of text. To manually test, underline &quot;hello&quot; below. WebKit should not crash.&lt;/p&gt;
+&lt;div id=&quot;editor&quot; contenteditable&gt;hello&lt;/div&gt;
+&lt;script&gt;
+document.getElementById('editor').focus();
+document.execCommand('selectAll', false, null);
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.execCommand('underline', false, null);
+}
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (184307 => 184308)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-05-13 21:37:50 UTC (rev 184307)
+++ trunk/Source/WebCore/ChangeLog        2015-05-13 21:58:41 UTC (rev 184308)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2015-05-13  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        REGRESSION(r183770): Crash inside WebEditorClient::shouldApplyStyle when applying underline
+        https://bugs.webkit.org/show_bug.cgi?id=144949
+        &lt;rdar://problem/20895753&gt;
+
+        Reviewed by Darin Adler.
+
+        The crash was caused by the variant of applyStyleToSelection that takes EditingStyle passing
+        a null pointer to shouldApplyStyle when we're only applying text decoration changes so that
+        m_mutableStyle in the editing style is null. This didn't reproduce in execCommand since we
+        wouldn't call shouldApplyStyle in that case. It didn't reproduce in my manual testing because
+        font panel also sets text shadow, which ends up filling up m_mutableStyle.
+
+        Fixed the bug by creating a mutable style properties when one is not provided by EditingStyle.
+        Also fixed the &quot;FIXME&quot; in the function by converting text decoration changes to a corresponding
+        text decoration value. The values passed to shouldApplyStyle now matches the old behavior prior
+        to r183770.
+
+        Test: editing/style/underline-by-user.html
+
+        * editing/EditingStyle.cpp:
+        (WebCore::EditingStyle::styleWithResolvedTextDecorations): Added.
+        * editing/EditingStyle.h:
+        * editing/Editor.cpp:
+        (WebCore::Editor::applyStyleToSelection): Use styleWithResolvedTextDecorations to avoid the crash.
+
</ins><span class="cx"> 2015-05-13  Eric Carlson  &lt;eric.carlson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Work around HTMLMediaElement::documentDidResumeFromPageCache being called twice
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditingStylecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (184307 => 184308)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/EditingStyle.cpp        2015-05-13 21:37:50 UTC (rev 184307)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp        2015-05-13 21:58:41 UTC (rev 184308)
</span><span class="lines">@@ -525,6 +525,28 @@
</span><span class="cx">         &amp;&amp; underlineChange() == TextDecorationChange::None &amp;&amp; strikeThroughChange() == TextDecorationChange::None;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Ref&lt;MutableStyleProperties&gt; EditingStyle::styleWithResolvedTextDecorations() const
+{
+    bool hasTextDecorationChanges = underlineChange() != TextDecorationChange::None || strikeThroughChange() != TextDecorationChange::None;
+    if (m_mutableStyle &amp;&amp; !hasTextDecorationChanges)
+        return *m_mutableStyle;
+
+    Ref&lt;MutableStyleProperties&gt; style = m_mutableStyle ? m_mutableStyle-&gt;mutableCopy() : MutableStyleProperties::create();
+
+    Ref&lt;CSSValueList&gt; valueList = CSSValueList::createSpaceSeparated();
+    if (underlineChange() == TextDecorationChange::Add)
+        valueList-&gt;append(cssValuePool().createIdentifierValue(CSSValueUnderline));
+    if (strikeThroughChange() == TextDecorationChange::Add)
+        valueList-&gt;append(cssValuePool().createIdentifierValue(CSSValueLineThrough));
+
+    if (valueList-&gt;length())
+        style-&gt;setProperty(CSSPropertyTextDecoration, valueList.ptr());
+    else
+        style-&gt;setProperty(CSSPropertyTextDecoration, cssValuePool().createIdentifierValue(CSSValueNone));
+
+    return style;
+}
+
</ins><span class="cx"> bool EditingStyle::textDirection(WritingDirection&amp; writingDirection) const
</span><span class="cx"> {
</span><span class="cx">     if (!m_mutableStyle)
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditingStyleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/EditingStyle.h (184307 => 184308)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/EditingStyle.h        2015-05-13 21:37:50 UTC (rev 184307)
+++ trunk/Source/WebCore/editing/EditingStyle.h        2015-05-13 21:58:41 UTC (rev 184308)
</span><span class="lines">@@ -112,6 +112,7 @@
</span><span class="cx">     WEBCORE_EXPORT ~EditingStyle();
</span><span class="cx"> 
</span><span class="cx">     MutableStyleProperties* style() { return m_mutableStyle.get(); }
</span><ins>+    Ref&lt;MutableStyleProperties&gt; styleWithResolvedTextDecorations() const;
</ins><span class="cx">     bool textDirection(WritingDirection&amp;) const;
</span><span class="cx">     bool isEmpty() const;
</span><span class="cx">     void setStyle(PassRefPtr&lt;MutableStyleProperties&gt;);
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.cpp (184307 => 184308)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.cpp        2015-05-13 21:37:50 UTC (rev 184307)
+++ trunk/Source/WebCore/editing/Editor.cpp        2015-05-13 21:58:41 UTC (rev 184308)
</span><span class="lines">@@ -947,7 +947,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     // FIXME: This is wrong for text decorations since m_mutableStyle is empty.
</span><del>-    if (!client() || !client()-&gt;shouldApplyStyle(style-&gt;style(), m_frame.selection().toNormalizedRange().get()))
</del><ins>+    if (!client() || !client()-&gt;shouldApplyStyle(style-&gt;styleWithResolvedTextDecorations().ptr(), m_frame.selection().toNormalizedRange().get()))
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     applyStyle(WTF::move(style), editingAction);
</span></span></pre>
</div>
</div>

</body>
</html>