Bug 1450526 - Part 2: Add a function which returns the bounds without flushing for textnode to nsDOMWindowUtils. r?
MozReview-Commit-ID: K2U7Ef7ub96
--- 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.
*/