зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1581034 - part 2: Get rid of `TextEditUtils::IsBreak()` and `TextEditUtils` itself r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D45811 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4f5eae49b0
Коммит
58f9c64190
|
@ -24,7 +24,6 @@
|
|||
#include "JoinNodeTransaction.h" // for JoinNodeTransaction
|
||||
#include "PlaceholderTransaction.h" // for PlaceholderTransaction
|
||||
#include "SplitNodeTransaction.h" // for SplitNodeTransaction
|
||||
#include "TextEditUtils.h" // for TextEditUtils
|
||||
#include "mozilla/CheckedInt.h" // for CheckedInt
|
||||
#include "mozilla/ComputedStyle.h" // for ComputedStyle
|
||||
#include "mozilla/CSSEditUtils.h" // for CSSEditUtils
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "HTMLEditorEventListener.h"
|
||||
#include "HTMLEditUtils.h"
|
||||
#include "TextEditUtils.h"
|
||||
#include "mozilla/EditAction.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "HTMLEditor.h"
|
||||
|
||||
#include "HTMLEditUtils.h"
|
||||
#include "TextEditUtils.h"
|
||||
#include "WSRunObject.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/ContentIterator.h"
|
||||
|
@ -4253,7 +4252,7 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList(
|
|||
bool bOnlyBreaks = true;
|
||||
for (auto& curNode : arrayOfNodes) {
|
||||
// if curNode is not a Break or empty inline, we're done
|
||||
if (!TextEditUtils::IsBreak(curNode) && !IsEmptyInineNode(curNode)) {
|
||||
if (!curNode->IsHTMLElement(nsGkAtoms::br) && !IsEmptyInineNode(curNode)) {
|
||||
bOnlyBreaks = false;
|
||||
break;
|
||||
}
|
||||
|
@ -6427,7 +6426,7 @@ nsresult HTMLEditor::AlignContentsAtSelection(const nsAString& aAlignType) {
|
|||
return rv;
|
||||
}
|
||||
|
||||
if (TextEditUtils::IsBreak(node)) {
|
||||
if (node->IsHTMLElement(nsGkAtoms::br)) {
|
||||
// The special case createEmptyDivElement code (below) that consumes
|
||||
// `<br>` elements can cause tables to split if the start node of the
|
||||
// selection is not in a table cell or caption, for example parent is a
|
||||
|
@ -6499,7 +6498,8 @@ EditActionResult HTMLEditor::AlignContentsAtSelectionWithEmptyDivElement(
|
|||
// creating extra lines, if possible.
|
||||
if (nsCOMPtr<nsIContent> maybeBRContent =
|
||||
GetNextEditableHTMLNodeInBlock(splitNodeResult.SplitPoint())) {
|
||||
if (TextEditUtils::IsBreak(maybeBRContent) && pointToInsertDiv.GetChild()) {
|
||||
if (maybeBRContent->IsHTMLElement(nsGkAtoms::br) &&
|
||||
pointToInsertDiv.GetChild()) {
|
||||
// Making use of html structure... if next node after where we are
|
||||
// putting our div is not a block, then the br we found is in same block
|
||||
// we are, so it's safe to consume it.
|
||||
|
@ -8449,7 +8449,7 @@ EditActionResult HTMLEditor::HandleInsertParagraphInParagraph(
|
|||
splitAfterNewBR = true;
|
||||
}
|
||||
}
|
||||
if (!pointToInsertBR.IsSet() && TextEditUtils::IsBreak(nearNode)) {
|
||||
if (!pointToInsertBR.IsSet() && nearNode->IsHTMLElement(nsGkAtoms::br)) {
|
||||
brContent = nearNode;
|
||||
}
|
||||
}
|
||||
|
@ -9812,7 +9812,7 @@ nsresult HTMLEditor::AdjustCaretPositionAndEnsurePaddingBRElement(
|
|||
if (blockElementAtCaret &&
|
||||
blockElementAtCaret == blockElementParentAtPreviousEditableContent &&
|
||||
previousEditableContent &&
|
||||
TextEditUtils::IsBreak(previousEditableContent)) {
|
||||
previousEditableContent->IsHTMLElement(nsGkAtoms::br)) {
|
||||
// If it's an invisible `<br>` element, we need to insert a padding
|
||||
// `<br>` element for making empty line have one-line height.
|
||||
if (!IsVisibleBRElement(previousEditableContent)) {
|
||||
|
@ -9862,7 +9862,7 @@ nsresult HTMLEditor::AdjustCaretPositionAndEnsurePaddingBRElement(
|
|||
// or `<hr>`, current caret position is fine.
|
||||
if (nsIContent* previousEditableContentInBlock =
|
||||
GetPreviousEditableHTMLNodeInBlock(point)) {
|
||||
if (TextEditUtils::IsBreak(previousEditableContentInBlock) ||
|
||||
if (previousEditableContentInBlock->IsHTMLElement(nsGkAtoms::br) ||
|
||||
EditorBase::IsTextNode(previousEditableContentInBlock) ||
|
||||
HTMLEditUtils::IsImage(previousEditableContentInBlock) ||
|
||||
previousEditableContentInBlock->IsHTMLElement(nsGkAtoms::hr)) {
|
||||
|
@ -9873,10 +9873,9 @@ nsresult HTMLEditor::AdjustCaretPositionAndEnsurePaddingBRElement(
|
|||
// `<hr>`, current caret position is fine.
|
||||
if (nsIContent* nextEditableContentInBlock =
|
||||
GetNextEditableHTMLNodeInBlock(point)) {
|
||||
if (TextEditUtils::IsBreak(nextEditableContentInBlock) ||
|
||||
EditorBase::IsTextNode(nextEditableContentInBlock) ||
|
||||
nextEditableContentInBlock->IsAnyOfHTMLElements(nsGkAtoms::img,
|
||||
nsGkAtoms::hr)) {
|
||||
if (EditorBase::IsTextNode(nextEditableContentInBlock) ||
|
||||
nextEditableContentInBlock->IsAnyOfHTMLElements(
|
||||
nsGkAtoms::br, nsGkAtoms::img, nsGkAtoms::hr)) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -9932,7 +9931,7 @@ nsIContent* HTMLEditor::FindNearEditableContent(
|
|||
// XXX This comment sounds odd. editableContent may have already crossed
|
||||
// breaks and/or images if they are non-editable.
|
||||
while (editableContent && !EditorBase::IsTextNode(editableContent) &&
|
||||
!TextEditUtils::IsBreak(editableContent) &&
|
||||
!editableContent->IsHTMLElement(nsGkAtoms::br) &&
|
||||
!HTMLEditUtils::IsImage(editableContent)) {
|
||||
if (aDirection == nsIEditor::ePrevious) {
|
||||
editableContent = GetPreviousEditableHTMLNode(*editableContent);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "HTMLEditUtils.h"
|
||||
|
||||
#include "TextEditUtils.h" // for TextEditUtils
|
||||
#include "mozilla/ArrayUtils.h" // for ArrayLength
|
||||
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
|
||||
#include "mozilla/EditAction.h" // for EditAction
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "HTMLEditorEventListener.h"
|
||||
#include "HTMLEditUtils.h"
|
||||
#include "TextEditUtils.h"
|
||||
#include "TypeInState.h"
|
||||
|
||||
#include "nsHTMLDocument.h"
|
||||
|
@ -883,7 +882,7 @@ void HTMLEditor::IsPrevCharInNodeWhitespace(nsIContent* aContent,
|
|||
|
||||
bool HTMLEditor::IsVisibleBRElement(nsINode* aNode) {
|
||||
MOZ_ASSERT(aNode);
|
||||
if (!TextEditUtils::IsBreak(aNode)) {
|
||||
if (!aNode->IsHTMLElement(nsGkAtoms::br)) {
|
||||
return false;
|
||||
}
|
||||
// Check if there is another element or text node in block after current
|
||||
|
@ -893,7 +892,7 @@ bool HTMLEditor::IsVisibleBRElement(nsINode* aNode) {
|
|||
// E.g., foo<br><button contenteditable="false">button</button>
|
||||
// However, we need to ignore invisible data nodes like comment node.
|
||||
nsCOMPtr<nsINode> nextNode = GetNextHTMLElementOrTextInBlock(*aNode);
|
||||
if (nextNode && TextEditUtils::IsBreak(nextNode)) {
|
||||
if (nextNode && nextNode->IsHTMLElement(nsGkAtoms::br)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -916,7 +915,7 @@ bool HTMLEditor::IsVisibleBRElement(nsINode* aNode) {
|
|||
// E.g., <button contenteditable="false"><br>foo
|
||||
// However, we need to ignore invisible data nodes like comment node.
|
||||
nsCOMPtr<nsINode> priorNode = GetPreviousHTMLElementOrTextInBlock(*aNode);
|
||||
if (priorNode && TextEditUtils::IsBreak(priorNode)) {
|
||||
if (priorNode && priorNode->IsHTMLElement(nsGkAtoms::br)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4493,7 +4492,7 @@ nsresult HTMLEditor::CopyLastEditableChildStylesWithTransaction(
|
|||
deepestEditableContent = child;
|
||||
}
|
||||
while (deepestEditableContent &&
|
||||
TextEditUtils::IsBreak(deepestEditableContent)) {
|
||||
deepestEditableContent->IsHTMLElement(nsGkAtoms::br)) {
|
||||
deepestEditableContent =
|
||||
GetPreviousEditableHTMLNode(*deepestEditableContent);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#include "HTMLEditUtils.h"
|
||||
#include "InternetCiter.h"
|
||||
#include "TextEditUtils.h"
|
||||
#include "WSRunObject.h"
|
||||
#include "mozilla/dom/Comment.h"
|
||||
#include "mozilla/dom/DataTransfer.h"
|
||||
|
@ -366,7 +365,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
|||
// element at end of what we paste, it will make the existing invisible
|
||||
// `<br>` element visible.
|
||||
WSRunObject wsObj(this, pointToInsert);
|
||||
if (wsObj.mEndReasonNode && TextEditUtils::IsBreak(wsObj.mEndReasonNode) &&
|
||||
if (wsObj.mEndReasonNode &&
|
||||
wsObj.mEndReasonNode->IsHTMLElement(nsGkAtoms::br) &&
|
||||
!IsVisibleBRElement(wsObj.mEndReasonNode)) {
|
||||
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
|
||||
rv = DeleteNodeWithTransaction(MOZ_KnownLive(*wsObj.mEndReasonNode));
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "mozilla/HTMLEditor.h"
|
||||
|
||||
#include "HTMLEditUtils.h"
|
||||
#include "TextEditUtils.h"
|
||||
#include "TypeInState.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/ContentIterator.h"
|
||||
|
@ -706,11 +705,11 @@ nsresult HTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
|
|||
if (!secondSplitParent) {
|
||||
secondSplitParent = rightNode;
|
||||
}
|
||||
nsCOMPtr<Element> savedBR;
|
||||
RefPtr<Element> savedBR;
|
||||
if (!IsContainer(secondSplitParent)) {
|
||||
if (TextEditUtils::IsBreak(secondSplitParent)) {
|
||||
savedBR = do_QueryInterface(secondSplitParent);
|
||||
NS_ENSURE_STATE(savedBR);
|
||||
if (secondSplitParent->IsHTMLElement(nsGkAtoms::br)) {
|
||||
savedBR = Element::FromNode(secondSplitParent);
|
||||
MOZ_ASSERT(savedBR);
|
||||
}
|
||||
|
||||
secondSplitParent = secondSplitParent->GetParentNode();
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "TextEditor.h"
|
||||
|
||||
#include "TextEditUtils.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/EditAction.h"
|
||||
#include "mozilla/EditorDOMPoint.h"
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "TextEditUtils.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/TextEditor.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/HTMLBRElement.h"
|
||||
#include "nsAString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCaseTreatment.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsError.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsNameSpaceManager.h"
|
||||
#include "nsLiteralString.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
using namespace dom;
|
||||
|
||||
/******************************************************************************
|
||||
* TextEditUtils
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* IsBreak() returns true if aNode is an html break node.
|
||||
*/
|
||||
bool TextEditUtils::IsBreak(nsINode* aNode) {
|
||||
MOZ_ASSERT(aNode);
|
||||
return aNode->IsHTMLElement(nsGkAtoms::br);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -1,24 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef TextEditUtils_h
|
||||
#define TextEditUtils_h
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
class nsINode;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class TextEditor;
|
||||
|
||||
class TextEditUtils final {
|
||||
public:
|
||||
static bool IsBreak(nsINode* aNode);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // #ifndef TextEditUtils_h
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "EditAggregateTransaction.h"
|
||||
#include "InternetCiter.h"
|
||||
#include "TextEditUtils.h"
|
||||
#include "gfxFontUtils.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/ContentIterator.h"
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
#include "WSRunObject.h"
|
||||
|
||||
#include "TextEditUtils.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Casting.h"
|
||||
#include "mozilla/EditorDOMPoint.h"
|
||||
|
@ -765,7 +763,7 @@ nsresult WSRunScanner::GetWSNodes() {
|
|||
// not a break but still serves as a terminator to ws runs.
|
||||
mStartNode = start.GetContainer();
|
||||
mStartOffset = start.Offset();
|
||||
if (TextEditUtils::IsBreak(priorNode)) {
|
||||
if (priorNode->IsHTMLElement(nsGkAtoms::br)) {
|
||||
mStartReason = WSType::br;
|
||||
} else {
|
||||
mStartReason = WSType::special;
|
||||
|
@ -872,7 +870,7 @@ nsresult WSRunScanner::GetWSNodes() {
|
|||
// serves as a terminator to ws runs.
|
||||
mEndNode = end.GetContainer();
|
||||
mEndOffset = end.Offset();
|
||||
if (TextEditUtils::IsBreak(nextNode)) {
|
||||
if (nextNode->IsHTMLElement(nsGkAtoms::br)) {
|
||||
mEndReason = WSType::br;
|
||||
} else {
|
||||
mEndReason = WSType::special;
|
||||
|
|
|
@ -71,7 +71,6 @@ UNIFIED_SOURCES += [
|
|||
'TextEditor.cpp',
|
||||
'TextEditorDataTransfer.cpp',
|
||||
'TextEditSubActionHandler.cpp',
|
||||
'TextEditUtils.cpp',
|
||||
'TypeInState.cpp',
|
||||
'WSRunObject.cpp',
|
||||
]
|
||||
|
|
Загрузка…
Ссылка в новой задаче