/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsCopySupport.h" #include "imgIContainer.h" #include "imgIRequest.h" #include "mozilla/ScopeExit.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/DataTransfer.h" #include "mozilla/dom/Document.h" #include "nsComponentManagerUtils.h" #include "nsFocusManager.h" #include "nsFrameSelection.h" #include "nsGkAtoms.h" #include "nsGlobalWindowInner.h" #include "nsHTMLDocument.h" #include "nsIClipboard.h" #include "nsIContent.h" #include "nsIDocShell.h" #include "nsIDocumentEncoder.h" #include "nsIDocumentViewerEdit.h" #include "nsIFormControl.h" #include "nsIFrame.h" #include "nsISelectionController.h" #include "nsISupports.h" #include "nsISupportsPrimitives.h" #include "nsPIDOMWindow.h" #include "nsRange.h" #include "nsServiceManagerUtils.h" #include "nsWidgetsCID.h" #include "nsXPCOM.h" // image copy stuff #include "nsContentUtils.h" #include "nsIImageLoadingContent.h" #include "nsIInterfaceRequestorUtils.h" #ifdef XP_WIN # include "mozilla/StaticPrefs_clipboard.h" # include "nsCExternalHandlerService.h" # include "nsEscape.h" # include "nsIMIMEInfo.h" # include "nsIMIMEService.h" # include "nsIURIMutator.h" # include "nsIURL.h" # include "nsReadableUtils.h" # include "nsXULAppAPI.h" #endif #include "mozilla/ContentEvents.h" #include "mozilla/EventDispatcher.h" #include "mozilla/IntegerRange.h" #include "mozilla/Preferences.h" #include "mozilla/PresShell.h" #include "mozilla/TextEditor.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/Selection.h" using namespace mozilla; using namespace mozilla::dom; static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID); static NS_DEFINE_CID(kHTMLConverterCID, NS_HTMLFORMATCONVERTER_CID); // copy string data onto the transferable static nsresult AppendString(nsITransferable* aTransferable, const nsAString& aString, const char* aFlavor); // copy HTML node data static nsresult AppendDOMNode(nsITransferable* aTransferable, nsINode* aDOMNode); #ifdef XP_WIN // copy image as file promise onto the transferable static nsresult AppendImagePromise(nsITransferable* aTransferable, imgIRequest* aImgRequest, nsINode* aImageNode); #endif static nsresult EncodeForTextPlain(nsIDocumentEncoder& aEncoder, Document& aDocument, Selection* aSelection, uint32_t aAdditionalEncoderFlags, bool& aCanBeEncodedAsTextHTML, nsAString& aSerializationResult) { // We assign text/html as the MIME type first, but in fact nsHTMLCopyEncoder // force the use of text/plain depending where the selection is (e.g., a // selection inside an or