From 9058c2c0504a27ea09d3d46c4d72b38f3b151350 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Sun, 12 Aug 2012 10:42:35 +0900 Subject: [PATCH] Bug 719320 part.8-2 GetScrollAmount() should return both width and height for oblique wheel event r=smaug --- content/events/src/nsEventStateManager.cpp | 43 +++++++++++----------- content/events/src/nsEventStateManager.h | 10 ++--- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 7b3ca4abca49..d72d0bca5230 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -2582,9 +2582,13 @@ nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame, // we're using nearest scrollable frame's information. nsIScrollableFrame* scrollableFrame = ComputeScrollTarget(aTargetFrame, aEvent, true); - PRInt32 pixelsPerUnit = nsPresContext::AppUnitsToIntCSSPixels( - GetScrollAmount(aPresContext, aEvent, aTargetFrame, - scrollableFrame)); + nsSize scrollAmount = + GetScrollAmount(aPresContext, aEvent, aTargetFrame, scrollableFrame); + bool isHorizontal = + (aEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) != 0; + PRInt32 pixelsPerUnit = + nsPresContext::AppUnitsToIntCSSPixels(isHorizontal ? scrollAmount.width : + scrollAmount.height); bool isTrusted = (aEvent->flags & NS_EVENT_FLAG_TRUSTED) != 0; nsMouseScrollEvent event(isTrusted, NS_MOUSE_PIXEL_SCROLL, nullptr); @@ -2734,7 +2738,7 @@ nsEventStateManager::ComputeScrollTarget(nsIFrame* aTargetFrame, ComputeScrollTarget(newFrame, aEvent, aForDefaultAction) : nullptr; } -nscoord +nsSize nsEventStateManager::GetScrollAmount(nsPresContext* aPresContext, nsMouseScrollEvent* aEvent, nsIFrame* aTargetFrame, @@ -2745,31 +2749,27 @@ nsEventStateManager::GetScrollAmount(nsPresContext* aPresContext, MOZ_ASSERT(aTargetFrame); bool isPage = (aEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) != 0; - bool isHorizontal = - (aEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) != 0; - if (aScrollableFrame) { - nsSize size = isPage ? aScrollableFrame->GetPageScrollAmount() : - aScrollableFrame->GetLineScrollAmount(); - return isHorizontal ? size.width : size.height; + return isPage ? aScrollableFrame->GetPageScrollAmount() : + aScrollableFrame->GetLineScrollAmount(); } // If there is no scrollable frame and page scrolling, use view port size. if (isPage) { - nsRect visibleRect = aPresContext->GetVisibleArea(); - return isHorizontal ? visibleRect.width : visibleRect.height; + return aPresContext->GetVisibleArea().Size(); } // If there is no scrollable frame, we should use root frame's information. nsIFrame* rootFrame = aPresContext->PresShell()->GetRootFrame(); if (!rootFrame) { - return 0; + return nsSize(0, 0); } nsRefPtr fm; nsLayoutUtils::GetFontMetricsForFrame(rootFrame, getter_AddRefs(fm), nsLayoutUtils::FontSizeInflationFor(rootFrame)); - NS_ENSURE_TRUE(fm, 0); - return fm->MaxHeight(); + NS_ENSURE_TRUE(fm, nsSize(0, 0)); + PRInt32 fontHeight = fm->MaxHeight(); + return nsSize(fontHeight, fontHeight); } nsresult @@ -5054,9 +5054,13 @@ nsEventStateManager::PixelDeltaAccumulator::OnMousePixelScrollEvent( nsIScrollableFrame* scrollTarget = aESM->ComputeScrollTarget(aTargetFrame, aEvent, false); - PRInt32 pixelsPerLine = nsPresContext::AppUnitsToIntCSSPixels( - aESM->GetScrollAmount(aPresContext, aEvent, - aTargetFrame, scrollTarget)); + nsSize scrollAmount = + aESM->GetScrollAmount(aPresContext, aEvent, aTargetFrame, scrollTarget); + bool isHorizontal = + (aEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) != 0; + PRInt32 pixelsPerLine = + nsPresContext::AppUnitsToIntCSSPixels(isHorizontal ? scrollAmount.width : + scrollAmount.height); if (!mLastTime.IsNull()) { TimeDuration duration = TimeStamp::Now() - mLastTime; @@ -5067,9 +5071,6 @@ nsEventStateManager::PixelDeltaAccumulator::OnMousePixelScrollEvent( mLastTime = TimeStamp::Now(); - bool isHorizontal = - (aEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) != 0; - // If the delta direction is changed, we should reset the accumulated values. if (mX && isHorizontal && aEvent->delta && ((aEvent->delta > 0) != (mX > 0))) { diff --git a/content/events/src/nsEventStateManager.h b/content/events/src/nsEventStateManager.h index d7d8856caec9..f0a352defdd9 100644 --- a/content/events/src/nsEventStateManager.h +++ b/content/events/src/nsEventStateManager.h @@ -421,7 +421,7 @@ protected: /** * GetScrollAmount() returns the scroll amount in app units of one line or * one page. If the mouse scroll event scrolls a page, returns the page width - * or height. Otherwise, returns line height. + * and height. Otherwise, returns line height by both .width and .height. * * @param aTargetFrame The event target of the wheel event. * Must not be NULL. @@ -432,10 +432,10 @@ protected: * frame. Then, this method uses root frame's * line height or visible area's width or height. */ - nscoord GetScrollAmount(nsPresContext* aPresContext, - nsMouseScrollEvent* aEvent, - nsIFrame* aTargetFrame, - nsIScrollableFrame* aScrollableFrame); + nsSize GetScrollAmount(nsPresContext* aPresContext, + nsMouseScrollEvent* aEvent, + nsIFrame* aTargetFrame, + nsIScrollableFrame* aScrollableFrame); /** * DoScrollText() scrolls the scrollable frame for aEvent.