Backed out changeset bee6729280d8

This commit is contained in:
Josh Aas 2009-12-30 17:29:26 -05:00
Родитель 8917c60dff
Коммит b3e5cdbc41
18 изменённых файлов: 66 добавлений и 631 удалений

Просмотреть файл

@ -154,7 +154,6 @@
#endif
#include "nsIFocusController.h"
#include "nsIController.h"
#include "nsICommandParams.h"
#ifdef XP_MACOSX
#import <ApplicationServices/ApplicationServices.h>
@ -1345,7 +1344,6 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
case NS_CONTENT_COMMAND_DELETE:
case NS_CONTENT_COMMAND_UNDO:
case NS_CONTENT_COMMAND_REDO:
case NS_CONTENT_COMMAND_PASTE_TRANSFERABLE:
{
DoContentCommandEvent(static_cast<nsContentCommandEvent*>(aEvent));
}
@ -4548,9 +4546,6 @@ nsEventStateManager::DoContentCommandEvent(nsContentCommandEvent* aEvent)
case NS_CONTENT_COMMAND_REDO:
cmd = "cmd_redo";
break;
case NS_CONTENT_COMMAND_PASTE_TRANSFERABLE:
cmd = "cmd_pasteTransferable";
break;
default:
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -4567,25 +4562,7 @@ nsEventStateManager::DoContentCommandEvent(nsContentCommandEvent* aEvent)
NS_ENSURE_SUCCESS(rv, rv);
aEvent->mIsEnabled = canDoIt;
if (canDoIt && !aEvent->mOnlyEnabledCheck) {
switch (aEvent->message) {
case NS_CONTENT_COMMAND_PASTE_TRANSFERABLE: {
nsCOMPtr<nsICommandController> commandController = do_QueryInterface(controller);
NS_ENSURE_STATE(commandController);
nsCOMPtr<nsICommandParams> params = do_CreateInstance("@mozilla.org/embedcomp/command-params;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = params->SetISupportsValue("transferable", aEvent->mTransferable);
NS_ENSURE_SUCCESS(rv, rv);
rv = commandController->DoCommandWithParams(cmd, params);
break;
}
default:
rv = controller->DoCommand(cmd);
break;
}
rv = controller->DoCommand(cmd);
NS_ENSURE_SUCCESS(rv, rv);
}
}

Просмотреть файл

