Bug 598289 - Unable to paste CF_HTML from clipboard if StartHTML/EndHTML is -1. r=ehsan
This commit is contained in:
@@ -139,7 +139,8 @@ static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
||||
#define NS_FOUND_TARGET NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_EDITOR, 3)
|
||||
|
||||
// some little helpers
|
||||
static PRInt32 FindPositiveIntegerAfterString(const char *aLeadingString, nsCString &aCStr);
|
||||
static PRBool FindIntegerAfterString(const char *aLeadingString,
|
||||
nsCString &aCStr, PRInt32 &foundNumber);
|
||||
static nsresult RemoveFragComments(nsCString &theStr);
|
||||
static void RemoveBodyAndHead(nsIDOMNode *aNode);
|
||||
static nsresult FindTargetNode(nsIDOMNode *aStart, nsCOMPtr<nsIDOMNode> &aResult);
|
||||
@@ -1149,22 +1150,24 @@ NS_IMETHODIMP nsHTMLEditor::PrepareHTMLTransferable(nsITransferable **aTransfera
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
FindPositiveIntegerAfterString(const char *aLeadingString, nsCString &aCStr)
|
||||
PRBool
|
||||
FindIntegerAfterString(const char *aLeadingString,
|
||||
nsCString &aCStr, PRInt32 &foundNumber)
|
||||
{
|
||||
// first obtain offsets from cfhtml str
|
||||
PRInt32 numFront = aCStr.Find(aLeadingString);
|
||||
if (numFront == -1)
|
||||
return -1;
|
||||
return PR_FALSE;
|
||||
numFront += strlen(aLeadingString);
|
||||
|
||||
PRInt32 numBack = aCStr.FindCharInSet(CRLF, numFront);
|
||||
if (numBack == -1)
|
||||
return -1;
|
||||
return PR_FALSE;
|
||||
|
||||
nsCAutoString numStr(Substring(aCStr, numFront, numBack-numFront));
|
||||
PRInt32 errorCode;
|
||||
return numStr.ToInteger(&errorCode);
|
||||
foundNumber = numStr.ToInteger(&errorCode);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@@ -1191,15 +1194,37 @@ RemoveFragComments(nsCString & aStr)
|
||||
nsresult
|
||||
nsHTMLEditor::ParseCFHTML(nsCString & aCfhtml, PRUnichar **aStuffToPaste, PRUnichar **aCfcontext)
|
||||
{
|
||||
// first obtain offsets from cfhtml str
|
||||
PRInt32 startHTML = FindPositiveIntegerAfterString("StartHTML:", aCfhtml);
|
||||
PRInt32 endHTML = FindPositiveIntegerAfterString("EndHTML:", aCfhtml);
|
||||
PRInt32 startFragment = FindPositiveIntegerAfterString("StartFragment:", aCfhtml);
|
||||
PRInt32 endFragment = FindPositiveIntegerAfterString("EndFragment:", aCfhtml);
|
||||
|
||||
if ((startHTML<0) || (endHTML<0) || (startFragment<0) || (endFragment<0))
|
||||
// First obtain offsets from cfhtml str.
|
||||
PRInt32 startHTML, endHTML, startFragment, endFragment;
|
||||
if (!FindIntegerAfterString("StartHTML:", aCfhtml, startHTML) ||
|
||||
startHTML < -1)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!FindIntegerAfterString("EndHTML:", aCfhtml, endHTML) ||
|
||||
endHTML < -1)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!FindIntegerAfterString("StartFragment:", aCfhtml, startFragment) ||
|
||||
startFragment < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!FindIntegerAfterString("EndFragment:", aCfhtml, endFragment) ||
|
||||
startFragment < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// The StartHTML and EndHTML markers are allowed to be -1 to include everything.
|
||||
// See Reference: MSDN doc entitled "HTML Clipboard Format"
|
||||
// http://msdn.microsoft.com/en-us/library/aa767917(VS.85).aspx#unknown_854
|
||||
if (startHTML == -1) {
|
||||
startHTML = aCfhtml.Find("<!--StartFragment-->");
|
||||
if (startHTML == -1)
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (endHTML == -1) {
|
||||
const char endFragmentMarker[] = "<!--EndFragment-->";
|
||||
endHTML = aCfhtml.Find(endFragmentMarker);
|
||||
if (endHTML == -1)
|
||||
return PR_FALSE;
|
||||
endHTML += NS_ARRAY_LENGTH(endFragmentMarker) - 1;
|
||||
}
|
||||
|
||||
// create context string
|
||||
nsCAutoString contextUTF8(Substring(aCfhtml, startHTML, startFragment - startHTML) +
|
||||
NS_LITERAL_CSTRING("<!--" kInsertCookie "-->") +
|
||||
|
||||
Reference in New Issue
Block a user