Bug 1527661 [wpt PR 15356] - Update wpt metadata, a=testonly
[gecko.git] / widget / nsBaseClipboard.cpp
bloba74f7e35ef46e884214d007b67126adb4131a63c
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()
14 : mEmptyingForSetData(false), mIgnoreEmptyNotification(false) {}
16 nsBaseClipboard::~nsBaseClipboard() {
17 EmptyClipboard(kSelectionClipboard);
18 EmptyClipboard(kGlobalClipboard);
19 EmptyClipboard(kFindClipboard);
22 NS_IMPL_ISUPPORTS(nsBaseClipboard, nsIClipboard)
24 /**
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)
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;
43 mEmptyingForSetData = true;
44 EmptyClipboard(aWhichClipboard);
45 mEmptyingForSetData = false;
47 mClipboardOwner = anOwner;
48 mTransferable = aTransferable;
50 nsresult rv = NS_ERROR_FAILURE;
51 if (mTransferable) {
52 rv = SetNativeClipboardData(aWhichClipboard);
55 return rv;
58 /**
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);
68 bool findClipPresent;
69 SupportsFindClipboard(&findClipPresent);
70 if (!selectClipPresent && !findClipPresent &&
71 aWhichClipboard != kGlobalClipboard)
72 return NS_ERROR_FAILURE;
74 if (aTransferable)
75 return GetNativeClipboardData(aTransferable, aWhichClipboard);
77 return NS_ERROR_FAILURE;
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;
89 if (mIgnoreEmptyNotification) return NS_OK;
91 if (mClipboardOwner) {
92 mClipboardOwner->LosingOwnership(mTransferable);
93 mClipboardOwner = nullptr;
96 mTransferable = nullptr;
97 return NS_OK;
100 NS_IMETHODIMP
101 nsBaseClipboard::HasDataMatchingFlavors(const char** aFlavorList,
102 uint32_t aLength,
103 int32_t aWhichClipboard,
104 bool* outResult) {
105 *outResult = true; // say we always do.
106 return NS_OK;
109 NS_IMETHODIMP
110 nsBaseClipboard::SupportsSelectionClipboard(bool* _retval) {
111 *_retval = false; // we don't support the selection clipboard by default.
112 return NS_OK;
115 NS_IMETHODIMP
116 nsBaseClipboard::SupportsFindClipboard(bool* _retval) {
117 *_retval = false; // we don't support the find clipboard by default.
118 return NS_OK;