From fdabe0cf7238a0b055d763d4cc06b715b22eed1c Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Mon, 29 Jul 2024 11:52:33 +0000 Subject: [PATCH] Bug 1809713 - Use ClipboardType in editor. r=masayuki Differential Revision: https://phabricator.services.mozilla.com/D214584 --- dom/base/nsCopySupport.cpp | 34 ++++++++++-------- dom/base/nsCopySupport.h | 14 ++++---- dom/base/nsGlobalWindowCommands.cpp | 4 +-- dom/events/EventStateManager.cpp | 6 ++-- editor/libeditor/EditorBase.cpp | 39 +++++++++++++-------- editor/libeditor/EditorBase.h | 27 ++++++++------ editor/libeditor/HTMLEditor.h | 26 ++++++++------ editor/libeditor/HTMLEditorDataTransfer.cpp | 18 +++++----- editor/libeditor/TextEditor.cpp | 4 +-- editor/libeditor/TextEditor.h | 13 ++++--- editor/libeditor/TextEditorDataTransfer.cpp | 4 +-- editor/nsIEditor.idl | 5 +-- layout/base/nsDocumentViewer.cpp | 3 +- layout/generic/AutoCopyListener.h | 6 ++-- 14 files changed, 120 insertions(+), 83 deletions(-) diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index 8786ff86f753..6c39932a845e 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -323,7 +323,7 @@ static nsresult CreateTransferable( static nsresult PutToClipboard( const EncodedDocumentWithContext& aEncodedDocumentWithContext, - int16_t aClipboardID, Document& aDocument) { + nsIClipboard::ClipboardType aClipboardID, Document& aDocument) { nsresult rv; nsCOMPtr clipboard = do_GetService(kCClipboardCID, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -341,7 +341,7 @@ static nsresult PutToClipboard( } nsresult nsCopySupport::EncodeDocumentWithContextAndPutToClipboard( - Selection* aSel, Document* aDoc, int16_t aClipboardID, + Selection* aSel, Document* aDoc, nsIClipboard::ClipboardType aClipboardID, bool aWithRubyAnnotation) { NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER); @@ -728,13 +728,13 @@ static Element* GetElementOrNearestFlattenedTreeParentElement(nsINode* aNode) { */ class MOZ_RAII AutoHandlingPasteEvent final { public: - explicit AutoHandlingPasteEvent(nsGlobalWindowInner* aWindow, - DataTransfer* aDataTransfer, - const EventMessage& aEventMessage, - const int32_t& aClipboardType) { + explicit AutoHandlingPasteEvent( + nsGlobalWindowInner* aWindow, DataTransfer* aDataTransfer, + const EventMessage& aEventMessage, + const mozilla::Maybe aClipboardType) { MOZ_ASSERT(aDataTransfer); if (aWindow && aEventMessage == ePaste && - aClipboardType == nsIClipboard::kGlobalClipboard) { + aClipboardType == Some(nsIClipboard::kGlobalClipboard)) { aWindow->SetCurrentPasteDataTransfer(aDataTransfer); mInnerWindow = aWindow; } @@ -750,11 +750,10 @@ class MOZ_RAII AutoHandlingPasteEvent final { RefPtr mInnerWindow; }; -bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, - int32_t aClipboardType, - PresShell* aPresShell, - Selection* aSelection, - bool* aActionTaken) { +bool nsCopySupport::FireClipboardEvent( + EventMessage aEventMessage, + mozilla::Maybe aClipboardType, + PresShell* aPresShell, Selection* aSelection, bool* aActionTaken) { if (aActionTaken) { *aActionTaken = false; } @@ -768,6 +767,8 @@ bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, originalEventMessage == ePaste, "Invalid clipboard event type"); + MOZ_ASSERT_IF(originalEventMessage != ePaste, aClipboardType.isSome()); + RefPtr presShell = aPresShell; if (!presShell) { return false; @@ -819,9 +820,12 @@ bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, bool doDefault = true; RefPtr clipboardData; if (chromeShell || StaticPrefs::dom_event_clipboardevents_enabled()) { + int32_t badClipboardType = + aClipboardType.isSome() ? int32_t(*aClipboardType) : -1; + clipboardData = new DataTransfer(doc->GetScopeObject(), aEventMessage, - originalEventMessage == ePaste, aClipboardType); + originalEventMessage == ePaste, badClipboardType); nsEventStatus status = nsEventStatus_eIgnore; InternalClipboardEvent evt(true, originalEventMessage); @@ -916,7 +920,7 @@ bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, // expose the full functionality in browser. See bug 1130891. bool withRubyAnnotation = IsSelectionInsideRuby(sel); nsresult rv = EncodeDocumentWithContextAndPutToClipboard( - sel, doc, aClipboardType, withRubyAnnotation); + sel, doc, *aClipboardType, withRubyAnnotation); if (NS_FAILED(rv)) { return false; } @@ -941,7 +945,7 @@ bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, if (aPresShell && aPresShell->GetDocument()) { settingWindowContext = aPresShell->GetDocument()->GetWindowContext(); } - nsresult rv = clipboard->SetData(transferable, nullptr, aClipboardType, + nsresult rv = clipboard->SetData(transferable, nullptr, *aClipboardType, settingWindowContext); if (NS_FAILED(rv)) { return false; diff --git a/dom/base/nsCopySupport.h b/dom/base/nsCopySupport.h index 5552e1a6074e..15c6164adc0a 100644 --- a/dom/base/nsCopySupport.h +++ b/dom/base/nsCopySupport.h @@ -11,6 +11,8 @@ #include "mozilla/AlreadyAddRefed.h" #include "mozilla/Attributes.h" #include "mozilla/BasicEvents.h" +#include "mozilla/Maybe.h" +#include "nsIClipboard.h" #include "nsStringFwd.h" class nsINode; @@ -37,7 +39,7 @@ class nsCopySupport { */ static nsresult EncodeDocumentWithContextAndPutToClipboard( mozilla::dom::Selection* aSel, mozilla::dom::Document* aDoc, - int16_t aClipboardID, bool aWithRubyAnnotation); + nsIClipboard::ClipboardType aClipboardID, bool aWithRubyAnnotation); // Get the selection, or entire document, in the format specified by the mime // type (text/html or text/plain). If aSel is non-null, use it, otherwise get @@ -108,11 +110,11 @@ class nsCopySupport { * If the event is cancelled or an error occurs, false will be returned. */ MOZ_CAN_RUN_SCRIPT_BOUNDARY - static bool FireClipboardEvent(mozilla::EventMessage aEventMessage, - int32_t aClipboardType, - mozilla::PresShell* aPresShell, - mozilla::dom::Selection* aSelection, - bool* aActionTaken = nullptr); + static bool FireClipboardEvent( + mozilla::EventMessage aEventMessage, + mozilla::Maybe aClipboardType, + mozilla::PresShell* aPresShell, mozilla::dom::Selection* aSelection, + bool* aActionTaken = nullptr); }; #endif diff --git a/dom/base/nsGlobalWindowCommands.cpp b/dom/base/nsGlobalWindowCommands.cpp index 8a65b3793c8c..68de88c8a72e 100644 --- a/dom/base/nsGlobalWindowCommands.cpp +++ b/dom/base/nsGlobalWindowCommands.cpp @@ -577,8 +577,8 @@ nsresult nsClipboardCommand::DoCommand(const char* aCommandName, bool actionTaken = false; nsCopySupport::FireClipboardEvent(eventMessage, - nsIClipboard::kGlobalClipboard, presShell, - nullptr, &actionTaken); + Some(nsIClipboard::kGlobalClipboard), + presShell, nullptr, &actionTaken); return actionTaken ? NS_OK : NS_SUCCESS_DOM_NO_OPERATION; } diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index f11c8a8ad3c4..7d165ffcf57a 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -6151,7 +6151,7 @@ nsresult EventStateManager::HandleMiddleClickPaste( // Don't modify selection here because we've already set caret to the point // at "mousedown" event. - int32_t clipboardType = nsIClipboard::kGlobalClipboard; + nsIClipboard::ClipboardType clipboardType = nsIClipboard::kGlobalClipboard; nsCOMPtr clipboardService = do_GetService("@mozilla.org/widget/clipboard;1"); if (clipboardService && clipboardService->IsClipboardTypeSupported( @@ -6162,8 +6162,8 @@ nsresult EventStateManager::HandleMiddleClickPaste( // Fire ePaste event by ourselves since we need to dispatch "paste" event // even if the middle click event was consumed for compatibility with // Chromium. - if (!nsCopySupport::FireClipboardEvent(ePaste, clipboardType, aPresShell, - selection)) { + if (!nsCopySupport::FireClipboardEvent(ePaste, Some(clipboardType), + aPresShell, selection)) { *aStatus = nsEventStatus_eConsumeNoDefault; return NS_OK; } diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp index fc4b02d8d17a..719a41e3ff88 100644 --- a/editor/libeditor/EditorBase.cpp +++ b/editor/libeditor/EditorBase.cpp @@ -1585,8 +1585,9 @@ bool EditorBase::CheckForClipboardCommandListener( } Result -EditorBase::DispatchClipboardEventAndUpdateClipboard(EventMessage aEventMessage, - int32_t aClipboardType) { +EditorBase::DispatchClipboardEventAndUpdateClipboard( + EventMessage aEventMessage, + Maybe aClipboardType) { MOZ_ASSERT(IsEditActionDataAvailable()); const bool isPasting = @@ -1667,7 +1668,7 @@ nsresult EditorBase::CutAsAction(nsIPrincipal* aPrincipal) { Result ret = DispatchClipboardEventAndUpdateClipboard( - eCut, nsIClipboard::kGlobalClipboard); + eCut, Some(nsIClipboard::kGlobalClipboard)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(eCut, " @@ -1756,8 +1757,8 @@ NS_IMETHODIMP EditorBase::Copy() { } Result ret = - DispatchClipboardEventAndUpdateClipboard(eCopy, - nsIClipboard::kGlobalClipboard); + DispatchClipboardEventAndUpdateClipboard( + eCopy, Some(nsIClipboard::kGlobalClipboard)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(eCopy, " @@ -1798,7 +1799,10 @@ bool EditorBase::IsCopyCommandEnabled() const { return CheckForClipboardCommandListener(nsGkAtoms::oncopy, eCopy); } -NS_IMETHODIMP EditorBase::Paste(int32_t aClipboardType) { +NS_IMETHODIMP EditorBase::Paste(nsIClipboard::ClipboardType aClipboardType) { + if (uint32_t(aClipboardType) >= nsIClipboard::kClipboardTypeCount) { + return NS_ERROR_INVALID_ARG; + } const nsresult rv = PasteAsAction(aClipboardType, DispatchPasteEvent::Yes); NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), @@ -1806,7 +1810,7 @@ NS_IMETHODIMP EditorBase::Paste(int32_t aClipboardType) { return rv; } -nsresult EditorBase::PasteAsAction(int32_t aClipboardType, +nsresult EditorBase::PasteAsAction(nsIClipboard::ClipboardType aClipboardType, DispatchPasteEvent aDispatchPasteEvent, nsIPrincipal* aPrincipal /* = nullptr */) { if (IsHTMLEditor() && IsReadonly()) { @@ -1827,7 +1831,7 @@ nsresult EditorBase::PasteAsAction(int32_t aClipboardType, const RefPtr focusedElement = focusManager->GetFocusedElement(); Result ret = - DispatchClipboardEventAndUpdateClipboard(ePaste, aClipboardType); + DispatchClipboardEventAndUpdateClipboard(ePaste, Some(aClipboardType)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(ePaste) " @@ -1879,7 +1883,8 @@ nsresult EditorBase::PasteAsAction(int32_t aClipboardType, } nsresult EditorBase::PasteAsQuotationAsAction( - int32_t aClipboardType, DispatchPasteEvent aDispatchPasteEvent, + nsIClipboard::ClipboardType aClipboardType, + DispatchPasteEvent aDispatchPasteEvent, nsIPrincipal* aPrincipal /* = nullptr */) { MOZ_ASSERT(aClipboardType == nsIClipboard::kGlobalClipboard || aClipboardType == nsIClipboard::kSelectionClipboard); @@ -1902,7 +1907,7 @@ nsresult EditorBase::PasteAsQuotationAsAction( const RefPtr focusedElement = focusManager->GetFocusedElement(); Result ret = - DispatchClipboardEventAndUpdateClipboard(ePaste, aClipboardType); + DispatchClipboardEventAndUpdateClipboard(ePaste, Some(aClipboardType)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(ePaste) " @@ -1976,12 +1981,13 @@ nsresult EditorBase::PasteTransferableAsAction( } const RefPtr focusedElement = focusManager->GetFocusedElement(); - // Use an invalid value for the clipboard type as data comes from + // Use a nothing value for the clipboard type as data comes from // aTransferable and we don't currently implement a way to put that in the // data transfer in TextEditor yet. Result ret = DispatchClipboardEventAndUpdateClipboard( - ePaste, IsTextEditor() ? -1 : nsIClipboard::kGlobalClipboard); + ePaste, + IsTextEditor() ? Nothing() : Some(nsIClipboard::kGlobalClipboard)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(ePaste) " @@ -2119,7 +2125,11 @@ NS_IMETHODIMP EditorBase::PasteTransferable(nsITransferable* aTransferable) { return rv; } -NS_IMETHODIMP EditorBase::CanPaste(int32_t aClipboardType, bool* aCanPaste) { +NS_IMETHODIMP EditorBase::CanPaste(nsIClipboard::ClipboardType aClipboardType, + bool* aCanPaste) { + if (uint32_t(aClipboardType) >= nsIClipboard::kClipboardTypeCount) { + return NS_ERROR_INVALID_ARG; + } if (NS_WARN_IF(!aCanPaste)) { return NS_ERROR_INVALID_ARG; } @@ -6568,7 +6578,8 @@ void EditorBase::AutoEditActionDataSetter::InitializeDataTransfer( } void EditorBase::AutoEditActionDataSetter::InitializeDataTransferWithClipboard( - SettingDataTransfer aSettingDataTransfer, int32_t aClipboardType) { + SettingDataTransfer aSettingDataTransfer, + nsIClipboard::ClipboardType aClipboardType) { MOZ_ASSERT(!HasTriedToDispatchBeforeInputEvent(), "It's too late to set dataTransfer since this may have already " "dispatched a beforeinput event"); diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h index dc2693e6ebb7..28335a0cd539 100644 --- a/editor/libeditor/EditorBase.h +++ b/editor/libeditor/EditorBase.h @@ -29,6 +29,7 @@ #include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr #include "nsCycleCollectionParticipant.h" #include "nsGkAtoms.h" +#include "nsIClipboard.h" // for nsIClipboard::ClipboardType #include "nsIContentInlines.h" // for nsINode::IsEditable() #include "nsIEditor.h" // for nsIEditor, etc. #include "nsISelectionController.h" // for nsISelectionController constants @@ -626,7 +627,7 @@ class EditorBase : public nsIEditor, /** * CanPaste() returns true if user can paste something at current selection. */ - virtual bool CanPaste(int32_t aClipboardType) const = 0; + virtual bool CanPaste(nsIClipboard::ClipboardType aClipboardType) const = 0; /** * Do "undo" or "redo". @@ -757,7 +758,8 @@ class EditorBase : public nsIEditor, */ enum class DispatchPasteEvent { No, Yes }; MOZ_CAN_RUN_SCRIPT nsresult - PasteAsAction(int32_t aClipboardType, DispatchPasteEvent aDispatchPasteEvent, + PasteAsAction(nsIClipboard::ClipboardType aClipboardType, + DispatchPasteEvent aDispatchPasteEvent, nsIPrincipal* aPrincipal = nullptr); /** @@ -789,9 +791,10 @@ class EditorBase : public nsIEditor, * JS. If set to nullptr, will be treated as * called by system. */ - MOZ_CAN_RUN_SCRIPT nsresult PasteAsQuotationAsAction( - int32_t aClipboardType, DispatchPasteEvent aDispatchPasteEvent, - nsIPrincipal* aPrincipal = nullptr); + MOZ_CAN_RUN_SCRIPT nsresult + PasteAsQuotationAsAction(nsIClipboard::ClipboardType aClipboardType, + DispatchPasteEvent aDispatchPasteEvent, + nsIPrincipal* aPrincipal = nullptr); /** * Return true if `beforeinput` or `input` event is being dispatched. @@ -1165,7 +1168,8 @@ class EditorBase : public nsIEditor, * initializes it with clipboard and sets mDataTransfer to it. */ void InitializeDataTransferWithClipboard( - SettingDataTransfer aSettingDataTransfer, int32_t aClipboardType); + SettingDataTransfer aSettingDataTransfer, + nsIClipboard::ClipboardType aClipboardType); dom::DataTransfer* GetDataTransfer() const { return mDataTransfer; } /** @@ -2712,22 +2716,25 @@ class EditorBase : public nsIEditor, DoDefault, }; [[nodiscard]] MOZ_CAN_RUN_SCRIPT Result - DispatchClipboardEventAndUpdateClipboard(EventMessage aEventMessage, - int32_t aClipboardType); + DispatchClipboardEventAndUpdateClipboard( + EventMessage aEventMessage, + mozilla::Maybe aClipboardType); /** * Called after PasteAsAction() dispatches "paste" event and it's not * canceled. */ [[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual nsresult HandlePaste( - AutoEditActionDataSetter& aEditActionData, int32_t aClipboardType) = 0; + AutoEditActionDataSetter& aEditActionData, + nsIClipboard::ClipboardType aClipboardType) = 0; /** * Called after PasteAsQuotationAsAction() dispatches "paste" event and it's * not canceled. */ [[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual nsresult HandlePasteAsQuotation( - AutoEditActionDataSetter& aEditActionData, int32_t aClipboardType) = 0; + AutoEditActionDataSetter& aEditActionData, + nsIClipboard::ClipboardType aClipboardType) = 0; /** * Called after PasteTransferableAsAction() dispatches "paste" event and it's diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index af5570afef5c..768b6ea8d551 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -37,7 +37,6 @@ class nsDocumentFragment; class nsFrameSelection; class nsHTMLDocument; class nsITransferable; -class nsIClipboard; class nsRange; class nsStaticAtom; class nsStyledElement; @@ -171,7 +170,7 @@ class HTMLEditor final : public EditorBase, bool IsEmpty() const final; - bool CanPaste(int32_t aClipboardType) const final; + bool CanPaste(nsIClipboard::ClipboardType aClipboardType) const final; using EditorBase::CanPaste; MOZ_CAN_RUN_SCRIPT NS_IMETHOD DeleteNode(nsINode* aNode, @@ -246,9 +245,10 @@ class HTMLEditor final : public EditorBase, * JS. If set to nullptr, will be treated as * called by system. */ - MOZ_CAN_RUN_SCRIPT nsresult PasteNoFormattingAsAction( - int32_t aClipboardType, DispatchPasteEvent aDispatchPasteEvent, - nsIPrincipal* aPrincipal = nullptr); + MOZ_CAN_RUN_SCRIPT nsresult + PasteNoFormattingAsAction(nsIClipboard::ClipboardType aClipboardType, + DispatchPasteEvent aDispatchPasteEvent, + nsIPrincipal* aPrincipal = nullptr); bool CanPasteTransferable(nsITransferable* aTransferable) final; @@ -3123,10 +3123,12 @@ class HTMLEditor final : public EditorBase, */ Result, nsresult> GetFirstSelectedCellElementInTable() const; - [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult HandlePaste( - AutoEditActionDataSetter& aEditActionData, int32_t aClipboardType) final; - [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult HandlePasteAsQuotation( - AutoEditActionDataSetter& aEditActionData, int32_t aClipboardType) final; + [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult + HandlePaste(AutoEditActionDataSetter& aEditActionData, + nsIClipboard::ClipboardType aClipboardType) final; + [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult + HandlePasteAsQuotation(AutoEditActionDataSetter& aEditActionData, + nsIClipboard::ClipboardType aClipboardType) final; [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult HandlePasteTransferable(AutoEditActionDataSetter& aEditActionData, nsITransferable& aTransferable) final; @@ -3139,7 +3141,8 @@ class HTMLEditor final : public EditorBase, * @param aClipboardType nsIClipboard::kGlobalClipboard or * nsIClipboard::kSelectionClipboard. */ - MOZ_CAN_RUN_SCRIPT nsresult PasteInternal(int32_t aClipboardType); + MOZ_CAN_RUN_SCRIPT nsresult + PasteInternal(nsIClipboard::ClipboardType aClipboardType); [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InsertWithQuotationsAsSubAction(const nsAString& aQuotedText) final; @@ -3713,7 +3716,8 @@ class HTMLEditor final : public EditorBase, [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetSelectionAtDocumentStart(); // Methods for handling plaintext quotations - MOZ_CAN_RUN_SCRIPT nsresult PasteAsPlaintextQuotation(int32_t aSelectionType); + MOZ_CAN_RUN_SCRIPT nsresult + PasteAsPlaintextQuotation(nsIClipboard::ClipboardType aSelectionType); /** * Insert a string as quoted text, replacing the selected text (if any). diff --git a/editor/libeditor/HTMLEditorDataTransfer.cpp b/editor/libeditor/HTMLEditorDataTransfer.cpp index 9ee923c719d6..8ba0ca1893ae 100644 --- a/editor/libeditor/HTMLEditorDataTransfer.cpp +++ b/editor/libeditor/HTMLEditorDataTransfer.cpp @@ -2286,7 +2286,7 @@ HTMLEditor::HavePrivateHTMLFlavor HTMLEditor::ClipboardHasPrivateHTMLFlavor( } nsresult HTMLEditor::HandlePaste(AutoEditActionDataSetter& aEditActionData, - int32_t aClipboardType) { + nsIClipboard::ClipboardType aClipboardType) { aEditActionData.InitializeDataTransferWithClipboard( SettingDataTransfer::eWithFormat, aClipboardType); nsresult rv = aEditActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); @@ -2300,7 +2300,7 @@ nsresult HTMLEditor::HandlePaste(AutoEditActionDataSetter& aEditActionData, return rv; } -nsresult HTMLEditor::PasteInternal(int32_t aClipboardType) { +nsresult HTMLEditor::PasteInternal(nsIClipboard::ClipboardType aClipboardType) { MOZ_ASSERT(IsEditActionDataAvailable()); // Get Clipboard Service @@ -2457,8 +2457,8 @@ nsresult HTMLEditor::HandlePasteTransferable( } nsresult HTMLEditor::PasteNoFormattingAsAction( - int32_t aClipboardType, DispatchPasteEvent aDispatchPasteEvent, - nsIPrincipal* aPrincipal) { + nsIClipboard::ClipboardType aClipboardType, + DispatchPasteEvent aDispatchPasteEvent, nsIPrincipal* aPrincipal) { if (IsReadonly()) { return NS_OK; } @@ -2480,7 +2480,7 @@ nsresult HTMLEditor::PasteNoFormattingAsAction( Result ret = DispatchClipboardEventAndUpdateClipboard(ePasteNoFormatting, - aClipboardType); + Some(aClipboardType)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(" @@ -2609,7 +2609,7 @@ static const char* textHtmlEditorFlavors[] = {kTextMime, kHTMLMime, kJPEGImageMime, kJPGImageMime, kPNGImageMime, kGIFImageMime}; -bool HTMLEditor::CanPaste(int32_t aClipboardType) const { +bool HTMLEditor::CanPaste(nsIClipboard::ClipboardType aClipboardType) const { if (AreClipboardCommandsUnconditionallyEnabled()) { return true; } @@ -2685,7 +2685,8 @@ bool HTMLEditor::CanPasteTransferable(nsITransferable* aTransferable) { } nsresult HTMLEditor::HandlePasteAsQuotation( - AutoEditActionDataSetter& aEditActionData, int32_t aClipboardType) { + AutoEditActionDataSetter& aEditActionData, + nsIClipboard::ClipboardType aClipboardType) { MOZ_ASSERT(aClipboardType == nsIClipboard::kGlobalClipboard || aClipboardType == nsIClipboard::kSelectionClipboard); aEditActionData.InitializeDataTransferWithClipboard( @@ -2808,7 +2809,8 @@ nsresult HTMLEditor::HandlePasteAsQuotation( return rv; } -nsresult HTMLEditor::PasteAsPlaintextQuotation(int32_t aSelectionType) { +nsresult HTMLEditor::PasteAsPlaintextQuotation( + nsIClipboard::ClipboardType aSelectionType) { // Get Clipboard Service nsresult rv; nsCOMPtr clipboard = diff --git a/editor/libeditor/TextEditor.cpp b/editor/libeditor/TextEditor.cpp index a4064407d14f..2c4f824893d5 100644 --- a/editor/libeditor/TextEditor.cpp +++ b/editor/libeditor/TextEditor.cpp @@ -46,7 +46,6 @@ #include "nsError.h" #include "nsFocusManager.h" #include "nsGkAtoms.h" -#include "nsIClipboard.h" #include "nsIContent.h" #include "nsINode.h" #include "nsIPrincipal.h" @@ -565,7 +564,8 @@ bool TextEditor::IsCopyToClipboardAllowedInternal() const { } nsresult TextEditor::HandlePasteAsQuotation( - AutoEditActionDataSetter& aEditActionData, int32_t aClipboardType) { + AutoEditActionDataSetter& aEditActionData, + nsIClipboard::ClipboardType aClipboardType) { MOZ_ASSERT(aClipboardType == nsIClipboard::kGlobalClipboard || aClipboardType == nsIClipboard::kSelectionClipboard); if (NS_WARN_IF(!GetDocument())) { diff --git a/editor/libeditor/TextEditor.h b/editor/libeditor/TextEditor.h index d6836020f1d2..1fd6c0547a1f 100644 --- a/editor/libeditor/TextEditor.h +++ b/editor/libeditor/TextEditor.h @@ -13,6 +13,7 @@ #include "nsCOMPtr.h" #include "nsCycleCollectionParticipant.h" +#include "nsIClipboard.h" #include "nsINamed.h" #include "nsISupportsImpl.h" #include "nsITimer.h" @@ -134,7 +135,7 @@ class TextEditor final : public EditorBase, // Overrides of EditorBase bool IsEmpty() const final; - bool CanPaste(int32_t aClipboardType) const final; + bool CanPaste(nsIClipboard::ClipboardType aClipboardType) const final; bool CanPasteTransferable(nsITransferable* aTransferable) final; @@ -565,10 +566,12 @@ class TextEditor final : public EditorBase, */ MOZ_CAN_RUN_SCRIPT nsresult SelectEntireDocument() final; - [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult HandlePaste( - AutoEditActionDataSetter& aEditActionData, int32_t aClipboardType) final; - [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult HandlePasteAsQuotation( - AutoEditActionDataSetter& aEditActionData, int32_t aClipboardType) final; + [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult + HandlePaste(AutoEditActionDataSetter& aEditActionData, + nsIClipboard::ClipboardType aClipboardType) final; + [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult + HandlePasteAsQuotation(AutoEditActionDataSetter& aEditActionData, + nsIClipboard::ClipboardType aClipboardType) final; [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult HandlePasteTransferable(AutoEditActionDataSetter& aEditActionData, nsITransferable& aTransferable) final; diff --git a/editor/libeditor/TextEditorDataTransfer.cpp b/editor/libeditor/TextEditorDataTransfer.cpp index ae7752843e58..00d7a3e66f81 100644 --- a/editor/libeditor/TextEditorDataTransfer.cpp +++ b/editor/libeditor/TextEditorDataTransfer.cpp @@ -161,7 +161,7 @@ nsresult TextEditor::InsertDroppedDataTransferAsAction( } nsresult TextEditor::HandlePaste(AutoEditActionDataSetter& aEditActionData, - int32_t aClipboardType) { + nsIClipboard::ClipboardType aClipboardType) { if (NS_WARN_IF(!GetDocument())) { return NS_OK; } @@ -229,7 +229,7 @@ nsresult TextEditor::HandlePasteTransferable( return rv; } -bool TextEditor::CanPaste(int32_t aClipboardType) const { +bool TextEditor::CanPaste(nsIClipboard::ClipboardType aClipboardType) const { if (AreClipboardCommandsUnconditionallyEnabled()) { return true; } diff --git a/editor/nsIEditor.idl b/editor/nsIEditor.idl index 9193dc1b8b6e..9e215a6cc152 100644 --- a/editor/nsIEditor.idl +++ b/editor/nsIEditor.idl @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsISupports.idl" +#include "nsIClipboard.idl" #include "domstubs.idl" %{C++ @@ -377,7 +378,7 @@ interface nsIEditor : nsISupports * the selected text (if any) */ [can_run_script] - void paste(in long aClipboardType); + void paste(in nsIClipboard_ClipboardType aClipboardType); /** Paste the text in |aTransferable| at the cursor position, replacing the * selected text (if any). @@ -388,7 +389,7 @@ interface nsIEditor : nsISupports /** Can we paste? True if the doc is modifiable, and we have * pasteable data in the clipboard. */ - boolean canPaste(in long aClipboardType); + boolean canPaste(in nsIClipboard_ClipboardType aClipboardType); /* ------------ Selection methods -------------- */ diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 4f9276d6e71b..d08b74bed9ea 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -78,6 +78,7 @@ #include "nsCopySupport.h" #include "nsXULPopupManager.h" +#include "nsIClipboard.h" #include "nsIClipboardHelper.h" #include "nsPIDOMWindow.h" @@ -2418,7 +2419,7 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocumentViewer::SelectAll() { NS_IMETHODIMP nsDocumentViewer::CopySelection() { RefPtr presShell = mPresShell; - nsCopySupport::FireClipboardEvent(eCopy, nsIClipboard::kGlobalClipboard, + nsCopySupport::FireClipboardEvent(eCopy, Some(nsIClipboard::kGlobalClipboard), presShell, nullptr); return NS_OK; } diff --git a/layout/generic/AutoCopyListener.h b/layout/generic/AutoCopyListener.h index 57de5bb78e24..ab6889bb068f 100644 --- a/layout/generic/AutoCopyListener.h +++ b/layout/generic/AutoCopyListener.h @@ -43,10 +43,12 @@ class AutoCopyListener final { private: #ifdef XP_MACOSX // On macOS, cache the current selection to send to service menu of macOS. - static const int16_t sClipboardID = nsIClipboard::kSelectionCache; + static const nsIClipboard::ClipboardType sClipboardID = + nsIClipboard::kSelectionCache; #else // Make the normal Selection notifies auto-copy listener of its changes. - static const int16_t sClipboardID = nsIClipboard::kSelectionClipboard; + static const nsIClipboard::ClipboardType sClipboardID = + nsIClipboard::kSelectionClipboard; #endif };