Bug 499803 - "Implement simple clipboard on Windows CE" [r=vladimir]

This commit is contained in:
Justin Dolske 2009-07-03 16:11:05 -07:00
Родитель 928b7c1dbc
Коммит 368112aee5
4 изменённых файлов: 199 добавлений и 13 удалений

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

@ -87,8 +87,10 @@ install::
endif
ifneq (,$(filter windows mac cocoa gtk2, $(MOZ_WIDGET_TOOLKIT)))
ifneq ($(OS_ARCH),WINCE)
DEFINES += -DCONTEXT_COPY_IMAGE_CONTENTS=1
endif
endif
ifneq (,$(BUILD_OFFICIAL)$(MOZILLA_OFFICIAL))
DEFINES += -DOFFICIAL_BUILD=1

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

@ -65,9 +65,9 @@
#include "nsClipboard.h"
#include "nsBidiKeyboard.h"
#include "nsDragService.h"
#include "nsHTMLFormatConverter.h"
#include "nsTransferable.h"
#endif
#include "nsTransferable.h"
#include "nsHTMLFormatConverter.h"
#ifdef NS_PRINTING
#include "nsDeviceContextSpecWin.h"
@ -86,9 +86,9 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
#ifndef WINCE
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
#ifndef WINCE
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
#endif
@ -151,6 +151,14 @@ static const nsModuleComponentInfo components[] =
NS_SOUND_CID,
"@mozilla.org/sound;1",
nsSoundConstructor },
{ "Transferable",
NS_TRANSFERABLE_CID,
"@mozilla.org/widget/transferable;1",
nsTransferableConstructor },
{ "HTML Format Converter",
NS_HTMLFORMATCONVERTER_CID,
"@mozilla.org/widget/htmlformatconverter;1",
nsHTMLFormatConverterConstructor },
#ifndef WINCE
{ "Drag Service",
@ -161,14 +169,6 @@ static const nsModuleComponentInfo components[] =
NS_BIDIKEYBOARD_CID,
"@mozilla.org/widget/bidikeyboard;1",
nsBidiKeyboardConstructor },
{ "Transferable",
NS_TRANSFERABLE_CID,
"@mozilla.org/widget/transferable;1",
nsTransferableConstructor },
{ "HTML Format Converter",
NS_HTMLFORMATCONVERTER_CID,
"@mozilla.org/widget/htmlformatconverter;1",
nsHTMLFormatConverterConstructor },
#endif
#ifdef NS_PRINTING

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

