michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsCopySupport_h__ michael@0: #define nsCopySupport_h__ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsINode.h" michael@0: michael@0: class nsISelection; michael@0: class nsIDocument; michael@0: class nsIImageLoadingContent; michael@0: class nsIContent; michael@0: class nsITransferable; michael@0: class nsACString; michael@0: class nsAString; michael@0: class nsIPresShell; michael@0: class nsILoadContext; michael@0: michael@0: class nsCopySupport michael@0: { michael@0: // class of static helper functions for copy support michael@0: public: michael@0: static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc, int16_t aClipboardID); michael@0: static nsresult DoHooks(nsIDocument *aDoc, nsITransferable *aTrans, michael@0: bool *aDoPutOnClipboard); michael@0: michael@0: // Get the selection, or entire document, in the format specified by the mime type michael@0: // (text/html or text/plain). If aSel is non-null, use it, otherwise get the entire michael@0: // doc. michael@0: static nsresult GetContents(const nsACString& aMimeType, uint32_t aFlags, nsISelection *aSel, nsIDocument *aDoc, nsAString& outdata); michael@0: michael@0: static nsresult ImageCopy(nsIImageLoadingContent* aImageElement, michael@0: nsILoadContext* aLoadContext, michael@0: int32_t aCopyFlags); michael@0: michael@0: // Get the selection as a transferable. Similar to HTMLCopy except does michael@0: // not deal with the clipboard. michael@0: static nsresult GetTransferableForSelection(nsISelection* aSelection, michael@0: nsIDocument* aDocument, michael@0: nsITransferable** aTransferable); michael@0: michael@0: // Same as GetTransferableForSelection, but doesn't skip invisible content. michael@0: static nsresult GetTransferableForNode(nsINode* aNode, michael@0: nsIDocument* aDoc, michael@0: nsITransferable** aTransferable); michael@0: /** michael@0: * Retrieve the selection for the given document. If the current focus michael@0: * within the document has its own selection, aSelection will be set to it michael@0: * and this focused content node returned. Otherwise, aSelection will be michael@0: * set to the document's selection and null will be returned. michael@0: */ michael@0: static nsIContent* GetSelectionForCopy(nsIDocument* aDocument, michael@0: nsISelection** aSelection); michael@0: michael@0: /** michael@0: * Returns true if a copy operation is currently permitted based on the michael@0: * current focus and selection within the specified document. michael@0: */ michael@0: static bool CanCopy(nsIDocument* aDocument); michael@0: michael@0: /** michael@0: * Fires a cut, copy or paste event, on the given presshell, depending michael@0: * on the value of aType, which should be either NS_CUT, NS_COPY or michael@0: * NS_PASTE, and perform the default copy action if the event was not michael@0: * cancelled. michael@0: * michael@0: * If aSelection is specified, then this selection is used as the target michael@0: * of the operation. Otherwise, GetSelectionForCopy is used to retrieve michael@0: * the current selection. michael@0: * michael@0: * This will fire a cut, copy or paste event at the node at the start michael@0: * point of the selection. If a cut or copy event is not cancelled, the michael@0: * selection is copied to the clipboard and true is returned. Paste events michael@0: * have no default behaviour but true will be returned. It is expected michael@0: * that the caller will execute any needed default paste behaviour. Also, michael@0: * note that this method only copies text to the clipboard, the caller is michael@0: * responsible for removing the content during a cut operation if true is michael@0: * returned. michael@0: * michael@0: * aClipboardType specifies which clipboard to use, from nsIClipboard. michael@0: * michael@0: * If the event is cancelled or an error occurs, false will be returned. michael@0: */ michael@0: static bool FireClipboardEvent(int32_t aType, michael@0: int32_t aClipboardType, michael@0: nsIPresShell* aPresShell, michael@0: nsISelection* aSelection); michael@0: }; michael@0: michael@0: #endif