From dc72b9cc31ebd8f55a70bafc1e3e22cceb386f9a Mon Sep 17 00:00:00 2001 From: Nickolay Ponomarev Date: Mon, 19 Jan 2009 22:29:48 +1300 Subject: [PATCH] Bug 472189. Delay attribute changes for progressmeter updates via script-runnables. r=enn,sr=roc --- layout/base/nsLayoutUtils.cpp | 19 +++++++++++++++++++ layout/base/nsLayoutUtils.h | 15 +++++++++++++++ layout/xul/base/src/crashtests/472189.xul | 13 +++++++++++++ .../xul/base/src/crashtests/crashtests.list | 1 + layout/xul/base/src/nsProgressMeterFrame.cpp | 14 +++++++------- 5 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 layout/xul/base/src/crashtests/472189.xul diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 153f59c6891..dc1b30b196d 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -3086,3 +3086,22 @@ nsUnsetAttrRunnable::Run() { return mContent->UnsetAttr(kNameSpaceID_None, mAttrName, PR_TRUE); } + +nsReflowFrameRunnable::nsReflowFrameRunnable(nsIFrame* aFrame, + nsIPresShell::IntrinsicDirty aIntrinsicDirty, + nsFrameState aBitToAdd) + : mWeakFrame(aFrame), + mIntrinsicDirty(aIntrinsicDirty), + mBitToAdd(aBitToAdd) +{ +} + +NS_IMETHODIMP +nsReflowFrameRunnable::Run() +{ + if (mWeakFrame.IsAlive()) { + mWeakFrame->PresContext()->PresShell()-> + FrameNeedsReflow(mWeakFrame, mIntrinsicDirty, mBitToAdd); + } + return NS_OK; +} diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 7a7276c444f..287b58888aa 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -59,6 +59,7 @@ class nsIFontMetrics; #include "nsIView.h" #include "nsIFrame.h" #include "nsThreadUtils.h" +#include "nsIPresShell.h" class nsBlockFrame; @@ -982,4 +983,18 @@ public: nsCOMPtr mAttrName; }; +class nsReflowFrameRunnable : public nsRunnable +{ +public: + nsReflowFrameRunnable(nsIFrame* aFrame, + nsIPresShell::IntrinsicDirty aIntrinsicDirty, + nsFrameState aBitToAdd); + + NS_DECL_NSIRUNNABLE + + nsWeakFrame mWeakFrame; + nsIPresShell::IntrinsicDirty mIntrinsicDirty; + nsFrameState mBitToAdd; +}; + #endif // nsLayoutUtils_h__ diff --git a/layout/xul/base/src/crashtests/472189.xul b/layout/xul/base/src/crashtests/472189.xul new file mode 100644 index 00000000000..e276d8fc706 --- /dev/null +++ b/layout/xul/base/src/crashtests/472189.xul @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/layout/xul/base/src/crashtests/crashtests.list b/layout/xul/base/src/crashtests/crashtests.list index b737b8e7468..0b13807c08f 100644 --- a/layout/xul/base/src/crashtests/crashtests.list +++ b/layout/xul/base/src/crashtests/crashtests.list @@ -30,3 +30,4 @@ load 433296-1.xul load 434458-1.xul load 467481-1.xul load 470063-1.html +load 472189.xul \ No newline at end of file diff --git a/layout/xul/base/src/nsProgressMeterFrame.cpp b/layout/xul/base/src/nsProgressMeterFrame.cpp index 8f6bc00d52c..10deb6b2a7b 100644 --- a/layout/xul/base/src/nsProgressMeterFrame.cpp +++ b/layout/xul/base/src/nsProgressMeterFrame.cpp @@ -51,6 +51,7 @@ #include "nsCOMPtr.h" #include "nsBoxLayoutState.h" #include "nsIReflowCallback.h" +#include "nsContentUtils.h" // // NS_NewToolbarFrame // @@ -154,14 +155,13 @@ nsProgressMeterFrame::AttributeChanged(PRInt32 aNameSpaceID, nsAutoString leftFlex, rightFlex; leftFlex.AppendInt(flex); rightFlex.AppendInt(remainder); - nsWeakFrame weakFrame(this); - barChild->GetContent()->SetAttr(kNameSpaceID_None, nsGkAtoms::flex, leftFlex, PR_TRUE); - remainderContent->SetAttr(kNameSpaceID_None, nsGkAtoms::flex, rightFlex, PR_TRUE); - if (weakFrame.IsAlive()) { - PresContext()->PresShell()-> - FrameNeedsReflow(this, nsIPresShell::eTreeChange, NS_FRAME_IS_DIRTY); - } + nsContentUtils::AddScriptRunner(new nsSetAttrRunnable( + barChild->GetContent(), nsGkAtoms::flex, leftFlex)); + nsContentUtils::AddScriptRunner(new nsSetAttrRunnable( + remainderContent, nsGkAtoms::flex, rightFlex)); + nsContentUtils::AddScriptRunner(new nsReflowFrameRunnable( + this, nsIPresShell::eTreeChange, NS_FRAME_IS_DIRTY)); } return NS_OK; }