Bug 791616. Part 1: Add nsIScrollableFrame::GetPerceivedScrollingDirections to consolidate logic for whether UI actions should be allowed to scroll in a given direction. r=mats

--HG--
extra : rebase_source : 470acc887036b633f43a30fb7dc6ca24ddc02dc6
This commit is contained in:
Robert O'Callahan 2012-09-24 16:30:33 +12:00
Родитель f876b8f52e
Коммит fb11721aa0
4 изменённых файлов: 27 добавлений и 13 удалений

Просмотреть файл

@ -383,12 +383,11 @@ CanScrollOn(nsIScrollableFrame* aScrollFrame, double aDeltaX, double aDeltaY)
nsPoint scrollPt = aScrollFrame->GetScrollPosition();
nsRect scrollRange = aScrollFrame->GetScrollRange();
nscoord oneDevPixel =
aScrollFrame->GetScrolledFrame()->PresContext()->AppUnitsPerDevPixel();
uint32_t directions = aScrollFrame->GetPerceivedScrollingDirections();
return (aDeltaX && scrollRange.width >= oneDevPixel &&
return (aDeltaX && (directions & nsIScrollableFrame::HORIZONTAL) &&
CanScrollInRange(scrollRange.x, scrollPt.x, scrollRange.XMost(), aDeltaX)) ||
(aDeltaY && scrollRange.height >= oneDevPixel &&
(aDeltaY && (directions & nsIScrollableFrame::VERTICAL) &&
CanScrollInRange(scrollRange.y, scrollPt.y, scrollRange.YMost(), aDeltaY));
}

Просмотреть файл

@ -943,18 +943,12 @@ nsLayoutUtils::GetNearestScrollableFrameForDirection(nsIFrame* aFrame,
nsIScrollableFrame* scrollableFrame = do_QueryFrame(f);
if (scrollableFrame) {
nsPresContext::ScrollbarStyles ss = scrollableFrame->GetScrollbarStyles();
uint32_t scrollbarVisibility = scrollableFrame->GetScrollbarVisibility();
nsRect scrollRange = scrollableFrame->GetScrollRange();
// Require visible scrollbars or something to scroll to in
// the given direction.
nscoord oneDevPixel = f->PresContext()->DevPixelsToAppUnits(1);
uint32_t directions = scrollableFrame->GetPerceivedScrollingDirections();
if (aDirection == eVertical ?
(ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN &&
((scrollbarVisibility & nsIScrollableFrame::VERTICAL) ||
scrollRange.height >= oneDevPixel)) :
(directions & nsIScrollableFrame::VERTICAL)) :
(ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN &&
((scrollbarVisibility & nsIScrollableFrame::HORIZONTAL) ||
scrollRange.width >= oneDevPixel)))
(directions & nsIScrollableFrame::HORIZONTAL)))
return scrollableFrame;
}
}

Просмотреть файл

@ -4170,3 +4170,18 @@ nsGfxScrollFrameInner::FireScrolledAreaEvent()
nsEventDispatcher::Dispatch(doc, prescontext, &event, nullptr);
}
}
uint32_t
nsIScrollableFrame::GetPerceivedScrollingDirections() const
{
nscoord oneDevPixel = GetScrolledFrame()->PresContext()->AppUnitsPerDevPixel();
uint32_t directions = GetScrollbarVisibility();
nsRect scrollRange = GetScrollRange();
if (scrollRange.width >= oneDevPixel) {
directions |= HORIZONTAL;
}
if (scrollRange.height >= oneDevPixel) {
directions |= VERTICAL;
}
return directions;
}

Просмотреть файл

@ -51,6 +51,12 @@ public:
* assumptions about scrollbar visibility.
*/
virtual uint32_t GetScrollbarVisibility() const = 0;
/**
* Returns the directions in which scrolling is perceived to be allowed.
* A direction is perceived to be allowed if there is a visible scrollbar
* for that direction or if the scroll range is at least one device pixel.
*/
uint32_t GetPerceivedScrollingDirections() const;
/**
* Return the actual sizes of all possible scrollbars. Returns 0 for scrollbar
* positions that don't have a scrollbar or where the scrollbar is not visible.