Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / nsClipboard.h
bloba9d5e79d968618d70ce42aaaf50a54f7aeb94d40
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);
43 protected:
44 // Implement the native clipboard behavior.
45 NS_IMETHOD SetNativeClipboardData(nsITransferable* aTransferable,
46 int32_t aWhichClipboard) override;
47 NS_IMETHOD GetNativeClipboardData(nsITransferable* aTransferable,
48 int32_t aWhichClipboard) override;
49 nsresult EmptyNativeClipboardData(int32_t aWhichClipboard) override;
50 mozilla::Result<int32_t, nsresult> GetNativeClipboardSequenceNumber(
51 int32_t aWhichClipboard) override;
52 mozilla::Result<bool, nsresult> HasNativeClipboardDataMatchingFlavors(
53 const nsTArray<nsCString>& aFlavorList, int32_t aWhichClipboard) override;
55 void ClearSelectionCache();
56 void SetSelectionCache(nsITransferable* aTransferable);
58 private:
59 virtual ~nsClipboard();
61 static mozilla::Maybe<uint32_t> FindIndexOfImageFlavor(
62 const nsTArray<nsCString>& aMIMETypes);
65 #endif // nsClipboard_h_