Bug 590294, part 0: Add an nsDOMWindowUtils::GetPresShell() helper. r=smaug

This commit is contained in:
Chris Jones 2010-09-03 15:10:45 -05:00
parent d2ad41fd06
commit 22a9c5e5dc
2 changed files with 27 additions and 18 deletions

View File

@ -111,6 +111,21 @@ nsDOMWindowUtils::~nsDOMWindowUtils()
{
}
nsIPresShell*
nsDOMWindowUtils::GetPresShell()
{
if (!mWindow)
return nsnull;
nsIDocShell *docShell = mWindow->GetDocShell();
if (!docShell)
return nsnull;
nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell(getter_AddRefs(presShell));
return presShell;
}
nsPresContext*
nsDOMWindowUtils::GetPresContext()
{
@ -189,35 +204,27 @@ nsDOMWindowUtils::GetDocumentMetadata(const nsAString& aName,
NS_IMETHODIMP
nsDOMWindowUtils::Redraw(PRUint32 aCount, PRUint32 *aDurationOut)
{
nsresult rv;
if (aCount == 0)
aCount = 1;
nsCOMPtr<nsIDocShell> docShell = mWindow->GetDocShell();
if (docShell) {
nsCOMPtr<nsIPresShell> presShell;
if (nsIPresShell* presShell = GetPresShell()) {
nsIFrame *rootFrame = presShell->GetRootFrame();
rv = docShell->GetPresShell(getter_AddRefs(presShell));
if (NS_SUCCEEDED(rv) && presShell) {
nsIFrame *rootFrame = presShell->GetRootFrame();
if (rootFrame) {
nsRect r(nsPoint(0, 0), rootFrame->GetSize());
if (rootFrame) {
nsRect r(nsPoint(0, 0), rootFrame->GetSize());
PRIntervalTime iStart = PR_IntervalNow();
PRIntervalTime iStart = PR_IntervalNow();
for (PRUint32 i = 0; i < aCount; i++)
rootFrame->InvalidateWithFlags(r, nsIFrame::INVALIDATE_IMMEDIATE);
for (PRUint32 i = 0; i < aCount; i++)
rootFrame->InvalidateWithFlags(r, nsIFrame::INVALIDATE_IMMEDIATE);
#if defined(MOZ_X11) && defined(MOZ_WIDGET_GTK2)
XSync(GDK_DISPLAY(), False);
XSync(GDK_DISPLAY(), False);
#endif
*aDurationOut = PR_IntervalToMilliseconds(PR_IntervalNow() - iStart);
*aDurationOut = PR_IntervalToMilliseconds(PR_IntervalNow() - iStart);
return NS_OK;
}
return NS_OK;
}
}
return NS_ERROR_FAILURE;

View File

@ -41,6 +41,7 @@
#include "nsIDOMWindowUtils.h"
class nsGlobalWindow;
class nsIPresShell;
class nsDOMWindowUtils : public nsIDOMWindowUtils,
public nsSupportsWeakReference
@ -61,6 +62,7 @@ protected:
nsIWidget* GetWidget(nsPoint* aOffset = nsnull);
nsIWidget* GetWidgetForElement(nsIDOMElement* aElement);
nsIPresShell* GetPresShell();
nsPresContext* GetPresContext();
NS_IMETHOD SendMouseEventCommon(const nsAString& aType,