Bug 1809713 - Use ClipboardType in editor. r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D214584
This commit is contained in:
Tom Schuster 2024-07-29 11:52:33 +00:00
parent d4f7db068b
commit fdabe0cf72
14 changed files with 120 additions and 83 deletions

View File

@ -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<nsIClipboard> 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<nsIClipboard::ClipboardType> 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<nsGlobalWindowInner> mInnerWindow;
};
bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
int32_t aClipboardType,
PresShell* aPresShell,
Selection* aSelection,
bool* aActionTaken) {
bool nsCopySupport::FireClipboardEvent(
EventMessage aEventMessage,
mozilla::Maybe<nsIClipboard::ClipboardType> 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> presShell = aPresShell;
if (!presShell) {
return false;
@ -819,9 +820,12 @@ bool nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
bool doDefault = true;
RefPtr<DataTransfer> 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;

View File

@ -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<nsIClipboard::ClipboardType> aClipboardType,
mozilla::PresShell* aPresShell, mozilla::dom::Selection* aSelection,
bool* aActionTaken = nullptr);
};
#endif

View File

@ -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;
}

View File

@ -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<nsIClipboard> 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;
}

View File

@ -1585,8 +1585,9 @@ bool EditorBase::CheckForClipboardCommandListener(
}
Result<EditorBase::ClipboardEventResult, nsresult>
EditorBase::DispatchClipboardEventAndUpdateClipboard(EventMessage aEventMessage,
int32_t aClipboardType) {
EditorBase::DispatchClipboardEventAndUpdateClipboard(
EventMessage aEventMessage,
Maybe<nsIClipboard::ClipboardType> aClipboardType) {
MOZ_ASSERT(IsEditActionDataAvailable());
const bool isPasting =
@ -1667,7 +1668,7 @@ nsresult EditorBase::CutAsAction(nsIPrincipal* aPrincipal) {
Result<ClipboardEventResult, nsresult> 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<ClipboardEventResult, nsresult> 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<Element> focusedElement = focusManager->GetFocusedElement();
Result<ClipboardEventResult, nsresult> 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<Element> focusedElement = focusManager->GetFocusedElement();
Result<ClipboardEventResult, nsresult> 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<Element> 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<ClipboardEventResult, nsresult> 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");

View File

@ -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<ClipboardEventResult, nsresult>
DispatchClipboardEventAndUpdateClipboard(EventMessage aEventMessage,
int32_t aClipboardType);
DispatchClipboardEventAndUpdateClipboard(
EventMessage aEventMessage,
mozilla::Maybe<nsIClipboard::ClipboardType> 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

View File

@ -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<RefPtr<Element>, 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).

View File

@ -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<ClipboardEventResult, nsresult> 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<nsIClipboard> clipboard =

View File

@ -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())) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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 -------------- */

View File

@ -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> presShell = mPresShell;
nsCopySupport::FireClipboardEvent(eCopy, nsIClipboard::kGlobalClipboard,
nsCopySupport::FireClipboardEvent(eCopy, Some(nsIClipboard::kGlobalClipboard),
presShell, nullptr);
return NS_OK;
}

View File

@ -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
};