Bug 1716720 - Clean up `TextEditor.h` and `HTMLEditor.h` r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 17 Jun 2021 23:25:55 +0000
changeset 583766 07029ce7f3e7626341c9aca6c6bb5a52fbb58956
parent 583765 4525315bf428b26ef70462516911f8dc1a1c14d6
child 583767 f7016db57a2e19b8f54897fee21426b4b7a07e9e
push id38550
push usermlaza@mozilla.com
push dateFri, 18 Jun 2021 09:20:56 +0000
treeherdermozilla-central@d70c3d846c39 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1716720
milestone91.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1716720 - Clean up `TextEditor.h` and `HTMLEditor.h` r=m_kato `TextEditor` is now a final class, so, it should be marked as so. And this patch modernize `virtual`, `override` and `final` keywords in them. Differential Revision: https://phabricator.services.mozilla.com/D117998
editor/libeditor/HTMLEditor.h
editor/libeditor/TextEditor.h
editor/nsIEditor.idl
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -137,43 +137,43 @@ class HTMLEditor final : public EditorBa
 
   static HTMLEditor* GetFrom(nsIEditor* aEditor) {
     return aEditor ? aEditor->GetAsHTMLEditor() : nullptr;
   }
   static const HTMLEditor* GetFrom(const nsIEditor* aEditor) {
     return aEditor ? aEditor->GetAsHTMLEditor() : nullptr;
   }
 
-  MOZ_CAN_RUN_SCRIPT virtual void PreDestroy(bool aDestroyingFrames) override;
+  MOZ_CAN_RUN_SCRIPT void PreDestroy(bool aDestroyingFrames) final;
 
   bool GetReturnInParagraphCreatesNewParagraph();
 
   // EditorBase overrides
-  MOZ_CAN_RUN_SCRIPT virtual nsresult Init(Document& aDoc, Element* aRoot,
-                                           nsISelectionController* aSelCon,
-                                           uint32_t aFlags,
-                                           const nsAString& aValue) override;
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD BeginningOfDocument() override;
-  MOZ_CAN_RUN_SCRIPT NS_IMETHOD SetFlags(uint32_t aFlags) override;
+  MOZ_CAN_RUN_SCRIPT nsresult Init(Document& aDoc, Element* aRoot,
+                                   nsISelectionController* aSelCon,
+                                   uint32_t aFlags,
+                                   const nsAString& aValue) final;
+  MOZ_CAN_RUN_SCRIPT NS_IMETHOD BeginningOfDocument() final;
+  MOZ_CAN_RUN_SCRIPT NS_IMETHOD SetFlags(uint32_t aFlags) final;
 
   NS_IMETHOD GetDocumentCharacterSet(nsACString& aCharacterSet) final;
   MOZ_CAN_RUN_SCRIPT NS_IMETHOD
   SetDocumentCharacterSet(const nsACString& aCharacterSet) final;
 
   bool IsEmpty() const final;
 
   bool CanPaste(int32_t aClipboardType) const final;
   using EditorBase::CanPaste;
 
   MOZ_CAN_RUN_SCRIPT nsresult PasteTransferableAsAction(
       nsITransferable* aTransferable, nsIPrincipal* aPrincipal = nullptr) final;
 
-  MOZ_CAN_RUN_SCRIPT NS_IMETHOD DeleteNode(nsINode* aNode) override;
-
-  MOZ_CAN_RUN_SCRIPT NS_IMETHOD InsertLineBreak() override;
+  MOZ_CAN_RUN_SCRIPT NS_IMETHOD DeleteNode(nsINode* aNode) final;
+
+  MOZ_CAN_RUN_SCRIPT NS_IMETHOD InsertLineBreak() final;
 
   /**
    * PreHandleMouseDown() and PreHandleMouseUp() are called before
    * HTMLEditorEventListener handles them.  The coming event may be
    * non-acceptable event.
    */
   void PreHandleMouseDown(const dom::MouseEvent& aMouseDownEvent);
   void PreHandleMouseUp(const dom::MouseEvent& aMouseUpEvent);
@@ -181,25 +181,25 @@ class HTMLEditor final : public EditorBa
   /**
    * PreHandleSelectionChangeCommand() and PostHandleSelectionChangeCommand()
    * are called before or after handling a command which may change selection
    * and/or scroll position.
    */
   void PreHandleSelectionChangeCommand(Command aCommand);
   void PostHandleSelectionChangeCommand(Command aCommand);
 
