зеркало из https://github.com/mozilla/gecko-dev.git
new clipboard apis and trying to reduce the number of copies we do in clipboard/d&d code.
This commit is contained in:
Родитель
dfbe041913
Коммит
58ab292e7d
|
@ -22,6 +22,7 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsISupportsArray;
|
||||
class nsITransferable;
|
||||
class nsIClipboardOwner;
|
||||
|
||||
|
@ -73,6 +74,18 @@ class nsIClipboard : public nsISupports {
|
|||
|
||||
NS_IMETHOD ForceDataToClipboard() = 0;
|
||||
|
||||
/**
|
||||
* This provides a way to give correct UI feedback about, for instance, a paste
|
||||
* should be allowed. It does _NOT_ actually retreive the data and should be a very
|
||||
* inexpensive call. All it does is check if there is data on the clipboard matching
|
||||
* any of the flavors in the given list.
|
||||
*
|
||||
* @aFlavorList - nsISupportsString's in a nsISupportsArray (for JavaScript).
|
||||
* @outResult - if data is present matching one of
|
||||
* @result NS_OK if successful.
|
||||
*/
|
||||
NS_IMETHOD HasDataMatchingFlavors ( nsISupportsArray* aFlavorList, PRBool * outResult ) = 0 ;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,13 +29,10 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
// XXX: This must go away when nsAutoCString moves out of nsFileSpec.h
|
||||
#include "nsFileSpec.h" // for nsAutoCString()
|
||||
|
||||
|
||||
|
||||
// The class statics:
|
||||
GtkWidget* nsClipboard::sWidget = 0;
|
||||
|
@ -264,14 +261,12 @@ NS_IMETHODIMP nsClipboard::SetNativeClipboardData()
|
|||
flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
|
||||
nsCOMPtr<nsISupportsString> currentFlavor ( do_QueryInterface(genericFlavor) );
|
||||
if ( currentFlavor ) {
|
||||
char* flavorStr;
|
||||
currentFlavor->ToString(&flavorStr);
|
||||
nsXPIDLCString flavorStr;
|
||||
currentFlavor->ToString(getter_Copies(flavorStr));
|
||||
gint format = GetFormat(flavorStr);
|
||||
|
||||
// add these types as selection targets
|
||||
RegisterFormat(format);
|
||||
|
||||
delete [] flavorStr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,42 +282,38 @@ void nsClipboard::AddTarget(GdkAtom aAtom)
|
|||
aAtom, aAtom);
|
||||
}
|
||||
|
||||
gint nsClipboard::GetFormat(const nsString &aMimeStr)
|
||||
gint nsClipboard::GetFormat(const char* aMimeStr)
|
||||
{
|
||||
gint type = TARGET_NONE;
|
||||
|
||||
nsCAutoString mimeStr ( CBufDescriptor(NS_CONST_CAST(char*,aMimeStr), PR_TRUE, PL_strlen(aMimeStr)+1) );
|
||||
#ifdef DEBUG_CLIPBOARD
|
||||
char *foo = aMimeStr.ToNewCString();
|
||||
g_print(" nsClipboard::GetFormat(%s)\n", foo);
|
||||
delete [] foo;
|
||||
g_print(" nsClipboard::GetFormat(%s)\n", aMimeStr);
|
||||
#endif
|
||||
if (aMimeStr.Equals(kTextMime)) {
|
||||
if (mimeStr.Equals(kTextMime)) {
|
||||
type = TARGET_TEXT_PLAIN;
|
||||
} else if (aMimeStr.Equals("STRING")) {
|
||||
} else if (mimeStr.Equals("STRING")) {
|
||||
type = TARGET_TEXT_PLAIN;
|
||||
} else if (aMimeStr.Equals(kXIFMime)) {
|
||||
} else if (mimeStr.Equals(kXIFMime)) {
|
||||
type = TARGET_TEXT_XIF;
|
||||
} else if (aMimeStr.Equals(kUnicodeMime)) {
|
||||
} else if (mimeStr.Equals(kUnicodeMime)) {
|
||||
type = TARGET_TEXT_UNICODE;
|
||||
} else if (aMimeStr.Equals(kHTMLMime)) {
|
||||
} else if (mimeStr.Equals(kHTMLMime)) {
|
||||
type = TARGET_TEXT_HTML;
|
||||
} else if (aMimeStr.Equals(kAOLMailMime)) {
|
||||
} else if (mimeStr.Equals(kAOLMailMime)) {
|
||||
type = TARGET_AOLMAIL;
|
||||
} else if (aMimeStr.Equals(kPNGImageMime)) {
|
||||
} else if (mimeStr.Equals(kPNGImageMime)) {
|
||||
type = TARGET_IMAGE_PNG;
|
||||
} else if (aMimeStr.Equals(kJPEGImageMime)) {
|
||||
} else if (mimeStr.Equals(kJPEGImageMime)) {
|
||||
type = TARGET_IMAGE_JPEG;
|
||||
} else if (aMimeStr.Equals(kGIFImageMime)) {
|
||||
} else if (mimeStr.Equals(kGIFImageMime)) {
|
||||
type = TARGET_IMAGE_GIF;
|
||||
}
|
||||
|
||||
#ifdef WE_DO_DND
|
||||
else if (aMimeStr.Equals(kDropFilesMime)) {
|
||||
else if (mimeStr.Equals(kDropFilesMime)) {
|
||||
format = CF_HDROP;
|
||||
} else {
|
||||
char * str = aMimeStr.ToNewCString();
|
||||
format = ::RegisterClipboardFormat(str);
|
||||
delete[] str;
|
||||
format = ::RegisterClipboardFormat(aMimeStr);
|
||||
}
|
||||
#endif
|
||||
return type;
|
||||
|
@ -530,21 +521,19 @@ nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable)
|
|||
// Walk through flavors and see which flavor matches the one being pasted:
|
||||
PRUint32 cnt;
|
||||
flavorList->Count(&cnt);
|
||||
char* foundFlavor = nsnull;
|
||||
for ( int i = 0; i < cnt; ++i ) {
|
||||
nsCAutoString foundFlavor;
|
||||
for ( PRUint32 i = 0; i < cnt; ++i ) {
|
||||
nsCOMPtr<nsISupports> genericFlavor;
|
||||
flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
|
||||
nsCOMPtr<nsISupportsString> currentFlavor ( do_QueryInterface(genericFlavor) );
|
||||
if ( currentFlavor ) {
|
||||
char* flavorStr;
|
||||
currentFlavor->ToString ( &flavorStr );
|
||||
nsXPIDLCString flavorStr;
|
||||
currentFlavor->ToString ( getter_Copies(flavorStr) );
|
||||
gint format = GetFormat(flavorStr);
|
||||
|
||||
if (DoConvert(format)) {
|
||||
foundFlavor = flavorStr;
|
||||
break;
|
||||
}
|
||||
delete [] flavorStr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -576,7 +565,6 @@ nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable)
|
|||
mSelectionData.length);
|
||||
|
||||
//delete name;
|
||||
delete [] foundFlavor;
|
||||
|
||||
// transferable is now copying the data, so we can free it.
|
||||
// g_free(mSelectionData.data);
|
||||
|
@ -807,7 +795,7 @@ void nsClipboard::SelectionGetCB(GtkWidget *widget,
|
|||
aInfo, size*8,
|
||||
(unsigned char *)clipboardData,
|
||||
dataLength);
|
||||
delete [] NS_REINTERPRET_CAST(unsigned char *, clipboardData);
|
||||
nsCRT::free ( NS_REINTERPRET_CAST(char*, clipboardData) );
|
||||
}
|
||||
else
|
||||
printf("Transferable didn't support the data flavor\n");
|
||||
|
|
|
@ -50,7 +50,7 @@ protected:
|
|||
|
||||
void AddTarget(GdkAtom aAtom);
|
||||
|
||||
gint GetFormat(const nsString & aMimeStr);
|
||||
gint GetFormat(const char* aMimeStr);
|
||||
void RegisterFormat(gint format);
|
||||
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
//
|
||||
// Remaining Work:
|
||||
// * only convert data to clipboard on an app switch.
|
||||
// * better mime type --> OS type conversion needed. Only a few formats supported now.
|
||||
//
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -38,6 +37,7 @@
|
|||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#include <Scrap.h>
|
||||
|
||||
|
@ -94,13 +94,13 @@ nsClipboard :: SetNativeClipboardData()
|
|||
// is required or not.
|
||||
PRUint32 cnt;
|
||||
flavorList->Count(&cnt);
|
||||
for ( int i = 0; i < cnt; ++i ) {
|
||||
for ( PRUint32 i = 0; i < cnt; ++i ) {
|
||||
nsCOMPtr<nsISupports> genericFlavor;
|
||||
flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
|
||||
nsCOMPtr<nsISupportsString> currentFlavor ( do_QueryInterface(genericFlavor) );
|
||||
if ( currentFlavor ) {
|
||||
char* flavorStr;
|
||||
currentFlavor->ToString(&flavorStr);
|
||||
nsXPIDLCString flavorStr;
|
||||
currentFlavor->ToString( getter_Copies(flavorStr) );
|
||||
|
||||
// find MacOS flavor
|
||||
ResType macOSFlavor = theMapper.MapMimeTypeToMacOSType(flavorStr);
|
||||
|
@ -121,8 +121,7 @@ nsClipboard :: SetNativeClipboardData()
|
|||
if ( numBytes != dataSize )
|
||||
errCode = NS_ERROR_FAILURE;
|
||||
|
||||
delete [] data;
|
||||
delete [] flavorStr;
|
||||
nsAllocator::Free ( data );
|
||||
}
|
||||
} // foreach flavor in transferable
|
||||
|
||||
|
@ -133,7 +132,7 @@ nsClipboard :: SetNativeClipboardData()
|
|||
long numBytes = ::PutScrap ( mappingLen, nsMimeMapperMac::MappingFlavor(), mapping );
|
||||
if ( numBytes != mappingLen )
|
||||
errCode = NS_ERROR_FAILURE;
|
||||
delete [] mapping;
|
||||
nsCRT::free ( NS_CONST_CAST(char*, mapping) );
|
||||
|
||||
return errCode;
|
||||
|
||||
|
@ -166,7 +165,7 @@ nsClipboard :: GetNativeClipboardData(nsITransferable * aTransferable)
|
|||
char* mimeMapperData = nsnull;
|
||||
GetDataOffClipboard ( nsMimeMapperMac::MappingFlavor(), &mimeMapperData, nsnull );
|
||||
nsMimeMapperMac theMapper ( mimeMapperData );
|
||||
delete [] mimeMapperData;
|
||||
nsCRT::free ( mimeMapperData );
|
||||
|
||||
//
|
||||
// Now walk down the list of flavors. When we find one that is actually on the
|
||||
|
@ -174,13 +173,13 @@ nsClipboard :: GetNativeClipboardData(nsITransferable * aTransferable)
|
|||
// implicitly handles conversions.
|
||||
PRUint32 cnt;
|
||||
flavorList->Count(&cnt);
|
||||
for ( int i = 0; i < cnt; ++i ) {
|
||||
for ( PRUint32 i = 0; i < cnt; ++i ) {
|
||||
nsCOMPtr<nsISupports> genericFlavor;
|
||||
flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
|
||||
nsCOMPtr<nsISupportsString> currentFlavor ( do_QueryInterface(genericFlavor) );
|
||||
if ( currentFlavor ) {
|
||||
char* flavorStr;
|
||||
currentFlavor->ToString ( &flavorStr );
|
||||
nsXPIDLCString flavorStr;
|
||||
currentFlavor->ToString ( getter_Copies(flavorStr) );
|
||||
|
||||
// find MacOS flavor
|
||||
ResType macOSFlavor = theMapper.MapMimeTypeToMacOSType(flavorStr);
|
||||
|
@ -196,12 +195,11 @@ nsClipboard :: GetNativeClipboardData(nsITransferable * aTransferable)
|
|||
#ifdef NS_DEBUG
|
||||
if ( errCode != NS_OK ) printf("nsClipboard:: Error setting data into transferable\n");
|
||||
#endif
|
||||
|
||||
nsCRT::free ( clipboardData );
|
||||
|
||||
// we found one, get out of this loop!
|
||||
delete [] flavorStr;
|
||||
break;
|
||||
} // if flavor found on clipboard
|
||||
delete [] flavorStr;
|
||||
}
|
||||
} // foreach flavor
|
||||
|
||||
|
@ -223,15 +221,12 @@ nsClipboard :: GetDataOffClipboard ( ResType inMacFlavor, char** outData, long*
|
|||
long offsetUnused = 0;
|
||||
OSErr clipResult = ::GetScrap(NULL, inMacFlavor, &offsetUnused);
|
||||
if ( clipResult > 0 ) {
|
||||
// we have it, get it off the clipboard. Put it into memory that we allocate
|
||||
// with new[] so that the tranferable can own it (and then later use delete[]
|
||||
// on it).
|
||||
Handle dataHand = ::NewHandle(0);
|
||||
if ( !dataHand )
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
long dataSize = ::GetScrap ( dataHand, inMacFlavor, &offsetUnused );
|
||||
if ( dataSize > 0 ) {
|
||||
char* dataBuff = new char[dataSize];
|
||||
char* dataBuff = NS_REINTERPRET_CAST(char*, nsAllocator::Alloc(dataSize));
|
||||
if ( !dataBuff )
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
::HLock(dataHand);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "nsVoidArray.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
|
||||
DragSendDataUPP nsDragService::sDragSendDataUPP = NewDragSendDataProc(DragSendDataProc);
|
||||
|
@ -209,11 +210,10 @@ nsDragService :: RegisterDragItemsAndFlavors ( nsISupportsArray * inArray )
|
|||
flavorList->GetElementAt ( flavorIndex, getter_AddRefs(genericWrapper) );
|
||||
nsCOMPtr<nsISupportsString> currentFlavor ( do_QueryInterface(genericWrapper) );
|
||||
if ( currentFlavor ) {
|
||||
char* flavorStr = nsnull;
|
||||
currentFlavor->ToString ( &flavorStr );
|
||||
nsXPIDLCString flavorStr;
|
||||
currentFlavor->ToString ( getter_Copies(flavorStr) );
|
||||
FlavorType macOSFlavor = theMapper.MapMimeTypeToMacOSType(flavorStr);
|
||||
::AddDragItemFlavor ( mDragRef, itemIndex, macOSFlavor, NULL, 0, flags );
|
||||
delete [] flavorStr;
|
||||
}
|
||||
|
||||
} // foreach flavor in item
|
||||
|
@ -223,11 +223,11 @@ nsDragService :: RegisterDragItemsAndFlavors ( nsISupportsArray * inArray )
|
|||
// put the mime mapping data for this item in a special flavor. Unlike the other data,
|
||||
// we have to put the data in now (rather than defer it) or the mappings will go out
|
||||
// of scope by the time they are asked for.
|
||||
const char* mapping = theMapper.ExportMapping(nsnull);
|
||||
char* mapping = theMapper.ExportMapping(nsnull);
|
||||
if ( strlen(mapping) )
|
||||
::AddDragItemFlavor ( mDragRef, itemIndex, nsMimeMapperMac::MappingFlavor(),
|
||||
mapping, strlen(mapping), flags );
|
||||
delete [] mapping;
|
||||
nsCRT::free ( mapping );
|
||||
|
||||
} // foreach drag item
|
||||
|
||||
|
@ -266,7 +266,7 @@ nsDragService :: GetData ( nsITransferable * aTransferable, PRUint32 aItemIndex
|
|||
// create a mime mapper to help us out based on data in a special flavor for this item
|
||||
char* mappings = LookupMimeMappingsForItem(mDragRef, itemRef);
|
||||
nsMimeMapperMac theMapper ( mappings );
|
||||
delete [] mappings;
|
||||
nsCRT::free ( mappings );
|
||||
|
||||
// Now walk down the list of flavors. When we find one that is actually present,
|
||||
// copy out the data into the transferable in that format. SetTransferData()
|
||||
|
@ -279,10 +279,10 @@ nsDragService :: GetData ( nsITransferable * aTransferable, PRUint32 aItemIndex
|
|||
nsCOMPtr<nsISupportsString> currentFlavor ( do_QueryInterface(genericWrapper) );
|
||||
if ( currentFlavor ) {
|
||||
// find MacOS flavor
|
||||
char* flavorStr;
|
||||
currentFlavor->ToString ( &flavorStr );
|
||||
nsXPIDLCString flavorStr;
|
||||
currentFlavor->ToString ( getter_Copies(flavorStr) );
|
||||
FlavorType macOSFlavor = theMapper.MapMimeTypeToMacOSType(flavorStr);
|
||||
printf("looking for data in type %s, mac flavor %ld\n", flavorStr, macOSFlavor);
|
||||
printf("looking for data in type %s, mac flavor %ld\n", NS_STATIC_CAST(const char*,flavorStr), macOSFlavor);
|
||||
|
||||
// check if it is present in the current drag item.
|
||||
FlavorFlags unused;
|
||||
|
@ -296,7 +296,7 @@ printf("flavor found\n");
|
|||
OSErr err = ::GetFlavorDataSize ( mDragRef, itemRef, macOSFlavor, &dataSize );
|
||||
printf("flavor data size is %ld\n", dataSize);
|
||||
if ( !err && dataSize > 0 ) {
|
||||
char* dataBuff = new char[dataSize];
|
||||
char* dataBuff = NS_REINTERPRET_CAST(char*, nsAllocator::Alloc(dataSize));
|
||||
if ( !dataBuff )
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
|
@ -316,7 +316,7 @@ printf("flavor data size is %ld\n", dataSize);
|
|||
if ( errCode != NS_OK ) printf("nsDragService:: Error setting data into transferable\n");
|
||||
#endif
|
||||
|
||||
delete [] dataBuff;
|
||||
nsAllocator::Free ( dataBuff );
|
||||
}
|
||||
else {
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -330,7 +330,6 @@ printf("flavor data size is %ld\n", dataSize);
|
|||
|
||||
} // if a flavor found
|
||||
|
||||
delete [] flavorStr;
|
||||
}
|
||||
} // foreach flavor
|
||||
|
||||
|
@ -445,7 +444,7 @@ nsDragService :: DragSendDataProc ( FlavorType inFlavor, void* inRefCon, ItemRef
|
|||
retVal = ::SetDragItemFlavorData ( inDragRef, inItemRef, inFlavor, data, dataSize, 0 );
|
||||
NS_ASSERTION ( retVal == noErr, "SDIFD failed in DragSendDataProc" );
|
||||
}
|
||||
delete [] data;
|
||||
nsAllocator::Free ( data );
|
||||
} // if valid refcon
|
||||
|
||||
return retVal;
|
||||
|
@ -474,22 +473,20 @@ nsDragService :: GetDataForFlavor ( nsISupportsArray* inDragItems, DragReference
|
|||
inDragItems->GetElementAt ( inItemIndex, getter_AddRefs(genericItem) );
|
||||
nsCOMPtr<nsITransferable> item ( do_QueryInterface(genericItem) );
|
||||
if ( item ) {
|
||||
nsString mimeFlavor;
|
||||
nsCAutoString mimeFlavor;
|
||||
|
||||
// create a mime mapper to help us out based on data in a special flavor for this item.
|
||||
char* mappings = LookupMimeMappingsForItem(inDragRef, inItemIndex) ;
|
||||
nsMimeMapperMac theMapper ( mappings );
|
||||
theMapper.MapMacOSTypeToMimeType ( inFlavor, mimeFlavor );
|
||||
delete [] mappings;
|
||||
nsCRT::free ( mappings );
|
||||
|
||||
*outDataSize = 0;
|
||||
char* mimeStr = mimeFlavor.ToNewCString();
|
||||
nsCOMPtr<nsISupports> data;
|
||||
if ( NS_SUCCEEDED(item->GetTransferData(mimeStr, getter_AddRefs(data), outDataSize)) )
|
||||
CreateDataFromPrimitive ( mimeStr, data, outData, *outDataSize );
|
||||
if ( NS_SUCCEEDED(item->GetTransferData(mimeFlavor.GetBuffer(), getter_AddRefs(data), outDataSize)) )
|
||||
CreateDataFromPrimitive ( mimeFlavor.GetBuffer(), data, outData, *outDataSize );
|
||||
else
|
||||
retVal = cantGetFlavorErr;
|
||||
delete [] mimeStr;
|
||||
} // if valid item
|
||||
|
||||
return retVal;
|
||||
|
@ -513,7 +510,7 @@ nsDragService :: LookupMimeMappingsForItem ( DragReference inDragRef, ItemRefere
|
|||
Size mapperSize = 0;
|
||||
OSErr err = ::GetFlavorDataSize ( inDragRef, itemRef, nsMimeMapperMac::MappingFlavor(), &mapperSize );
|
||||
if ( !err && mapperSize > 0 ) {
|
||||
mapperData = new char[mapperSize + 1];
|
||||
mapperData = NS_REINTERPRET_CAST(char*, nsAllocator::Alloc(mapperSize + 1));
|
||||
if ( !mapperData )
|
||||
return nsnull;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ nsMimeMapperMac :: ~nsMimeMapperMac ( )
|
|||
// be exported along with the data.
|
||||
//
|
||||
ResType
|
||||
nsMimeMapperMac :: MapMimeTypeToMacOSType ( const nsString & aMimeStr )
|
||||
nsMimeMapperMac :: MapMimeTypeToMacOSType ( const char* aMimeStr )
|
||||
{
|
||||
ResType format = 0;
|
||||
|
||||
|
@ -77,7 +77,7 @@ nsMimeMapperMac :: MapMimeTypeToMacOSType ( const nsString & aMimeStr )
|
|||
// pick them up by special casing MapMacsOSTypeToMimeType(). This means that
|
||||
// the low two bytes of the generated flavor can be used as an index into the list.
|
||||
if ( !format ) {
|
||||
if (aMimeStr.Equals(kTextMime) )
|
||||
if ( PL_strcmp(aMimeStr, kTextMime) == 0 )
|
||||
format = 'TEXT';
|
||||
else {
|
||||
// create the flavor based on the unique id in the lower two bytes and 'MZ' in the
|
||||
|
@ -105,7 +105,7 @@ nsMimeMapperMac :: MapMimeTypeToMacOSType ( const nsString & aMimeStr )
|
|||
// we probably won't get a match in that case.
|
||||
//
|
||||
void
|
||||
nsMimeMapperMac :: MapMacOSTypeToMimeType ( ResType inMacType, nsString & outMimeStr )
|
||||
nsMimeMapperMac :: MapMacOSTypeToMimeType ( ResType inMacType, nsCAutoString & outMimeStr )
|
||||
{
|
||||
switch ( inMacType ) {
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@ public:
|
|||
~nsMimeMapperMac ( ) ;
|
||||
|
||||
// Converts from mime type (eg: text/plain) to MacOS type (eg: 'TEXT').
|
||||
ResType MapMimeTypeToMacOSType ( const nsString & aMimeStr ) ;
|
||||
void MapMacOSTypeToMimeType ( ResType inMacType, nsString & outMimeStr ) ;
|
||||
ResType MapMimeTypeToMacOSType ( const char* aMimeStr ) ;
|
||||
void MapMacOSTypeToMimeType ( ResType inMacType, nsCAutoString & outMimeStr ) ;
|
||||
|
||||
// Takes the internal mappings and converts them to a string for
|
||||
// placing on the clipboard or in a drag item. |outLength| includes
|
||||
|
@ -74,7 +74,7 @@ private:
|
|||
|
||||
void ParseMappings ( const char* inMappings ) ;
|
||||
|
||||
typedef pair<ResType, nsString> MimePair;
|
||||
typedef pair<ResType, nsCAutoString> MimePair;
|
||||
typedef std::vector<MimePair> MimeMap;
|
||||
typedef MimeMap::iterator MimeMapIterator;
|
||||
typedef MimeMap::const_iterator MimeMapConstIterator;
|
||||
|
|
|
@ -190,3 +190,10 @@ nsBaseClipboard :: CreateDataFromPrimitive ( const char* aFlavor, nsISupports* a
|
|||
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBaseClipboard :: HasDataMatchingFlavors ( nsISupportsArray* aFlavorList, PRBool * outResult )
|
||||
{
|
||||
*outResult = PR_TRUE; // say we always do.
|
||||
return NS_OK;
|
||||
}
|
|
@ -48,6 +48,7 @@ public:
|
|||
NS_IMETHOD EmptyClipboard();
|
||||
NS_IMETHOD ForceDataToClipboard();
|
||||
|
||||
NS_IMETHOD HasDataMatchingFlavors ( nsISupportsArray* aFlavorList, PRBool * outResult ) ;
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ struct DataStruct
|
|||
void GetData( nsISupports** outData, PRUint32 *outDataLen );
|
||||
nsIFileSpec * GetFileSpec(const char * aFileName);
|
||||
PRBool IsDataAvilable() { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
|
||||
nsString mFlavor;
|
||||
nsCAutoString mFlavor;
|
||||
|
||||
protected:
|
||||
nsresult WriteCache(nsISupports* aData, PRUint32 aDataLen );
|
||||
|
@ -283,11 +283,9 @@ nsTransferable :: GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList)
|
|||
rv = nsComponentManager::CreateInstance(NS_SUPPORTS_STRING_PROGID, nsnull,
|
||||
NS_GET_IID(nsISupportsString), getter_AddRefs(flavorWrapper));
|
||||
if ( flavorWrapper ) {
|
||||
char* tempBecauseNSStringIsLame = data->mFlavor.ToNewCString();
|
||||
flavorWrapper->SetData ( tempBecauseNSStringIsLame );
|
||||
flavorWrapper->SetData ( NS_CONST_CAST(char*, data->mFlavor.GetBuffer()) );
|
||||
nsCOMPtr<nsISupports> genericWrapper ( do_QueryInterface(flavorWrapper) );
|
||||
(*aDataFlavorList)->AppendElement( genericWrapper );
|
||||
delete [] tempBecauseNSStringIsLame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -328,17 +326,15 @@ nsTransferable :: GetTransferData(const char *aFlavor, nsISupports **aData, PRUi
|
|||
if ( !found && mFormatConv ) {
|
||||
for (i=0;i<mDataArray->Count();i++) {
|
||||
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
|
||||
char* tempBecauseNSStringIsLame = data->mFlavor.ToNewCString();
|
||||
PRBool canConvert = PR_FALSE;
|
||||
mFormatConv->CanConvert(tempBecauseNSStringIsLame, aFlavor, &canConvert);
|
||||
mFormatConv->CanConvert(data->mFlavor.GetBuffer(), aFlavor, &canConvert);
|
||||
if ( canConvert ) {
|
||||
nsCOMPtr<nsISupports> dataBytes;
|
||||
PRUint32 len;
|
||||
data->GetData(getter_AddRefs(dataBytes), &len);
|
||||
mFormatConv->Convert(tempBecauseNSStringIsLame, dataBytes, len, aFlavor, aData, aDataLen);
|
||||
mFormatConv->Convert(data->mFlavor.GetBuffer(), dataBytes, len, aFlavor, aData, aDataLen);
|
||||
found = PR_TRUE;
|
||||
}
|
||||
delete [] tempBecauseNSStringIsLame;
|
||||
}
|
||||
}
|
||||
return found ? NS_OK : NS_ERROR_FAILURE;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "nsRepository.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#include "nsITransferable.h" // for mime defs, this is BAD
|
||||
|
||||
|
@ -211,29 +212,29 @@ nsXIFFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromDat
|
|||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsAutoString fromFlavor ( aFromDataFlavor );
|
||||
nsCAutoString fromFlavor ( aFromDataFlavor );
|
||||
if ( fromFlavor.Equals(kXIFMime) ) {
|
||||
nsAutoString toFlavor ( aToDataFlavor );
|
||||
nsCAutoString toFlavor ( aToDataFlavor );
|
||||
|
||||
// XIF on clipboard is going to always be double byte so it will be in a primitive
|
||||
// class of nsISupportsWString. Also, since the data is in two byte chunks the
|
||||
// length represents the length in 1-byte chars, so we need to divide by two.
|
||||
nsCOMPtr<nsISupportsWString> dataWrapper ( do_QueryInterface(aFromData) );
|
||||
if ( dataWrapper ) {
|
||||
PRUnichar* data = nsnull;
|
||||
dataWrapper->ToString ( &data );
|
||||
nsXPIDLString data;
|
||||
dataWrapper->ToString ( getter_Copies(data) ); //¥¥¥ COPY #1
|
||||
if ( data ) {
|
||||
nsAutoString dataStr ( data );
|
||||
nsAutoString dataStr ( data ); //¥¥¥ COPY #2
|
||||
nsAutoString outStr;
|
||||
|
||||
if ( toFlavor.Equals(kTextMime) ) {
|
||||
if ( NS_SUCCEEDED(ConvertFromXIFToText(dataStr, outStr)) ) {
|
||||
if ( NS_SUCCEEDED(ConvertFromXIFToText(dataStr, outStr)) ) { //¥¥¥ COPY #3, then runs over the data to parse
|
||||
nsCOMPtr<nsISupportsString> dataWrapper;
|
||||
nsComponentManager::CreateInstance(NS_SUPPORTS_STRING_PROGID, nsnull,
|
||||
NS_GET_IID(nsISupportsString), getter_AddRefs(dataWrapper) );
|
||||
if ( dataWrapper ) {
|
||||
char* holderBecauseNSStringIsLame = outStr.ToNewCString();
|
||||
dataWrapper->SetData ( holderBecauseNSStringIsLame );
|
||||
char* holderBecauseNSStringIsLame = outStr.ToNewCString(); //¥¥¥ COPY #4
|
||||
dataWrapper->SetData ( holderBecauseNSStringIsLame ); //¥¥¥ COPY #5
|
||||
nsCOMPtr<nsISupports> genericDataWrapper ( do_QueryInterface(dataWrapper) );
|
||||
*aToData = genericDataWrapper;
|
||||
NS_ADDREF(*aToData);
|
||||
|
@ -248,13 +249,11 @@ nsXIFFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromDat
|
|||
nsComponentManager::CreateInstance(NS_SUPPORTS_WSTRING_PROGID, nsnull,
|
||||
NS_GET_IID(nsISupportsWString), getter_AddRefs(dataWrapper) );
|
||||
if ( dataWrapper ) {
|
||||
PRUnichar* holderBecauseNSStringIsLame = outStr.ToNewUnicode();
|
||||
dataWrapper->SetData ( holderBecauseNSStringIsLame );
|
||||
dataWrapper->SetData ( NS_CONST_CAST(PRUnichar*,outStr.GetUnicode()) );
|
||||
nsCOMPtr<nsISupports> genericDataWrapper ( do_QueryInterface(dataWrapper) );
|
||||
*aToData = genericDataWrapper;
|
||||
NS_ADDREF(*aToData);
|
||||
*aDataToLen = outStr.Length() * 2;
|
||||
delete [] holderBecauseNSStringIsLame;
|
||||
}
|
||||
}
|
||||
} // else if HTML
|
||||
|
@ -264,13 +263,11 @@ nsXIFFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromDat
|
|||
nsComponentManager::CreateInstance(NS_SUPPORTS_WSTRING_PROGID, nsnull,
|
||||
NS_GET_IID(nsISupportsWString), getter_AddRefs(dataWrapper) );
|
||||
if ( dataWrapper ) {
|
||||
PRUnichar* holderBecauseNSStringIsLame = outStr.ToNewUnicode();
|
||||
dataWrapper->SetData ( holderBecauseNSStringIsLame );
|
||||
dataWrapper->SetData ( NS_CONST_CAST(PRUnichar*,outStr.GetUnicode()) );
|
||||
nsCOMPtr<nsISupports> genericDataWrapper ( do_QueryInterface(dataWrapper) );
|
||||
*aToData = genericDataWrapper;
|
||||
NS_ADDREF(*aToData);
|
||||
*aDataToLen = outStr.Length() * 2;
|
||||
delete [] holderBecauseNSStringIsLame;
|
||||
}
|
||||
}
|
||||
} // else if AOL mail
|
||||
|
|
Загрузка…
Ссылка в новой задаче