@ -946,47 +946,6 @@ nsDOMWindowUtils::DispatchDOMEventViaPresShell(nsIDOMNode* aTarget,
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::SendContentCommandEvent(const nsAString& aType,
nsITransferable * aTransferable)
{
PRBool hasCap = PR_FALSE;
if (NS_FAILED(nsContentUtils::GetSecurityManager()->IsCapabilityEnabled("UniversalXPConnect", &hasCap))
|| !hasCap)
return NS_ERROR_DOM_SECURITY_ERR;
// get the widget to send the event to
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget)
return NS_ERROR_FAILURE;
PRInt32 msg;
if (aType.EqualsLiteral("cut"))
msg = NS_CONTENT_COMMAND_CUT;
else if (aType.EqualsLiteral("copy"))
msg = NS_CONTENT_COMMAND_COPY;
else if (aType.EqualsLiteral("paste"))
msg = NS_CONTENT_COMMAND_PASTE;
else if (aType.EqualsLiteral("delete"))
msg = NS_CONTENT_COMMAND_DELETE;
else if (aType.EqualsLiteral("undo"))
msg = NS_CONTENT_COMMAND_UNDO;
else if (aType.EqualsLiteral("redo"))
msg = NS_CONTENT_COMMAND_REDO;
else if (aType.EqualsLiteral("pasteTransferable"))
msg = NS_CONTENT_COMMAND_PASTE_TRANSFERABLE;
else
return NS_ERROR_FAILURE;
nsContentCommandEvent event(PR_TRUE, msg, widget);
if (msg == NS_CONTENT_COMMAND_PASTE_TRANSFERABLE) {
event.mTransferable = aTransferable;
}
nsEventStatus status;
return widget->DispatchEvent(&event, status);
}
NS_IMETHODIMP
nsDOMWindowUtils::GetClassName(char **aName)
{

Просмотреть файл

@ -49,9 +49,8 @@ interface nsIDOMNode;
interface nsIDOMElement;
interface nsIDOMHTMLCanvasElement;
interface nsIDOMEvent;
interface nsITransferable;
[scriptable, uuid(5ab44028-20ed-499a-bbe4-1805a1f350c8)]
[scriptable, uuid(0e13d9a6-bcd1-4d61-9986-c32f78f99d1a)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -428,19 +427,4 @@ interface nsIDOMWindowUtils : nsISupports {
* wrapper) of aObj.
*/
string getClassName(/*in JSObjectPtr aObj*/);
/**
* Generate a content command event.
*
* Cannot be accessed from unprivileged context (not content-accessible)
* Will throw a DOM security error if called without UniversalXPConnect
* privileges.
*
* @param aType Type of command content event to send. Can be one of "cut",
* "copy", "paste", "delete", "undo", "redo", or "pasteTransferable".
* @param aTransferable an instance of nsITransferable when aType is
* "pasteTransferable"
*/
void sendContentCommandEvent(in AString aType,
[optional] in nsITransferable aTransferable);
};

Просмотреть файл

@ -53,7 +53,6 @@ interface nsITransaction;
interface nsIEditorObserver;
interface nsIEditActionListener;
interface nsIInlineSpellChecker;
interface nsITransferable;
%{C++
class nsIPresShell;
@ -62,7 +61,7 @@ typedef short EDirection;
[ptr] native nsIPresShellPtr(nsIPresShell);
[scriptable, uuid(63084019-4cd0-45f8-8b10-d9f0231b2f63)]
[scriptable, uuid(96b60ba0-634a-41e4-928e-78ab0b3c4b46)]
interface nsIEditor : nsISupports
{
@ -340,23 +339,11 @@ interface nsIEditor : nsISupports
*/
void paste(in long aSelectionType);
/** Paste the text in |aTransferable| at the cursor position, replacing the
* selected text (if any).
*/
void pasteTransferable(in nsITransferable aTransferable);
/** Can we paste? True if the doc is modifiable, and we have
* pasteable data in the clipboard.
*/
boolean canPaste(in long aSelectionType);
/** Can we paste |aTransferable| or, if |aTransferable| is null, will a call
* to pasteTransferable later possibly succeed if given an instance of
* nsITransferable then? True if the doc is modifiable, and, if
* |aTransfeable| is non-null, we have pasteable data in |aTransfeable|.
*/
boolean canPasteTransferable([optional] in nsITransferable aTransferable);
/* ------------ Selection methods -------------- */
/** sets the document selection to the entire contents of the document */

Просмотреть файл

@ -112,8 +112,6 @@
#include "nsIHTMLDocument.h"
#include "nsIParserService.h"
#include "nsITransferable.h"
#define NS_ERROR_EDITOR_NO_SELECTION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_EDITOR,1)
#define NS_ERROR_EDITOR_NO_TEXTNODE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_EDITOR,2)
@ -1260,24 +1258,12 @@ nsEditor::Paste(PRInt32 aSelectionType)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsEditor::PasteTransferable(nsITransferable *aTransferable)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsEditor::CanPasteTransferable(nsITransferable *aTransferable, PRBool *aCanPaste)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsEditor::CanDrag(nsIDOMEvent *aEvent, PRBool *aCanDrag)
{

Просмотреть файл

@ -436,73 +436,6 @@ nsPasteCommand::GetCommandStateParams(const char *aCommandName,
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
}
NS_IMETHODIMP
nsPasteTransferableCommand::IsCommandEnabled(const char *aCommandName,
nsISupports *aCommandRefCon,
PRBool *outCmdEnabled)
{
NS_ENSURE_ARG_POINTER(outCmdEnabled);
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
if (editor)
return editor->CanPasteTransferable(nsnull, outCmdEnabled);
*outCmdEnabled = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsPasteTransferableCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsPasteTransferableCommand::DoCommandParams(const char *aCommandName,
nsICommandParams *aParams,
nsISupports *aCommandRefCon)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
if (!editor)
return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports> supports;
aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
if (!supports)
return NS_ERROR_FAILURE;
nsCOMPtr<nsITransferable> trans = do_QueryInterface(supports);
if (!trans)
return NS_ERROR_FAILURE;
return editor->PasteTransferable(trans);
}
NS_IMETHODIMP
nsPasteTransferableCommand::GetCommandStateParams(const char *aCommandName,
nsICommandParams *aParams,
nsISupports *aCommandRefCon)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
if (!editor)
return NS_ERROR_FAILURE;
nsCOMPtr<nsITransferable> trans;
nsCOMPtr<nsISupports> supports;
aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
if (supports) {
trans = do_QueryInterface(supports);
if (!trans)
return NS_ERROR_FAILURE;
}
PRBool canPaste;
nsresult rv = editor->CanPasteTransferable(trans, &canPaste);
NS_ENSURE_SUCCESS(rv, rv);
return aParams->SetBooleanValue(STATE_ENABLED, canPaste);
}
NS_IMETHODIMP
nsSwitchTextDirectionCommand::IsCommandEnabled(const char *aCommandName,
nsISupports *aCommandRefCon,

Просмотреть файл

@ -82,7 +82,6 @@ NS_DECL_EDITOR_COMMAND(nsCutOrDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsCopyCommand)
NS_DECL_EDITOR_COMMAND(nsCopyOrDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsPasteCommand)
NS_DECL_EDITOR_COMMAND(nsPasteTransferableCommand)
NS_DECL_EDITOR_COMMAND(nsSwitchTextDirectionCommand)
NS_DECL_EDITOR_COMMAND(nsDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsSelectAllCommand)

Просмотреть файл

@ -91,8 +91,6 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandTable *i
NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll");
NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste");
NS_REGISTER_ONE_COMMAND(nsPasteTransferableCommand, "cmd_pasteTransferable");
NS_REGISTER_ONE_COMMAND(nsSwitchTextDirectionCommand, "cmd_switchTextDirection");
NS_REGISTER_FIRST_COMMAND(nsDeleteCommand, "cmd_delete");

Просмотреть файл

@ -1933,30 +1933,6 @@ NS_IMETHODIMP nsHTMLEditor::Paste(PRInt32 aSelectionType)
return rv;
}
NS_IMETHODIMP nsHTMLEditor::PasteTransferable(nsITransferable *aTransferable)
{
ForceCompositionEnd();
PRBool preventDefault;
nsresult rv = FireClipboardEvent(NS_PASTE, &preventDefault);
if (NS_FAILED(rv) || preventDefault)
return rv;
// handle transferable hooks
nsCOMPtr<nsIDOMDocument> domdoc;
GetDocument(getter_AddRefs(domdoc));
if (!nsEditorHookUtils::DoInsertionHook(domdoc, nsnull, aTransferable))
return NS_OK;
// Beware! This may flush notifications via synchronous
// ScrollSelectionIntoView.
nsAutoString contextStr, infoStr;
rv = InsertFromTransferable(aTransferable, nsnull, contextStr, infoStr,
nsnull, 0, PR_TRUE);
return rv;
}
//
// HTML PasteNoFormatting. Ignore any HTML styles and formating in paste source
//
@ -1991,14 +1967,6 @@ NS_IMETHODIMP nsHTMLEditor::PasteNoFormatting(PRInt32 aSelectionType)
}
// The following arrays contain the MIME types that we can paste. The arrays
// are used by CanPaste() and CanPasteTransferable() below.
static const char* textEditorFlavors[] = { kUnicodeMime };
static const char* textHtmlEditorFlavors[] = { kUnicodeMime, kHTMLMime,
kJPEGImageMime, kPNGImageMime,
kGIFImageMime };
NS_IMETHODIMP nsHTMLEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste)
{
NS_ENSURE_ARG_POINTER(aCanPaste);
@ -2012,6 +1980,11 @@ NS_IMETHODIMP nsHTMLEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste)
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_FAILED(rv)) return rv;
// the flavors that we can deal with (preferred order selectable for k*ImageMime)
const char* textEditorFlavors[] = { kUnicodeMime };
const char* textHtmlEditorFlavors[] = { kUnicodeMime, kHTMLMime,
kJPEGImageMime, kPNGImageMime, kGIFImageMime };
PRUint32 editorFlags;
GetFlags(&editorFlags);
@ -2033,54 +2006,6 @@ NS_IMETHODIMP nsHTMLEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste)
return NS_OK;
}
NS_IMETHODIMP nsHTMLEditor::CanPasteTransferable(nsITransferable *aTransferable, PRBool *aCanPaste)
{
NS_ENSURE_ARG_POINTER(aCanPaste);
// can't paste if readonly
if (!IsModifiable()) {
*aCanPaste = PR_FALSE;
return NS_OK;
}
// If |aTransferable| is null, assume that a paste will succeed.
if (!aTransferable) {
*aCanPaste = PR_TRUE;
return NS_OK;
}
// Peek in |aTransferable| to see if it contains a supported MIME type.
PRUint32 editorFlags;
GetFlags(&editorFlags);
// Use the flavors depending on the current editor mask
const char ** flavors;
unsigned length;
if ((editorFlags & eEditorPlaintextMask)) {
flavors = textEditorFlavors;
length = NS_ARRAY_LENGTH(textEditorFlavors);
} else {
flavors = textHtmlEditorFlavors;
length = NS_ARRAY_LENGTH(textHtmlEditorFlavors);
}
for (unsigned int i = 0; i < length; i++, flavors++) {
nsCOMPtr<nsISupports> data;
PRUint32 dataLen;
nsresult rv = aTransferable->GetTransferData(*flavors,
getter_AddRefs(data),
&dataLen);
if (NS_SUCCEEDED(rv) && data) {
*aCanPaste = PR_TRUE;
return NS_OK;
}
}
*aCanPaste = PR_FALSE;
return NS_OK;
}
//
// HTML PasteAsQuotation: Paste in a blockquote type=cite

