LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Nov 2006 23:37:43 +0000 (23:37 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Nov 2006 23:37:43 +0000 (23:37 +0000)
        Reviewed by Oliver

        * editing/pasteboard/paste-unrendered-select-expected.checksum: Added.
        * editing/pasteboard/paste-unrendered-select-expected.png: Added.
        * editing/pasteboard/paste-unrendered-select-expected.txt: Added.
        * editing/pasteboard/paste-unrendered-select.html: Added.

WebCore:

        Reviewed by Oliver

        <rdar://problem/4820026>
        copy/paste of news.google.com yields text from hidden select element options

        We were adding descendants of unrendered select elements.

        * editing/markup.cpp:
        (WebCore::createMarkup): Don't traverse into nodes without renderers, unless
        they are grandfathered in by a rendered select element.

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

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

index 4eff9c9..7a1ce5c 100644 (file)
@@ -1,3 +1,12 @@
+2006-11-13  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Oliver
+
+        * editing/pasteboard/paste-unrendered-select-expected.checksum: Added.
+        * editing/pasteboard/paste-unrendered-select-expected.png: Added.
+        * editing/pasteboard/paste-unrendered-select-expected.txt: Added.
+        * editing/pasteboard/paste-unrendered-select.html: Added.
+
 2006-11-11  Rob Buis  <buis@kde.org>
 
         Reviewed by hyatt.
diff --git a/LayoutTests/editing/pasteboard/paste-unrendered-select-expected.checksum b/LayoutTests/editing/pasteboard/paste-unrendered-select-expected.checksum
new file mode 100644 (file)
index 0000000..d917539
--- /dev/null
@@ -0,0 +1 @@
+6b622c75c77f78ebc12738f5ce97156e
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/paste-unrendered-select-expected.png b/LayoutTests/editing/pasteboard/paste-unrendered-select-expected.png
new file mode 100644 (file)
index 0000000..296c3ec
Binary files /dev/null and b/LayoutTests/editing/pasteboard/paste-unrendered-select-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/paste-unrendered-select-expected.txt b/LayoutTests/editing/pasteboard/paste-unrendered-select-expected.txt
new file mode 100644 (file)
index 0000000..201b941
--- /dev/null
@@ -0,0 +1,22 @@
+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
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 570x18
+          text run at (0,0) width 288: "This tests copy/paste of an unrendered select. "
+          text run at (288,0) width 282: "The options inside of it should not be pasted."
+      RenderBlock {DIV} at (0,34) size 784x18
+        RenderText {#text} at (0,0) size 39x18
+          text run at (0,0) width 39: "Hello "
+        RenderText {#text} at (39,0) size 40x18
+          text run at (39,0) width 40: "World"
+      RenderBlock {DIV} at (0,52) size 784x18
+        RenderText {#text} at (0,0) size 35x18
+          text run at (0,0) width 35: "Hello"
+        RenderText {#text} at (35,0) size 4x18
+          text run at (35,0) width 4: " "
+        RenderText {#text} at (39,0) size 40x18
+          text run at (39,0) width 40: "World"
+caret: position 5 of child 2 {#text} of child 4 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/paste-unrendered-select.html b/LayoutTests/editing/pasteboard/paste-unrendered-select.html
new file mode 100644 (file)
index 0000000..a1af573
--- /dev/null
@@ -0,0 +1,14 @@
+<p>This tests copy/paste of an unrendered select.  The options inside of it should not be pasted.</p>
+<div id="copy" contenteditable="true">Hello <span style="display:none;"><select><option>1</option></select></span> World</div>
+<div id="paste" contenteditable="true"></div>
+
+<script>
+var copy = document.getElementById("copy");
+copy.focus();
+document.execCommand("SelectAll");
+document.execCommand("Copy");
+
+var paste = document.getElementById("paste");
+paste.focus();
+document.execCommand("Paste");
+</script>
index 619c454..ef6357a 100644 (file)
@@ -1,3 +1,16 @@
+2006-11-10  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Oliver
+        
+        <rdar://problem/4820026>
+        copy/paste of news.google.com yields text from hidden select element options
+
+        We were adding descendants of unrendered select elements. 
+
+        * editing/markup.cpp:
+        (WebCore::createMarkup): Don't traverse into nodes without renderers, unless 
+        they are grandfathered in by a rendered select element.
+        
 2006-11-12  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Sam Weinig.
index 15428c1..af80089 100644 (file)
@@ -354,22 +354,32 @@ DeprecatedString createMarkup(const Range *range, Vector<Node*>* nodes, EAnnotat
     Node *next;
     for (Node *n = startNode; n != pastEnd; n = next) {
         next = n->traverseNextNode();
+        bool skipDescendants = false;
+        bool addMarkupForNode = true;
+        
+        if (!n->renderer() && !enclosingNodeWithTag(n, selectTag)) {
+            skipDescendants = true;
+            addMarkupForNode = false;
+            next = n->traverseNextSibling();
+            // Don't skip over pastEnd.
+            if (pastEnd && pastEnd->isDescendantOf(n))
+                next = pastEnd;
+        }
 
         if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd)
             // Don't write out empty block containers that aren't fully selected.
             continue;
         
         // Add the node to the markup.
-        // FIXME: Add markup for nodes without renderers?  Also see the three checks below.
-        if (n->renderer() || enclosingNodeWithTag(n, selectTag)) {
+        if (addMarkupForNode) {
             markups.append(startMarkup(n, range, annotate, defaultStyle.get()));
             if (nodes)
                 nodes->append(n);
         }
         
-        if (n->firstChild() == 0) {
-            // Node has no children, add its close tag now.
-            if (n->renderer() || enclosingNodeWithTag(n, selectTag)) {
+        if (n->firstChild() == 0 || skipDescendants) {
+            // Node has no children, or we are skipping it's descendants, add its close tag now.
+            if (addMarkupForNode) {
                 markups.append(endMarkup(n));
                 lastClosed = n;
             }
@@ -407,8 +417,8 @@ DeprecatedString createMarkup(const Range *range, Vector<Node*>* nodes, EAnnotat
                     }
                 }
             }
-        } else if (n->renderer() || enclosingNodeWithTag(n, selectTag))
-            // Node is an ancestor, set it to close eventually.
+        } else if (addMarkupForNode && !skipDescendants)
+            // We added markup for this node, and we're descending into it.  Set it to close eventually.
             ancestorsToClose.append(n);
     }