Bug 1129078 - part 3, Add a mIsGenerated bit to ranges that ExcludeNonSelectableNodes created due to user-select:none. Also, return the index to the range we want to be the new mAnchorFocusRange, based on the Selection direction. r=smaug
☠☠ backed out by 7afbf9ebc89b ☠ ☠
authorMats Palmgren <mats@mozilla.com>
Fri, 20 Feb 2015 17:34:21 +0000
changeset 258778 c199ff86c77f2b0562fb525ce32d78566008a6d1
parent 258777 38b1b039f14d690f0caece009e8a66de416d1505
child 258779 ce5cb876af9ab955878f61367262c33cc9971ef4
push id721
push userjlund@mozilla.com
push dateTue, 21 Apr 2015 23:03:33 +0000
treeherdermozilla-release@d27c9211ebb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1129078
milestone38.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 1129078 - part 3, Add a mIsGenerated bit to ranges that ExcludeNonSelectableNodes created due to user-select:none. Also, return the index to the range we want to be the new mAnchorFocusRange, based on the Selection direction. r=smaug
dom/base/nsRange.h
layout/generic/nsSelection.cpp
--- a/dom/base/nsRange.h
+++ b/dom/base/nsRange.h
@@ -44,16 +44,17 @@ public:
   explicit nsRange(nsINode* aNode)
     : mRoot(nullptr)
     , mStartOffset(0)
     , mEndOffset(0)
     , mIsPositioned(false)
     , mIsDetached(false)
     , mMaySpanAnonymousSubtrees(false)
     , mInSelection(false)
+    , mIsGenerated(false)
     , mStartOffsetWasIncremented(false)
     , mEndOffsetWasIncremented(false)
     , mEnableGravitationOnElementRemoval(true)
 #ifdef DEBUG
     , mAssertNextInsertOrAppendIndex(-1)
     , mAssertNextInsertOrAppendNode(nullptr)
 #endif
   {
@@ -148,16 +149,37 @@ public:
     NS_ASSERTION(commonAncestor, "unexpected disconnected nodes");
     if (mInSelection) {
       RegisterCommonAncestor(commonAncestor);
     } else {
       UnregisterCommonAncestor(commonAncestor);
     }
   }
 
+  /**
+   * Return true if this range was generated.
+   * @see SetIsGenerated
+   */
+  bool IsGenerated() const
+  {
+    return mIsGenerated;
+  }
+
+  /**
+   * Mark this range as being generated or not.
+   * Currently it is used for marking ranges that are created when splitting up
+   * a range to exclude a -moz-user-select:none region.
+   * @see Selection::AddItem
+   * @see ExcludeNonSelectableNodes
+   */
+  void SetIsGenerated(bool aIsGenerated)
+  {
+    mIsGenerated = aIsGenerated;
+  }
+
   nsINode* GetCommonAncestor() const;
   void Reset();
   nsresult SetStart(nsINode* aParent, int32_t aOffset);
   nsresult SetEnd(nsINode* aParent, int32_t aOffset);
   already_AddRefed<nsRange> CloneRange() const;
 
   nsresult Set(nsINode* aStartParent, int32_t aStartOffset,
                nsINode* aEndParent, int32_t aEndOffset)
@@ -328,16 +350,17 @@ protected:
   nsCOMPtr<nsINode> mEndParent;
   int32_t mStartOffset;
   int32_t mEndOffset;
 
   bool mIsPositioned;
   bool mIsDetached;
   bool mMaySpanAnonymousSubtrees;
   bool mInSelection;
+  bool mIsGenerated;
   bool mStartOffsetWasIncremented;
   bool mEndOffsetWasIncremented;
   bool mEnableGravitationOnElementRemoval;
 #ifdef DEBUG
   int32_t  mAssertNextInsertOrAppendIndex;
   nsINode* mAssertNextInsertOrAppendNode;
 #endif
 };
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -3507,19 +3507,29 @@ Selection::AddItem(nsRange* aItem, int32
       nsINode* node = aItem->GetStartContainer(err);
       if (node && node->IsContent() && node->AsContent()->GetEditingHost()) {
         // A contenteditable node with user-select:none, for example.
         // Allow it to have a collapsed selection (for the caret).
         aItem->Collapse(GetDirection() == eDirPrevious);
         rangesToAdd.AppendElement(aItem);
       }
     }
+    *aOutIndex = -1;
+    size_t newAnchorFocusIndex =
+      GetDirection() == eDirPrevious ? 0 : rangesToAdd.Length() - 1;
     for (size_t i = 0; i < rangesToAdd.Length(); ++i) {
-      nsresult rv = AddItemInternal(rangesToAdd[i], aOutIndex);
+      int32_t index;
+      nsresult rv = AddItemInternal(rangesToAdd[i], &index);
       NS_ENSURE_SUCCESS(rv, rv);
+      if (i == newAnchorFocusIndex) {
+        *aOutIndex = index;
+        rangesToAdd[i]->SetIsGenerated(false);
+      } else {
+        rangesToAdd[i]->SetIsGenerated(true);
+      }
     }
     return NS_OK;
   }
   return AddItemInternal(aItem, aOutIndex);
 }
 
 nsresult
 Selection::AddItemInternal(nsRange* aItem, int32_t* aOutIndex)