Bug 1639074 - Don't call `EditorDOMPoint::GetPreviousSiblingOfChild()` if the container is not a container element r=m_kato

For warning the potential of callers' bug, `GetPreviousSiblingOfChild()` outputs
warning into the console when its container is not a container element, e.g.,
it's odd trying to get previous sibling of child if the container is a text
node.  Therefore, this patch makes the new caller,
`WSRunScanner::GetPreviousEditableCharPoint()`, check
`CanContainerHaveChildren()` before calling it.

Differential Revision: https://phabricator.services.mozilla.com/D75888
This commit is contained in:
Masayuki Nakano 2020-05-20 07:11:17 +00:00
Родитель 9577e42b6f
Коммит a97bc5aea1
1 изменённых файлов: 5 добавлений и 2 удалений

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

@ -1316,7 +1316,8 @@ EditorDOMPointInText WSRunScanner::GetInclusiveNextEditableCharPoint(
}
EditorRawDOMPoint point;
if (nsIContent* child = aPoint.GetChild()) {
if (nsIContent* child =
aPoint.CanContainerHaveChildren() ? aPoint.GetChild() : nullptr) {
nsIContent* leafContent = child->HasChildren()
? HTMLEditUtils::GetFirstLeafChild(
*child, ChildBlockBoundary::Ignore)
@ -1380,7 +1381,9 @@ EditorDOMPointInText WSRunScanner::GetPreviousEditableCharPoint(
}
EditorRawDOMPoint point;
if (nsIContent* previousChild = aPoint.GetPreviousSiblingOfChild()) {
if (nsIContent* previousChild = aPoint.CanContainerHaveChildren()
? aPoint.GetPreviousSiblingOfChild()
: nullptr) {
nsIContent* leafContent =
previousChild->HasChildren()
? HTMLEditUtils::GetLastLeafChild(*previousChild,