2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsBaseClipboard.h"
|
|
|
|
|
|
|
|
#include "nsIClipboardOwner.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsXPCOM.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
|
|
|
|
nsBaseClipboard::nsBaseClipboard()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mClipboardOwner = nullptr;
|
|
|
|
mTransferable = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIgnoreEmptyNotification = false;
|
2013-07-09 11:39:46 -07:00
|
|
|
mEmptyingForSetData = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBaseClipboard::~nsBaseClipboard()
|
|
|
|
{
|
|
|
|
EmptyClipboard(kSelectionClipboard);
|
|
|
|
EmptyClipboard(kGlobalClipboard);
|
2014-02-28 07:07:30 -08:00
|
|
|
EmptyClipboard(kFindClipboard);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsBaseClipboard, nsIClipboard)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the transferable object
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable * aTransferable, nsIClipboardOwner * anOwner,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aWhichClipboard)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION ( aTransferable, "clipboard given a null transferable" );
|
|
|
|
|
|
|
|
if (aTransferable == mTransferable && anOwner == mClipboardOwner)
|
|
|
|
return NS_OK;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool selectClipPresent;
|
2007-03-22 10:30:00 -07:00
|
|
|
SupportsSelectionClipboard(&selectClipPresent);
|
2014-02-28 07:07:30 -08:00
|
|
|
bool findClipPresent;
|
|
|
|
SupportsFindClipboard(&findClipPresent);
|
|
|
|
if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2013-07-09 11:39:46 -07:00
|
|
|
mEmptyingForSetData = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
EmptyClipboard(aWhichClipboard);
|
2013-07-09 11:39:46 -07:00
|
|
|
mEmptyingForSetData = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mClipboardOwner = anOwner;
|
|
|
|
if ( anOwner )
|
|
|
|
NS_ADDREF(mClipboardOwner);
|
|
|
|
|
|
|
|
mTransferable = aTransferable;
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if ( mTransferable ) {
|
|
|
|
NS_ADDREF(mTransferable);
|
|
|
|
rv = SetNativeClipboardData(aWhichClipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the transferable object
|
|
|
|
*
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsBaseClipboard::GetData(nsITransferable * aTransferable, int32_t aWhichClipboard)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION ( aTransferable, "clipboard given a null transferable" );
|
2014-02-28 07:07:30 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool selectClipPresent;
|
2007-03-22 10:30:00 -07:00
|
|
|
SupportsSelectionClipboard(&selectClipPresent);
|
2014-02-28 07:07:30 -08:00
|
|
|
bool findClipPresent;
|
|
|
|
SupportsFindClipboard(&findClipPresent);
|
|
|
|
if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if ( aTransferable )
|
|
|
|
return GetNativeClipboardData(aTransferable, aWhichClipboard);
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsBaseClipboard::EmptyClipboard(int32_t aWhichClipboard)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool selectClipPresent;
|
2007-03-22 10:30:00 -07:00
|
|
|
SupportsSelectionClipboard(&selectClipPresent);
|
2014-02-28 07:07:30 -08:00
|
|
|
bool findClipPresent;
|
|
|
|
SupportsFindClipboard(&findClipPresent);
|
|
|
|
if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mIgnoreEmptyNotification)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if ( mClipboardOwner ) {
|
|
|
|
mClipboardOwner->LosingOwnership(mTransferable);
|
|
|
|
NS_RELEASE(mClipboardOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mTransferable);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-11-20 11:06:30 -08:00
|
|
|
nsBaseClipboard::HasDataMatchingFlavors(const char** aFlavorList,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aWhichClipboard,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* outResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*outResult = true; // say we always do.
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsBaseClipboard::SupportsSelectionClipboard(bool* _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false; // we don't support the selection clipboard by default.
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-02-28 07:07:30 -08:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseClipboard::SupportsFindClipboard(bool* _retval)
|
|
|
|
{
|
|
|
|
*_retval = false; // we don't support the find clipboard by default.
|
|
|
|
return NS_OK;
|
|
|
|
}
|