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); + } } }