<!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>[184714] branches/safari-601.1.32.2-branch</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/184714">184714</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2015-05-21 08:24:21 -0700 (Thu, 21 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/184308">r184308</a>.  rdar://problem/20895753</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6011322branchLayoutTestsChangeLog">branches/safari-601.1.32.2-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari6011322branchSourceWebCoreChangeLog">branches/safari-601.1.32.2-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari6011322branchSourceWebCoreeditingEditingStylecpp">branches/safari-601.1.32.2-branch/Source/WebCore/editing/EditingStyle.cpp</a></li>
<li><a href="#branchessafari6011322branchSourceWebCoreeditingEditingStyleh">branches/safari-601.1.32.2-branch/Source/WebCore/editing/EditingStyle.h</a></li>
<li><a href="#branchessafari6011322branchSourceWebCoreeditingEditorcpp">branches/safari-601.1.32.2-branch/Source/WebCore/editing/Editor.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari6011322branchLayoutTestseditingstyleunderlinebyuserexpectedtxt">branches/safari-601.1.32.2-branch/LayoutTests/editing/style/underline-by-user-expected.txt</a></li>
<li><a href="#branchessafari6011322branchLayoutTestseditingstyleunderlinebyuserhtml">branches/safari-601.1.32.2-branch/LayoutTests/editing/style/underline-by-user.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6011322branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.32.2-branch/LayoutTests/ChangeLog (184713 => 184714)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.32.2-branch/LayoutTests/ChangeLog        2015-05-21 12:29:43 UTC (rev 184713)
+++ branches/safari-601.1.32.2-branch/LayoutTests/ChangeLog        2015-05-21 15:24:21 UTC (rev 184714)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2015-05-20  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
+        Merge r184308.
+
+    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-18  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r184510. rdar://problem/21004989
</span></span></pre></div>
<a id="branchessafari6011322branchLayoutTestseditingstyleunderlinebyuserexpectedtxtfromrev184308trunkLayoutTestseditingstyleunderlinebyuserexpectedtxt"></a>
<div class="copfile"><h4>Copied: branches/safari-601.1.32.2-branch/LayoutTests/editing/style/underline-by-user-expected.txt (from rev 184308, trunk/LayoutTests/editing/style/underline-by-user-expected.txt) (0 => 184714)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.32.2-branch/LayoutTests/editing/style/underline-by-user-expected.txt                                (rev 0)
+++ branches/safari-601.1.32.2-branch/LayoutTests/editing/style/underline-by-user-expected.txt        2015-05-21 15:24:21 UTC (rev 184714)
</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="branchessafari6011322branchLayoutTestseditingstyleunderlinebyuserhtmlfromrev184308trunkLayoutTestseditingstyleunderlinebyuserhtml"></a>
<div class="copfile"><h4>Copied: branches/safari-601.1.32.2-branch/LayoutTests/editing/style/underline-by-user.html (from rev 184308, trunk/LayoutTests/editing/style/underline-by-user.html) (0 => 184714)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.32.2-branch/LayoutTests/editing/style/underline-by-user.html                                (rev 0)
+++ branches/safari-601.1.32.2-branch/LayoutTests/editing/style/underline-by-user.html        2015-05-21 15:24:21 UTC (rev 184714)
</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="branchessafari6011322branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.32.2-branch/Source/WebCore/ChangeLog (184713 => 184714)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.32.2-branch/Source/WebCore/ChangeLog        2015-05-21 12:29:43 UTC (rev 184713)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/ChangeLog        2015-05-21 15:24:21 UTC (rev 184714)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2015-05-20  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
+        Merge r184308.
+
+    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-20  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r184654. rdar://problem/21044514
</span></span></pre></div>
<a id="branchessafari6011322branchSourceWebCoreeditingEditingStylecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.32.2-branch/Source/WebCore/editing/EditingStyle.cpp (184713 => 184714)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.32.2-branch/Source/WebCore/editing/EditingStyle.cpp        2015-05-21 12:29:43 UTC (rev 184713)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/editing/EditingStyle.cpp        2015-05-21 15:24:21 UTC (rev 184714)
</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="branchessafari6011322branchSourceWebCoreeditingEditingStyleh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.32.2-branch/Source/WebCore/editing/EditingStyle.h (184713 => 184714)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.32.2-branch/Source/WebCore/editing/EditingStyle.h        2015-05-21 12:29:43 UTC (rev 184713)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/editing/EditingStyle.h        2015-05-21 15:24:21 UTC (rev 184714)
</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="branchessafari6011322branchSourceWebCoreeditingEditorcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.32.2-branch/Source/WebCore/editing/Editor.cpp (184713 => 184714)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.32.2-branch/Source/WebCore/editing/Editor.cpp        2015-05-21 12:29:43 UTC (rev 184713)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/editing/Editor.cpp        2015-05-21 15:24:21 UTC (rev 184714)
</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>