Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / widget / windows / nsClipboard.h
blob2c1244dc8ea6e5ecaf7f12bebbae888f50d9e300
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 "nsIObserver.h"
11 #include "nsIURI.h"
13 #include <ole2.h>
14 #include <windows.h>
16 class nsITransferable;
17 class nsIWidget;
18 class nsIFile;
19 struct IDataObject;
21 /**
22 * Native Win32 Clipboard wrapper
25 class nsClipboard : public nsBaseClipboard, public nsIObserver {
26 virtual ~nsClipboard();
28 public:
29 nsClipboard();
31 NS_DECL_ISUPPORTS_INHERITED
33 // nsIObserver
34 NS_DECL_NSIOBSERVER
36 // Internal Native Routines
37 enum class MightNeedToFlush : bool { No, Yes };
38 static nsresult CreateNativeDataObject(nsITransferable* aTransferable,
39 IDataObject** aDataObj, nsIURI* aUri,
40 MightNeedToFlush* = nullptr);
41 static nsresult SetupNativeDataObject(nsITransferable* aTransferable,
42 IDataObject* aDataObj,
43 MightNeedToFlush* = nullptr);
44 static nsresult GetDataFromDataObject(IDataObject* aDataObject, UINT anIndex,
45 nsIWidget* aWindow,
46 nsITransferable* aTransferable);
47 static nsresult GetNativeDataOffClipboard(nsIWidget* aWindow, UINT aIndex,
48 UINT aFormat, void** aData,
49 uint32_t* aLen);
50 static nsresult GetNativeDataOffClipboard(IDataObject* aDataObject,
51 UINT aIndex, UINT aFormat,
52 const char* aMIMEImageFormat,
53 void** aData, uint32_t* aLen);
54 static nsresult GetGlobalData(HGLOBAL aHGBL, void** aData, uint32_t* aLen);
56 // This function returns the internal Windows clipboard format identifier
57 // for a given Mime string. The default is to map kHTMLMime ("text/html")
58 // to the clipboard format CF_HTML ("HTLM Format"), but it can also be
59 // registered as clipboard format "text/html" to support previous versions
60 // of Gecko.
61 static UINT GetFormat(const char* aMimeStr, bool aMapHTMLMime = true);
63 static UINT GetClipboardFileDescriptorFormatA();
64 static UINT GetClipboardFileDescriptorFormatW();
65 static UINT GetHtmlClipboardFormat();
66 static UINT GetCustomClipboardFormat();
67 mozilla::Result<int32_t, nsresult> GetNativeClipboardSequenceNumber(
68 ClipboardType aWhichClipboard) override;
70 protected:
71 // @param aDataObject must be non-nullptr.
72 static HRESULT FillSTGMedium(IDataObject* aDataObject, UINT aFormat,
73 LPFORMATETC pFE, LPSTGMEDIUM pSTM, DWORD aTymed);
75 // Implement the native clipboard behavior.
76 NS_IMETHOD SetNativeClipboardData(nsITransferable* aTransferable,
77 ClipboardType aWhichClipboard) override;
78 NS_IMETHOD GetNativeClipboardData(nsITransferable* aTransferable,
79 ClipboardType aWhichClipboard) override;
80 nsresult EmptyNativeClipboardData(ClipboardType aWhichClipboard) override;
81 mozilla::Result<bool, nsresult> HasNativeClipboardDataMatchingFlavors(
82 const nsTArray<nsCString>& aFlavorList,
83 ClipboardType aWhichClipboard) override;
85 static bool IsInternetShortcut(const nsAString& inFileName);
86 static bool FindURLFromLocalFile(IDataObject* inDataObject, UINT inIndex,
87 void** outData, uint32_t* outDataLen);
88 static bool FindURLFromNativeURL(IDataObject* inDataObject, UINT inIndex,
89 void** outData, uint32_t* outDataLen);
90 static bool FindUnicodeFromPlainText(IDataObject* inDataObject, UINT inIndex,
91 void** outData, uint32_t* outDataLen);
92 static bool FindPlatformHTML(IDataObject* inDataObject, UINT inIndex,
93 void** outData, uint32_t* outStartOfData,
94 uint32_t* outDataLen);
96 static void ResolveShortcut(nsIFile* inFileName, nsACString& outURL);
97 static nsresult GetTempFilePath(const nsAString& aFileName,
98 nsAString& aFilePath);
99 static nsresult SaveStorageOrStream(IDataObject* aDataObject, UINT aIndex,
100 const nsAString& aFileName);
102 nsIWidget* mWindow;
105 #define SET_FORMATETC(fe, cf, td, asp, li, med) \
107 (fe).cfFormat = cf; \
108 (fe).ptd = td; \
109 (fe).dwAspect = asp; \
110 (fe).lindex = li; \
111 (fe).tymed = med; \
114 #endif // nsClipboard_h__