diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 1588a8199b26..c049e80cef7d 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1639,7 +1639,7 @@ void Element::GetElementsWithGrid(nsTArray>& aElements) { bool Element::HasVisibleScrollbars() { nsIScrollableFrame* scrollFrame = GetScrollFrame(); - return scrollFrame && scrollFrame->GetScrollbarVisibility(); + return scrollFrame && (!scrollFrame->GetScrollbarVisibility().isEmpty()); } nsresult Element::BindToTree(BindContext& aContext, nsINode& aParent) { diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index dab7427a1593..05384f1819bf 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -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; } diff --git a/dom/events/WheelHandlingHelper.cpp b/dom/events/WheelHandlingHelper.cpp index d3b38243e499..6f7a24fb551a 100644 --- a/dom/events/WheelHandlingHelper.cpp +++ b/dom/events/WheelHandlingHelper.cpp @@ -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 { diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index b759859b3f5d..18b8a562d20c 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -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)) { diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 3bceada48353..54e3b0670ced 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -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; } } diff --git a/layout/generic/nsFrameSelection.cpp b/layout/generic/nsFrameSelection.cpp index 7adedc935535..0abb7c335df6 100644 --- a/layout/generic/nsFrameSelection.cpp +++ b/layout/generic/nsFrameSelection.cpp @@ -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; } diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 21402dfa12d7..be2d2b0fcc18 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -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; } diff --git a/layout/generic/nsGfxScrollFrame.h b/layout/generic/nsGfxScrollFrame.h index 0766537a8e8c..0374244d65ce 100644 --- a/layout/generic/nsGfxScrollFrame.h +++ b/layout/generic/nsGfxScrollFrame.h @@ -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( diff --git a/layout/generic/nsIScrollableFrame.h b/layout/generic/nsIScrollableFrame.h index 7392f92f070d..4ecbc3e5bb6f 100644 --- a/layout/generic/nsIScrollableFrame.h +++ b/layout/generic/nsIScrollableFrame.h @@ -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 diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm index ae58a744fe76..f12e0aa2d1fb 100644 --- a/widget/cocoa/nsNativeThemeCocoa.mm +++ b/widget/cocoa/nsNativeThemeCocoa.mm @@ -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: