Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsHTMLCopyEncoder Class Reference
Inheritance diagram for nsHTMLCopyEncoder:
Inheritance graph
[legend]
Collaboration diagram for nsHTMLCopyEncoder:
Collaboration graph
[legend]

List of all members.

Public Types

enum  {
  OutputSelectionOnly = 1, OutputFormatted = 2, OutputRaw = 4, OutputBodyOnly = 8,
  OutputPreformatted = 16, OutputWrap = 32, OutputFormatFlowed = 64, OutputAbsoluteLinks = 128,
  OutputEncodeW3CEntities = 256, OutputCRLineBreak = 512, OutputLFLineBreak = 1024, OutputNoScriptContent = 2048,
  OutputNoFramesContent = 4096, OutputNoFormattingInPre = 8192, OutputEncodeBasicEntities = 16384, OutputEncodeLatin1Entities = 32768,
  OutputEncodeHTMLEntities = 65536
}
 Output methods flag bits. More...

Public Member Functions

 nsHTMLCopyEncoder ()
virtual ~nsHTMLCopyEncoder ()
NS_IMETHOD Init (nsIDocument *aDocument, const nsAString &aMimeType, PRUint32 aFlags)
 Initialize with a pointer to the document and the mime type.
NS_IMETHOD SetSelection (nsISelection *aSelection)
 If the selection is set to a non-null value, then the selection is used for encoding, otherwise the entire document is encoded.
NS_IMETHOD EncodeToStringWithContext (nsAString &aEncodedString, nsAString &aContextString, nsAString &aInfoString)
 The document is encoded, the result is sent to the to aEncodedString.
NS_IMETHOD SetRange (nsIDOMRange *aRange)
 If the range is set to a non-null value, then the range is used for encoding, otherwise the entire document or selection is encoded.
NS_IMETHOD SetNode (nsIDOMNode *aNode)
 If the node is set to a non-null value, then the node is used for encoding, otherwise the entire document or range or selection is encoded.
NS_IMETHOD SetWrapColumn (PRUint32 aWC)
 Set a wrap column.
NS_IMETHOD SetCharset (const nsACString &aCharset)
 Documents typically have an intrinsic character set.
NS_IMETHOD GetMimeType (nsAString &aMimeType)
 Get the mime type preferred by the encoder.
NS_IMETHOD EncodeToStream (nsIOutputStream *aStream)
 The document is encoded, the result is sent to the to nsIOutputStream.
NS_IMETHOD EncodeToString (nsAString &aOutputString)
NS_IMETHOD SetNodeFixup (nsIDocumentEncoderNodeFixup *aFixup)
 Set the fixup object associated with node persistence.

Protected Types

enum  Endpoint { kStart, kEnd }

Protected Member Functions

nsresult PromoteRange (nsIDOMRange *inRange)
nsresult PromoteAncestorChain (nsCOMPtr< nsIDOMNode > *ioNode, PRInt32 *ioStartOffset, PRInt32 *ioEndOffset)
nsresult GetPromotedPoint (Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr< nsIDOMNode > *outNode, PRInt32 *outOffset, nsIDOMNode *aCommon)
nsCOMPtr< nsIDOMNodeGetChildAt (nsIDOMNode *aParent, PRInt32 aOffset)
PRBool IsMozBR (nsIDOMNode *aNode)
nsresult GetNodeLocation (nsIDOMNode *inChild, nsCOMPtr< nsIDOMNode > *outParent, PRInt32 *outOffset)
PRBool IsRoot (nsIDOMNode *aNode)
PRBool IsFirstNode (nsIDOMNode *aNode)
PRBool IsLastNode (nsIDOMNode *aNode)
PRBool IsEmptyTextContent (nsIDOMNode *aNode)
virtual PRBool IncludeInContext (nsIDOMNode *aNode)
void Initialize ()
nsresult SerializeNodeStart (nsIDOMNode *aNode, PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString &aStr)
nsresult SerializeToStringRecursive (nsIDOMNode *aNode, nsAString &aStr)
nsresult SerializeNodeEnd (nsIDOMNode *aNode, nsAString &aStr)
nsresult SerializeRangeToString (nsIDOMRange *aRange, nsAString &aOutputString)
nsresult SerializeRangeNodes (nsIDOMRange *aRange, nsIDOMNode *aNode, nsAString &aString, PRInt32 aDepth)
nsresult SerializeRangeContextStart (const nsVoidArray &aAncestorArray, nsAString &aString)
nsresult SerializeRangeContextEnd (const nsVoidArray &aAncestorArray, nsAString &aString)
nsresult FlushText (nsAString &aString, PRBool aForce)

Static Protected Member Functions

static PRBool IsTag (nsIDOMNode *aNode, nsIAtom *aAtom)

Protected Attributes

PRBool mIsTextWidget
nsCOMPtr< nsIDocumentmDocument
nsCOMPtr< nsISelectionmSelection
nsCOMPtr< nsIDOMRangemRange
nsCOMPtr< nsIDOMNodemNode
nsCOMPtr< nsIOutputStreammStream
nsCOMPtr< nsIContentSerializermSerializer
nsCOMPtr< nsIUnicodeEncodermUnicodeEncoder
nsCOMPtr< nsIDOMNodemCommonParent
nsCOMPtr
< nsIDocumentEncoderNodeFixup
mNodeFixup
nsCOMPtr
< nsICharsetConverterManager
mCharsetConverterManager
nsString mMimeType
nsCString mCharset
PRUint32 mFlags
PRUint32 mWrapColumn
PRUint32 mStartDepth
PRUint32 mEndDepth
PRInt32 mStartRootIndex
PRInt32 mEndRootIndex
nsAutoVoidArray mCommonAncestors
nsAutoVoidArray mStartNodes
nsAutoVoidArray mStartOffsets
nsAutoVoidArray mEndNodes
nsAutoVoidArray mEndOffsets
PRPackedBool mHaltRangeHint
PRPackedBool mIsCopying

Detailed Description

Definition at line 1020 of file nsDocumentEncoder.cpp.


Member Enumeration Documentation

anonymous enum [inherited]

Output methods flag bits.

There are a frightening number of these, because everyone wants something a little bit different!

These should move to an idl file so that Javascript can have access to the symbols, not just the constants.

Enumerator:
OutputSelectionOnly 
OutputFormatted 
OutputRaw 
OutputBodyOnly 
OutputPreformatted 
OutputWrap 
OutputFormatFlowed 
OutputAbsoluteLinks 
OutputEncodeW3CEntities 
OutputCRLineBreak 
OutputLFLineBreak 
OutputNoScriptContent 
OutputNoFramesContent 
OutputNoFormattingInPre 
OutputEncodeBasicEntities 
OutputEncodeLatin1Entities 
OutputEncodeHTMLEntities 

Definition at line 110 of file nsIDocumentEncoder.h.

       {
    // Output only the selection (as opposed to the whole document).
    OutputSelectionOnly = 1,

    // Plaintext output: Convert html to plaintext that looks like the html.
    // Implies wrap (except inside <pre>), since html wraps.
    // HTML output: always do prettyprinting, ignoring existing formatting.
    // (Probably not well tested for HTML output.)
    OutputFormatted     = 2,

    // Don't do prettyprinting of HTML.  Don't do any wrapping that's not in
    // the existing HTML source.  This option overrides OutputFormatted if both
    // are set.  Note that this option does not affect entity conversion.
    OutputRaw           = 4,

    // No html head tags
    OutputBodyOnly      = 8,

    // Wrap even if we're not doing formatted output (e.g. for text fields)
    // XXXbz this doesn't seem to be used by all serializers... document?  How
    // does this interact with
    // OutputFormatted/OutputRaw/OutputWrap/OutputFormatFlowed?
    OutputPreformatted  = 16,

    // Output as though the content is preformatted
    // (e.g. maybe it's wrapped in a MOZ_PRE or MOZ_PRE_WRAP style tag)
    // XXXbz this doesn't seem to be used by all serializers... document?  How
    // does this interact with
    // OutputFormatted/OutputRaw/OutputPreformatted/OutputFormatFlowed?
    OutputWrap          = 32,

    // Output for format flowed (RFC 2646). This is used when converting
    // to text for mail sending. This differs just slightly
    // but in an important way from normal formatted, and that is that
    // lines are space stuffed. This can't (correctly) be done later.
    // XXXbz this doesn't seem to be used by all serializers... document?  How
    // does this interact with
    // OutputFormatted/OutputRaw/OutputPreformatted/OutputWrap?
    OutputFormatFlowed  = 64,

    // Convert links, image src, and script src to absolute URLs when possible
    OutputAbsoluteLinks = 128,

    // Attempt to encode entities standardized at W3C (HTML, MathML, etc).
    // This is a catch-all flag for documents with mixed contents. Beware of
    // interoperability issues. See below for other flags which might likely
    // do what you want.
    OutputEncodeW3CEntities = 256,

    // LineBreak processing: we can do either platform line breaks,
    // CR, LF, or CRLF.  If neither of these flags is set, then we
    // will use platform line breaks.
    OutputCRLineBreak = 512,
    OutputLFLineBreak = 1024,

    // Output the content of noscript elements (only for serializing
    // to plaintext).
    OutputNoScriptContent = 2048,

    // Output the content of noframes elements (only for serializing
    // to plaintext).
    OutputNoFramesContent = 4096,

    // Don't allow any formatting nodes (e.g. <br>, <b>) inside a <pre>.
    // This is used primarily by mail.
    OutputNoFormattingInPre = 8192,

    // Encode entities when outputting to a string.
    // E.g. If set, we'll output &nbsp; if clear, we'll output 0xa0.
    // The basic set is just &nbsp; &amp; &lt; &gt; &quot; for interoperability
    // with older products that don't support &alpha; and friends.
    // The Latin1 entity set additionally includes 8bit accented letters
    // between 128 and 255.
    // The HTML entity set additionally includes accented letters, greek
    // letters, and other special markup symbols as defined in HTML4.
    OutputEncodeBasicEntities = 16384,
    OutputEncodeLatin1Entities = 32768,
    OutputEncodeHTMLEntities = 65536
  };
enum nsHTMLCopyEncoder::Endpoint [protected]
Enumerator:
kStart 
kEnd 

Definition at line 1037 of file nsDocumentEncoder.cpp.

  {
    kStart,
    kEnd
  };

Constructor & Destructor Documentation

Definition at line 1066 of file nsDocumentEncoder.cpp.

Definition at line 1071 of file nsDocumentEncoder.cpp.

{
}

Member Function Documentation

The document is encoded, the result is sent to the to nsIOutputStream.

Possible result codes are passing along whatever stream errors might have been encountered.

Implements nsIDocumentEncoder.

Definition at line 949 of file nsDocumentEncoder.cpp.

{
  nsresult rv = NS_OK;

  if (!mDocument)
    return NS_ERROR_NOT_INITIALIZED;

  if (!mCharsetConverterManager) {
    mCharsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  rv = mCharsetConverterManager->GetUnicodeEncoder(mCharset.get(),
                                                   getter_AddRefs(mUnicodeEncoder));
  NS_ENSURE_SUCCESS(rv, rv);

  if (mMimeType.LowerCaseEqualsLiteral("text/plain")) {
    rv = mUnicodeEncoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');
    NS_ENSURE_SUCCESS(rv, rv);
  }

  mStream = aStream;

  nsAutoString buf;

  rv = EncodeToString(buf);

  // Force a flush of the last chunk of data.
  FlushText(buf, PR_TRUE);

  mStream = nsnull;
  mUnicodeEncoder = nsnull;

  return rv;
}

Here is the call graph for this function:

NS_IMETHODIMP nsDocumentEncoder::EncodeToString ( nsAString &  aOutputString) [virtual, inherited]

Implements nsIDocumentEncoder.

Definition at line 885 of file nsDocumentEncoder.cpp.

{
  if (!mDocument)
    return NS_ERROR_NOT_INITIALIZED;

  aOutputString.Truncate();

  nsCAutoString progId(NS_CONTENTSERIALIZER_CONTRACTID_PREFIX);
  AppendUTF16toUTF8(mMimeType, progId);

  mSerializer = do_CreateInstance(progId.get());
  NS_ENSURE_TRUE(mSerializer, NS_ERROR_NOT_IMPLEMENTED);

  nsresult rv = NS_OK;

  nsCOMPtr<nsIAtom> charsetAtom;
  if (!mCharset.IsEmpty()) {
    if (!mCharsetConverterManager) {
      mCharsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
      NS_ENSURE_SUCCESS(rv, rv);
    }
  }
  mSerializer->Init(mFlags, mWrapColumn, mCharset.get(), mIsCopying);

  if (mSelection) {
    nsCOMPtr<nsIDOMRange> range;
    PRInt32 i, count = 0;

    rv = mSelection->GetRangeCount(&count);
    NS_ENSURE_SUCCESS(rv, rv);

    for (i = 0; i < count; i++) {
      mSelection->GetRangeAt(i, getter_AddRefs(range));

      rv = SerializeRangeToString(range, aOutputString);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    mSelection = nsnull;
  } else if (mRange) {
      rv = SerializeRangeToString(mRange, aOutputString);

      mRange = nsnull;
  } else if (mNode) {
    rv = SerializeToStringRecursive(mNode, aOutputString);
    mNode = nsnull;
  } else {
    nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));
    rv = mSerializer->AppendDocumentStart(domdoc, aOutputString);

    if (NS_SUCCEEDED(rv)) {
      nsCOMPtr<nsIDOMNode> doc(do_QueryInterface(mDocument));

      rv = SerializeToStringRecursive(doc, aOutputString);
    }
  }

  NS_ENSURE_SUCCESS(rv, rv);
  rv = mSerializer->Flush(aOutputString);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsHTMLCopyEncoder::EncodeToStringWithContext ( nsAString &  aEncodedString,
nsAString &  aContextString,
nsAString &  aInfoString 
) [virtual]

The document is encoded, the result is sent to the to aEncodedString.

Parent heirarchy information is encoded to aContextString. Extra context info is encoded in aInfoString.

Reimplemented from nsDocumentEncoder.

Definition at line 1216 of file nsDocumentEncoder.cpp.

{
  nsresult rv = EncodeToString(aEncodedString);
  NS_ENSURE_SUCCESS(rv, rv);

  // do not encode any context info or range hints if we are in a text widget.
  if (mIsTextWidget) return NS_OK;

  // now encode common ancestors into aContextString.  Note that the common ancestors
  // will be for the last range in the selection in the case of multirange selections.
  // encoding ancestors every range in a multirange selection in a way that could be 
  // understood by the paste code would be a lot more work to do.  As a practical matter,
  // selections are single range, and the ones that aren't are table cell selections
  // where all the cells are in the same table.

  // leaf of ancestors might be text node.  If so discard it.
  PRInt32 count = mCommonAncestors.Count();
  PRInt32 i;
  nsCOMPtr<nsIDOMNode> node;
  if (count > 0)
    node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(0));

  if (node && IsTextNode(node)) 
  {
    mCommonAncestors.RemoveElementAt(0);
    // don't forget to adjust range depth info
    if (mStartDepth) mStartDepth--;
    if (mEndDepth) mEndDepth--;
    // and the count
    count--;
  }
  
  i = count;
  while (i > 0)
  {
    node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(--i));
    SerializeNodeStart(node, 0, -1, aContextString);
  }
  //i = 0; guaranteed by above
  while (i < count)
  {
    node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(i++));
    SerializeNodeEnd(node, aContextString);
  }

  // encode range info : the start and end depth of the selection, where the depth is 
  // distance down in the parent hierarchy.  Later we will need to add leading/trailing
  // whitespace info to this.
  nsAutoString infoString;
  infoString.AppendInt(mStartDepth);
  infoString.Append(PRUnichar(','));
  infoString.AppendInt(mEndDepth);
  aInfoString = infoString;
  
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsDocumentEncoder::FlushText ( nsAString &  aString,
PRBool  aForce 
) [protected, inherited]

