Bug 1343978 Part 1: Change ClientRectsAndTexts usage of DOMStringList to Sequence<DOMString>. draft
authorBrad Werth <bwerth@mozilla.com>
Thu, 02 Mar 2017 13:13:12 -0800
changeset 492137 5f97fb4a706ac5f97c853c953bedf0070b53c3fa
parent 492009 d29f84406483c721a13cf9a52936ecced0c5c98a
child 547662 5931000268d570a1d8082888ded2525f3c804204
push id47542
push userbwerth@mozilla.com
push dateThu, 02 Mar 2017 21:16:03 +0000
bugs1343978
milestone54.0a1
Bug 1343978 Part 1: Change ClientRectsAndTexts usage of DOMStringList to Sequence<DOMString>. MozReview-Commit-ID: 8mKxdPTq4Ej
dom/base/nsRange.cpp
dom/base/nsRange.h
dom/webidl/Range.webidl
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -2894,17 +2894,17 @@ GetTextFrameForContent(nsIContent* aCont
     if (frame && frame->GetType() == nsGkAtoms::textFrame) {
       return static_cast<nsTextFrame*>(frame);
     }
   }
   return nullptr;
 }
 
 static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback,
-                                   mozilla::dom::DOMStringList* aTextList,
+                                   Sequence<nsString>* aTextList,
                                    nsIContent* aContent, int32_t aStartOffset,
                                    int32_t aEndOffset, bool aClampToEdge,
                                    bool aFlushLayout)
 {
   nsTextFrame* textFrame = GetTextFrameForContent(aContent, aFlushLayout);
   if (textFrame) {
     // If we'll need it later, collect the full content text now.
     nsAutoString textContent;
@@ -2942,26 +2942,26 @@ static nsresult GetPartialTextRect(nsLay
       aCallback->AddRect(r);
 
       // Finally capture the text, if requested.
       if (aTextList) {
         const nsAString& textSubstring =
           Substring(textContent,
                     textContentStart,
                     (textContentEnd - textContentStart));
-        aTextList->Add(textSubstring);
+        aTextList->AppendElement(textSubstring, fallible);
       }
     }
   }
   return NS_OK;
 }
 
 /* static */ void
 nsRange::CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
