Bug 1708422: part 18) Factor `mozInlineSpellChecker::SpellCheckerSlice::IsInNoCheckRa...
[gecko.git] / widget / nsBaseClipboard.cpp
blob91da56d0ad982cc95513c3a680a9e7612d895598
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"
12 nsBaseClipboard::nsBaseClipboard()
13 : mEmptyingForSetData(false), mIgnoreEmptyNotification(false) {}
15 nsBaseClipboard::~nsBaseClipboard() {
16 EmptyClipboard(kSelectionClipboard);
17 EmptyClipboard(kGlobalClipboard);
18 EmptyClipboard(kFindClipboard);
21 NS_IMPL_ISUPPORTS(nsBaseClipboard, nsIClipboard)
23 /**
24 * Sets the transferable object
27 NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable* aTransferable,
28 nsIClipboardOwner* anOwner,
29 int32_t aWhichClipboard) {
30 NS_ASSERTION(aTransferable, "clipboard given a null transferable");
32 if (aTransferable == mTransferable && anOwner == mClipboardOwner)
33 return NS_OK;
34 bool selectClipPresent;
35 SupportsSelectionClipboard(&selectClipPresent);
36 bool findClipPresent;
37 SupportsFindClipboard(&findClipPresent);
38 if (!selectClipPresent && !findClipPresent &&
39 aWhichClipboard != kGlobalClipboard)
40 return NS_ERROR_FAILURE;
42 mEmptyingForSetData = true;
43 EmptyClipboard(aWhichClipboard);
44 mEmptyingForSetData = false;
46 mClipboardOwner = anOwner;
47 mTransferable = aTransferable;
49 nsresult rv = NS_ERROR_FAILURE;
50 if (mTransferable) {
51 rv = SetNativeClipboardData(aWhichClipboard);
54 return rv;
57 /**
58 * Gets the transferable object
61 NS_IMETHODIMP nsBaseClipboard::GetData(nsITransferable* aTransferable,
62 int32_t aWhichClipboard) {
63 NS_ASSERTION(aTransferable, "clipboard given a null transferable");
65 bool selectClipPresent;
66 SupportsSelectionClipboard(&selectClipPresent);
67 bool findClipPresent;
68 SupportsFindClipboard(&findClipPresent);
69 if (!selectClipPresent && !findClipPresent &&
70 aWhichClipboard != kGlobalClipboard)
71 return NS_ERROR_FAILURE;
73 if (aTransferable)
74 return GetNativeClipboardData(aTransferable, aWhichClipboard);
76 return NS_ERROR_FAILURE;
79 NS_IMETHODIMP nsBaseClipboard::EmptyClipboard(int32_t aWhichClipboard) {
80 bool selectClipPresent;
81 SupportsSelectionClipboard(&selectClipPresent);
82 bool findClipPresent;
83 SupportsFindClipboard(&findClipPresent);
84 if (!selectClipPresent && !findClipPresent &&
85 aWhichClipboard != kGlobalClipboard)
86 return NS_ERROR_FAILURE;
88 if (mIgnoreEmptyNotification) return NS_OK;
90 if (mClipboardOwner) {
91 mClipboardOwner->LosingOwnership(mTransferable);
92 mClipboardOwner = nullptr;
95 mTransferable = nullptr;
96 return NS_OK;
99 NS_IMETHODIMP
100 nsBaseClipboard::HasDataMatchingFlavors(const nsTArray<nsCString>& aFlavorList,
101 int32_t aWhichClipboard,
102 bool* outResult) {
103 *outResult = true; // say we always do.
104 return NS_OK;
107 NS_IMETHODIMP
108 nsBaseClipboard::SupportsSelectionClipboard(bool* _retval) {
109 *_retval = false; // we don't support the selection clipboard by default.
110 return NS_OK;
113 NS_IMETHODIMP
114 nsBaseClipboard::SupportsFindClipboard(bool* _retval) {
115 *_retval = false; // we don't support the find clipboard by default.
116 return NS_OK;