Definition at line 489 of file nsDocumentEncoder.cpp.

{
  if (!mStream)
    return NS_OK;

  nsresult rv = NS_OK;

  if (aString.Length() > 1024 || aForce) {
    rv = ConvertAndWrite(aString, mStream, mUnicodeEncoder);

    aString.Truncate();
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsCOMPtr< nsIDOMNode > nsHTMLCopyEncoder::GetChildAt ( nsIDOMNode aParent,
PRInt32  aOffset 
) [protected]

Definition at line 1592 of file nsDocumentEncoder.cpp.

{
  nsCOMPtr<nsIDOMNode> resultNode;
  
  if (!aParent) 
    return resultNode;
  
  nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
  NS_PRECONDITION(content, "null content in nsHTMLCopyEncoder::GetChildAt");

  resultNode = do_QueryInterface(content->GetChildAt(aOffset));

  return resultNode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsDocumentEncoder::GetMimeType ( nsAString &  aMimeType) [virtual, inherited]

Get the mime type preferred by the encoder.

This piece of api was added because the copy encoder may need to switch mime types on you if you ask it to copy html that really represents plaintext content. Call this AFTER Init() and SetSelection() have both been called.

Implements nsIDocumentEncoder.

Definition at line 260 of file nsDocumentEncoder.cpp.

{
  aMimeType = mMimeType;
  return NS_OK;
}
nsresult nsHTMLCopyEncoder::GetNodeLocation ( nsIDOMNode inChild,
nsCOMPtr< nsIDOMNode > *  outParent,
PRInt32 outOffset 
) [protected]

Definition at line 1628 of file nsDocumentEncoder.cpp.

{
  NS_ASSERTION((inChild && outParent && outOffset), "bad args");
  nsresult result = NS_ERROR_NULL_POINTER;
  if (inChild && outParent && outOffset)
  {
    result = inChild->GetParentNode(getter_AddRefs(*outParent));
    if ((NS_SUCCEEDED(result)) && (*outParent))
    {
      nsCOMPtr<nsIContent> content = do_QueryInterface(*outParent);
      nsCOMPtr<nsIContent> cChild = do_QueryInterface(inChild);
      if (!cChild || !content)
        return NS_ERROR_NULL_POINTER;

      *outOffset = content->IndexOf(cChild);
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCopyEncoder::GetPromotedPoint ( Endpoint  aWhere,
nsIDOMNode aNode,
PRInt32  aOffset,
nsCOMPtr< nsIDOMNode > *  outNode,
PRInt32 outOffset,
nsIDOMNode aCommon 
) [protected]

Definition at line 1407 of file nsDocumentEncoder.cpp.

{
  nsresult rv = NS_OK;
  nsCOMPtr<nsIDOMNode> node = aNode;
  nsCOMPtr<nsIDOMNode> parent = aNode;
  PRInt32 offset = aOffset;
  PRBool  bResetPromotion = PR_FALSE;
  
  // default values
  *outNode = node;
  *outOffset = offset;

  if (common == node) 
    return NS_OK;
    
  if (aWhere == kStart)
  {
    // some special casing for text nodes
    if (IsTextNode(aNode))  
    {
      // if not at beginning of text node, we are done
      if (offset >  0) 
      {
        // unless everything before us in just whitespace.  NOTE: we need a more
        // general solution that truly detects all cases of non-significant
        // whitesace with no false alarms.
        nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
        nsAutoString text;
        nodeAsText->SubstringData(0, offset, text);
        text.CompressWhitespace();
        if (!text.IsEmpty())
          return NS_OK;
        bResetPromotion = PR_TRUE;
      }
      // else
      rv = GetNodeLocation(aNode, address_of(parent), &offset);
      NS_ENSURE_SUCCESS(rv, rv);
    }
    else
    {
      node = GetChildAt(parent,offset);
    }
    if (!node) node = parent;

    // finding the real start for this point.  look up the tree for as long as we are the 
    // first node in the container, and as long as we haven't hit the body node.
    if (!IsRoot(node) && (parent != common))
    {
      rv = GetNodeLocation(node, address_of(parent), &offset);
      NS_ENSURE_SUCCESS(rv, rv);
      if (offset == -1) return NS_OK; // we hit generated content; STOP
      nsIParserService *parserService =
        nsContentUtils::GetParserServiceWeakRef();
      if (!parserService)
        return NS_ERROR_OUT_OF_MEMORY;
      while ((IsFirstNode(node)) && (!IsRoot(parent)) && (parent != common))
      {
        if (bResetPromotion)
        {
          nsCOMPtr<nsIContent> content = do_QueryInterface(parent);
          if (content)
          {
            PRBool isBlock = PR_FALSE;
            parserService->IsBlock(parserService->HTMLAtomTagToId(content->Tag()), isBlock);
            if (isBlock)
            {
              bResetPromotion = PR_FALSE;
            }
          }   
        }
         
        node = parent;
        rv = GetNodeLocation(node, address_of(parent), &offset);
        NS_ENSURE_SUCCESS(rv, rv);
        if (offset == -1)  // we hit generated content; STOP
        {
          // back up a bit
          parent = node;
          offset = 0;
          break;
        }
      } 
      if (bResetPromotion)
      {
        *outNode = aNode;
        *outOffset = aOffset;
      }
      else
      {
        *outNode = parent;
        *outOffset = offset;
      }
      return rv;
    }
  }
  
  if (aWhere == kEnd)
  {
    // some special casing for text nodes
    if (IsTextNode(aNode))  
    {
      // if not at end of text node, we are done
      PRUint32 len;
      GetLengthOfDOMNode(aNode, len);
      if (offset < (PRInt32)len)
      {
        // unless everything after us in just whitespace.  NOTE: we need a more
        // general solution that truly detects all cases of non-significant
        // whitesace with no false alarms.
        nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
        nsAutoString text;
        nodeAsText->SubstringData(offset, len-offset, text);
        text.CompressWhitespace();
        if (!text.IsEmpty())
          return NS_OK;
        bResetPromotion = PR_TRUE;
      }
      rv = GetNodeLocation(aNode, address_of(parent), &offset);
      NS_ENSURE_SUCCESS(rv, rv);
    }
    else
    {
      if (offset) offset--; // we want node _before_ offset
      node = GetChildAt(parent,offset);
    }
    if (!node) node = parent;
    
    // finding the real end for this point.  look up the tree for as long as we are the 
    // last node in the container, and as long as we haven't hit the body node.
    if (!IsRoot(node) && (parent != common))
    {
      rv = GetNodeLocation(node, address_of(parent), &offset);
      NS_ENSURE_SUCCESS(rv, rv);
      if (offset == -1) return NS_OK; // we hit generated content; STOP
      nsIParserService *parserService =
        nsContentUtils::GetParserServiceWeakRef();
      if (!parserService)
        return NS_ERROR_OUT_OF_MEMORY;
      while ((IsLastNode(node)) && (!IsRoot(parent)) && (parent != common))
      {
        if (bResetPromotion)
        {
          nsCOMPtr<nsIContent> content = do_QueryInterface(parent);
          if (content)
          {
            PRBool isBlock = PR_FALSE;
            parserService->IsBlock(parserService->HTMLAtomTagToId(content->Tag()), isBlock);
            if (isBlock)
            {
              bResetPromotion = PR_FALSE;
            }
          }   
        }
          
        node = parent;
        rv = GetNodeLocation(node, address_of(parent), &offset);
        NS_ENSURE_SUCCESS(rv, rv);
        if (offset == -1)  // we hit generated content; STOP
        {
          // back up a bit
          parent = node;
          offset = 0;
          break;
        }
      } 
      if (bResetPromotion)
      {
        *outNode = aNode;
        *outOffset = aOffset;
      }
      else
      {
        *outNode = parent;
        offset++;  // add one since this in an endpoint - want to be AFTER node.
        *outOffset = offset;
      }
      return rv;
    }
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsHTMLCopyEncoder::IncludeInContext ( nsIDOMNode aNode) [protected, virtual]

Reimplemented from nsDocumentEncoder.

Definition at line 1277 of file nsDocumentEncoder.cpp.

{
  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));

  if (!content)
    return PR_FALSE;

  nsIAtom *tag = content->Tag();

  return (tag == nsHTMLAtoms::b        ||
          tag == nsHTMLAtoms::i        ||
          tag == nsHTMLAtoms::u        ||
          tag == nsHTMLAtoms::a        ||
          tag == nsHTMLAtoms::tt       ||
          tag == nsHTMLAtoms::s        ||
          tag == nsHTMLAtoms::big      ||
          tag == nsHTMLAtoms::small    ||
          tag == nsHTMLAtoms::strike   ||
          tag == nsHTMLAtoms::em       ||
          tag == nsHTMLAtoms::strong   ||
          tag == nsHTMLAtoms::dfn      ||
          tag == nsHTMLAtoms::code     ||
          tag == nsHTMLAtoms::cite     ||
          tag == nsHTMLAtoms::variable ||
          tag == nsHTMLAtoms::abbr     ||
          tag == nsHTMLAtoms::font     ||
          tag == nsHTMLAtoms::script   ||
          tag == nsHTMLAtoms::span     ||
          tag == nsHTMLAtoms::pre      ||
          tag == nsHTMLAtoms::h1       ||
          tag == nsHTMLAtoms::h2       ||
          tag == nsHTMLAtoms::h3       ||
          tag == nsHTMLAtoms::h4       ||
          tag == nsHTMLAtoms::h5       ||
          tag == nsHTMLAtoms::h6);
}

Here is the call graph for this function:

NS_IMETHODIMP nsHTMLCopyEncoder::Init ( nsIDocument aDocument,
const nsAString &  aMimeType,
PRUint32  flags 
) [virtual]

Initialize with a pointer to the document and the mime type.

Reimplemented from nsDocumentEncoder.

Definition at line 1076 of file nsDocumentEncoder.cpp.

{
  if (!aDocument)
    return NS_ERROR_INVALID_ARG;

  mIsTextWidget = PR_FALSE;
  Initialize();

  mIsCopying = PR_TRUE;
  mDocument = aDocument;


  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;
}

Here is the call graph for this function:

void nsDocumentEncoder::Initialize ( ) [protected, inherited]

Definition at line 189 of file nsDocumentEncoder.cpp.

Here is the caller graph for this function:

Definition at line 1750 of file nsDocumentEncoder.cpp.

{
  PRBool result = PR_FALSE;
  nsCOMPtr<nsITextContent> tc(do_QueryInterface(aNode));
  if (tc) {
    result = tc->IsOnlyWhitespace();
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1666 of file nsDocumentEncoder.cpp.

{
  nsCOMPtr<nsIDOMNode> parent;
  PRInt32 offset, j=0;
  nsresult rv = GetNodeLocation(aNode, address_of(parent), &offset);
  if (NS_FAILED(rv)) 
  {
    NS_NOTREACHED("failure in IsFirstNode");
    return PR_FALSE;
  }
  if (offset == 0)  // easy case, we are first dom child
    return PR_TRUE;
  if (!parent)  
    return PR_TRUE;
  
  // need to check if any nodes before us are really visible.
  // Mike wrote something for me along these lines in nsSelectionController,
  // but I don't think it's ready for use yet - revisit.
  // HACK: for now, simply consider all whitespace text nodes to be 
  // invisible formatting nodes.
  nsCOMPtr<nsIDOMNodeList> childList;
  nsCOMPtr<nsIDOMNode> child;

  rv = parent->GetChildNodes(getter_AddRefs(childList));
  if (NS_FAILED(rv) || !childList) 
  {
    NS_NOTREACHED("failure in IsFirstNode");
    return PR_TRUE;
  }
  while (j < offset)
  {
    childList->Item(j, getter_AddRefs(child));
    if (!IsEmptyTextContent(child)) 
      return PR_FALSE;
    j++;
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1707 of file nsDocumentEncoder.cpp.

{
  nsCOMPtr<nsIDOMNode> parent;
  PRInt32 offset,j;
  PRUint32 numChildren;
  nsresult rv = GetNodeLocation(aNode, address_of(parent), &offset);
  if (NS_FAILED(rv)) 
  {
    NS_NOTREACHED("failure in IsLastNode");
    return PR_FALSE;
  }
  GetLengthOfDOMNode(parent, numChildren); 
  if (offset+1 == (PRInt32)numChildren) // easy case, we are last dom child
    return PR_TRUE;
  if (!parent)
    return PR_TRUE;
  // need to check if any nodes after us are really visible.
  // Mike wrote something for me along these lines in nsSelectionController,
  // but I don't think it's ready for use yet - revisit.
  // HACK: for now, simply consider all whitespace text nodes to be 
  // invisible formatting nodes.
  j = (PRInt32)numChildren-1;
  nsCOMPtr<nsIDOMNodeList>childList;
  nsCOMPtr<nsIDOMNode> child;
  rv = parent->GetChildNodes(getter_AddRefs(childList));
  if (NS_FAILED(rv) || !childList) 
  {
    NS_NOTREACHED("failure in IsLastNode");
    return PR_TRUE;
  }
  while (j > offset)
  {
    childList->Item(j, getter_AddRefs(child));
    j--;
    if (IsMozBR(child))  // we ignore trailing moz BRs.  
      continue;
    if (!IsEmptyTextContent(child)) 
      return PR_FALSE;
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsHTMLCopyEncoder::IsMozBR ( nsIDOMNode aNode) [protected]

Definition at line 1608 of file nsDocumentEncoder.cpp.

{
  if (IsTag(aNode, nsHTMLAtoms::br))
  {
    nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(aNode);
    if (elem)
    {
      nsAutoString typeAttrName(NS_LITERAL_STRING("type"));
      nsAutoString typeAttrVal;
      nsresult rv = elem->GetAttribute(typeAttrName, typeAttrVal);
      ToLowerCase(typeAttrVal);
      if (NS_SUCCEEDED(rv) && (typeAttrVal.EqualsLiteral("_moz")))
        return PR_TRUE;
    }
    return PR_FALSE;
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsHTMLCopyEncoder::IsRoot ( nsIDOMNode aNode) [protected]

Definition at line 1651 of file nsDocumentEncoder.cpp.

{
  if (aNode)
  {
    if (mIsTextWidget) 
      return (IsTag(aNode, nsHTMLAtoms::div));
    else
      return (IsTag(aNode, nsHTMLAtoms::body) || 
              IsTag(aNode, nsHTMLAtoms::td)   ||
              IsTag(aNode, nsHTMLAtoms::th));
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsDocumentEncoder::IsTag ( nsIDOMNode aNode,
nsIAtom aAtom 
) [static, protected, inherited]

Definition at line 397 of file nsDocumentEncoder.cpp.

{
  nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
  return content && content->Tag() == aAtom;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCopyEncoder::PromoteAncestorChain ( nsCOMPtr< nsIDOMNode > *  ioNode,
PRInt32 ioStartOffset,
PRInt32 ioEndOffset 
) [protected]

Definition at line 1365 of file nsDocumentEncoder.cpp.

{
  if (!ioNode || !ioStartOffset || !ioEndOffset) return NS_ERROR_NULL_POINTER;

  nsresult rv = NS_OK;
  PRBool done = PR_FALSE;

  nsCOMPtr<nsIDOMNode> frontNode, endNode, parent;
  PRInt32 frontOffset, endOffset;
  
  // loop for as long as we can promote both endpoints
  while (!done)
  {
    rv = (*ioNode)->GetParentNode(getter_AddRefs(parent));
    if ((NS_FAILED(rv)) || !parent)
      done = PR_TRUE;
    else
    {
      // passing parent as last param to GetPromotedPoint() allows it to promote only one level
      // up the heirarchy.
      rv = GetPromotedPoint( kStart, *ioNode, *ioStartOffset, address_of(frontNode), &frontOffset, parent);
      NS_ENSURE_SUCCESS(rv, rv);
      // 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) )
        done = PR_TRUE;
      else
      {
        *ioNode = frontNode;  
        *ioStartOffset = frontOffset;
        *ioEndOffset = endOffset;
      }
    }
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1316 of file nsDocumentEncoder.cpp.

{
  if (!inRange) return NS_ERROR_NULL_POINTER;
  nsresult rv;
  nsCOMPtr<nsIDOMNode> startNode, endNode, common;
  PRInt32 startOffset, endOffset;
  
  rv = inRange->GetCommonAncestorContainer(getter_AddRefs(common));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = inRange->GetStartContainer(getter_AddRefs(startNode));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = inRange->GetStartOffset(&startOffset);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = inRange->GetEndContainer(getter_AddRefs(endNode));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = inRange->GetEndOffset(&endOffset);
  NS_ENSURE_SUCCESS(rv, rv);
  
  nsCOMPtr<nsIDOMNode> opStartNode;
  nsCOMPtr<nsIDOMNode> opEndNode;
  PRInt32 opStartOffset, opEndOffset;
  nsCOMPtr<nsIDOMRange> opRange;
  
  // examine range endpoints.  
  rv = GetPromotedPoint( kStart, startNode, startOffset, address_of(opStartNode), &opStartOffset, common);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = GetPromotedPoint( kEnd, endNode, endOffset, address_of(opEndNode), &opEndOffset, common);
  NS_ENSURE_SUCCESS(rv, rv);
  
  // if both range endpoints are at the common ancestor, check for possible inclusion of ancestors
  if ( (opStartNode == common) && (opEndNode == common) )
  {
    rv = PromoteAncestorChain(address_of(opStartNode), &opStartOffset, &opEndOffset);
    NS_ENSURE_SUCCESS(rv, rv);
    opEndNode = opStartNode;
  }
  
  // set the range to the new values
  rv = inRange->SetStart(opStartNode, opStartOffset);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = inRange->SetEnd(opEndNode, opEndOffset);
  return rv;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDocumentEncoder::SerializeNodeEnd ( nsIDOMNode aNode,
nsAString &  aStr 
) [protected, inherited]

Definition at line 342 of file nsDocumentEncoder.cpp.

{
  PRUint16 type;

  aNode->GetNodeType(&type);
  switch (type) {
    case nsIDOMNode::ELEMENT_NODE:
    {
      nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
      mSerializer->AppendElementEnd(element, aStr);
      break;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDocumentEncoder::SerializeNodeStart ( nsIDOMNode aNode,
PRInt32  aStartOffset,
PRInt32  aEndOffset,
nsAString &  aStr 
) [protected, inherited]

Definition at line 274 of file nsDocumentEncoder.cpp.

{
  PRUint16 type;

  nsCOMPtr<nsIDOMNode> node;
  if (mNodeFixup)
  {
    mNodeFixup->FixupNode(aNode, getter_AddRefs(node));
  }
  if (!node)
  {
    node = do_QueryInterface(aNode);
  }

  node->GetNodeType(&type);
  switch (type) {
    case nsIDOMNode::ELEMENT_NODE:
    {
      nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
      // Because FixupNode() may have done a shallow copy of aNode
      // we need to tell the serializer if the original had children.
      // Some serializers (notably XML) need this information 
      // in order to handle empty tags properly.
      PRBool hasChildren;
      mSerializer->AppendElementStart(element, 
                                      NS_SUCCEEDED(aNode->HasChildNodes(&hasChildren)) && hasChildren,
                                      aStr);
      break;
    }
    case nsIDOMNode::TEXT_NODE:
    {
      nsCOMPtr<nsIDOMText> text = do_QueryInterface(node);
      mSerializer->AppendText(text, aStartOffset, aEndOffset, aStr);
      break;
    }
    case nsIDOMNode::CDATA_SECTION_NODE:
    {
      nsCOMPtr<nsIDOMCDATASection> cdata = do_QueryInterface(node);
      mSerializer->AppendCDATASection(cdata, aStartOffset, aEndOffset, aStr);
      break;
    }
    case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
    {
      nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(node);
      mSerializer->AppendProcessingInstruction(pi, aStartOffset, aEndOffset,
                                               aStr);
      break;
    }
    case nsIDOMNode::COMMENT_NODE:
    {
      nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(node);
      mSerializer->AppendComment(comment, aStartOffset, aEndOffset, aStr);
      break;
    }
    case nsIDOMNode::DOCUMENT_TYPE_NODE:
    {
      nsCOMPtr<nsIDOMDocumentType> doctype = do_QueryInterface(node);
      mSerializer->AppendDoctype(doctype, aStr);
      break;
    }
  }
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDocumentEncoder::SerializeRangeContextEnd ( const nsVoidArray aAncestorArray,
nsAString &  aString 
) [protected, inherited]

Definition at line 793 of file nsDocumentEncoder.cpp.

{
  PRInt32 i = 0;
  PRInt32 count = aAncestorArray.Count();
  nsresult rv = NS_OK;

  while (i < count) {
    nsIDOMNode *node = (nsIDOMNode *)aAncestorArray.ElementAt(i++);

    if (!node)
      break;

    if (IncludeInContext(node)) {
      rv = SerializeNodeEnd(node, aString);

      if (NS_FAILED(rv))
        break;
    }
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDocumentEncoder::SerializeRangeContextStart ( const nsVoidArray aAncestorArray,
nsAString &  aString 
) [protected, inherited]

Definition at line 769 of file nsDocumentEncoder.cpp.

{
  PRInt32 i = aAncestorArray.Count();
  nsresult rv = NS_OK;

  while (i > 0) {
    nsIDOMNode *node = (nsIDOMNode *)aAncestorArray.ElementAt(--i);

    if (!node)
      break;

    if (IncludeInContext(node)) {
      rv = SerializeNodeStart(node, 0, -1, aString);

      if (NS_FAILED(rv))
        break;
    }
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDocumentEncoder::SerializeRangeNodes ( nsIDOMRange aRange,
nsIDOMNode aNode,
nsAString &  aString,
PRInt32  aDepth 
) [protected, inherited]

Definition at line 649 of file nsDocumentEncoder.cpp.

{
  nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
  NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);

  nsresult rv=NS_OK;
  
  // get start and end nodes for this recursion level
  nsCOMPtr<nsIContent> startNode, endNode;
  PRInt32 start = mStartRootIndex - aDepth;
  if (start >= 0 && start <= mStartNodes.Count())
    startNode = NS_STATIC_CAST(nsIContent *, mStartNodes[start]);

  PRInt32 end = mEndRootIndex - aDepth;
  if (end >= 0 && end <= mEndNodes.Count())
    endNode = NS_STATIC_CAST(nsIContent *, mEndNodes[end]);

  if ((startNode != content) && (endNode != content))
  {
    // node is completely contained in range.  Serialize the whole subtree
    // rooted by this node.
    rv = SerializeToStringRecursive(aNode, aString);
    NS_ENSURE_SUCCESS(rv, rv);
  }
  else
  {
    // due to implementation it is impossible for text node to be both start and end of 
    // range.  We would have handled that case without getting here.
    if (IsTextNode(aNode))
    {
      if (startNode == content)
      {
        PRInt32 startOffset;
        aRange->GetStartOffset(&startOffset);
        rv = SerializeNodeStart(aNode, startOffset, -1, aString);
        NS_ENSURE_SUCCESS(rv, rv);
      }
      else
      {
        PRInt32 endOffset;
        aRange->GetEndOffset(&endOffset);
        rv = SerializeNodeStart(aNode, 0, endOffset, aString);
        NS_ENSURE_SUCCESS(rv, rv);
      }
    }
    else
    {
      if (aNode != mCommonParent)
      {
        if (IncludeInContext(aNode))
        {
          // halt the incrementing of mStartDepth/mEndDepth.  This is
          // so paste client will include this node in paste.
          mHaltRangeHint = PR_TRUE;
        }
        if ((startNode == content) && !mHaltRangeHint) mStartDepth++;
        if ((endNode == content) && !mHaltRangeHint) mEndDepth++;
      
        // serialize the start of this node
        rv = SerializeNodeStart(aNode, 0, -1, aString);
        NS_ENSURE_SUCCESS(rv, rv);
      }
      
      // do some calculations that will tell us which children of this
      // node are in the range.
      nsCOMPtr<nsIDOMNode> childAsNode;
      PRInt32 startOffset = 0, endOffset = -1;
      if (startNode == content && mStartRootIndex >= aDepth)
        startOffset = NS_PTR_TO_INT32(mStartOffsets[mStartRootIndex - aDepth]);
      if (endNode == content && mEndRootIndex >= aDepth)
        endOffset = NS_PTR_TO_INT32(mEndOffsets[mEndRootIndex - aDepth]) ;
      // generated content will cause offset values of -1 to be returned.  
      PRInt32 j;
      PRUint32 childCount = content->GetChildCount();

      if (startOffset == -1) startOffset = 0;
      if (endOffset == -1) endOffset = childCount;
      else
      {
        // if we are at the "tip" of the selection, endOffset is fine.
        // otherwise, we need to add one.  This is because of the semantics
        // of the offset list created by GetAncestorsAndOffsets().  The
        // intermediate points on the list use the endOffset of the 
        // location of the ancestor, rather than just past it.  So we need
        // to add one here in order to include it in the children we serialize.
        nsCOMPtr<nsIDOMNode> endParent;
        aRange->GetEndContainer(getter_AddRefs(endParent));
        if (aNode != endParent)
        {
          endOffset++;
        }
      }
      // serialize the children of this node that are in the range
      for (j=startOffset; j<endOffset; j++)
      {
        childAsNode = do_QueryInterface(content->GetChildAt(j));

        if ((j==startOffset) || (j==endOffset-1))
          rv = SerializeRangeNodes(aRange, childAsNode, aString, aDepth+1);
        else
          rv = SerializeToStringRecursive(childAsNode, aString);

        NS_ENSURE_SUCCESS(rv, rv);
      }

      // serialize the end of this node
      if (aNode != mCommonParent)
      {
        rv = SerializeNodeEnd(aNode, aString);
        NS_ENSURE_SUCCESS(rv, rv); 
      }
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDocumentEncoder::SerializeRangeToString ( nsIDOMRange aRange,
nsAString &  aOutputString 
) [protected, inherited]

Definition at line 818 of file nsDocumentEncoder.cpp.

{
  if (!aRange)
    return NS_OK;

  PRBool collapsed;

  aRange->GetCollapsed(&collapsed);

  if (collapsed)
    return NS_OK;

  nsCOMPtr<nsIDOMNode> startParent, endParent;
  PRInt32 startOffset, endOffset;
  
  aRange->GetCommonAncestorContainer(getter_AddRefs(mCommonParent));

  if (!mCommonParent)
    return NS_OK;
  
  aRange->GetStartContainer(getter_AddRefs(startParent));
  NS_ENSURE_TRUE(startParent, NS_ERROR_FAILURE);
  aRange->GetStartOffset(&startOffset);

  aRange->GetEndContainer(getter_AddRefs(endParent));
  NS_ENSURE_TRUE(endParent, NS_ERROR_FAILURE);
  aRange->GetEndOffset(&endOffset);

  mCommonAncestors.Clear();
  mStartNodes.Clear();
  mStartOffsets.Clear();
  mEndNodes.Clear();
  mEndOffsets.Clear();

  nsContentUtils::GetAncestors(mCommonParent, &mCommonAncestors);
  nsContentUtils::GetAncestorsAndOffsets(startParent, startOffset,
                                         &mStartNodes, &mStartOffsets);
  nsContentUtils::GetAncestorsAndOffsets(endParent, endOffset,
                                         &mEndNodes, &mEndOffsets);

  nsCOMPtr<nsIContent> commonContent = do_QueryInterface(mCommonParent);
  mStartRootIndex = mStartNodes.IndexOf(commonContent);
  mEndRootIndex = mEndNodes.IndexOf(commonContent);
  
  nsresult rv = NS_OK;

  rv = SerializeRangeContextStart(mCommonAncestors, aOutputString);
  NS_ENSURE_SUCCESS(rv, rv);

  if ((startParent == endParent) && IsTextNode(startParent))
  {
    rv = SerializeNodeStart(startParent, startOffset, endOffset, aOutputString);
    NS_ENSURE_SUCCESS(rv, rv);
  }
  else
  {
    rv = SerializeRangeNodes(aRange, mCommonParent, aOutputString, 0);
    NS_ENSURE_SUCCESS(rv, rv);
  }
  rv = SerializeRangeContextEnd(mCommonAncestors, aOutputString);
  NS_ENSURE_SUCCESS(rv, rv);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDocumentEncoder::SerializeToStringRecursive ( nsIDOMNode aNode,
nsAString &  aStr 
) [protected, inherited]

Definition at line 361 of file nsDocumentEncoder.cpp.

{
  nsresult rv = SerializeNodeStart(aNode, 0, -1, aStr);
  NS_ENSURE_SUCCESS(rv, rv);

  PRBool hasChildren = PR_FALSE;

  aNode->HasChildNodes(&hasChildren);

  if (hasChildren) {
    nsCOMPtr<nsIDOMNodeList> childNodes;
    rv = aNode->GetChildNodes(getter_AddRefs(childNodes));
    NS_ENSURE_TRUE(childNodes, NS_SUCCEEDED(rv) ? NS_ERROR_FAILURE : rv);

    PRInt32 index, count;

    childNodes->GetLength((PRUint32*)&count);
    for (index = 0; index < count; index++) {
      nsCOMPtr<nsIDOMNode> child;

      rv = childNodes->Item(index, getter_AddRefs(child));
      NS_ENSURE_SUCCESS(rv, rv);

      rv = SerializeToStringRecursive(child, aStr);
      NS_ENSURE_SUCCESS(rv, rv);     
    }
  }

  rv = SerializeNodeEnd(aNode, aStr);
  NS_ENSURE_SUCCESS(rv, rv);

  return FlushText(aStr, PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsDocumentEncoder::SetCharset ( const nsACString &  aCharset) [virtual, inherited]

Documents typically have an intrinsic character set.

If no intrinsic value is found, the platform character set is used. aCharset overrides the both the intrinsic or platform character set when encoding the document.

Possible result codes: NS_ERROR_NO_CHARSET_CONVERTER

Implements nsIDocumentEncoder.

Definition at line 253 of file nsDocumentEncoder.cpp.

{
  mCharset = aCharset;
  return NS_OK;
}
NS_IMETHODIMP nsDocumentEncoder::SetNode ( nsIDOMNode aNode) [virtual, inherited]

If the node is set to a non-null value, then the node is used for encoding, otherwise the entire document or range or selection is encoded.

Implements nsIDocumentEncoder.

Definition at line 246 of file nsDocumentEncoder.cpp.

{
  mNode = aNode;
  return NS_OK;
}

Set the fixup object associated with node persistence.

Implements nsIDocumentEncoder.

Definition at line 994 of file nsDocumentEncoder.cpp.

{
  mNodeFixup = aFixup;
  return NS_OK;
}
NS_IMETHODIMP nsDocumentEncoder::SetRange ( nsIDOMRange aRange) [virtual, inherited]

If the range is set to a non-null value, then the range is used for encoding, otherwise the entire document or selection is encoded.

Implements nsIDocumentEncoder.

Definition at line 239 of file nsDocumentEncoder.cpp.

{
  mRange = aRange;
  return NS_OK;
}

If the selection is set to a non-null value, then the selection is used for encoding, otherwise the entire document is encoded.

Reimplemented from nsDocumentEncoder.

Definition at line 1103 of file nsDocumentEncoder.cpp.

{
  // check for text widgets: we need to recognize these so that
  // we don't tweak the selection to be outside of the magic
  // div that ender-lite text widgets are embedded in.
  
  if (!aSelection) 
    return NS_ERROR_NULL_POINTER;
  
  nsCOMPtr<nsIDOMRange> range;
  nsCOMPtr<nsIDOMNode> commonParent;
  PRInt32 count = 0;

  nsresult rv = aSelection->GetRangeCount(&count);
  NS_ENSURE_SUCCESS(rv, rv);

  // if selection is uninitialized return
  if (!count)
    return NS_ERROR_FAILURE;
  
  // we'll just use the common parent of the first range.  Implicit assumption
  // here that multi-range selections are table cell selections, in which case
  // the common parent is somewhere in the table and we don't really care where.
  rv = aSelection->GetRangeAt(0, getter_AddRefs(range));
  NS_ENSURE_SUCCESS(rv, rv);
  if (!range)
    return NS_ERROR_NULL_POINTER;
  range->GetCommonAncestorContainer(getter_AddRefs(commonParent));

  for (nsCOMPtr<nsIContent> selContent(do_QueryInterface(commonParent));
       selContent;
       selContent = selContent->GetParent())
  {
    // checking for selection inside a plaintext form widget
    nsIAtom *atom = selContent->Tag();
    if (atom == nsHTMLAtoms::input ||
        atom == nsHTMLAtoms::textarea)
    {
      mIsTextWidget = PR_TRUE;
      break;
    }
    else if (atom == nsHTMLAtoms::body)
    {
      // check for moz prewrap style on body.  If it's there we are 
      // in a plaintext editor.  This is pretty cheezy but I haven't 
      // found a good way to tell if we are in a plaintext editor.
      nsCOMPtr<nsIDOMElement> bodyElem = do_QueryInterface(selContent);
      nsAutoString wsVal;
      rv = bodyElem->GetAttribute(NS_LITERAL_STRING("style"), wsVal);
      if (NS_SUCCEEDED(rv) && (kNotFound != wsVal.Find(NS_LITERAL_STRING("-moz-pre-wrap"))))
      {
        mIsTextWidget = PR_TRUE;
        break;
      }
    }
  }
  
  // also consider ourselves in a text widget if we can't find an html document
  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
  if (!htmlDoc || mDocument->IsCaseSensitive())
    mIsTextWidget = PR_TRUE;
  
  // normalize selection if we are not in a widget
  if (mIsTextWidget) 
  {
    mSelection = aSelection;
    mMimeType.AssignLiteral("text/plain");
    return NS_OK;
  }
  
  // there's no Clone() for selection! fix...
  //nsresult rv = aSelection->Clone(getter_AddRefs(mSelection);
  //NS_ENSURE_SUCCESS(rv, rv);
  NS_NewDomSelection(getter_AddRefs(mSelection));
  NS_ENSURE_TRUE(mSelection, NS_ERROR_FAILURE);
  nsCOMPtr<nsISelectionPrivate> privSelection( do_QueryInterface(aSelection) );
  NS_ENSURE_TRUE(privSelection, NS_ERROR_FAILURE);
  
  // get selection range enumerator
  nsCOMPtr<nsIEnumerator> enumerator;
  rv = privSelection->GetEnumerator(getter_AddRefs(enumerator));
  NS_ENSURE_SUCCESS(rv, rv);
  NS_ENSURE_TRUE(enumerator, NS_ERROR_FAILURE);

  // loop thru the ranges in the selection
  enumerator->First(); 
  nsCOMPtr<nsISupports> currentItem;
  while ((NS_ENUMERATOR_FALSE == enumerator->IsDone()))
  {
    rv = enumerator->CurrentItem(getter_AddRefs(currentItem));
    NS_ENSURE_SUCCESS(rv, rv);
    NS_ENSURE_TRUE(currentItem, NS_ERROR_FAILURE);
    
    range = do_QueryInterface(currentItem);
    NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
    nsCOMPtr<nsIDOMRange> myRange;
    range->CloneRange(getter_AddRefs(myRange));
    NS_ENSURE_TRUE(myRange, NS_ERROR_FAILURE);

    // adjust range to include any ancestors who's children are entirely selected
    rv = PromoteRange(myRange);
    NS_ENSURE_SUCCESS(rv, rv);
    
    rv = mSelection->AddRange(myRange);
    NS_ENSURE_SUCCESS(rv, rv);

    enumerator->Next();
  }

  return NS_OK;
}

Here is the call graph for this function:

Set a wrap column.

This may have no effect in some types of encoders.

Implements nsIDocumentEncoder.

Definition at line 225 of file nsDocumentEncoder.cpp.

{
  mWrapColumn = aWC;
  return NS_OK;
}

Member Data Documentation

nsCString nsDocumentEncoder::mCharset [protected, inherited]

Definition at line 153 of file nsDocumentEncoder.cpp.

Definition at line 150 of file nsDocumentEncoder.cpp.

nsAutoVoidArray nsDocumentEncoder::mCommonAncestors [protected, inherited]

Definition at line 160 of file nsDocumentEncoder.cpp.

Definition at line 148 of file nsDocumentEncoder.cpp.

Definition at line 141 of file nsDocumentEncoder.cpp.

PRUint32 nsDocumentEncoder::mEndDepth [protected, inherited]

Definition at line 157 of file nsDocumentEncoder.cpp.

nsAutoVoidArray nsDocumentEncoder::mEndNodes [protected, inherited]

Definition at line 163 of file nsDocumentEncoder.cpp.

nsAutoVoidArray nsDocumentEncoder::mEndOffsets [protected, inherited]

Definition at line 164 of file nsDocumentEncoder.cpp.

PRInt32 nsDocumentEncoder::mEndRootIndex [protected, inherited]

Definition at line 159 of file nsDocumentEncoder.cpp.

PRUint32 nsDocumentEncoder::mFlags [protected, inherited]

Definition at line 154 of file nsDocumentEncoder.cpp.

Definition at line 165 of file nsDocumentEncoder.cpp.

Definition at line 166 of file nsDocumentEncoder.cpp.

Definition at line 1058 of file nsDocumentEncoder.cpp.

nsString nsDocumentEncoder::mMimeType [protected, inherited]

Definition at line 152 of file nsDocumentEncoder.cpp.

nsCOMPtr<nsIDOMNode> nsDocumentEncoder::mNode [protected, inherited]

Definition at line 144 of file nsDocumentEncoder.cpp.

Definition at line 149 of file nsDocumentEncoder.cpp.

Definition at line 143 of file nsDocumentEncoder.cpp.

Definition at line 142 of file nsDocumentEncoder.cpp.

Definition at line 146 of file nsDocumentEncoder.cpp.

PRUint32 nsDocumentEncoder::mStartDepth [protected, inherited]

Definition at line 156 of file nsDocumentEncoder.cpp.

nsAutoVoidArray nsDocumentEncoder::mStartNodes [protected, inherited]

Definition at line 161 of file nsDocumentEncoder.cpp.

nsAutoVoidArray nsDocumentEncoder::mStartOffsets [protected, inherited]

Definition at line 162 of file nsDocumentEncoder.cpp.

Definition at line 158 of file nsDocumentEncoder.cpp.

Definition at line 145 of file nsDocumentEncoder.cpp.

Definition at line 147 of file nsDocumentEncoder.cpp.

PRUint32 nsDocumentEncoder::mWrapColumn [protected, inherited]

Definition at line 155 of file nsDocumentEncoder.cpp.


The documentation for this class was generated from the following file: