Bug 1450526 - Part 2: Add a function which returns the bounds without flushing for textnode to nsDOMWindowUtils. r? draft
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Mon, 09 Apr 2018 10:47:07 +0900
changeset 779099 855a40e4f384a177859f9e156b7b3721667434ed
parent 779092 ec5eb585e485627c7092cf197d7c973978877623
child 779100 7c96ef731929e3c3b01a4f96137b48e8b2b7c7f4
push id105656
push userbmo:dakatsuka@mozilla.com
push dateMon, 09 Apr 2018 04:15:49 +0000
bugs1450526
milestone61.0a1
Bug 1450526 - Part 2: Add a function which returns the bounds without flushing for textnode to nsDOMWindowUtils. r? MozReview-Commit-ID: K2U7Ef7ub96
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1663,25 +1663,26 @@ nsDOMWindowUtils::GetScrollbarSize(bool 
 
   nsMargin sizes = scrollFrame->GetActualScrollbarSizes();
   *aWidth = nsPresContext::AppUnitsToIntCSSPixels(sizes.LeftRight());
   *aHeight = nsPresContext::AppUnitsToIntCSSPixels(sizes.TopBottom());
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsDOMWindowUtils::GetBoundsWithoutFlushing(nsIDOMElement *aElement,
-                                           nsISupports** aResult)
+static nsresult
+GetBoundsWithoutFlushingInternal(nsIDOMNode *aNode,
+                                 nsWeakPtr aWindow,
+                                 nsISupports** aResult)
 {
-  nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
+  nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(aWindow);
   NS_ENSURE_STATE(window);
 
   nsresult rv;
-  nsCOMPtr<nsIContent> content = do_QueryInterface(aElement, &rv);
+  nsCOMPtr<nsIContent> content = do_QueryInterface(aNode, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   RefPtr<DOMRect> rect = new DOMRect(window);
   nsIFrame* frame = content->GetPrimaryFrame();
 
   if (frame) {
     nsRect r = nsLayoutUtils::GetAllInFlowRectsUnion(frame,
                nsLayoutUtils::GetContainingBlockForClientRect(frame),
@@ -1689,16 +1690,36 @@ nsDOMWindowUtils::GetBoundsWithoutFlushi
     rect->SetLayoutRect(r);
   }
 
   rect.forget(aResult);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDOMWindowUtils::GetBoundsWithoutFlushing(nsIDOMElement *aElement,
+                                           nsISupports** aResult)
+{
+  return GetBoundsWithoutFlushingInternal(aElement, mWindow, aResult);
+}
+
+NS_IMETHODIMP
+nsDOMWindowUtils::GetTextNodeBoundsWithoutFlushing(nsIDOMNode *aTextNode,
+                                                   nsISupports** aResult)
+{
+  nsCOMPtr<nsINode> node = do_QueryInterface(aTextNode);
+
+  if (node->NodeType() != nsINode::TEXT_NODE) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  return GetBoundsWithoutFlushingInternal(aTextNode, mWindow, aResult);
+}
+
+NS_IMETHODIMP
 nsDOMWindowUtils::NeedsFlush(int32_t aFlushType, bool* aResult)
 {
   MOZ_ASSERT(aResult);
 
   nsCOMPtr<nsIDocument> doc = GetDocument();
   NS_ENSURE_STATE(doc);
 
   nsIPresShell* presShell = doc->GetShell();
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -841,16 +841,21 @@ interface nsIDOMWindowUtils : nsISupport
   void getScrollbarSize(in boolean aFlushLayout, out long aWidth, out long aHeight);
 
   /**
    * Returns the given element's bounds without flushing pending layout changes.
    * The returned object is a DOMRect (bug 1444991 may remove this walkaround).
    */
   nsISupports getBoundsWithoutFlushing(in nsIDOMElement aElement);
 
+  /**
+   * Returns the given text node's bounds without flushing pending layout changes.
+   */
+  nsISupports getTextNodeBoundsWithoutFlushing(in nsIDOMNode aTextNode);
+
   const long FLUSH_NONE = -1;
   const long FLUSH_STYLE = 0;
   const long FLUSH_LAYOUT = 1;
   const long FLUSH_DISPLAY = 2;
 
   /**
    * Returns true if a flush of the given type is needed.
    */