Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / widget / cocoa / nsClipboard.h
blobcbcc73cd4dfe805e58910764b0a5179eaf3bea8d
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 #ifndef nsClipboard_h_
7 #define nsClipboard_h_
9 #include "nsBaseClipboard.h"
10 #include "nsCOMPtr.h"
11 #include "nsIClipboard.h"
12 #include "nsString.h"
13 #include "mozilla/Maybe.h"
14 #include "mozilla/StaticPtr.h"
16 #import <Cocoa/Cocoa.h>
18 class nsITransferable;
20 class nsClipboard : public nsBaseClipboard {
21 public:
22 nsClipboard();
24 NS_DECL_ISUPPORTS_INHERITED
26 // On macOS, cache the transferable of the current selection (chrome/content)
27 // in the parent process. This is needed for the services menu which
28 // requires synchronous access to the current selection.
29 static mozilla::StaticRefPtr<nsITransferable> sSelectionCache;
30 static int32_t sSelectionCacheChangeCount;
32 // Helper methods, used also by nsDragService
33 static NSDictionary* PasteboardDictFromTransferable(
34 nsITransferable* aTransferable);
35 // aPasteboardType is being retained and needs to be released by the caller.
36 static bool IsStringType(const nsCString& aMIMEType,
37 NSString** aPasteboardType);
38 static bool IsImageType(const nsACString& aMIMEType);
39 static NSString* WrapHtmlForSystemPasteboard(NSString* aString);
40 static nsresult TransferableFromPasteboard(nsITransferable* aTransferable,
41 NSPasteboard* pboard);
42 mozilla::Result<int32_t, nsresult> GetNativeClipboardSequenceNumber(
43 ClipboardType aWhichClipboard) override;
45 protected:
46 // Implement the native clipboard behavior.
47 NS_IMETHOD SetNativeClipboardData(nsITransferable* aTransferable,
48 ClipboardType aWhichClipboard) override;
49 NS_IMETHOD GetNativeClipboardData(nsITransferable* aTransferable,
50 ClipboardType aWhichClipboard) override;
51 nsresult EmptyNativeClipboardData(ClipboardType aWhichClipboard) override;
52 mozilla::Result<bool, nsresult> HasNativeClipboardDataMatchingFlavors(
53 const nsTArray<nsCString>& aFlavorList,
54 ClipboardType aWhichClipboard) override;
56 void ClearSelectionCache();
57 void SetSelectionCache(nsITransferable* aTransferable);
59 private:
60 virtual ~nsClipboard();
62 static mozilla::Maybe<uint32_t> FindIndexOfImageFlavor(
63 const nsTArray<nsCString>& aMIMETypes);
66 #endif // nsClipboard_h_