-                                   mozilla::dom::DOMStringList* aTextList,
+                                   Sequence<nsString>* aTextList,
                                    nsRange* aRange,
                                    nsINode* aStartParent, int32_t aStartOffset,
                                    nsINode* aEndParent, int32_t aEndOffset,
                                    bool aClampToEdge, bool aFlushLayout)
 {
   // Hold strong pointers across the flush
   nsCOMPtr<nsINode> startContainer = aStartParent;
   nsCOMPtr<nsINode> endContainer = aEndParent;
@@ -3092,21 +3092,20 @@ nsRange::GetClientRectsAndTexts(
   mozilla::dom::ClientRectsAndTexts& aResult,
   ErrorResult& aErr)
 {
   if (!mStartParent) {
     return;
   }
 
   aResult.mRectList = new DOMRectList(static_cast<nsIDOMRange*>(this));
-  aResult.mTextList = new DOMStringList();
 
   nsLayoutUtils::RectListBuilder builder(aResult.mRectList);
 
-  CollectClientRectsAndText(&builder, aResult.mTextList, this,
+  CollectClientRectsAndText(&builder, &aResult.mTextList, this,
     mStartParent, mStartOffset, mEndParent, mEndOffset, true, true);
 }
 
 NS_IMETHODIMP
 nsRange::GetUsedFontFaces(nsIDOMFontFaceList** aResult)
 {
   *aResult = nullptr;
 
--- a/dom/base/nsRange.h
+++ b/dom/base/nsRange.h
@@ -267,17 +267,17 @@ public:
   static bool IsNodeSelected(nsINode* aNode, uint32_t aStartOffset,
                              uint32_t aEndOffset);
 
   /**
    * This helper function gets rects and correlated text for the given range.
    * @param aTextList optional where nullptr = don't retrieve text
    */
   static void CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
-                                        mozilla::dom::DOMStringList* aTextList,
+                                        mozilla::dom::Sequence<nsString>* aTextList,
                                         nsRange* aRange,
                                         nsINode* aStartParent, int32_t aStartOffset,
                                         nsINode* aEndParent, int32_t aEndOffset,
                                         bool aClampToEdge, bool aFlushLayout);
 
   /**
    * Scan this range for -moz-user-select:none nodes and split it up into
    * multiple ranges to exclude those nodes.  The resulting ranges are put
--- a/dom/webidl/Range.webidl
+++ b/dom/webidl/Range.webidl
@@ -84,15 +84,15 @@ partial interface Range {
 // http://dvcs.w3.org/hg/csswg/raw-file/tip/cssom-view/Overview.html#extensions-to-the-range-interface
 partial interface Range {
   DOMRectList? getClientRects();
   DOMRect getBoundingClientRect();
 };
 
 dictionary ClientRectsAndTexts {
   required DOMRectList rectList;
-  required DOMStringList textList;
+  required sequence<DOMString> textList;
 };
 
 partial interface Range {
   [ChromeOnly, Throws]
   ClientRectsAndTexts getClientRectsAndTexts();
 };
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -3967,21 +3967,21 @@ struct BoxToRect : public nsLayoutUtils:
       r = nsLayoutUtils::TransformFrameRectToAncestor(outer, r, mRelativeTo);
     } else {
       r += outer->GetOffsetTo(mRelativeTo);
     }
     mCallback->AddRect(r);
   }
 };
 
-struct BoxToRectAndText : public BoxToRect {
-  mozilla::dom::DOMStringList* mTextList;
+struct MOZ_RAII BoxToRectAndText : public BoxToRect {
+  Sequence<nsString>* mTextList;
 
   BoxToRectAndText(nsIFrame* aRelativeTo, nsLayoutUtils::RectCallback* aCallback,
-                   mozilla::dom::DOMStringList* aTextList, uint32_t aFlags)
+                   Sequence<nsString>* aTextList, uint32_t aFlags)
     : BoxToRect(aRelativeTo, aCallback, aFlags), mTextList(aTextList) {}
 
   static void AccumulateText(nsIFrame* aFrame, nsAString& aResult) {
     MOZ_ASSERT(aFrame);
 
     // Get all the text in aFrame and child frames, while respecting
     // the content offsets in each of the nsTextFrames.
     if (aFrame->GetType() == nsGkAtoms::textFrame) {
@@ -4004,35 +4004,36 @@ struct BoxToRectAndText : public BoxToRe
          child = child->GetNextSibling()) {
       AccumulateText(child, aResult);
     }
   }
 
   virtual void AddBox(nsIFrame* aFrame) override {
     BoxToRect::AddBox(aFrame);
     if (mTextList) {
-      nsAutoString textForFrame;
-      AccumulateText(aFrame, textForFrame);
-      mTextList->Add(textForFrame);
+      nsString* textForFrame = mTextList->AppendElement(fallible);
+      if (textForFrame) {
+        AccumulateText(aFrame, *textForFrame);
+      }
     }
   }
 };
 
 void
 nsLayoutUtils::GetAllInFlowRects(nsIFrame* aFrame, nsIFrame* aRelativeTo,
                                  RectCallback* aCallback, uint32_t aFlags)
 {
   BoxToRect converter(aRelativeTo, aCallback, aFlags);
   GetAllInFlowBoxes(aFrame, &converter);
 }
 
 void
 nsLayoutUtils::GetAllInFlowRectsAndTexts(nsIFrame* aFrame, nsIFrame* aRelativeTo,
                                          RectCallback* aCallback,
-                                         mozilla::dom::DOMStringList* aTextList,
+                                         Sequence<nsString>* aTextList,
                                          uint32_t aFlags)
 {
   BoxToRectAndText converter(aRelativeTo, aCallback, aTextList, aFlags);
   GetAllInFlowBoxes(aFrame, &converter);
 }
 
 nsLayoutUtils::RectAccumulator::RectAccumulator() : mSeenFirstRect(false) {}
 
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -1208,17 +1208,17 @@ public:
    * or RECTS_USE_MARGIN_BOX, the corresponding type of box is used.
    * Otherwise (by default), the border box is used.
    */
   static void GetAllInFlowRects(nsIFrame* aFrame, nsIFrame* aRelativeTo,
                                 RectCallback* aCallback, uint32_t aFlags = 0);
 
   static void GetAllInFlowRectsAndTexts(nsIFrame* aFrame, nsIFrame* aRelativeTo,
                                         RectCallback* aCallback,
-                                        mozilla::dom::DOMStringList* aTextList,
+                                        mozilla::dom::Sequence<nsString>* aTextList,
                                         uint32_t aFlags = 0);
 
   /**
    * Computes the union of all rects returned by GetAllInFlowRects. If
    * the union is empty, returns the first rect.
    * If aFlags includes RECTS_ACCOUNT_FOR_TRANSFORMS, then when converting
    * the boxes into aRelativeTo coordinates, transforms (including CSS
    * and SVG transforms) are taken into account.