-  MOZ_CAN_RUN_SCRIPT virtual nsresult HandleKeyPressEvent(
-      WidgetKeyboardEvent* aKeyboardEvent) override;
-  virtual nsIContent* GetFocusedContent() const override;
-  virtual nsIContent* GetFocusedContentForIME() const override;
-  virtual bool IsActiveInDOMWindow() const override;
-  virtual dom::EventTarget* GetDOMEventTarget() const override;
-  virtual Element* FindSelectionRoot(nsINode* aNode) const override;
-  virtual bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) const override;
-  virtual nsresult GetPreferredIMEState(widget::IMEState* aState) override;
+  MOZ_CAN_RUN_SCRIPT nsresult
+  HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) final;
+  nsIContent* GetFocusedContent() const final;
+  nsIContent* GetFocusedContentForIME() const final;
+  bool IsActiveInDOMWindow() const final;
+  dom::EventTarget* GetDOMEventTarget() const final;
+  Element* FindSelectionRoot(nsINode* aNode) const final;
+  bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) const final;
+  nsresult GetPreferredIMEState(widget::IMEState* aState) final;
 
   /**
    * GetBackgroundColorState() returns what the background color of the
    * selection.
    *
    * @param aMixed      true if there is more than one font color
    * @param aOutColor   Color string. "" is returned for none.
    */
@@ -419,18 +419,16 @@ class HTMLEditor final : public EditorBa
 
     mIsAbsolutelyPositioningEnabled = aEnable;
     RefreshEditingUI();
   }
   bool IsAbsolutePositionEditorEnabled() const {
     return mIsAbsolutelyPositioningEnabled;
   }
 
-  // non-virtual methods of interface methods
-
   /**
    * returns the deepest absolutely positioned container of the selection
    * if it exists or null.
    */
   MOZ_CAN_RUN_SCRIPT already_AddRefed<Element>
   GetAbsolutelyPositionedSelectionContainer() const;
 
   Element* GetPositionedElement() const { return mAbsolutelyPositionedObject; }
@@ -716,20 +714,20 @@ class HTMLEditor final : public EditorBa
    */
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult ReplaceTextWithTransaction(
       dom::Text& aTextNode, uint32_t aOffset, uint32_t aLength,
       const nsAString& aStringToInsert);
 
   /**
    * InsertTextWithTransaction() inserts aStringToInsert at aPointToInsert.
    */
-  MOZ_CAN_RUN_SCRIPT virtual nsresult InsertTextWithTransaction(
+  MOZ_CAN_RUN_SCRIPT nsresult InsertTextWithTransaction(
       Document& aDocument, const nsAString& aStringToInsert,
       const EditorRawDOMPoint& aPointToInsert,
-      EditorRawDOMPoint* aPointAfterInsertedString = nullptr) override;
+      EditorRawDOMPoint* aPointAfterInsertedString = nullptr) final;
 
   /**
    * CopyLastEditableChildStyles() clones inline container elements into
    * aPreviousBlock to aNewBlock to keep using same style in it.
    *
    * @param aPreviousBlock      The previous block element.  All inline
    *                            elements which are last sibling of each level
    *                            are cloned to aNewBlock.
@@ -748,23 +746,22 @@ class HTMLEditor final : public EditorBa
    * element to have at least one line-height, this inserts <br> element
    * automatically.
    *
    * @param aElement            Block element to be removed.
    */
   MOZ_CAN_RUN_SCRIPT nsresult
   RemoveBlockContainerWithTransaction(Element& aElement);
 
-  virtual Element* GetEditorRoot() const override;
-  MOZ_CAN_RUN_SCRIPT virtual nsresult RemoveAttributeOrEquivalent(
-      Element* aElement, nsAtom* aAttribute,
-      bool aSuppressTransaction) override;
-  MOZ_CAN_RUN_SCRIPT virtual nsresult SetAttributeOrEquivalent(
+  Element* GetEditorRoot() const final;
+  MOZ_CAN_RUN_SCRIPT nsresult RemoveAttributeOrEquivalent(
+      Element* aElement, nsAtom* aAttribute, bool aSuppressTransaction) final;
+  MOZ_CAN_RUN_SCRIPT nsresult SetAttributeOrEquivalent(
       Element* aElement, nsAtom* aAttribute, const nsAString& aValue,
-      bool aSuppressTransaction) override;
+      bool aSuppressTransaction) final;
   using EditorBase::RemoveAttributeOrEquivalent;
   using EditorBase::SetAttributeOrEquivalent;
 
   /**
    * Returns container element of ranges in Selection.  If Selection is
    * collapsed, returns focus container node (or its parent element).
    * If Selection selects only one element node, returns the element node.
    * If Selection is only one range, returns common ancestor of the range.
@@ -2216,17 +2213,17 @@ class HTMLEditor final : public EditorBa
                       AutoRangeArray& aRangesToDelete);
 
   /**
    * This method handles "delete selection" commands.
    *
    * @param aDirectionAndAmount Direction of the deletion.
    * @param aStripWrappers      Must be eStrip or eNoStrip.
    */
