зеркало из https://github.com/mozilla/pjs.git
refactoring some code, and preparing for image copying. r=saari, sr=sfraser
This commit is contained in:
Родитель
39e1729ff4
Коммит
a9fc4fc665
|
@ -43,11 +43,13 @@
|
||||||
#include "nsISupportsPrimitives.h"
|
#include "nsISupportsPrimitives.h"
|
||||||
#include "nsXPIDLString.h"
|
#include "nsXPIDLString.h"
|
||||||
#include "nsPrimitiveHelpers.h"
|
#include "nsPrimitiveHelpers.h"
|
||||||
|
#include "nsIImage.h"
|
||||||
#include "nsMemory.h"
|
#include "nsMemory.h"
|
||||||
|
|
||||||
#include <Scrap.h>
|
#include <Scrap.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// nsClipboard constructor
|
// nsClipboard constructor
|
||||||
//
|
//
|
||||||
|
@ -119,48 +121,63 @@ nsClipboard :: SetNativeClipboardData ( PRInt32 aWhichClipboard )
|
||||||
// find MacOS flavor
|
// find MacOS flavor
|
||||||
ResType macOSFlavor = theMapper.MapMimeTypeToMacOSType(flavorStr);
|
ResType macOSFlavor = theMapper.MapMimeTypeToMacOSType(flavorStr);
|
||||||
|
|
||||||
// get data. This takes converters into account.
|
// get data. This takes converters into account. Different things happen for
|
||||||
|
// different flavors, so do some special processing.
|
||||||
void* data = nsnull;
|
void* data = nsnull;
|
||||||
PRUint32 dataSize = 0;
|
PRUint32 dataSize = 0;
|
||||||
nsCOMPtr<nsISupports> genericDataWrapper;
|
|
||||||
errCode = mTransferable->GetTransferData ( flavorStr, getter_AddRefs(genericDataWrapper), &dataSize );
|
|
||||||
nsPrimitiveHelpers::CreateDataFromPrimitive ( flavorStr, genericDataWrapper, &data, dataSize );
|
|
||||||
#ifdef NS_DEBUG
|
|
||||||
if ( NS_FAILED(errCode) ) printf("nsClipboard:: Error getting data from transferable\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// stash on clipboard
|
|
||||||
#if TARGET_CARBON
|
|
||||||
ScrapRef scrap;
|
|
||||||
::GetCurrentScrap(&scrap);
|
|
||||||
::PutScrapFlavor(scrap, macOSFlavor, 0L/*???*/, dataSize, data);
|
|
||||||
#else
|
|
||||||
long numBytes = ::PutScrap ( dataSize, macOSFlavor, data );
|
|
||||||
if ( numBytes != noErr )
|
|
||||||
errCode = NS_ERROR_FAILURE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// if the flavor was unicode, then we also need to put it on as 'TEXT' after
|
|
||||||
// doing the conversion to the platform charset.
|
|
||||||
if ( strcmp(flavorStr,kUnicodeMime) == 0 ) {
|
if ( strcmp(flavorStr,kUnicodeMime) == 0 ) {
|
||||||
char* plainTextData = nsnull;
|
// we have unicode, put it on first as unicode
|
||||||
PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, data);
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
||||||
PRInt32 plainTextLen = 0;
|
errCode = mTransferable->GetTransferData ( flavorStr, getter_AddRefs(genericDataWrapper), &dataSize );
|
||||||
nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, dataSize / 2, &plainTextData, &plainTextLen );
|
nsPrimitiveHelpers::CreateDataFromPrimitive ( flavorStr, genericDataWrapper, &data, dataSize );
|
||||||
if ( plainTextData ) {
|
errCode = PutOnClipboard ( macOSFlavor, data, dataSize );
|
||||||
#if TARGET_CARBON
|
if ( NS_SUCCEEDED(errCode) ) {
|
||||||
ScrapRef scrap;
|
// we also need to put it on as 'TEXT' after doing the conversion to the platform charset.
|
||||||
::GetCurrentScrap(&scrap);
|
char* plainTextData = nsnull;
|
||||||
::PutScrapFlavor( scrap, 'TEXT', 0L/*???*/, plainTextLen, plainTextData );
|
PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, data);
|
||||||
#else
|
PRInt32 plainTextLen = 0;
|
||||||
long numTextBytes = ::PutScrap ( plainTextLen, 'TEXT', plainTextData );
|
nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, dataSize / 2, &plainTextData, &plainTextLen );
|
||||||
if ( numTextBytes != noErr )
|
if ( plainTextData ) {
|
||||||
errCode = NS_ERROR_FAILURE;
|
errCode = PutOnClipboard ( 'TEXT', plainTextData, plainTextLen );
|
||||||
#endif
|
nsMemory::Free ( plainTextData );
|
||||||
nsMemory::Free ( plainTextData );
|
}
|
||||||
}
|
}
|
||||||
} // if unicode
|
} // if unicode
|
||||||
|
else if ( strcmp(flavorStr, kPNGImageMime) == 0 || strcmp(flavorStr, kJPEGImageMime) == 0 ||
|
||||||
|
strcmp(flavorStr, kGIFImageMime) == 0 ) {
|
||||||
|
// we have an image, which is in the transferable as an nsIImage. Convert it
|
||||||
|
// to PICT and put those bits on the clipboard. Don't put the pointer itself on
|
||||||
|
// the clipboard.
|
||||||
|
#if NOT_YET_IMPLEMENTED
|
||||||
|
nsCOMPtr<nsISupports> imageSupports;
|
||||||
|
errCode = mTransferable->GetTransferData ( flavorStr, getter_AddRefs(imageSupports), &dataSize );
|
||||||
|
nsCOMPtr<nsIImage> image ( do_QueryInterface(imageSupports) );
|
||||||
|
if ( image ) {
|
||||||
|
PixMap* pm = NS_REINTERPRET_CAST(PixMap*, image->GetBitInfo());
|
||||||
|
if ( pm ) {
|
||||||
|
|
||||||
|
// create a GWorld, clear it out
|
||||||
|
|
||||||
|
// blit pixmap into GWorld, code from sfraser
|
||||||
|
|
||||||
|
errCode = PutOnClipboard ( 'PICT', data, dataSize );
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
NS_WARNING ( "Image isn't an nsIImage in transferable" );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// we don't know what we have. let's just assume it's unicode but doesn't need to be
|
||||||
|
// translated to TEXT.
|
||||||
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
||||||
|
errCode = mTransferable->GetTransferData ( flavorStr, getter_AddRefs(genericDataWrapper), &dataSize );
|
||||||
|
nsPrimitiveHelpers::CreateDataFromPrimitive ( flavorStr, genericDataWrapper, &data, dataSize );
|
||||||
|
errCode = PutOnClipboard ( macOSFlavor, data, dataSize );
|
||||||
|
}
|
||||||
|
|
||||||
nsMemory::Free ( data );
|
nsMemory::Free ( data );
|
||||||
}
|
}
|
||||||
} // foreach flavor in transferable
|
} // foreach flavor in transferable
|
||||||
|
@ -170,15 +187,7 @@ nsClipboard :: SetNativeClipboardData ( PRInt32 aWhichClipboard )
|
||||||
short mappingLen = 0;
|
short mappingLen = 0;
|
||||||
const char* mapping = theMapper.ExportMapping(&mappingLen);
|
const char* mapping = theMapper.ExportMapping(&mappingLen);
|
||||||
if ( mapping && mappingLen ) {
|
if ( mapping && mappingLen ) {
|
||||||
#if TARGET_CARBON
|
errCode = PutOnClipboard ( nsMimeMapperMac::MappingFlavor(), mapping, mappingLen );
|
||||||
ScrapRef scrap;
|
|
||||||
::GetCurrentScrap(&scrap);
|
|
||||||
::PutScrapFlavor(scrap, nsMimeMapperMac::MappingFlavor(), 0L/*???*/, mappingLen, mapping);
|
|
||||||
#else
|
|
||||||
long numBytes = ::PutScrap ( mappingLen, nsMimeMapperMac::MappingFlavor(), mapping );
|
|
||||||
if ( numBytes != noErr )
|
|
||||||
errCode = NS_ERROR_FAILURE;
|
|
||||||
#endif
|
|
||||||
nsCRT::free ( NS_CONST_CAST(char*, mapping) );
|
nsCRT::free ( NS_CONST_CAST(char*, mapping) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,6 +196,32 @@ nsClipboard :: SetNativeClipboardData ( PRInt32 aWhichClipboard )
|
||||||
} // SetNativeClipboardData
|
} // SetNativeClipboardData
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// PutOnClipboard
|
||||||
|
//
|
||||||
|
// Actually does the work of placing the data on the native clipboard
|
||||||
|
// in the given flavor
|
||||||
|
//
|
||||||
|
nsresult
|
||||||
|
nsClipboard :: PutOnClipboard ( ResType inFlavor, const void* inData, short inLen )
|
||||||
|
{
|
||||||
|
nsresult errCode = NS_OK;
|
||||||
|
|
||||||
|
#if TARGET_CARBON
|
||||||
|
ScrapRef scrap;
|
||||||
|
::GetCurrentScrap(&scrap);
|
||||||
|
::PutScrapFlavor( scrap, inFlavor, kScrapFlavorMaskNone, inLen, inData );
|
||||||
|
#else
|
||||||
|
long numBytes = ::PutScrap ( inLen, inFlavor, inData );
|
||||||
|
if ( numBytes != noErr )
|
||||||
|
errCode = NS_ERROR_FAILURE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return errCode;
|
||||||
|
|
||||||
|
} // PutOnClipboard
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// GetNativeClipboardData
|
// GetNativeClipboardData
|
||||||
//
|
//
|
||||||
|
@ -263,18 +298,28 @@ nsClipboard :: GetNativeClipboardData ( nsITransferable * aTransferable, PRInt32
|
||||||
} // if looking for text/unicode
|
} // if looking for text/unicode
|
||||||
} // else we try one last ditch effort to find our data
|
} // else we try one last ditch effort to find our data
|
||||||
|
|
||||||
if ( dataFound ) {
|
if ( dataFound ) {
|
||||||
// the DOM only wants LF, so convert from MacOS line endings to DOM line
|
if ( strcmp(flavorStr, kPNGImageMime) == 0 || strcmp(flavorStr, kJPEGImageMime) == 0 ||
|
||||||
// endings.
|
strcmp(flavorStr, kGIFImageMime) == 0 ) {
|
||||||
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks ( flavorStr, &clipboardData, &dataSize );
|
// someone asked for an image, so we have to convert from PICT to the desired
|
||||||
|
// image format
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf ( "----------- IMAGE REQUESTED ----------" );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // if image requested
|
||||||
|
else {
|
||||||
|
// Assume that we have some form of textual data. The DOM only wants LF, so convert
|
||||||
|
// from MacOS line endings to DOM line endings.
|
||||||
|
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks ( flavorStr, &clipboardData, &dataSize );
|
||||||
|
|
||||||
|
// put it into the transferable
|
||||||
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
||||||
|
nsPrimitiveHelpers::CreatePrimitiveForData ( flavorStr, clipboardData, dataSize, getter_AddRefs(genericDataWrapper) );
|
||||||
|
errCode = aTransferable->SetTransferData ( flavorStr, genericDataWrapper, dataSize );
|
||||||
|
}
|
||||||
|
|
||||||
// put it into the transferable
|
|
||||||
nsCOMPtr<nsISupports> genericDataWrapper;
|
|
||||||
nsPrimitiveHelpers::CreatePrimitiveForData ( flavorStr, clipboardData, dataSize, getter_AddRefs(genericDataWrapper) );
|
|
||||||
errCode = aTransferable->SetTransferData ( flavorStr, genericDataWrapper, dataSize );
|
|
||||||
#ifdef NS_DEBUG
|
|
||||||
if ( errCode != NS_OK ) printf("nsClipboard:: Error setting data into transferable\n");
|
|
||||||
#endif
|
|
||||||
nsMemory::Free ( clipboardData );
|
nsMemory::Free ( clipboardData );
|
||||||
|
|
||||||
// we found one, get out of this loop!
|
// we found one, get out of this loop!
|
||||||
|
@ -290,7 +335,9 @@ nsClipboard :: GetNativeClipboardData ( nsITransferable * aTransferable, PRInt32
|
||||||
//
|
//
|
||||||
// GetDataOffClipboard
|
// GetDataOffClipboard
|
||||||
//
|
//
|
||||||
//
|
// Actually does the work of retrieving the data from the native clipboard
|
||||||
|
// with the given MacOS flavor
|
||||||
|
//
|
||||||
nsresult
|
nsresult
|
||||||
nsClipboard :: GetDataOffClipboard ( ResType inMacFlavor, void** outData, PRInt32* outDataSize )
|
nsClipboard :: GetDataOffClipboard ( ResType inMacFlavor, void** outData, PRInt32* outDataSize )
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,6 +62,9 @@ protected:
|
||||||
// helper to check if the data is really there
|
// helper to check if the data is really there
|
||||||
PRBool CheckIfFlavorPresent ( ResType inMacFlavor ) ;
|
PRBool CheckIfFlavorPresent ( ResType inMacFlavor ) ;
|
||||||
|
|
||||||
|
// actually places data on the clipboard
|
||||||
|
nsresult PutOnClipboard ( ResType inFlavor, const void* inData, short inLen ) ;
|
||||||
|
|
||||||
}; // nsClipboard
|
}; // nsClipboard
|
||||||
|
|
||||||
#endif // nsClipboard_h__
|
#endif // nsClipboard_h__
|
||||||
|
|
Загрузка…
Ссылка в новой задаче