1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsBaseClipboard.h"
8 #include "nsIClipboardOwner.h"
11 #include "nsISupportsPrimitives.h"
13 nsBaseClipboard::nsBaseClipboard()
14 : mEmptyingForSetData(false), mIgnoreEmptyNotification(false) {}
16 nsBaseClipboard::~nsBaseClipboard() {
17 EmptyClipboard(kSelectionClipboard
);
18 EmptyClipboard(kGlobalClipboard
);
19 EmptyClipboard(kFindClipboard
);
22 NS_IMPL_ISUPPORTS(nsBaseClipboard
, nsIClipboard
)
25 * Sets the transferable object
28 NS_IMETHODIMP
nsBaseClipboard::SetData(nsITransferable
* aTransferable
,
29 nsIClipboardOwner
* anOwner
,
30 int32_t aWhichClipboard
) {
31 NS_ASSERTION(aTransferable
, "clipboard given a null transferable");
33 if (aTransferable
== mTransferable
&& anOwner
== mClipboardOwner
)
35 bool selectClipPresent
;
36 SupportsSelectionClipboard(&selectClipPresent
);
38 SupportsFindClipboard(&findClipPresent
);
39 if (!selectClipPresent
&& !findClipPresent
&&
40 aWhichClipboard
!= kGlobalClipboard
)
41 return NS_ERROR_FAILURE
;
43 mEmptyingForSetData
= true;
44 EmptyClipboard(aWhichClipboard
);
45 mEmptyingForSetData
= false;
47 mClipboardOwner
= anOwner
;
48 mTransferable
= aTransferable
;
50 nsresult rv
= NS_ERROR_FAILURE
;
52 rv
= SetNativeClipboardData(aWhichClipboard
);
59 * Gets the transferable object
62 NS_IMETHODIMP
nsBaseClipboard::GetData(nsITransferable
* aTransferable
,
63 int32_t aWhichClipboard
) {
64 NS_ASSERTION(aTransferable
, "clipboard given a null transferable");
66 bool selectClipPresent
;
67 SupportsSelectionClipboard(&selectClipPresent
);
69 SupportsFindClipboard(&findClipPresent
);
70 if (!selectClipPresent
&& !findClipPresent
&&
71 aWhichClipboard
!= kGlobalClipboard
)
72 return NS_ERROR_FAILURE
;
75 return GetNativeClipboardData(aTransferable
, aWhichClipboard
);
77 return NS_ERROR_FAILURE
;
80 NS_IMETHODIMP
nsBaseClipboard::EmptyClipboard(int32_t aWhichClipboard
) {
81 bool selectClipPresent
;
82 SupportsSelectionClipboard(&selectClipPresent
);
84 SupportsFindClipboard(&findClipPresent
);
85 if (!selectClipPresent
&& !findClipPresent
&&
86 aWhichClipboard
!= kGlobalClipboard
)
87 return NS_ERROR_FAILURE
;
89 if (mIgnoreEmptyNotification
) return NS_OK
;
91 if (mClipboardOwner
) {
92 mClipboardOwner
->LosingOwnership(mTransferable
);
93 mClipboardOwner
= nullptr;
96 mTransferable
= nullptr;
101 nsBaseClipboard::HasDataMatchingFlavors(const char** aFlavorList
,
103 int32_t aWhichClipboard
,
105 *outResult
= true; // say we always do.
110 nsBaseClipboard::SupportsSelectionClipboard(bool* _retval
) {
111 *_retval
= false; // we don't support the selection clipboard by default.
116 nsBaseClipboard::SupportsFindClipboard(bool* _retval
) {
117 *_retval
= false; // we don't support the find clipboard by default.