<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#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>
<title>[28611] trunk</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/28611">28611</a></dd>
<dt>Author</dt> <dd>justin.garcia@apple.com</dd>
<dt>Date</dt> <dd>2007-12-10 23:43:26 -0800 (Mon, 10 Dec 2007)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebCore:

        Reviewed by Oliver Hunt.

        &lt;rdar://problem/5482023&gt; GoogleDocs: After FormatBlock in an empty document, certain functions are disabled
        
        We were trying to insert a block of the requested type before the body element.
        
        * editing/FormatBlockCommand.cpp:
        (WebCore::FormatBlockCommand::doApply): 
        Removed unnecessary ()s in the if condition.
        Removed &quot;|| !upstreamStart.node()-&gt;isDescendantOf(root)&quot; from the if condition, since
        a) upstreamStart will never be outside the root editable element, since in that case
        there would be no block inside the editable root to Format, and b) if upstreamStart.node() 
        *is* the root, then refNode is the root, and we shouldn't insert before the root, we should insert
        at [root, 0].
        Added comments to explain the use of upstream() in the second if-clause.
        Added an early return for case where there is nothing selected, in that case, there is nothing
        to move.

LayoutTests:

        Reviewed by Oliver Hunt.
        
        &lt;rdar://problem/5482023&gt; GoogleDocs: After performing FormatBlock in an empty document, certain functions are disabled

        * editing/execCommand/5482023.html: Added.
        * platform/mac/editing/execCommand/5482023-expected.checksum: Added.
        * platform/mac/editing/execCommand/5482023-expected.png: Added.
        * platform/mac/editing/execCommand/5482023-expected.txt: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCoreeditingFormatBlockCommandcpp">trunk/WebCore/editing/FormatBlockCommand.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingexecCommand5482023html">trunk/LayoutTests/editing/execCommand/5482023.html</a></li>
