Bug 1639074 - Don't call `EditorDOMPoint::GetPreviousSiblingOfChild()` if the container is not a container element r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 20 May 2020 07:11:17 +0000
changeset 530966 029bf474ca62ae35411cf904a1e7bea4fee5a2d6
parent 530965 dbaa47665f9a2693efa9bbafef7133f6c8278ee0
child 530967 dc4525f247b901b1f6f958e3fd8518dd85dfff17
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1639074
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
editor/libeditor/WSRunObject.cpp
--- a/editor/libeditor/WSRunObject.cpp
+++ b/editor/libeditor/WSRunObject.cpp
@@ -1311,17 +1311,18 @@ EditorDOMPointInText WSRunScanner::GetIn
   MOZ_ASSERT(aPoint.IsSetAndValid());
 
   if (NS_WARN_IF(!aPoint.IsInContentNode()) ||
       NS_WARN_IF(!mScanStartPoint.IsInContentNode())) {
     return EditorDOMPointInText();
   }
 
   EditorRawDOMPoint point;
-  if (nsIContent* child = aPoint.GetChild()) {
+  if (nsIContent* child =
+          aPoint.CanContainerHaveChildren() ? aPoint.GetChild() : nullptr) {
     nsIContent* leafContent = child->HasChildren()
                                   ? HTMLEditUtils::GetFirstLeafChild(
                                         *child, ChildBlockBoundary::Ignore)
                                   : child;
     if (NS_WARN_IF(!leafContent)) {
       return EditorDOMPointInText();
     }
     point.Set(leafContent, 0);
@@ -1375,17 +1376,19 @@ EditorDOMPointInText WSRunScanner::GetPr
   MOZ_ASSERT(aPoint.IsSetAndValid());
 
   if (NS_WARN_IF(!aPoint.IsInContentNode()) ||
       NS_WARN_IF(!mScanStartPoint.IsInContentNode())) {
     return EditorDOMPointInText();
   }
 
   EditorRawDOMPoint point;
-  if (nsIContent* previousChild = aPoint.GetPreviousSiblingOfChild()) {
+  if (nsIContent* previousChild = aPoint.CanContainerHaveChildren()
+                                      ? aPoint.GetPreviousSiblingOfChild()
+                                      : nullptr) {
     nsIContent* leafContent =
         previousChild->HasChildren()
             ? HTMLEditUtils::GetLastLeafChild(*previousChild,
                                               ChildBlockBoundary::Ignore)
             : previousChild;
     if (NS_WARN_IF(!leafContent)) {
       return EditorDOMPointInText();
     }