` 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(
EditSubAction aTopLevelEditSubAction,
nsIEditor::EDirection aDirectionOfTopLevelEditSubAction,
ErrorResult& aRv) override;
MOZ_CAN_RUN_SCRIPT virtual nsresult OnEndHandlingTopLevelEditSubAction()
override;
/**
* EnsurePaddingBRElementForEmptyEditor() creates padding
element for
* empty editor or changes padding
element for empty last line to for
* empty editor when we're empty.
*/
MOZ_CAN_RUN_SCRIPT nsresult EnsurePaddingBRElementForEmptyEditor();
/**
* HandleInlineSpellCheckAfterEdit() does spell-check after handling top level
* edit subaction.
*/
nsresult HandleInlineSpellCheckAfterEdit() {
MOZ_ASSERT(IsEditActionDataAvailable());
if (!GetSpellCheckRestartPoint().IsSet()) {
return NS_OK; // Maybe being initialized.
}
nsresult rv = HandleInlineSpellCheck(GetSpellCheckRestartPoint());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to spellcheck");
ClearSpellCheckRestartPoint();
return rv;
}
protected: // Shouldn't be used by friend classes
virtual ~TextEditor();
/**
* InitEditorContentAndSelection() may insert a padding `
` element for
* if it's required in the anonymous `
` element and collapse selection
* at the end if there is no selection ranges.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InitEditorContentAndSelection();
/**
* CanEchoPasswordNow() returns true if currently we can echo password.
* 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;
/**
* OnInputText() is called when user inputs text with keyboard or something.
*
* @param aStringToInsert The string to insert.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
OnInputText(const nsAString& aStringToInsert);
/**
* PrepareInsertContent() is a helper method of InsertTextAt(),
* HTMLEditor::DoInsertHTMLWithContext(). They insert content coming from
* clipboard or drag and drop. Before that, they may need to remove selected
* contents and adjust selection. This does them instead.
*
* @param aPointToInsert Point to insert. Must be set. Callers
* shouldn't use this instance after calling this
* method because this method may cause changing
* the DOM tree and Selection.
* @param aDoDeleteSelection true if selected content should be removed.
*/
MOZ_CAN_RUN_SCRIPT nsresult PrepareToInsertContent(
const EditorDOMPoint& aPointToInsert, bool aDoDeleteSelection);
/**
* InsertTextAt() inserts aStringToInsert at aPointToInsert.
*
* @param aStringToInsert The string which you want to insert.
* @param aPointToInsert The insertion point.
* @param aDoDeleteSelection true if you want this to delete selected
* content. Otherwise, false.
*/
MOZ_CAN_RUN_SCRIPT nsresult InsertTextAt(const nsAString& aStringToInsert,
const EditorDOMPoint& aPointToInsert,
bool aDoDeleteSelection);
/**
* InsertWithQuotationsAsSubAction() inserts aQuotedText with appending ">"
* to start of every line.
*
* @param aQuotedText String to insert. This will be quoted by ">"
* automatically.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual nsresult
InsertWithQuotationsAsSubAction(const nsAString& aQuotedText);
/**
* Return true if the data is safe to insert as the source and destination
* principals match, or we are in a editor context where this doesn't matter.
* Otherwise, the data must be sanitized first.
*/
bool IsSafeToInsertData(const Document* aSourceDoc) const;
/**
* GetAndInitDocEncoder() returns a document encoder instance for aFormatType
* after initializing it. The result may be cached for saving recreation
* cost.
*
* @param aFormatType MIME type like "text/plain".
* @param aDocumentEncoderFlags Flags of nsIDocumentEncoder.
* @param aCharset Encoding of the document.
*/
already_AddRefed GetAndInitDocEncoder(
const nsAString& aFormatType, uint32_t aDocumentEncoderFlags,
const nsACString& aCharset) const;
/**
* ComputeValueInternal() computes string value of this editor for given
* format. This may be too expensive if it's in hot path.
*
* @param aFormatType MIME type like "text/plain".
* @param aDocumentEncoderFlags Flags of nsIDocumentEncoder.
* @param aCharset Encoding of the document.
*/
nsresult ComputeValueInternal(const nsAString& aFormatType,
uint32_t aDocumentEncoderFlags,
nsAString& aOutputString) const;
/**
* Factored methods for handling insertion of data from transferables
* (drag&drop or clipboard).
*/
virtual nsresult PrepareTransferable(nsITransferable** transferable);
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
InsertTextFromTransferable(nsITransferable* transferable);
/**
* Shared outputstring; returns whether selection is collapsed and resulting
* string.
*/
nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed,
nsAString& aResult) const;
/**
* See comment of IsCopyToClipboardAllowed() for the detail.
*/
bool IsCopyToClipboardAllowedInternal() const;
bool FireClipboardEvent(EventMessage aEventMessage, int32_t aSelectionType,
bool* aActionTaken = nullptr);
MOZ_CAN_RUN_SCRIPT bool UpdateMetaCharset(Document& aDocument,
const nsACString& aCharacterSet);
/**
* EnsureComposition() should be called by composition event handlers. This
* tries to get the composition for the event and set it to mComposition.
* However, this may fail because the composition may be committed before
* the event comes to the editor.
*
* @return true if there is a composition. Otherwise, for example,
* a composition event handler in web contents moved focus
* for committing the composition, returns false.
*/
bool EnsureComposition(WidgetCompositionEvent& aCompositionEvent);
virtual already_AddRefed GetInputEventTargetElement() const override;
/**
* 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,
uint32_t aLength,
uint32_t aTimeout,
bool aNotify,
bool aForceStartMasking);
protected:
mutable nsCOMPtr mCachedDocumentEncoder;
// Timer to mask unmasked characters automatically. Used only when it's
// a password field.
nsCOMPtr mMaskTimer;
mutable nsString mCachedDocumentEncoderType;
int32_t mMaxTextLength;
// Unmasked character range. Used only when it's a password field.
// If mUnmaskedLength is 0, it means there is no unmasked characters.
uint32_t mUnmaskedStart;
uint32_t mUnmaskedLength;
// Set to true if all characters are masked or waiting notification from
// `mMaskTimer`. Otherwise, i.e., part of or all of password is unmasked
// without setting `mMaskTimer`, set to false.
bool mIsMaskingPassword;
friend class DeleteNodeTransaction;
friend class EditorBase;
friend class InsertNodeTransaction;
};
} // namespace mozilla
mozilla::TextEditor* nsIEditor::AsTextEditor() {
return static_cast(this);
}
const mozilla::TextEditor* nsIEditor::AsTextEditor() const {
return static_cast(this);
}
#endif // #ifndef mozilla_TextEditor_h