Bug 1627175 - part 53: Rename `HTMLEditUtils::GetFirstLeafChild()` and `HTMLEditUtils::GetLastLeafChild()` r=m_kato

They may return a descendant, and now `HTMLEditUtils` has some methods whose
name ends with `Child` and they scan only direct children of given node.
So, we should rename these methods for avoiding misunderstanding.

Differential Revision: https://phabricator.services.mozilla.com/D115122
This commit is contained in:
Masayuki Nakano 2021-05-17 08:01:37 +00:00
Родитель 83505534d9
Коммит d6eec3ae11
7 изменённых файлов: 34 добавлений и 33 удалений

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

@ -5418,7 +5418,7 @@ nsresult HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction() {
// of going "down" into a block and "up" out of a block.
if (wsScannerAtEnd.StartsFromOtherBlockElement()) {
// endpoint is just after the close of a block.
nsIContent* child = HTMLEditUtils::GetLastLeafChild(
nsIContent* child = HTMLEditUtils::GetLastLeafContent(
*wsScannerAtEnd.StartReasonOtherBlockElementPtr(),
{LeafNodeType::LeafNodeOrChildBlock});
if (child) {
@ -5455,7 +5455,7 @@ nsresult HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction() {
// of going "down" into a block and "up" out of a block.
if (wsScannerAtStart.EndsByOtherBlockElement()) {
// startpoint is just before the start of a block.
nsINode* child = HTMLEditUtils::GetFirstLeafChild(
nsINode* child = HTMLEditUtils::GetFirstLeafContent(
*wsScannerAtStart.EndReasonOtherBlockElementPtr(),
{LeafNodeType::LeafNodeOrChildBlock});
if (child) {
@ -6901,7 +6901,7 @@ nsresult HTMLEditor::SplitParagraph(
// selection to beginning of right hand para;
// look inside any containers that are up front.
nsCOMPtr<nsIContent> child = HTMLEditUtils::GetFirstLeafChild(
nsCOMPtr<nsIContent> child = HTMLEditUtils::GetFirstLeafContent(
aParentDivOrP, {LeafNodeType::LeafNodeOrChildBlock});
if (child && (child->IsText() || HTMLEditUtils::IsContainerNode(*child))) {
nsresult rv = CollapseSelectionToStartOf(*child);

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

@ -987,7 +987,7 @@ nsIContent* HTMLEditUtils::GetPreviousContent(
// unless there isn't one, in which case we are at the end of the node
// and want the deep-right child.
nsIContent* lastLeafContent = HTMLEditUtils::GetLastLeafChild(
nsIContent* lastLeafContent = HTMLEditUtils::GetLastLeafContent(
*aPoint.GetContainer(),
{aOptions.contains(WalkTreeOption::StopAtBlockBoundary)
? LeafNodeType::LeafNodeOrChildBlock
@ -1032,7 +1032,7 @@ nsIContent* HTMLEditUtils::GetNextContent(
return point.GetChild();
}
nsIContent* firstLeafContent = HTMLEditUtils::GetFirstLeafChild(
nsIContent* firstLeafContent = HTMLEditUtils::GetFirstLeafContent(
*point.GetChild(),
{aOptions.contains(WalkTreeOption::StopAtBlockBoundary)
? LeafNodeType::LeafNodeOrChildBlock
@ -1100,8 +1100,8 @@ nsIContent* HTMLEditUtils::GetAdjacentLeafContent(
: LeafNodeType::OnlyLeafNode};
nsIContent* leafContent =
aWalkTreeDirection == WalkTreeDirection::Forward
? HTMLEditUtils::GetFirstLeafChild(*sibling, leafNodeTypes)
: HTMLEditUtils::GetLastLeafChild(*sibling, leafNodeTypes);
? HTMLEditUtils::GetFirstLeafContent(*sibling, leafNodeTypes)
: HTMLEditUtils::GetLastLeafContent(*sibling, leafNodeTypes);
return leafContent ? leafContent : sibling;
}

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

@ -555,8 +555,9 @@ class HTMLEditUtils final {
}
/**
* GetLastLeafChild() returns rightmost leaf content in aNode. It depends on
* aLeafNodeTypes whether this which types of nodes are treated as leaf nodes.
* GetLastLeafContent() returns rightmost leaf content in aNode. It depends
* on aLeafNodeTypes whether this which types of nodes are treated as leaf
* nodes.
*/
enum class LeafNodeType {
// Even if there is a child block, keep scanning a leaf content in it.
@ -569,8 +570,8 @@ class HTMLEditUtils final {
LeafNodeOrNonEditableNode,
};
using LeafNodeTypes = EnumSet<LeafNodeType>;
static nsIContent* GetLastLeafChild(nsINode& aNode,
const LeafNodeTypes& aLeafNodeTypes) {
static nsIContent* GetLastLeafContent(nsINode& aNode,
const LeafNodeTypes& aLeafNodeTypes) {
for (nsIContent* content = aNode.GetLastChild(); content;
content = content->GetLastChild()) {
if (aLeafNodeTypes.contains(LeafNodeType::LeafNodeOrChildBlock) &&
@ -589,12 +590,12 @@ class HTMLEditUtils final {
}
/**
* GetFirstLeafChild() returns leftmost leaf content in aNode. It depends on
* aLeafNodeTypes whether this scans into a block child or treat
* block as a leaf.
* GetFirstLeafContent() returns leftmost leaf content in aNode. It depends
* on aLeafNodeTypes whether this scans into a block child or treat block as a
* leaf.
*/
static nsIContent* GetFirstLeafChild(const nsINode& aNode,
const LeafNodeTypes& aLeafNodeTypes) {
static nsIContent* GetFirstLeafContent(const nsINode& aNode,
const LeafNodeTypes& aLeafNodeTypes) {
for (nsIContent* content = aNode.GetFirstChild(); content;
content = content->GetFirstChild()) {
if (aLeafNodeTypes.contains(LeafNodeType::LeafNodeOrChildBlock) &&
@ -671,8 +672,8 @@ class HTMLEditUtils final {
}
if (HTMLEditUtils::IsContainerNode(*nextContent)) {
// Else if it's a container, get deep leftmost child
if (nsIContent* child =
HTMLEditUtils::GetFirstLeafChild(*nextContent, aLeafNodeTypes)) {
if (nsIContent* child = HTMLEditUtils::GetFirstLeafContent(
*nextContent, aLeafNodeTypes)) {
return child;
}
}
@ -729,8 +730,8 @@ class HTMLEditUtils final {
}
if (HTMLEditUtils::IsContainerNode(*nextContent)) {
// else if it's a container, get deep leftmost child
if (nsIContent* child =
HTMLEditUtils::GetFirstLeafChild(*nextContent, aLeafNodeTypes)) {
if (nsIContent* child = HTMLEditUtils::GetFirstLeafContent(
*nextContent, aLeafNodeTypes)) {
return child;
}
}
@ -798,8 +799,8 @@ class HTMLEditUtils final {
}
if (HTMLEditUtils::IsContainerNode(*previousContent)) {
// Else if it's a container, get deep rightmost child
if (nsIContent* child = HTMLEditUtils::GetLastLeafChild(*previousContent,
aLeafNodeTypes)) {
if (nsIContent* child = HTMLEditUtils::GetLastLeafContent(
*previousContent, aLeafNodeTypes)) {
return child;
}
}
@ -861,8 +862,8 @@ class HTMLEditUtils final {
}
if (HTMLEditUtils::IsContainerNode(*previousContent)) {
// Else if it's a container, get deep rightmost child
if (nsIContent* child = HTMLEditUtils::GetLastLeafChild(*previousContent,
aLeafNodeTypes)) {
if (nsIContent* child = HTMLEditUtils::GetLastLeafContent(
*previousContent, aLeafNodeTypes)) {
return child;
}
}

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

@ -2811,7 +2811,7 @@ already_AddRefed<Element> HTMLEditor::GetSelectedElement(const nsAtom* aTagName,
if (nextSibling->IsHTMLElement(nsGkAtoms::br)) {
return nullptr;
}
nsIContent* firstEditableLeaf = HTMLEditUtils::GetFirstLeafChild(
nsIContent* firstEditableLeaf = HTMLEditUtils::GetFirstLeafContent(
*nextSibling, {LeafNodeType::OnlyLeafNode});
if (firstEditableLeaf &&
firstEditableLeaf->IsHTMLElement(nsGkAtoms::br)) {
@ -4939,7 +4939,7 @@ nsIContent* HTMLEditor::GetFirstEditableLeaf(nsINode& aNode) const {
return nullptr;
}
nsIContent* child =
HTMLEditUtils::GetFirstLeafChild(aNode, {LeafNodeType::OnlyLeafNode});
HTMLEditUtils::GetFirstLeafContent(aNode, {LeafNodeType::OnlyLeafNode});
while (child && (!EditorUtils::IsEditableContent(*child, EditorType::HTML) ||
child->HasChildren())) {
child = HTMLEditUtils::GetNextContent(
@ -4957,7 +4957,7 @@ nsIContent* HTMLEditor::GetLastEditableLeaf(nsINode& aNode) const {
return nullptr;
}
nsIContent* child =
HTMLEditUtils::GetLastLeafChild(aNode, {LeafNodeType::OnlyLeafNode});
HTMLEditUtils::GetLastLeafContent(aNode, {LeafNodeType::OnlyLeafNode});
while (child && (!EditorUtils::IsEditableContent(*child, EditorType::HTML) ||
child->HasChildren())) {
child = HTMLEditUtils::GetPreviousContent(

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

@ -1008,7 +1008,7 @@ EditResult HTMLEditor::ClearStyleAt(const EditorDOMPoint& aPoint,
// the next node. The first example should become
// `<p><b><i>a</i></b><b><i></i></b><b><i>bc</i></b></p>`.
// ^^^^^^^^^^^^^^
nsIContent* firstLeafChildOfNextNode = HTMLEditUtils::GetFirstLeafChild(
nsIContent* firstLeafChildOfNextNode = HTMLEditUtils::GetFirstLeafContent(
*splitResult.GetNextNode(), {LeafNodeType::OnlyLeafNode});
EditorDOMPoint atStartOfNextNode(firstLeafChildOfNextNode
? firstLeafChildOfNextNode
@ -1070,7 +1070,7 @@ EditResult HTMLEditor::ClearStyleAt(const EditorDOMPoint& aPoint,
// Now, we want to put `<br>` element into the empty split node if
// it was in next node of the first split.
// E.g., `<p><b><i>a</i></b><b><i><br></i></b><b><i>bc</i></b></p>`
nsIContent* firstLeafChildOfPreviousNode = HTMLEditUtils::GetFirstLeafChild(
nsIContent* firstLeafChildOfPreviousNode = HTMLEditUtils::GetFirstLeafContent(
*splitResultAtStartOfNextNode.GetPreviousNode(),
{LeafNodeType::OnlyLeafNode});
EditorDOMPoint pointToPutCaret(

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

@ -1021,7 +1021,7 @@ nsresult TextEditor::UndoAsAction(uint32_t aCount, nsIPrincipal* aPrincipal) {
// at redo, or doing it everywhere else that might care. Since undo
// and redo are relatively rare, it makes sense to take the (small)
// performance hit here.
nsIContent* firstLeafChild = HTMLEditUtils::GetFirstLeafChild(
nsIContent* firstLeafChild = HTMLEditUtils::GetFirstLeafContent(
*mRootElement, {LeafNodeType::OnlyLeafNode});
if (firstLeafChild &&
EditorUtils::IsPaddingBRElementForEmptyEditor(*firstLeafChild)) {

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

@ -2305,7 +2305,7 @@ WSRunScanner::TextFragmentData::GetInclusiveNextEditableCharPoint(
if (nsIContent* child =
aPoint.CanContainerHaveChildren() ? aPoint.GetChild() : nullptr) {
nsIContent* leafContent = child->HasChildren()
? HTMLEditUtils::GetFirstLeafChild(
? HTMLEditUtils::GetFirstLeafContent(
*child, {LeafNodeType::OnlyLeafNode})
: child;
if (NS_WARN_IF(!leafContent)) {
@ -2385,8 +2385,8 @@ WSRunScanner::TextFragmentData::GetPreviousEditableCharPoint(
: nullptr) {
nsIContent* leafContent =
previousChild->HasChildren()
? HTMLEditUtils::GetLastLeafChild(*previousChild,
{LeafNodeType::OnlyLeafNode})
? HTMLEditUtils::GetLastLeafContent(*previousChild,
{LeafNodeType::OnlyLeafNode})
: previousChild;
if (NS_WARN_IF(!leafContent)) {
return EditorDOMPointInText();