diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index 0db373936b9c..fa8e28c9cf93 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -755,8 +755,13 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, *aActionTaken = false; } - NS_ASSERTION(aEventMessage == eCut || aEventMessage == eCopy || - aEventMessage == ePaste, + EventMessage originalEventMessage = aEventMessage; + if (originalEventMessage == ePasteNoFormatting) { + originalEventMessage = ePaste; + } + + NS_ASSERTION(originalEventMessage == eCut || originalEventMessage == eCopy || + originalEventMessage == ePaste, "Invalid clipboard event type"); nsCOMPtr presShell = aPresShell; @@ -813,10 +818,10 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, if (chromeShell || Preferences::GetBool("dom.event.clipboardevents.enabled", true)) { clipboardData = new DataTransfer(doc->GetScopeObject(), aEventMessage, - aEventMessage == ePaste, aClipboardType); + originalEventMessage == ePaste, aClipboardType); nsEventStatus status = nsEventStatus_eIgnore; - InternalClipboardEvent evt(true, aEventMessage); + InternalClipboardEvent evt(true, originalEventMessage); evt.mClipboardData = clipboardData; EventDispatcher::Dispatch(content, presShell->GetPresContext(), &evt, nullptr, &status); @@ -827,7 +832,7 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, // No need to do anything special during a paste. Either an event listener // took care of it and cancelled the event, or the caller will handle it. // Return true to indicate that the event wasn't cancelled. - if (aEventMessage == ePaste) { + if (originalEventMessage == ePaste) { // Clear and mark the clipboardData as readonly. This prevents someone // from reading the clipboard contents after the paste event has fired. if (clipboardData) { @@ -867,7 +872,7 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, // when cutting non-editable content, do nothing // XXX this is probably the wrong editable flag to check - if (aEventMessage != eCut || content->IsEditable()) { + if (originalEventMessage != eCut || content->IsEditable()) { // get the data from the selection if any bool isCollapsed; sel->GetIsCollapsed(&isCollapsed); diff --git a/dom/events/DataTransfer.cpp b/dom/events/DataTransfer.cpp index 26d2320d624d..5d31d2cb300b 100644 --- a/dom/events/DataTransfer.cpp +++ b/dom/events/DataTransfer.cpp @@ -105,8 +105,11 @@ DataTransfer::DataTransfer(nsISupports* aParent, EventMessage aEventMessage, aEventMessage == eDragStart) { mReadOnly = false; } else if (mIsExternal) { - if (aEventMessage == ePaste) { - CacheExternalClipboardFormats(); + if (aEventMessage == ePasteNoFormatting) { + mEventMessage = ePaste; + CacheExternalClipboardFormats(true); + } else if (aEventMessage == ePaste) { + CacheExternalClipboardFormats(false); } else if (aEventMessage >= eDragDropEventFirst && aEventMessage <= eDragDropEventLast) { CacheExternalDragFormats(); @@ -1356,7 +1359,7 @@ DataTransfer::CacheExternalDragFormats() } void -DataTransfer::CacheExternalClipboardFormats() +DataTransfer::CacheExternalClipboardFormats(bool aPlainTextOnly) { NS_ASSERTION(mEventMessage == ePaste, "caching clipboard data for invalid event"); @@ -1375,6 +1378,17 @@ DataTransfer::CacheExternalClipboardFormats() nsCOMPtr sysPrincipal; ssm->GetSystemPrincipal(getter_AddRefs(sysPrincipal)); + if (aPlainTextOnly) { + bool supported; + const char* unicodeMime[] = { kUnicodeMime }; + clipboard->HasDataMatchingFlavors(unicodeMime, 1, mClipboardType, + &supported); + if (supported) { + CacheExternalData(kUnicodeMime, 0, sysPrincipal, false); + } + return; + } + // Check if the clipboard has any files bool hasFileData = false; const char *fileMime[] = { kFileMime }; diff --git a/dom/events/DataTransfer.h b/dom/events/DataTransfer.h index 284edd56992c..729b23feb371 100644 --- a/dom/events/DataTransfer.h +++ b/dom/events/DataTransfer.h @@ -307,7 +307,7 @@ protected: void CacheExternalDragFormats(); // caches the formats that exist in the clipboard - void CacheExternalClipboardFormats(); + void CacheExternalClipboardFormats(bool aPlainTextOnly); FileList* GetFilesInternal(ErrorResult& aRv, nsIPrincipal* aSubjectPrincipal); nsresult GetDataAtInternal(const nsAString& aFormat, uint32_t aIndex, diff --git a/editor/libeditor/HTMLEditorDataTransfer.cpp b/editor/libeditor/HTMLEditorDataTransfer.cpp index 21a6948e1673..1d126fe09aeb 100644 --- a/editor/libeditor/HTMLEditorDataTransfer.cpp +++ b/editor/libeditor/HTMLEditorDataTransfer.cpp @@ -1495,7 +1495,7 @@ HTMLEditor::PasteTransferable(nsITransferable* aTransferable) NS_IMETHODIMP HTMLEditor::PasteNoFormatting(int32_t aSelectionType) { - if (!FireClipboardEvent(ePaste, aSelectionType)) { + if (!FireClipboardEvent(ePasteNoFormatting, aSelectionType)) { return NS_OK; } diff --git a/widget/EventMessageList.h b/widget/EventMessageList.h index a183253b5248..c4e42835663e 100644 --- a/widget/EventMessageList.h +++ b/widget/EventMessageList.h @@ -226,6 +226,7 @@ NS_EVENT_MESSAGE(eXULCommand) NS_EVENT_MESSAGE(eCopy) NS_EVENT_MESSAGE(eCut) NS_EVENT_MESSAGE(ePaste) +NS_EVENT_MESSAGE(ePasteNoFormatting) // Query for the selected text information, it return the selection offset, // selection length and selected text.