diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 7f4cac787688..ebcfb30d727c 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -154,7 +154,6 @@ #endif #include "nsIFocusController.h" #include "nsIController.h" -#include "nsICommandParams.h" #ifdef XP_MACOSX #import @@ -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(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 commandController = do_QueryInterface(controller); - NS_ENSURE_STATE(commandController); - - nsCOMPtr 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); } } diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 787e1b923b71..e376473be970 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -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 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) { diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index d72c92928bc4..5efab995fdda 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -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); }; diff --git a/editor/idl/nsIEditor.idl b/editor/idl/nsIEditor.idl index 7e5adb5a0b31..7966abbe7ad8 100644 --- a/editor/idl/nsIEditor.idl +++ b/editor/idl/nsIEditor.idl @@ -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 */ diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 8b2ed20686a9..b7c01fb158bd 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -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) { diff --git a/editor/libeditor/base/nsEditorCommands.cpp b/editor/libeditor/base/nsEditorCommands.cpp index 7259d7ce0b16..ffe898ada5ca 100644 --- a/editor/libeditor/base/nsEditorCommands.cpp +++ b/editor/libeditor/base/nsEditorCommands.cpp @@ -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 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 editor = do_QueryInterface(aCommandRefCon); - if (!editor) - return NS_ERROR_FAILURE; - - nsCOMPtr supports; - aParams->GetISupportsValue("transferable", getter_AddRefs(supports)); - if (!supports) - return NS_ERROR_FAILURE; - - nsCOMPtr 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 editor = do_QueryInterface(aCommandRefCon); - if (!editor) - return NS_ERROR_FAILURE; - - nsCOMPtr trans; - - nsCOMPtr 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, diff --git a/editor/libeditor/base/nsEditorCommands.h b/editor/libeditor/base/nsEditorCommands.h index 359e728d1eb6..5c7491a59d0b 100644 --- a/editor/libeditor/base/nsEditorCommands.h +++ b/editor/libeditor/base/nsEditorCommands.h @@ -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) diff --git a/editor/libeditor/base/nsEditorController.cpp b/editor/libeditor/base/nsEditorController.cpp index 2cedbd3a36e4..4afb56cd344d 100644 --- a/editor/libeditor/base/nsEditorController.cpp +++ b/editor/libeditor/base/nsEditorController.cpp @@ -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"); diff --git a/editor/libeditor/html/nsHTMLDataTransfer.cpp b/editor/libeditor/html/nsHTMLDataTransfer.cpp index dfca7a288bec..7a9a42a81fa9 100644 --- a/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -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 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 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 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 diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index d9ca3a23f0a0..61a692bb3d1d 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -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 diff --git a/editor/libeditor/html/tests/Makefile.in b/editor/libeditor/html/tests/Makefile.in index 03f4b389d544..79793a687e6d 100644 --- a/editor/libeditor/html/tests/Makefile.in +++ b/editor/libeditor/html/tests/Makefile.in @@ -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) diff --git a/editor/libeditor/html/tests/test_bug525389.html b/editor/libeditor/html/tests/test_bug525389.html deleted file mode 100644 index f0d1db0cdf6c..000000000000 --- a/editor/libeditor/html/tests/test_bug525389.html +++ /dev/null @@ -1,189 +0,0 @@ - - -Test for bug 525389 - - - - - - - - -Mozilla Bug 525389 -

- -
-
- -
-
- - - diff --git a/editor/libeditor/text/nsPlaintextDataTransfer.cpp b/editor/libeditor/text/nsPlaintextDataTransfer.cpp index 917ce6991afa..cb59e0dd1eeb 100644 --- a/editor/libeditor/text/nsPlaintextDataTransfer.cpp +++ b/editor/libeditor/text/nsPlaintextDataTransfer.cpp @@ -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 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 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) { diff --git a/editor/libeditor/text/nsPlaintextEditor.h b/editor/libeditor/text/nsPlaintextEditor.h index 01f19ac03a8b..03faf0a9906d 100644 --- a/editor/libeditor/text/nsPlaintextEditor.h +++ b/editor/libeditor/text/nsPlaintextEditor.h @@ -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); diff --git a/widget/public/nsGUIEvent.h b/widget/public/nsGUIEvent.h index 0dca15573fe7..f8cfc786e680 100644 --- a/widget/public/nsGUIEvent.h +++ b/widget/public/nsGUIEvent.h @@ -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 mTransferable; // [in] PRPackedBool mOnlyEnabledCheck; // [in] PRPackedBool mSucceeded; // [out] diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index 5e6c678dbff7..c0631e5c7d7b 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -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 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 - diff --git a/widget/src/cocoa/nsClipboard.h b/widget/src/cocoa/nsClipboard.h index c812049a0c8f..4b30a6784fd0 100644 --- a/widget/src/cocoa/nsClipboard.h +++ b/widget/src/cocoa/nsClipboard.h @@ -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: diff --git a/widget/src/cocoa/nsClipboard.mm b/widget/src/cocoa/nsClipboard.mm index 9ad4b06d02c4..86cc0fd22c5d 100644 --- a/widget/src/cocoa/nsClipboard.mm +++ b/widget/src/cocoa/nsClipboard.mm @@ -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 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 genericFlavor; + flavorList->GetElementAt(i, getter_AddRefs(genericFlavor)); + nsCOMPtr currentFlavor(do_QueryInterface(genericFlavor)); + if (!currentFlavor) + continue; + + nsXPIDLCString flavorStr; + currentFlavor->ToString(getter_Copies(flavorStr)); + + nsCOMPtr 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 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 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 genericFlavor; - flavorList->GetElementAt(i, getter_AddRefs(genericFlavor)); - nsCOMPtr currentFlavor(do_QueryInterface(genericFlavor)); - if (!currentFlavor) - continue; - - nsXPIDLCString flavorStr; - currentFlavor->ToString(getter_Copies(flavorStr)); - - nsCOMPtr 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,