Bug 1340138. r=smaug
authorMats Palmgren <mats@mozilla.com>
Tue, 28 Feb 2017 16:41:08 +0100
changeset 374260 b76ee87a9589c1ad6d9b345cc67cca1f2181722c
parent 374259 02fb91584ef6c701b002a1ab5a132fe2a0c047be
child 374261 d19ad1c1c214c7f2f8b2fb292e7b4c8d4328a5f8
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1340138
milestone54.0a1
Bug 1340138. r=smaug MozReview-Commit-ID: HoTn7hfCiSC
toolkit/components/find/nsFind.cpp
toolkit/components/find/nsFind.h
toolkit/components/find/nsWebBrowserFind.cpp
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -112,16 +112,23 @@ public:
   virtual nsINode* GetCurrentNode() override;
   virtual bool IsDone() override;
   virtual nsresult PositionAt(nsINode* aCurNode) override;
 
 protected:
   virtual ~nsFindContentIterator() {}
 
 private:
+  static already_AddRefed<nsIDOMRange> CreateRange(nsINode* aNode)
+  {
+    RefPtr<nsRange> range = new nsRange(aNode);
+    range->SetMaySpanAnonymousSubtrees(true);
+    return range.forget();
+  }
+
   nsCOMPtr<nsIContentIterator> mOuterIterator;
   nsCOMPtr<nsIContentIterator> mInnerIterator;
   // Can't use a range here, since we want to represent part of the flattened
   // tree, including native anonymous content.
   nsCOMPtr<nsIDOMNode> mStartNode;
   int32_t mStartOffset;
   nsCOMPtr<nsIDOMNode> mEndNode;
   int32_t mEndOffset;
@@ -276,17 +283,17 @@ nsFindContentIterator::Reset()
   }
 
   // Note: OK to just set up the outer iterator here; if our range has a native
   // anonymous endpoint we'll end up setting up an inner iterator, and reset the
   // outer one in the process.
   nsCOMPtr<nsINode> node = do_QueryInterface(mStartNode);
   NS_ENSURE_TRUE_VOID(node);
 
-  nsCOMPtr<nsIDOMRange> range = nsFind::CreateRange(node);
+  nsCOMPtr<nsIDOMRange> range = CreateRange(node);
   range->SetStart(mStartNode, mStartOffset);
   range->SetEnd(mEndNode, mEndOffset);
   mOuterIterator->Init(range);
 
   if (!mFindBackward) {
     if (mStartOuterContent != startContent) {
       // the start node was an anonymous text node
       SetupInnerIterator(mStartOuterContent);
@@ -377,18 +384,18 @@ nsFindContentIterator::SetupInnerIterato
   editor->GetFlags(&editorFlags);
   if (editorFlags & nsIPlaintextEditor::eEditorDisabledMask) {
     return;
   }
 
   nsCOMPtr<nsIDOMElement> rootElement;
   editor->GetRootElement(getter_AddRefs(rootElement));
 
-  nsCOMPtr<nsIDOMRange> innerRange = nsFind::CreateRange(aContent);
-  nsCOMPtr<nsIDOMRange> outerRange = nsFind::CreateRange(aContent);
+  nsCOMPtr<nsIDOMRange> innerRange = CreateRange(aContent);
+  nsCOMPtr<nsIDOMRange> outerRange = CreateRange(aContent);
   if (!innerRange || !outerRange) {
     return;
   }
 
   // now create the inner-iterator
   mInnerIterator = do_CreateInstance(kCPreContentIteratorCID);
 
   if (mInnerIterator) {
@@ -1265,17 +1272,17 @@ nsFind::Find(const char16_t* aPatText, n
 
           // If a word break isn't there when it needs to be, reset search.
           if (!mWordBreaker->BreakInBetween(&c, 1, &nextChar, 1)) {
             matchAnchorNode = nullptr;
             continue;
           }
         }
 
-        nsCOMPtr<nsIDOMRange> range = CreateRange(tc);
+        nsCOMPtr<nsIDOMRange> range = new nsRange(tc);
         if (range) {
           int32_t matchStartOffset, matchEndOffset;
           // convert char index to range point:
           int32_t mao = matchAnchorOffset + (mFindBackward ? 1 : 0);
           if (mFindBackward) {
             startParent = do_QueryInterface(tc);
             endParent = matchAnchorNode;
             matchStartOffset = findex;
@@ -1369,17 +1376,8 @@ nsFind::Find(const char16_t* aPatText, n
 
 #endif
   }
 
   // Out of nodes, and didn't match.
   ResetAll();
   return NS_OK;
 }
-
-/* static */
-already_AddRefed<nsIDOMRange>
-nsFind::CreateRange(nsINode* aNode)
-{
-  RefPtr<nsRange> range = new nsRange(aNode);
-  range->SetMaySpanAnonymousSubtrees(true);
-  return range.forget();
-}
--- a/toolkit/components/find/nsFind.h
+++ b/toolkit/components/find/nsFind.h
@@ -29,18 +29,16 @@ class nsFind : public nsIFind
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIFIND
   NS_DECL_CYCLE_COLLECTION_CLASS(nsFind)
 
   nsFind();
 
-  static already_AddRefed<nsIDOMRange> CreateRange(nsINode* aNode);
-
 protected:
   virtual ~nsFind();
 
   // Parameters set from the interface:
   //nsCOMPtr<nsIDOMRange> mRange;   // search only in this range
   bool mFindBackward;
   bool mCaseSensitive;
 
--- a/toolkit/components/find/nsWebBrowserFind.cpp
+++ b/toolkit/components/find/nsWebBrowserFind.cpp
@@ -723,21 +723,21 @@ nsWebBrowserFind::SearchInFrame(nsPIDOMW
 
   // Now make sure the content (for actual finding) and frame (for
   // selection) models are up to date.
   theDoc->FlushPendingNotifications(FlushType::Frames);
 
   nsCOMPtr<nsISelection> sel = GetFrameSelection(aWindow);
   NS_ENSURE_ARG_POINTER(sel);
 
-  nsCOMPtr<nsIDOMRange> searchRange = nsFind::CreateRange(theDoc);
+  nsCOMPtr<nsIDOMRange> searchRange = new nsRange(theDoc);
   NS_ENSURE_ARG_POINTER(searchRange);
-  nsCOMPtr<nsIDOMRange> startPt = nsFind::CreateRange(theDoc);
+  nsCOMPtr<nsIDOMRange> startPt = new nsRange(theDoc);
   NS_ENSURE_ARG_POINTER(startPt);
-  nsCOMPtr<nsIDOMRange> endPt = nsFind::CreateRange(theDoc);
+  nsCOMPtr<nsIDOMRange> endPt = new nsRange(theDoc);
   NS_ENSURE_ARG_POINTER(endPt);
 
   nsCOMPtr<nsIDOMRange> foundRange;
 
   nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(theDoc);
   MOZ_ASSERT(domDoc);
 
   // If !aWrapping, search from selection to end