Commit 3f40cb78 authored by Tatiana Meshkova's avatar Tatiana Meshkova

Added basic implementation for clipboard... need to figure out how to make...

Added basic implementation for clipboard... need to figure out how to make SyncMessage send without window
parent cecac694
......@@ -12,13 +12,21 @@
#include "imgIContainer.h"
#include "gfxImageSurface.h"
#include "nsWidgetsCID.h"
#include "nsServiceManagerUtils.h"
using namespace mozilla;
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
static const char* sClipboardTextFlavors[] = { kUnicodeMime };
NS_IMPL_ISUPPORTS1(nsEmbedClipboard, nsIClipboard)
nsEmbedClipboard::nsEmbedClipboard() : nsIClipboard()
{
if (!mService) {
mService = do_GetService("@mozilla.org/embedlite-app-service;1");
}
}
nsEmbedClipboard::~nsEmbedClipboard()
......@@ -28,38 +36,94 @@ nsEmbedClipboard::~nsEmbedClipboard()
NS_IMETHODIMP
nsEmbedClipboard::SetData(nsITransferable* aTransferable, nsIClipboardOwner* anOwner, int32_t aWhichClipboard)
{
printf("nsEmbedClipboard::SetData NONIMPL\n");
if (aWhichClipboard != kGlobalClipboard)
return NS_ERROR_NOT_IMPLEMENTED;
nsCOMPtr<nsISupports> tmp;
uint32_t len;
nsresult rv = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp),
&len);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp);
// No support for non-text data
NS_ENSURE_TRUE(supportsString, NS_ERROR_NOT_IMPLEMENTED);
nsAutoString buffer;
supportsString->GetData(buffer);
bool isPrivateData = false;
aTransferable->GetIsPrivateData(&isPrivateData);
printf("nsEmbedClipboard::SetData: priv:%i, which:%i, buff:%s\n", isPrivateData, aWhichClipboard, NS_ConvertUTF16toUTF8(buffer).get());
// ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData, aWhichClipboard);
return NS_OK;
}
NS_IMETHODIMP
nsEmbedClipboard::GetData(nsITransferable* aTransferable, int32_t aWhichClipboard)
{
printf("nsEmbedClipboard::GetData NONIMPL\n");
if (aWhichClipboard != kGlobalClipboard)
return NS_ERROR_NOT_IMPLEMENTED;
nsAutoString buffer;
printf("nsEmbedClipboard::GetData: clipID:%i, buff:%s - heh we did not make request\n", aWhichClipboard, NS_ConvertUTF16toUTF8(buffer).get());
// ContentChild::GetSingleton()->SendGetClipboardText(aWhichClipboard, &buffer);
nsresult rv;
nsCOMPtr<nsISupportsString> dataWrapper =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = dataWrapper->SetData(buffer);
NS_ENSURE_SUCCESS(rv, rv);
// If our data flavor has already been added, this will fail. But we don't care
aTransferable->AddDataFlavor(kUnicodeMime);
nsCOMPtr<nsISupports> nsisupportsDataWrapper =
do_QueryInterface(dataWrapper);
rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
buffer.Length() * sizeof(PRUnichar));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP
nsEmbedClipboard::EmptyClipboard(int32_t aWhichClipboard)
nsEmbedClipboard::HasDataMatchingFlavors(const char* *aFlavorList, uint32_t aLength, int32_t aWhichClipboard, bool* aHasText)
{
printf("nsEmbedClipboard::EmptyClipboard NONIMPL\n");
NS_ENSURE_ARG_POINTER(aHasText);
*aHasText = false;
if (aWhichClipboard != kGlobalClipboard)
return NS_ERROR_NOT_IMPLEMENTED;
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
clipboard->HasDataMatchingFlavors(sClipboardTextFlavors, 1,
nsIClipboard::kGlobalClipboard, aHasText);
return NS_OK;
}
NS_IMETHODIMP
nsEmbedClipboard::HasDataMatchingFlavors(const char* *aFlavorList, uint32_t aLength, int32_t aWhichClipboard, bool* _retval)
nsEmbedClipboard::EmptyClipboard(int32_t aWhichClipboard)
{
NS_ENSURE_ARG_POINTER(_retval);
printf("nsEmbedClipboard::HasDataMatchingFlavors NONIMPL\n");
*_retval = false;
if (aWhichClipboard != kGlobalClipboard)
return NS_ERROR_NOT_IMPLEMENTED;
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
clipboard->EmptyClipboard(nsIClipboard::kGlobalClipboard);
return NS_OK;
}
NS_IMETHODIMP
nsEmbedClipboard::SupportsSelectionClipboard(bool* _retval)
{
printf("nsEmbedClipboard::SupportsSelectionClipboard NONIMPL\n");
*_retval = false;
return NS_OK;
}
......@@ -6,9 +6,11 @@
#define nsEmbedClipboard_h__
#include "nsIClipboard.h"
#include "nsITransferable.h"
#include "nsIClipboardOwner.h"
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "nsIEmbedAppService.h"
/* Native Qt Clipboard wrapper */
class nsEmbedClipboard : public nsIClipboard
......@@ -22,6 +24,9 @@ public:
// nsIClipboard
NS_DECL_NSICLIPBOARD
private:
nsCOMPtr<nsIEmbedAppService> mService;
};
#define NS_EMBED_CLIPBOARD_SERVICE_CID \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment