WebCore:
authorjustin.garcia@apple.com <justin.garcia@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Dec 2007 07:43:26 +0000 (07:43 +0000)
committerjustin.garcia@apple.com <justin.garcia@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Dec 2007 07:43:26 +0000 (07:43 +0000)
        Reviewed by Oliver Hunt.

        <rdar://problem/5482023> 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 "|| !upstreamStart.node()->isDescendantOf(root)" 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.

        <rdar://problem/5482023> 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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28611 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/execCommand/5482023.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/editing/execCommand/5482023-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/FormatBlockCommand.cpp

index ced8629..356d14a 100644 (file)
@@ -1,3 +1,14 @@
+2007-12-10  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Oliver Hunt.
+        
+        <rdar://problem/5482023> 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.
+
 2007-12-10  Darin Adler  <darin@apple.com>
 
         Reviewed by Sam Weinig.
diff --git a/LayoutTests/editing/execCommand/5482023.html b/LayoutTests/editing/execCommand/5482023.html
new file mode 100644 (file)
index 0000000..abdb9b0
--- /dev/null
@@ -0,0 +1,11 @@
+<head>
+<script>
+function runTest() {
+    document.body.focus();
+    document.execCommand("FormatBlock", false, "h1");
+    document.execCommand("InsertText", false, "This tests for a bug when performing a FormatBlock inside a body with no visible content.  This text should be inside an h1 element.");
+}
+</script>
+</head>
+<body onload="runTest();" contenteditable="true">
+</body>
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.checksum
new file mode 100644 (file)
index 0000000..de3a2ea
--- /dev/null
@@ -0,0 +1 @@
+5b84455378b756fc872ae48aef37a3d3
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png
new file mode 100644 (file)
index 0000000..728ab71
Binary files /dev/null and b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.png differ
diff --git a/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt b/LayoutTests/platform/mac/editing/execCommand/5482023-expected.txt
new file mode 100644 (file)
index 0000000..33dd3c0
--- /dev/null
@@ -0,0 +1,12 @@
+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: "This tests for a bug when performing a FormatBlock "
+          text run at (0,37) width 779: "inside a body with no visible content.  This text should be"
+          text run at (779,37) width 5: " "
+          text run at (0,74) width 287: "inside an h1 element."
+caret: position 132 of child 0 {#text} of child 0 {H1} of child 1 {BODY} of child 0 {HTML} of document
index 5990c13..fea6413 100644 (file)
@@ -1,3 +1,23 @@
+2007-12-10  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        <rdar://problem/5482023> 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 "|| !upstreamStart.node()->isDescendantOf(root)" 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.
+
 2007-12-10  Adele Peterson  <adele@apple.com>
 
         Reviewed and partially fixed by Tim Hatcher.
index 85deafa..06a527d 100644 (file)
@@ -110,19 +110,24 @@ void FormatBlockCommand::doApply()
     RefPtr<Node> placeholder = createBreakElement(document());
     
     Node* root = endingSelection().start().node()->rootEditableElement();
-    if (refNode == root || root->isDescendantOf(refNode))
-        refNode = paragraphStart.deepEquivalent().node();
-    
-    Position upstreamStart = paragraphStart.deepEquivalent().upstream();
-    if ((validBlockTag(refNode->nodeName().lower()) && paragraphStart == blockStart && paragraphEnd == blockEnd) ||
-        !upstreamStart.node()->isDescendantOf(root))
+    if (validBlockTag(refNode->nodeName().lower()) && 
+        paragraphStart == blockStart && paragraphEnd == blockEnd && 
+        refNode != root && !root->isDescendantOf(refNode))
         // Already in a valid block tag that only contains the current paragraph, so we can swap with the new tag
         insertNodeBefore(blockNode.get(), refNode);
     else {
-        insertNodeAt(blockNode.get(), upstreamStart);
+        // Avoid inserting inside inline elements that surround paragraphStart with upstream().
+        // This is only to avoid creating bloated markup.
+        insertNodeAt(blockNode.get(), paragraphStart.deepEquivalent().upstream());
     }
     appendNode(placeholder.get(), blockNode.get());
-    moveParagraph(paragraphStart, paragraphEnd, VisiblePosition(Position(placeholder.get(), 0)), true, false);
+    
+    VisiblePosition destination(Position(placeholder.get(), 0));
+    if (paragraphStart == paragraphEnd) {
+        setEndingSelection(destination);
+        return;
+    }
+    moveParagraph(paragraphStart, paragraphEnd, destination, true, false);
 }
 
 }