Bug 1383367: Part 1 - Add JS helper to determine if a layout flush is required. r=mconley
This lets us decide whether to defer operations if they might trigger a
reflow.
MozReview-Commit-ID: 4M13HKAuZ7M
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1846,16 +1846,49 @@ nsDOMWindowUtils::GetBoundsWithoutFlushi
rect->SetLayoutRect(r);
}
rect.forget(aResult);
return NS_OK;
}
NS_IMETHODIMP
+nsDOMWindowUtils::NeedsFlush(int32_t aFlushType, bool* aResult)
+{
+ MOZ_ASSERT(aResult);
+
+ nsCOMPtr<nsIDocument> doc = GetDocument();
+ NS_ENSURE_STATE(doc);
+
+ nsIPresShell* presShell = doc->GetShell();
+ NS_ENSURE_STATE(presShell);
+
+ FlushType flushType;
+ switch (aFlushType) {
+ case FLUSH_STYLE:
+ flushType = FlushType::Style;
+ break;
+
+ case FLUSH_LAYOUT:
+ flushType = FlushType::Layout;
+ break;
+
+ case FLUSH_DISPLAY:
+ flushType = FlushType::Display;
+ break;
+
+ default:
+ return NS_ERROR_INVALID_ARG;
+ }
+
+ *aResult = presShell->NeedFlush(flushType);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
nsDOMWindowUtils::GetRootBounds(nsIDOMClientRect** aResult)
{
nsIDocument* doc = GetDocument();
NS_ENSURE_STATE(doc);
nsRect bounds(0, 0, 0, 0);
nsIPresShell* presShell = doc->GetShell();
if (presShell) {
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -989,16 +989,25 @@ 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.
*/
nsIDOMClientRect getBoundsWithoutFlushing(in nsIDOMElement aElement);
+ 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.
+ */
+ bool needsFlush(in long aFlushtype);
+
/**
* Returns the bounds of the window's currently loaded document. This will
* generally be (0, 0, pageWidth, pageHeight) but in some cases (e.g. RTL
* documents) may have a negative left value.
*/
nsIDOMClientRect getRootBounds();
/**