Bug 1727844 - part 3: Rename `EditorUtils::IsContentPreformatted()` to `IsWhiteSpacePreformatted()` r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 31 Aug 2021 17:37:41 +0000
changeset 590344 4be65378de382a1fa8505e5093a8fc5901a2b45f
parent 590343 b55f2bffdb958a4bb013f59e6435041c46ea09a0
child 590345 11dce090ce943aada134ba77a201ac7de49ea4e3
push id38752
push usermalexandru@mozilla.com
push dateWed, 01 Sep 2021 03:48:05 +0000
treeherdermozilla-central@a14cf6b742de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1727844
milestone93.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 1727844 - part 3: Rename `EditorUtils::IsContentPreformatted()` to `IsWhiteSpacePreformatted()` r=m_kato The method returns false even if linefeed characters are preformatted. So, it should be renamed to explain what it does clearer. And this renames `TextFragmentData::mIsPreformatted` and its accessors too. Differential Revision: https://phabricator.services.mozilla.com/D123870
editor/libeditor/EditorUtils.cpp
editor/libeditor/EditorUtils.h
editor/libeditor/HTMLEditSubActionHandler.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/WSRunObject.cpp
editor/libeditor/WSRunObject.h
--- a/editor/libeditor/EditorUtils.cpp
+++ b/editor/libeditor/EditorUtils.cpp
@@ -533,17 +533,17 @@ void EditorUtils::MaskString(nsString& a
     // Skip the following low surrogate.
     if (isSurrogatePair) {
       ++i;
     }
   }
 }
 
 // static
