Part 2 of the fix for bug 382778. r=smaug, sr=sicking.

This commit is contained in:
peterv@propagandism.org 2007-07-03 06:00:12 -07:00
Родитель 80053e4cb7
Коммит 076f59da12
1 изменённых файлов: 31 добавлений и 3 удалений

Просмотреть файл

@ -5609,6 +5609,21 @@ nsHTMLEditRules::PromoteRange(nsIDOMRange *inRange,
return res; return res;
} }
class nsUniqueFunctor : public nsBoolDomIterFunctor
{
public:
nsUniqueFunctor(nsCOMArray<nsIDOMNode> &aArray) : mArray(aArray)
{
}
virtual PRBool operator()(nsIDOMNode* aNode) // used to build list of all nodes iterator covers
{
return mArray.IndexOf(aNode) < 0;
}
private:
nsCOMArray<nsIDOMNode> &mArray;
};
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// GetNodesForOperation: run through the ranges in the array and construct // GetNodesForOperation: run through the ranges in the array and construct
// a new array of nodes to be acted on. // a new array of nodes to be acted on.
@ -5673,12 +5688,25 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges,
{ {
opRange = inArrayOfRanges[i]; opRange = inArrayOfRanges[i];
nsTrivialFunctor functor;
nsDOMSubtreeIterator iter; nsDOMSubtreeIterator iter;
res = iter.Init(opRange); res = iter.Init(opRange);
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
res = iter.AppendList(functor, outArrayOfNodes); if (outArrayOfNodes.Count() == 0) {
if (NS_FAILED(res)) return res; nsTrivialFunctor functor;
res = iter.AppendList(functor, outArrayOfNodes);
if (NS_FAILED(res)) return res;
}
else {
// We don't want duplicates in outArrayOfNodes, so we use an
// iterator/functor that only return nodes that are not already in
// outArrayOfNodes.
nsCOMArray<nsIDOMNode> nodes;
nsUniqueFunctor functor(outArrayOfNodes);
res = iter.AppendList(functor, nodes);
if (NS_FAILED(res)) return res;
if (!outArrayOfNodes.AppendObjects(nodes))
return NS_ERROR_OUT_OF_MEMORY;
}
} }
// certain operations should not act on li's and td's, but rather inside // certain operations should not act on li's and td's, but rather inside