@ -38,6 +38,11 @@
#include "nsClipboardCE.h"
#include "nsISupportsPrimitives.h"
#include "nsXPIDLString.h"
#include "nsCRT.h"
#include "nsComponentManagerUtils.h"
#include <winuserm.h>
nsClipboard::nsClipboard()
@ -48,15 +53,189 @@ nsClipboard::~nsClipboard()
{
}
UINT nsClipboard::GetFormat(const char* aMimeStr)
{
UINT format;
if (strcmp(aMimeStr, kTextMime) == 0)
format = CF_TEXT;
else if (strcmp(aMimeStr, kUnicodeMime) == 0)
format = CF_UNICODETEXT;
else if (strcmp(aMimeStr, kJPEGImageMime) == 0 ||
strcmp(aMimeStr, kPNGImageMime) == 0)
format = CF_DIB;
else if (strcmp(aMimeStr, kFileMime) == 0 ||
strcmp(aMimeStr, kFilePromiseMime) == 0)
format = CF_HDROP; // XXX CF_HDROP not listed as supported but it compiles!
else
format = ::RegisterClipboardFormat(NS_ConvertASCIItoUTF16(aMimeStr).get());
// CE doesn't support CF_HTML (kNativeHTMLMime)
return format;
}
NS_IMETHODIMP
nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard)
{
return NS_ERROR_FAILURE;
if (aWhichClipboard != kGlobalClipboard || !mTransferable)
return NS_ERROR_INVALID_ARG;
if (!::OpenClipboard(NULL))
return NS_ERROR_FAILURE;
if (!::EmptyClipboard())
return NS_ERROR_FAILURE;
nsCOMPtr<nsISupportsArray> flavorList;
mTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
PRUint32 count, i;
flavorList->Count(&count);
nsresult rv = NS_OK;
for (i = 0; i < count; i++) {
nsCOMPtr<nsISupports> listItem;
flavorList->GetElementAt(i, getter_AddRefs(listItem));
nsCOMPtr<nsISupportsCString> flavor(do_QueryInterface(listItem));
if (!flavor)
continue;
nsXPIDLCString flavorStr;
flavor->ToString(getter_Copies(flavorStr));
UINT format = GetFormat(flavorStr);
PRUint32 len;
nsCOMPtr<nsISupports> wrapper;
mTransferable->GetTransferData(flavorStr, getter_AddRefs(wrapper), &len);
if (!wrapper)
continue;
char *memory = nsnull;
nsCOMPtr<nsISupportsString> textItem(do_QueryInterface(wrapper));
nsCOMPtr<nsISupportsPRBool> boolItem(do_QueryInterface(wrapper));
if (format == CF_TEXT || format == CF_DIB || format == CF_HDROP) {
NS_WARNING("Setting this clipboard format not implemented");
continue;
} else if (textItem) {
// format == CF_UNICODETEXT, or is otherwise unicode data.
nsAutoString text;
textItem->GetData(text);
PRInt32 len = text.Length() * 2;
memory = reinterpret_cast<char*>(::LocalAlloc(LMEM_FIXED, len + 2));
if (!memory) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
memcpy(memory, nsPromiseFlatString(text).get(), len);
memory[len] = '\0';
memory[len+1] = '\0';
} else if (boolItem) {
// Private browsing sets a boolean type.
PRBool value;
boolItem->GetData(&value);
memory = reinterpret_cast<char*>(::LocalAlloc(LMEM_FIXED, 1));
if (!memory) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
*memory = value ? 1 : 0;
} else {
NS_WARNING("Can't set unknown transferrable primitive");
continue;
}
if (!::SetClipboardData(format, memory)) {
NS_WARNING("::SetClipboardData failed");
if (memory)
::LocalFree(memory);
}
}
::CloseClipboard();
return rv;
}
NS_IMETHODIMP
nsClipboard::GetNativeClipboardData(nsITransferable *aTransferable,
PRInt32 aWhichClipboard)
{
return NS_ERROR_FAILURE;
if (aWhichClipboard != kGlobalClipboard || !aTransferable)
return NS_ERROR_INVALID_ARG;
if (!::OpenClipboard(NULL))
return NS_ERROR_FAILURE;
nsCOMPtr<nsISupportsArray> flavorList;
mTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
PRUint32 count, i;
flavorList->Count(&count);
nsresult rv = NS_OK;
for (i = 0; i < count; i++) {
nsCOMPtr<nsISupports> listItem;
flavorList->GetElementAt(i, getter_AddRefs(listItem));
nsCOMPtr<nsISupportsCString> flavor(do_QueryInterface(listItem));
if (!flavor)
continue;
nsXPIDLCString flavorStr;
flavor->ToString(getter_Copies(flavorStr));
UINT format = GetFormat(flavorStr);
void *data;
data = ::GetClipboardData(format);
if (!data)
continue;
if (format == CF_UNICODETEXT) {
PRUnichar *dataStr = reinterpret_cast<PRUnichar*>(data);
nsString *stringCopy = new nsString(dataStr);
nsCOMPtr<nsISupportsString> primitive =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
if (!primitive) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
primitive->SetData(*stringCopy);
aTransferable->SetTransferData(flavorStr, primitive,
stringCopy->Length() * sizeof(PRUnichar));
} else {
NS_WARNING("Getting this clipboard format not implemented");
continue;
}
}
::CloseClipboard();
return rv;
}
NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(const char** aFlavorList,
PRUint32 aLength,
PRInt32 aWhichClipboard,
PRBool *_retval)
{
*_retval = PR_FALSE;
if (aWhichClipboard != kGlobalClipboard || !aFlavorList)
return NS_OK;
for (PRUint32 i = 0;i < aLength; ++i) {
UINT format = GetFormat(aFlavorList[i]);
if (::IsClipboardFormatAvailable(format)) {
*_retval = PR_TRUE;
break;
}
}
return NS_OK;
}

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

@ -53,10 +53,15 @@ class nsClipboard :
public:
nsClipboard();
virtual ~nsClipboard();
NS_IMETHOD HasDataMatchingFlavors(const char** aFlavorList, PRUint32 aLength,
PRInt32 aWhichClipboard, PRBool *_retval);
protected:
NS_IMETHOD SetNativeClipboardData (PRInt32 aWhichClipboard);
NS_IMETHOD GetNativeClipboardData (nsITransferable * aTransferable, PRInt32 aWhichClipboard);
private:
static UINT GetFormat(const char* aMimeStr);
};
#endif