Bug 526394. Part 31.5: Cleanup ScrolledAreaEvent stuff to be simpler. In particular we don't need to store the scrolled area, we can just compute it when we fire the event. r=mats

This commit is contained in:
Robert O'Callahan 2010-01-12 10:45:19 +13:00
parent 0de717dfb6
commit eefea0e5e3
2 changed files with 32 additions and 80 deletions

View File

@ -851,7 +851,7 @@ nsHTMLScrollFrame::Reflow(nsPresContext* aPresContext,
}
if (mInner.mIsRoot && oldScrolledAreaBounds != newScrolledAreaBounds) {
mInner.PostScrolledAreaEvent(newScrolledAreaBounds);
mInner.PostScrolledAreaEvent();
}
aStatus = NS_FRAME_COMPLETE;
@ -889,15 +889,6 @@ NS_IMETHODIMP nsHTMLScrollFrame::GetAccessible(nsIAccessible** aAccessible)
}
#endif
NS_IMETHODIMP
nsHTMLScrollFrame::PostScrolledAreaEventForCurrentArea()
{
nsRect currentScrolledArea = mInner.mScrolledFrame->GetView()->GetBounds();
mInner.PostScrolledAreaEvent(currentScrolledArea);
return NS_OK;
}
NS_QUERYFRAME_HEAD(nsHTMLScrollFrame)
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
NS_QUERYFRAME_ENTRY(nsIScrollableFrame)
@ -1179,15 +1170,6 @@ nsXULScrollFrame::DoLayout(nsBoxLayoutState& aState)
return rv;
}
NS_IMETHODIMP
nsXULScrollFrame::PostScrolledAreaEventForCurrentArea()
{
nsRect currentScrolledArea = mInner.mScrolledFrame->GetView()->GetBounds();
mInner.PostScrolledAreaEvent(currentScrolledArea);
return NS_OK;
}
NS_QUERYFRAME_HEAD(nsXULScrollFrame)
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
NS_QUERYFRAME_ENTRY(nsIScrollableFrame)
@ -2242,13 +2224,10 @@ nsGfxScrollFrameInner::Destroy()
nsContentUtils::DestroyAnonymousContent(&mVScrollbarContent);
nsContentUtils::DestroyAnonymousContent(&mScrollCornerContent);
mScrollEvent.Revoke();
mAsyncScrollPortEvent.Revoke();
if (mPostedReflowCallback) {
mOuter->PresContext()->PresShell()->CancelReflowCallback(this);
mPostedReflowCallback = PR_FALSE;
}
mScrolledAreaEventDispatcher.Revoke();
}
/**
@ -3251,54 +3230,40 @@ nsGfxScrollFrameInner::RestoreState(nsPresState* aState)
}
void
nsGfxScrollFrameInner::PostScrolledAreaEvent(nsRect &aScrolledArea)
nsGfxScrollFrameInner::PostScrolledAreaEvent()
{
if (mScrolledAreaEventDispatcher.IsPending()) {
mScrolledAreaEventDispatcher.get()->mScrolledArea = aScrolledArea;
if (mScrolledAreaEvent.IsPending()) {
return;
}
nsRefPtr<ScrolledAreaEventDispatcher> dp = new ScrolledAreaEventDispatcher(this);
if (!dp) {
NS_WARNING("OOM while posting NS_SCROLLEDAREACHANGED");
return;
}
dp->mScrolledArea = aScrolledArea;
if (NS_FAILED(NS_DispatchToCurrentThread(dp))) {
NS_WARNING("Failed to dispatch ScrolledAreaEventDispatcher");
} else {
mScrolledAreaEventDispatcher = dp;
}
mScrolledAreaEvent = new ScrolledAreaEvent(this);
NS_DispatchToCurrentThread(mScrolledAreaEvent.get());
}
////////////////////////////////////////////////////////////////////////////////
// ScrolledArea change event dispatch
NS_IMETHODIMP
nsGfxScrollFrameInner::ScrolledAreaEventDispatcher::Run()
nsGfxScrollFrameInner::ScrolledAreaEvent::Run()
{
if (mScrollFrameInner)
mScrollFrameInner->FireScrolledAreaEvent(mScrolledArea);
if (mInner) {
mInner->FireScrolledAreaEvent();
}
return NS_OK;
}
void
nsGfxScrollFrameInner::FireScrolledAreaEvent(nsRect &aScrolledArea)
nsGfxScrollFrameInner::FireScrolledAreaEvent()
{
mScrolledAreaEventDispatcher.Forget();
mScrolledAreaEvent.Forget();
nsScrollAreaEvent event(PR_TRUE, NS_SCROLLEDAREACHANGED, nsnull);
nsPresContext *prescontext = mOuter->PresContext();
nsIContent* content = mOuter->GetContent();
event.mArea = aScrolledArea;
event.mArea = mScrolledFrame->GetOverflowRectRelativeToParent();
nsIDocument *doc = content->GetCurrentDoc();
if (doc) {
nsEventDispatcher::Dispatch(doc, prescontext, &event, nsnull);
}
}

View File

@ -97,9 +97,8 @@ public:
void CurPosAttributeChanged(nsIContent* aChild);
void PostScrollEvent();
void FireScrollEvent();
void PostScrolledAreaEvent(nsRect &aScrolledArea);
void FireScrolledAreaEvent(nsRect &aScrolledArea);
void PostScrolledAreaEvent();
void FireScrolledAreaEvent();
class ScrollEvent : public nsRunnable {
public:
@ -119,6 +118,15 @@ public:
nsGfxScrollFrameInner *mInner;
};
class ScrolledAreaEvent : public nsRunnable {
public:
NS_DECL_NSIRUNNABLE
ScrolledAreaEvent(nsGfxScrollFrameInner *inner) : mInner(inner) {}
void Revoke() { mInner = nsnull; }
private:
nsGfxScrollFrameInner *mInner;
};
static void FinishReflowForScrollbar(nsIContent* aContent, nscoord aMinXY,
nscoord aMaxXY, nscoord aCurPosXY,
nscoord aPageIncrement,
@ -213,6 +221,7 @@ public:
nsRevocableEventPtr<ScrollEvent> mScrollEvent;
nsRevocableEventPtr<AsyncScrollPortEvent> mAsyncScrollPortEvent;
nsRevocableEventPtr<ScrolledAreaEvent> mScrolledAreaEvent;
nsIBox* mHScrollbarBox;
nsIBox* mVScrollbarBox;
nsIFrame* mScrolledFrame;
@ -264,25 +273,6 @@ public:
// If true, need to actually update our scrollbar attributes in the
// reflow callback.
PRPackedBool mUpdateScrollbarAttributes:1;
private:
class ScrolledAreaEventDispatcher : public nsRunnable {
public:
NS_DECL_NSIRUNNABLE
ScrolledAreaEventDispatcher(nsGfxScrollFrameInner *aScrollFrameInner)
: mScrollFrameInner(aScrollFrameInner),
mScrolledArea(0, 0, 0, 0)
{
}
void Revoke() { mScrollFrameInner = nsnull; }
nsGfxScrollFrameInner *mScrollFrameInner;
nsRect mScrolledArea;
};
nsRevocableEventPtr<ScrolledAreaEventDispatcher> mScrolledAreaEventDispatcher;
};
/**
@ -434,6 +424,10 @@ public:
virtual void CurPosAttributeChanged(nsIContent* aChild) {
mInner.CurPosAttributeChanged(aChild);
}
NS_IMETHOD PostScrolledAreaEventForCurrentArea() {
mInner.PostScrolledAreaEvent();
return NS_OK;
}
// nsIStatefulFrame
NS_IMETHOD SaveState(SpecialStateID aStateID, nsPresState** aState) {
@ -464,13 +458,6 @@ public:
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
#endif
/**
* Helper functions and class to dispatch events related to changes in the
* scroll frame's scrolled content area.
*/
NS_IMETHOD PostScrolledAreaEventForCurrentArea();
protected:
nsHTMLScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, PRBool aIsRoot);
virtual PRIntn GetSkipSides() const;
@ -659,6 +646,10 @@ public:
virtual void CurPosAttributeChanged(nsIContent* aChild) {
mInner.CurPosAttributeChanged(aChild);
}
NS_IMETHOD PostScrolledAreaEventForCurrentArea() {
mInner.PostScrolledAreaEvent();
return NS_OK;
}
// nsIStatefulFrame
NS_IMETHOD SaveState(SpecialStateID aStateID, nsPresState** aState) {
@ -687,10 +678,6 @@ public:
return nsBoxFrame::IsFrameOfType(aFlags);
}
void PostScrolledAreaEvent(nsRect &aScrolledArea);
NS_IMETHOD PostScrolledAreaEventForCurrentArea();
#ifdef NS_DEBUG
NS_IMETHOD GetFrameName(nsAString& aResult) const;
#endif