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/. */
9 #include "nsBaseClipboard.h"
11 #include "nsIClipboard.h"
13 #include "mozilla/Maybe.h"
14 #include "mozilla/StaticPtr.h"
16 #import <Cocoa/Cocoa.h>
18 class nsITransferable
;
20 @interface UTIHelper
: NSObject
21 + (NSString
*)stringFromPboardType
:(NSString
*)aType
;
24 class nsClipboard
: public nsBaseClipboard
{
28 NS_DECL_ISUPPORTS_INHERITED
31 NS_IMETHOD
SetData(nsITransferable
* aTransferable
, nsIClipboardOwner
* anOwner
,
32 int32_t aWhichClipboard
) override
;
33 NS_IMETHOD
HasDataMatchingFlavors(const nsTArray
<nsCString
>& aFlavorList
, int32_t aWhichClipboard
,
34 bool* _retval
) override
;
35 NS_IMETHOD
SupportsFindClipboard(bool* _retval
) override
;
36 NS_IMETHOD
EmptyClipboard(int32_t aWhichClipboard
) override
;
38 // On macOS, cache the transferable of the current selection (chrome/content)
39 // in the parent process. This is needed for the services menu which
40 // requires synchronous access to the current selection.
41 static mozilla::StaticRefPtr
<nsITransferable
> sSelectionCache
;
43 // Helper methods, used also by nsDragService
44 static NSDictionary
* PasteboardDictFromTransferable(nsITransferable
* aTransferable
);
45 // aPasteboardType is being retained and needs to be released by the caller.
46 static bool IsStringType(const nsCString
& aMIMEType
, NSString
** aPasteboardType
);
47 static bool IsImageType(const nsACString
& aMIMEType
);
48 static NSString
* WrapHtmlForSystemPasteboard(NSString
* aString
);
49 static nsresult
TransferableFromPasteboard(nsITransferable
* aTransferable
, NSPasteboard
* pboard
);
52 // impelement the native clipboard behavior
53 NS_IMETHOD
SetNativeClipboardData(int32_t aWhichClipboard
) override
;
54 NS_IMETHOD
GetNativeClipboardData(nsITransferable
* aTransferable
,
55 int32_t aWhichClipboard
) override
;
56 void ClearSelectionCache();
57 void SetSelectionCache(nsITransferable
* aTransferable
);
60 virtual ~nsClipboard();
62 static mozilla::Maybe
<uint32_t> FindIndexOfImageFlavor(const nsTArray
<nsCString
>& aMIMETypes
);
64 int32_t mCachedClipboard
;
65 int32_t mChangeCount
; // Set to the native change count after any modification of the clipboard.
68 #endif // nsClipboard_h_