зеркало из https://github.com/mozilla/pjs.git
added new interfaces for closure over all flavors and converters when clients ask for a list of known flavors.
This commit is contained in:
Родитель
42d6035400
Коммит
2a1b764154
|
@ -37,9 +37,30 @@ class nsITransferable : public nsISupports {
|
|||
static const nsIID& GetIID() { static nsIID iid = NS_ITRANSFERABLE_IID; return iid; }
|
||||
|
||||
/**
|
||||
* Get the list of data flavors that this transferable supports.
|
||||
* Computes a list of flavors that the transferable can accept into it, either through
|
||||
* intrinsic knowledge or input data converters.
|
||||
*
|
||||
* @param aDataFlavorList fills list with supported flavors
|
||||
* @param outFlavorList fills list with supported flavors. This is a copy of
|
||||
* the internal list, so it may be edited w/out affecting the transferable.
|
||||
*/
|
||||
NS_IMETHOD FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList ) = 0;
|
||||
|
||||
/**
|
||||
* Computes a list of flavors that the transferable can export, either through
|
||||
* intrinsic knowledge or output data converters.
|
||||
*
|
||||
* @param aDataFlavorList fills list with supported flavors. This is a copy of
|
||||
* the internal list, so it may be edited w/out affecting the transferable.
|
||||
*/
|
||||
NS_IMETHOD FlavorsTransferableCanExport ( nsISupportsArray** outFlavorList ) = 0;
|
||||
|
||||
/**
|
||||
* Get the list of data flavors that this transferable supports (w/out conversion).
|
||||
* (NOTE: We're not sure how useful this is in the presence of the above two methods,
|
||||
* but figured we'd keep it around just in case).
|
||||
*
|
||||
* @param aDataFlavorList fills list with supported flavors. This is a copy of
|
||||
* the internal list, so it may be edited w/out affecting the transferable.
|
||||
*/
|
||||
NS_IMETHOD GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList) = 0;
|
||||
|
||||
|
@ -55,13 +76,14 @@ class nsITransferable : public nsISupports {
|
|||
* Given a flavor retrieve the data.
|
||||
*
|
||||
* @param aFlavor the flavor of data to retrieve
|
||||
* @param aData the data
|
||||
* @param aData the data. This is NOT a copy, so the caller MUST NOT DELETE it.
|
||||
* @param aDataLen the length of the data
|
||||
*/
|
||||
NS_IMETHOD GetTransferData(nsIDataFlavor * aFlavor, void ** aData, PRUint32 * aDataLen) = 0;
|
||||
|
||||
/**
|
||||
* Set Data into the transferable as a specified DataFlavor
|
||||
* Set Data into the transferable as a specified DataFlavor. The transferable now
|
||||
* owns the data, so the caller must not delete it.
|
||||
*
|
||||
* @param aFlavor the flavor of data that is being set
|
||||
* @param aData the data
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "nsIFormatConverter.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kITransferableIID, NS_ITRANSFERABLE_IID);
|
||||
|
@ -49,7 +50,6 @@ nsTransferable::nsTransferable()
|
|||
{
|
||||
NS_INIT_REFCNT();
|
||||
mDataArray = new nsVoidArray();
|
||||
mFormatConv = nsnull;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -59,8 +59,6 @@ nsTransferable::nsTransferable()
|
|||
//-------------------------------------------------------------------------
|
||||
nsTransferable::~nsTransferable()
|
||||
{
|
||||
NS_IF_RELEASE(mFormatConv);
|
||||
|
||||
PRInt32 i;
|
||||
for (i=0;i<mDataArray->Count();i++) {
|
||||
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
|
||||
|
@ -252,14 +250,7 @@ NS_IMETHODIMP nsTransferable::IsLargeDataSet()
|
|||
*/
|
||||
NS_IMETHODIMP nsTransferable::SetConverter(nsIFormatConverter * aConverter)
|
||||
{
|
||||
if (nsnull != mFormatConv) {
|
||||
NS_RELEASE(mFormatConv);
|
||||
}
|
||||
|
||||
mFormatConv = aConverter;
|
||||
if (nsnull != mFormatConv) {
|
||||
NS_ADDREF(mFormatConv);
|
||||
}
|
||||
mFormatConv = dont_QueryInterface(aConverter);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -271,8 +262,76 @@ NS_IMETHODIMP nsTransferable::GetConverter(nsIFormatConverter ** aConverter)
|
|||
{
|
||||
if (nsnull != mFormatConv) {
|
||||
*aConverter = mFormatConv;
|
||||
NS_ADDREF(mFormatConv);
|
||||
NS_ADDREF(*aConverter);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// FlavorsTransferableCanImport
|
||||
//
|
||||
// Computes a list of flavors that the transferable can accept into it, either through
|
||||
// intrinsic knowledge or input data converters.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsTransferable :: FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList )
|
||||
{
|
||||
if ( !outFlavorList )
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// Get the flavor list, and on to the end of it, append the list of flavors we
|
||||
// can also get to through a converter. This is so that we can just walk the list
|
||||
// in one go, looking for the desired flavor.
|
||||
GetTransferDataFlavors(outFlavorList); // addrefs
|
||||
nsCOMPtr<nsIFormatConverter> converter;
|
||||
GetConverter(getter_AddRefs(converter));
|
||||
if ( converter ) {
|
||||
nsCOMPtr<nsISupportsArray> convertedList;
|
||||
converter->GetInputDataFlavors(getter_AddRefs(convertedList));
|
||||
if ( convertedList ) {
|
||||
for (int i=0;i<convertedList->Count();i++) {
|
||||
nsCOMPtr<nsISupports> temp = getter_AddRefs(convertedList->ElementAt(i));
|
||||
(*outFlavorList)->AppendElement(temp); // this addref's for us
|
||||
} // foreach flavor that can be converted to
|
||||
}
|
||||
} // if a converter exists
|
||||
|
||||
return NS_OK;
|
||||
|
||||
} // FlavorsTransferableCanImport
|
||||
|
||||
|
||||
//
|
||||
// FlavorsTransferableCanExport
|
||||
//
|
||||
// Computes a list of flavors that the transferable can export, either through
|
||||
// intrinsic knowledge or output data converters.
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsTransferable :: FlavorsTransferableCanExport ( nsISupportsArray** outFlavorList )
|
||||
{
|
||||
if ( !outFlavorList )
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// Get the flavor list, and on to the end of it, append the list of flavors we
|
||||
// can also get to through a converter. This is so that we can just walk the list
|
||||
// in one go, looking for the desired flavor.
|
||||
GetTransferDataFlavors(outFlavorList); // addrefs
|
||||
nsCOMPtr<nsIFormatConverter> converter;
|
||||
GetConverter(getter_AddRefs(converter));
|
||||
if ( converter ) {
|
||||
nsCOMPtr<nsISupportsArray> convertedList;
|
||||
converter->GetOutputDataFlavors(getter_AddRefs(convertedList));
|
||||
if ( convertedList ) {
|
||||
for (int i=0;i<convertedList->Count();i++) {
|
||||
nsCOMPtr<nsISupports> temp = getter_AddRefs(convertedList->ElementAt(i));
|
||||
(*outFlavorList)->AppendElement(temp); // this addref's for us
|
||||
} // foreach flavor that can be converted to
|
||||
}
|
||||
} // if a converter exists
|
||||
|
||||
return NS_OK;
|
||||
|
||||
} // FlavorsTransferableCanImport
|
||||
|
||||
|
|
|
@ -19,13 +19,15 @@
|
|||
#ifndef nsTransferable_h__
|
||||
#define nsTransferable_h__
|
||||
|
||||
#include "nsIFormatConverter.h"
|
||||
#include "nsITransferable.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
|
||||
class nsISupportsArray;
|
||||
class nsIDataFlavor;
|
||||
class nsDataObj;
|
||||
class nsVoidArray;
|
||||
class nsIFormatConverter;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -43,11 +45,12 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
//nsITransferable
|
||||
// Returns a copy of the flavor list
|
||||
NS_IMETHOD FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList ) ;
|
||||
NS_IMETHOD FlavorsTransferableCanExport ( nsISupportsArray** outFlavorList ) ;
|
||||
NS_IMETHOD GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList);
|
||||
NS_IMETHOD IsDataFlavorSupported(nsIDataFlavor * aFlavor);
|
||||
|
||||
// Transferable still owns |aData|. Do not delete it.
|
||||
// Transferable still owns |aData|. Do not delete it.
|
||||
NS_IMETHOD GetTransferData(nsIDataFlavor * aFlavor, void ** aData, PRUint32 * aDataLen);
|
||||
// Transferable consumes |aData|. Do not delete it.
|
||||
NS_IMETHOD SetTransferData(nsIDataFlavor * aFlavor, void * aData, PRUint32 aDataLen);
|
||||
|
@ -58,10 +61,11 @@ public:
|
|||
NS_IMETHOD SetConverter(nsIFormatConverter * aConverter);
|
||||
NS_IMETHOD GetConverter(nsIFormatConverter ** aConverter);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
nsVoidArray * mDataArray;
|
||||
nsIFormatConverter * mFormatConv;
|
||||
nsCOMPtr<nsIFormatConverter> mFormatConv;
|
||||
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче