|
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/. */ |
|
5 |
|
6 #ifndef nsCopySupport_h__ |
|
7 #define nsCopySupport_h__ |
|
8 |
|
9 #include "nscore.h" |
|
10 #include "nsINode.h" |
|
11 |
|
12 class nsISelection; |
|
13 class nsIDocument; |
|
14 class nsIImageLoadingContent; |
|
15 class nsIContent; |
|
16 class nsITransferable; |
|
17 class nsACString; |
|
18 class nsAString; |
|
19 class nsIPresShell; |
|
20 class nsILoadContext; |
|
21 |
|
22 class nsCopySupport |
|
23 { |
|
24 // class of static helper functions for copy support |
|
25 public: |
|
26 static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc, int16_t aClipboardID); |
|
27 static nsresult DoHooks(nsIDocument *aDoc, nsITransferable *aTrans, |
|
28 bool *aDoPutOnClipboard); |
|
29 |
|
30 // Get the selection, or entire document, in the format specified by the mime type |
|
31 // (text/html or text/plain). If aSel is non-null, use it, otherwise get the entire |
|
32 // doc. |
|
33 static nsresult GetContents(const nsACString& aMimeType, uint32_t aFlags, nsISelection *aSel, nsIDocument *aDoc, nsAString& outdata); |
|
34 |
|
35 static nsresult ImageCopy(nsIImageLoadingContent* aImageElement, |
|
36 nsILoadContext* aLoadContext, |
|
37 int32_t aCopyFlags); |
|
38 |
|
39 // Get the selection as a transferable. Similar to HTMLCopy except does |
|
40 // not deal with the clipboard. |
|
41 static nsresult GetTransferableForSelection(nsISelection* aSelection, |
|
42 nsIDocument* aDocument, |
|
43 nsITransferable** aTransferable); |
|
44 |
|
45 // Same as GetTransferableForSelection, but doesn't skip invisible content. |
|
46 static nsresult GetTransferableForNode(nsINode* aNode, |
|
47 nsIDocument* aDoc, |
|
48 nsITransferable** aTransferable); |
|
49 /** |
|
50 * Retrieve the selection for the given document. If the current focus |
|
51 * within the document has its own selection, aSelection will be set to it |
|
52 * and this focused content node returned. Otherwise, aSelection will be |
|
53 * set to the document's selection and null will be returned. |
|
54 */ |
|
55 static nsIContent* GetSelectionForCopy(nsIDocument* aDocument, |
|
56 nsISelection** aSelection); |
|
57 |
|
58 /** |
|
59 * Returns true if a copy operation is currently permitted based on the |
|
60 * current focus and selection within the specified document. |
|
61 */ |
|
62 static bool CanCopy(nsIDocument* aDocument); |
|
63 |
|
64 /** |
|
65 * Fires a cut, copy or paste event, on the given presshell, depending |
|
66 * on the value of aType, which should be either NS_CUT, NS_COPY or |
|
67 * NS_PASTE, and perform the default copy action if the event was not |
|
68 * cancelled. |
|
69 * |
|
70 * If aSelection is specified, then this selection is used as the target |
|
71 * of the operation. Otherwise, GetSelectionForCopy is used to retrieve |
|
72 * the current selection. |
|
73 * |
|
74 * This will fire a cut, copy or paste event at the node at the start |
|
75 * point of the selection. If a cut or copy event is not cancelled, the |
|
76 * selection is copied to the clipboard and true is returned. Paste events |
|
77 * have no default behaviour but true will be returned. It is expected |
|
78 * that the caller will execute any needed default paste behaviour. Also, |
|
79 * note that this method only copies text to the clipboard, the caller is |
|
80 * responsible for removing the content during a cut operation if true is |
|
81 * returned. |
|
82 * |
|
83 * aClipboardType specifies which clipboard to use, from nsIClipboard. |
|
84 * |
|
85 * If the event is cancelled or an error occurs, false will be returned. |
|
86 */ |
|
87 static bool FireClipboardEvent(int32_t aType, |
|
88 int32_t aClipboardType, |
|
89 nsIPresShell* aPresShell, |
|
90 nsISelection* aSelection); |
|
91 }; |
|
92 |
|
93 #endif |