2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2002-02-17 22:28:13 +03:00
|
|
|
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
|
|
|
|
// Local Includes
|
|
|
|
#include "nsContentAreaDragDrop.h"
|
|
|
|
|
|
|
|
// Helper Classes
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
// Interfaces needed to be included
|
2010-05-25 03:24:15 +04:00
|
|
|
#include "nsCopySupport.h"
|
2002-02-17 22:28:13 +03:00
|
|
|
#include "nsISelection.h"
|
2012-02-17 18:16:59 +04:00
|
|
|
#include "nsISelectionController.h"
|
2002-02-17 22:28:13 +03:00
|
|
|
#include "nsIDOMNode.h"
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2002-02-17 22:28:13 +03:00
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
2002-02-17 22:28:13 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2004-11-25 01:48:45 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2002-08-15 22:38:46 +04:00
|
|
|
#include "nsNetUtil.h"
|
2002-02-17 22:28:13 +03:00
|
|
|
#include "nsIFile.h"
|
2015-04-08 21:48:11 +03:00
|
|
|
#include "nsFrameLoader.h"
|
2002-02-17 22:28:13 +03:00
|
|
|
#include "nsIWebNavigation.h"
|
2003-04-17 17:23:34 +04:00
|
|
|
#include "nsIDocShell.h"
|
2002-04-01 08:27:50 +04:00
|
|
|
#include "nsIContent.h"
|
2003-03-19 06:47:09 +03:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2012-02-17 18:16:59 +04:00
|
|
|
#include "nsITextControlElement.h"
|
2002-04-01 08:27:50 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
2003-04-19 00:20:04 +04:00
|
|
|
#include "nsIURL.h"
|
2018-01-31 04:33:06 +03:00
|
|
|
#include "nsIURIMutator.h"
|
2002-04-23 18:24:48 +04:00
|
|
|
#include "nsIDocument.h"
|
2005-03-17 20:40:55 +03:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2008-08-27 16:07:27 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2004-04-22 07:16:18 +04:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2003-04-19 00:20:04 +04:00
|
|
|
#include "nsIWebBrowserPersist.h"
|
|
|
|
#include "nsEscape.h"
|
2004-07-30 10:04:57 +04:00
|
|
|
#include "nsContentUtils.h"
|
2005-02-08 01:20:14 +03:00
|
|
|
#include "nsIMIMEService.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
#include "imgIContainer.h"
|
2005-02-08 01:20:14 +03:00
|
|
|
#include "imgIRequest.h"
|
2013-08-12 18:45:33 +04:00
|
|
|
#include "mozilla/dom/DataTransfer.h"
|
2013-09-23 07:35:05 +04:00
|
|
|
#include "nsIMIMEInfo.h"
|
2014-01-15 18:26:51 +04:00
|
|
|
#include "nsRange.h"
|
2015-04-08 21:48:11 +03:00
|
|
|
#include "TabParent.h"
|
2012-05-06 11:53:11 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-08-08 00:23:08 +04:00
|
|
|
#include "mozilla/dom/HTMLAreaElement.h"
|
2017-09-23 00:56:51 +03:00
|
|
|
#include "mozilla/dom/HTMLAnchorElement.h"
|
2015-10-07 18:17:42 +03:00
|
|
|
#include "nsVariant.h"
|
2013-08-08 00:23:08 +04:00
|
|
|
|
2013-08-12 18:45:33 +04:00
|
|
|
using namespace mozilla::dom;
|
2018-02-01 22:21:14 +03:00
|
|
|
using mozilla::IgnoreErrors;
|
2002-04-23 18:24:48 +04:00
|
|
|
|
2013-04-12 07:20:09 +04:00
|
|
|
class MOZ_STACK_CLASS DragDataProducer
|
2003-06-18 02:35:01 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-01-30 20:05:36 +03:00
|
|
|
DragDataProducer(nsPIDOMWindowOuter* aWindow,
|
2010-04-18 22:27:18 +04:00
|
|
|
nsIContent* aTarget,
|
|
|
|
nsIContent* aSelectionTargetNode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsAltKeyPressed);
|
2013-08-12 18:45:33 +04:00
|
|
|
nsresult Produce(DataTransfer* aDataTransfer,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aCanDrag,
|
2012-02-17 18:16:59 +04:00
|
|
|
nsISelection** aSelection,
|
2018-02-09 04:43:53 +03:00
|
|
|
nsIContent** aDragNode,
|
|
|
|
nsACString& aPrincipalURISpec);
|
2003-06-18 02:35:01 +04:00
|
|
|
|
|
|
|
private:
|
2013-08-12 18:45:33 +04:00
|
|
|
void AddString(DataTransfer* aDataTransfer,
|
2008-08-27 16:07:27 +04:00
|
|
|
const nsAString& aFlavor,
|
|
|
|
const nsAString& aData,
|
2018-03-28 00:55:33 +03:00
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
bool aHidden=false);
|
2008-08-27 16:07:27 +04:00
|
|
|
nsresult AddStringsToDataTransfer(nsIContent* aDragNode,
|
2013-08-12 18:45:33 +04:00
|
|
|
DataTransfer* aDataTransfer);
|
2018-03-28 00:55:33 +03:00
|
|
|
nsresult GetImageData(imgIContainer* aImage, imgIRequest* aRequest);
|
2005-03-17 21:00:33 +03:00
|
|
|
static nsresult GetDraggableSelectionData(nsISelection* inSelection,
|
2008-08-27 16:07:27 +04:00
|
|
|
nsIContent* inRealTargetNode,
|
|
|
|
nsIContent **outImageOrLinkNode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* outDragSelectedText);
|
2008-08-27 16:07:27 +04:00
|
|
|
static already_AddRefed<nsIContent> FindParentLinkNode(nsIContent* inNode);
|
2016-09-08 07:17:58 +03:00
|
|
|
static MOZ_MUST_USE nsresult
|
|
|
|
GetAnchorURL(nsIContent* inNode, nsAString& outURL);
|
2008-08-27 16:07:27 +04:00
|
|
|
static void GetNodeString(nsIContent* inNode, nsAString & outNodeString);
|
2003-06-18 02:35:01 +04:00
|
|
|
static void CreateLinkText(const nsAString& inURL, const nsAString & inText,
|
|
|
|
nsAString& outLinkText);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> mWindow;
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIContent> mTarget;
|
|
|
|
nsCOMPtr<nsIContent> mSelectionTargetNode;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsAltKeyPressed;
|
2003-06-18 02:35:01 +04:00
|
|
|
|
|
|
|
nsString mUrlString;
|
|
|
|
nsString mImageSourceString;
|
2005-02-18 22:18:20 +03:00
|
|
|
nsString mImageDestFileName;
|
2018-03-28 00:55:33 +03:00
|
|
|
#if defined (XP_MACOSX)
|
|
|
|
nsString mImageRequestMime;
|
|
|
|
#endif
|
2003-06-18 02:35:01 +04:00
|
|
|
nsString mTitleString;
|
2005-03-17 21:00:33 +03:00
|
|
|
// will be filled automatically if you fill urlstring
|
|
|
|
nsString mHtmlString;
|
2003-06-18 02:35:01 +04:00
|
|
|
nsString mContextString;
|
|
|
|
nsString mInfoString;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsAnchor;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
nsCOMPtr<imgIContainer> mImage;
|
2003-06-18 02:35:01 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
nsresult
|
2016-01-30 20:05:36 +03:00
|
|
|
nsContentAreaDragDrop::GetDragData(nsPIDOMWindowOuter* aWindow,
|
2008-08-27 16:07:27 +04:00
|
|
|
nsIContent* aTarget,
|
|
|
|
nsIContent* aSelectionTargetNode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsAltKeyPressed,
|
2013-08-12 18:45:33 +04:00
|
|
|
DataTransfer* aDataTransfer,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aCanDrag,
|
2012-02-17 18:16:59 +04:00
|
|
|
nsISelection** aSelection,
|
2018-02-09 04:43:53 +03:00
|
|
|
nsIContent** aDragNode,
|
|
|
|
nsACString& aPrincipalURISpec)
|
2008-08-27 16:07:27 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aSelectionTargetNode, NS_ERROR_INVALID_ARG);
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanDrag = true;
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2010-04-18 22:27:18 +04:00
|
|
|
DragDataProducer
|
|
|
|
provider(aWindow, aTarget, aSelectionTargetNode, aIsAltKeyPressed);
|
2018-02-09 04:43:53 +03:00
|
|
|
return provider.Produce(aDataTransfer, aCanDrag, aSelection, aDragNode,
|
|
|
|
aPrincipalURISpec);
|
2003-06-18 02:35:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsContentAreaDragDropDataProvider, nsIFlavorDataProvider)
|
2008-08-27 16:07:27 +04:00
|
|
|
|
2003-06-18 02:35:01 +04:00
|
|
|
// SaveURIToFile
|
|
|
|
// used on platforms where it's possible to drag items (e.g. images)
|
|
|
|
// into the file system
|
|
|
|
nsresult
|
2018-03-28 00:55:33 +03:00
|
|
|
nsContentAreaDragDropDataProvider::SaveURIToFile(nsIURI* inSourceURI,
|
2012-10-04 23:07:51 +04:00
|
|
|
nsIFile* inDestFile,
|
|
|
|
bool isPrivate)
|
2003-06-18 02:35:01 +04:00
|
|
|
{
|
2018-03-28 00:55:33 +03:00
|
|
|
nsCOMPtr<nsIURL> sourceURL = do_QueryInterface(inSourceURI);
|
2005-03-17 21:00:33 +03:00
|
|
|
if (!sourceURL) {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
2003-06-18 02:35:01 +04:00
|
|
|
|
2018-03-28 00:55:33 +03:00
|
|
|
nsresult rv = inDestFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
|
2005-02-18 22:18:20 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-06-18 02:35:01 +04:00
|
|
|
|
|
|
|
// we rely on the fact that the WPB is refcounted by the channel etc,
|
|
|
|
// so we don't keep a ref to it. It will die when finished.
|
2005-02-18 22:18:20 +03:00
|
|
|
nsCOMPtr<nsIWebBrowserPersist> persist =
|
|
|
|
do_CreateInstance("@mozilla.org/embedding/browser/nsWebBrowserPersist;1",
|
|
|
|
&rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-06-18 02:35:01 +04:00
|
|
|
|
2011-12-15 23:14:38 +04:00
|
|
|
persist->SetPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION);
|
|
|
|
|
2014-11-18 16:47:14 +03:00
|
|
|
// referrer policy can be anything since the referrer is nullptr
|
2018-03-06 06:19:42 +03:00
|
|
|
return persist->SavePrivacyAwareURI(inSourceURI, 0, nullptr,
|
2017-01-05 06:29:56 +03:00
|
|
|
mozilla::net::RP_Unset,
|
2014-11-18 16:47:14 +03:00
|
|
|
nullptr, nullptr,
|
2012-10-04 23:07:51 +04:00
|
|
|
inDestFile, isPrivate);
|
2003-06-18 02:35:01 +04:00
|
|
|
}
|
|
|
|
|
2018-03-28 00:55:33 +03:00
|
|
|
/*
|
|
|
|
* Check if the provided filename extension is valid for the MIME type and
|
|
|
|
* return the MIME type's primary extension.
|
|
|
|
*
|
|
|
|
* @param aExtension [in] the extension to check
|
|
|
|
* @param aMimeType [in] the MIME type to check the extension with
|
|
|
|
* @param aIsValidExtension [out] true if |aExtension| is valid for
|
|
|
|
* |aMimeType|
|
|
|
|
* @param aPrimaryExtension [out] the primary extension for the MIME type
|
|
|
|
* to potentially be used as a replacement
|
|
|
|
* for |aExtension|
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
CheckAndGetExtensionForMime(const nsCString& aExtension,
|
|
|
|
const nsCString& aMimeType,
|
|
|
|
bool* aIsValidExtension,
|
|
|
|
nsACString* aPrimaryExtension)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMIMEService> mimeService = do_GetService("@mozilla.org/mime;1");
|
|
|
|
if (NS_WARN_IF(!mimeService)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMIMEInfo> mimeInfo;
|
|
|
|
rv = mimeService->GetFromTypeAndExtension(aMimeType, EmptyCString(),
|
|
|
|
getter_AddRefs(mimeInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mimeInfo->GetPrimaryExtension(*aPrimaryExtension);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aExtension.IsEmpty()) {
|
|
|
|
*aIsValidExtension = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mimeInfo->ExtensionExists(aExtension, aIsValidExtension);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-17 21:00:33 +03:00
|
|
|
// This is our nsIFlavorDataProvider callback. There are several
|
|
|
|
// assumptions here that make this work:
|
|
|
|
//
|
|
|
|
// 1. Someone put a kFilePromiseURLMime flavor into the transferable
|
|
|
|
// with the source URI of the file to save (as a string). We did
|
2008-08-27 16:07:27 +04:00
|
|
|
// that in AddStringsToDataTransfer.
|
2005-03-17 21:00:33 +03:00
|
|
|
//
|
|
|
|
// 2. Someone put a kFilePromiseDirectoryMime flavor into the
|
2012-06-06 06:08:30 +04:00
|
|
|
// transferable with an nsIFile for the directory we are to
|
2005-03-17 21:00:33 +03:00
|
|
|
// save in. That has to be done by platform-specific code (in
|
2008-08-27 16:07:27 +04:00
|
|
|
// widget), which gets the destination directory from
|
|
|
|
// OS-specific drag information.
|
2005-03-17 21:00:33 +03:00
|
|
|
//
|
2003-06-18 02:35:01 +04:00
|
|
|
NS_IMETHODIMP
|
2008-08-27 16:07:27 +04:00
|
|
|
nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable *aTransferable,
|
|
|
|
const char *aFlavor,
|
|
|
|
nsISupports **aData,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t *aDataLen)
|
2003-06-18 02:35:01 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aData && aDataLen);
|
2012-07-30 18:20:58 +04:00
|
|
|
*aData = nullptr;
|
2003-06-18 02:35:01 +04:00
|
|
|
*aDataLen = 0;
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
2005-03-17 21:00:33 +03:00
|
|
|
|
|
|
|
if (strcmp(aFlavor, kFilePromiseMime) == 0) {
|
2003-06-18 02:35:01 +04:00
|
|
|
// get the URI from the kFilePromiseURLMime flavor
|
|
|
|
NS_ENSURE_ARG(aTransferable);
|
2005-02-18 22:18:20 +03:00
|
|
|
nsCOMPtr<nsISupports> tmp;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dataSize = 0;
|
2005-02-18 22:18:20 +03:00
|
|
|
aTransferable->GetTransferData(kFilePromiseURLMime,
|
|
|
|
getter_AddRefs(tmp), &dataSize);
|
|
|
|
nsCOMPtr<nsISupportsString> supportsString =
|
|
|
|
do_QueryInterface(tmp);
|
|
|
|
if (!supportsString)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-06-18 02:35:01 +04:00
|
|
|
nsAutoString sourceURLString;
|
2005-02-18 22:18:20 +03:00
|
|
|
supportsString->GetData(sourceURLString);
|
2003-06-18 02:35:01 +04:00
|
|
|
if (sourceURLString.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2018-03-28 00:55:33 +03:00
|
|
|
nsCOMPtr<nsIURI> sourceURI;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(sourceURI), sourceURLString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-02-18 22:18:20 +03:00
|
|
|
aTransferable->GetTransferData(kFilePromiseDestFilename,
|
|
|
|
getter_AddRefs(tmp), &dataSize);
|
|
|
|
supportsString = do_QueryInterface(tmp);
|
|
|
|
if (!supportsString)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsAutoString targetFilename;
|
|
|
|
supportsString->GetData(targetFilename);
|
|
|
|
if (targetFilename.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2018-03-28 00:55:33 +03:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// Use the image request's MIME type to ensure the filename's
|
|
|
|
// extension is compatible with the OS's handler for this type.
|
|
|
|
// If it isn't, or is missing, replace the extension with the
|
|
|
|
// primary extension. On Mac, do this in the parent process
|
|
|
|
// because sandboxing blocks access to MIME-handler info from
|
|
|
|
// content processes.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
aTransferable->GetTransferData(kImageRequestMime,
|
|
|
|
getter_AddRefs(tmp), &dataSize);
|
|
|
|
supportsString = do_QueryInterface(tmp);
|
|
|
|
if (!supportsString)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsAutoString imageRequestMime;
|
|
|
|
supportsString->GetData(imageRequestMime);
|
|
|
|
|
|
|
|
// If we have a MIME type, check the extension is compatible
|
|
|
|
if (!imageRequestMime.IsEmpty()) {
|
|
|
|
// Build a URL to get the filename extension
|
|
|
|
nsCOMPtr<nsIURL> imageURL = do_QueryInterface(sourceURI, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoCString extension;
|
|
|
|
rv = imageURL->GetFileExtension(extension);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 mimeCString(imageRequestMime);
|
|
|
|
bool isValidExtension;
|
|
|
|
nsAutoCString primaryExtension;
|
|
|
|
rv = CheckAndGetExtensionForMime(extension,
|
|
|
|
mimeCString,
|
|
|
|
&isValidExtension,
|
|
|
|
&primaryExtension);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!isValidExtension) {
|
|
|
|
// The filename extension is missing or incompatible
|
|
|
|
// with the MIME type, replace it with the primary
|
|
|
|
// extension.
|
|
|
|
nsAutoCString newFileName;
|
|
|
|
rv = imageURL->GetFileBaseName(newFileName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
newFileName.Append(".");
|
|
|
|
newFileName.Append(primaryExtension);
|
|
|
|
targetFilename = NS_ConvertUTF8toUTF16(newFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// make the filename safe for the filesystem
|
|
|
|
targetFilename.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS,
|
|
|
|
'-');
|
|
|
|
#endif /* defined(XP_MACOSX) */
|
|
|
|
|
2018-03-26 23:53:06 +03:00
|
|
|
// get the target directory from the kFilePromiseDirectoryMime
|
|
|
|
// flavor
|
|
|
|
nsCOMPtr<nsISupports> dirPrimitive;
|
|
|
|
dataSize = 0;
|
|
|
|
aTransferable->GetTransferData(kFilePromiseDirectoryMime,
|
|
|
|
getter_AddRefs(dirPrimitive), &dataSize);
|
|
|
|
nsCOMPtr<nsIFile> destDirectory = do_QueryInterface(dirPrimitive);
|
|
|
|
if (!destDirectory)
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-02-18 22:18:20 +03:00
|
|
|
|
2018-03-26 23:53:06 +03:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = destDirectory->Clone(getter_AddRefs(file));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-18 22:18:20 +03:00
|
|
|
|
2018-03-26 23:53:06 +03:00
|
|
|
file->Append(targetFilename);
|
2005-02-18 22:18:20 +03:00
|
|
|
|
2018-03-26 23:53:06 +03:00
|
|
|
bool isPrivate;
|
|
|
|
aTransferable->GetIsPrivateData(&isPrivate);
|
2012-10-04 23:07:51 +04:00
|
|
|
|
2018-03-28 00:55:33 +03:00
|
|
|
rv = SaveURIToFile(sourceURI, file, isPrivate);
|
2018-03-26 23:53:06 +03:00
|
|
|
// send back an nsIFile
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
CallQueryInterface(file, aData);
|
|
|
|
*aDataLen = sizeof(nsIFile*);
|
2003-06-18 02:35:01 +04:00
|
|
|
}
|
|
|
|
}
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2003-06-18 02:35:01 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
DragDataProducer::DragDataProducer(nsPIDOMWindowOuter* aWindow,
|
2010-04-18 22:27:18 +04:00
|
|
|
nsIContent* aTarget,
|
|
|
|
nsIContent* aSelectionTargetNode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsAltKeyPressed)
|
2008-08-27 16:07:27 +04:00
|
|
|
: mWindow(aWindow),
|
|
|
|
mTarget(aTarget),
|
|
|
|
mSelectionTargetNode(aSelectionTargetNode),
|
2010-04-18 22:27:18 +04:00
|
|
|
mIsAltKeyPressed(aIsAltKeyPressed),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnchor(false)
|
2003-06-18 02:26:07 +04:00
|
|
|
{
|
|
|
|
}
|
2002-02-17 22:28:13 +03:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2002-04-01 08:27:50 +04:00
|
|
|
// FindParentLinkNode
|
2002-02-17 22:28:13 +03:00
|
|
|
//
|
2004-07-30 10:04:57 +04:00
|
|
|
// Finds the parent with the given link tag starting at |inNode|. If
|
|
|
|
// it gets up to the root without finding it, we stop looking and
|
|
|
|
// return null.
|
2002-02-17 22:28:13 +03:00
|
|
|
//
|
2008-08-27 16:07:27 +04:00
|
|
|
already_AddRefed<nsIContent>
|
2010-04-18 22:27:18 +04:00
|
|
|
DragDataProducer::FindParentLinkNode(nsIContent* inNode)
|
2002-02-17 22:28:13 +03:00
|
|
|
{
|
2008-08-27 16:07:27 +04:00
|
|
|
nsIContent* content = inNode;
|
2004-07-30 10:04:57 +04:00
|
|
|
if (!content) {
|
|
|
|
// That must have been the document node; nothing else to do here;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2004-07-30 10:04:57 +04:00
|
|
|
}
|
2002-04-01 08:27:50 +04:00
|
|
|
|
2005-03-17 21:00:33 +03:00
|
|
|
for (; content; content = content->GetParent()) {
|
2004-07-30 10:04:57 +04:00
|
|
|
if (nsContentUtils::IsDraggableLink(content)) {
|
2013-04-22 15:15:59 +04:00
|
|
|
nsCOMPtr<nsIContent> ret = content;
|
|
|
|
return ret.forget();
|
2002-02-17 22:28:13 +03:00
|
|
|
}
|
|
|
|
}
|
2004-07-30 20:07:07 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2002-02-17 22:28:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// GetAnchorURL
|
|
|
|
//
|
2016-09-08 07:17:58 +03:00
|
|
|
nsresult
|
2010-04-18 22:27:18 +04:00
|
|
|
DragDataProducer::GetAnchorURL(nsIContent* inNode, nsAString& outURL)
|
2002-02-17 22:28:13 +03:00
|
|
|
{
|
2007-01-04 13:53:59 +03:00
|
|
|
nsCOMPtr<nsIURI> linkURI;
|
2008-08-27 16:07:27 +04:00
|
|
|
if (!inNode || !inNode->IsLink(getter_AddRefs(linkURI))) {
|
2004-07-30 10:04:57 +04:00
|
|
|
// Not a link
|
2007-01-04 13:53:59 +03:00
|
|
|
outURL.Truncate();
|
2016-09-08 07:17:58 +03:00
|
|
|
return NS_OK;
|
2002-02-17 22:28:13 +03:00
|
|
|
}
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2016-09-08 07:17:58 +03:00
|
|
|
nsresult rv = linkURI->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-07-30 10:04:57 +04:00
|
|
|
CopyUTF8toUTF16(spec, outURL);
|
2016-09-08 07:17:58 +03:00
|
|
|
return NS_OK;
|
2002-02-17 22:28:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CreateLinkText
|
|
|
|
//
|
|
|
|
// Creates the html for an anchor in the form
|
|
|
|
// <a href="inURL">inText</a>
|
2005-03-17 21:00:33 +03:00
|
|
|
//
|
2002-02-17 22:28:13 +03:00
|
|
|
void
|
2010-04-18 22:27:18 +04:00
|
|
|
DragDataProducer::CreateLinkText(const nsAString& inURL,
|
|
|
|
const nsAString & inText,
|
|
|
|
nsAString& outLinkText)
|
2002-02-17 22:28:13 +03:00
|
|
|
{
|
2005-03-17 21:00:33 +03:00
|
|
|
// use a temp var in case |inText| is the same string as
|
|
|
|
// |outLinkText| to avoid overwriting it while building up the
|
|
|
|
// string in pieces.
|
2002-04-01 08:27:50 +04:00
|
|
|
nsAutoString linkText(NS_LITERAL_STRING("<a href=\"") +
|
|
|
|
inURL +
|
|
|
|
NS_LITERAL_STRING("\">") +
|
|
|
|
inText +
|
|
|
|
NS_LITERAL_STRING("</a>") );
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2002-02-17 22:28:13 +03:00
|
|
|
outLinkText = linkText;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// GetNodeString
|
|
|
|
//
|
|
|
|
// Gets the text associated with a node
|
|
|
|
//
|
|
|
|
void
|
2010-04-18 22:27:18 +04:00
|
|
|
DragDataProducer::GetNodeString(nsIContent* inNode,
|
|
|
|
nsAString & outNodeString)
|
2002-02-17 22:28:13 +03:00
|
|
|
{
|
2014-01-15 18:26:51 +04:00
|
|
|
nsCOMPtr<nsINode> node = inNode;
|
2008-08-27 16:07:27 +04:00
|
|
|
|
2002-04-01 08:27:50 +04:00
|
|
|
outNodeString.Truncate();
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2002-02-17 22:28:13 +03:00
|
|
|
// use a range to get the text-equivalent of the node
|
2014-01-15 18:26:51 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = node->OwnerDoc();
|
2018-02-01 22:21:14 +03:00
|
|
|
RefPtr<nsRange> range = doc->CreateRange(IgnoreErrors());
|
2014-01-15 18:26:51 +04:00
|
|
|
if (range) {
|
2018-02-01 22:21:14 +03:00
|
|
|
range->SelectNode(*node, IgnoreErrors());
|
2018-03-27 07:35:22 +03:00
|
|
|
range->ToString(outNodeString, IgnoreErrors());
|
2002-02-17 22:28:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 00:55:33 +03:00
|
|
|
nsresult
|
|
|
|
DragDataProducer::GetImageData(imgIContainer* aImage, imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> imgUri;
|
|
|
|
aRequest->GetURI(getter_AddRefs(imgUri));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> imgUrl(do_QueryInterface(imgUri));
|
|
|
|
if (imgUrl) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
nsresult rv = imgUrl->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// pass out the image source string
|
|
|
|
CopyUTF8toUTF16(spec, mImageSourceString);
|
|
|
|
|
|
|
|
nsCString mimeType;
|
|
|
|
aRequest->GetMimeType(getter_Copies(mimeType));
|
|
|
|
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// Save the MIME type so we can make sure the extension
|
|
|
|
// is compatible (and replace it if it isn't) when the
|
|
|
|
// image is dropped. On Mac, we need to get the OS MIME
|
|
|
|
// handler information in the parent due to sandboxing.
|
|
|
|
CopyUTF8toUTF16(mimeType, mImageRequestMime);
|
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIMIMEService> mimeService = do_GetService("@mozilla.org/mime;1");
|
|
|
|
if (NS_WARN_IF(!mimeService)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMIMEInfo> mimeInfo;
|
|
|
|
mimeService->GetFromTypeAndExtension(mimeType, EmptyCString(),
|
|
|
|
getter_AddRefs(mimeInfo));
|
|
|
|
if (mimeInfo) {
|
|
|
|
nsAutoCString extension;
|
|
|
|
imgUrl->GetFileExtension(extension);
|
|
|
|
|
|
|
|
bool validExtension;
|
|
|
|
if (extension.IsEmpty() ||
|
|
|
|
NS_FAILED(mimeInfo->ExtensionExists(extension,
|
|
|
|
&validExtension)) ||
|
|
|
|
!validExtension) {
|
|
|
|
// Fix the file extension in the URL
|
|
|
|
nsAutoCString primaryExtension;
|
|
|
|
mimeInfo->GetPrimaryExtension(primaryExtension);
|
|
|
|
|
|
|
|
rv = NS_MutateURI(imgUrl)
|
|
|
|
.Apply(NS_MutatorMethod(&nsIURLMutator::SetFileExtension,
|
|
|
|
primaryExtension, nullptr))
|
|
|
|
.Finalize(imgUrl);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* defined(XP_MACOSX) */
|
|
|
|
|
|
|
|
nsAutoCString fileName;
|
|
|
|
imgUrl->GetFileName(fileName);
|
|
|
|
|
|
|
|
NS_UnescapeURL(fileName);
|
|
|
|
|
|
|
|
#if !defined(XP_MACOSX)
|
|
|
|
// make the filename safe for the filesystem
|
|
|
|
fileName.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '-');
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CopyUTF8toUTF16(fileName, mImageDestFileName);
|
|
|
|
|
|
|
|
// and the image object
|
|
|
|
mImage = aImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-18 02:26:07 +04:00
|
|
|
nsresult
|
2013-08-12 18:45:33 +04:00
|
|
|
DragDataProducer::Produce(DataTransfer* aDataTransfer,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aCanDrag,
|
2012-02-17 18:16:59 +04:00
|
|
|
nsISelection** aSelection,
|
2018-02-09 04:43:53 +03:00
|
|
|
nsIContent** aDragNode,
|
|
|
|
nsACString& aPrincipalURISpec)
|
2002-02-17 22:28:13 +03:00
|
|
|
{
|
2012-02-17 18:16:59 +04:00
|
|
|
NS_PRECONDITION(aCanDrag && aSelection && aDataTransfer && aDragNode,
|
2008-08-27 16:07:27 +04:00
|
|
|
"null pointer passed to Produce");
|
|
|
|
NS_ASSERTION(mWindow, "window not set");
|
|
|
|
NS_ASSERTION(mSelectionTargetNode, "selection target node should have been set");
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDragNode = nullptr;
|
2002-02-17 22:28:13 +03:00
|
|
|
|
2010-05-25 03:24:15 +04:00
|
|
|
nsresult rv;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIContent* dragNode = nullptr;
|
|
|
|
*aSelection = nullptr;
|
2002-02-17 22:28:13 +03:00
|
|
|
|
2012-02-17 18:16:59 +04:00
|
|
|
// Find the selection to see what we could be dragging and if what we're
|
|
|
|
// dragging is in what is selected. If this is an editable textbox, use
|
|
|
|
// the textbox's selection, otherwise use the window's selection.
|
2003-04-11 01:21:15 +04:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
2012-02-17 18:16:59 +04:00
|
|
|
nsIContent* editingElement = mSelectionTargetNode->IsEditable() ?
|
2012-07-30 18:20:58 +04:00
|
|
|
mSelectionTargetNode->GetEditingHost() : nullptr;
|
2010-11-16 23:45:49 +03:00
|
|
|
nsCOMPtr<nsITextControlElement> textControl =
|
|
|
|
nsITextControlElement::GetTextControlElementFromEditingHost(editingElement);
|
2012-02-17 18:16:59 +04:00
|
|
|
if (textControl) {
|
|
|
|
nsISelectionController* selcon = textControl->GetSelectionController();
|
|
|
|
if (selcon) {
|
|
|
|
selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
|
|
|
|
}
|
2012-02-29 00:33:30 +04:00
|
|
|
|
|
|
|
if (!selection)
|
|
|
|
return NS_OK;
|
2005-03-17 21:00:33 +03:00
|
|
|
}
|
2012-02-17 18:16:59 +04:00
|
|
|
else {
|
2015-10-27 00:37:32 +03:00
|
|
|
selection = mWindow->GetSelection();
|
2012-02-17 18:16:59 +04:00
|
|
|
if (!selection)
|
2008-08-27 16:07:27 +04:00
|
|
|
return NS_OK;
|
2012-02-17 18:16:59 +04:00
|
|
|
|
|
|
|
// Check if the node is inside a form control. Don't set aCanDrag to false
|
|
|
|
//however, as we still want to allow the drag.
|
|
|
|
nsCOMPtr<nsIContent> findFormNode = mSelectionTargetNode;
|
|
|
|
nsIContent* findFormParent = findFormNode->GetParent();
|
|
|
|
while (findFormParent) {
|
|
|
|
nsCOMPtr<nsIFormControl> form(do_QueryInterface(findFormParent));
|
|
|
|
if (form && !form->AllowDraggableChildren()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
findFormParent = findFormParent->GetParent();
|
2011-03-24 17:55:32 +03:00
|
|
|
}
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2005-03-17 21:00:33 +03:00
|
|
|
// if set, serialize the content under this node
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIContent> nodeToSerialize;
|
2003-04-11 01:21:15 +04:00
|
|
|
|
2014-01-10 06:03:47 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = mWindow->GetDocShell();
|
2014-01-20 11:58:26 +04:00
|
|
|
const bool isChromeShell =
|
|
|
|
dsti && dsti->ItemType() == nsIDocShellTreeItem::typeChrome;
|
2012-02-17 18:16:59 +04:00
|
|
|
|
|
|
|
// In chrome shells, only allow dragging inside editable areas.
|
2015-04-08 21:48:11 +03:00
|
|
|
if (isChromeShell && !editingElement) {
|
|
|
|
nsCOMPtr<nsIFrameLoaderOwner> flo = do_QueryInterface(mTarget);
|
|
|
|
if (flo) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameLoader> fl = flo->GetFrameLoader();
|
2015-04-08 21:48:11 +03:00
|
|
|
if (fl) {
|
|
|
|
TabParent* tp = static_cast<TabParent*>(fl->GetRemoteBrowser());
|
|
|
|
if (tp) {
|
|
|
|
// We have a TabParent, so it may have data for dnd in case the child
|
|
|
|
// process started a dnd session.
|
2018-02-09 04:43:53 +03:00
|
|
|
tp->AddInitialDnDDataTo(aDataTransfer, aPrincipalURISpec);
|
2015-04-08 21:48:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-17 18:16:59 +04:00
|
|
|
return NS_OK;
|
2015-04-08 21:48:11 +03:00
|
|
|
}
|
2012-02-17 18:16:59 +04:00
|
|
|
|
|
|
|
if (isChromeShell && textControl) {
|
2012-02-29 00:33:30 +04:00
|
|
|
// Only use the selection if the target node is in the selection.
|
|
|
|
bool selectionContainsTarget = false;
|
|
|
|
nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(mSelectionTargetNode);
|
|
|
|
selection->ContainsNode(targetNode, false, &selectionContainsTarget);
|
|
|
|
if (!selectionContainsTarget)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
selection.swap(*aSelection);
|
2012-02-17 18:16:59 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// In content shells, a number of checks are made below to determine
|
|
|
|
// whether an image or a link is being dragged. If so, add additional
|
|
|
|
// data to the data transfer. This is also done for chrome shells, but
|
|
|
|
// only when in a non-textbox editor.
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveSelectedContent = false;
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2005-03-17 21:00:33 +03:00
|
|
|
// possible parent link node
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIContent> parentLink;
|
|
|
|
nsCOMPtr<nsIContent> draggedNode;
|
2003-06-18 02:26:07 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
// only drag form elements by using the alt key,
|
|
|
|
// otherwise buttons and select widgets are hard to use
|
2004-07-30 10:04:57 +04:00
|
|
|
|
|
|
|
// Note that while <object> elements implement nsIFormControl, we should
|
|
|
|
// really allow dragging them if they happen to be images.
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIFormControl> form(do_QueryInterface(mTarget));
|
2017-04-01 05:49:00 +03:00
|
|
|
if (form && !mIsAltKeyPressed && form->ControlType() != NS_FORM_OBJECT) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanDrag = false;
|
2003-06-18 02:26:07 +04:00
|
|
|
return NS_OK;
|
2005-03-17 21:00:33 +03:00
|
|
|
}
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
draggedNode = mTarget;
|
2002-12-20 18:37:03 +03:00
|
|
|
}
|
|
|
|
|
2004-07-30 10:04:57 +04:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> image;
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIContent> selectedImageOrLinkNode;
|
|
|
|
GetDraggableSelectionData(selection, mSelectionTargetNode,
|
|
|
|
getter_AddRefs(selectedImageOrLinkNode),
|
|
|
|
&haveSelectedContent);
|
|
|
|
|
|
|
|
// either plain text or anchor text is selected
|
|
|
|
if (haveSelectedContent) {
|
2012-02-17 18:16:59 +04:00
|
|
|
selection.swap(*aSelection);
|
2008-08-27 16:07:27 +04:00
|
|
|
} else if (selectedImageOrLinkNode) {
|
|
|
|
// an image is selected
|
|
|
|
image = do_QueryInterface(selectedImageOrLinkNode);
|
|
|
|
} else {
|
|
|
|
// nothing is selected -
|
|
|
|
//
|
|
|
|
// look for draggable elements under the mouse
|
|
|
|
//
|
|
|
|
// if the alt key is down, don't start a drag if we're in an
|
|
|
|
// anchor because we want to do selection.
|
|
|
|
parentLink = FindParentLinkNode(draggedNode);
|
|
|
|
if (parentLink && mIsAltKeyPressed) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanDrag = false;
|
2008-08-27 16:07:27 +04:00
|
|
|
return NS_OK;
|
2008-08-25 19:08:28 +04:00
|
|
|
}
|
2008-08-27 16:07:27 +04:00
|
|
|
image = do_QueryInterface(draggedNode);
|
2003-06-18 02:26:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2005-03-17 21:00:33 +03:00
|
|
|
// set for linked images, and links
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIContent> linkNode;
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
RefPtr<HTMLAreaElement> areaElem = HTMLAreaElement::FromNodeOrNull(draggedNode);
|
2017-09-23 00:56:51 +03:00
|
|
|
if (areaElem) {
|
2003-06-18 02:26:07 +04:00
|
|
|
// use the alt text (or, if missing, the href) as the title
|
2013-08-08 00:23:08 +04:00
|
|
|
areaElem->GetAttribute(NS_LITERAL_STRING("alt"), mTitleString);
|
2005-03-17 21:00:33 +03:00
|
|
|
if (mTitleString.IsEmpty()) {
|
|
|
|
// this can be a relative link
|
2013-08-08 00:23:08 +04:00
|
|
|
areaElem->GetAttribute(NS_LITERAL_STRING("href"), mTitleString);
|
2005-03-17 21:00:33 +03:00
|
|
|
}
|
2003-06-18 02:26:07 +04:00
|
|
|
|
|
|
|
// we'll generate HTML like <a href="absurl">alt text</a>
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnchor = true;
|
2005-03-17 21:00:33 +03:00
|
|
|
|
|
|
|
// gives an absolute link
|
2016-09-08 07:17:58 +03:00
|
|
|
nsresult rv = GetAnchorURL(draggedNode, mUrlString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
mHtmlString.AssignLiteral("<a href=\"");
|
2003-06-18 02:26:07 +04:00
|
|
|
mHtmlString.Append(mUrlString);
|
2004-06-17 04:13:25 +04:00
|
|
|
mHtmlString.AppendLiteral("\">");
|
2003-06-18 02:26:07 +04:00
|
|
|
mHtmlString.Append(mTitleString);
|
2004-06-17 04:13:25 +04:00
|
|
|
mHtmlString.AppendLiteral("</a>");
|
2008-08-27 16:07:27 +04:00
|
|
|
|
|
|
|
dragNode = draggedNode;
|
2005-03-17 21:00:33 +03:00
|
|
|
} else if (image) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnchor = true;
|
2005-03-17 21:00:33 +03:00
|
|
|
// grab the href as the url, use alt text as the title of the
|
|
|
|
// area if it's there. the drag data is the image tag and src
|
|
|
|
// attribute.
|
2015-08-20 19:45:18 +03:00
|
|
|
nsCOMPtr<nsIURI> imageURI;
|
|
|
|
image->GetCurrentURI(getter_AddRefs(imageURI));
|
|
|
|
if (imageURI) {
|
|
|
|
nsAutoCString spec;
|
2016-09-08 07:17:58 +03:00
|
|
|
rv = imageURI->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-08-20 19:45:18 +03:00
|
|
|
CopyUTF8toUTF16(spec, mUrlString);
|
|
|
|
}
|
|
|
|
|
2018-01-30 07:28:00 +03:00
|
|
|
nsCOMPtr<Element> imageElement(do_QueryInterface(image));
|
2004-07-30 10:04:57 +04:00
|
|
|
// XXXbz Shouldn't we use the "title" attr for title? Using
|
|
|
|
// "alt" seems very wrong....
|
2018-01-30 07:28:00 +03:00
|
|
|
// XXXbz Also, what if this is an nsIImageLoadingContent
|
|
|
|
// that's not an <html:img>?
|
2004-07-30 10:04:57 +04:00
|
|
|
if (imageElement) {
|
|
|
|
imageElement->GetAttribute(NS_LITERAL_STRING("alt"), mTitleString);
|
|
|
|
}
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2015-08-20 19:45:18 +03:00
|
|
|
if (mTitleString.IsEmpty()) {
|
|
|
|
mTitleString = mUrlString;
|
|
|
|
}
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2014-11-11 01:06:24 +03:00
|
|
|
nsCOMPtr<imgIRequest> imgRequest;
|
2015-08-20 19:45:18 +03:00
|
|
|
|
|
|
|
// grab the image data, and its request.
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
nsCOMPtr<imgIContainer> img =
|
2005-02-08 01:20:14 +03:00
|
|
|
nsContentUtils::GetImageFromContent(image,
|
|
|
|
getter_AddRefs(imgRequest));
|
2018-03-28 00:55:33 +03:00
|
|
|
if (imgRequest) {
|
|
|
|
rv = GetImageData(img, imgRequest);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-08 01:20:14 +03:00
|
|
|
}
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2005-03-17 21:00:33 +03:00
|
|
|
if (parentLink) {
|
2003-06-18 02:26:07 +04:00
|
|
|
// If we are dragging around an image in an anchor, then we
|
|
|
|
// are dragging the entire anchor
|
|
|
|
linkNode = parentLink;
|
|
|
|
nodeToSerialize = linkNode;
|
2005-03-17 21:00:33 +03:00
|
|
|
} else {
|
2008-08-27 16:07:27 +04:00
|
|
|
nodeToSerialize = do_QueryInterface(draggedNode);
|
2005-03-17 21:00:33 +03:00
|
|
|
}
|
2008-08-27 16:07:27 +04:00
|
|
|
dragNode = nodeToSerialize;
|
2017-09-23 00:56:51 +03:00
|
|
|
} else if (draggedNode && draggedNode->IsHTMLElement(nsGkAtoms::a)) {
|
2003-06-18 02:26:07 +04:00
|
|
|
// set linkNode. The code below will handle this
|
2017-09-23 00:56:51 +03:00
|
|
|
linkNode = do_QueryInterface(draggedNode); // XXX test this
|
2003-06-18 02:26:07 +04:00
|
|
|
GetNodeString(draggedNode, mTitleString);
|
2005-03-17 21:00:33 +03:00
|
|
|
} else if (parentLink) {
|
2004-04-23 17:52:50 +04:00
|
|
|
// parentLink will always be null if there's selected content
|
2003-06-18 02:26:07 +04:00
|
|
|
linkNode = parentLink;
|
|
|
|
nodeToSerialize = linkNode;
|
2005-03-17 21:00:33 +03:00
|
|
|
} else if (!haveSelectedContent) {
|
2003-06-18 02:26:07 +04:00
|
|
|
// nothing draggable
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-17 21:00:33 +03:00
|
|
|
if (linkNode) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnchor = true;
|
2016-09-08 07:17:58 +03:00
|
|
|
rv = GetAnchorURL(linkNode, mUrlString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-08-27 16:07:27 +04:00
|
|
|
dragNode = linkNode;
|
2003-06-18 02:26:07 +04:00
|
|
|
}
|
|
|
|
}
|
2003-04-11 01:21:15 +04:00
|
|
|
}
|
2003-06-18 02:26:07 +04:00
|
|
|
|
2012-02-17 18:16:59 +04:00
|
|
|
if (nodeToSerialize || *aSelection) {
|
2010-05-25 03:24:15 +04:00
|
|
|
mHtmlString.Truncate();
|
|
|
|
mContextString.Truncate();
|
|
|
|
mInfoString.Truncate();
|
|
|
|
mTitleString.Truncate();
|
2012-02-17 18:16:59 +04:00
|
|
|
|
2012-08-04 11:44:01 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetDoc();
|
2012-02-17 18:16:59 +04:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// if we have selected text, use it in preference to the node
|
2010-05-25 03:24:15 +04:00
|
|
|
nsCOMPtr<nsITransferable> transferable;
|
2012-02-17 18:16:59 +04:00
|
|
|
if (*aSelection) {
|
|
|
|
rv = nsCopySupport::GetTransferableForSelection(*aSelection, doc,
|
|
|
|
getter_AddRefs(transferable));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = nsCopySupport::GetTransferableForNode(nodeToSerialize, doc,
|
|
|
|
getter_AddRefs(transferable));
|
|
|
|
}
|
2012-02-24 00:59:45 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-02-17 18:16:59 +04:00
|
|
|
|
2014-03-15 23:00:17 +04:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
2010-05-25 03:24:15 +04:00
|
|
|
nsCOMPtr<nsISupportsString> data;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dataSize;
|
2014-03-15 23:00:17 +04:00
|
|
|
rv = transferable->GetTransferData(kHTMLMime, getter_AddRefs(supports),
|
|
|
|
&dataSize);
|
|
|
|
data = do_QueryInterface(supports);
|
2010-05-25 03:24:15 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
data->GetData(mHtmlString);
|
|
|
|
}
|
2014-03-15 23:00:17 +04:00
|
|
|
rv = transferable->GetTransferData(kHTMLContext, getter_AddRefs(supports),
|
|
|
|
&dataSize);
|
|
|
|
data = do_QueryInterface(supports);
|
2010-05-25 03:24:15 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
data->GetData(mContextString);
|
|
|
|
}
|
2014-03-15 23:00:17 +04:00
|
|
|
rv = transferable->GetTransferData(kHTMLInfo, getter_AddRefs(supports),
|
|
|
|
&dataSize);
|
|
|
|
data = do_QueryInterface(supports);
|
2010-05-25 03:24:15 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
data->GetData(mInfoString);
|
|
|
|
}
|
2014-03-15 23:00:17 +04:00
|
|
|
rv = transferable->GetTransferData(kUnicodeMime, getter_AddRefs(supports),
|
|
|
|
&dataSize);
|
|
|
|
data = do_QueryInterface(supports);
|
2010-05-25 03:24:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv); // require plain text at a minimum
|
|
|
|
data->GetData(mTitleString);
|
2003-04-11 01:21:15 +04:00
|
|
|
}
|
|
|
|
|
2003-06-18 02:26:07 +04:00
|
|
|
// default text value is the URL
|
2005-03-17 21:00:33 +03:00
|
|
|
if (mTitleString.IsEmpty()) {
|
2003-06-18 02:26:07 +04:00
|
|
|
mTitleString = mUrlString;
|
2005-03-17 21:00:33 +03:00
|
|
|
}
|
2002-02-17 22:28:13 +03:00
|
|
|
|
2003-06-18 02:26:07 +04:00
|
|
|
// if we haven't constructed a html version, make one now
|
|
|
|
if (mHtmlString.IsEmpty() && !mUrlString.IsEmpty())
|
|
|
|
CreateLinkText(mUrlString, mTitleString, mHtmlString);
|
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
// if there is no drag node, which will be the case for a selection, just
|
|
|
|
// use the selection target node.
|
2010-05-25 03:24:15 +04:00
|
|
|
rv = AddStringsToDataTransfer(
|
|
|
|
dragNode ? dragNode : mSelectionTargetNode.get(), aDataTransfer);
|
2008-08-27 16:07:27 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aDragNode = dragNode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-12 18:45:33 +04:00
|
|
|
DragDataProducer::AddString(DataTransfer* aDataTransfer,
|
2010-04-18 22:27:18 +04:00
|
|
|
const nsAString& aFlavor,
|
|
|
|
const nsAString& aData,
|
2018-03-28 00:55:33 +03:00
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
bool aHidden)
|
2008-08-27 16:07:27 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsVariantCC> variant = new nsVariantCC();
|
2015-10-07 18:17:42 +03:00
|
|
|
variant->SetAsAString(aData);
|
2018-03-28 00:55:33 +03:00
|
|
|
aDataTransfer->SetDataWithPrincipal(aFlavor, variant, 0, aPrincipal, aHidden);
|
2003-06-18 02:26:07 +04:00
|
|
|
}
|
2002-02-17 22:28:13 +03:00
|
|
|
|
|
|
|
nsresult
|
2010-04-18 22:27:18 +04:00
|
|
|
DragDataProducer::AddStringsToDataTransfer(nsIContent* aDragNode,
|
2013-08-12 18:45:33 +04:00
|
|
|
DataTransfer* aDataTransfer)
|
2002-02-17 22:28:13 +03:00
|
|
|
{
|
2008-08-27 16:07:27 +04:00
|
|
|
NS_ASSERTION(aDragNode, "adding strings for null node");
|
|
|
|
|
|
|
|
// set all of the data to have the principal of the node where the data came from
|
|
|
|
nsIPrincipal* principal = aDragNode->NodePrincipal();
|
2005-03-17 21:00:33 +03:00
|
|
|
|
|
|
|
// add a special flavor if we're an anchor to indicate that we have
|
|
|
|
// a URL in the drag data
|
|
|
|
if (!mUrlString.IsEmpty() && mIsAnchor) {
|
|
|
|
nsAutoString dragData(mUrlString);
|
2014-05-22 07:48:51 +04:00
|
|
|
dragData.Append('\n');
|
2014-01-09 01:04:58 +04:00
|
|
|
// Remove leading and trailing newlines in the title and replace them with
|
|
|
|
// space in remaining positions - they confuse PlacesUtils::unwrapNodes
|
|
|
|
// that expects url\ntitle formatted data for x-moz-url.
|
|
|
|
nsAutoString title(mTitleString);
|
|
|
|
title.Trim("\r\n");
|
|
|
|
title.ReplaceChar("\r\n", ' ');
|
|
|
|
dragData += title;
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kURLMime), dragData, principal);
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kURLDataMime), mUrlString, principal);
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kURLDescriptionMime), mTitleString, principal);
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING("text/uri-list"), mUrlString, principal);
|
2003-06-18 02:26:07 +04:00
|
|
|
}
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2012-02-17 18:16:59 +04:00
|
|
|
// add a special flavor for the html context data
|
|
|
|
if (!mContextString.IsEmpty())
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kHTMLContext), mContextString, principal);
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2003-06-18 02:26:07 +04:00
|
|
|
// add a special flavor if we have html info data
|
2008-08-27 16:07:27 +04:00
|
|
|
if (!mInfoString.IsEmpty())
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kHTMLInfo), mInfoString, principal);
|
2008-08-25 13:56:29 +04:00
|
|
|
|
2008-08-25 19:08:28 +04:00
|
|
|
// add the full html
|
2012-02-17 18:16:59 +04:00
|
|
|
if (!mHtmlString.IsEmpty())
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kHTMLMime), mHtmlString, principal);
|
2008-08-27 16:07:27 +04:00
|
|
|
|
|
|
|
// add the plain text. we use the url for text/plain data if an anchor is
|
|
|
|
// being dragged, rather than the title text of the link or the alt text for
|
|
|
|
// an anchor image.
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kTextMime),
|
|
|
|
mIsAnchor ? mUrlString : mTitleString, principal);
|
2005-03-17 21:00:33 +03:00
|
|
|
|
|
|
|
// add image data, if present. For now, all we're going to do with
|
|
|
|
// this is turn it into a native data flavor, so indicate that with
|
|
|
|
// a new flavor so as not to confuse anyone who is really registered
|
|
|
|
// for image/gif or image/jpg.
|
2003-06-18 02:26:07 +04:00
|
|
|
if (mImage) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsVariantCC> variant = new nsVariantCC();
|
2015-10-07 18:17:42 +03:00
|
|
|
variant->SetAsISupports(mImage);
|
|
|
|
aDataTransfer->SetDataWithPrincipal(NS_LITERAL_STRING(kNativeImageMime),
|
|
|
|
variant, 0, principal);
|
2005-03-17 21:00:33 +03:00
|
|
|
|
|
|
|
// assume the image comes from a file, and add a file promise. We
|
|
|
|
// register ourselves as a nsIFlavorDataProvider, and will use the
|
|
|
|
// GetFlavorData callback to save the image to disk.
|
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIFlavorDataProvider> dataProvider =
|
|
|
|
new nsContentAreaDragDropDataProvider();
|
|
|
|
if (dataProvider) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsVariantCC> variant = new nsVariantCC();
|
2015-10-07 18:17:42 +03:00
|
|
|
variant->SetAsISupports(dataProvider);
|
|
|
|
aDataTransfer->SetDataWithPrincipal(NS_LITERAL_STRING(kFilePromiseMime),
|
|
|
|
variant, 0, principal);
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
2008-08-25 19:08:28 +04:00
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kFilePromiseURLMime),
|
|
|
|
mImageSourceString, principal);
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kFilePromiseDestFilename),
|
|
|
|
mImageDestFileName, principal);
|
2018-03-28 00:55:33 +03:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kImageRequestMime),
|
|
|
|
mImageRequestMime, principal, /* aHidden= */ true);
|
|
|
|
#endif
|
2005-02-18 22:18:20 +03:00
|
|
|
|
2003-04-19 00:20:04 +04:00
|
|
|
// if not an anchor, add the image url
|
2005-03-17 21:00:33 +03:00
|
|
|
if (!mIsAnchor) {
|
2008-08-27 16:07:27 +04:00
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING(kURLDataMime), mUrlString, principal);
|
|
|
|
AddString(aDataTransfer, NS_LITERAL_STRING("text/uri-list"), mUrlString, principal);
|
2003-04-19 00:20:04 +04:00
|
|
|
}
|
2002-04-23 18:24:48 +04:00
|
|
|
}
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2002-02-17 22:28:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-11 01:21:15 +04:00
|
|
|
// note that this can return NS_OK, but a null out param (by design)
|
2005-03-17 21:00:33 +03:00
|
|
|
// static
|
|
|
|
nsresult
|
2010-04-18 22:27:18 +04:00
|
|
|
DragDataProducer::GetDraggableSelectionData(nsISelection* inSelection,
|
|
|
|
nsIContent* inRealTargetNode,
|
|
|
|
nsIContent **outImageOrLinkNode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* outDragSelectedText)
|
2003-04-11 01:21:15 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(inSelection);
|
|
|
|
NS_ENSURE_ARG(inRealTargetNode);
|
|
|
|
NS_ENSURE_ARG_POINTER(outImageOrLinkNode);
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*outImageOrLinkNode = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
*outDragSelectedText = false;
|
2003-04-11 01:21:15 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool selectionContainsTarget = false;
|
2003-04-11 01:21:15 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isCollapsed = false;
|
2003-04-11 01:21:15 +04:00
|
|
|
inSelection->GetIsCollapsed(&isCollapsed);
|
2005-03-17 21:00:33 +03:00
|
|
|
if (!isCollapsed) {
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> realTargetNode = do_QueryInterface(inRealTargetNode);
|
2011-10-17 18:59:28 +04:00
|
|
|
inSelection->ContainsNode(realTargetNode, false,
|
2005-03-17 21:00:33 +03:00
|
|
|
&selectionContainsTarget);
|
|
|
|
|
|
|
|
if (selectionContainsTarget) {
|
2003-04-11 01:21:15 +04:00
|
|
|
// track down the anchor node, if any, for the url
|
|
|
|
nsCOMPtr<nsIDOMNode> selectionStart;
|
|
|
|
inSelection->GetAnchorNode(getter_AddRefs(selectionStart));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> selectionEnd;
|
|
|
|
inSelection->GetFocusNode(getter_AddRefs(selectionEnd));
|
2005-03-17 21:00:33 +03:00
|
|
|
|
2003-04-11 01:21:15 +04:00
|
|
|
// look for a selection around a single node, like an image.
|
|
|
|
// in this case, drag the image, rather than a serialization of the HTML
|
|
|
|
// XXX generalize this to other draggable element types?
|
2005-03-17 21:00:33 +03:00
|
|
|
if (selectionStart == selectionEnd) {
|
2018-01-30 07:10:51 +03:00
|
|
|
nsCOMPtr<nsIContent> selStartContent = do_QueryInterface(selectionStart);
|
|
|
|
if (selStartContent && selStartContent->HasChildNodes()) {
|
2003-04-11 01:21:15 +04:00
|
|
|
// see if just one node is selected
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t anchorOffset, focusOffset;
|
2003-04-11 01:21:15 +04:00
|
|
|
inSelection->GetAnchorOffset(&anchorOffset);
|
|
|
|
inSelection->GetFocusOffset(&focusOffset);
|
2005-03-17 21:00:33 +03:00
|
|
|
if (abs(anchorOffset - focusOffset) == 1) {
|
2018-01-30 07:10:51 +03:00
|
|
|
int32_t childOffset =
|
|
|
|
(anchorOffset < focusOffset) ? anchorOffset : focusOffset;
|
|
|
|
nsIContent *childContent =
|
|
|
|
selStartContent->GetChildAt_Deprecated(childOffset);
|
|
|
|
// if we find an image, we'll fall into the node-dragging code,
|
|
|
|
// rather the the selection-dragging code
|
|
|
|
if (nsContentUtils::IsDraggableImage(childContent)) {
|
|
|
|
NS_ADDREF(*outImageOrLinkNode = childContent);
|
|
|
|
return NS_OK;
|
2003-04-11 01:21:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-23 17:52:50 +04:00
|
|
|
// indicate that a link or text is selected
|
2011-10-17 18:59:28 +04:00
|
|
|
*outDragSelectedText = true;
|
2003-04-11 01:21:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|