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

--HG--
extra : source : 6679237a46723432264361b5542454bb91d4831e
extra : intermediate-source : 46d1fa12a0829046f2bee4ffd10d7af38616bba9
This commit is contained in:
Kris Maglione 2017-07-24 20:07:39 -07:00
parent 427fc1d03c
commit f55d5b792a
2 changed files with 42 additions and 0 deletions

View File

@ -1825,6 +1825,39 @@ nsDOMWindowUtils::GetBoundsWithoutFlushing(nsIDOMElement *aElement,
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)
{

View File

@ -995,6 +995,15 @@ interface nsIDOMWindowUtils : nsISupports {
*/
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