This commit is contained in:
Olli.Pettay%helsinki.fi 2007-03-01 09:25:25 +00:00
Родитель 787a33b3e8
Коммит d9e209b096
3 изменённых файлов: 40 добавлений и 35 удалений

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

@ -190,6 +190,7 @@ NS_IMPL_RELEASE(nsSVGPathSeg)
NS_INTERFACE_MAP_BEGIN(nsSVGPathSeg)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGPathSeg)
NS_INTERFACE_MAP_ENTRY(nsSVGPathSeg)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

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

@ -44,6 +44,20 @@
#include "nsSVGUtils.h"
#include "nsSVGPathDataParser.h"
// 0dfd1b3c-5638-4813-a6f8-5a325a35d06e
#define NS_SVGPATHSEG_IID \
{ 0x0dfd1b3c, 0x5638, 0x4813, \
{ 0xa6, 0xf8, 0x5a, 0x32, 0x5a, 0x35, 0xd0, 0x6e } }
#define NS_ENSURE_NATIVE_PATH_SEG(obj, retval) \
{ \
nsresult rv; \
if (retval) \
*retval = nsnull; \
nsCOMPtr<nsSVGPathSeg> path = do_QueryInterface(obj, &rv); \
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_SVG_WRONG_TYPE_ERR); \
}
class nsSVGPathSegList;
class nsISVGValue;
@ -60,6 +74,8 @@ struct nsSVGPathSegTraversalState {
class nsSVGPathSeg : public nsIDOMSVGPathSeg
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_SVGPATHSEG_IID)
nsSVGPathSeg() : mCurrentList(nsnull) {}
nsresult SetCurrentList(nsISVGValue* aList);
nsQueryReferent GetCurrentList() const;
@ -83,6 +99,8 @@ private:
nsCOMPtr<nsIWeakReference> mCurrentList;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsSVGPathSeg, NS_SVGPATHSEG_IID)
nsIDOMSVGPathSeg*
NS_NewSVGPathSegClosePath();

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

@ -83,10 +83,10 @@ public:
protected:
// implementation helpers:
void AppendElement(nsIDOMSVGPathSeg* aElement);
void AppendElement(nsSVGPathSeg* aElement);
void RemoveElementAt(PRInt32 index);
void InsertElementAt(nsIDOMSVGPathSeg* aElement, PRInt32 index);
void RemoveFromCurrentList(nsIDOMSVGPathSeg*);
void InsertElementAt(nsSVGPathSeg* aElement, PRInt32 index);
void RemoveFromCurrentList(nsSVGPathSeg*);
void ReleaseSegments(PRBool aModify = PR_TRUE);
@ -201,10 +201,7 @@ NS_IMETHODIMP nsSVGPathSegList::Clear()
NS_IMETHODIMP nsSVGPathSegList::Initialize(nsIDOMSVGPathSeg *newItem,
nsIDOMSVGPathSeg **_retval)
{
if (!newItem) {
*_retval = nsnull;
return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
}
NS_ENSURE_NATIVE_PATH_SEG(newItem, _retval);
Clear();
return AppendItem(newItem, _retval);
}
@ -227,17 +224,14 @@ NS_IMETHODIMP nsSVGPathSegList::InsertItemBefore(nsIDOMSVGPathSeg *newItem,
PRUint32 index,
nsIDOMSVGPathSeg **_retval)
{
*_retval = newItem;
if (!newItem)
return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
NS_ENSURE_NATIVE_PATH_SEG(newItem, _retval);
if (index >= NS_STATIC_CAST(PRUint32, mSegments.Count())) {
*_retval = nsnull;
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
InsertElementAt(newItem, index);
NS_ADDREF(*_retval);
InsertElementAt(NS_STATIC_CAST(nsSVGPathSeg*, newItem), index);
NS_ADDREF(*_retval = newItem);
return NS_OK;
}
@ -247,18 +241,15 @@ NS_IMETHODIMP nsSVGPathSegList::ReplaceItem(nsIDOMSVGPathSeg *newItem,
PRUint32 index,
nsIDOMSVGPathSeg **_retval)
{
*_retval = newItem;
if (!newItem)
return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
NS_ENSURE_NATIVE_PATH_SEG(newItem, _retval);
if (index >= NS_STATIC_CAST(PRUint32, mSegments.Count())) {
*_retval = nsnull;
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
InsertElementAt(newItem, index);
InsertElementAt(NS_STATIC_CAST(nsSVGPathSeg*, newItem), index);
RemoveElementAt(index+1);
NS_ADDREF(*_retval);
NS_ADDREF(*_retval = newItem);
return NS_OK;
}
@ -283,11 +274,9 @@ NS_IMETHODIMP nsSVGPathSegList::RemoveItem(PRUint32 index, nsIDOMSVGPathSeg **_r
NS_IMETHODIMP nsSVGPathSegList::AppendItem(nsIDOMSVGPathSeg *newItem,
nsIDOMSVGPathSeg **_retval)
{
*_retval = newItem;
if (!newItem)
return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
AppendElement(newItem);
NS_ADDREF(*_retval);
NS_ENSURE_NATIVE_PATH_SEG(newItem, _retval);
NS_ADDREF(*_retval = newItem);
AppendElement(NS_STATIC_CAST(nsSVGPathSeg*, newItem));
return NS_OK;
}
@ -336,15 +325,14 @@ nsSVGPathSegList::ReleaseSegments(PRBool aModify)
}
void
nsSVGPathSegList::AppendElement(nsIDOMSVGPathSeg* aElement)
nsSVGPathSegList::AppendElement(nsSVGPathSeg* aElement)
{
WillModify();
// XXX: we should only remove an item from its current list if we
// successfully added it to this list
RemoveFromCurrentList(aElement);
mSegments.AppendObject(aElement);
nsSVGPathSeg* seg = NS_STATIC_CAST(nsSVGPathSeg*, aElement);
seg->SetCurrentList(this);
aElement->SetCurrentList(this);
DidModify();
}
@ -359,15 +347,14 @@ nsSVGPathSegList::RemoveElementAt(PRInt32 index)
}
void
nsSVGPathSegList::InsertElementAt(nsIDOMSVGPathSeg* aElement, PRInt32 index)
nsSVGPathSegList::InsertElementAt(nsSVGPathSeg* aElement, PRInt32 index)
{
WillModify();
// XXX: we should only remove an item from its current list if we
// successfully added it to this list
RemoveFromCurrentList(aElement);
mSegments.InsertObjectAt(aElement, index);
nsSVGPathSeg* seg = NS_STATIC_CAST(nsSVGPathSeg*, aElement);
seg->SetCurrentList(this);
aElement->SetCurrentList(this);
DidModify();
}
@ -375,18 +362,17 @@ nsSVGPathSegList::InsertElementAt(nsIDOMSVGPathSeg* aElement, PRInt32 index)
// is removed from its previous list before it is inserted into this
// list'. This is a helper function to do that.
void
nsSVGPathSegList::RemoveFromCurrentList(nsIDOMSVGPathSeg* aSeg)
nsSVGPathSegList::RemoveFromCurrentList(nsSVGPathSeg* aSeg)
{
nsSVGPathSeg *theSeg = NS_STATIC_CAST(nsSVGPathSeg*, aSeg);
nsCOMPtr<nsISVGValue> currentList = theSeg->GetCurrentList();
nsCOMPtr<nsISVGValue> currentList = aSeg->GetCurrentList();
if (currentList) {
// aSeg's current list must be cast back to a nsSVGPathSegList*
nsSVGPathSegList* otherSegList = NS_STATIC_CAST(nsSVGPathSegList*, currentList.get());
PRInt32 ix = otherSegList->mSegments.IndexOfObject(theSeg);
PRInt32 ix = otherSegList->mSegments.IndexOfObject(aSeg);
if (ix != -1) {
otherSegList->RemoveElementAt(ix);
}
theSeg->SetCurrentList(nsnull);
aSeg->SetCurrentList(nsnull);
}
}