<li><a href="#trunkLayoutTestsplatformmaceditingexecCommand5482023expectedchecksum">trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum</a></li>
<li><a href="#trunkLayoutTestsplatformmaceditingexecCommand5482023expectedpng">trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png</a></li>
<li><a href="#trunkLayoutTestsplatformmaceditingexecCommand5482023expectedtxt">trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (28610 => 28611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2007-12-11 07:24:17 UTC (rev 28610)
+++ trunk/LayoutTests/ChangeLog        2007-12-11 07:43:26 UTC (rev 28611)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2007-12-10  Justin Garcia  &lt;justin.garcia@apple.com&gt;
+
+        Reviewed by Oliver Hunt.
+        
+        &lt;rdar://problem/5482023&gt; GoogleDocs: After performing FormatBlock in an empty document, certain functions are disabled
+
+        * editing/execCommand/5482023.html: Added.
+        * platform/mac/editing/execCommand/5482023-expected.checksum: Added.
+        * platform/mac/editing/execCommand/5482023-expected.png: Added.
+        * platform/mac/editing/execCommand/5482023-expected.txt: Added.
+
</ins><span class="cx"> 2007-12-10  Darin Adler  &lt;darin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Sam Weinig.
</span></span></pre></div>
<a id="trunkLayoutTestseditingexecCommand5482023html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/execCommand/5482023.html (0 => 28611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/execCommand/5482023.html                                (rev 0)
+++ trunk/LayoutTests/editing/execCommand/5482023.html        2007-12-11 07:43:26 UTC (rev 28611)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;head&gt;
+&lt;script&gt;
+function runTest() {
+    document.body.focus();
+    document.execCommand(&quot;FormatBlock&quot;, false, &quot;h1&quot;);
+    document.execCommand(&quot;InsertText&quot;, false, &quot;This tests for a bug when performing a FormatBlock inside a body with no visible content.  This text should be inside an h1 element.&quot;);
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest();&quot; contenteditable=&quot;true&quot;&gt;
+&lt;/body&gt;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmaceditingexecCommand5482023expectedchecksum"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum (0 => 28611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum                                (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum        2007-12-11 07:43:26 UTC (rev 28611)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+5b84455378b756fc872ae48aef37a3d3
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmaceditingexecCommand5482023expectedpng"></a>
<div class="binary"><h4>Added: trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png
</span><span class="cx">___________________________________________________________________
</span><span class="cx">Name: svn:mime-type
</span><span class="cx">   + application/octet-stream
</span><a id="trunkLayoutTestsplatformmaceditingexecCommand5482023expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt (0 => 28611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt                                (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt        2007-12-11 07:43:26 UTC (rev 28611)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x571
+      RenderBlock {H1} at (0,0) size 784x111
+        RenderText {#text} at (0,0) size 784x111
+          text run at (0,0) width 729: &quot;This tests for a bug when performing a FormatBlock &quot;
+          text run at (0,37) width 779: &quot;inside a body with no visible content.  This text should be&quot;
+          text run at (779,37) width 5: &quot; &quot;
+          text run at (0,74) width 287: &quot;inside an h1 element.&quot;
+caret: position 132 of child 0 {#text} of child 0 {H1} of child 1 {BODY} of child 0 {HTML} of document
</ins></span></pre></div>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (28610 => 28611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2007-12-11 07:24:17 UTC (rev 28610)
+++ trunk/WebCore/ChangeLog        2007-12-11 07:43:26 UTC (rev 28611)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2007-12-10  Justin Garcia  &lt;justin.garcia@apple.com&gt;
+
+        Reviewed by Oliver Hunt.
+
+        &lt;rdar://problem/5482023&gt; GoogleDocs: After FormatBlock in an empty document, certain functions are disabled
+        
+        We were trying to insert a block of the requested type before the body element.
+        
+        * editing/FormatBlockCommand.cpp:
+        (WebCore::FormatBlockCommand::doApply): 
+        Removed unnecessary ()s in the if condition.
+        Removed &quot;|| !upstreamStart.node()-&gt;isDescendantOf(root)&quot; from the if condition, since
+        a) upstreamStart will never be outside the root editable element, since in that case
+        there would be no block inside the editable root to Format, and b) if upstreamStart.node() 
+        *is* the root, then refNode is the root, and we shouldn't insert before the root, we should insert
+        at [root, 0].
+        Added comments to explain the use of upstream() in the second if-clause.
+        Added an early return for case where there is nothing selected, in that case, there is nothing
+        to move.
+
</ins><span class="cx"> 2007-12-10  Adele Peterson  &lt;adele@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed and partially fixed by Tim Hatcher.
</span></span></pre></div>
<a id="trunkWebCoreeditingFormatBlockCommandcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/editing/FormatBlockCommand.cpp (28610 => 28611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/editing/FormatBlockCommand.cpp        2007-12-11 07:24:17 UTC (rev 28610)
+++ trunk/WebCore/editing/FormatBlockCommand.cpp        2007-12-11 07:43:26 UTC (rev 28611)
</span><span class="lines">@@ -110,19 +110,24 @@
</span><span class="cx">     RefPtr&lt;Node&gt; placeholder = createBreakElement(document());
</span><span class="cx">     
</span><span class="cx">     Node* root = endingSelection().start().node()-&gt;rootEditableElement();
</span><del>-    if (refNode == root || root-&gt;isDescendantOf(refNode))
-        refNode = paragraphStart.deepEquivalent().node();
-    
-    Position upstreamStart = paragraphStart.deepEquivalent().upstream();
-    if ((validBlockTag(refNode-&gt;nodeName().lower()) &amp;&amp; paragraphStart == blockStart &amp;&amp; paragraphEnd == blockEnd) ||
-        !upstreamStart.node()-&gt;isDescendantOf(root))
</del><ins>+    if (validBlockTag(refNode-&gt;nodeName().lower()) &amp;&amp; 
+        paragraphStart == blockStart &amp;&amp; paragraphEnd == blockEnd &amp;&amp; 
+        refNode != root &amp;&amp; !root-&gt;isDescendantOf(refNode))
</ins><span class="cx">         // Already in a valid block tag that only contains the current paragraph, so we can swap with the new tag
</span><span class="cx">         insertNodeBefore(blockNode.get(), refNode);
</span><span class="cx">     else {
</span><del>-        insertNodeAt(blockNode.get(), upstreamStart);
</del><ins>+        // Avoid inserting inside inline elements that surround paragraphStart with upstream().
+        // This is only to avoid creating bloated markup.
+        insertNodeAt(blockNode.get(), paragraphStart.deepEquivalent().upstream());
</ins><span class="cx">     }
</span><span class="cx">     appendNode(placeholder.get(), blockNode.get());
</span><del>-    moveParagraph(paragraphStart, paragraphEnd, VisiblePosition(Position(placeholder.get(), 0)), true, false);
</del><ins>+    
+    VisiblePosition destination(Position(placeholder.get(), 0));
+    if (paragraphStart == paragraphEnd) {
+        setEndingSelection(destination);
+        return;
+    }
+    moveParagraph(paragraphStart, paragraphEnd, destination, true, false);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>