2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:21:17 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-01-28 20:13:07 +00:00
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-01-28 20:13:07 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2001-01-28 20:13:07 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 22:53:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-01-28 20:13:07 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:21:17 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 22:53:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:21:17 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 22:53:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:21:17 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 22:53:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
#include "mozilla/Util.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
|
|
|
|
#include "nsPlaintextEditor.h"
|
|
|
|
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
2004-02-11 21:31:53 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIFormControl.h"
|
2007-05-14 09:11:38 +00:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2001-12-06 06:57:03 +00:00
|
|
|
#include "nsIDOMNSEvent.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
#include "nsIDOMDragEvent.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
#include "nsISelection.h"
|
2003-04-25 21:05:32 +00:00
|
|
|
#include "nsCRT.h"
|
2004-11-24 22:48:45 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-03-20 15:21:41 +00:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2003-04-25 21:05:32 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
#include "nsIDOMRange.h"
|
2012-02-17 14:16:59 +00:00
|
|
|
#include "nsIDOMDOMStringList.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
#include "nsIDocumentEncoder.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
|
|
|
|
// Drag & Drop, Clipboard
|
|
|
|
#include "nsIClipboard.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsIDragService.h"
|
2011-08-26 07:43:49 +00:00
|
|
|
#include "nsIDOMUIEvent.h"
|
2010-03-19 18:32:13 +00:00
|
|
|
#include "nsCopySupport.h"
|
2012-02-17 14:16:59 +00:00
|
|
|
#include "nsITransferable.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
|
|
|
|
// Misc
|
|
|
|
#include "nsEditorUtils.h"
|
2006-03-14 17:12:41 +00:00
|
|
|
#include "nsContentCID.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsFrameSelection.h"
|
2007-07-26 04:14:33 +00:00
|
|
|
#include "nsEventDispatcher.h"
|
2011-09-15 19:32:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
NS_IMETHODIMP nsPlaintextEditor::PrepareTransferable(nsITransferable **transferable)
|
|
|
|
{
|
|
|
|
// Create generic Transferable for getting the data
|
2003-07-28 13:13:50 +00:00
|
|
|
nsresult rv = CallCreateInstance("@mozilla.org/widget/transferable;1", transferable);
|
2010-06-17 20:44:35 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
|
|
|
// Get the nsITransferable interface for getting the data from the clipboard
|
2009-03-27 06:50:03 +00:00
|
|
|
if (transferable) {
|
|
|
|
(*transferable)->AddDataFlavor(kUnicodeMime);
|
|
|
|
(*transferable)->AddDataFlavor(kMozTextInternal);
|
|
|
|
};
|
2001-01-28 20:13:07 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-25 21:05:32 +00:00
|
|
|
nsresult nsPlaintextEditor::InsertTextAt(const nsAString &aStringToInsert,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
|
|
|
PRInt32 aDestOffset,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aDoDeleteSelection)
|
2003-04-25 21:05:32 +00:00
|
|
|
{
|
|
|
|
if (aDestinationNode)
|
|
|
|
{
|
|
|
|
nsresult res;
|
|
|
|
nsCOMPtr<nsISelection>selection;
|
|
|
|
res = GetSelection(getter_AddRefs(selection));
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> targetNode = aDestinationNode;
|
|
|
|
PRInt32 targetOffset = aDestOffset;
|
|
|
|
|
|
|
|
if (aDoDeleteSelection)
|
|
|
|
{
|
|
|
|
// Use an auto tracker so that our drop point is correctly
|
|
|
|
// positioned after the delete.
|
|
|
|
nsAutoTrackDOMPoint tracker(mRangeUpdater, &targetNode, &targetOffset);
|
|
|
|
res = DeleteSelection(eNone);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = selection->Collapse(targetNode, targetOffset);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
return InsertText(aStringToInsert);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPlaintextEditor::InsertTextFromTransferable(nsITransferable *aTransferable,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
|
|
|
PRInt32 aDestOffset,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aDoDeleteSelection)
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
2012-03-27 01:36:44 +00:00
|
|
|
HandlingTrustedAction trusted(this);
|
2011-01-16 04:16:45 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
char* bestFlavor = nsnull;
|
|
|
|
nsCOMPtr<nsISupports> genericDataObj;
|
|
|
|
PRUint32 len = 0;
|
2003-07-28 13:13:50 +00:00
|
|
|
if (NS_SUCCEEDED(aTransferable->GetAnyTransferData(&bestFlavor, getter_AddRefs(genericDataObj), &len))
|
2009-03-27 06:50:03 +00:00
|
|
|
&& bestFlavor && (0 == nsCRT::strcmp(bestFlavor, kUnicodeMime) ||
|
|
|
|
0 == nsCRT::strcmp(bestFlavor, kMozTextInternal)))
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
|
|
|
nsAutoTxnsConserveSelection dontSpazMySelection(this);
|
2003-07-28 13:13:50 +00:00
|
|
|
nsCOMPtr<nsISupportsString> textDataObj ( do_QueryInterface(genericDataObj) );
|
|
|
|
if (textDataObj && len > 0)
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
2003-07-28 13:13:50 +00:00
|
|
|
nsAutoString stuffToPaste;
|
|
|
|
textDataObj->GetData(stuffToPaste);
|
|
|
|
NS_ASSERTION(stuffToPaste.Length() <= (len/2), "Invalid length!");
|
2011-09-15 19:32:42 +00:00
|
|
|
|
|
|
|
// Sanitize possible carriage returns in the string to be inserted
|
|
|
|
nsContentUtils::PlatformToDOMLineBreaks(stuffToPaste);
|
|
|
|
|
2003-07-28 13:13:50 +00:00
|
|
|
nsAutoEditBatch beginBatching(this);
|
|
|
|
rv = InsertTextAt(stuffToPaste, aDestinationNode, aDestOffset, aDoDeleteSelection);
|
2001-01-28 20:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-08 04:35:17 +00:00
|
|
|
NS_Free(bestFlavor);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
|
|
|
// Try to scroll the selection into view if the paste/drop succeeded
|
2008-02-28 15:28:37 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2011-10-17 14:59:28 +00:00
|
|
|
ScrollSelectionIntoView(false);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-02-17 14:16:59 +00:00
|
|
|
nsresult nsPlaintextEditor::InsertFromDataTransfer(nsIDOMDataTransfer *aDataTransfer,
|
|
|
|
PRInt32 aIndex,
|
|
|
|
nsIDOMDocument *aSourceDoc,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
|
|
|
PRInt32 aDestOffset,
|
|
|
|
bool aDoDeleteSelection)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIVariant> data;
|
|
|
|
aDataTransfer->MozGetDataAt(NS_LITERAL_STRING("text/plain"), aIndex,
|
|
|
|
getter_AddRefs(data));
|
2012-02-23 20:59:45 +00:00
|
|
|
if (data) {
|
|
|
|
nsAutoString insertText;
|
|
|
|
data->GetAsAString(insertText);
|
|
|
|
nsContentUtils::PlatformToDOMLineBreaks(insertText);
|
2012-02-17 14:16:59 +00:00
|
|
|
|
2012-02-23 20:59:45 +00:00
|
|
|
nsAutoEditBatch beginBatching(this);
|
|
|
|
return InsertTextAt(insertText, aDestinationNode, aDestOffset, aDoDeleteSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-02-17 14:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent)
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
|
|
|
ForceCompositionEnd();
|
|
|
|
|
2012-02-17 14:16:59 +00:00
|
|
|
nsCOMPtr<nsIDOMDragEvent> dragEvent(do_QueryInterface(aDropEvent));
|
|
|
|
NS_ENSURE_TRUE(dragEvent, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDataTransfer> dataTransfer;
|
|
|
|
nsresult rv = dragEvent->GetDataTransfer(getter_AddRefs(dataTransfer));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2012-03-20 15:21:41 +00:00
|
|
|
nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
|
|
|
|
NS_ASSERTION(dragSession, "No drag session");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aDropEvent));
|
|
|
|
nsDragEvent* dragEventInternal = static_cast<nsDragEvent *>(privateEvent->GetInternalNSEvent());
|
|
|
|
if (nsContentUtils::CheckForSubFrameDrop(dragSession, dragEventInternal)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-28 13:13:50 +00:00
|
|
|
// Current doc is destination
|
2012-03-24 08:19:14 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> destdomdoc = GetDOMDocument();
|
|
|
|
NS_ENSURE_TRUE(destdomdoc, NS_ERROR_NOT_INITIALIZED);
|
2003-07-28 13:13:50 +00:00
|
|
|
|
2012-02-17 14:16:59 +00:00
|
|
|
PRUint32 numItems = 0;
|
2012-02-17 14:16:59 +00:00
|
|
|
rv = dataTransfer->GetMozItemCount(&numItems);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-07-28 13:13:50 +00:00
|
|
|
if (numItems < 1) return NS_ERROR_FAILURE; // nothing to drop?
|
2001-01-28 20:13:07 +00:00
|
|
|
|
|
|
|
// Combine any deletion and drop insertion into one transaction
|
|
|
|
nsAutoEditBatch beginBatching(this);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool deleteSelection = false;
|
2003-07-28 13:13:50 +00:00
|
|
|
|
|
|
|
// We have to figure out whether to delete and relocate caret only once
|
|
|
|
// Parent and offset are under the mouse cursor
|
2011-08-26 07:43:49 +00:00
|
|
|
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aDropEvent);
|
|
|
|
NS_ENSURE_TRUE(uiEvent, NS_ERROR_FAILURE);
|
2003-07-28 13:13:50 +00:00
|
|
|
|
2003-04-25 21:05:32 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> newSelectionParent;
|
2011-08-26 07:43:49 +00:00
|
|
|
rv = uiEvent->GetRangeParent(getter_AddRefs(newSelectionParent));
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-17 19:41:16 +00:00
|
|
|
NS_ENSURE_TRUE(newSelectionParent, NS_ERROR_FAILURE);
|
2003-04-25 21:05:32 +00:00
|
|
|
|
2003-07-28 13:13:50 +00:00
|
|
|
PRInt32 newSelectionOffset;
|
2011-08-26 07:43:49 +00:00
|
|
|
rv = uiEvent->GetRangeOffset(&newSelectionOffset);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-07-28 13:13:50 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
rv = GetSelection(getter_AddRefs(selection));
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-17 19:41:16 +00:00
|
|
|
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
|
2003-07-28 13:13:50 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isCollapsed;
|
2003-07-28 13:13:50 +00:00
|
|
|
rv = selection->GetIsCollapsed(&isCollapsed);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-07-28 13:13:50 +00:00
|
|
|
|
2012-02-17 14:16:59 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> sourceNode;
|
|
|
|
dataTransfer->GetMozSourceNode(getter_AddRefs(sourceNode));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> srcdomdoc;
|
|
|
|
if (sourceNode) {
|
|
|
|
sourceNode->GetOwnerDocument(getter_AddRefs(srcdomdoc));
|
|
|
|
NS_ENSURE_TRUE(sourceNode, NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only the nsHTMLEditor::FindUserSelectAllNode returns a node.
|
|
|
|
nsCOMPtr<nsIDOMNode> userSelectNode = FindUserSelectAllNode(newSelectionParent);
|
|
|
|
if (userSelectNode)
|
|
|
|
{
|
|
|
|
// The drop is happening over a "-moz-user-select: all"
|
|
|
|
// subtree so make sure the content we insert goes before
|
|
|
|
// the root of the subtree.
|
|
|
|
//
|
|
|
|
// XXX: Note that inserting before the subtree matches the
|
|
|
|
// current behavior when dropping on top of an image.
|
|
|
|
// The decision for dropping before or after the
|
|
|
|
// subtree should really be done based on coordinates.
|
|
|
|
|
|
|
|
rv = GetNodeLocation(userSelectNode, address_of(newSelectionParent),
|
|
|
|
&newSelectionOffset);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(newSelectionParent, NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
2003-07-28 13:13:50 +00:00
|
|
|
// Check if mouse is in the selection
|
|
|
|
// if so, jump through some hoops to determine if mouse is over selection (bail)
|
|
|
|
// and whether user wants to copy selection or delete it
|
|
|
|
if (!isCollapsed)
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
2003-07-28 13:13:50 +00:00
|
|
|
// We never have to delete if selection is already collapsed
|
2011-09-29 06:19:26 +00:00
|
|
|
bool cursorIsInSelection = false;
|
2003-07-28 13:13:50 +00:00
|
|
|
|
|
|
|
PRInt32 rangeCount;
|
|
|
|
rv = selection->GetRangeCount(&rangeCount);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2003-07-28 13:13:50 +00:00
|
|
|
for (PRInt32 j = 0; j < rangeCount; j++)
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
2003-07-28 13:13:50 +00:00
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
rv = selection->GetRangeAt(j, getter_AddRefs(range));
|
2012-01-10 14:19:54 +00:00
|
|
|
if (NS_FAILED(rv) || !range)
|
2003-07-28 13:13:50 +00:00
|
|
|
continue; // don't bail yet, iterate through them all
|
|
|
|
|
2012-01-10 14:19:54 +00:00
|
|
|
rv = range->IsPointInRange(newSelectionParent, newSelectionOffset, &cursorIsInSelection);
|
2003-07-28 13:13:50 +00:00
|
|
|
if (cursorIsInSelection)
|
|
|
|
break;
|
|
|
|
}
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2003-07-28 13:13:50 +00:00
|
|
|
if (cursorIsInSelection)
|
|
|
|
{
|
|
|
|
// Dragging within same doc can't drop on itself -- leave!
|
|
|
|
if (srcdomdoc == destdomdoc)
|
|
|
|
return NS_OK;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2003-07-28 13:13:50 +00:00
|
|
|
// Dragging from another window onto a selection
|
|
|
|
// XXX Decision made to NOT do this,
|
|
|
|
// note that 4.x does replace if dropped on
|
2011-10-17 14:59:28 +00:00
|
|
|
//deleteSelection = true;
|
2003-07-28 13:13:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We are NOT over the selection
|
|
|
|
if (srcdomdoc == destdomdoc)
|
|
|
|
{
|
|
|
|
// Within the same doc: delete if user doesn't want to copy
|
2012-02-17 14:16:59 +00:00
|
|
|
PRUint32 dropEffect;
|
|
|
|
dataTransfer->GetDropEffectInt(&dropEffect);
|
|
|
|
deleteSelection = !(dropEffect & nsIDragService::DRAGDROP_ACTION_COPY);
|
2003-07-28 13:13:50 +00:00
|
|
|
}
|
|
|
|
else
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
2003-07-28 13:13:50 +00:00
|
|
|
// Different source doc: Don't delete
|
2011-10-17 14:59:28 +00:00
|
|
|
deleteSelection = false;
|
2001-01-28 20:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-28 13:13:50 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 14:16:59 +00:00
|
|
|
if (IsPlaintextEditor()) {
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(newSelectionParent);
|
|
|
|
while (content) {
|
|
|
|
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(content));
|
|
|
|
if (formControl && !formControl->AllowDrop()) {
|
|
|
|
// Don't allow dropping into a form control that doesn't allow being
|
|
|
|
// dropped into.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
content = content->GetParent();
|
2004-02-11 21:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-17 14:16:59 +00:00
|
|
|
for (PRUint32 i = 0; i < numItems; ++i) {
|
|
|
|
InsertFromDataTransfer(dataTransfer, i, srcdomdoc, newSelectionParent,
|
|
|
|
newSelectionOffset, deleteSelection);
|
2001-01-28 20:13:07 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 14:16:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
ScrollSelectionIntoView(false);
|
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPlaintextEditor::Paste(PRInt32 aSelectionType)
|
|
|
|
{
|
2010-03-19 18:32:13 +00:00
|
|
|
if (!FireClipboardEvent(NS_PASTE))
|
|
|
|
return NS_OK;
|
2007-07-26 04:14:33 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
// Get Clipboard Service
|
2010-03-19 18:32:13 +00:00
|
|
|
nsresult rv;
|
2003-07-08 20:22:56 +00:00
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
|
2001-01-28 20:13:07 +00:00
|
|
|
if ( NS_FAILED(rv) )
|
|
|
|
return rv;
|
2003-07-28 13:13:50 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
// Get the nsITransferable interface for getting the data from the clipboard
|
|
|
|
nsCOMPtr<nsITransferable> trans;
|
|
|
|
rv = PrepareTransferable(getter_AddRefs(trans));
|
|
|
|
if (NS_SUCCEEDED(rv) && trans)
|
|
|
|
{
|
|
|
|
// Get the Data from the clipboard
|
|
|
|
if (NS_SUCCEEDED(clipboard->GetData(trans, aSelectionType)) && IsModifiable())
|
|
|
|
{
|
2003-04-25 21:05:32 +00:00
|
|
|
// handle transferable hooks
|
2012-03-24 08:19:14 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc = GetDOMDocument();
|
2003-07-08 20:22:56 +00:00
|
|
|
if (!nsEditorHookUtils::DoInsertionHook(domdoc, nsnull, trans))
|
2003-04-25 21:05:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = InsertTextFromTransferable(trans, nsnull, nsnull, true);
|
2001-01-28 20:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-11 01:45:45 +00:00
|
|
|
NS_IMETHODIMP nsPlaintextEditor::PasteTransferable(nsITransferable *aTransferable)
|
|
|
|
{
|
2010-03-19 18:32:13 +00:00
|
|
|
if (!FireClipboardEvent(NS_PASTE))
|
|
|
|
return NS_OK;
|
2010-01-11 01:45:45 +00:00
|
|
|
|
|
|
|
if (!IsModifiable())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// handle transferable hooks
|
2012-03-24 08:19:14 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc = GetDOMDocument();
|
2010-01-11 01:45:45 +00:00
|
|
|
if (!nsEditorHookUtils::DoInsertionHook(domdoc, nsnull, aTransferable))
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return InsertTextFromTransferable(aTransferable, nsnull, nsnull, true);
|
2010-01-11 01:45:45 +00:00
|
|
|
}
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsPlaintextEditor::CanPaste(PRInt32 aSelectionType, bool *aCanPaste)
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
2007-07-26 04:14:33 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aCanPaste);
|
2011-10-17 14:59:28 +00:00
|
|
|
*aCanPaste = false;
|
2007-07-26 04:14:33 +00:00
|
|
|
|
2001-01-31 02:50:16 +00:00
|
|
|
// can't paste if readonly
|
|
|
|
if (!IsModifiable())
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-02-24 10:55:37 +00:00
|
|
|
nsresult rv;
|
2003-07-08 20:22:56 +00:00
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
|
|
|
// the flavors that we can deal with
|
2007-11-20 19:06:30 +00:00
|
|
|
const char* textEditorFlavors[] = { kUnicodeMime };
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool haveFlavors;
|
2007-11-20 19:06:30 +00:00
|
|
|
rv = clipboard->HasDataMatchingFlavors(textEditorFlavors,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(textEditorFlavors),
|
2007-11-20 19:06:30 +00:00
|
|
|
aSelectionType, &haveFlavors);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2001-04-07 00:45:26 +00:00
|
|
|
*aCanPaste = haveFlavors;
|
2001-01-28 20:13:07 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-04-17 13:18:51 +00:00
|
|
|
|
2010-01-11 01:45:45 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsPlaintextEditor::CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste)
|
2010-01-11 01:45:45 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCanPaste);
|
|
|
|
|
|
|
|
// can't paste if readonly
|
|
|
|
if (!IsModifiable()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aCanPaste = false;
|
2010-01-11 01:45:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If |aTransferable| is null, assume that a paste will succeed.
|
|
|
|
if (!aTransferable) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aCanPaste = true;
|
2010-01-11 01:45:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> data;
|
|
|
|
PRUint32 dataLen;
|
|
|
|
nsresult rv = aTransferable->GetTransferData(kUnicodeMime,
|
|
|
|
getter_AddRefs(data),
|
|
|
|
&dataLen);
|
|
|
|
if (NS_SUCCEEDED(rv) && data)
|
2011-10-17 14:59:28 +00:00
|
|
|
*aCanPaste = true;
|
2010-01-11 01:45:45 +00:00
|
|
|
else
|
2011-10-17 14:59:28 +00:00
|
|
|
*aCanPaste = false;
|
2010-01-11 01:45:45 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|