-  [[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual EditActionResult
+  [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
   HandleDeleteSelection(nsIEditor::EDirection aDirectionAndAmount,
                         nsIEditor::EStripWrappers aStripWrappers) final;
 
   class AutoDeleteRangesHandler;
 
   /**
    * DeleteMostAncestorMailCiteElementIfEmpty() deletes most ancestor
    * mail cite element (`<blockquote type="cite">` or
@@ -2639,22 +2636,21 @@ class HTMLEditor final : public EditorBa
   AddZIndexAsSubAction(int32_t aChange);
 
   /**
    * OnDocumentModified() is called when editor content is changed.
    */
   MOZ_CAN_RUN_SCRIPT nsresult OnDocumentModified();
 
  protected:  // Called by helper classes.
-  MOZ_CAN_RUN_SCRIPT virtual void OnStartToHandleTopLevelEditSubAction(
+  MOZ_CAN_RUN_SCRIPT void OnStartToHandleTopLevelEditSubAction(
       EditSubAction aTopLevelEditSubAction,
       nsIEditor::EDirection aDirectionOfTopLevelEditSubAction,
-      ErrorResult& aRv) override;
-  MOZ_CAN_RUN_SCRIPT virtual nsresult OnEndHandlingTopLevelEditSubAction()
-      override;
+      ErrorResult& aRv) final;
+  MOZ_CAN_RUN_SCRIPT nsresult OnEndHandlingTopLevelEditSubAction() final;
 
  protected:  // Shouldn't be used by friend classes
   virtual ~HTMLEditor();
 
   template <typename PT, typename CT>
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT MOZ_NEVER_INLINE_DEBUG nsresult
   CollapseSelectionTo(const EditorDOMPointBase<PT, CT>& aPoint) const {
     ErrorResult error;
@@ -2692,17 +2688,17 @@ class HTMLEditor final : public EditorBa
    * `<br>` elements if they are required for `<body>` or document element.
    * And collapse selection at the end if there is no selection ranges.
    * XXX I think that this should work with active editing host unless
    *     all over the document is ediable (i.e., in design mode or `<body>`
    *     or `<html>` has `contenteditable` attribute).
    */
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InitEditorContentAndSelection();
 
-  MOZ_CAN_RUN_SCRIPT virtual nsresult SelectAllInternal() override;
+  MOZ_CAN_RUN_SCRIPT nsresult SelectAllInternal() final;
 
   /**
    * SelectContentInternal() sets Selection to aContentToSelect to
    * aContentToSelect + 1 in parent of aContentToSelect.
    *
    * @param aContentToSelect    The content which should be selected.
    */
   MOZ_CAN_RUN_SCRIPT nsresult
@@ -3345,24 +3341,23 @@ class HTMLEditor final : public EditorBa
    * This sets background on the appropriate container element (table, cell,)
    * or calls to set the page background.
    */
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
   SetCSSBackgroundColorWithTransaction(const nsAString& aColor);
   MOZ_CAN_RUN_SCRIPT nsresult
   SetHTMLBackgroundColorWithTransaction(const nsAString& aColor);
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void InitializeSelectionAncestorLimit(
-      nsIContent& aAncestorLimit) const override;
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY void InitializeSelectionAncestorLimit(
+      nsIContent& aAncestorLimit) const final;
 
   /**
    * Make the given selection span the entire document.
    */
-  [[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual nsresult SelectEntireDocument()
-      override;
+  [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SelectEntireDocument() final;
 
   /**
    * Use this to assure that selection is set after attribute nodes when
    * trying to collapse selection at begining of a block node
    * e.g., when setting at beginning of a table cell
    * This will stop at a table, however, since we don't want to
    * "drill down" into nested tables.
    */
@@ -3417,32 +3412,32 @@ class HTMLEditor final : public EditorBa
     nsCOMPtr<Document> mSourceDoc;
     EditorDOMPoint mPointToInsert;
     EditAction mEditAction;
     bool mIsSafe;
     bool mDoDeleteSelection;
     bool mNeedsToDispatchBeforeInputEvent;
   };
 
-  virtual void CreateEventListeners() override;
-  virtual nsresult InstallEventListeners() override;
-  virtual void RemoveEventListeners() override;
+  void CreateEventListeners() final;
+  nsresult InstallEventListeners() final;
+  void RemoveEventListeners() final;
 
   bool ShouldReplaceRootElement() const;
   MOZ_CAN_RUN_SCRIPT void NotifyRootChanged();
   Element* GetBodyElement() const;
 
   /**
    * Get the focused node of this editor.
    * @return    If the editor has focus, this returns the focused node.
    *            Otherwise, returns null.
    */
   nsINode* GetFocusedNode() const;
 
-  virtual already_AddRefed<Element> GetInputEventTargetElement() const override;
+  already_AddRefed<Element> GetInputEventTargetElement() const final;
 
   /**
    * Return TRUE if aElement is a table-related elemet and caret was set.
    */
   MOZ_CAN_RUN_SCRIPT bool SetCaretInTableCell(dom::Element* aElement);
 
   /**
    * HandleTabKeyPressInTable() handles "Tab" key press in table if selection
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -29,17 +29,19 @@ enum class EditSubAction : int32_t;
 namespace dom {
 class Selection;
 }  // namespace dom
 
 /**
  * The text editor implementation.
  * Use to edit text document represented as a DOM tree.
  */
-class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
+class TextEditor final : public EditorBase,
+                         public nsITimerCallback,
+                         public nsINamed {
  public:
   /****************************************************************************
    * NOTE: DO NOT MAKE YOUR NEW METHODS PUBLIC IF they are called by other
    *       classes under libeditor except EditorEventListener and
    *       HTMLEditorEventListener because each public method which may fire
    *       eEditorInput event will need to instantiate new stack class for
    *       managing input type value of eEditorInput and cache some objects
    *       for smarter handling.  In other words, when you add new root
@@ -57,58 +59,57 @@ class TextEditor : public EditorBase, pu
   static const TextEditor* GetFrom(const nsIEditor* aEditor) {
     return aEditor ? aEditor->GetAsTextEditor() : nullptr;
   }
 
   NS_DECL_NSITIMERCALLBACK
   NS_DECL_NSINAMED
 
   // Overrides of nsIEditor
-  NS_IMETHOD GetTextLength(int32_t* aCount) override;
-  MOZ_CAN_RUN_SCRIPT NS_IMETHOD Paste(int32_t aClipboardType) override {
+  NS_IMETHOD GetTextLength(int32_t* aCount) final;
+  MOZ_CAN_RUN_SCRIPT NS_IMETHOD Paste(int32_t aClipboardType) final {
     const nsresult rv = TextEditor::PasteAsAction(aClipboardType, true);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                          "HTMLEditor::PasteAsAction() failed");
     return rv;
   }
 
   // Shouldn't be used internally, but we need these using declarations for
   // avoiding warnings of clang.
   using EditorBase::CanCopy;
   using EditorBase::CanCut;
   using EditorBase::CanPaste;
 
   // Overrides of EditorBase
-  MOZ_CAN_RUN_SCRIPT virtual nsresult Init(Document& aDoc, Element* aRoot,
-                                           nsISelectionController* aSelCon,
-                                           uint32_t aFlags,
-                                           const nsAString& aValue) override;
+  MOZ_CAN_RUN_SCRIPT nsresult Init(Document& aDoc, Element* aRoot,
+                                   nsISelectionController* aSelCon,
+                                   uint32_t aFlags,
+                                   const nsAString& aValue) final;
+
+  bool IsEmpty() const final;
 
-  bool IsEmpty() const override;
+  bool CanPaste(int32_t aClipboardType) const final;
 
-  bool CanPaste(int32_t aClipboardType) const override;
+  MOZ_CAN_RUN_SCRIPT nsresult PasteTransferableAsAction(
+      nsITransferable* aTransferable, nsIPrincipal* aPrincipal = nullptr) final;
+
+  bool CanPasteTransferable(nsITransferable* aTransferable) final;
 
   MOZ_CAN_RUN_SCRIPT nsresult
-  PasteTransferableAsAction(nsITransferable* aTransferable,
-                            nsIPrincipal* aPrincipal = nullptr) override;
-
-  virtual bool CanPasteTransferable(nsITransferable* aTransferable) override;
+  HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) final;
 
-  MOZ_CAN_RUN_SCRIPT virtual nsresult HandleKeyPressEvent(
-      WidgetKeyboardEvent* aKeyboardEvent) override;
-
-  virtual dom::EventTarget* GetDOMEventTarget() const override;
+  dom::EventTarget* GetDOMEventTarget() const final;
 
   MOZ_CAN_RUN_SCRIPT nsresult
   PasteAsAction(int32_t aClipboardType, bool aDispatchPasteEvent,
-                nsIPrincipal* aPrincipal = nullptr) override;
+                nsIPrincipal* aPrincipal = nullptr) final;
 
   MOZ_CAN_RUN_SCRIPT nsresult
   PasteAsQuotationAsAction(int32_t aClipboardType, bool aDispatchPasteEvent,
-                           nsIPrincipal* aPrincipal = nullptr) override;
+                           nsIPrincipal* aPrincipal = nullptr) final;
 
   /**
    * The maximum number of characters allowed.
    *   default: -1 (unlimited).
    */
   int32_t MaxTextLength() const { return mMaxTextLength; }
   void SetMaxTextLength(int32_t aLength) { mMaxTextLength = aLength; }
 
@@ -125,17 +126,17 @@ class TextEditor : public EditorBase, pu
    *                            called by system.
    */
   MOZ_CAN_RUN_SCRIPT nsresult SetTextAsAction(
       const nsAString& aString,
       AllowBeforeInputEventCancelable aAllowBeforeInputEventCancelable,
       nsIPrincipal* aPrincipal = nullptr);
 
   MOZ_CAN_RUN_SCRIPT nsresult
-  InsertLineBreakAsAction(nsIPrincipal* aPrincipal = nullptr) override;
+  InsertLineBreakAsAction(nsIPrincipal* aPrincipal = nullptr) final;
 
   /**
    * ComputeTextValue() computes plaintext value of this editor.  This may be
    * too expensive if it's in hot path.
    *
    * @param aDocumentEncoderFlags   Flags of nsIDocumentEncoder.
    * @param aCharset                Encoding of the document.
    */
@@ -195,22 +196,21 @@ class TextEditor : public EditorBase, pu
   /****************************************************************************
    * Some friend classes are allowed to call the following protected methods.
    * However, those methods won't prepare caches of some objects which are
    * necessary for them.  So, if you call them from friend classes, you need
    * to make sure that AutoEditActionDataSetter is created.
    ****************************************************************************/
 
   // Overrides of EditorBase
-  MOZ_CAN_RUN_SCRIPT virtual nsresult RemoveAttributeOrEquivalent(
-      Element* aElement, nsAtom* aAttribute,
-      bool aSuppressTransaction) override;
-  MOZ_CAN_RUN_SCRIPT virtual nsresult SetAttributeOrEquivalent(
+  MOZ_CAN_RUN_SCRIPT nsresult RemoveAttributeOrEquivalent(
+      Element* aElement, nsAtom* aAttribute, bool aSuppressTransaction) final;
+  MOZ_CAN_RUN_SCRIPT nsresult SetAttributeOrEquivalent(
       Element* aElement, nsAtom* aAttribute, const nsAString& aValue,
-      bool aSuppressTransaction) override;
+      bool aSuppressTransaction) final;
   using EditorBase::RemoveAttributeOrEquivalent;
   using EditorBase::SetAttributeOrEquivalent;
 
   /**
    * Replace existed string with aString.  Caller must guarantee that there
    * is a placeholder transaction which will have the transaction.
    *
    * @ param aString   The string to be set.
@@ -355,22 +355,22 @@ class TextEditor : public EditorBase, pu
    *   nsIEditor::eNewlinesPasteToFirst (1) or any other value:
    *     remove the first newline and all characters following it.
    *
    * @param aString the string to be modified in place.
    */
   void HandleNewLinesInStringForSingleLineEditor(nsString& aString) const;
 
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult HandleInsertText(
-      EditSubAction aEditSubAction, const nsAString& aInsertionString) override;
+      EditSubAction aEditSubAction, const nsAString& aInsertionString) final;
 
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InsertDroppedDataTransferAsAction(
       AutoEditActionDataSetter& aEditActionData,
       dom::DataTransfer& aDataTransfer, const EditorDOMPoint& aDroppedAt,
-      dom::Document* aSrcDocument) override;
+      dom::Document* aSrcDocument) final;
 
   /**
    * HandleDeleteSelectionInternal() is a helper method of
    * HandleDeleteSelection().  Must be called only when the instance is
    * TextEditor.
    * NOTE: This method creates SelectionBatcher.  Therefore, each caller
    *       needs to check if the editor is still available even if this returns
    *       NS_OK.
@@ -382,17 +382,17 @@ class TextEditor : public EditorBase, pu
   /**
    * This method handles "delete selection" commands.
    *
    * @param aDirectionAndAmount Direction of the deletion.
    * @param aStripWrappers      Must be nsIEditor::eNoStrip.
    */
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
   HandleDeleteSelection(nsIEditor::EDirection aDirectionAndAmount,
-                        nsIEditor::EStripWrappers aStripWrappers) override;
+                        nsIEditor::EStripWrappers aStripWrappers) final;
 
   /**
    * ComputeValueFromTextNodeAndBRElement() tries to compute "value" of
    * this editor content only with text nodes and `<br>` elements.
    * If this succeeds to compute the value, it's returned with aValue and
    * the result is marked as "handled".  Otherwise, the caller needs to
    * compute it with another way.
    */
@@ -410,22 +410,21 @@ class TextEditor : public EditorBase, pu
   /**
    * EnsureCaretNotAtEndOfTextNode() collapses selection at the padding `<br>`
    * element (i.e., container becomes the anonymous `<div>` element) if
    * `Selection` is at end of the text node.
    */
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult EnsureCaretNotAtEndOfTextNode();
 
  protected:  // Called by helper classes.
-  MOZ_CAN_RUN_SCRIPT virtual void OnStartToHandleTopLevelEditSubAction(
+  MOZ_CAN_RUN_SCRIPT void OnStartToHandleTopLevelEditSubAction(
       EditSubAction aTopLevelEditSubAction,
       nsIEditor::EDirection aDirectionOfTopLevelEditSubAction,
-      ErrorResult& aRv) override;
-  MOZ_CAN_RUN_SCRIPT virtual nsresult OnEndHandlingTopLevelEditSubAction()
-      override;
+      ErrorResult& aRv) final;
+  MOZ_CAN_RUN_SCRIPT nsresult OnEndHandlingTopLevelEditSubAction() final;
 
   /**
    * EnsurePaddingBRElementForEmptyEditor() creates padding <br> element for
    * empty editor or changes padding <br> element for empty last line to for
    * empty editor when we're empty.
    */
   MOZ_CAN_RUN_SCRIPT nsresult EnsurePaddingBRElementForEmptyEditor();
 
@@ -452,27 +451,27 @@ class TextEditor : public EditorBase, pu
    * If it's direct user input such as pasting or dropping text, this
    * returns false even if we may echo password.
    */
   bool CanEchoPasswordNow() const;
 
   /**
    * Make the given selection span the entire document.
    */
-  MOZ_CAN_RUN_SCRIPT virtual nsresult SelectEntireDocument() override;
+  MOZ_CAN_RUN_SCRIPT nsresult SelectEntireDocument() final;
 
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
-  InsertWithQuotationsAsSubAction(const nsAString& aQuotedText) override;
+  InsertWithQuotationsAsSubAction(const nsAString& aQuotedText) final;
 
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
   InsertTextFromTransferable(nsITransferable* transferable);
 
   bool IsCopyToClipboardAllowedInternal() const final;
 
-  virtual already_AddRefed<Element> GetInputEventTargetElement() const override;
+  already_AddRefed<Element> GetInputEventTargetElement() const final;
 
   /**
    * See SetUnmaskRange() and SetUnmaskRangeAndNotify() for the detail.
    *
    * @param aForceStartMasking  If true, forcibly starts masking.  This should
    *                            be used only when `nsIEditor::Mask()` is called.
    */
   MOZ_CAN_RUN_SCRIPT nsresult SetUnmaskRangeInternal(uint32_t aStart,
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -382,16 +382,17 @@ interface nsIEditor  : nsISupports
    * editable text nodes or inline elements which can have text nodes as their
    * children, collapses selection at start of the editing host.  If there is
    * an editable text node which is not collapsed, collapses selection at
    * start of the text node.  If there is an editable inline element which
    * cannot have text nodes as its child, collapses selection at before the
    * element node.  Otherwise, collapses selection at start of the editing
    * host.
    */
+  [can_run_script]
   void beginningOfDocument();
 
   /** sets the document selection to the end of the document */
   void endOfDocument();
 
   /* ------------ Node manipulation methods -------------- */
 
   /**