From 9a1b9595f35d4debac748e157b37220c034e4659 Mon Sep 17 00:00:00 2001 From: liucougar Date: Sun, 1 Nov 2009 15:43:18 -0800 Subject: [PATCH] Bug 436703 - select all + Copy/paste in contenteditable div pastes the editable div inside itself, r=peterv --- content/base/src/nsDocumentEncoder.cpp | 11 +++++++++-- content/base/test/test_htmlcopyencoder.html | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/content/base/src/nsDocumentEncoder.cpp b/content/base/src/nsDocumentEncoder.cpp index a19777ff0e7b..1195ce908f06 100644 --- a/content/base/src/nsDocumentEncoder.cpp +++ b/content/base/src/nsDocumentEncoder.cpp @@ -1399,6 +1399,10 @@ nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr *ioNode, nsCOMPtr frontNode, endNode, parent; PRInt32 frontOffset, endOffset; + + //save the editable state of the ioNode, so we don't promote an ancestor if it has different editable state + nsCOMPtr node = do_QueryInterface(*ioNode); + PRBool isEditable = node->IsEditable(); // loop for as long as we can promote both endpoints while (!done) @@ -1415,8 +1419,11 @@ nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr *ioNode, // then we make the same attempt with the endpoint rv = GetPromotedPoint( kEnd, *ioNode, *ioEndOffset, address_of(endNode), &endOffset, parent); NS_ENSURE_SUCCESS(rv, rv); - // if both endpoints were promoted one level, keep looping - otherwise we are done. - if ( (frontNode != parent) || (endNode != parent) ) + + nsCOMPtr frontINode = do_QueryInterface(frontNode); + // if both endpoints were promoted one level and isEditable is the same as the original node, + // keep looping - otherwise we are done. + if ( (frontNode != parent) || (endNode != parent) || (frontINode->IsEditable() != isEditable) ) done = PR_TRUE; else { diff --git a/content/base/test/test_htmlcopyencoder.html b/content/base/test/test_htmlcopyencoder.html index df6d96680a07..c7dba4bbd527 100644 --- a/content/base/test/test_htmlcopyencoder.html +++ b/content/base/test/test_htmlcopyencoder.html @@ -157,6 +157,15 @@ function testHtmlCopyEncoder () { expected = '
    \n
  1. Lorem ipsum dolor
  2. \n
  3. sit amet, consectetuer
  4. \n
  5. adipiscing elit
  6. \n
  7. Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus \naliquet lectus. Nunc vitae eros. Class
  8. \n
  9. aptent taciti
  10. \n
'; is(out, expected, "test list selection with a value on a LI"); + //test Bug 436703 + node = document.getElementById('aContentEditable'); + select.selectAllChildren(node); + encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); + encoder.setSelection(select); + out = encoder.encodeToString(); + expected = '

one

two

'; + is(out, expected, "select all children in an contentEditable div should not select the div itself"); + SimpleTest.finish(); } @@ -183,5 +192,7 @@ addLoadEvent(testHtmlCopyEncoder); foo bar + +

one

two