Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / nsCopySupport.h
blob5552e1a6074e504c2ebceb97f97c0cdb7a8b0771
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 nsCopySupport_h__
7 #define nsCopySupport_h__
9 #include <cstdint>
10 #include "ErrorList.h"
11 #include "mozilla/AlreadyAddRefed.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/BasicEvents.h"
14 #include "nsStringFwd.h"
16 class nsINode;
17 class nsIImageLoadingContent;
18 class nsITransferable;
19 class nsILoadContext;
21 namespace mozilla {
22 class PresShell;
23 namespace dom {
24 class Document;
25 class Selection;
26 class WindowContext;
27 } // namespace dom
28 } // namespace mozilla
30 class nsCopySupport {
31 // class of static helper functions for copy support
32 public:
33 static nsresult ClearSelectionCache();
35 /**
36 * @param aDoc Needs to be not nullptr.
38 static nsresult EncodeDocumentWithContextAndPutToClipboard(
39 mozilla::dom::Selection* aSel, mozilla::dom::Document* aDoc,
40 int16_t aClipboardID, bool aWithRubyAnnotation);
42 // Get the selection, or entire document, in the format specified by the mime
43 // type (text/html or text/plain). If aSel is non-null, use it, otherwise get
44 // the entire doc.
45 static nsresult GetContents(const nsACString& aMimeType, uint32_t aFlags,
46 mozilla::dom::Selection* aSel,
47 mozilla::dom::Document* aDoc, nsAString& outdata);
49 static nsresult ImageCopy(nsIImageLoadingContent* aImageElement,
50 nsILoadContext* aLoadContext, int32_t aCopyFlags,
51 mozilla::dom::WindowContext* aSettingWindowContext);
53 // Get the selection as a transferable.
54 // @param aSelection Can be nullptr.
55 // @param aDocument Needs to be not nullptr.
56 // @param aTransferable Needs to be not nullptr.
57 static nsresult GetTransferableForSelection(
58 mozilla::dom::Selection* aSelection, mozilla::dom::Document* aDocument,
59 nsITransferable** aTransferable);
61 // Same as GetTransferableForSelection, but doesn't skip invisible content.
62 // @param aNode Needs to be not nullptr.
63 // @param aDoc Needs to be not nullptr.
64 // @param aTransferable Needs to be not nullptr.
65 MOZ_CAN_RUN_SCRIPT_BOUNDARY
66 static nsresult GetTransferableForNode(nsINode* aNode,
67 mozilla::dom::Document* aDoc,
68 nsITransferable** aTransferable);
69 /**
70 * Retrieve the selection for the given document. If the current focus
71 * within the document has its own selection, aSelection will be set to it
72 * and this focused content node returned. Otherwise, aSelection will be
73 * set to the document's selection and null will be returned.
75 static already_AddRefed<mozilla::dom::Selection> GetSelectionForCopy(
76 mozilla::dom::Document* aDocument);
78 /**
79 * Returns true if a copy operation is currently permitted based on the
80 * current focus and selection within the specified document.
82 static bool CanCopy(mozilla::dom::Document* aDocument);
84 /**
85 * Fires a cut, copy or paste event, on the given presshell, depending
86 * on the value of aEventMessage, which should be either eCut, eCopy or
87 * ePaste, and perform the default copy action if the event was not
88 * cancelled.
90 * If aSelection is specified, then this selection is used as the target
91 * of the operation. Otherwise, GetSelectionForCopy is used to retrieve
92 * the current selection.
94 * This will fire a cut, copy or paste event at the node at the start
95 * point of the selection. If a cut or copy event is not cancelled, the
96 * selection is copied to the clipboard and true is returned. Paste events
97 * have no default behaviour but true will be returned. It is expected
98 * that the caller will execute any needed default paste behaviour. Also,
99 * note that this method only copies text to the clipboard, the caller is
100 * responsible for removing the content during a cut operation if true is
101 * returned.
103 * aClipboardType specifies which clipboard to use, from nsIClipboard.
105 * If aActionTaken is non-NULL, it will be set to true if an action was
106 * taken, whether it be the default action or the default being prevented.
108 * If the event is cancelled or an error occurs, false will be returned.
110 MOZ_CAN_RUN_SCRIPT_BOUNDARY
111 static bool FireClipboardEvent(mozilla::EventMessage aEventMessage,
112 int32_t aClipboardType,
113 mozilla::PresShell* aPresShell,
114 mozilla::dom::Selection* aSelection,
115 bool* aActionTaken = nullptr);
118 #endif