Bug 1677643 - Replace nsIScrollableFrame::{HORIZONTAL, VERTICAL} with ScrollDirections. r=botond

Differential Revision: https://phabricator.services.mozilla.com/D102087
This commit is contained in:
nirmay 2021-01-21 17:45:19 +00:00
Родитель 8c3701e76e
Коммит 55420bffb0
10 изменённых файлов: 69 добавлений и 55 удалений

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

@ -1639,7 +1639,7 @@ void Element::GetElementsWithGrid(nsTArray<RefPtr<Element>>& aElements) {
bool Element::HasVisibleScrollbars() {
nsIScrollableFrame* scrollFrame = GetScrollFrame();
return scrollFrame && scrollFrame->GetScrollbarVisibility();
return scrollFrame && (!scrollFrame->GetScrollbarVisibility().isEmpty());
}
nsresult Element::BindToTree(BindContext& aContext, nsINode& aParent) {

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

@ -2730,14 +2730,14 @@ nsIFrame* EventStateManager::ComputeScrollTargetAndMayAdjustWheelEvent(
}
}
uint32_t directions =
layers::ScrollDirections directions =
scrollableFrame->GetAvailableScrollingDirectionsForUserInputEvents();
if ((!(directions & nsIScrollableFrame::VERTICAL) &&
!(directions & nsIScrollableFrame::HORIZONTAL)) ||
if ((!(directions.contains(layers::ScrollDirection::eVertical)) &&
!(directions.contains(layers::ScrollDirection::eHorizontal))) ||
(checkIfScrollableY && !checkIfScrollableX &&
!(directions & nsIScrollableFrame::VERTICAL)) ||
!(directions.contains(layers::ScrollDirection::eVertical))) ||
(checkIfScrollableX && !checkIfScrollableY &&
!(directions & nsIScrollableFrame::HORIZONTAL))) {
!(directions.contains(layers::ScrollDirection::eHorizontal)))) {
continue;
}
@ -3053,17 +3053,18 @@ void EventStateManager::DecideGestureEvent(WidgetGestureNotifyEvent* aEvent,
displayPanFeedback = false;
}
} else { // Not a XUL box
uint32_t scrollbarVisibility =
layers::ScrollDirections scrollbarVisibility =
scrollableFrame->GetScrollbarVisibility();
// Check if we have visible scrollbars
if (scrollbarVisibility & nsIScrollableFrame::VERTICAL) {
if (scrollbarVisibility.contains(layers::ScrollDirection::eVertical)) {
panDirection = WidgetGestureNotifyEvent::ePanVertical;
displayPanFeedback = true;
break;
}
if (scrollbarVisibility & nsIScrollableFrame::HORIZONTAL) {
if (scrollbarVisibility.contains(
layers::ScrollDirection::eHorizontal)) {
panDirection = WidgetGestureNotifyEvent::ePanHorizontal;
displayPanFeedback = true;
}

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

@ -71,13 +71,15 @@ bool WheelHandlingUtils::CanScrollOn(nsIScrollableFrame* aScrollFrame,
nsPoint scrollPt = aScrollFrame->GetVisualViewportOffset();
nsRect scrollRange = aScrollFrame->GetScrollRangeForUserInputEvents();
uint32_t directions =
layers::ScrollDirections directions =
aScrollFrame->GetAvailableScrollingDirectionsForUserInputEvents();
return (aDirectionX && (directions & nsIScrollableFrame::HORIZONTAL) &&
return ((aDirectionX != 0.0) &&
(directions.contains(layers::ScrollDirection::eHorizontal)) &&
CanScrollInRange(scrollRange.x, scrollPt.x, scrollRange.XMost(),
aDirectionX)) ||
(aDirectionY && (directions & nsIScrollableFrame::VERTICAL) &&
((aDirectionY != 0.0) &&
(directions.contains(layers::ScrollDirection::eVertical)) &&
CanScrollInRange(scrollRange.y, scrollPt.y, scrollRange.YMost(),
aDirectionY));
}
@ -721,13 +723,13 @@ void ESMAutoDirWheelDeltaAdjuster::OnAdjusted() {
}
bool ESMAutoDirWheelDeltaAdjuster::CanScrollAlongXAxis() const {
return mScrollTargetFrame->GetAvailableScrollingDirections() &
nsIScrollableFrame::HORIZONTAL;
return mScrollTargetFrame->GetAvailableScrollingDirections().contains(
layers::ScrollDirection::eHorizontal);
}
bool ESMAutoDirWheelDeltaAdjuster::CanScrollAlongYAxis() const {
return mScrollTargetFrame->GetAvailableScrollingDirections() &
nsIScrollableFrame::VERTICAL;
return mScrollTargetFrame->GetAvailableScrollingDirections().contains(
layers::ScrollDirection::eVertical);
}
bool ESMAutoDirWheelDeltaAdjuster::CanScrollUpwards() const {

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

@ -3450,12 +3450,13 @@ static void ScrollToShowRect(nsIScrollableFrame* aFrameAsScrollable,
}
ScrollStyles ss = aFrameAsScrollable->GetScrollStyles();
nsRect allowedRange(scrollPt, nsSize(0, 0));
uint32_t directions = aFrameAsScrollable->GetAvailableScrollingDirections();
ScrollDirections directions =
aFrameAsScrollable->GetAvailableScrollingDirections();
if (((aScrollFlags & ScrollFlags::ScrollOverflowHidden) ||
ss.mVertical != StyleOverflow::Hidden) &&
(!aVertical.mOnlyIfPerceivedScrollableDirection ||
(directions & nsIScrollableFrame::VERTICAL))) {
(directions.contains(ScrollDirection::eVertical)))) {
if (ComputeNeedToScroll(aVertical.mWhenToScroll, lineSize.height, aRect.y,
aRect.YMost(), visibleRect.y + scrollPadding.top,
visibleRect.YMost() - scrollPadding.bottom)) {
@ -3471,7 +3472,7 @@ static void ScrollToShowRect(nsIScrollableFrame* aFrameAsScrollable,
if (((aScrollFlags & ScrollFlags::ScrollOverflowHidden) ||
ss.mHorizontal != StyleOverflow::Hidden) &&
(!aHorizontal.mOnlyIfPerceivedScrollableDirection ||
(directions & nsIScrollableFrame::HORIZONTAL))) {
(directions.contains(ScrollDirection::eHorizontal)))) {
if (ComputeNeedToScroll(aHorizontal.mWhenToScroll, lineSize.width, aRect.x,
aRect.XMost(), visibleRect.x + scrollPadding.left,
visibleRect.XMost() - scrollPadding.right)) {

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

@ -1397,15 +1397,15 @@ nsIScrollableFrame* nsLayoutUtils::GetNearestScrollableFrameForDirection(
for (nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
nsIScrollableFrame* scrollableFrame = do_QueryFrame(f);
if (scrollableFrame) {
uint32_t directions =
ScrollDirections directions =
scrollableFrame->GetAvailableScrollingDirectionsForUserInputEvents();
if (aDirections.contains(ScrollDirection::eVertical)) {
if (directions & nsIScrollableFrame::VERTICAL) {
if (directions.contains(ScrollDirection::eVertical)) {
return scrollableFrame;
}
}
if (aDirections.contains(ScrollDirection::eHorizontal)) {
if (directions & nsIScrollableFrame::HORIZONTAL) {
if (directions.contains(ScrollDirection::eHorizontal)) {
return scrollableFrame;
}
}

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

@ -1800,8 +1800,9 @@ nsIFrame* nsFrameSelection::GetFrameToPageSelect() const {
if (scrollStyles.mVertical == StyleOverflow::Hidden) {
continue;
}
uint32_t directions = scrollableFrame->GetAvailableScrollingDirections();
if (directions & nsIScrollableFrame::VERTICAL) {
layers::ScrollDirections directions =
scrollableFrame->GetAvailableScrollingDirections();
if (directions.contains(layers::ScrollDirection::eVertical)) {
// If there is sub scrollable frame, let's use its page size to select.
return frame;
}

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

@ -115,16 +115,16 @@ using namespace mozilla::layers;
using namespace mozilla::layout;
using nsStyleTransformMatrix::TransformReferenceBox;
static uint32_t GetOverflowChange(const nsRect& aCurScrolledRect,
const nsRect& aPrevScrolledRect) {
uint32_t result = 0;
static ScrollDirections GetOverflowChange(const nsRect& aCurScrolledRect,
const nsRect& aPrevScrolledRect) {
ScrollDirections result;
if (aPrevScrolledRect.x != aCurScrolledRect.x ||
aPrevScrolledRect.width != aCurScrolledRect.width) {
result |= nsIScrollableFrame::HORIZONTAL;
result += ScrollDirection::eHorizontal;
}
if (aPrevScrolledRect.y != aCurScrolledRect.y ||
aPrevScrolledRect.height != aCurScrolledRect.height) {
result |= nsIScrollableFrame::VERTICAL;
result += ScrollDirection::eVertical;
}
return result;
}
@ -6543,17 +6543,18 @@ bool ScrollFrameHelper::ComputeCustomOverflow(OverflowAreas& aOverflowAreas) {
// changing or might require repositioning the scrolled content due to
// reduced extents.
nsRect scrolledRect = GetScrolledRect();
uint32_t overflowChange = GetOverflowChange(scrolledRect, mPrevScrolledRect);
ScrollDirections overflowChange =
GetOverflowChange(scrolledRect, mPrevScrolledRect);
mPrevScrolledRect = scrolledRect;
bool needReflow = false;
nsPoint scrollPosition = GetScrollPosition();
if (overflowChange & nsIScrollableFrame::HORIZONTAL) {
if (overflowChange.contains(ScrollDirection::eHorizontal)) {
if (ss.mHorizontal != StyleOverflow::Hidden || scrollPosition.x) {
needReflow = true;
}
}
if (overflowChange & nsIScrollableFrame::VERTICAL) {
if (overflowChange.contains(ScrollDirection::eVertical)) {
if (ss.mVertical != StyleOverflow::Hidden || scrollPosition.y) {
needReflow = true;
}
@ -7301,16 +7302,16 @@ void ScrollFrameHelper::FireScrolledAreaEvent() {
}
}
uint32_t nsIScrollableFrame::GetAvailableScrollingDirections() const {
ScrollDirections nsIScrollableFrame::GetAvailableScrollingDirections() const {
nscoord oneDevPixel =
GetScrolledFrame()->PresContext()->AppUnitsPerDevPixel();
uint32_t directions = 0;
ScrollDirections directions;
nsRect scrollRange = GetScrollRange();
if (scrollRange.width >= oneDevPixel) {
directions |= HORIZONTAL;
directions += ScrollDirection::eHorizontal;
}
if (scrollRange.height >= oneDevPixel) {
directions |= VERTICAL;
directions += ScrollDirection::eVertical;
}
return directions;
}
@ -7347,8 +7348,8 @@ nsRect ScrollFrameHelper::GetScrollRangeForUserInputEvents() const {
return scrollRange;
}
uint32_t ScrollFrameHelper::GetAvailableScrollingDirectionsForUserInputEvents()
const {
ScrollDirections
ScrollFrameHelper::GetAvailableScrollingDirectionsForUserInputEvents() const {
nsRect scrollRange = GetScrollRangeForUserInputEvents();
// We check if there is at least one half of a screen pixel of scroll range to
@ -7360,12 +7361,12 @@ uint32_t ScrollFrameHelper::GetAvailableScrollingDirectionsForUserInputEvents()
float halfScreenPixel =
GetScrolledFrame()->PresContext()->AppUnitsPerDevPixel() /
(mOuter->PresShell()->GetCumulativeResolution() * 2.f);
uint32_t directions = 0;
ScrollDirections directions;
if (scrollRange.width >= halfScreenPixel) {
directions |= nsIScrollableFrame::HORIZONTAL;
directions += ScrollDirection::eHorizontal;
}
if (scrollRange.height >= halfScreenPixel) {
directions |= nsIScrollableFrame::VERTICAL;
directions += ScrollDirection::eVertical;
}
return directions;
}

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

@ -338,11 +338,18 @@ class ScrollFrameHelper : public nsIReflowCallback {
nsRect GetUnsnappedScrolledRectInternal(const nsRect& aScrolledOverflowArea,
const nsSize& aScrollPortSize) const;
uint32_t GetAvailableScrollingDirectionsForUserInputEvents() const;
layers::ScrollDirections GetAvailableScrollingDirectionsForUserInputEvents()
const;
uint32_t GetScrollbarVisibility() const {
return (mHasVerticalScrollbar ? nsIScrollableFrame::VERTICAL : 0) |
(mHasHorizontalScrollbar ? nsIScrollableFrame::HORIZONTAL : 0);
layers::ScrollDirections GetScrollbarVisibility() const {
layers::ScrollDirections result;
if (mHasHorizontalScrollbar) {
result += layers::ScrollDirection::eHorizontal;
}
if (mHasVerticalScrollbar) {
result += layers::ScrollDirection::eVertical;
}
return result;
}
nsMargin GetActualScrollbarSizes(
nsIScrollableFrame::ScrollbarSizesOptions aOptions =
@ -901,10 +908,11 @@ class nsHTMLScrollFrame : public nsContainerFrame,
const final {
return mHelper.GetOverscrollBehaviorInfo();
}
uint32_t GetAvailableScrollingDirectionsForUserInputEvents() const final {
mozilla::layers::ScrollDirections
GetAvailableScrollingDirectionsForUserInputEvents() const final {
return mHelper.GetAvailableScrollingDirectionsForUserInputEvents();
}
uint32_t GetScrollbarVisibility() const final {
mozilla::layers::ScrollDirections GetScrollbarVisibility() const final {
return mHelper.GetScrollbarVisibility();
}
nsMargin GetActualScrollbarSizes(
@ -1383,10 +1391,11 @@ class nsXULScrollFrame final : public nsBoxFrame,
const final {
return mHelper.GetOverscrollBehaviorInfo();
}
uint32_t GetAvailableScrollingDirectionsForUserInputEvents() const final {
mozilla::layers::ScrollDirections
GetAvailableScrollingDirectionsForUserInputEvents() const final {
return mHelper.GetAvailableScrollingDirectionsForUserInputEvents();
}
uint32_t GetScrollbarVisibility() const final {
mozilla::layers::ScrollDirections GetScrollbarVisibility() const final {
return mHelper.GetScrollbarVisibility();
}
nsMargin GetActualScrollbarSizes(

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

@ -91,25 +91,24 @@ class nsIScrollableFrame : public nsIScrollbarMediator {
virtual mozilla::layers::OverscrollBehaviorInfo GetOverscrollBehaviorInfo()
const = 0;
enum { HORIZONTAL = 0x01, VERTICAL = 0x02 };
/**
* Return the scrollbars which are visible. It's OK to call this during reflow
* of the scrolled contents, in which case it will reflect the current
* assumptions about scrollbar visibility.
*/
virtual uint32_t GetScrollbarVisibility() const = 0;
virtual mozilla::layers::ScrollDirections GetScrollbarVisibility() const = 0;
/**
* Returns the directions in which scrolling is allowed (if the scroll range
* is at least one device pixel in that direction).
*/
uint32_t GetAvailableScrollingDirections() const;
mozilla::layers::ScrollDirections GetAvailableScrollingDirections() const;
/**
* Returns the directions in which scrolling is allowed when taking into
* account the visual viewport size and overflow hidden. (An (apz) zoomed in
* overflow hidden scrollframe is actually user scrollable.)
*/
virtual uint32_t GetAvailableScrollingDirectionsForUserInputEvents()
const = 0;
virtual mozilla::layers::ScrollDirections
GetAvailableScrollingDirectionsForUserInputEvents() const = 0;
/**
* 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

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

@ -3745,7 +3745,7 @@ bool nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFra
// scrollbars are not present.
nsIScrollableFrame* scrollFrame = do_QueryFrame(parentFrame);
return (!nsLookAndFeel::UseOverlayScrollbars() && scrollFrame &&
scrollFrame->GetScrollbarVisibility());
(!scrollFrame->GetScrollbarVisibility().isEmpty()));
}
case StyleAppearance::FocusOutline: