Backout bug 39098 due to Tinderbox orange.
authorMats Palmgren <matspal@gmail.com>
Fri, 21 May 2010 18:28:39 +0200
changeset 42536 f07f6896c00f26ab9b617b289fefe336bcfd270a
parent 42535 80499a657289161d6e679ca797304fe403122930
child 42537 05c4d3361afca3d1bc97b0048649374ebface6c0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs39098
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Backout bug 39098 due to Tinderbox orange.
content/base/public/nsIDocumentEncoder.idl
content/base/src/nsContentAreaDragDrop.cpp
content/base/src/nsCopySupport.cpp
content/base/src/nsDocumentEncoder.cpp
content/base/test/test_copypaste.html
layout/generic/nsSelection.cpp
--- a/content/base/public/nsIDocumentEncoder.idl
+++ b/content/base/public/nsIDocumentEncoder.idl
@@ -56,17 +56,17 @@ interface nsIDocumentEncoderNodeFixup : 
    * @param [OUT] aSerializeCloneKids True if the document encoder should
    * apply recursive serialization to the children of the fixed up node
    * instead of the children of the original node.
    * @return The resulting fixed up node.
    */
   nsIDOMNode fixupNode(in nsIDOMNode aNode, out boolean aSerializeCloneKids);
 };
 
