Bug 1224101 part.2 Backout bug 1215798 from Aurora r=smaug a=ritu
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 17 Nov 2015 10:24:46 -0800
changeset 303750 ce2dd840a84ebb2176c65c2b537073c6d0c4f9c4
parent 303749 b5ca0fa6c80c45fac4bdff9ef218cad3766f8ce0
child 303751 24e48f5abcf2f7ff17ec65c622ebedf5d5b463d7
push idunknown
push userunknown
push dateunknown
reviewerssmaug, ritu
bugs1224101, 1215798
milestone44.0a2
Bug 1224101 part.2 Backout bug 1215798 from Aurora r=smaug a=ritu
dom/base/nsContentIterator.cpp
--- a/dom/base/nsContentIterator.cpp
+++ b/dom/base/nsContentIterator.cpp
@@ -43,31 +43,21 @@ static bool
 NodeIsInTraversalRange(nsINode* aNode, bool aIsPreMode,
                        nsINode* aStartNode, int32_t aStartOffset,
                        nsINode* aEndNode, int32_t aEndOffset)
 {
   if (!aStartNode || !aEndNode || !aNode) {
     return false;
   }
 
-  // If a leaf node contains an end point of the traversal range, it is
+  // If a chardata node contains an end point of the traversal range, it is
   // always in the traversal range.
-  if (aNode == aStartNode || aNode == aEndNode) {
-    if (aNode->IsNodeOfType(nsINode::eDATA_NODE)) {
-      return true; // text node or something
-    }
-    if (!aNode->HasChildren()) {
-      MOZ_ASSERT(aNode != aStartNode || !aStartOffset,
-        "aStartNode doesn't have children and not a data node, "
-        "aStartOffset should be 0");
-      MOZ_ASSERT(aNode != aEndNode || !aEndOffset,
-        "aStartNode doesn't have children and not a data node, "
-        "aStartOffset should be 0");
-      return true;
-    }
+  if (aNode->IsNodeOfType(nsINode::eDATA_NODE) &&
+      (aNode == aStartNode || aNode == aEndNode)) {
+    return true;
   }
 
   nsINode* parent = aNode->GetParentNode();
   if (!parent) {
     return false;
   }
 
   int32_t indx = parent->IndexOf(aNode);
@@ -346,24 +336,22 @@ nsContentIterator::Init(nsIDOMRange* aDO
     // XXXbz no children might also just mean no children.  So I'm not
     // sure what that comment above is talking about.
 
     if (mPre) {
       // XXX: In the future, if start offset is after the last
       //      character in the cdata node, should we set mFirst to
       //      the next sibling?
 
-      // If the node has no child, the child may be <br> or something.
-      // So, we shouldn't skip the empty node if the start offset is 0.
-      // In other words, if the offset is 1, the node should be ignored.
-      if (!startIsData && startIndx) {
+      if (!startIsData) {
         mFirst = GetNextSibling(startNode);
 
         // Does mFirst node really intersect the range?  The range could be
         // 'degenerate', i.e., not collapsed but still contain no content.
+
         if (mFirst && !NodeIsInTraversalRange(mFirst, mPre, startNode,
                                               startIndx, endNode, endIndx)) {
           mFirst = nullptr;
         }
       } else {
         mFirst = startNode->AsContent();
       }
     } else {