Skip to content

Commit

Permalink
Bug 1920646 - part 1: Make HTMLEditor paste/drop things as plaintex…
Browse files Browse the repository at this point in the history
…t when `contenteditable=plaintext-only` r=m_kato

Chrome sets `beforeinput.data` instead of `beforeinput.dataTransfer`, but
Input Events Level 2 spec defines that browsers should set `dataTransfer` when
**contenteditable** [1].  Therefore, the new WPT expects `dataTransfer`.

However, it's unclear that the `dataTransfer` should have `text/html` or only
`text/plain`.  From web apps point of view, `text/html` data may make them
serialize the rich text format to plaintext without any dependencies of browsers
and OS.  On the other hand, they cannot distinguish whether the user tries to
paste with or without formatting when `contenteditable=true`.  Therefore, I
filed a spec issue for this.  We need to be back later about this issue.

1. https://w3c.github.io/input-events/#overview
2. w3c/input-events#162

Differential Revision: https://phabricator.services.mozilla.com/D223908

UltraBlame original commit: 2e3f866560e2c750fe1e4469b81d89f10bffc6a1
  • Loading branch information
marco-c committed Oct 9, 2024
1 parent 6fd2736 commit 4d939db
Show file tree
Hide file tree
Showing 8 changed files with 721 additions and 125 deletions.
24 changes: 15 additions & 9 deletions editor/libeditor/HTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3143,8 +3143,9 @@ class HTMLEditor final : public EditorBase,



MOZ_CAN_RUN_SCRIPT nsresult
PasteInternal(nsIClipboard::ClipboardType aClipboardType);

MOZ_CAN_RUN_SCRIPT nsresult PasteInternal(
nsIClipboard::ClipboardType aClipboardType, const Element& aEditingHost);

[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
InsertWithQuotationsAsSubAction(const nsAString& aQuotedText) final;
Expand Down Expand Up @@ -3198,8 +3199,8 @@ class HTMLEditor final : public EditorBase,



MOZ_CAN_RUN_SCRIPT nsresult
InsertTextWithQuotationsInternal(const nsAString& aStringToInsert);
MOZ_CAN_RUN_SCRIPT nsresult InsertTextWithQuotationsInternal(
const nsAString& aStringToInsert, const Element& aEditingHost);



Expand Down Expand Up @@ -3722,9 +3723,10 @@ class HTMLEditor final : public EditorBase,
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetSelectionAtDocumentStart();


MOZ_CAN_RUN_SCRIPT nsresult
PasteAsPlaintextQuotation(nsIClipboard::ClipboardType aSelectionType);
MOZ_CAN_RUN_SCRIPT nsresult PasteAsPlaintextQuotation(
nsIClipboard::ClipboardType aSelectionType, const Element& aEditingHost);

enum class AddCites { No, Yes };



Expand All @@ -3734,8 +3736,10 @@ class HTMLEditor final : public EditorBase,




[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InsertAsPlaintextQuotation(
const nsAString& aQuotedText, bool aAddCites, nsINode** aNodeInserted);
const nsAString& aQuotedText, AddCites aAddCites,
const Element& aEditingHost, nsINode** aNodeInserted = nullptr);



Expand All @@ -3749,7 +3753,8 @@ class HTMLEditor final : public EditorBase,
DeleteSelectedContent aDeleteSelectedContent);

class HTMLTransferablePreparer;
nsresult PrepareHTMLTransferable(nsITransferable** aTransferable) const;
nsresult PrepareHTMLTransferable(nsITransferable** aTransferable,
const Element* aEditingHost) const;

enum class HavePrivateHTMLFlavor { No, Yes };
MOZ_CAN_RUN_SCRIPT nsresult InsertFromTransferableAtSelection(
Expand All @@ -3765,7 +3770,8 @@ class HTMLEditor final : public EditorBase,
MOZ_CAN_RUN_SCRIPT nsresult InsertFromDataTransfer(
const dom::DataTransfer* aDataTransfer, uint32_t aIndex,
nsIPrincipal* aSourcePrincipal, const EditorDOMPoint& aDroppedAt,
DeleteSelectedContent aDeleteSelectedContent);
DeleteSelectedContent aDeleteSelectedContent,
const Element& aEditingHost);

static HavePrivateHTMLFlavor ClipboardHasPrivateHTMLFlavor(
nsIClipboard* clipboard);
Expand Down
Loading

0 comments on commit 4d939db

Please sign in to comment.