-[scriptable, uuid(196a3aee-006e-4f8f-a420-e1c1b0958a26)]
+[scriptable, uuid(f85c5a20-258d-11db-a98b-0800200c9a66)]
 interface nsIDocumentEncoder : nsISupports
 {
   // Output methods flag bits. There are a frightening number of these,
   // because everyone wants something a little bit different
    
 
   /** 
    * Output only the selection (as opposed to the whole document).
@@ -211,23 +211,16 @@ interface nsIDocumentEncoder : nsISuppor
   /**
    * Normally when serializing the whole document using the HTML or 
    * XHTML serializer, the encoding declaration is rewritten to match.
    * This flag suppresses that behavior.
    */
   const unsigned long OutputDontRewriteEncodingDeclaration = (1 << 18);
   
   /**
-   * When using the HTML or XHTML serializer, skip elements that are not
-   * visible when this flag is set.  Elements are not visible when they
-   * have CSS style display:none or visibility:collapse, for example.
-   */
-  const unsigned long SkipInvisibleContent = (1 << 19);
-  
-  /**
    * Initialize with a pointer to the document and the mime type.
    * @param aDocument Document to encode.
    * @param aMimeType MimeType to use. May also be set by SetMimeType.
    * @param aFlags Flags to use while encoding. May also be set by SetFlags.
    */
   void init(in nsIDOMDocument aDocument,
             in AString aMimeType,
             in unsigned long aFlags);
--- a/content/base/src/nsContentAreaDragDrop.cpp
+++ b/content/base/src/nsContentAreaDragDrop.cpp
@@ -40,101 +40,73 @@
 
 // Local Includes
 #include "nsContentAreaDragDrop.h"
 
 // Helper Classes
 #include "nsString.h"
 
 // Interfaces needed to be included
-#include "nsCopySupport.h"
+#include "nsIVariant.h"
 #include "nsIDOMNSUIEvent.h"
 #include "nsIDOMUIEvent.h"
 #include "nsISelection.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMNSEvent.h"
 #include "nsIDOMDragEvent.h"
 #include "nsIDOMAbstractView.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMDocumentRange.h"
 #include "nsIDOMRange.h"
+#include "nsIDocumentEncoder.h"
 #include "nsIFormControl.h"
+#include "nsISelectionPrivate.h"
 #include "nsIDOMHTMLAreaElement.h"
 #include "nsIDOMHTMLAnchorElement.h"
 #include "nsITransferable.h"
 #include "nsComponentManagerUtils.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsServiceManagerUtils.h"
 #include "nsNetUtil.h"
 #include "nsIFile.h"
 #include "nsIWebNavigation.h"
 #include "nsIDocShell.h"
 #include "nsIContent.h"
 #include "nsIImageLoadingContent.h"
+#include "nsINameSpaceManager.h"
 #include "nsUnicharUtils.h"
 #include "nsIURL.h"
 #include "nsIDocument.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
 #include "nsIDocShellTreeItem.h"
+#include "nsIFrame.h"
 #include "nsRange.h"
 #include "nsIWebBrowserPersist.h"
 #include "nsEscape.h"
 #include "nsContentUtils.h"
 #include "nsIMIMEService.h"
 #include "imgIContainer.h"
 #include "imgIRequest.h"
+#include "nsContentCID.h"
 #include "nsDOMDataTransfer.h"
+#include "nsISelectionController.h"
+#include "nsFrameSelection.h"
+#include "nsWidgetsCID.h"
+
+static NS_DEFINE_CID(kHTMLConverterCID,        NS_HTMLFORMATCONVERTER_CID);
 
 // private clipboard data flavors for html copy, used by editor when pasting
 #define kHTMLContext   "text/_moz_htmlcontext"
 #define kHTMLInfo      "text/_moz_htmlinfo"
 
-nsresult NS_NewDomSelection(nsISelection **aDomSelection);
-
-// if inNode is null, use the selection from the window
-static nsresult
-GetTransferableForNodeOrSelection(nsIDOMWindow*     aWindow,
-                                  nsIContent*       aNode,
-                                  nsITransferable** aTransferable)
-{
-  NS_ENSURE_ARG_POINTER(aWindow);
-
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aWindow->GetDocument(getter_AddRefs(domDoc));
-  NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
-  nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
-
-  nsresult rv;
-  nsCOMPtr<nsISelection> selection;
-  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
-  if (node) {
-    // Make a temporary selection with this node in a single range.
-    rv = NS_NewDomSelection(getter_AddRefs(selection));
-    NS_ENSURE_SUCCESS(rv, rv);
-    nsCOMPtr<nsIDOMRange> range;
-    rv = NS_NewRange(getter_AddRefs(range));
-    NS_ENSURE_SUCCESS(rv, rv);
-    rv = range->SelectNode(node);
-    NS_ENSURE_SUCCESS(rv, rv);
-    rv = selection->AddRange(range);
-    NS_ENSURE_SUCCESS(rv, rv);
-  } else {
-    aWindow->GetSelection(getter_AddRefs(selection));
-  }
-
-  rv = nsCopySupport::GetTransferableForSelection(selection, doc,
-                                                  aTransferable);
-  NS_ENSURE_SUCCESS(rv, rv);
-  return rv;
-}
 
 class NS_STACK_CLASS DragDataProducer
 {
 public:
   DragDataProducer(nsIDOMWindow* aWindow,
                    nsIContent* aTarget,
                    nsIContent* aSelectionTargetNode,
                    PRBool aIsAltKeyPressed);
@@ -157,16 +129,23 @@ private:
   static already_AddRefed<nsIContent> FindParentLinkNode(nsIContent* inNode);
   static void GetAnchorURL(nsIContent* inNode, nsAString& outURL);
   static void GetNodeString(nsIContent* inNode, nsAString & outNodeString);
   static void CreateLinkText(const nsAString& inURL, const nsAString & inText,
                               nsAString& outLinkText);
   static void GetSelectedLink(nsISelection* inSelection,
                               nsIContent **outLinkNode);
 
+  // if inNode is null, use the selection from the window
+  static nsresult SerializeNodeOrSelection(nsIDOMWindow* inWindow,
+                                           nsIContent* inNode,
+                                           nsAString& outResultString,
+                                           nsAString& outHTMLContext,
+                                           nsAString& outHTMLInfo);
+
   nsCOMPtr<nsIDOMWindow> mWindow;
   nsCOMPtr<nsIContent> mTarget;
   nsCOMPtr<nsIContent> mSelectionTargetNode;
   PRPackedBool mIsAltKeyPressed;
 
   nsString mUrlString;
   nsString mImageSourceString;
   nsString mImageDestFileName;
@@ -433,17 +412,16 @@ DragDataProducer::Produce(nsDOMDataTrans
 {
   NS_PRECONDITION(aCanDrag && aDragSelection && aDataTransfer && aDragNode,
                   "null pointer passed to Produce");
   NS_ASSERTION(mWindow, "window not set");
   NS_ASSERTION(mSelectionTargetNode, "selection target node should have been set");
 
   *aDragNode = nsnull;
 
-  nsresult rv;
   nsIContent* dragNode = nsnull;
 
   // find the selection to see what we could be dragging and if
   // what we're dragging is in what is selected.
   nsCOMPtr<nsISelection> selection;
   mWindow->GetSelection(getter_AddRefs(selection));
   if (!selection) {
     return NS_OK;
@@ -680,56 +658,49 @@ DragDataProducer::Produce(nsDOMDataTrans
   }
 
   if (nodeToSerialize || *aDragSelection) {
     // if we have selected text, use it in preference to the node
     if (*aDragSelection) {
       nodeToSerialize = nsnull;
     }
 
-    mHtmlString.Truncate();
-    mContextString.Truncate();
-    mInfoString.Truncate();
-    mTitleString.Truncate();
-    nsCOMPtr<nsITransferable> transferable;
-    rv = ::GetTransferableForNodeOrSelection(mWindow, nodeToSerialize,
-                                             getter_AddRefs(transferable));
-    NS_ENSURE_SUCCESS(rv, rv);
-    nsCOMPtr<nsISupportsString> data;
-    PRUint32 dataSize;
-    rv = transferable->GetTransferData(kHTMLMime, getter_AddRefs(data), &dataSize);
-    if (NS_SUCCEEDED(rv)) {
-      data->GetData(mHtmlString);
-    }
-    rv = transferable->GetTransferData(kHTMLContext, getter_AddRefs(data), &dataSize);
-    if (NS_SUCCEEDED(rv)) {
-      data->GetData(mContextString);
-    }
-    rv = transferable->GetTransferData(kHTMLInfo, getter_AddRefs(data), &dataSize);
-    if (NS_SUCCEEDED(rv)) {
-      data->GetData(mInfoString);
-    }
-    rv = transferable->GetTransferData(kUnicodeMime, getter_AddRefs(data), &dataSize);
-    NS_ENSURE_SUCCESS(rv, rv); // require plain text at a minimum
-    data->GetData(mTitleString);
+    SerializeNodeOrSelection(mWindow, nodeToSerialize,
+                             mHtmlString, mContextString, mInfoString);
+
+    nsCOMPtr<nsIFormatConverter> htmlConverter =
+      do_CreateInstance(kHTMLConverterCID);
+    NS_ENSURE_TRUE(htmlConverter, NS_ERROR_FAILURE);
+
+    nsCOMPtr<nsISupportsString> html =
+      do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
+    NS_ENSURE_TRUE(html, NS_ERROR_FAILURE);
+    html->SetData(mHtmlString);
+
+    nsCOMPtr<nsISupportsString> text;
+    PRUint32 textLen;
+    htmlConverter->Convert(kHTMLMime, html, mHtmlString.Length() * 2,
+                           kUnicodeMime, getter_AddRefs(text), &textLen);
+    NS_ENSURE_TRUE(text, NS_ERROR_FAILURE);
+    text->GetData(mTitleString);
   }
 
   // default text value is the URL
   if (mTitleString.IsEmpty()) {
     mTitleString = mUrlString;
   }
 
   // if we haven't constructed a html version, make one now
   if (mHtmlString.IsEmpty() && !mUrlString.IsEmpty())
     CreateLinkText(mUrlString, mTitleString, mHtmlString);
 
   // if there is no drag node, which will be the case for a selection, just
   // use the selection target node.
-  rv = AddStringsToDataTransfer(
-         dragNode ? dragNode : mSelectionTargetNode.get(), aDataTransfer);
+  nsresult rv = AddStringsToDataTransfer(
+           dragNode ? dragNode : mSelectionTargetNode.get(), aDataTransfer);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_IF_ADDREF(*aDragNode = dragNode);
   return NS_OK;
 }
 
 void
 DragDataProducer::AddString(nsDOMDataTransfer* aDataTransfer,
@@ -1006,8 +977,57 @@ DragDataProducer::GetSelectedLink(nsISel
 
     if (link == link2) {
       NS_IF_ADDREF(*outLinkNode = link);
     }
   }
 
   return;
 }
+
+// static
+nsresult
+DragDataProducer::SerializeNodeOrSelection(nsIDOMWindow* inWindow,
+                                           nsIContent* inNode,
+                                           nsAString& outResultString,
+                                           nsAString& outContext,
+                                           nsAString& outInfo)
+{
+  NS_ENSURE_ARG_POINTER(inWindow);
+
+  nsresult rv;
+  nsCOMPtr<nsIDocumentEncoder> encoder =
+    do_CreateInstance(NS_HTMLCOPY_ENCODER_CONTRACTID);
+  NS_ENSURE_TRUE(encoder, NS_ERROR_FAILURE);
+
+  nsCOMPtr<nsIDOMDocument> domDoc;
+  inWindow->GetDocument(getter_AddRefs(domDoc));
+  NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
+
+  PRUint32 flags = nsIDocumentEncoder::OutputAbsoluteLinks |
+                   nsIDocumentEncoder::OutputEncodeHTMLEntities |
+                   nsIDocumentEncoder::OutputRaw;
+  nsCOMPtr<nsIDOMRange> range;
+  nsCOMPtr<nsISelection> selection;
+  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(inNode);
+  if (node) {
+    // make a range around this node
+    rv = NS_NewRange(getter_AddRefs(range));
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = range->SelectNode(node);
+    NS_ENSURE_SUCCESS(rv, rv);
+  } else {
+    inWindow->GetSelection(getter_AddRefs(selection));
+    flags |= nsIDocumentEncoder::OutputSelectionOnly;
+  }
+
+  rv = encoder->Init(domDoc, NS_LITERAL_STRING(kHTMLMime), flags);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (range) {
+    encoder->SetRange(range);
+  } else if (selection) {
+    encoder->SetSelection(selection);
+  }
+
+  return encoder->EncodeToStringWithContext(outContext, outInfo,
+                                            outResultString);
+}
--- a/content/base/src/nsCopySupport.cpp
+++ b/content/base/src/nsCopySupport.cpp
@@ -17,17 +17,16 @@
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Kathleen Brade <brade@netscape.com>
  *   David Gardiner <david.gardiner@unisa.edu.au>
- *   Mats Palmgren <matpal@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -130,19 +129,17 @@ SelectionCopyHelper(nsISelection *aSel, 
   // is. if it is a selection into input/textarea element or in a html content
   // with pre-wrap style : text/plain. Otherwise text/html.
   // see nsHTMLCopyEncoder::SetSelection
   mimeType.AssignLiteral(kUnicodeMime);
   
   // we want preformatted for the case where the selection is inside input/textarea
   // and we don't want pretty printing for others cases, to not have additionnal
   // line breaks which are then converted into spaces by the htmlConverter (see bug #524975)
-  PRUint32 flags = nsIDocumentEncoder::OutputPreformatted
-                   | nsIDocumentEncoder::OutputRaw
-                   | nsIDocumentEncoder::SkipInvisibleContent;
+  PRUint32 flags = nsIDocumentEncoder::OutputPreformatted | nsIDocumentEncoder::OutputRaw;
 
   nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDoc);
   NS_ASSERTION(domDoc, "Need a document");
 
   rv = docEncoder->Init(domDoc, mimeType, flags);
   if (NS_FAILED(rv)) 
     return rv;
 
@@ -173,17 +170,17 @@ SelectionCopyHelper(nsISelection *aSel, 
     PRUint32 ConvertedLen;
     rv = htmlConverter->Convert(kHTMLMime, plainHTML, textBuffer.Length() * 2, kUnicodeMime, getter_AddRefs(ConvertedData), &ConvertedLen);
     NS_ENSURE_SUCCESS(rv, rv);
 
     ConvertedData->GetData(plaintextBuffer);
 
     mimeType.AssignLiteral(kHTMLMime);
 
-    flags = nsIDocumentEncoder::SkipInvisibleContent;
+    flags = 0;
 
     rv = docEncoder->Init(domDoc, mimeType, flags);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = docEncoder->SetSelection(aSel);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // encode the selection as html with contextual info
@@ -418,17 +415,17 @@ nsCopySupport::GetContents(const nsACStr
   nsCOMPtr<nsIDocumentEncoder> docEncoder;
 
   nsCAutoString encoderContractID(NS_DOC_ENCODER_CONTRACTID_BASE);
   encoderContractID.Append(aMimeType);
     
   docEncoder = do_CreateInstance(encoderContractID.get());
   NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE);
 
-  PRUint32 flags = aFlags | nsIDocumentEncoder::SkipInvisibleContent;
+  PRUint32 flags = aFlags;
   
   if (aMimeType.Equals("text/plain"))
     flags |= nsIDocumentEncoder::OutputPreformatted;
 
   NS_ConvertASCIItoUTF16 unicodeMimeType(aMimeType);
 
   nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDoc);
   NS_ASSERTION(domDoc, "Need a document");
--- a/content/base/src/nsDocumentEncoder.cpp
+++ b/content/base/src/nsDocumentEncoder.cpp
@@ -16,17 +16,16 @@
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Pierre Phaneuf <pp@ludusdesign.com>
- *   Mats Palmgren <matpal@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -46,16 +45,17 @@
 
 #include "nscore.h"
 #include "nsIFactory.h"
 #include "nsISupports.h"
 #include "nsIComponentManager.h" 
 #include "nsIServiceManager.h"
 #include "nsIDocument.h"
 #include "nsIHTMLDocument.h"
+#include "nsISelection.h"
 #include "nsCOMPtr.h"
 #include "nsIContentSerializer.h"
 #include "nsIUnicodeEncoder.h"
 #include "nsIOutputStream.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMText.h"
 #include "nsIDOMCDATASection.h"
 #include "nsIDOMComment.h"
@@ -64,23 +64,21 @@
 #include "nsIDOMNodeList.h"
 #include "nsIRange.h"
 #include "nsIDOMRange.h"
 #include "nsIDOMDocument.h"
 #include "nsICharsetConverterManager.h"
 #include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsIEnumerator.h"
+#include "nsISelectionPrivate.h"
 #include "nsIParserService.h"
 #include "nsIScriptContext.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptSecurityManager.h"
-#include "nsISelection.h"
-#include "nsISelectionPrivate.h"
-#include "nsITransferable.h" // for kUnicodeMime
 #include "nsContentUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsReadableUtils.h"
 #include "nsTArray.h"
 #include "nsIFrame.h"
 
 nsresult NS_NewDomSelection(nsISelection **aDomSelection);
 
@@ -116,39 +114,16 @@ protected:
                                PRInt32 aDepth);
   nsresult SerializeRangeContextStart(const nsTArray<nsINode*>& aAncestorArray,
                                       nsAString& aString);
   nsresult SerializeRangeContextEnd(const nsTArray<nsINode*>& aAncestorArray,
                                     nsAString& aString);
 
   nsresult FlushText(nsAString& aString, PRBool aForce);
 
-  PRBool IsVisibleNode(nsINode* aNode)
-  {
-    NS_PRECONDITION(aNode, "");
-
-    if (mFlags & SkipInvisibleContent) {
-      nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
-      if (content) {
-        nsIFrame* frame = content->GetPrimaryFrame();
-        if (!frame) {
-          if (aNode->IsNodeOfType(nsINode::eTEXT)) {
-            // We have already checked that our parent is visible.
-            return PR_TRUE;
-          }
-          return PR_FALSE;
-        }
-        PRBool isVisible = frame->GetStyleVisibility()->IsVisible();
-        if (!isVisible && aNode->IsNodeOfType(nsINode::eTEXT))
-          return PR_FALSE;
-      }
-    }
-    return PR_TRUE;
-  }
-
   static PRBool IsTag(nsIContent* aContent, nsIAtom* aAtom);
   
   virtual PRBool IncludeInContext(nsINode *aNode);
 
   nsCOMPtr<nsIDocument>          mDocument;
   nsCOMPtr<nsISelection>         mSelection;
   nsCOMPtr<nsIRange>             mRange;
   nsCOMPtr<nsINode>              mNode;
@@ -289,19 +264,18 @@ nsDocumentEncoder::IncludeInContext(nsIN
 
 nsresult
 nsDocumentEncoder::SerializeNodeStart(nsINode* aNode,
                                       PRInt32 aStartOffset,
                                       PRInt32 aEndOffset,
                                       nsAString& aStr,
                                       nsINode* aOriginalNode)
 {
-  if (!IsVisibleNode(aNode))
-    return NS_OK;
-  
+  PRUint16 type;
+
   nsINode* node = nsnull;
   nsCOMPtr<nsINode> fixedNodeKungfuDeathGrip;
 
   // Caller didn't do fixup, so we'll do it ourselves
   if (!aOriginalNode) {
     aOriginalNode = aNode;
     if (mNodeFixup) { 
       PRBool dummy;
@@ -313,17 +287,16 @@ nsDocumentEncoder::SerializeNodeStart(ns
     }
   }
 
   // Either there was no fixed-up node,
   // or the caller did fixup themselves and aNode is already fixed
   if (!node)
     node = aNode;
 
-  PRUint16 type;
   node->GetNodeType(&type);
   switch (type) {
     case nsIDOMNode::ELEMENT_NODE:
     {
       nsIContent* originalElement =
         aOriginalNode && aOriginalNode->IsElement() ?
           static_cast<nsIContent*>(aOriginalNode) : nsnull;
       mSerializer->AppendElementStart(static_cast<nsIContent*>(node),
@@ -363,33 +336,27 @@ nsDocumentEncoder::SerializeNodeStart(ns
 
   return NS_OK;
 }
 
 nsresult
 nsDocumentEncoder::SerializeNodeEnd(nsINode* aNode,
                                     nsAString& aStr)
 {
-  if (!IsVisibleNode(aNode))
-    return NS_OK;
-
   if (aNode->IsElement()) {
     mSerializer->AppendElementEnd(static_cast<nsIContent*>(aNode), aStr);
   }
   return NS_OK;
 }
 
 nsresult
 nsDocumentEncoder::SerializeToStringRecursive(nsINode* aNode,
                                               nsAString& aStr,
                                               PRBool aDontSerializeRoot)
 {
-  if (!IsVisibleNode(aNode))
-    return NS_OK;
-
   nsresult rv = NS_OK;
   PRBool serializeClonedChildren = PR_FALSE;
   nsINode* maybeFixedNode = nsnull;
 
   // Keep the node from FixupNode alive.
   nsCOMPtr<nsINode> fixedNodeKungfuDeathGrip;
   if (mNodeFixup) {
     nsCOMPtr<nsIDOMNode> domNodeIn = do_QueryInterface(aNode);
@@ -684,34 +651,29 @@ nsresult
 nsDocumentEncoder::SerializeRangeNodes(nsIRange* aRange,
                                        nsINode* aNode,
                                        nsAString& aString,
                                        PRInt32 aDepth)
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
-  if (!IsVisibleNode(aNode))
-    return NS_OK;
-
-  nsresult rv = NS_OK;
-
+  nsresult rv=NS_OK;
+  
   // get start and end nodes for this recursion level
   nsCOMPtr<nsIContent> startNode, endNode;
-  {
-    PRInt32 start = mStartRootIndex - aDepth;
-    if (start >= 0 && (PRUint32)start <= mStartNodes.Length())
-      startNode = mStartNodes[start];
+  PRInt32 start = mStartRootIndex - aDepth;
+  if (start >= 0 && (PRUint32)start <= mStartNodes.Length())
+    startNode = mStartNodes[start];
 
-    PRInt32 end = mEndRootIndex - aDepth;
-    if (end >= 0 && (PRUint32)end <= mEndNodes.Length())
-      endNode = mEndNodes[end];
-  }
+  PRInt32 end = mEndRootIndex - aDepth;
+  if (end >= 0 && (PRUint32)end <= mEndNodes.Length())
+    endNode = mEndNodes[end];
 
-  if (startNode != content && endNode != content)
+  if ((startNode != content) && (endNode != content))
   {
     // node is completely contained in range.  Serialize the whole subtree
     // rooted by this node.
     rv = SerializeToStringRecursive(aNode, aString, PR_FALSE);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   else
   {
@@ -891,26 +853,16 @@ nsDocumentEncoder::SerializeRangeToStrin
   
   nsresult rv = NS_OK;
 
   rv = SerializeRangeContextStart(mCommonAncestors, aOutputString);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if ((startParent == endParent) && IsTextNode(startParent))
   {
-    if (mFlags & SkipInvisibleContent) {
-      // Check that the parent is visible if we don't a frame.
-      // IsVisibleNode() will do it when there's a frame.
-      nsCOMPtr<nsIContent> content = do_QueryInterface(startParent);
-      if (content && !content->GetPrimaryFrame()) {
-        nsIContent* parent = content->GetParent();
-        if (!parent || !IsVisibleNode(parent))
-          return NS_OK;
-      }
-    }
     rv = SerializeNodeStart(startParent, startOffset, endOffset, aOutputString);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   else
   {
     rv = SerializeRangeNodes(aRange, mCommonParent, aOutputString, 0);
     NS_ENSURE_SUCCESS(rv, rv);
   }
@@ -1123,31 +1075,31 @@ nsHTMLCopyEncoder::nsHTMLCopyEncoder()
 }
 
 nsHTMLCopyEncoder::~nsHTMLCopyEncoder()
 {
 }
 
 NS_IMETHODIMP
 nsHTMLCopyEncoder::Init(nsIDOMDocument* aDocument,
-                        const nsAString& aMimeType,
+                        const nsAString& aMimetype,
                         PRUint32 aFlags)
 {
   if (!aDocument)
     return NS_ERROR_INVALID_ARG;
 
   mIsTextWidget = PR_FALSE;
   Initialize();
 
   mIsCopying = PR_TRUE;
   mDocument = do_QueryInterface(aDocument);
   NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
 
   mMimeType.AssignLiteral("text/html");
-
+  
   // Make all links absolute when copying
   // (see related bugs #57296, #41924, #58646, #32768)
   mFlags = aFlags | OutputAbsoluteLinks;
 
   if (!mDocument->IsScriptEnabled())
     mFlags |= OutputNoScriptContent;
 
   return NS_OK;
--- a/content/base/test/test_copypaste.html
+++ b/content/base/test/test_copypaste.html
@@ -25,165 +25,99 @@ function testCopyPaste () {
   var docShell = webnav.QueryInterface(Components.interfaces.nsIDocShell);
 
   var documentViewer = docShell.contentViewer
                                .QueryInterface(Components.interfaces.nsIContentViewerEdit);
 
   var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
                             .getService(Components.interfaces.nsIClipboard);
 
+  var transferable, node;
+  var data = {};
   var textarea = document.getElementById('input');
 
-  function copySelectionToClipboard() {
-    documentViewer.copySelection();
-    is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), true);
-    is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true);
-  }
-  function copyToClipboard(node) {
-    textarea.blur();
-    clipboard.emptyClipboard(1);
-    var sel = window.getSelection();
-    sel.removeAllRanges();
-    var r = document.createRange();
-    r.selectNode(node);
-    window.getSelection().addRange(r);
-    copySelectionToClipboard();
-  }
-  function copyRangeToClipboard(startNode,startIndex,endNode,endIndex) {
-    textarea.blur();
-    clipboard.emptyClipboard(1);
-    var sel = window.getSelection();
-    sel.removeAllRanges();
-    var r = document.createRange();
-    r.setStart(startNode,startIndex)
-    r.setEnd(endNode,endIndex)
-    window.getSelection().addRange(r);
-    copySelectionToClipboard();
-  }
-  function copyChildrenToClipboard(id) {
-    textarea.blur();
-    clipboard.emptyClipboard(1);
-    window.getSelection().selectAllChildren(document.getElementById(id));
-    copySelectionToClipboard();
-  }
-  function getClipboardData(mime) {
-    var transferable = Components.classes['@mozilla.org/widget/transferable;1']
-                                 .createInstance(Components.interfaces.nsITransferable);
-    transferable.addDataFlavor(mime);
-    clipboard.getData(transferable, 1);
-    var data = {};
-    transferable.getTransferData(mime, data, {}) ;
-    return data;
-  }
-  function testClipboardValue(mime, expected) {
-    var data = getClipboardData(mime);
-    is (data.value == null ? data.value :
-        data.value.QueryInterface(Components.interfaces.nsISupportsString).data,
-      expected,
-      mime + " value in the clipboard");
-    return data.value;
-  }
-  function testPasteText(expected) {
-    textarea.value="";
-    textarea.focus();
-    textarea.QueryInterface(Components.interfaces.nsIDOMNSEditableElement)
-            .editor.paste(1);
-    is(textarea.value, expected, "value of the textarea after the paste");
-  }
-  function testSelectionToString(expected) {
-    is(window.getSelection().toString().replace(/\r\n/g,"\n"), expected, "Selection.toString");
-  }
-  function testInnerHTML(id, expected) {
-    var value = document.getElementById(id).innerHTML;
-    is(value, expected, id + ".innerHTML");
-  }
-  function testEmptyChildren(id) {
-    copyChildrenToClipboard(id);
-    testSelectionToString("");
-    testClipboardValue("text/unicode", null);
-    testClipboardValue("text/html", null);
-    testPasteText("");
-  }
+  // ============  copy paste test from a simple text content to a textarea
+
+  // selection of the node
+  node = document.getElementById('draggable');
+  window.getSelection().selectAllChildren(node);
+
+  // let's copy the selection
+  documentViewer.copySelection();
+
+  is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), true);
+  is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true);
+
+  // is the clipboard contain a text/unicode data ?
+  transferable = Components.classes['@mozilla.org/widget/transferable;1']
+                           .createInstance(Components.interfaces.nsITransferable);
+  transferable.addDataFlavor("text/unicode");
+  clipboard.getData(transferable, 1);
+
+  transferable.getTransferData ("text/unicode", data, {} ) ;
+  is (data.value.QueryInterface(Components.interfaces.nsISupportsString).data,
+      "This is a draggable bit of text.",
+      "text/unicode value in the clipboard");
+  
+  // is the clipboard contain a text/html data ?
+  transferable = Components.classes['@mozilla.org/widget/transferable;1']
+                           .createInstance(Components.interfaces.nsITransferable);
+  transferable.addDataFlavor("text/html");
+  clipboard.getData(transferable, 1);
+
+  transferable.getTransferData ("text/html", data, {} ) ;
+  is (data.value.QueryInterface(Components.interfaces.nsISupportsString).data,
+      "<div id=\"draggable\" title=\"title to have a long HTML line\">This is a <em>draggable</em> bit of text.</div>",
+      "text/html value in the clipboard");
+  
+  // let's paste now in the textarea and verify its content
+  textarea.focus();
+  textarea.QueryInterface(Components.interfaces.nsIDOMNSEditableElement)
+          .editor.paste(1);
+  is(textarea.value, "This is a draggable bit of text.", "value of the textarea after the paste");
 
-  copyChildrenToClipboard("draggable");
-  testSelectionToString("This is a draggable bit of text.");
-  testClipboardValue("text/unicode",
-                     "This is a draggable bit of text.");
-  testClipboardValue("text/html",
-                     "<div id=\"draggable\" title=\"title to have a long HTML line\">This is a <em>draggable</em> bit of text.</div>");
-  testPasteText("This is a draggable bit of text.");
-
-  copyChildrenToClipboard("alist");
-  testSelectionToString("bla\n\n    * foo\n    * bar\n\n");
-  testClipboardValue("text/unicode", " bla\n\n    * foo\n    * bar\n\n");
-  testClipboardValue("text/html", "<div id=\"alist\">\n    bla\n    <ul>\n      <li>foo</li>\n      \n      <li>bar</li>\n    </ul>\n  </div>");
-  testPasteText(" bla\n\n    * foo\n    * bar\n\n");
 
-  copyChildrenToClipboard("div4");
-  testSelectionToString("Tt t t ");
-  testClipboardValue("text/unicode", " Tt t t ");
-  testClipboardValue("text/html", "<div id=\"div4\">\n  T<textarea>t t t</textarea>\n</div>");
-  testInnerHTML("div4", "\n  T<textarea>t t t</textarea>\n");
-  testPasteText(" Tt t t ");
+  // ============ copy paste test from a piece of HTML to a textarea
+  textarea.blur();
+  node = document.getElementById('alist');
+  window.getSelection().selectAllChildren(node);
+  documentViewer.copySelection();
 
-  copyChildrenToClipboard("div5");
-  testSelectionToString("T ");
-  testClipboardValue("text/unicode", " T ");
-  testClipboardValue("text/html", "<div id=\"div5\">\n  T<textarea>     </textarea>\n</div>");
-  testInnerHTML("div5", "\n  T<textarea>     </textarea>\n");
-  testPasteText(" T ");
-
-  copyRangeToClipboard($("div6").childNodes[0],0, $("div6").childNodes[1],1);
-  testSelectionToString("");
-// START Disabled due to bug 564688
-if (false) {
-  testClipboardValue("text/unicode", "");
-  testClipboardValue("text/html", "");
-}
-// END Disabled due to bug 564688
-  testInnerHTML("div6", "div6");
+  is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), true);
+  is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true);
 
-  copyRangeToClipboard($("div7").childNodes[0],0, $("div7").childNodes[0],4);
-  testSelectionToString("");
-// START Disabled due to bug 564688
-if (false) {
-  testClipboardValue("text/unicode", "");
-  testClipboardValue("text/html", "");
-}
-// END Disabled due to bug 564688
-  testInnerHTML("div7", "div7");
+  // let's verify the clipboard content for the text/unicode flavor
+  transferable = Components.classes['@mozilla.org/widget/transferable;1']
+                           .createInstance(Components.interfaces.nsITransferable);
+  transferable.addDataFlavor("text/unicode");
+  clipboard.getData(transferable, 1);
+  data = {};
+  transferable.getTransferData ("text/unicode", data, {} ) ;
+  is (data.value.QueryInterface(Components.interfaces.nsISupportsString).data,
+      " bla\n\n    * foo\n    * bar\n\n",
+      "text/unicode value in the clipboard (html piece)");
 
-  copyRangeToClipboard($("div8").childNodes[0],0, $("div8").childNodes[0],4);
-  testSelectionToString("");
-// START Disabled due to bug 564688
-if (false) {
-  testClipboardValue("text/unicode", "");
-  testClipboardValue("text/html", "");
-}
-// END Disabled due to bug 564688
-  testInnerHTML("div8", "div8");
-
-  copyRangeToClipboard($("div9").childNodes[0],0, $("div9").childNodes[0],4);
-  testSelectionToString("div9");
-  testClipboardValue("text/unicode", "div9");
-  testClipboardValue("text/html", "div9");
-  testInnerHTML("div9", "div9");
-
-  copyToClipboard($("div10"));
-  testSelectionToString("");
-  testInnerHTML("div10", "div10");
-
-  copyToClipboard($("div10").firstChild);
-  testSelectionToString("");
-
-  copyRangeToClipboard($("div10").childNodes[0],0, $("div10").childNodes[0],1);
-  testSelectionToString("");
-
-  copyRangeToClipboard($("div10").childNodes[1],0, $("div10").childNodes[1],1);
-  testSelectionToString("");
+  // let's verify the clipboard content for the text/html flavor
+  transferable = Components.classes['@mozilla.org/widget/transferable;1']
+                           .createInstance(Components.interfaces.nsITransferable);
+  transferable.addDataFlavor("text/html");
+  clipboard.getData(transferable, 1);
+  data = {};
+  transferable.getTransferData ("text/html", data, {} ) ;
+  is (data.value.QueryInterface(Components.interfaces.nsISupportsString).data,
+      "<div id=\"alist\">\n    bla\n    <ul>\n      <li>foo</li>\n      <li>bar</li>\n    </ul>\n  </div>",
+      "text/html value in the clipboard (html piece)");
+  
+  // let's paste now in the textarea and verify its content
+  textarea.value="";
+  textarea.focus();
+  textarea.QueryInterface(Components.interfaces.nsIDOMNSEditableElement)
+          .editor.paste(1);
+  is(textarea.value, " bla\n\n    * foo\n    * bar\n\n", "value of the textarea after the paste (html piece)");
+  
 
   // ============ copy/paste test from/to a textarea
 
   var val = "1\n 2\n  3";
   textarea.value=val;
   textarea.select();
   textarea.editor.copy();
   
@@ -206,42 +140,15 @@ addLoadEvent(testCopyPaste);
 
   <div id="draggable" title="title to have a long HTML line">This is a <em>draggable</em> bit of text.</div>
   <textarea id="input" cols="40" rows="10"></textarea>
 
   <div id="alist">
     bla
     <ul>
       <li>foo</li>
-      <li style="display: none;">baz</li>
       <li>bar</li>
     </ul>
   </div>
 
-<div id="div4">
-  T<textarea>t t t</textarea>
-</div>
-
-<div id="div5">
-  T<textarea>     </textarea>
-</div>
-
-<div id="div6" style="display:none"></div>
-<script>
-var x = $("div6")
-x.appendChild(document.createTextNode('di'))
-x.appendChild(document.createTextNode('v6'))
-</script>
-
-<div id="div7" style="display:none">div7</div>
-<div id="div8" style="visibility:hidden">div8</div>
-<div style="visibility:hidden"><div id="div9" style="visibility:visible">div9</div></div>
-<div style="visibility:hidden"><div><div><div id="div10"></div></div></div></div>
-<script>
-var x = $("div10")
-x.appendChild(document.createTextNode('div'))
-x.appendChild(document.createTextNode('10'))
-</script>
-
-
 </div>
 </body>
 </html>
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -1296,19 +1296,17 @@ nsFrameSelection::MoveCaret(PRUint32    
 //END nsFrameSelection methods
 
 
 //BEGIN nsFrameSelection methods
 
 NS_IMETHODIMP
 nsTypedSelection::ToString(PRUnichar **aReturn)
 {
-  return ToStringWithFormat("text/plain",
-                            nsIDocumentEncoder::SkipInvisibleContent,
-                            0, aReturn);
+  return ToStringWithFormat("text/plain", 0, 0, aReturn);
 }
 
 
 NS_IMETHODIMP
 nsTypedSelection::ToStringWithFormat(const char * aFormatType, PRUint32 aFlags, 
                                    PRInt32 aWrapCol, PRUnichar **aReturn)
 {
   nsresult rv = NS_OK;