From d98fdec7b0f13b401cbcc393137447ceb1523cfc Mon Sep 17 00:00:00 2001 From: "radha%netscape.com" Date: Wed, 25 Sep 2002 21:29:33 +0000 Subject: [PATCH] Fix for bug 156312. onScroll events fire when scroll doesn't happen. r=saari sr=jst. git-svn-id: svn://10.0.0.236/trunk@130443 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsGfxScrollFrame.cpp | 28 +++++++++++++------ .../layout/html/base/src/nsGfxScrollFrame.cpp | 28 +++++++++++++------ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/mozilla/layout/generic/nsGfxScrollFrame.cpp b/mozilla/layout/generic/nsGfxScrollFrame.cpp index b60294c65a7..9ff4e6c9322 100644 --- a/mozilla/layout/generic/nsGfxScrollFrame.cpp +++ b/mozilla/layout/generic/nsGfxScrollFrame.cpp @@ -951,16 +951,26 @@ nsGfxScrollFrameInner::AttributeChanged(nsIDocument *aDocument, nsCOMPtr presShell; mOuter->mPresContext->GetShell(getter_AddRefs(presShell)); - // Fire the onScroll event. - if (presShell && targetFrame && targetContent) - presShell->HandleEventWithTarget(&event, targetFrame, targetContent, - NS_EVENT_FLAG_INIT, &status); - + // Make sure the scrollbars indeed moved before firing the event. + // I think it is OK to prevent the call to ScrollbarChanged() + // if we didn't actually move. The following check is the first + // thing ScrollbarChanged() does anyway, before deciding to move + // the scrollbars. + nscoord curPosX=0, curPosY=0; nsIScrollableView* s = GetScrollableView(mOuter->mPresContext); - s->RemoveScrollPositionListener(this); - ScrollbarChanged(mOuter->mPresContext, x*mOnePixel, y*mOnePixel); - s->AddScrollPositionListener(this); - + if (s) { + s->GetScrollPosition(curPosX, curPosY); + if ((x*mOnePixel) == curPosX && (y*mOnePixel) == curPosY) + return NS_OK; + + // Fire the onScroll event. + if (presShell && targetFrame && targetContent) + presShell->HandleEventWithTarget(&event, targetFrame, targetContent, + NS_EVENT_FLAG_INIT, &status); + s->RemoveScrollPositionListener(this); + ScrollbarChanged(mOuter->mPresContext, x*mOnePixel, y*mOnePixel); + s->AddScrollPositionListener(this); + } } } diff --git a/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp b/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp index b60294c65a7..9ff4e6c9322 100644 --- a/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp +++ b/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp @@ -951,16 +951,26 @@ nsGfxScrollFrameInner::AttributeChanged(nsIDocument *aDocument, nsCOMPtr presShell; mOuter->mPresContext->GetShell(getter_AddRefs(presShell)); - // Fire the onScroll event. - if (presShell && targetFrame && targetContent) - presShell->HandleEventWithTarget(&event, targetFrame, targetContent, - NS_EVENT_FLAG_INIT, &status); - + // Make sure the scrollbars indeed moved before firing the event. + // I think it is OK to prevent the call to ScrollbarChanged() + // if we didn't actually move. The following check is the first + // thing ScrollbarChanged() does anyway, before deciding to move + // the scrollbars. + nscoord curPosX=0, curPosY=0; nsIScrollableView* s = GetScrollableView(mOuter->mPresContext); - s->RemoveScrollPositionListener(this); - ScrollbarChanged(mOuter->mPresContext, x*mOnePixel, y*mOnePixel); - s->AddScrollPositionListener(this); - + if (s) { + s->GetScrollPosition(curPosX, curPosY); + if ((x*mOnePixel) == curPosX && (y*mOnePixel) == curPosY) + return NS_OK; + + // Fire the onScroll event. + if (presShell && targetFrame && targetContent) + presShell->HandleEventWithTarget(&event, targetFrame, targetContent, + NS_EVENT_FLAG_INIT, &status); + s->RemoveScrollPositionListener(this); + ScrollbarChanged(mOuter->mPresContext, x*mOnePixel, y*mOnePixel); + s->AddScrollPositionListener(this); + } } }