Просмотреть файл

@ -319,9 +319,6 @@ public:
NS_IMETHOD Paste(PRInt32 aSelectionType);
NS_IMETHOD CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste);
NS_IMETHOD PasteTransferable(nsITransferable *aTransferable);
NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, PRBool *aCanPaste);
NS_IMETHOD DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed);
/** All editor operations which alter the doc should be prefaced

Просмотреть файл

@ -52,7 +52,6 @@ _TEST_FILES = \
test_bug478725.html \
test_bug480972.html \
test_bug487524.html \
test_bug525389.html \
test_select_all_without_body.html \
file_select_all_without_body.html \
$(NULL)

Просмотреть файл

@ -1,189 +0,0 @@
<!DOCTYPE HTML>
<html><head>
<title>Test for bug 525389</title>
<style src="/tests/SimpleTest/test.css" type="text/css"></style>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script class="testbody" type="application/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
var Cc = Components.classes;
var Ci = Components.interfaces;
function runTest() {
var pasteCount = 0;
var pasteFunc = function (event) { pasteCount++; };
function verifyContent(s) {
var e = document.getElementById('i1');
var doc = e.contentDocument;
is(doc.body.innerHTML, s, "");
}
function pasteInto(trans, html, target_id) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var e = document.getElementById('i1');
var doc = e.contentDocument;
doc.designMode = "on";
doc.body.innerHTML = html;
doc.defaultView.focus();
if (target_id)
e = doc.getElementById(target_id);
else
e = doc.body;
var selection = doc.defaultView.getSelection();
selection.removeAllRanges();
selection.selectAllChildren(e);
selection.collapseToEnd();
pasteCount = 0;
e.addEventListener("paste", pasteFunc, false);
utils.sendContentCommandEvent("pasteTransferable", trans);
e.removeEventListener("paste", pasteFunc, false);
return e;
}
function getTransferableFromClipboard(asHTML) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
if (asHTML) {
trans.addDataFlavor("text/html");
} else {
trans.addDataFlavor("text/unicode");
}
var clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
clip.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
return trans;
}
function makeTransferable(s,asHTML,target_id) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var e = document.getElementById('i2');
var doc = e.contentDocument;
if (asHTML) {
doc.body.innerHTML = s;
} else {
var text = doc.createTextNode(s);
doc.body.appendChild(text);
}
doc.designMode = "on";
doc.defaultView.focus();
var selection = doc.defaultView.getSelection();
selection.removeAllRanges();
if (!target_id) {
selection.selectAllChildren(doc.body);
} else {
var range = document.createRange();
range.selectNode(doc.getElementById(target_id));
selection.addRange(range);
}
// We cannot use plain strings, we have to use nsSupportsString.
var supportsStringClass = Components.classes["@mozilla.org/supports-string;1"];
var ssData = supportsStringClass.createInstance(Ci.nsISupportsString);
// Create the transferable.
var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
// Add the data to the transferable.
if (asHTML) {
trans.addDataFlavor("text/html");
ssData.data = doc.body.innerHTML;
trans.setTransferData("text/html", ssData, ssData.length * 2);
} else {
trans.addDataFlavor("text/unicode");
ssData.data = doc.body.innerHTML;
trans.setTransferData("text/unicode", ssData, ssData.length * 2);
}
return trans;
}
function copyToClipBoard(s,asHTML,target_id) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var e = document.getElementById('i2');
var doc = e.contentDocument;
if (asHTML) {
doc.body.innerHTML = s;
} else {
var text = doc.createTextNode(s);
doc.body.appendChild(text);
}
doc.designMode = "on";
doc.defaultView.focus();
var selection = doc.defaultView.getSelection();
selection.removeAllRanges();
if (!target_id) {
selection.selectAllChildren(doc.body);
} else {
var range = document.createRange();
range.selectNode(doc.getElementById(target_id));
selection.addRange(range);
}
doc.execCommand("copy", false, null);
return e;
}
copyToClipBoard('<span>Hello</span><span>Kitty</span>', true);
var trans = getTransferableFromClipboard(true);
pasteInto(trans, '');
verifyContent('<span>Hello</span><span>Kitty</span>');
is(pasteCount, 1, "paste event was not triggered");
// this test is not working out exactly like the clipboard test
// has to do with generating the nsITransferable above
//trans = makeTransferable('<span>Hello</span><span>Kitty</span>', true);
//pasteInto(trans, '');
//verifyContent('<span>Hello</span><span>Kitty</span>');
copyToClipBoard("<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span>", true);
trans = getTransferableFromClipboard(true);
pasteInto(trans, '<ol><li id="paste_here">X</li></ol>',"paste_here");
verifyContent('<ol><li id="paste_here">X<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span></li></ol>');
is(pasteCount, 1, "paste event was not triggered");
// The following test doesn't do what I expected, because the special handling
// of IsList nodes in nsHTMLEditor::InsertHTMLWithContext simply removes
// non-list/item children. See bug 481177.
// copyToClipBoard("<ol><li>Hello Kitty</li><span>Hello</span></ol>", true);
// pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here");
// verifyContent('<ol><li id="paste_here">X</li><li>Hello Kitty</li><span>Hello</span></ol>');
copyToClipBoard("<pre>Kitty</pre><span>Hello</span>", true);
trans = getTransferableFromClipboard(true);
pasteInto(trans, '<pre id="paste_here">Hello </pre>',"paste_here");
verifyContent('<pre id="paste_here">Hello Kitty<span>Hello</span></pre>');
is(pasteCount, 1, "paste event was not triggered");
// test that we can preventDefault pastes
pasteFunc = function (event) { event.preventDefault(); return false; };
copyToClipBoard("<pre>Kitty</pre><span>Hello</span>", true);
trans = getTransferableFromClipboard(true);
pasteInto(trans, '<pre id="paste_here">Hello </pre>',"paste_here");
verifyContent('<pre id="paste_here">Hello </pre>');
is(pasteCount, 0, "paste event was triggered");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=525389">Mozilla Bug 525389</a>
<p id="display"></p>
<pre id="test">
</pre>
<iframe id="i1" width="200" height="100" src="about:blank"></iframe><br>
<iframe id="i2" width="200" height="100" src="about:blank"></iframe><br>
</body>
</html>

Просмотреть файл

@ -455,30 +455,6 @@ NS_IMETHODIMP nsPlaintextEditor::Paste(PRInt32 aSelectionType)
return rv;
}
NS_IMETHODIMP nsPlaintextEditor::PasteTransferable(nsITransferable *aTransferable)
{
ForceCompositionEnd();
PRBool preventDefault;
nsresult rv = FireClipboardEvent(NS_PASTE, &preventDefault);
if (NS_FAILED(rv) || preventDefault)
return rv;
if (!IsModifiable())
return NS_OK;
// handle transferable hooks
nsCOMPtr<nsIDOMDocument> domdoc;
GetDocument(getter_AddRefs(domdoc));
if (!nsEditorHookUtils::DoInsertionHook(domdoc, nsnull, aTransferable))
return NS_OK;
// Beware! This may flush notifications via synchronous
// ScrollSelectionIntoView.
rv = InsertTextFromTransferable(aTransferable, nsnull, nsnull, PR_TRUE);
return rv;
}
NS_IMETHODIMP nsPlaintextEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste)
{
@ -506,37 +482,6 @@ NS_IMETHODIMP nsPlaintextEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPa
return NS_OK;
}
NS_IMETHODIMP nsPlaintextEditor::CanPasteTransferable(nsITransferable *aTransferable, PRBool *aCanPaste)
{
NS_ENSURE_ARG_POINTER(aCanPaste);
// can't paste if readonly
if (!IsModifiable()) {
*aCanPaste = PR_FALSE;
return NS_OK;
}
// If |aTransferable| is null, assume that a paste will succeed.
if (!aTransferable) {
*aCanPaste = PR_TRUE;
return NS_OK;
}
nsCOMPtr<nsISupports> data;
PRUint32 dataLen;
nsresult rv = aTransferable->GetTransferData(kUnicodeMime,
getter_AddRefs(data),
&dataLen);
if (NS_SUCCEEDED(rv) && data)
*aCanPaste = PR_TRUE;
else
*aCanPaste = PR_FALSE;
return NS_OK;
}
nsresult
nsPlaintextEditor::SetupDocEncoder(nsIDocumentEncoder **aDocEncoder)
{

Просмотреть файл

@ -124,8 +124,6 @@ public:
NS_IMETHOD CanCopy(PRBool *aCanCopy);
NS_IMETHOD Paste(PRInt32 aSelectionType);
NS_IMETHOD CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste);
NS_IMETHOD PasteTransferable(nsITransferable *aTransferable);
NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, PRBool *aCanPaste);
NS_IMETHOD CanDrag(nsIDOMEvent *aDragEvent, PRBool *aCanDrag);
NS_IMETHOD DoDrag(nsIDOMEvent *aDragEvent);

Просмотреть файл

@ -439,7 +439,6 @@ class nsHashKey;
#define NS_CONTENT_COMMAND_DELETE (NS_CONTENT_COMMAND_EVENT_START+3)
#define NS_CONTENT_COMMAND_UNDO (NS_CONTENT_COMMAND_EVENT_START+4)
#define NS_CONTENT_COMMAND_REDO (NS_CONTENT_COMMAND_EVENT_START+5)
#define NS_CONTENT_COMMAND_PASTE_TRANSFERABLE (NS_CONTENT_COMMAND_EVENT_START+6)
// Event to gesture notification
#define NS_GESTURENOTIFY_EVENT_START 3900
@ -1235,7 +1234,6 @@ public:
{
}
nsCOMPtr<nsITransferable> mTransferable; // [in]
PRPackedBool mOnlyEnabledCheck; // [in]
PRPackedBool mSucceeded; // [out]

Просмотреть файл

@ -2198,8 +2198,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
// that we can handle.
NSArray *sendTypes = [[NSArray alloc] initWithObjects:NSStringPboardType,NSHTMLPboardType,nil];
NSArray *returnTypes = [[NSArray alloc] initWithObjects:NSStringPboardType,NSHTMLPboardType,nil];
NSArray *returnTypes = [[NSArray alloc] init];
[NSApp registerServicesMenuSendTypes:sendTypes returnTypes:returnTypes];
[sendTypes release];
@ -6086,47 +6086,26 @@ static BOOL keyUpAlreadySentKeyDown = NO;
// returnType is nil if the service will not return any data.
//
// The following condition thus triggers when the service expects a string
// or HTML from us or no data at all AND when the service will either not
// send back any data to us or will send a string or HTML back to us.
// or HTML from us or no data at all AND when the service will not send back
// any data to us.
#define IsSupportedType(typeStr) ([typeStr isEqual:NSStringPboardType] || [typeStr isEqual:NSHTMLPboardType])
id result = nil;
if ((!sendType || IsSupportedType(sendType)) &&
(!returnType || IsSupportedType(returnType))) {
if ((!sendType || [sendType isEqual:NSStringPboardType] ||
[sendType isEqual:NSHTMLPboardType]) && !returnType) {
// Query the Gecko window to determine if there is a current selection.
if (mGeckoChild) {
// Assume that this object will be able to handle this request.
result = self;
// Keep the ChildView alive during this operation.
nsAutoRetainCocoaObject kungFuDeathGrip(self);
// Determine if there is a selection (if sending to the service).
if (sendType) {
nsQueryContentEvent event(PR_TRUE, NS_QUERY_CONTENT_STATE, mGeckoChild);
mGeckoChild->DispatchWindowEvent(event);
if (!event.mSucceeded || !event.mReply.mHasSelection)
result = nil;
}
// Determine if we can paste (if receiving data from the service).
if (returnType) {
nsContentCommandEvent command(PR_TRUE, NS_CONTENT_COMMAND_PASTE_TRANSFERABLE, mGeckoChild, PR_TRUE);
mGeckoChild->DispatchWindowEvent(command);
if (!command.mSucceeded || !command.mIsEnabled)
result = nil;
}
nsQueryContentEvent event(PR_TRUE, NS_QUERY_CONTENT_STATE, mGeckoChild);
mGeckoChild->DispatchWindowEvent(event);
// Return this object if it can handle the request.
if ((!sendType || (event.mSucceeded && event.mReply.mHasSelection)) &&
!returnType)
return self;
}
}
#undef IsSupportedType
// Give the superclass a chance if this object will not handle this request.
if (!result)
result = [super validRequestorForSendType:sendType returnType:returnType];
return result;
return [super validRequestorForSendType:sendType returnType:returnType];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
@ -6190,31 +6169,11 @@ static BOOL keyUpAlreadySentKeyDown = NO;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
}
// Called if the service wants us to replace the current selection.
// Called if the service wants us to replace the current selection. We do
// not currently support replacing the current selection so just return NO.
- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
{
nsresult rv;
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
if (NS_FAILED(rv))
return NO;
trans->AddDataFlavor(kUnicodeMime);
trans->AddDataFlavor(kHTMLMime);
rv = nsClipboard::TransferableFromPasteboard(trans, pboard);
if (NS_FAILED(rv))
return NO;
if (!mGeckoChild)
return NO;
nsContentCommandEvent command(PR_TRUE,
NS_CONTENT_COMMAND_PASTE_TRANSFERABLE,
mGeckoChild);
command.mTransferable = trans;
mGeckoChild->DispatchWindowEvent(command);
return command.mSucceeded && command.mIsEnabled;
return NO;
}
#pragma mark -

Просмотреть файл

@ -61,7 +61,6 @@ public:
static NSDictionary* PasteboardDictFromTransferable(nsITransferable *aTransferable);
static PRBool IsStringType(const nsCString& aMIMEType, const NSString** aPasteboardType);
static NSString* WrapHtmlForSystemPasteboard(NSString* aString);
static nsresult TransferableFromPasteboard(nsITransferable *aTransferable, NSPasteboard *pboard);
protected:

Просмотреть файл

@ -132,11 +132,18 @@ nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard)
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult
nsClipboard::TransferableFromPasteboard(nsITransferable *aTransferable, NSPasteboard *cocoaPasteboard)
NS_IMETHODIMP
nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, PRInt32 aWhichClipboard)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
if ((aWhichClipboard != kGlobalClipboard) || !aTransferable)
return NS_ERROR_FAILURE;
NSPasteboard* cocoaPasteboard = [NSPasteboard generalPasteboard];
if (!cocoaPasteboard)
return NS_ERROR_FAILURE;
// get flavor list that includes all acceptable flavors (including ones obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
@ -146,6 +153,37 @@ nsClipboard::TransferableFromPasteboard(nsITransferable *aTransferable, NSPasteb
PRUint32 flavorCount;
flavorList->Count(&flavorCount);
// If we were the last ones to put something on the pasteboard, then just use the cached
// transferable. Otherwise clear it because it isn't relevant any more.
if (mChangeCount == [cocoaPasteboard changeCount]) {
if (mTransferable) {
for (PRUint32 i = 0; i < flavorCount; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
if (!currentFlavor)
continue;
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
nsCOMPtr<nsISupports> dataSupports;
PRUint32 dataSize = 0;
rv = mTransferable->GetTransferData(flavorStr, getter_AddRefs(dataSupports), &dataSize);
if (NS_SUCCEEDED(rv)) {
aTransferable->SetTransferData(flavorStr, dataSupports, dataSize);
return NS_OK; // maybe try to fill in more types? Is there a point?
}
}
}
}
else {
nsBaseClipboard::EmptyClipboard(kGlobalClipboard);
}
// at this point we can't satisfy the request from cache data so let's look
// for things other people put on the system clipboard
for (PRUint32 i = 0; i < flavorCount; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
@ -259,63 +297,6 @@ nsClipboard::TransferableFromPasteboard(nsITransferable *aTransferable, NSPasteb
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP
nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, PRInt32 aWhichClipboard)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
if ((aWhichClipboard != kGlobalClipboard) || !aTransferable)
return NS_ERROR_FAILURE;
NSPasteboard* cocoaPasteboard = [NSPasteboard generalPasteboard];
if (!cocoaPasteboard)
return NS_ERROR_FAILURE;
// get flavor list that includes all acceptable flavors (including ones obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
PRUint32 flavorCount;
flavorList->Count(&flavorCount);
// If we were the last ones to put something on the pasteboard, then just use the cached
// transferable. Otherwise clear it because it isn't relevant any more.
if (mChangeCount == [cocoaPasteboard changeCount]) {
if (mTransferable) {
for (PRUint32 i = 0; i < flavorCount; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
if (!currentFlavor)
continue;
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
nsCOMPtr<nsISupports> dataSupports;
PRUint32 dataSize = 0;
rv = mTransferable->GetTransferData(flavorStr, getter_AddRefs(dataSupports), &dataSize);
if (NS_SUCCEEDED(rv)) {
aTransferable->SetTransferData(flavorStr, dataSupports, dataSize);
return NS_OK; // maybe try to fill in more types? Is there a point?
}
}
}
}
else {
nsBaseClipboard::EmptyClipboard(kGlobalClipboard);
}
// at this point we can't satisfy the request from cache data so let's look
// for things other people put on the system clipboard
return nsClipboard::TransferableFromPasteboard(aTransferable, cocoaPasteboard);
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
// returns true if we have *any* of the passed in flavors available for pasting
NS_IMETHODIMP
nsClipboard::HasDataMatchingFlavors(const char** aFlavorList, PRUint32 aLength,