Source code

Revision control

Other Tools

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/. */
5
6
#include "nsBaseClipboard.h"
7
8
#include "nsIClipboardOwner.h"
9
#include "nsCOMPtr.h"
10
#include "nsXPCOM.h"
11
#include "nsISupportsPrimitives.h"
12
13
nsBaseClipboard::nsBaseClipboard()
14
: mEmptyingForSetData(false), mIgnoreEmptyNotification(false) {}
15
16
nsBaseClipboard::~nsBaseClipboard() {
17
EmptyClipboard(kSelectionClipboard);
18
EmptyClipboard(kGlobalClipboard);
19
EmptyClipboard(kFindClipboard);
20
}
21
22
NS_IMPL_ISUPPORTS(nsBaseClipboard, nsIClipboard)
23
24
/**
25
* Sets the transferable object
26
*
27
*/
28
NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable* aTransferable,
29
nsIClipboardOwner* anOwner,
30
int32_t aWhichClipboard) {
31
NS_ASSERTION(aTransferable, "clipboard given a null transferable");
32
33
if (aTransferable == mTransferable && anOwner == mClipboardOwner)
34
return NS_OK;
35
bool selectClipPresent;
36
SupportsSelectionClipboard(&selectClipPresent);
37
bool findClipPresent;
38
SupportsFindClipboard(&findClipPresent);
39
if (!selectClipPresent && !findClipPresent &&
40
aWhichClipboard != kGlobalClipboard)
41
return NS_ERROR_FAILURE;
42
43
mEmptyingForSetData = true;
44
EmptyClipboard(aWhichClipboard);
45
mEmptyingForSetData = false;
46
47
mClipboardOwner = anOwner;
48
mTransferable = aTransferable;
49
50
nsresult rv = NS_ERROR_FAILURE;
51
if (mTransferable) {
52
rv = SetNativeClipboardData(aWhichClipboard);
53
}
54
55
return rv;
56
}
57
58
/**
59
* Gets the transferable object
60
*
61
*/
62
NS_IMETHODIMP nsBaseClipboard::GetData(nsITransferable* aTransferable,
63
int32_t aWhichClipboard) {
64
NS_ASSERTION(aTransferable, "clipboard given a null transferable");
65
66
bool selectClipPresent;
67
SupportsSelectionClipboard(&selectClipPresent);
68
bool findClipPresent;
69
SupportsFindClipboard(&findClipPresent);
70
if (!selectClipPresent && !findClipPresent &&
71
aWhichClipboard != kGlobalClipboard)
72
return NS_ERROR_FAILURE;
73
74
if (aTransferable)
75
return GetNativeClipboardData(aTransferable, aWhichClipboard);
76
77
return NS_ERROR_FAILURE;
78
}
79
80
NS_IMETHODIMP nsBaseClipboard::EmptyClipboard(int32_t aWhichClipboard) {
81
bool selectClipPresent;
82
SupportsSelectionClipboard(&selectClipPresent);
83
bool findClipPresent;
84
SupportsFindClipboard(&findClipPresent);
85
if (!selectClipPresent && !findClipPresent &&
86
aWhichClipboard != kGlobalClipboard)
87
return NS_ERROR_FAILURE;
88
89
if (mIgnoreEmptyNotification) return NS_OK;
90
91
if (mClipboardOwner) {
92
mClipboardOwner->LosingOwnership(mTransferable);
93
mClipboardOwner = nullptr;
94
}
95
96
mTransferable = nullptr;
97
return NS_OK;
98
}
99
100
NS_IMETHODIMP
101
nsBaseClipboard::HasDataMatchingFlavors(const nsTArray<nsCString>& aFlavorList,
102
int32_t aWhichClipboard,
103
bool* outResult) {
104
*outResult = true; // say we always do.
105
return NS_OK;
106
}
107
108
NS_IMETHODIMP
109
nsBaseClipboard::SupportsSelectionClipboard(bool* _retval) {
110
*_retval = false; // we don't support the selection clipboard by default.
111
return NS_OK;
112
}
113
114
NS_IMETHODIMP
115
nsBaseClipboard::SupportsFindClipboard(bool* _retval) {
116
*_retval = false; // we don't support the find clipboard by default.
117
return NS_OK;
118
}