Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsCopySupport.cpp File Reference
#include "nsCopySupport.h"
#include "nsIDocumentEncoder.h"
#include "nsISupports.h"
#include "nsIContent.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIClipboard.h"
#include "nsISelection.h"
#include "nsWidgetsCID.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIDOMRange.h"
#include "nsIDocShell.h"
#include "nsIContentViewerEdit.h"
#include "nsIClipboardDragDropHooks.h"
#include "nsIClipboardDragDropHookList.h"
#include "nsIDocument.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIHTMLDocument.h"
#include "nsHTMLAtoms.h"
#include "nsIImageLoadingContent.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIImage.h"
#include "nsContentUtils.h"

Go to the source code of this file.

Defines

#define kHTMLContext   "text/_moz_htmlcontext"
#define kHTMLInfo   "text/_moz_htmlinfo"

Functions

static NS_DEFINE_CID (kCClipboardCID, NS_CLIPBOARD_CID)
static NS_DEFINE_CID (kCTransferableCID, NS_TRANSFERABLE_CID)
static NS_DEFINE_CID (kHTMLConverterCID, NS_HTMLFORMATCONVERTER_CID)
static nsresult AppendString (nsITransferable *aTransferable, const nsAString &aString, const char *aFlavor)
static nsresult AppendDOMNode (nsITransferable *aTransferable, nsIDOMNode *aDOMNode)

Define Documentation

#define kHTMLContext   "text/_moz_htmlcontext"

Definition at line 76 of file nsCopySupport.cpp.

#define kHTMLInfo   "text/_moz_htmlinfo"

Definition at line 77 of file nsCopySupport.cpp.


Function Documentation

static nsresult AppendDOMNode ( nsITransferable aTransferable,
nsIDOMNode aDOMNode 
) [static]

Definition at line 487 of file nsCopySupport.cpp.

{
  nsresult rv;
  
  // selializer
  nsCOMPtr<nsIDocumentEncoder>
    docEncoder(do_CreateInstance(NS_HTMLCOPY_ENCODER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  // get document for the encoder
  nsCOMPtr<nsIDOMDocument> domDocument;
  rv = aDOMNode->GetOwnerDocument(getter_AddRefs(domDocument));
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIDocument> document(do_QueryInterface(domDocument, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  // Note that XHTML is not counted as HTML here, because we can't copy it
  // properly (all the copy code for non-plaintext assumes using HTML
  // serializers and parsers is OK, and those mess up XHTML).
  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document, &rv);
  NS_ENSURE_SUCCESS(rv, NS_OK);
  NS_ENSURE_TRUE(!(document->IsCaseSensitive()), NS_OK);

  // init encoder with document and node
  rv = docEncoder->Init(document, NS_LITERAL_STRING(kHTMLMime),
                        nsIDocumentEncoder::OutputAbsoluteLinks |
                        nsIDocumentEncoder::OutputEncodeW3CEntities);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = docEncoder->SetNode(aDOMNode);
  NS_ENSURE_SUCCESS(rv, rv);

  // serialize to string
  nsAutoString html, context, info;
  rv = docEncoder->EncodeToStringWithContext(html, context, info);
  NS_ENSURE_SUCCESS(rv, rv);

  // copy them to the transferable
  if (!html.IsEmpty()) {
    rv = AppendString(aTransferable, html, kHTMLMime);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  if (!info.IsEmpty()) {
    rv = AppendString(aTransferable, info, kHTMLInfo);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  // add a special flavor, even if we don't have html context data
  return AppendString(aTransferable, context, kHTMLContext);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult AppendString ( nsITransferable aTransferable,
const nsAString &  aString,
const char *  aFlavor 
) [static]

Definition at line 467 of file nsCopySupport.cpp.

{
  nsresult rv;

  nsCOMPtr<nsISupportsString>
    data(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = data->SetData(aString);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = aTransferable->AddDataFlavor(aFlavor);
  NS_ENSURE_SUCCESS(rv, rv);

  return aTransferable->SetTransferData(aFlavor, data,
                                        aString.Length() * sizeof(PRUnichar));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kCClipboardCID  ,
NS_CLIPBOARD_CID   
) [static]
static NS_DEFINE_CID ( kCTransferableCID  ,
NS_TRANSFERABLE_CID   
) [static]
static NS_DEFINE_CID ( kHTMLConverterCID  ,
NS_HTMLFORMATCONVERTER_CID   
) [static]