Call WillPaint() on all descendant view observers. b=517772 r=bzbarsky r=roc

This commit is contained in:
Mats Palmgren 2009-10-16 12:55:19 +02:00
parent 2d83c2550e
commit 3b7aeeee5a
2 changed files with 33 additions and 20 deletions

View File

@ -943,10 +943,8 @@ NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent,
if (!didResize) {
//NS_ASSERTION(IsViewVisible(view), "painting an invisible view");
// Just notify our own view observer that we're about to paint
// XXXbz do we need to notify other view observers for viewmanagers
// in our tree?
// Make sure to not send WillPaint notifications while scrolling
// Notify view observers that we're about to paint.
// Make sure to not send WillPaint notifications while scrolling.
nsRefPtr<nsViewManager> rootVM = RootViewManager();
nsCOMPtr<nsIWidget> widget;
@ -971,7 +969,7 @@ NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent,
// We should really sort out the rules on our synch painting
// api....
UpdateViewBatch batch(this);
observer->WillPaint();
rootVM->CallWillPaintOnObservers();
batch.EndUpdateViewBatch(NS_VMREFRESH_NO_SYNC);
// Get the view pointer again since the code above might have
@ -1988,22 +1986,9 @@ nsViewManager::FlushPendingInvalidates()
PRBool refreshEnabled = mRefreshEnabled;
mRefreshEnabled = PR_FALSE;
++mUpdateBatchCnt;
PRInt32 index;
for (index = 0; index < mVMCount; index++) {
nsViewManager* vm = (nsViewManager*)gViewManagers->ElementAt(index);
if (vm->RootViewManager() == this) {
// One of our kids
nsIViewObserver* observer = vm->GetViewObserver();
if (observer) {
observer->WillPaint();
NS_ASSERTION(mUpdateBatchCnt == 1,
"Observer did not end view batch?");
}
}
}
CallWillPaintOnObservers();
--mUpdateBatchCnt;
// Someone could have called EnableRefresh on us from inside WillPaint().
// Only reset the old mRefreshEnabled value if the current value is false.
if (!mRefreshEnabled) {
@ -2017,6 +2002,30 @@ nsViewManager::FlushPendingInvalidates()
}
}
void
nsViewManager::CallWillPaintOnObservers()
{
NS_PRECONDITION(IsRootVM(), "Must be root VM for this to be called!\n");
NS_PRECONDITION(mUpdateBatchCnt > 0, "Must be in an update batch!");
#ifdef DEBUG
PRInt32 savedUpdateBatchCnt = mUpdateBatchCnt;
#endif
PRInt32 index;
for (index = 0; index < mVMCount; index++) {
nsViewManager* vm = (nsViewManager*)gViewManagers->ElementAt(index);
if (vm->RootViewManager() == this) {
// One of our kids.
nsCOMPtr<nsIViewObserver> obs = vm->GetViewObserver();
if (obs) {
obs->WillPaint();
NS_ASSERTION(mUpdateBatchCnt == savedUpdateBatchCnt,
"Observer did not end view batch?");
}
}
}
}
void
nsViewManager::ProcessInvalidateEvent()
{

View File

@ -197,6 +197,10 @@ private:
void FlushPendingInvalidates();
void ProcessPendingUpdates(nsView *aView, PRBool aDoInvalidate);
/**
* Call WillPaint() on all view observers under this vm root.
*/
void CallWillPaintOnObservers();
void ReparentChildWidgets(nsIView* aView, nsIWidget *aNewWidget);
void ReparentWidgets(nsIView* aView, nsIView *aParent);
already_AddRefed<nsIRenderingContext> CreateRenderingContext(nsView &aView);