LayoutTests:
authorharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jul 2006 17:24:22 +0000 (17:24 +0000)
committerharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jul 2006 17:24:22 +0000 (17:24 +0000)
        <rdar://problem/4629307> -[DOMRange markupString] does not include the initial table element if it is at the beginning of the range
        <rdar://problem/4062218> pasting in contents of web.apple.com strips off the <table> element from the first table

        (this really only tests the symptoms of <rdar://problem/4062218>, because -[DOMRange markupString] is not testable)

        * editing/pasteboard/paste-table-003-expected.checksum: Added.
        * editing/pasteboard/paste-table-003-expected.png: Added.
        * editing/pasteboard/paste-table-003-expected.txt: Added.
        * editing/pasteboard/paste-table-003.html: Added.

WebCore:

        Reviewed by Tim Hatcher.

        <rdar://problem/4629307> -[DOMRange markupString] does not include the initial table element if it is at the beginning of the range
        <rdar://problem/4062218> pasting in contents of web.apple.com strips off the <table> element from the first table

        Better patch than previous checkin.

        * test: editing/pasteboard/paste-table-003.html

        * editing/markup.cpp:
        (WebCore::createMarkup):
        Make sure to include the table when including a tbody.

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

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/paste-table-003-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/paste-table-003-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/paste-table-003-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/paste-table-003.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/markup.cpp

index 31a039c21f9fa03a4145f35a0b85ddfa5f9dfdf4..cc6cd8312f0b20e635dcb6582c63e9b432e0ae8a 100644 (file)
@@ -1,3 +1,15 @@
+2006-07-19  David Harrison  <harrison@apple.com>
+
+        <rdar://problem/4629307> -[DOMRange markupString] does not include the initial table element if it is at the beginning of the range
+        <rdar://problem/4062218> pasting in contents of web.apple.com strips off the <table> element from the first table
+
+        (this really only tests the symptoms of <rdar://problem/4062218>, because -[DOMRange markupString] is not testable)
+        
+        * editing/pasteboard/paste-table-003-expected.checksum: Added.
+        * editing/pasteboard/paste-table-003-expected.png: Added.
+        * editing/pasteboard/paste-table-003-expected.txt: Added.
+        * editing/pasteboard/paste-table-003.html: Added.
+
 2006-07-18  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Adele Peterson.
diff --git a/LayoutTests/editing/pasteboard/paste-table-003-expected.checksum b/LayoutTests/editing/pasteboard/paste-table-003-expected.checksum
new file mode 100644 (file)
index 0000000..e4d0b8f
--- /dev/null
@@ -0,0 +1 @@
+00eb248dca688216f1341399284e4d66
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/paste-table-003-expected.png b/LayoutTests/editing/pasteboard/paste-table-003-expected.png
new file mode 100644 (file)
index 0000000..b66d014
Binary files /dev/null and b/LayoutTests/editing/pasteboard/paste-table-003-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/paste-table-003-expected.txt b/LayoutTests/editing/pasteboard/paste-table-003-expected.txt
new file mode 100644 (file)
index 0000000..d298b90
--- /dev/null
@@ -0,0 +1,38 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of BODY > HTML > #document to 5 of BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 9 of #text > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 2 of TD > TR > TBODY > TABLE > DIV > BODY > HTML > #document to 2 of TD > TR > TBODY > TABLE > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+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 784x584
+      RenderTable {TABLE} at (0,0) size 57x24
+        RenderTableSection {TBODY} at (0,0) size 57x24
+          RenderTableRow {TR} at (0,2) size 57x20
+            RenderTableCell {TD} at (2,2) size 25x20 [r=0 c=0 rs=1 cs=1]
+              RenderText {#text} at (1,1) size 23x18
+                text run at (1,1) width 23: "one"
+            RenderTableCell {TD} at (29,2) size 26x20 [r=0 c=1 rs=1 cs=1]
+              RenderText {#text} at (1,1) size 24x18
+                text run at (1,1) width 24: "two"
+      RenderBlock {DIV} at (0,24) size 784x60
+        RenderTable {TABLE} at (0,0) size 57x42
+          RenderTableSection {TBODY} at (0,0) size 57x42
+            RenderTableRow {TR} at (0,2) size 57x38
+              RenderTableCell {TD} at (2,11) size 25x20 [r=0 c=0 rs=1 cs=1]
+                RenderText {#text} at (1,1) size 23x18
+                  text run at (1,1) width 23: "one"
+              RenderTableCell {TD} at (29,2) size 26x38 [r=0 c=1 rs=1 cs=1]
+                RenderText {#text} at (1,1) size 24x18
+                  text run at (1,1) width 24: "two"
+                RenderBR {BR} at (25,15) size 0x0
+                RenderBR {BR} at (1,19) size 0x18
+        RenderBlock (anonymous) at (0,42) size 784x18
+          RenderBR {BR} at (0,0) size 0x18
+caret: position 0 of child 2 {BR} of child 1 {TD} of child 0 {TR} of child 0 {TBODY} of child 0 {TABLE} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/paste-table-003.html b/LayoutTests/editing/pasteboard/paste-table-003.html
new file mode 100644 (file)
index 0000000..e65e94f
--- /dev/null
@@ -0,0 +1,45 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+.scenario { margin-bottom: 16px;}
+.scenario:first-line { font-weight: bold; margin-bottom: 16px;}
+.expected-results:first-line { font-weight: bold }
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+function editingTest() {
+       var r = document.getElementById("root");
+    setSelectionCommand(r, 0, r, 1);
+       copyCommand();
+       
+       var e = document.getElementById("target");
+    setSelectionCommand(e, 0, e, 1);
+    pasteCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body id="root" contenteditable><table id="test">
+<tbody><tr><td>one</td><td>two</td></tr></tbody></table>
+<div id="target">replaceme</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index 98fc86d052561dcf1e2bdb07781a54e97eff1515..2a806bcea44cc2a460f656798cbec5e200afcddb 100644 (file)
@@ -1,3 +1,18 @@
+2006-07-19  David Harrison  <harrison@apple.com>
+
+        Reviewed by Tim Hatcher.
+
+        <rdar://problem/4629307> -[DOMRange markupString] does not include the initial table element if it is at the beginning of the range
+        <rdar://problem/4062218> pasting in contents of web.apple.com strips off the <table> element from the first table
+        
+        Better patch than previous checkin.
+
+        * test: editing/pasteboard/paste-table-003.html
+        
+        * editing/markup.cpp:
+        (WebCore::createMarkup):
+        Make sure to include the table when including a tbody.
+
 === Safari-521.19 ===
 
 2006-07-19  David Harrison  <harrison@apple.com>
index 0c491dbeb396e96b84288d64ab0637424e6def53..8cea44921f182feb22cb1b10fce05adfb881000d 100644 (file)
@@ -311,7 +311,6 @@ DeprecatedString createMarkup(const Range *range, DeprecatedPtrList<Node> *nodes
     Node *pastEnd = range->pastEndNode();
     Node *lastClosed = 0;
     DeprecatedPtrList<Node> ancestorsToClose;
-    bool prependNewline = false;
 
     // calculate the "default style" for this markup
     Position pos(doc->documentElement(), 0);
@@ -325,15 +324,23 @@ DeprecatedString createMarkup(const Range *range, DeprecatedPtrList<Node> *nodes
     if (!inSameBlock(visibleStart, visibleStart.next())) {
         if (visibleStart == visibleEnd.previous())
             return interchangeNewlineString;
-        
-        // remember to prepend newline later, after prepending any ancestors
-        prependNewline = true;
+            
+        // FIXME: This adds a newline, but a later add of the ancestor could go before that newline (e.g. when startNode is tbody,
+        // we will later add a table, but the interchangeNewlineString will appear between the table and the tbody! for now, that
+        // does not happen with tables because of code below that moves startNode to the table when at tbody)
+        markups.append(interchangeNewlineString);
         startNode = startNode->traverseNextNode();
     }
-    
-    Node *rangeStartNode = startNode;
-    int rangeStartOffset = startNode == range->startNode() ? range->startOffset(ec) : 0;
-    ASSERT(ec == 0);
+
+    // no use having a tbody without its table
+    // NOTE: need sibling check because startNode might be anonymous text (like newlines)
+    // FIXME: This would not be needed if ancestor adding applied to more than just the lastClosed
+    for (Node *n = startNode; n; n = n->nextSibling()) {
+        if (n->hasTagName(tbodyTag)) {
+            startNode = startNode->parent();
+            break;
+        }
+    }
 
     // Iterate through the nodes of the range.
     Node *next;
@@ -391,6 +398,10 @@ DeprecatedString createMarkup(const Range *range, DeprecatedPtrList<Node> *nodes
             ancestorsToClose.append(n);
     }
     
+    Node *rangeStartNode = range->startNode();
+    int rangeStartOffset = range->startOffset(ec);
+    ASSERT(ec == 0);
+    
     // Add ancestors up to the common ancestor block so inline ancestors such as FONT and B are part of the markup.
     if (lastClosed) {
         for (Node *ancestor = lastClosed->parentNode(); ancestor; ancestor = ancestor->parentNode()) {
@@ -421,8 +432,6 @@ DeprecatedString createMarkup(const Range *range, DeprecatedPtrList<Node> *nodes
         }
     }
 
-    if (prependNewline)
-        markups.prepend(interchangeNewlineString);
     if (annotate) {
         if (!inSameBlock(visibleEnd, visibleEnd.previous()))
             markups.append(interchangeNewlineString);