Bug 1716746 - Rename `EditorBase::IsPlaintextEditor()` to `IsInPlaintextMode()` r=m_kato

Developers may be confused at `IsTextEditor()` and `IsPlaintextEditor()`. When
the latter is `true`, the former is always `true`, but it may be `true` when the
editor is `HTMLEditor` too. So, it's a mode of  `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D118246
This commit is contained in:
Masayuki Nakano 2021-06-18 20:35:48 +00:00
Родитель fb069248c0
Коммит 698fd90470
10 изменённых файлов: 38 добавлений и 32 удалений

Просмотреть файл

@ -386,7 +386,7 @@ nsresult EditorBase::InitEditorContentAndSelection() {
}
}
if (IsPlaintextEditor() && !IsSingleLineEditor()) {
if (IsInPlaintextMode() && !IsSingleLineEditor()) {
nsresult rv = EnsurePaddingBRElementInMultilineEditor();
if (NS_FAILED(rv)) {
NS_WARNING(
@ -580,7 +580,7 @@ bool EditorBase::GetDesiredSpellCheckState() {
return false;
}
if (!IsPlaintextEditor()) {
if (!IsInPlaintextMode()) {
// Some of the page content might be editable and some not, if spellcheck=
// is explicitly set anywhere, so if there's anything editable on the page,
// return true and let the spellchecker figure it out.
@ -674,6 +674,10 @@ NS_IMETHODIMP EditorBase::SetFlags(uint32_t aFlags) {
return NS_OK;
}
// If we're a `TextEditor` instance, the plaintext mode should always be set.
// If we're an `HTMLEditor` instance, either is fine.
MOZ_ASSERT_IF(IsTextEditor(), !!(aFlags & nsIEditor::eEditorPlaintextMask));
DebugOnly<bool> changingPasswordEditorFlagDynamically =
mFlags != ~aFlags && ((mFlags ^ aFlags) & nsIEditor::eEditorPasswordMask);
MOZ_ASSERT(
@ -2871,7 +2875,7 @@ EditorRawDOMPoint EditorBase::FindBetterInsertionPoint(
return aPoint;
}
if (!IsPlaintextEditor()) {
if (!IsInPlaintextMode()) {
// We cannot find "better" insertion point in HTML editor.
// WARNING: When you add some code to find better node in HTML editor,
// you need to call this before calling InsertTextWithTransaction()
@ -3304,7 +3308,6 @@ nsresult EditorBase::SetTextNodeWithoutTransaction(const nsAString& aString,
Text& aTextNode) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(IsTextEditor());
MOZ_ASSERT(IsPlaintextEditor());
MOZ_ASSERT(!IsUndoRedoEnabled());
const uint32_t length = aTextNode.Length();
@ -3538,7 +3541,7 @@ nsresult EditorBase::GetEndChildNode(const Selection& aSelection,
nsresult EditorBase::EnsurePaddingBRElementInMultilineEditor() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(IsPlaintextEditor());
MOZ_ASSERT(IsInPlaintextMode());
MOZ_ASSERT(!IsSingleLineEditor());
Element* anonymousDivOrBodyElement = GetRoot();
@ -4662,7 +4665,7 @@ nsresult EditorBase::HandleDropEvent(DragEvent* aDropEvent) {
}
}
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
for (nsIContent* content = droppedAt.GetContainerAsContent(); content;
content = content->GetParent()) {
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(content));
@ -5239,7 +5242,7 @@ nsresult EditorBase::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) {
return NS_OK;
}
case NS_VK_TAB: {
MOZ_ASSERT_IF(IsHTMLEditor(), IsPlaintextEditor());
MOZ_ASSERT_IF(IsHTMLEditor(), IsInPlaintextMode());
if (IsTabbable()) {
return NS_OK; // let it be used for focus switching
}
@ -6115,7 +6118,7 @@ NS_IMETHODIMP EditorBase::SetWrapWidth(int32_t aWrapColumn) {
// Make sure we're a plaintext editor, otherwise we shouldn't
// do the rest of this.
if (!IsPlaintextEditor()) {
if (!IsInPlaintextMode()) {
return NS_OK;
}

Просмотреть файл

@ -550,8 +550,11 @@ class EditorBase : public nsIEditor,
return SetFlags(kNewFlags); // virtual call and may be expensive.
}
bool IsPlaintextEditor() const {
return (mFlags & nsIEditor::eEditorPlaintextMask) != 0;
bool IsInPlaintextMode() const {
const bool isPlaintextMode =
(mFlags & nsIEditor::eEditorPlaintextMask) != 0;
MOZ_ASSERT_IF(IsTextEditor(), isPlaintextMode);
return isPlaintextMode;
}
bool IsSingleLineEditor() const {

Просмотреть файл

@ -572,7 +572,7 @@ nsresult EditorEventListener::KeyUp(const WidgetKeyboardEvent* aKeyboardEvent) {
RefPtr<EditorBase> editorBase(mEditorBase);
if ((aKeyboardEvent->mKeyCode == NS_VK_SHIFT ||
aKeyboardEvent->mKeyCode == NS_VK_CONTROL) &&
mShouldSwitchTextDirection && editorBase->IsPlaintextEditor()) {
mShouldSwitchTextDirection && editorBase->IsInPlaintextMode()) {
editorBase->SwitchTextDirectionTo(mSwitchToRTL
? EditorBase::TextDirection::eRTL
: EditorBase::TextDirection::eLTR);
@ -974,7 +974,7 @@ bool EditorEventListener::DragEventHasSupportingData(
return dataTransfer->HasType(NS_LITERAL_STRING_FROM_CSTRING(kTextMime)) ||
dataTransfer->HasType(
NS_LITERAL_STRING_FROM_CSTRING(kMozTextInternal)) ||
(!mEditorBase->IsPlaintextEditor() &&
(!mEditorBase->IsInPlaintextMode() &&
(dataTransfer->HasType(NS_LITERAL_STRING_FROM_CSTRING(kHTMLMime)) ||
dataTransfer->HasType(NS_LITERAL_STRING_FROM_CSTRING(kFileMime))));
}

Просмотреть файл

@ -968,7 +968,7 @@ EditActionResult HTMLEditor::HandleInsertText(
// for efficiency, break out the pre case separately. This is because
// its a lot cheaper to search the input string for only newlines than
// it is to search for both tabs and newlines.
if (isPRE || IsPlaintextEditor()) {
if (isPRE || IsInPlaintextMode()) {
while (pos != -1 &&
pos < static_cast<int32_t>(aInsertionString.Length())) {
int32_t oldPos = pos;
@ -1478,7 +1478,7 @@ nsresult HTMLEditor::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
// First, insert a <br> element.
RefPtr<Element> brElement;
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
Result<RefPtr<Element>, nsresult> resultOfInsertingBRElement =
InsertBRElementWithTransaction(aPointToBreak);
if (resultOfInsertingBRElement.isErr()) {
@ -7674,7 +7674,7 @@ nsresult HTMLEditor::JoinNearestEditableNodesWithTransaction(
Element* HTMLEditor::GetMostAncestorMailCiteElement(nsINode& aNode) const {
Element* mailCiteElement = nullptr;
bool isPlaintextEditor = IsPlaintextEditor();
const bool isPlaintextEditor = IsInPlaintextMode();
for (nsINode* node = &aNode; node; node = node->GetParentNode()) {
if ((isPlaintextEditor && node->IsHTMLElement(nsGkAtoms::pre)) ||
HTMLEditUtils::IsMailCite(node)) {

Просмотреть файл

@ -276,7 +276,7 @@ nsresult HTMLEditor::Init(Document& aDoc, Element* aRoot,
if (NS_WARN_IF(!document)) {
return NS_ERROR_FAILURE;
}
if (!IsPlaintextEditor() && !IsInteractionAllowed()) {
if (!IsInPlaintextMode() && !IsInteractionAllowed()) {
mDisabledLinkHandling = true;
mOldLinkHandlingEnabled = document->LinkHandlingEnabled();
document->SetLinkHandlingEnabled(false);
@ -897,7 +897,7 @@ nsresult HTMLEditor::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) {
return rv;
}
case NS_VK_TAB: {
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
// If this works as plain text editor, e.g., mail editor for plain
// text, should be handled with common logic with EditorBase.
nsresult rv = EditorBase::HandleKeyPressEvent(aKeyboardEvent);
@ -5123,7 +5123,7 @@ nsresult HTMLEditor::SetCSSBackgroundColorWithTransaction(
CommitComposition();
// XXX Shouldn't we do this before calling `CommitComposition()`?
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
return NS_OK;
}

Просмотреть файл

@ -3135,7 +3135,7 @@ class HTMLEditor final : public EditorBase,
/**
* InsertAsCitedQuotationInternal() inserts a <blockquote> element whose
* cite attribute is aCitation and whose content is aQuotedText.
* Note that this shouldn't be called when IsPlaintextEditor() is true.
* Note that this shouldn't be called when IsInPlaintextMode() is true.
*
* @param aQuotedText HTML source if aInsertHTML is true. Otherwise,
* plain text. This is inserted into new <blockquote>

Просмотреть файл

@ -1167,7 +1167,7 @@ void HTMLEditor::HTMLTransferablePreparer::AddDataFlavorsInBestOrder(
// Create the desired DataFlavor for the type of data
// we want to get out of the transferable
// This should only happen in html editors, not plaintext
if (!mHTMLEditor.IsPlaintextEditor()) {
if (!mHTMLEditor.IsInPlaintextMode()) {
DebugOnly<nsresult> rvIgnored =
aTransferable.AddDataFlavor(kNativeHTMLMime);
NS_WARNING_ASSERTION(
@ -1902,7 +1902,7 @@ nsresult HTMLEditor::InsertFromDataTransfer(const DataTransfer* aDataTransfer,
bool hasPrivateHTMLFlavor =
types->Contains(NS_LITERAL_STRING_FROM_CSTRING(kHTMLContext));
bool isPlaintextEditor = IsPlaintextEditor();
bool isPlaintextEditor = IsInPlaintextMode();
bool isSafe = IsSafeToInsertData(aSourceDoc);
uint32_t length = types->Length();
@ -2322,7 +2322,7 @@ bool HTMLEditor::CanPaste(int32_t aClipboardType) const {
}
// Use the flavors depending on the current editor mask
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
AutoTArray<nsCString, ArrayLength(textEditorFlavors)> flavors;
flavors.AppendElements<const char*>(Span<const char*>(textEditorFlavors));
bool haveFlavors;
@ -2358,7 +2358,7 @@ bool HTMLEditor::CanPasteTransferable(nsITransferable* aTransferable) {
// Use the flavors depending on the current editor mask
const char** flavors;
size_t length;
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
flavors = textEditorFlavors;
length = ArrayLength(textEditorFlavors);
} else {
@ -2412,7 +2412,7 @@ nsresult HTMLEditor::PasteAsQuotationAsAction(int32_t aClipboardType,
return EditorBase::ToGenericNSResult(rv);
}
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
nsresult rv = PasteAsPlaintextQuotation(aClipboardType);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HTMLEditor::PasteAsPlaintextQuotation() failed");
@ -2772,7 +2772,7 @@ nsresult HTMLEditor::InsertTextWithQuotationsInternal(
nsresult HTMLEditor::InsertAsQuotation(const nsAString& aQuotedText,
nsINode** aNodeInserted) {
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
AutoEditActionDataSetter editActionData(*this, EditAction::eInsertText);
MOZ_ASSERT(!aQuotedText.IsVoid());
editActionData.SetData(aQuotedText);
@ -3035,7 +3035,7 @@ NS_IMETHODIMP HTMLEditor::InsertAsCitedQuotation(const nsAString& aQuotedText,
bool aInsertHTML,
nsINode** aNodeInserted) {
// Don't let anyone insert HTML when we're in plaintext mode.
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
NS_ASSERTION(
!aInsertHTML,
"InsertAsCitedQuotation: trying to insert html into plaintext editor");
@ -3081,7 +3081,7 @@ nsresult HTMLEditor::InsertAsCitedQuotationInternal(
const nsAString& aQuotedText, const nsAString& aCitation, bool aInsertHTML,
nsINode** aNodeInserted) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsPlaintextEditor());
MOZ_ASSERT(!IsInPlaintextMode());
if (IsReadonly()) {
return NS_OK;

Просмотреть файл

@ -2908,7 +2908,7 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteNonCollapsedRanges(
}
}
if (!aHTMLEditor.IsPlaintextEditor()) {
if (!aHTMLEditor.IsInPlaintextMode()) {
EditorDOMRange firstRange(aRangesToDelete.FirstRangeRef());
EditorDOMRange extendedRange =
WSRunScanner::GetRangeContainingInvisibleWhiteSpacesAtRangeBoundaries(
@ -3001,7 +3001,7 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteNonCollapsedRanges(
// Figure out if the endpoints are in nodes that can be merged. Adjust
// surrounding white-space in preparation to delete selection.
if (!aHTMLEditor.IsPlaintextEditor()) {
if (!aHTMLEditor.IsInPlaintextMode()) {
AutoTransactionsConserveSelection dontChangeMySelection(aHTMLEditor);
AutoTrackDOMRange firstRangeTracker(aHTMLEditor.RangeUpdaterRef(),
&aRangesToDelete.FirstRangeRef());

Просмотреть файл

@ -216,7 +216,7 @@ nsresult HTMLEditor::SetInlinePropertyInternal(
}
// XXX Shouldn't we return before calling `CommitComposition()`?
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
return NS_OK;
}
@ -1898,7 +1898,7 @@ nsresult HTMLEditor::RemoveInlinePropertyInternal(
}
// XXX Shouldn't we quit before calling `CommitComposition()`?
if (IsPlaintextEditor()) {
if (IsInPlaintextMode()) {
return NS_OK;
}

Просмотреть файл

@ -293,7 +293,7 @@ nsresult TextEditor::SetTextAsSubAction(const nsAString& aString) {
!ignoredError.Failed(),
"TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
if (IsPlaintextEditor() && !IsIMEComposing() && !IsUndoRedoEnabled() &&
if (!IsIMEComposing() && !IsUndoRedoEnabled() &&
GetEditAction() != EditAction::eReplaceText && mMaxTextLength < 0) {
EditActionResult result = SetTextWithoutTransaction(aString);
if (result.Failed() || result.Canceled() || result.Handled()) {