Bug 1714918 - Sort out editor class accessors of nsIEditor r=m_kato

For consistency with the similar internal DOM API, `As*()` should just cast
the type without checking editor type.  Instead, `GetAs*()` should do it.

Differential Revision: https://phabricator.services.mozilla.com/D117381
This commit is contained in:
Masayuki Nakano 2021-06-11 03:01:08 +00:00
parent 38119d0d9d
commit db1228b24c
17 changed files with 155 additions and 171 deletions

View File

@ -12120,7 +12120,7 @@ nsDocShell::GetEditor(nsIEditor** aEditor) {
NS_IMETHODIMP
nsDocShell::SetEditor(nsIEditor* aEditor) {
HTMLEditor* htmlEditor = aEditor ? aEditor->AsHTMLEditor() : nullptr;
HTMLEditor* htmlEditor = aEditor ? aEditor->GetAsHTMLEditor() : nullptr;
// If TextEditor comes, throw an error.
if (aEditor && !htmlEditor) {
return NS_ERROR_INVALID_ARG;

View File

@ -371,8 +371,8 @@ nsresult nsEditingSession::SetupEditorOnWindow(nsPIDOMWindowOuter& aWindow) {
// create and set editor
// Try to reuse an existing editor
nsCOMPtr<nsIEditor> editor = do_QueryReferent(mExistingEditor);
RefPtr<HTMLEditor> htmlEditor = editor ? editor->AsHTMLEditor() : nullptr;
MOZ_ASSERT(!editor || htmlEditor);
RefPtr<HTMLEditor> htmlEditor = HTMLEditor::GetFrom(editor);
MOZ_ASSERT_IF(editor, htmlEditor);
if (htmlEditor) {
htmlEditor->PreDestroy(false);
} else {

View File

@ -2082,7 +2082,7 @@ Result<RefPtr<Element>, nsresult> EditorBase::CreateNodeWithTransaction(
"Rangeupdater::SelAdjCreateNode() failed, but ignored");
}
if (AsHTMLEditor() && newElement) {
if (IsHTMLEditor() && newElement) {
TopLevelEditSubActionDataRef().DidCreateElement(*this, *newElement);
}
@ -2149,7 +2149,7 @@ nsresult EditorBase::InsertNodeWithTransaction(
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"RangeUpdater::SelAdjInsertNode() failed, but ignored");
if (AsHTMLEditor()) {
if (IsHTMLEditor()) {
TopLevelEditSubActionDataRef().DidInsertContent(*this, aContentToInsert);
}
@ -2229,7 +2229,7 @@ nsresult EditorBase::DeleteNodeWithTransaction(nsIContent& aContent) {
!ignoredError.Failed(),
"TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
if (AsHTMLEditor()) {
if (IsHTMLEditor()) {
TopLevelEditSubActionDataRef().WillDeleteContent(*this, aContent);
}
@ -2411,10 +2411,9 @@ void EditorBase::DispatchInputEvent() {
if (NS_WARN_IF(!targetElement)) {
return;
}
RefPtr<TextEditor> textEditor = AsTextEditor();
RefPtr<DataTransfer> dataTransfer = GetInputEventDataTransfer();
DebugOnly<nsresult> rvIgnored = nsContentUtils::DispatchInputEvent(
targetElement, eEditorInput, ToInputType(GetEditAction()), textEditor,
targetElement, eEditorInput, ToInputType(GetEditAction()), this,
dataTransfer ? InputEventOptions(dataTransfer,
InputEventOptions::NeverCancelable::No)
: InputEventOptions(GetInputEventData(),
@ -2648,7 +2647,7 @@ void EditorBase::DoInsertText(Text& aText, uint32_t aOffset,
NS_WARNING("Text::InsertData() failed");
return;
}
if (!AsHTMLEditor() && !aStringToInsert.IsEmpty()) {
if (IsTextEditor() && !aStringToInsert.IsEmpty()) {
aRv = MOZ_KnownLive(AsTextEditor())
->DidInsertText(aText.TextLength(), aOffset,
aStringToInsert.Length());
@ -2658,7 +2657,7 @@ void EditorBase::DoInsertText(Text& aText, uint32_t aOffset,
void EditorBase::DoDeleteText(Text& aText, uint32_t aOffset, uint32_t aCount,
ErrorResult& aRv) {
if (!AsHTMLEditor() && aCount > 0) {
if (IsTextEditor() && aCount > 0) {
AsTextEditor()->WillDeleteText(aText.TextLength(), aOffset, aCount);
}
aText.DeleteData(aOffset, aCount, aRv);
@ -2672,7 +2671,7 @@ void EditorBase::DoDeleteText(Text& aText, uint32_t aOffset, uint32_t aCount,
void EditorBase::DoReplaceText(Text& aText, uint32_t aOffset, uint32_t aCount,
const nsAString& aStringToInsert,
ErrorResult& aRv) {
if (!AsHTMLEditor() && aCount > 0) {
if (IsTextEditor() && aCount > 0) {
AsTextEditor()->WillDeleteText(aText.TextLength(), aOffset, aCount);
}
aText.ReplaceData(aOffset, aCount, aStringToInsert, aRv);
@ -2684,7 +2683,7 @@ void EditorBase::DoReplaceText(Text& aText, uint32_t aOffset, uint32_t aCount,
NS_WARNING("Text::ReplaceData() failed");
return;
}
if (!AsHTMLEditor() && !aStringToInsert.IsEmpty()) {
if (IsTextEditor() && !aStringToInsert.IsEmpty()) {
aRv = MOZ_KnownLive(AsTextEditor())
->DidInsertText(aText.TextLength(), aOffset,
aStringToInsert.Length());
@ -2694,7 +2693,7 @@ void EditorBase::DoReplaceText(Text& aText, uint32_t aOffset, uint32_t aCount,
void EditorBase::DoSetText(Text& aText, const nsAString& aStringToSet,
ErrorResult& aRv) {
if (!AsHTMLEditor()) {
if (IsTextEditor()) {
uint32_t length = aText.TextLength();
if (length > 0) {
AsTextEditor()->WillDeleteText(length, 0, length);
@ -2709,7 +2708,7 @@ void EditorBase::DoSetText(Text& aText, const nsAString& aStringToSet,
NS_WARNING("Text::SetData() failed");
return;
}
if (!AsHTMLEditor() && !aStringToSet.IsEmpty()) {
if (IsTextEditor() && !aStringToSet.IsEmpty()) {
aRv = MOZ_KnownLive(AsTextEditor())
->DidInsertText(aText.Length(), 0, aStringToSet.Length());
NS_WARNING_ASSERTION(!aRv.Failed(), "TextEditor::DidInsertText() failed");
@ -2864,7 +2863,7 @@ EditorRawDOMPoint EditorBase::FindBetterInsertionPoint(
// we'll adjust aInOutNode and aInOutOffset to the preceding text node,
// if any.
if (!aPoint.IsStartOfContainer()) {
if (AsHTMLEditor()) {
if (IsHTMLEditor()) {
// Fall back to a slow path that uses GetChildAt_Deprecated() for
// Thunderbird's plaintext editor.
nsIContent* child = aPoint.GetPreviousSiblingOfChild();
@ -3136,7 +3135,7 @@ nsresult EditorBase::InsertTextIntoTextNodeWithTransaction(
"EditorBase::DoTransactionInternal() failed");
EndUpdateViewBatch();
if (AsHTMLEditor() && pointToInsert.IsSet()) {
if (IsHTMLEditor() && pointToInsert.IsSet()) {
EditorDOMPointInText begin, end;
Tie(begin, end) = ComputeInsertedRange(pointToInsert, aStringToInsert);
if (begin.IsSet() && end.IsSet()) {
@ -3184,7 +3183,7 @@ nsresult EditorBase::NotifyDocumentListeners(
TDocumentListenerNotification aNotificationType) {
switch (aNotificationType) {
case eDocumentCreated:
if (!AsHTMLEditor()) {
if (IsTextEditor()) {
return NS_OK;
}
if (RefPtr<ComposerCommandsUpdater> composerCommandsUpdate =
@ -3195,7 +3194,7 @@ nsresult EditorBase::NotifyDocumentListeners(
case eDocumentToBeDestroyed: {
RefPtr<ComposerCommandsUpdater> composerCommandsUpdate =
AsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr;
IsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr;
if (!mDocStateListeners.Length() && !composerCommandsUpdate) {
return NS_OK;
}
@ -3237,7 +3236,7 @@ nsresult EditorBase::NotifyDocumentListeners(
mDocDirtyState = docIsDirty;
RefPtr<ComposerCommandsUpdater> composerCommandsUpdate =
AsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr;
IsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr;
if (!mDocStateListeners.Length() && !composerCommandsUpdate) {
return NS_OK;
}
@ -3273,7 +3272,7 @@ nsresult EditorBase::NotifyDocumentListeners(
nsresult EditorBase::SetTextNodeWithoutTransaction(const nsAString& aString,
Text& aTextNode) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsTextEditor());
MOZ_ASSERT(IsPlaintextEditor());
MOZ_ASSERT(!IsUndoRedoEnabled());
@ -3366,7 +3365,7 @@ nsresult EditorBase::DeleteTextWithTransaction(Text& aTextNode,
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditorBase::DoTransactionInternal() failed");
if (AsHTMLEditor()) {
if (IsHTMLEditor()) {
TopLevelEditSubActionDataRef().DidDeleteText(
*this, EditorRawDOMPoint(&aTextNode, aOffset));
}
@ -3699,8 +3698,7 @@ void EditorBase::EndUpdateViewBatch() {
// Turn selection updating and notifications back on.
SelectionRef().EndBatchChanges();
HTMLEditor* htmlEditor = AsHTMLEditor();
if (!htmlEditor) {
if (!IsHTMLEditor()) {
return;
}
@ -3710,7 +3708,8 @@ void EditorBase::EndUpdateViewBatch() {
// to a document may result in multiple events, some of them quite hard
// to listen too (in particular when an ancestor of the selection is
// changed but the selection itself is not changed).
DebugOnly<nsresult> rvIgnored = MOZ_KnownLive(htmlEditor)->RefreshEditingUI();
DebugOnly<nsresult> rvIgnored =
MOZ_KnownLive(AsHTMLEditor())->RefreshEditingUI();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"HTMLEditor::RefreshEditingUI() failed, but ignored");
}
@ -5005,7 +5004,7 @@ nsresult EditorBase::DeleteRangesWithTransaction(
return rv;
}
if (!IsHTMLEditor() || aStripWrappers == nsIEditor::eNoStrip) {
if (IsTextEditor() || aStripWrappers == nsIEditor::eNoStrip) {
return NS_OK;
}
@ -6221,7 +6220,7 @@ nsresult EditorBase::InsertTextAsAction(const nsAString& aStringToInsert,
}
nsString stringToInsert(aStringToInsert);
if (!AsHTMLEditor()) {
if (IsTextEditor()) {
nsContentUtils::PlatformToDOMLineBreaks(stringToInsert);
}
AutoPlaceholderBatch treatAsOneTransaction(*this,
@ -6235,7 +6234,7 @@ nsresult EditorBase::InsertTextAsAction(const nsAString& aStringToInsert,
nsresult EditorBase::InsertTextAsSubAction(const nsAString& aStringToInsert) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(mPlaceholderBatch);
MOZ_ASSERT(AsHTMLEditor() ||
MOZ_ASSERT(IsHTMLEditor() ||
aStringToInsert.FindChar(nsCRT::CR) == kNotFound);
if (NS_WARN_IF(!mInitSucceeded)) {
@ -6285,6 +6284,7 @@ NS_IMETHODIMP EditorBase::InsertLineBreak() {
nsresult EditorBase::InsertLineBreakAsSubAction() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(IsTextEditor());
if (NS_WARN_IF(!mInitSucceeded)) {
return NS_ERROR_NOT_INITIALIZED;
@ -6589,15 +6589,15 @@ nsresult EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent(
// success code instead of error.
return NS_OK;
}
OwningNonNull<TextEditor> textEditor = *mEditorBase.AsTextEditor();
OwningNonNull<EditorBase> editorBase = mEditorBase;
EditorInputType inputType = ToInputType(mEditAction);
if (textEditor->IsHTMLEditor() && mTargetRanges.IsEmpty()) {
if (editorBase->IsHTMLEditor() && mTargetRanges.IsEmpty()) {
// If the edit action will delete selected ranges, compute the range
// strictly.
if (MayEditActionDeleteAroundCollapsedSelection(mEditAction) ||
(!textEditor->SelectionRef().IsCollapsed() &&
(!editorBase->SelectionRef().IsCollapsed() &&
MayEditActionDeleteSelection(mEditAction))) {
if (!textEditor
if (!editorBase
->FlushPendingNotificationsIfToHandleDeletionWithFrameSelection(
aDeleteDirectionAndAmount)) {
NS_WARNING(
@ -6605,9 +6605,9 @@ nsresult EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent(
return NS_ERROR_EDITOR_DESTROYED;
}
AutoRangeArray rangesToDelete(textEditor->SelectionRef());
AutoRangeArray rangesToDelete(editorBase->SelectionRef());
if (!rangesToDelete.Ranges().IsEmpty()) {
nsresult rv = MOZ_KnownLive(textEditor->AsHTMLEditor())
nsresult rv = MOZ_KnownLive(editorBase->AsHTMLEditor())
->ComputeTargetRanges(aDeleteDirectionAndAmount,
rangesToDelete);
if (rv == NS_ERROR_EDITOR_DESTROYED) {
@ -6634,10 +6634,10 @@ nsresult EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent(
}
// Otherwise, just set target ranges to selection ranges.
else if (MayHaveTargetRangesOnHTMLEditor(inputType)) {
if (uint32_t rangeCount = textEditor->SelectionRef().RangeCount()) {
if (uint32_t rangeCount = editorBase->SelectionRef().RangeCount()) {
mTargetRanges.SetCapacity(rangeCount);
for (uint32_t i = 0; i < rangeCount; i++) {
const nsRange* range = textEditor->SelectionRef().GetRangeAt(i);
const nsRange* range = editorBase->SelectionRef().GetRangeAt(i);
if (NS_WARN_IF(!range) || NS_WARN_IF(!range->IsPositioned())) {
continue;
}
@ -6662,7 +6662,7 @@ nsresult EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent(
? InputEventOptions::NeverCancelable::Yes
: InputEventOptions::NeverCancelable::No;
nsresult rv = nsContentUtils::DispatchInputEvent(
targetElement, eEditorBeforeInput, inputType, textEditor,
targetElement, eEditorBeforeInput, inputType, editorBase,
mDataTransfer
? InputEventOptions(mDataTransfer, std::move(mTargetRanges),
neverCancelable)

View File

@ -159,9 +159,6 @@ class EditorBase : public nsIEditor,
*/
EditorBase();
bool IsTextEditor() const { return !mIsHTMLEditorClass; }
bool IsHTMLEditor() const { return mIsHTMLEditorClass; }
/**
* Init is to tell the implementation of nsIEditor to begin its services
* @param aDoc The dom document interface being observed
@ -2942,6 +2939,14 @@ class EditorBase : public nsIEditor,
} // namespace mozilla
bool nsIEditor::IsTextEditor() const {
return !AsEditorBase()->mIsHTMLEditorClass;
}
bool nsIEditor::IsHTMLEditor() const {
return AsEditorBase()->mIsHTMLEditorClass;
}
mozilla::EditorBase* nsIEditor::AsEditorBase() {
return static_cast<mozilla::EditorBase*>(this);
}

View File

@ -666,9 +666,9 @@ nsresult EditorEventListener::MouseClick(WidgetMouseEvent* aMouseClickEvent) {
return NS_OK;
}
// nothing to do if editor isn't editable or clicked on out of the editor.
RefPtr<TextEditor> textEditor = mEditorBase->AsTextEditor();
if (textEditor->IsReadonly() ||
!textEditor->IsAcceptableInputEvent(aMouseClickEvent)) {
OwningNonNull<EditorBase> editorBase = *mEditorBase;
if (editorBase->IsReadonly() ||
!editorBase->IsAcceptableInputEvent(aMouseClickEvent)) {
return NS_OK;
}
@ -723,7 +723,7 @@ nsresult EditorEventListener::MouseClick(WidgetMouseEvent* aMouseClickEvent) {
nsEventStatus status = nsEventStatus_eIgnore;
RefPtr<EventStateManager> esm = presContext->EventStateManager();
DebugOnly<nsresult> rvIgnored = esm->HandleMiddleClickPaste(
presShell, aMouseClickEvent, &status, textEditor);
presShell, aMouseClickEvent, &status, editorBase);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),
"EventStateManager::HandleMiddleClickPaste() failed, but ignored");
@ -859,7 +859,7 @@ nsresult EditorEventListener::DragOverOrDrop(DragEvent* aDragEvent) {
if (notEditable) {
// If we're a text control element which is readonly or disabled,
// we should refuse to drop.
if (!mEditorBase->AsHTMLEditor()) {
if (mEditorBase->IsTextEditor()) {
RefuseToDropAndHideCaret(aDragEvent);
return NS_OK;
}
@ -1260,13 +1260,12 @@ bool EditorEventListener::ShouldHandleNativeKeyBindings(
return false;
}
RefPtr<EditorBase> editorBase(mEditorBase);
HTMLEditor* htmlEditor = editorBase->AsHTMLEditor();
RefPtr<HTMLEditor> htmlEditor = HTMLEditor::GetFrom(mEditorBase);
if (!htmlEditor) {
return false;
}
RefPtr<Document> doc = editorBase->GetDocument();
RefPtr<Document> doc = htmlEditor->GetDocument();
if (doc->HasFlag(NODE_IS_EDITABLE)) {
// Don't need to perform any checks in designMode documents.
return true;

View File

@ -4148,7 +4148,7 @@ already_AddRefed<nsIContent> HTMLEditor::SplitNodeWithTransaction(
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"RangeUpdater::SelAdjSplitNode() failed, but ignored");
}
if (AsHTMLEditor() && newLeftContent) {
if (newLeftContent) {
TopLevelEditSubActionDataRef().DidSplitContent(
*this, *aStartOfRightNode.GetContainerAsContent(), *newLeftContent);
}
@ -4326,8 +4326,6 @@ void HTMLEditor::DoSplitNode(const EditorDOMPoint& aStartOfRightNode,
Text* rightAsText = aStartOfRightNode.GetContainerAsText();
Text* leftAsText = aNewLeftNode.GetAsText();
if (rightAsText && leftAsText) {
MOZ_DIAGNOSTIC_ASSERT(AsHTMLEditor(),
"Text node in TextEditor shouldn't be split");
// Fix right node
nsAutoString leftText;
IgnoredErrorResult ignoredError;
@ -4487,7 +4485,7 @@ nsresult HTMLEditor::JoinNodesWithTransaction(nsINode& aLeftNode,
}
NS_WARNING_ASSERTION(
!ignoredError.Failed(),
"TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
"HTMLEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
// Remember some values; later used for saved selection updating.
// Find the offset between the nodes to be joined.
@ -4495,10 +4493,8 @@ nsresult HTMLEditor::JoinNodesWithTransaction(nsINode& aLeftNode,
// Find the number of children of the lefthand node
uint32_t oldLeftNodeLen = aLeftNode.Length();
if (AsHTMLEditor()) {
TopLevelEditSubActionDataRef().WillJoinContents(
*this, *aLeftNode.AsContent(), *aRightNode.AsContent());
}
TopLevelEditSubActionDataRef().WillJoinContents(*this, *aLeftNode.AsContent(),
*aRightNode.AsContent());
RefPtr<JoinNodeTransaction> transaction = JoinNodeTransaction::MaybeCreate(
*this, *aLeftNode.AsContent(), *aRightNode.AsContent());
@ -4520,10 +4516,8 @@ nsresult HTMLEditor::JoinNodesWithTransaction(nsINode& aLeftNode,
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"RangeUpdater::SelAdjJoinNodes() failed, but ignored");
if (AsHTMLEditor()) {
TopLevelEditSubActionDataRef().DidJoinContents(
*this, *aLeftNode.AsContent(), *aRightNode.AsContent());
}
TopLevelEditSubActionDataRef().DidJoinContents(*this, *aLeftNode.AsContent(),
*aRightNode.AsContent());
if (mInlineSpellChecker) {
RefPtr<mozInlineSpellChecker> spellChecker = mInlineSpellChecker;
@ -4551,7 +4545,6 @@ nsresult HTMLEditor::JoinNodesWithTransaction(nsINode& aLeftNode,
nsresult HTMLEditor::DoJoinNodes(nsIContent& aContentToKeep,
nsIContent& aContentToJoin) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_DIAGNOSTIC_ASSERT(AsHTMLEditor());
uint32_t firstNodeLength = aContentToJoin.Length();

View File

@ -135,8 +135,11 @@ class HTMLEditor final : public TextEditor,
HTMLEditor();
static HTMLEditor* GetFrom(EditorBase* aEditorBase) {
return aEditorBase ? aEditorBase->AsHTMLEditor() : nullptr;
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;
@ -4534,15 +4537,21 @@ class MOZ_STACK_CLASS ParagraphStateAtSelection final {
} // namespace mozilla
mozilla::HTMLEditor* nsIEditor::AsHTMLEditor() {
return static_cast<mozilla::EditorBase*>(this)->IsHTMLEditor()
? static_cast<mozilla::HTMLEditor*>(this)
: nullptr;
MOZ_DIAGNOSTIC_ASSERT(IsHTMLEditor());
return static_cast<mozilla::HTMLEditor*>(this);
}
const mozilla::HTMLEditor* nsIEditor::AsHTMLEditor() const {
return static_cast<const mozilla::EditorBase*>(this)->IsHTMLEditor()
? static_cast<const mozilla::HTMLEditor*>(this)
: nullptr;
MOZ_DIAGNOSTIC_ASSERT(IsHTMLEditor());
return static_cast<const mozilla::HTMLEditor*>(this);
}
mozilla::HTMLEditor* nsIEditor::GetAsHTMLEditor() {
return AsEditorBase()->IsHTMLEditor() ? AsHTMLEditor() : nullptr;
}
const mozilla::HTMLEditor* nsIEditor::GetAsHTMLEditor() const {
return AsEditorBase()->IsHTMLEditor() ? AsHTMLEditor() : nullptr;
}
#endif // #ifndef mozilla_HTMLEditor_h

View File

@ -48,10 +48,7 @@ static nsresult GetListState(HTMLEditor* aHTMLEditor, bool* aMixed,
bool StateUpdatingCommandBase::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -67,7 +64,7 @@ bool StateUpdatingCommandBase::IsCommandEnabled(Command aCommand,
nsresult StateUpdatingCommandBase::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -88,7 +85,7 @@ nsresult StateUpdatingCommandBase::GetCommandStateParams(
if (!aEditorBase) {
return NS_OK;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase->GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -111,10 +108,7 @@ StaticRefPtr<PasteNoFormattingCommand> PasteNoFormattingCommand::sInstance;
bool PasteNoFormattingCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -124,7 +118,7 @@ bool PasteNoFormattingCommand::IsCommandEnabled(Command aCommand,
nsresult PasteNoFormattingCommand::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -362,11 +356,7 @@ StaticRefPtr<RemoveListCommand> RemoveListCommand::sInstance;
bool RemoveListCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -385,7 +375,7 @@ bool RemoveListCommand::IsCommandEnabled(Command aCommand,
nsresult RemoveListCommand::DoCommand(Command aCommand, EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_OK;
}
@ -412,10 +402,7 @@ StaticRefPtr<IndentCommand> IndentCommand::sInstance;
bool IndentCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -424,7 +411,7 @@ bool IndentCommand::IsCommandEnabled(Command aCommand,
nsresult IndentCommand::DoCommand(Command aCommand, EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_OK;
}
@ -448,10 +435,7 @@ StaticRefPtr<OutdentCommand> OutdentCommand::sInstance;
bool OutdentCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -460,7 +444,7 @@ bool OutdentCommand::IsCommandEnabled(Command aCommand,
nsresult OutdentCommand::DoCommand(Command aCommand, EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_OK;
}
@ -483,10 +467,7 @@ nsresult OutdentCommand::GetCommandStateParams(
bool MultiStateCommandBase::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -509,7 +490,7 @@ nsresult MultiStateCommandBase::DoCommandParam(Command aCommand,
NS_WARNING_ASSERTION(aCommand != Command::FormatJustify,
"Command::FormatJustify should be used only for "
"IsCommandEnabled() and GetCommandStateParams()");
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -525,7 +506,7 @@ nsresult MultiStateCommandBase::GetCommandStateParams(
if (!aEditorBase) {
return NS_OK;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase->GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -942,10 +923,7 @@ StaticRefPtr<DecreaseZIndexCommand> DecreaseZIndexCommand::sInstance;
bool DecreaseZIndexCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
RefPtr<HTMLEditor> htmlEditor = aEditorBase->AsHTMLEditor();
RefPtr<HTMLEditor> htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -962,7 +940,7 @@ bool DecreaseZIndexCommand::IsCommandEnabled(Command aCommand,
nsresult DecreaseZIndexCommand::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -987,10 +965,7 @@ StaticRefPtr<IncreaseZIndexCommand> IncreaseZIndexCommand::sInstance;
bool IncreaseZIndexCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -1003,7 +978,7 @@ bool IncreaseZIndexCommand::IsCommandEnabled(Command aCommand,
nsresult IncreaseZIndexCommand::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -1028,10 +1003,7 @@ StaticRefPtr<RemoveStylesCommand> RemoveStylesCommand::sInstance;
bool RemoveStylesCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -1042,7 +1014,7 @@ bool RemoveStylesCommand::IsCommandEnabled(Command aCommand,
nsresult RemoveStylesCommand::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_OK;
}
@ -1069,10 +1041,7 @@ StaticRefPtr<IncreaseFontSizeCommand> IncreaseFontSizeCommand::sInstance;
bool IncreaseFontSizeCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -1083,7 +1052,7 @@ bool IncreaseFontSizeCommand::IsCommandEnabled(Command aCommand,
nsresult IncreaseFontSizeCommand::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_OK;
}
@ -1108,10 +1077,7 @@ StaticRefPtr<DecreaseFontSizeCommand> DecreaseFontSizeCommand::sInstance;
bool DecreaseFontSizeCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -1122,7 +1088,7 @@ bool DecreaseFontSizeCommand::IsCommandEnabled(Command aCommand,
nsresult DecreaseFontSizeCommand::DoCommand(Command aCommand,
EditorBase& aEditorBase,
nsIPrincipal* aPrincipal) const {
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_OK;
}
@ -1147,10 +1113,7 @@ StaticRefPtr<InsertHTMLCommand> InsertHTMLCommand::sInstance;
bool InsertHTMLCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -1162,7 +1125,7 @@ nsresult InsertHTMLCommand::DoCommand(Command aCommand, EditorBase& aEditorBase,
// If InsertHTMLCommand is called with no parameters, it was probably called
// with an empty string parameter ''. In this case, it should act the same as
// the delete command
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -1181,7 +1144,7 @@ nsresult InsertHTMLCommand::DoCommandParam(Command aCommand,
return NS_ERROR_INVALID_ARG;
}
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -1207,10 +1170,7 @@ StaticRefPtr<InsertTagCommand> InsertTagCommand::sInstance;
bool InsertTagCommand::IsCommandEnabled(Command aCommand,
EditorBase* aEditorBase) const {
if (!aEditorBase) {
return false;
}
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (!htmlEditor) {
return false;
}
@ -1225,7 +1185,7 @@ nsresult InsertTagCommand::DoCommand(Command aCommand, EditorBase& aEditorBase,
return NS_ERROR_NOT_IMPLEMENTED;
}
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}
@ -1258,7 +1218,7 @@ nsresult InsertTagCommand::DoCommandParam(Command aCommand,
return NS_ERROR_UNEXPECTED;
}
HTMLEditor* htmlEditor = aEditorBase.AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase.GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_FAILURE;
}

View File

@ -47,7 +47,7 @@ bool SetDocumentStateCommand::IsCommandEnabled(Command aCommand,
return !!aEditorBase;
}
// The other commands are always enabled if given editor is an HTMLEditor.
return aEditorBase && aEditorBase->AsHTMLEditor();
return aEditorBase && aEditorBase->IsHTMLEditor();
}
nsresult SetDocumentStateCommand::DoCommand(Command aCommand,
@ -251,7 +251,7 @@ nsresult SetDocumentStateCommand::GetCommandStateParams(
return rv;
}
case Command::SetDocumentUseCSS: {
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase->GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_INVALID_ARG;
}
@ -261,7 +261,7 @@ nsresult SetDocumentStateCommand::GetCommandStateParams(
return rv;
}
case Command::SetDocumentInsertBROnEnterKeyPress: {
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase->GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_INVALID_ARG;
}
@ -278,7 +278,7 @@ nsresult SetDocumentStateCommand::GetCommandStateParams(
return rv;
}
case Command::SetDocumentDefaultParagraphSeparator: {
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase->GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_INVALID_ARG;
}
@ -310,7 +310,7 @@ nsresult SetDocumentStateCommand::GetCommandStateParams(
}
}
case Command::ToggleObjectResizers: {
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase->GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_INVALID_ARG;
}
@ -324,7 +324,7 @@ nsresult SetDocumentStateCommand::GetCommandStateParams(
return rv;
}
case Command::ToggleInlineTableEditor: {
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase->GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_INVALID_ARG;
}
@ -338,7 +338,7 @@ nsresult SetDocumentStateCommand::GetCommandStateParams(
return rv;
}
case Command::ToggleAbsolutePositionEditor: {
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = aEditorBase->GetAsHTMLEditor();
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_INVALID_ARG;
}

View File

@ -25,11 +25,8 @@ namespace mozilla {
using namespace dom;
nsresult HTMLEditorEventListener::Connect(EditorBase* aEditorBase) {
if (NS_WARN_IF(!aEditorBase)) {
return NS_ERROR_INVALID_ARG;
}
// Guarantee that mEditorBase is always HTMLEditor.
HTMLEditor* htmlEditor = aEditorBase->AsHTMLEditor();
HTMLEditor* htmlEditor = HTMLEditor::GetFrom(aEditorBase);
if (NS_WARN_IF(!htmlEditor)) {
return NS_ERROR_INVALID_ARG;
}
@ -82,7 +79,6 @@ NS_IMETHODIMP HTMLEditorEventListener::HandleEvent(Event* aEvent) {
}
RefPtr<HTMLEditor> htmlEditor = mEditorBase->AsHTMLEditor();
MOZ_ASSERT(htmlEditor);
DebugOnly<nsresult> rvIgnored =
htmlEditor->UpdateResizerOrGrabberPositionTo(CSSIntPoint(
mouseMoveEvent->ClientX(), mouseMoveEvent->ClientY()));
@ -97,7 +93,6 @@ NS_IMETHODIMP HTMLEditorEventListener::HandleEvent(Event* aEvent) {
}
RefPtr<HTMLEditor> htmlEditor = mEditorBase->AsHTMLEditor();
MOZ_ASSERT(htmlEditor);
nsresult rv = htmlEditor->RefreshResizers();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HTMLEditor::RefreshResizers() failed");
@ -240,8 +235,6 @@ nsresult HTMLEditorEventListener::MouseUp(MouseEvent* aMouseEvent) {
// FYI: We need to notify HTML editor of mouseup even if it's consumed
// because HTML editor always needs to release grabbing resizer.
RefPtr<HTMLEditor> htmlEditor = mEditorBase->AsHTMLEditor();
MOZ_ASSERT(htmlEditor);
htmlEditor->PreHandleMouseUp(*aMouseEvent);
if (NS_WARN_IF(!aMouseEvent->GetTarget())) {
@ -390,8 +383,6 @@ nsresult HTMLEditorEventListener::MouseDown(MouseEvent* aMouseEvent) {
}
RefPtr<HTMLEditor> htmlEditor = mEditorBase->AsHTMLEditor();
MOZ_ASSERT(htmlEditor);
htmlEditor->PreHandleMouseDown(*aMouseEvent);
if (!IsAcceptableMouseEvent(*htmlEditor, aMouseEvent)) {
@ -432,7 +423,6 @@ nsresult HTMLEditorEventListener::MouseClick(
}
RefPtr<HTMLEditor> htmlEditor = mEditorBase->AsHTMLEditor();
MOZ_ASSERT(htmlEditor);
DebugOnly<nsresult> rvIgnored =
htmlEditor->DoInlineTableEditingAction(*element);
NS_WARNING_ASSERTION(

View File

@ -137,7 +137,7 @@ NS_IMETHODIMP InsertNodeTransaction::DoTransaction() {
return error.StealNSResult();
}
if (!editorBase->AsHTMLEditor() && contentToInsert->IsText()) {
if (editorBase->IsTextEditor() && contentToInsert->IsText()) {
uint32_t length = contentToInsert->AsText()->TextLength();
if (length > 0) {
nsresult rv = MOZ_KnownLive(editorBase->AsTextEditor())
@ -179,7 +179,7 @@ NS_IMETHODIMP InsertNodeTransaction::UndoTransaction() {
NS_WARN_IF(!mPointToInsert.IsSet())) {
return NS_ERROR_NOT_INITIALIZED;
}
if (!mEditorBase->AsHTMLEditor() && mContentToInsert->IsText()) {
if (mEditorBase->IsTextEditor() && mContentToInsert->IsText()) {
uint32_t length = mContentToInsert->TextLength();
if (length > 0) {
mEditorBase->AsTextEditor()->WillDeleteText(length, 0, length);

View File

@ -51,7 +51,7 @@ void TextEditor::OnStartToHandleTopLevelEditSubAction(
EditSubAction aTopLevelEditSubAction,
nsIEditor::EDirection aDirectionOfTopLevelEditSubAction, ErrorResult& aRv) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsTextEditor());
MOZ_ASSERT(!aRv.Failed());
EditorBase::OnStartToHandleTopLevelEditSubAction(
@ -99,7 +99,7 @@ void TextEditor::OnStartToHandleTopLevelEditSubAction(
nsresult TextEditor::OnEndHandlingTopLevelEditSubAction() {
MOZ_ASSERT(IsTopLevelEditSubActionDataAvailable());
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsTextEditor());
nsresult rv;
while (true) {
@ -579,8 +579,7 @@ EditActionResult TextEditor::HandleInsertText(
EditActionResult TextEditor::SetTextWithoutTransaction(
const nsAString& aValue) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsPlaintextEditor());
MOZ_ASSERT(IsTextEditor());
MOZ_ASSERT(!IsIMEComposing());
MOZ_ASSERT(!IsUndoRedoEnabled());
MOZ_ASSERT(GetEditAction() != EditAction::eReplaceText);

View File

@ -112,7 +112,7 @@ NS_INTERFACE_MAP_END_INHERITING(EditorBase)
nsresult TextEditor::Init(Document& aDoc, Element* aRoot,
nsISelectionController* aSelCon, uint32_t aFlags,
const nsAString& aInitialValue) {
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsTextEditor());
MOZ_ASSERT(!mInitSucceeded,
"TextEditor::Init() called again without calling PreDestroy()?");
@ -255,7 +255,7 @@ nsresult TextEditor::SetTextAsAction(
AllowBeforeInputEventCancelable aAllowBeforeInputEventCancelable,
nsIPrincipal* aPrincipal) {
MOZ_ASSERT(aString.FindChar(nsCRT::CR) == kNotFound);
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsTextEditor());
AutoEditActionDataSetter editActionData(*this, EditAction::eSetText,
aPrincipal);
@ -584,7 +584,7 @@ nsresult TextEditor::InsertWithQuotationsAsSubAction(
nsresult TextEditor::SelectEntireDocument() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsTextEditor());
if (NS_WARN_IF(!mInitSucceeded)) {
return NS_ERROR_NOT_INITIALIZED;
@ -684,7 +684,7 @@ nsresult TextEditor::RemoveAttributeOrEquivalent(Element* aElement,
nsresult TextEditor::EnsurePaddingBRElementForEmptyEditor() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsTextEditor());
// If there is padding <br> element for empty editor, we have no work to do.
if (mPaddingBRElementForEmptyEditor) {

View File

@ -51,6 +51,13 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
TextEditor();
static TextEditor* GetFrom(nsIEditor* aEditor) {
return aEditor ? aEditor->GetAsTextEditor() : nullptr;
}
static const TextEditor* GetFrom(const nsIEditor* aEditor) {
return aEditor ? aEditor->GetAsTextEditor() : nullptr;
}
NS_DECL_NSITIMERCALLBACK
NS_DECL_NSINAMED
@ -499,11 +506,21 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
} // namespace mozilla
mozilla::TextEditor* nsIEditor::AsTextEditor() {
MOZ_DIAGNOSTIC_ASSERT(IsTextEditor());
return static_cast<mozilla::TextEditor*>(this);
}
const mozilla::TextEditor* nsIEditor::AsTextEditor() const {
MOZ_DIAGNOSTIC_ASSERT(IsTextEditor());
return static_cast<const mozilla::TextEditor*>(this);
}
mozilla::TextEditor* nsIEditor::GetAsTextEditor() {
return AsEditorBase()->IsTextEditor() ? AsTextEditor() : nullptr;
}
const mozilla::TextEditor* nsIEditor::GetAsTextEditor() const {
return AsEditorBase()->IsTextEditor() ? AsTextEditor() : nullptr;
}
#endif // #ifndef mozilla_TextEditor_h

View File

@ -41,7 +41,7 @@ using namespace dom;
nsresult TextEditor::InsertTextFromTransferable(
nsITransferable* aTransferable) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!AsHTMLEditor());
MOZ_ASSERT(IsTextEditor());
nsAutoCString bestFlavor;
nsCOMPtr<nsISupports> genericDataObj;

View File

@ -595,6 +595,9 @@ interface nsIEditor : nsISupports
void insertLineBreak();
%{C++
inline bool IsHTMLEditor() const;
inline bool IsTextEditor() const;
/**
* AsEditorBase() returns a pointer to EditorBase class.
*
@ -605,21 +608,31 @@ interface nsIEditor : nsISupports
inline const mozilla::EditorBase* AsEditorBase() const;
/**
* AsTextEditor() returns a pointer to TextEditor class.
* AsTextEditor() and GetTextEditor() return a pointer to TextEditor class.
* AsTextEditor() does not check the concrete class type. So, it never
* returns nullptr. GetAsTextEditor() does check the concrete class type.
* So, it may return nullptr.
*
* In order to avoid circular dependency issues, this method is defined
* in mozilla/TextEditor.h. Consumers need to #include that header.
*/
inline mozilla::TextEditor* AsTextEditor();
inline const mozilla::TextEditor* AsTextEditor() const;
inline mozilla::TextEditor* GetAsTextEditor();
inline const mozilla::TextEditor* GetAsTextEditor() const;
/**
* AsHTMLEditor() returns a pointer to HTMLEditor class.
* AsHTMLEditor() and GetHTMLEditor() return a pointer to HTMLEditor class.
* AsHTMLEditor() does not check the concrete class type. So, it never
* returns nullptr. GetAsHTMLEditor() does check the concrete class type.
* So, it may return nullptr.
*
* In order to avoid circular dependency issues, this method is defined
* in mozilla/HTMLEditor.h. Consumers need to #include that header.
*/
inline mozilla::HTMLEditor* AsHTMLEditor();
inline const mozilla::HTMLEditor* AsHTMLEditor() const;
inline mozilla::HTMLEditor* GetAsHTMLEditor();
inline const mozilla::HTMLEditor* GetAsHTMLEditor() const;
%}
};

View File

@ -628,8 +628,7 @@ EditorSpellCheck::UpdateCurrentDictionary(
// Get language with html5 algorithm
nsCOMPtr<nsIContent> rootContent;
HTMLEditor* htmlEditor = mEditor->AsHTMLEditor();
if (htmlEditor) {
if (HTMLEditor* htmlEditor = mEditor->GetAsHTMLEditor()) {
if (flags & nsIEditor::eEditorMailMask) {
// Always determine the root content for a mail editor,
// even if not focused, to enable further processing below.