-bool EditorUtils::IsContentPreformatted(nsIContent& aContent) {
+bool EditorUtils::IsWhiteSpacePreformatted(const nsIContent& aContent) {
   // Look at the node (and its parent if it's not an element), and grab its
   // ComputedStyle.
   Element* element = aContent.GetAsElementOrParentElement();
   if (!element) {
     return false;
   }
 
   RefPtr<ComputedStyle> elementStyle =
--- a/editor/libeditor/EditorUtils.h
+++ b/editor/libeditor/EditorUtils.h
@@ -1156,20 +1156,20 @@ class EditorUtils final {
   static bool IsElementOrText(const nsIContent& aContent) {
     if (aContent.IsText()) {
       return true;
     }
     return aContent.IsElement() && !IsPaddingBRElementForEmptyEditor(aContent);
   }
 
   /**
-   * IsContentPreformatted() checks the style info for the node for the
+   * IsWhiteSpacePreformatted() checks the style info for the node for the
    * preformatted text style.  This does NOT flush layout.
    */
-  static bool IsContentPreformatted(nsIContent& aContent);
+  static bool IsWhiteSpacePreformatted(const nsIContent& aContent);
 
   /**
    * Helper method for `AppendString()` and `AppendSubString()`.  This should
    * be called only when `aText` is in a password field.  This method masks
    * A part of or all of `aText` (`aStartOffsetInText` and later) should've
    * been copied (apppended) to `aString`.  `aStartOffsetInString` is where
    * the password was appended into `aString`.
    */
--- a/editor/libeditor/HTMLEditSubActionHandler.cpp
+++ b/editor/libeditor/HTMLEditSubActionHandler.cpp
@@ -1107,18 +1107,18 @@ EditActionResult HTMLEditor::HandleInser
 
   MOZ_ASSERT(aEditSubAction == EditSubAction::eInsertText);
 
   // find where we are
   EditorDOMPoint currentPoint(pointToInsert);
 
   // is our text going to be PREformatted?
   // We remember this so that we know how to handle tabs.
-  bool isPRE =
-      EditorUtils::IsContentPreformatted(*pointToInsert.ContainerAsContent());
+  const bool isWhiteSpaceCollapsible = !EditorUtils::IsWhiteSpacePreformatted(
+      *pointToInsert.ContainerAsContent());
 
   // turn off the edit listener: we know how to
   // build the "doc changed range" ourselves, and it's
   // must faster to do it once here than to track all
   // the changes one at a time.
   AutoRestore<bool> disableListener(
       EditSubActionDataRef().mAdjustChangedRangeFromListener);
   EditSubActionDataRef().mAdjustChangedRangeFromListener = false;
@@ -1129,17 +1129,17 @@ EditActionResult HTMLEditor::HandleInser
   constexpr auto newlineStr = NS_LITERAL_STRING_FROM_CSTRING(LFSTR);
 
   {
     AutoTrackDOMPoint tracker(RangeUpdaterRef(), &pointToInsert);
 
     // 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 || IsInPlaintextMode()) {
+    if (!isWhiteSpaceCollapsible || IsInPlaintextMode()) {
       while (pos != -1 &&
              pos < AssertedCast<int32_t>(aInsertionString.Length())) {
         int32_t oldPos = pos;
         int32_t subStrLen;
         pos = aInsertionString.FindChar(nsCRT::LF, oldPos);
 
         if (pos != -1) {
           subStrLen = pos - oldPos;
@@ -2110,24 +2110,24 @@ void HTMLEditor::ExtendRangeToDeleteWith
       aStartToDelete.ContainerAsText() != aEndToDelete.ContainerAsText() ||
       (aEndToDelete.IsEndOfContainer() && followingCharPoint.IsSet());
   const bool maybeNormalizePrecedingWhiteSpaces =
       !removingLastCharOfStartNode && precedingCharPoint.IsSet() &&
       !precedingCharPoint.IsEndOfContainer() &&
       precedingCharPoint.ContainerAsText() ==
           aStartToDelete.ContainerAsText() &&
       precedingCharPoint.IsCharASCIISpaceOrNBSP() &&
-      !EditorUtils::IsContentPreformatted(
+      !EditorUtils::IsWhiteSpacePreformatted(
           *precedingCharPoint.ContainerAsText());
   const bool maybeNormalizeFollowingWhiteSpaces =
       followingCharPoint.IsSet() && !followingCharPoint.IsEndOfContainer() &&
       (followingCharPoint.ContainerAsText() == aEndToDelete.ContainerAsText() ||
        removingLastCharOfStartNode) &&
       followingCharPoint.IsCharASCIISpaceOrNBSP() &&
-      !EditorUtils::IsContentPreformatted(
+      !EditorUtils::IsWhiteSpacePreformatted(
           *followingCharPoint.ContainerAsText());
 
   if (!maybeNormalizePrecedingWhiteSpaces &&
       !maybeNormalizeFollowingWhiteSpaces) {
     return;  // There are no white-spaces.
   }
 
   // Next, consider the range to normalize.
@@ -5802,17 +5802,17 @@ EditorDOMPoint HTMLEditor::GetCurrentHar
       break;
     }
     if (HTMLEditUtils::IsVisibleBRElement(*nextEditableContent, editingHost)) {
       break;
     }
 
     // Check for newlines in pre-formatted text nodes.
     if (nextEditableContent->IsText() &&
-        EditorUtils::IsContentPreformatted(*nextEditableContent)) {
+        EditorUtils::IsWhiteSpacePreformatted(*nextEditableContent)) {
       nsAutoString textContent;
       nextEditableContent->GetAsText()->GetData(textContent);
       int32_t newlinePos = textContent.FindChar(nsCRT::LF);
       if (newlinePos >= 0) {
         if (AssertedCast<uint32_t>(newlinePos) + 1 == textContent.Length()) {
           // No need for special processing if the newline is at the end.
           break;
         }
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -2184,32 +2184,32 @@ class HTMLEditor final : public EditorBa
    */
   template <typename EditorDOMPointType>
   static CharPointType GetPreviousCharPointType(
       const EditorDOMPointType& aPoint) {
     MOZ_ASSERT(aPoint.IsInTextNode());
     if (aPoint.IsStartOfContainer()) {
       return CharPointType::TextEnd;
     }
-    if (EditorUtils::IsContentPreformatted(*aPoint.ContainerAsText())) {
+    if (EditorUtils::IsWhiteSpacePreformatted(*aPoint.ContainerAsText())) {
       return CharPointType::PreformattedChar;
     }
     if (aPoint.IsPreviousCharASCIISpace()) {
       return CharPointType::ASCIIWhiteSpace;
     }
     return aPoint.IsPreviousCharNBSP() ? CharPointType::NoBreakingSpace
                                        : CharPointType::VisibleChar;
   }
   template <typename EditorDOMPointType>
   static CharPointType GetCharPointType(const EditorDOMPointType& aPoint) {
     MOZ_ASSERT(aPoint.IsInTextNode());
     if (aPoint.IsEndOfContainer()) {
       return CharPointType::TextEnd;
     }
-    if (EditorUtils::IsContentPreformatted(*aPoint.ContainerAsText())) {
+    if (EditorUtils::IsWhiteSpacePreformatted(*aPoint.ContainerAsText())) {
       return CharPointType::PreformattedChar;
     }
     if (aPoint.IsCharASCIISpace()) {
       return CharPointType::ASCIIWhiteSpace;
     }
     return aPoint.IsCharNBSP() ? CharPointType::NoBreakingSpace
                                : CharPointType::VisibleChar;
   }
--- a/editor/libeditor/WSRunObject.cpp
+++ b/editor/libeditor/WSRunObject.cpp
@@ -728,17 +728,17 @@ Result<RefPtr<Element>, nsresult> WhiteS
              pointPositionWithVisibleWhiteSpaces ==
                  PointPosition::MiddleOfFragment) {
       EditorRawDOMPointInText atNextCharOfInsertionPoint =
           textFragmentDataAtInsertionPoint.GetInclusiveNextEditableCharPoint(
               pointToInsert);
       if (atNextCharOfInsertionPoint.IsSet() &&
           !atNextCharOfInsertionPoint.IsEndOfContainer() &&
           atNextCharOfInsertionPoint.IsCharASCIISpace() &&
-          !EditorUtils::IsContentPreformatted(
+          !EditorUtils::IsWhiteSpacePreformatted(
               *atNextCharOfInsertionPoint.ContainerAsText())) {
         EditorRawDOMPointInText atPreviousCharOfNextCharOfInsertionPoint =
             textFragmentDataAtInsertionPoint.GetPreviousEditableCharPoint(
                 atNextCharOfInsertionPoint);
         if (!atPreviousCharOfNextCharOfInsertionPoint.IsSet() ||
             atPreviousCharOfNextCharOfInsertionPoint.IsEndOfContainer() ||
             !atPreviousCharOfNextCharOfInsertionPoint.IsCharASCIISpace()) {
           // We are at start of non-nbsps.  Convert to a single nbsp.
@@ -1111,17 +1111,17 @@ nsresult WhiteSpaceVisibilityKeeper::Del
   EditorDOMPointInText atPreviousCharOfStart =
       textFragmentDataAtDeletion.GetPreviousEditableCharPoint(aPoint);
   if (!atPreviousCharOfStart.IsSet() ||
       atPreviousCharOfStart.IsEndOfContainer()) {
     return NS_OK;
   }
 
   // Easy case, preformatted ws.
-  if (EditorUtils::IsContentPreformatted(
+  if (EditorUtils::IsWhiteSpacePreformatted(
           *atPreviousCharOfStart.ContainerAsText())) {
     if (!atPreviousCharOfStart.IsCharASCIISpace() &&
         !atPreviousCharOfStart.IsCharNBSP()) {
       return NS_OK;
     }
     nsresult rv = aHTMLEditor.DeleteTextAndTextNodesWithTransaction(
         atPreviousCharOfStart, atPreviousCharOfStart.NextPoint(),
         HTMLEditor::TreatEmptyTextNodes::KeepIfContainerOfRangeBoundaries);
@@ -1196,17 +1196,17 @@ nsresult WhiteSpaceVisibilityKeeper::Del
   }
   EditorDOMPointInText atNextCharOfStart =
       textFragmentDataAtDeletion.GetInclusiveNextEditableCharPoint(aPoint);
   if (!atNextCharOfStart.IsSet() || atNextCharOfStart.IsEndOfContainer()) {
     return NS_OK;
   }
 
   // Easy case, preformatted ws.
-  if (EditorUtils::IsContentPreformatted(
+  if (EditorUtils::IsWhiteSpacePreformatted(
           *atNextCharOfStart.ContainerAsText())) {
     if (!atNextCharOfStart.IsCharASCIISpace() &&
         !atNextCharOfStart.IsCharNBSP()) {
       return NS_OK;
     }
     nsresult rv = aHTMLEditor.DeleteTextAndTextNodesWithTransaction(
         atNextCharOfStart, atNextCharOfStart.NextPoint(),
         HTMLEditor::TreatEmptyTextNodes::KeepIfContainerOfRangeBoundaries);
@@ -1427,17 +1427,17 @@ WSScanResult WSRunScanner::ScanNextVisib
   }
   return WSScanResult(TextFragmentDataAtStartRef().EndRef(),
                       TextFragmentDataAtStartRef().EndRawReason());
 }
 
 template <typename EditorDOMPointType>
 WSRunScanner::TextFragmentData::TextFragmentData(
     const EditorDOMPointType& aPoint, const Element* aEditingHost)
-    : mEditingHost(aEditingHost), mIsPreformatted(false) {
+    : mEditingHost(aEditingHost), mIsWhiteSpaceCollapsible(true) {
   if (!aPoint.IsSetAndValid()) {
     NS_WARNING("aPoint was invalid");
     return;
   }
   if (!aPoint.IsInContentNode()) {
     NS_WARNING("aPoint was in Document or DocumentFragment");
     // I.e., we're try to modify outside of root element.  We don't need to
     // support such odd case because web apps cannot append text nodes as
@@ -1475,32 +1475,32 @@ WSRunScanner::TextFragmentData::TextFrag
       mScanStartPoint, *editableBlockElementOrInlineEditingHost, mEditingHost,
       &mNBSPData);
   // If scan start point is start/end of preformatted text node, only
   // mEnd/mStart crosses a preformatted character so that when one of
   // them crosses a preformatted character, this fragment's range is
   // preformatted.
   // Additionally, if the scan start point is preformatted, and there is
   // no text node around it, the range is also preformatted.
-  mIsPreformatted = mStart.AcrossPreformattedCharacter() ||
-                    mEnd.AcrossPreformattedCharacter() ||
-                    (EditorUtils::IsContentPreformatted(
-                         *mScanStartPoint.ContainerAsContent()) &&
-                     !mStart.IsNormalText() && !mEnd.IsNormalText());
+  mIsWhiteSpaceCollapsible = !mStart.AcrossPreformattedCharacter() &&
+                             !mEnd.AcrossPreformattedCharacter() &&
+                             !(EditorUtils::IsWhiteSpacePreformatted(
+                                   *mScanStartPoint.ContainerAsContent()) &&
+                               !mStart.IsNormalText() && !mEnd.IsNormalText());
 }
 
 // static
 template <typename EditorDOMPointType>
 Maybe<WSRunScanner::TextFragmentData::BoundaryData> WSRunScanner::
     TextFragmentData::BoundaryData::ScanCollapsibleWhiteSpaceStartInTextNode(
         const EditorDOMPointType& aPoint, NoBreakingSpaceData* aNBSPData) {
   MOZ_ASSERT(aPoint.IsSetAndValid());
   MOZ_DIAGNOSTIC_ASSERT(aPoint.IsInTextNode());
   MOZ_DIAGNOSTIC_ASSERT(
-      !EditorUtils::IsContentPreformatted(*aPoint.ContainerAsText()));
+      !EditorUtils::IsWhiteSpacePreformatted(*aPoint.ContainerAsText()));
 
   const nsTextFragment& textFragment = aPoint.ContainerAsText()->TextFragment();
   for (uint32_t i = std::min(aPoint.Offset(), textFragment.GetLength()); i;
        i--) {
     char16_t ch = textFragment.CharAt(i - 1);
     if (nsCRT::IsAsciiSpace(ch)) {
       continue;
     }
@@ -1529,17 +1529,17 @@ WSRunScanner::TextFragmentData::Boundary
         const EditorDOMPointType& aPoint,
         const Element& aEditableBlockParentOrTopmostEditableInlineContent,
         const Element* aEditingHost, NoBreakingSpaceData* aNBSPData) {
   MOZ_ASSERT(aPoint.IsSetAndValid());
 
   if (aPoint.IsInTextNode() && !aPoint.IsStartOfContainer()) {
     // If the point is in a text node which is preformatted, we should return
     // the point as a visible character point.
-    if (EditorUtils::IsContentPreformatted(*aPoint.ContainerAsText())) {
+    if (EditorUtils::IsWhiteSpacePreformatted(*aPoint.ContainerAsText())) {
       return BoundaryData(aPoint, *aPoint.ContainerAsText(), WSType::NormalText,
                           Preformatted::Yes);
     }
     // If the text node is not preformatted, we should look for its preceding
     // characters.
     Maybe<BoundaryData> startInTextNode =
         BoundaryData::ScanCollapsibleWhiteSpaceStartInTextNode(aPoint,
                                                                aNBSPData);
@@ -1591,17 +1591,17 @@ WSRunScanner::TextFragmentData::Boundary
     // Note that even if the empty text node is preformatted, we should keep
     // looking for the previous one.
     return BoundaryData::ScanCollapsibleWhiteSpaceStartFrom(
         EditorDOMPointInText(previousLeafContentOrBlock->AsText(), 0),
         aEditableBlockParentOrTopmostEditableInlineContent, aEditingHost,
         aNBSPData);
   }
 
-  if (EditorUtils::IsContentPreformatted(*previousLeafContentOrBlock)) {
+  if (EditorUtils::IsWhiteSpacePreformatted(*previousLeafContentOrBlock)) {
     // If the previous text node is preformatted and not empty, we should return
     // its end as found a visible character.  Note that we stop scanning
     // collapsible white-spaces due to reaching preformatted non-empty text
     // node.  I.e., the following text node might be not preformatted.
     return BoundaryData(EditorDOMPoint::AtEndOf(*previousLeafContentOrBlock),
                         *previousLeafContentOrBlock, WSType::NormalText,
                         Preformatted::No);
   }
@@ -1625,17 +1625,17 @@ WSRunScanner::TextFragmentData::Boundary
 // static
 template <typename EditorDOMPointType>
 Maybe<WSRunScanner::TextFragmentData::BoundaryData> WSRunScanner::
     TextFragmentData::BoundaryData::ScanCollapsibleWhiteSpaceEndInTextNode(
         const EditorDOMPointType& aPoint, NoBreakingSpaceData* aNBSPData) {
   MOZ_ASSERT(aPoint.IsSetAndValid());
   MOZ_DIAGNOSTIC_ASSERT(aPoint.IsInTextNode());
   MOZ_DIAGNOSTIC_ASSERT(
-      !EditorUtils::IsContentPreformatted(*aPoint.ContainerAsText()));
+      !EditorUtils::IsWhiteSpacePreformatted(*aPoint.ContainerAsText()));
 
   const nsTextFragment& textFragment = aPoint.ContainerAsText()->TextFragment();
   for (uint32_t i = aPoint.Offset(); i < textFragment.GetLength(); i++) {
     char16_t ch = textFragment.CharAt(i);
     if (nsCRT::IsAsciiSpace(ch)) {
       continue;
     }
 
@@ -1662,17 +1662,17 @@ WSRunScanner::TextFragmentData::Boundary
     const EditorDOMPointType& aPoint,
     const Element& aEditableBlockParentOrTopmostEditableInlineElement,
     const Element* aEditingHost, NoBreakingSpaceData* aNBSPData) {
   MOZ_ASSERT(aPoint.IsSetAndValid());
 
   if (aPoint.IsInTextNode() && !aPoint.IsEndOfContainer()) {
     // If the point is in a text node which is preformatted, we should return
     // the point as a visible character point.
-    if (EditorUtils::IsContentPreformatted(*aPoint.ContainerAsText())) {
+    if (EditorUtils::IsWhiteSpacePreformatted(*aPoint.ContainerAsText())) {
       return BoundaryData(aPoint, *aPoint.ContainerAsText(), WSType::NormalText,
                           Preformatted::Yes);
     }
     // If the text node is not preformatted, we should look for inclusive
     // next characters.
     Maybe<BoundaryData> endInTextNode =
         BoundaryData::ScanCollapsibleWhiteSpaceEndInTextNode(aPoint, aNBSPData);
     if (endInTextNode.isSome()) {
@@ -1725,17 +1725,17 @@ WSRunScanner::TextFragmentData::Boundary
     // Note that even if the empty text node is preformatted, we should keep
     // looking for the next one.
     return BoundaryData::ScanCollapsibleWhiteSpaceEndFrom(
         EditorDOMPointInText(nextLeafContentOrBlock->AsText(), 0),
         aEditableBlockParentOrTopmostEditableInlineElement, aEditingHost,
         aNBSPData);
   }
 
-  if (EditorUtils::IsContentPreformatted(*nextLeafContentOrBlock)) {
+  if (EditorUtils::IsWhiteSpacePreformatted(*nextLeafContentOrBlock)) {
     // If the next text node is preformatted and not empty, we should return
     // its start as found a visible character.  Note that we stop scanning
     // collapsible white-spaces due to reaching preformatted non-empty text
     // node.  I.e., the following text node might be not preformatted.
     return BoundaryData(EditorDOMPoint(nextLeafContentOrBlock, 0),
                         *nextLeafContentOrBlock, WSType::NormalText,
                         Preformatted::No);
   }
@@ -1868,17 +1868,17 @@ WSRunScanner::TextFragmentData::GetNonCo
 }
 
 const WSRunScanner::VisibleWhiteSpacesData&
 WSRunScanner::TextFragmentData::VisibleWhiteSpacesDataRef() const {
   if (mVisibleWhiteSpacesData.isSome()) {
     return mVisibleWhiteSpacesData.ref();
   }
 
-  if (IsPreformattedOrSurrondedByVisibleContent()) {
+  if (IsWhiteSpaceNotCollapsibleOrSurrondedByVisibleContent()) {
     VisibleWhiteSpacesData visibleWhiteSpaces;
     if (mStart.PointRef().IsSet()) {
       visibleWhiteSpaces.SetStartPoint(mStart.PointRef());
     }
     visibleWhiteSpaces.SetStartFrom(mStart.RawReason());
     if (mEnd.PointRef().IsSet()) {
       visibleWhiteSpaces.SetEndPoint(mEnd.PointRef());
     }
@@ -2146,17 +2146,17 @@ WSRunScanner::TextFragmentData::GetRepla
     if (invisibleTrailingWhiteSpaceRangeAtEnd.Collapsed()) {
       return ReplaceRangeData();
     }
     // XXX Why don't we remove all invisible white-spaces?
     MOZ_ASSERT(invisibleTrailingWhiteSpaceRangeAtEnd.StartRef() == endToDelete);
     return ReplaceRangeData(invisibleTrailingWhiteSpaceRangeAtEnd, u""_ns);
   }
 
-  if (IsPreformatted()) {
+  if (!IsWhiteSpaceCollapsible()) {
     return ReplaceRangeData();
   }
 
   // If end of the deleting range is followed by visible white-spaces which
   // is not preformatted, we might need to replace the following ASCII
   // white-spaces with an NBSP.
   const VisibleWhiteSpacesData& nonPreformattedVisibleWhiteSpacesAtEnd =
       VisibleWhiteSpacesDataRef();
@@ -2178,17 +2178,17 @@ WSRunScanner::TextFragmentData::GetRepla
            .FollowingContentMayBecomeFirstVisibleContent(startToDelete)) {
     return ReplaceRangeData();
   }
   EditorRawDOMPointInText nextCharOfStartOfEnd =
       GetInclusiveNextEditableCharPoint(endToDelete);
   if (!nextCharOfStartOfEnd.IsSet() ||
       nextCharOfStartOfEnd.IsEndOfContainer() ||
       !nextCharOfStartOfEnd.IsCharASCIISpace() ||
-      EditorUtils::IsContentPreformatted(
+      EditorUtils::IsWhiteSpacePreformatted(
           *nextCharOfStartOfEnd.ContainerAsText())) {
     return ReplaceRangeData();
   }
   if (nextCharOfStartOfEnd.IsStartOfContainer() ||
       nextCharOfStartOfEnd.IsPreviousCharASCIISpace()) {
     nextCharOfStartOfEnd =
         aTextFragmentDataAtStartToDelete
             .GetFirstASCIIWhiteSpacePointCollapsedTo(nextCharOfStartOfEnd);
@@ -2225,17 +2225,17 @@ WSRunScanner::TextFragmentData::GetRepla
     if (invisibleLeadingWhiteSpaceRangeAtStart.Collapsed()) {
       return ReplaceRangeData();
     }
 
     // XXX Why don't we remove all leading white-spaces?
     return ReplaceRangeData(invisibleLeadingWhiteSpaceRangeAtStart, u""_ns);
   }
 
-  if (IsPreformatted()) {
+  if (!IsWhiteSpaceCollapsible()) {
     return ReplaceRangeData();
   }
 
   // If start of the deleting range follows visible white-spaces which is not
   // preformatted, we might need to replace previous ASCII white-spaces with
   // an NBSP.
   const VisibleWhiteSpacesData& nonPreformattedVisibleWhiteSpacesAtStart =
       VisibleWhiteSpacesDataRef();
@@ -2259,17 +2259,17 @@ WSRunScanner::TextFragmentData::GetRepla
           endToDelete)) {
     return ReplaceRangeData();
   }
   EditorRawDOMPointInText atPreviousCharOfStart =
       GetPreviousEditableCharPoint(startToDelete);
   if (!atPreviousCharOfStart.IsSet() ||
       atPreviousCharOfStart.IsEndOfContainer() ||
       !atPreviousCharOfStart.IsCharASCIISpace() ||
-      EditorUtils::IsContentPreformatted(
+      EditorUtils::IsWhiteSpacePreformatted(
           *atPreviousCharOfStart.ContainerAsText())) {
     return ReplaceRangeData();
   }
   if (atPreviousCharOfStart.IsStartOfContainer() ||
       atPreviousCharOfStart.IsPreviousCharASCIISpace()) {
     atPreviousCharOfStart =
         GetFirstASCIIWhiteSpacePointCollapsedTo(atPreviousCharOfStart);
   }
@@ -2312,17 +2312,17 @@ WhiteSpaceVisibilityKeeper::MakeSureToKe
   EditorDOMPoint pointToSplit(aPointToSplit);
   if (pointPositionWithVisibleWhiteSpaces == PointPosition::StartOfFragment ||
       pointPositionWithVisibleWhiteSpaces == PointPosition::MiddleOfFragment) {
     EditorRawDOMPointInText atNextCharOfStart =
         textFragmentDataAtSplitPoint.GetInclusiveNextEditableCharPoint(
             pointToSplit);
     if (atNextCharOfStart.IsSet() && !atNextCharOfStart.IsEndOfContainer() &&
         atNextCharOfStart.IsCharASCIISpace() &&
-        !EditorUtils::IsContentPreformatted(
+        !EditorUtils::IsWhiteSpacePreformatted(
             *atNextCharOfStart.ContainerAsText())) {
       // pointToSplit will be referred bellow so that we need to keep
       // it a valid point.
       AutoEditorDOMPointChildInvalidator forgetChild(pointToSplit);
       if (atNextCharOfStart.IsStartOfContainer() ||
           atNextCharOfStart.IsPreviousCharASCIISpace()) {
         atNextCharOfStart =
             textFragmentDataAtSplitPoint
@@ -2351,17 +2351,17 @@ WhiteSpaceVisibilityKeeper::MakeSureToKe
   // NBSP.
   if (pointPositionWithVisibleWhiteSpaces == PointPosition::MiddleOfFragment ||
       pointPositionWithVisibleWhiteSpaces == PointPosition::EndOfFragment) {
     EditorRawDOMPointInText atPreviousCharOfStart =
         textFragmentDataAtSplitPoint.GetPreviousEditableCharPoint(pointToSplit);
     if (atPreviousCharOfStart.IsSet() &&
         !atPreviousCharOfStart.IsEndOfContainer() &&
         atPreviousCharOfStart.IsCharASCIISpace() &&
-        !EditorUtils::IsContentPreformatted(
+        !EditorUtils::IsWhiteSpacePreformatted(
             *atPreviousCharOfStart.ContainerAsText())) {
       if (atPreviousCharOfStart.IsStartOfContainer() ||
           atPreviousCharOfStart.IsPreviousCharASCIISpace()) {
         atPreviousCharOfStart =
             textFragmentDataAtSplitPoint
                 .GetFirstASCIIWhiteSpacePointCollapsedTo(atPreviousCharOfStart);
       }
       EditorRawDOMPointInText endOfCollapsibleASCIIWhiteSpaces =
@@ -2547,17 +2547,17 @@ WSRunScanner::TextFragmentData::GetPrevi
   }
   return EditorDOMPointInText();
 }
 
 // static
 template <typename EditorDOMPointType>
 EditorDOMPointType WSRunScanner::GetAfterLastVisiblePoint(
     Text& aTextNode, const Element* aAncestorLimiter) {
-  if (EditorUtils::IsContentPreformatted(aTextNode)) {
+  if (EditorUtils::IsWhiteSpacePreformatted(aTextNode)) {
     return EditorDOMPointType::AtEndOf(aTextNode);
   }
   TextFragmentData textFragmentData(
       EditorDOMPoint(&aTextNode,
                      aTextNode.Length() ? aTextNode.Length() - 1 : 0),
       aAncestorLimiter);
   if (NS_WARN_IF(!textFragmentData.IsInitialized())) {
     return EditorDOMPointType();  // TODO: Make here return error with Err.
@@ -2570,17 +2570,17 @@ EditorDOMPointType WSRunScanner::GetAfte
   }
   return EditorDOMPointType(invisibleWhiteSpaceRange.StartRef());
 }
 
 // static
 template <typename EditorDOMPointType>
 EditorDOMPointType WSRunScanner::GetFirstVisiblePoint(
     Text& aTextNode, const Element* aAncestorLimiter) {
-  if (EditorUtils::IsContentPreformatted(aTextNode)) {
+  if (EditorUtils::IsWhiteSpacePreformatted(aTextNode)) {
     return EditorDOMPointType(&aTextNode, 0);
   }
   TextFragmentData textFragmentData(EditorDOMPoint(&aTextNode, 0),
                                     aAncestorLimiter);
   if (NS_WARN_IF(!textFragmentData.IsInitialized())) {
     return EditorDOMPointType();  // TODO: Make here return error with Err.
   }
   const EditorDOMRange& invisibleWhiteSpaceRange =
@@ -2593,17 +2593,17 @@ EditorDOMPointType WSRunScanner::GetFirs
 }
 
 EditorDOMPointInText
 WSRunScanner::TextFragmentData::GetEndOfCollapsibleASCIIWhiteSpaces(
     const EditorDOMPointInText& aPointAtASCIIWhiteSpace) const {
   MOZ_ASSERT(aPointAtASCIIWhiteSpace.IsSet());
   MOZ_ASSERT(!aPointAtASCIIWhiteSpace.IsEndOfContainer());
   MOZ_ASSERT(aPointAtASCIIWhiteSpace.IsCharASCIISpace());
-  NS_ASSERTION(!EditorUtils::IsContentPreformatted(
+  NS_ASSERTION(!EditorUtils::IsWhiteSpacePreformatted(
                    *aPointAtASCIIWhiteSpace.ContainerAsText()),
                "aPointAtASCIIWhiteSpace should be in a formatted text node");
 
   // If it's not the last character in the text node, let's scan following
   // characters in it.
   if (!aPointAtASCIIWhiteSpace.IsAtLastContent()) {
     Maybe<uint32_t> nextVisibleCharOffset =
         HTMLEditUtils::GetNextCharOffsetExceptASCIIWhiteSpaces(
@@ -2633,17 +2633,17 @@ WSRunScanner::TextFragmentData::GetEndOf
     if (atStartOfNextTextNode.IsContainerEmpty()) {
       atEndOfPreviousTextNode = atStartOfNextTextNode;
       continue;
     }
 
     // If next node starts with non-white-space character or next node is
     // preformatted, return end of previous text node.
     if (!atStartOfNextTextNode.IsCharASCIISpace() ||
-        EditorUtils::IsContentPreformatted(
+        EditorUtils::IsWhiteSpacePreformatted(
             *atStartOfNextTextNode.ContainerAsText())) {
       return afterLastWhiteSpace;
     }
 
     // Otherwise, scan the text node.
     Maybe<uint32_t> nextVisibleCharOffset =
         HTMLEditUtils::GetNextCharOffsetExceptASCIIWhiteSpaces(
             atStartOfNextTextNode);
@@ -2659,17 +2659,17 @@ WSRunScanner::TextFragmentData::GetEndOf
 }
 
 EditorDOMPointInText
 WSRunScanner::TextFragmentData::GetFirstASCIIWhiteSpacePointCollapsedTo(
     const EditorDOMPointInText& aPointAtASCIIWhiteSpace) const {
   MOZ_ASSERT(aPointAtASCIIWhiteSpace.IsSet());
   MOZ_ASSERT(!aPointAtASCIIWhiteSpace.IsEndOfContainer());
   MOZ_ASSERT(aPointAtASCIIWhiteSpace.IsCharASCIISpace());
-  NS_ASSERTION(!EditorUtils::IsContentPreformatted(
+  NS_ASSERTION(!EditorUtils::IsWhiteSpacePreformatted(
                    *aPointAtASCIIWhiteSpace.ContainerAsText()),
                "aPointAtASCIIWhiteSpace should be in a formatted text node");
 
   // If there is some characters before it, scan it in the text node first.
   if (!aPointAtASCIIWhiteSpace.IsStartOfContainer()) {
     uint32_t firstASCIIWhiteSpaceOffset =
         HTMLEditUtils::GetFirstASCIIWhiteSpaceOffsetCollapsedWith(
             aPointAtASCIIWhiteSpace);
@@ -2698,17 +2698,17 @@ WSRunScanner::TextFragmentData::GetFirst
     if (atLastCharOfNextTextNode.IsContainerEmpty()) {
       atStartOfPreviousTextNode = atLastCharOfNextTextNode;
       continue;
     }
 
     // If next node ends with non-white-space character or next node is
     // preformatted, return start of previous text node.
     if (!atLastCharOfNextTextNode.IsCharASCIISpace() ||
-        EditorUtils::IsContentPreformatted(
+        EditorUtils::IsWhiteSpacePreformatted(
             *atLastCharOfNextTextNode.ContainerAsText())) {
       return atLastWhiteSpace;
     }
 
     // Otherwise, scan the text node.
     uint32_t firstASCIIWhiteSpaceOffset =
         HTMLEditUtils::GetFirstASCIIWhiteSpaceOffsetCollapsedWith(
             atLastCharOfNextTextNode);
@@ -2927,17 +2927,17 @@ nsresult WhiteSpaceVisibilityKeeper::Nor
     // element and following (maybe multiple) ASCII spaces, remove the NBSP,
     // but inserts a NBSP before the spaces.  This makes a line break
     // opportunity to wrap the line.
     // XXX This is different behavior from Blink.  Blink generates pairs of
     //     an NBSP and an ASCII white-space, but put NBSP at the end of the
     //     sequence.  We should follow the behavior for web-compat.
     if (maybeNBSPFollowingVisibleContent || !isPreviousCharASCIIWhiteSpace ||
         !followedByVisibleContentOrBRElement ||
-        EditorUtils::IsContentPreformatted(
+        EditorUtils::IsWhiteSpacePreformatted(
             *atPreviousCharOfPreviousCharOfEndOfVisibleWhiteSpaces
                  .GetContainerAsText())) {
       return NS_OK;
     }
 
     // Currently, we're at an NBSP following an ASCII space, and we need to
     // replace them with `"&nbsp; "` for avoiding collapsing white-spaces.
     MOZ_ASSERT(!atPreviousCharOfPreviousCharOfEndOfVisibleWhiteSpaces
@@ -3059,28 +3059,29 @@ EditorDOMPointInText WSRunScanner::TextF
   // proliferation.  This routine is called when we are about to make this
   // point in the ws abut an inserted break or text, so we don't have to worry
   // about what is after it.  What is after it now will end up after the
   // inserted object.
   EditorDOMPointInText atPreviousChar =
       GetPreviousEditableCharPoint(aPointToInsert);
   if (!atPreviousChar.IsSet() || atPreviousChar.IsEndOfContainer() ||
       !atPreviousChar.IsCharNBSP() ||
-      EditorUtils::IsContentPreformatted(*atPreviousChar.ContainerAsText())) {
+      EditorUtils::IsWhiteSpacePreformatted(
+          *atPreviousChar.ContainerAsText())) {
     return EditorDOMPointInText();
   }
 
   EditorDOMPointInText atPreviousCharOfPreviousChar =
       GetPreviousEditableCharPoint(atPreviousChar);
   if (atPreviousCharOfPreviousChar.IsSet()) {
     // If the previous char is in different text node and it's preformatted,
     // we shouldn't touch it.
     if (atPreviousChar.ContainerAsText() !=
             atPreviousCharOfPreviousChar.ContainerAsText() &&
-        EditorUtils::IsContentPreformatted(
+        EditorUtils::IsWhiteSpacePreformatted(
             *atPreviousCharOfPreviousChar.ContainerAsText())) {
       return EditorDOMPointInText();
     }
     // If the previous char of the NBSP at previous position of aPointToInsert
     // is an ASCII white-space, we don't need to replace it with same character.
     if (!atPreviousCharOfPreviousChar.IsEndOfContainer() &&
         atPreviousCharOfPreviousChar.IsCharASCIISpace()) {
       return EditorDOMPointInText();
@@ -3114,28 +3115,28 @@ EditorDOMPointInText WSRunScanner::TextF
   // Try to change an nbsp to a space, if possible, just to prevent nbsp
   // proliferation This routine is called when we are about to make this point
   // in the ws abut an inserted text, so we don't have to worry about what is
   // before it.  What is before it now will end up before the inserted text.
   EditorDOMPointInText atNextChar =
       GetInclusiveNextEditableCharPoint(aPointToInsert);
   if (!atNextChar.IsSet() || NS_WARN_IF(atNextChar.IsEndOfContainer()) ||
       !atNextChar.IsCharNBSP() ||
-      EditorUtils::IsContentPreformatted(*atNextChar.ContainerAsText())) {
+      EditorUtils::IsWhiteSpacePreformatted(*atNextChar.ContainerAsText())) {
     return EditorDOMPointInText();
   }
 
   EditorDOMPointInText atNextCharOfNextCharOfNBSP =
       GetInclusiveNextEditableCharPoint(atNextChar.NextPoint());
   if (atNextCharOfNextCharOfNBSP.IsSet()) {
     // If the next char is in different text node and it's preformatted,
     // we shouldn't touch it.
     if (atNextChar.ContainerAsText() !=
             atNextCharOfNextCharOfNBSP.ContainerAsText() &&
-        EditorUtils::IsContentPreformatted(
+        EditorUtils::IsWhiteSpacePreformatted(
             *atNextCharOfNextCharOfNBSP.ContainerAsText())) {
       return EditorDOMPointInText();
     }
     // If following character of an NBSP is an ASCII white-space, we don't
     // need to replace it with same character.
     if (!atNextCharOfNextCharOfNBSP.IsEndOfContainer() &&
         atNextCharOfNextCharOfNBSP.IsCharASCIISpace()) {
       return EditorDOMPointInText();
@@ -3349,17 +3350,17 @@ WSRunScanner::GetRangeInTextNodesToBacks
     // If caret is in middle of a surrogate pair, delete the surrogate pair
     // (blink-compat).
     else if (atPreviousChar.IsCharHighSurrogateFollowedByLowSurrogate()) {
       atNextChar = atNextChar.NextPoint();
     }
   }
 
   // If the text node is preformatted, just remove the previous character.
-  if (textFragmentDataAtCaret.IsPreformatted()) {
+  if (!textFragmentDataAtCaret.IsWhiteSpaceCollapsible()) {
     return EditorDOMRangeInTexts(atPreviousChar, atNextChar);
   }
 
   // If previous char is an ASCII white-spaces, delete all adjcent ASCII
   // whitespaces.
   EditorDOMRangeInTexts rangeToDelete;
   if (atPreviousChar.IsCharASCIISpace()) {
     EditorDOMPointInText startToDelete =
@@ -3444,17 +3445,17 @@ WSRunScanner::GetRangeInTextNodesToForwa
   // Extend delete range if previous char is a low surrogate following
   // a high surrogate.
   EditorDOMPointInText atNextChar = atCaret.NextPoint();
   if (atCaret.IsCharHighSurrogateFollowedByLowSurrogate()) {
     atNextChar = atNextChar.NextPoint();
   }
 
   // If the text node is preformatted, just remove the previous character.
-  if (textFragmentDataAtCaret.IsPreformatted()) {
+  if (!textFragmentDataAtCaret.IsWhiteSpaceCollapsible()) {
     return EditorDOMRangeInTexts(atCaret, atNextChar);
   }
 
   // If next char is an ASCII whitespaces, delete all adjcent ASCII
   // whitespaces.
   EditorDOMRangeInTexts rangeToDelete;
   if (atCaret.IsCharASCIISpace()) {
     EditorDOMPointInText startToDelete =
--- a/editor/libeditor/WSRunObject.h
+++ b/editor/libeditor/WSRunObject.h
@@ -958,17 +958,17 @@ class MOZ_STACK_CLASS WSRunScanner final
     bool FoundNoBreakingWhiteSpaces() const { return mNBSPData.FoundNBSP(); }
     const EditorDOMPointInText& FirstNBSPPointRef() const {
       return mNBSPData.FirstPointRef();
     }
     const EditorDOMPointInText& LastNBSPPointRef() const {
       return mNBSPData.LastPointRef();
     }
 
-    bool IsPreformatted() const { return mIsPreformatted; }
+    bool IsWhiteSpaceCollapsible() const { return mIsWhiteSpaceCollapsible; }
 
     template <typename PT, typename CT>
     EditorDOMPointInText GetInclusiveNextEditableCharPoint(
         const EditorDOMPointBase<PT, CT>& aPoint) const;
     template <typename PT, typename CT>
     EditorDOMPointInText GetPreviousEditableCharPoint(
         const EditorDOMPointBase<PT, CT>& aPoint) const;
 
@@ -1211,40 +1211,40 @@ class MOZ_STACK_CLASS WSRunScanner final
      * Note that when there is no visible content, it's not initialized.
      * Otherwise, even if there is no white-spaces, it's initialized and
      * the range is collapsed in such case.
      */
     const VisibleWhiteSpacesData& VisibleWhiteSpacesDataRef() const;
 
    private:
     /**
-     * IsPreformattedOrSurrondedByVisibleContent() returns true if the text is
-     * preformatted or the text fragment is surrounded by visible content.
-     * When this returns true, all of the text is visible.
+     * IsWhiteSpaceNotCollapsibleOrSurrondedByVisibleContent() returns true if
+     * the text is preformatted or the text fragment is surrounded by visible
+     * content. When this returns true, all of the text is visible.
      */
-    bool IsPreformattedOrSurrondedByVisibleContent() const {
-      return mIsPreformatted ||
+    bool IsWhiteSpaceNotCollapsibleOrSurrondedByVisibleContent() const {
+      return !mIsWhiteSpaceCollapsible ||
              ((StartsFromNormalText() || StartsFromSpecialContent()) &&
               (EndsByNormalText() || EndsBySpecialContent() ||
                EndsByBRElement()));
     }
 
     EditorDOMPoint mScanStartPoint;
     BoundaryData mStart;
     BoundaryData mEnd;
     NoBreakingSpaceData mNBSPData;
     RefPtr<const Element> mEditingHost;
     mutable Maybe<EditorDOMRange> mLeadingWhiteSpaceRange;
     mutable Maybe<EditorDOMRange> mTrailingWhiteSpaceRange;
     mutable Maybe<VisibleWhiteSpacesData> mVisibleWhiteSpacesData;
-    // XXX Currently we set mIsPreformatted to `WSRunScanner::mPRE` value
+    // XXX Currently `WSRunScanner` refers `IsWhiteSpaceCollapsible()` result
     //     even if some text nodes between mStart and mEnd are different styled
     //     nodes.  This caused some bugs actually, but we now keep traditional
     //     behavior for now.
-    bool mIsPreformatted;
+    bool mIsWhiteSpaceCollapsible;
   };
 
   const TextFragmentData& TextFragmentDataAtStartRef() const {
     return mTextFragmentDataAtStart;
   }
 
   // The node passed to our constructor.
   EditorDOMPoint mScanStartPoint;