bug 57863: pasting multiple table cells outside of table doens't work. r=cmanske;sr=kin

This commit is contained in:
jfrancis%netscape.com 2001-03-09 01:36:38 +00:00
parent f38ac7825d
commit d916478ef5
3 changed files with 73 additions and 65 deletions

View File

@ -120,7 +120,6 @@ protected:
nsresult FlushText(nsAWritableString& aString, PRBool aForce);
static PRBool IsTag(nsIDOMNode* aNode, nsIAtom* aAtom);
static nsresult AdjustCommonParent(nsCOMPtr<nsIDOMNode> *aCommPar);
virtual PRBool IncludeInContext(nsIDOMNode *aNode);
@ -375,35 +374,6 @@ nsDocumentEncoder::IsTag(nsIDOMNode* aNode, nsIAtom* aAtom)
return PR_FALSE;
}
nsresult
nsDocumentEncoder::AdjustCommonParent(nsCOMPtr<nsIDOMNode> *aCommPar)
{
// if common parent is a table section other than
// td or th, look for the parent of the enclosing
// table and use that instead.
if (IsTag(*aCommPar, nsHTMLAtoms::tr) ||
IsTag(*aCommPar, nsHTMLAtoms::tbody) ||
IsTag(*aCommPar, nsHTMLAtoms::tfoot) ||
IsTag(*aCommPar, nsHTMLAtoms::thead) ||
IsTag(*aCommPar, nsHTMLAtoms::table))
{
nsCOMPtr<nsIDOMNode> parent, tmp=*aCommPar;
while (tmp)
{
if (IsTag(parent, nsHTMLAtoms::table))
{
// return parent of table
parent->GetParentNode(getter_AddRefs(tmp));
*aCommPar = tmp;
break;
}
tmp->GetParentNode(getter_AddRefs(parent));
tmp = parent;
}
}
return NS_OK;
}
static nsresult
ConvertAndWrite(nsAReadableString& aString,
nsIOutputStream* aStream,
@ -1198,7 +1168,13 @@ nsHTMLCopyEncoder::EncodeToStringWithContext(nsAWritableString& aEncodedString,
// leaf of ancestors might be text node. If so discard it.
nsCOMPtr<nsIDOMNode> node;
node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(0));
if (node && IsTextNode(node)) mCommonAncestors.RemoveElementAt(0);
if (node && IsTextNode(node))
{
mCommonAncestors.RemoveElementAt(0);
// don't forget to adjust range depth info
if (mStartDepth) mStartDepth--;
if (mEndDepth) mEndDepth--;
}
PRInt32 i = mCommonAncestors.Count();

View File

@ -215,12 +215,12 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsString& aInputStr
if (NS_FAILED(res)) return res;
// Get the first range in the selection, for context:
nsCOMPtr<nsIDOMRange> range;
nsCOMPtr<nsIDOMRange> range, clone;
res = selection->GetRangeAt(0, getter_AddRefs(range));
if (NS_FAILED(res))
return res;
nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(range));
NS_ENSURE_SUCCESS(res, res);
res = range->CloneRange(getter_AddRefs(clone));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(clone));
if (!nsrange)
return NS_ERROR_NO_INTERFACE;
@ -1503,7 +1503,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText,
return res;
}
nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *nsrange,
nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *aNSRange,
const nsString& aInputString,
const nsString& aContextStr,
const nsString& aInfoStr,
@ -1511,25 +1511,21 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *nsrange,
PRInt32 *outRangeStartHint,
PRInt32 *outRangeEndHint)
{
if (!outFragNode || !outRangeStartHint || !outRangeEndHint)
if (!outFragNode || !outRangeStartHint || !outRangeEndHint || !aNSRange)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDOMDocumentFragment> docfrag;
nsresult res = nsrange->CreateContextualFragment(aInputString, getter_AddRefs(docfrag));
NS_ENSURE_SUCCESS(res, res);
*outFragNode = do_QueryInterface(docfrag);
res = StripFormattingNodes(*outFragNode);
NS_ENSURE_SUCCESS(res, res);
// if we have context info, create a fragment for that too
nsCOMPtr<nsIDOMNode> contextAsNode;
nsresult res = NS_OK;
// if we have context info, create a fragment for that
nsCOMPtr<nsIDOMDocumentFragment> contextfrag;
nsCOMPtr<nsIDOMNode> contextLeaf;
PRInt32 contextDepth = 0;
if (aContextStr.Length())
{
res = nsrange->CreateContextualFragment(aContextStr, getter_AddRefs(contextfrag));
res = aNSRange->CreateContextualFragment(aContextStr, getter_AddRefs(contextfrag));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> contextAsNode (do_QueryInterface(contextfrag));
contextAsNode = do_QueryInterface(contextfrag);
res = StripFormattingNodes(contextAsNode);
NS_ENSURE_SUCCESS(res, res);
// cache the deepest leaf in the context
@ -1540,6 +1536,26 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *nsrange,
contextLeaf = tmp;
contextLeaf->GetFirstChild(getter_AddRefs(tmp));
}
// tweak aNSRange to point inside contextAsNode
nsCOMPtr<nsIDOMRange> range(do_QueryInterface(aNSRange));
if (range)
{
aNSRange->NSDetach();
range->SetStart(contextLeaf,0);
range->SetEnd(contextLeaf,0);
}
}
// create fragment for pasted html
res = aNSRange->CreateContextualFragment(aInputString, getter_AddRefs(docfrag));
NS_ENSURE_SUCCESS(res, res);
*outFragNode = do_QueryInterface(docfrag);
res = StripFormattingNodes(*outFragNode);
NS_ENSURE_SUCCESS(res, res);
if (contextfrag)
{
nsCOMPtr<nsIDOMNode> junk;
// unite the two trees
contextLeaf->AppendChild(*outFragNode, getter_AddRefs(junk));
*outFragNode = contextAsNode;

View File

@ -215,12 +215,12 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsString& aInputStr
if (NS_FAILED(res)) return res;
// Get the first range in the selection, for context:
nsCOMPtr<nsIDOMRange> range;
nsCOMPtr<nsIDOMRange> range, clone;
res = selection->GetRangeAt(0, getter_AddRefs(range));
if (NS_FAILED(res))
return res;
nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(range));
NS_ENSURE_SUCCESS(res, res);
res = range->CloneRange(getter_AddRefs(clone));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(clone));
if (!nsrange)
return NS_ERROR_NO_INTERFACE;
@ -1503,7 +1503,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText,
return res;
}
nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *nsrange,
nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *aNSRange,
const nsString& aInputString,
const nsString& aContextStr,
const nsString& aInfoStr,
@ -1511,25 +1511,21 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *nsrange,
PRInt32 *outRangeStartHint,
PRInt32 *outRangeEndHint)
{
if (!outFragNode || !outRangeStartHint || !outRangeEndHint)
if (!outFragNode || !outRangeStartHint || !outRangeEndHint || !aNSRange)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDOMDocumentFragment> docfrag;
nsresult res = nsrange->CreateContextualFragment(aInputString, getter_AddRefs(docfrag));
NS_ENSURE_SUCCESS(res, res);
*outFragNode = do_QueryInterface(docfrag);
res = StripFormattingNodes(*outFragNode);
NS_ENSURE_SUCCESS(res, res);
// if we have context info, create a fragment for that too
nsCOMPtr<nsIDOMNode> contextAsNode;
nsresult res = NS_OK;
// if we have context info, create a fragment for that
nsCOMPtr<nsIDOMDocumentFragment> contextfrag;
nsCOMPtr<nsIDOMNode> contextLeaf;
PRInt32 contextDepth = 0;
if (aContextStr.Length())
{
res = nsrange->CreateContextualFragment(aContextStr, getter_AddRefs(contextfrag));
res = aNSRange->CreateContextualFragment(aContextStr, getter_AddRefs(contextfrag));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> contextAsNode (do_QueryInterface(contextfrag));
contextAsNode = do_QueryInterface(contextfrag);
res = StripFormattingNodes(contextAsNode);
NS_ENSURE_SUCCESS(res, res);
// cache the deepest leaf in the context
@ -1540,6 +1536,26 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *nsrange,
contextLeaf = tmp;
contextLeaf->GetFirstChild(getter_AddRefs(tmp));
}
// tweak aNSRange to point inside contextAsNode
nsCOMPtr<nsIDOMRange> range(do_QueryInterface(aNSRange));
if (range)
{
aNSRange->NSDetach();
range->SetStart(contextLeaf,0);
range->SetEnd(contextLeaf,0);
}
}
// create fragment for pasted html
res = aNSRange->CreateContextualFragment(aInputString, getter_AddRefs(docfrag));
NS_ENSURE_SUCCESS(res, res);
*outFragNode = do_QueryInterface(docfrag);
res = StripFormattingNodes(*outFragNode);
NS_ENSURE_SUCCESS(res, res);
if (contextfrag)
{
nsCOMPtr<nsIDOMNode> junk;
// unite the two trees
contextLeaf->AppendChild(*outFragNode, getter_AddRefs(junk));
*outFragNode = contextAsNode;