Bumping manifests a=b2g-bump
[gecko.git] / widget / nsBaseClipboard.cpp
blobfd22dab658982ef6eeb61546aa21350ae25cd752
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"
9 #include "nsCOMPtr.h"
10 #include "nsXPCOM.h"
11 #include "nsISupportsPrimitives.h"
13 nsBaseClipboard::nsBaseClipboard()
15 mClipboardOwner = nullptr;
16 mTransferable = nullptr;
17 mIgnoreEmptyNotification = false;
18 mEmptyingForSetData = false;
21 nsBaseClipboard::~nsBaseClipboard()
23 EmptyClipboard(kSelectionClipboard);
24 EmptyClipboard(kGlobalClipboard);
25 EmptyClipboard(kFindClipboard);
28 NS_IMPL_ISUPPORTS(nsBaseClipboard, nsIClipboard)
30 /**
31 * Sets the transferable object
34 NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable * aTransferable, nsIClipboardOwner * anOwner,
35 int32_t aWhichClipboard)
37 NS_ASSERTION ( aTransferable, "clipboard given a null transferable" );
39 if (aTransferable == mTransferable && anOwner == mClipboardOwner)
40 return NS_OK;
41 bool selectClipPresent;
42 SupportsSelectionClipboard(&selectClipPresent);
43 bool findClipPresent;
44 SupportsFindClipboard(&findClipPresent);
45 if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
46 return NS_ERROR_FAILURE;
48 mEmptyingForSetData = true;
49 EmptyClipboard(aWhichClipboard);
50 mEmptyingForSetData = false;
52 mClipboardOwner = anOwner;
53 if ( anOwner )
54 NS_ADDREF(mClipboardOwner);
56 mTransferable = aTransferable;
58 nsresult rv = NS_ERROR_FAILURE;
60 if ( mTransferable ) {
61 NS_ADDREF(mTransferable);
62 rv = SetNativeClipboardData(aWhichClipboard);
65 return rv;
68 /**
69 * Gets the transferable object
72 NS_IMETHODIMP nsBaseClipboard::GetData(nsITransferable * aTransferable, int32_t aWhichClipboard)
74 NS_ASSERTION ( aTransferable, "clipboard given a null transferable" );
76 bool selectClipPresent;
77 SupportsSelectionClipboard(&selectClipPresent);
78 bool findClipPresent;
79 SupportsFindClipboard(&findClipPresent);
80 if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
81 return NS_ERROR_FAILURE;
83 if ( aTransferable )
84 return GetNativeClipboardData(aTransferable, aWhichClipboard);
86 return NS_ERROR_FAILURE;
89 NS_IMETHODIMP nsBaseClipboard::EmptyClipboard(int32_t aWhichClipboard)
91 bool selectClipPresent;
92 SupportsSelectionClipboard(&selectClipPresent);
93 bool findClipPresent;
94 SupportsFindClipboard(&findClipPresent);
95 if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
96 return NS_ERROR_FAILURE;
98 if (mIgnoreEmptyNotification)
99 return NS_OK;
101 if ( mClipboardOwner ) {
102 mClipboardOwner->LosingOwnership(mTransferable);
103 NS_RELEASE(mClipboardOwner);
106 NS_IF_RELEASE(mTransferable);
108 return NS_OK;
111 NS_IMETHODIMP
112 nsBaseClipboard::HasDataMatchingFlavors(const char** aFlavorList,
113 uint32_t aLength,
114 int32_t aWhichClipboard,
115 bool* outResult)
117 *outResult = true; // say we always do.
118 return NS_OK;
121 NS_IMETHODIMP
122 nsBaseClipboard::SupportsSelectionClipboard(bool* _retval)
124 *_retval = false; // we don't support the selection clipboard by default.
125 return NS_OK;
128 NS_IMETHODIMP
129 nsBaseClipboard::SupportsFindClipboard(bool* _retval)
131 *_retval = false; // we don't support the find clipboard by default.
132 return NS_OK;