Bug 1507189 - Replace nsIPresShell::ScrollDirection with an enumset over layers::ScrollDirection r=botond
authorAlaa Emad <eng.alaaemad.ae@gmail.com>
Mon, 26 Oct 2020 04:04:16 +0000
changeset 554357 9cf73428357c3679bf6dfff0e1e0c1bc24d5c0e9
parent 554356 45bbeabb0c89cf73d644b59898cb207e4462f147
child 554358 be354ee427d01400963bf0086058b63b9dfadc09
push id37893
push userbtara@mozilla.com
push dateMon, 26 Oct 2020 09:28:34 +0000
treeherdermozilla-central@b1a74943bc51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1507189
milestone84.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1507189 - Replace nsIPresShell::ScrollDirection with an enumset over layers::ScrollDirection r=botond Differential Revision: https://phabricator.services.mozilla.com/D94146
dom/events/EventStateManager.cpp
gfx/layers/LayersTypes.h
gfx/layers/apz/src/APZUtils.h
gfx/layers/apz/src/FocusTarget.cpp
layout/base/PresShell.cpp
layout/base/PresShell.h
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -2689,16 +2689,17 @@ nsIFrame* EventStateManager::ComputeScro
     MOZ_ASSERT(frameToScroll);
 
     if (!checkIfScrollableX && !checkIfScrollableY) {
       return frameToScroll;
     }
 
     // If the frame disregards the direction the user is trying to scroll, then
     // it should just bubbles the scroll event up to its parental scroll frame
+
     Maybe<layers::ScrollDirection> disregardedDirection =
         WheelHandlingUtils::GetDisregardedWheelScrollDirection(scrollFrame);
     if (disregardedDirection) {
       switch (disregardedDirection.ref()) {
         case layers::ScrollDirection::eHorizontal:
           if (checkIfScrollableX) {
             continue;
           }
@@ -5882,17 +5883,17 @@ nsresult EventStateManager::DoContentCom
       break;
     default:
       return NS_ERROR_INVALID_ARG;
   }
 
   aEvent->mSucceeded = true;
 
   nsIScrollableFrame* sf =
-      presShell->GetScrollableFrameToScroll(ScrollableDirection::Either);
+      presShell->GetScrollableFrameToScroll(layers::EitherScrollDirection);
   aEvent->mIsEnabled =
       sf ? (aEvent->mScroll.mIsHorizontal ? WheelHandlingUtils::CanScrollOn(
                                                 sf, aEvent->mScroll.mAmount, 0)
                                           : WheelHandlingUtils::CanScrollOn(
                                                 sf, 0, aEvent->mScroll.mAmount))
          : false;
 
   if (!aEvent->mIsEnabled || aEvent->mOnlyEnabledCheck) {
--- a/gfx/layers/LayersTypes.h
+++ b/gfx/layers/LayersTypes.h
@@ -11,16 +11,17 @@
 #include <stdint.h>  // for uint32_t
 #include <stdio.h>   // FILE
 
 #include "Units.h"
 #include "mozilla/DefineEnum.h"  // for MOZ_DEFINE_ENUM_CLASS_WITH_BASE
 #include "mozilla/Maybe.h"
 #include "mozilla/TimeStamp.h"  // for TimeStamp
 #include "nsRegion.h"
+#include "mozilla/EnumSet.h"
 
 #ifndef MOZ_LAYERS_HAVE_LOG
 #  define MOZ_LAYERS_HAVE_LOG
 #endif
 #define MOZ_LAYERS_LOG(_args) \
   MOZ_LOG(LayerManager::GetLog(), LogLevel::Debug, _args)
 #define MOZ_LAYERS_LOG_IF_SHADOWABLE(layer, _args)             \
   do {                                                         \
@@ -369,16 +370,23 @@ class CompositableHandle final {
 };
 
 // clang-format off
 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollDirection, uint32_t, (
   eVertical,
   eHorizontal
 ));
 
+typedef EnumSet<ScrollDirection> ScrollDirections;
+
+constexpr ScrollDirections EitherScrollDirection(ScrollDirection::eVertical,ScrollDirection::eHorizontal);
+constexpr ScrollDirections HorizontalScrollDirection(ScrollDirection::eHorizontal);
+constexpr ScrollDirections VerticalScollDirection(ScrollDirection::eVertical);
+
+
 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(CompositionPayloadType, uint8_t, (
   /**
    * A |CompositionPayload| with this type indicates a key press happened
    * before composition and will be used to determine latency between key press
    * and presentation in |mozilla::Telemetry::KEYPRESS_PRESENT_LATENCY|
    */
   eKeyPress,
 
--- a/gfx/layers/apz/src/APZUtils.h
+++ b/gfx/layers/apz/src/APZUtils.h
@@ -38,18 +38,16 @@ enum CancelAnimationFlags : uint32_t {
 };
 
 inline CancelAnimationFlags operator|(CancelAnimationFlags a,
                                       CancelAnimationFlags b) {
   return static_cast<CancelAnimationFlags>(static_cast<int>(a) |
                                            static_cast<int>(b));
 }
 
-typedef EnumSet<ScrollDirection> ScrollDirections;
-
 // clang-format off
 enum class ScrollSource {
   // scrollTo() or something similar.
   DOM,
 
   // Touch-screen or trackpad with gesture support.
   Touch,
 
--- a/gfx/layers/apz/src/FocusTarget.cpp
+++ b/gfx/layers/apz/src/FocusTarget.cpp
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/layers/FocusTarget.h"
-
 #include "mozilla/dom/BrowserBridgeChild.h"  // for BrowserBridgeChild
 #include "mozilla/dom/EventTarget.h"         // for EventTarget
 #include "mozilla/dom/RemoteBrowser.h"       // For RemoteBrowser
 #include "mozilla/EventDispatcher.h"         // for EventDispatcher
 #include "mozilla/PresShell.h"               // For PresShell
 #include "mozilla/StaticPrefs_apz.h"
 #include "nsIContentInlines.h"  // for nsINode::IsEditable()
 #include "nsLayoutUtils.h"      // for nsLayoutUtils
@@ -184,20 +183,20 @@ FocusTarget::FocusTarget(PresShell* aRoo
 
   nsCOMPtr<nsIContent> selectedContent =
       presShell->GetSelectedContentForScrolling();
 
   // Gather the scrollable frames that would be scrolled in each direction
   // for this scroll target
   nsIScrollableFrame* horizontal =
       presShell->GetScrollableFrameToScrollForContent(
-          selectedContent.get(), ScrollableDirection::Horizontal);
+          selectedContent.get(), HorizontalScrollDirection);
   nsIScrollableFrame* vertical =
-      presShell->GetScrollableFrameToScrollForContent(
-          selectedContent.get(), ScrollableDirection::Vertical);
+      presShell->GetScrollableFrameToScrollForContent(selectedContent.get(),
+                                                      VerticalScollDirection);
 
   // We might have the globally focused element for scrolling. Gather a ViewID
   // for the horizontal and vertical scroll targets of this element.
   ScrollTargets target;
   target.mHorizontal = nsLayoutUtils::FindIDForScrollableFrame(horizontal);
   target.mVertical = nsLayoutUtils::FindIDForScrollableFrame(vertical);
   mData = AsVariant(target);
 
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -2333,18 +2333,17 @@ PresShell::IntraLineMove(bool aForward, 
   RefPtr<nsFrameSelection> frameSelection = mSelection;
   return frameSelection->IntraLineMove(aForward, aExtend);
 }
 
 NS_IMETHODIMP
 PresShell::PageMove(bool aForward, bool aExtend) {
   nsIFrame* frame = nullptr;
   if (!aExtend) {
-    frame = do_QueryFrame(
-        GetScrollableFrameToScroll(ScrollableDirection::Vertical));
+    frame = do_QueryFrame(GetScrollableFrameToScroll(VerticalScollDirection));
     // If there is no scrollable frame, get the frame to move caret instead.
   }
   if (!frame || frame->PresContext() != mPresContext) {
     frame = mSelection->GetFrameToPageSelect();
     if (!frame) {
       return NS_OK;
     }
   }
@@ -2354,33 +2353,33 @@ PresShell::PageMove(bool aForward, bool 
   RefPtr<nsFrameSelection> frameSelection = mSelection;
   return frameSelection->PageMove(
       aForward, aExtend, frame, nsFrameSelection::SelectionIntoView::IfChanged);
 }
 
 NS_IMETHODIMP
 PresShell::ScrollPage(bool aForward) {
   nsIScrollableFrame* scrollFrame =
-      GetScrollableFrameToScroll(ScrollableDirection::Vertical);
+      GetScrollableFrameToScroll(VerticalScollDirection);
   if (scrollFrame) {
     mozilla::Telemetry::Accumulate(
         mozilla::Telemetry::SCROLL_INPUT_METHODS,
         (uint32_t)ScrollInputMethod::MainThreadScrollPage);
     scrollFrame->ScrollBy(
         nsIntPoint(0, aForward ? 1 : -1), ScrollUnit::PAGES, ScrollMode::Smooth,
         nullptr, mozilla::ScrollOrigin::NotSpecified,
         nsIScrollableFrame::NOT_MOMENTUM, nsIScrollableFrame::ENABLE_SNAP);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::ScrollLine(bool aForward) {
   nsIScrollableFrame* scrollFrame =
-      GetScrollableFrameToScroll(ScrollableDirection::Vertical);
+      GetScrollableFrameToScroll(VerticalScollDirection);
   if (scrollFrame) {
     mozilla::Telemetry::Accumulate(
         mozilla::Telemetry::SCROLL_INPUT_METHODS,
         (uint32_t)ScrollInputMethod::MainThreadScrollLine);
     int32_t lineCount =
         Preferences::GetInt("toolkit.scrollbox.verticalScrollDistance",
                             NS_DEFAULT_VERTICAL_SCROLL_DISTANCE);
     scrollFrame->ScrollBy(
@@ -2389,17 +2388,17 @@ PresShell::ScrollLine(bool aForward) {
         nsIScrollableFrame::NOT_MOMENTUM, nsIScrollableFrame::ENABLE_SNAP);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::ScrollCharacter(bool aRight) {
   nsIScrollableFrame* scrollFrame =
-      GetScrollableFrameToScroll(ScrollableDirection::Horizontal);
+      GetScrollableFrameToScroll(HorizontalScrollDirection);
   if (scrollFrame) {
     mozilla::Telemetry::Accumulate(
         mozilla::Telemetry::SCROLL_INPUT_METHODS,
         (uint32_t)ScrollInputMethod::MainThreadScrollCharacter);
     int32_t h =
         Preferences::GetInt("toolkit.scrollbox.horizontalScrollDistance",
                             NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE);
     scrollFrame->ScrollBy(
@@ -2408,17 +2407,17 @@ PresShell::ScrollCharacter(bool aRight) 
         nsIScrollableFrame::NOT_MOMENTUM, nsIScrollableFrame::ENABLE_SNAP);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::CompleteScroll(bool aForward) {
   nsIScrollableFrame* scrollFrame =
-      GetScrollableFrameToScroll(ScrollableDirection::Vertical);
+      GetScrollableFrameToScroll(VerticalScollDirection);
   if (scrollFrame) {
     mozilla::Telemetry::Accumulate(
         mozilla::Telemetry::SCROLL_INPUT_METHODS,
         (uint32_t)ScrollInputMethod::MainThreadCompleteScroll);
     scrollFrame->ScrollBy(
         nsIntPoint(0, aForward ? 1 : -1), ScrollUnit::WHOLE, ScrollMode::Smooth,
         nullptr, mozilla::ScrollOrigin::NotSpecified,
         nsIScrollableFrame::NOT_MOMENTUM, nsIScrollableFrame::ENABLE_SNAP);
@@ -2876,44 +2875,44 @@ already_AddRefed<nsIContent> PresShell::
       selectedContent =
           nsIContent::FromNodeOrNull(domSelection->GetFocusNode());
     }
   }
   return selectedContent.forget();
 }
 
 nsIScrollableFrame* PresShell::GetScrollableFrameToScrollForContent(
-    nsIContent* aContent, ScrollableDirection aDirection) {
+    nsIContent* aContent, ScrollDirections aDirections) {
   nsIScrollableFrame* scrollFrame = nullptr;
   if (aContent) {
     nsIFrame* startFrame = aContent->GetPrimaryFrame();
     if (startFrame) {
       scrollFrame = startFrame->GetScrollTargetFrame();
       if (scrollFrame) {
         startFrame = scrollFrame->GetScrolledFrame();
       }
       scrollFrame = nsLayoutUtils::GetNearestScrollableFrameForDirection(
-          startFrame, aDirection);
+          startFrame, aDirections);
     }
   }
   if (!scrollFrame) {
     scrollFrame = GetRootScrollFrameAsScrollable();
     if (!scrollFrame || !scrollFrame->GetScrolledFrame()) {
       return nullptr;
     }
     scrollFrame = nsLayoutUtils::GetNearestScrollableFrameForDirection(
-        scrollFrame->GetScrolledFrame(), aDirection);
+        scrollFrame->GetScrolledFrame(), aDirections);
   }
   return scrollFrame;
 }
 
 nsIScrollableFrame* PresShell::GetScrollableFrameToScroll(
-    ScrollableDirection aDirection) {
+    ScrollDirections aDirections) {
   nsCOMPtr<nsIContent> content = GetContentForScrolling();
-  return GetScrollableFrameToScrollForContent(content.get(), aDirection);
+  return GetScrollableFrameToScrollForContent(content.get(), aDirections);
 }
 
 void PresShell::CancelAllPendingReflows() {
   mDirtyRoots.Clear();
 
   if (mObservingLayoutFlushes) {
     GetPresContext()->RefreshDriver()->RemoveLayoutFlushObserver(this);
     mObservingLayoutFlushes = false;
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -82,18 +82,16 @@ struct RangePaintInfo;
 #ifdef MOZ_REFLOW_PERF
 class ReflowCountMgr;
 #endif
 class WeakFrame;
 class ZoomConstraintsClient;
 
 struct nsCallbackEventRequest;
 
-enum class ScrollableDirection;
-
 namespace mozilla {
 class AccessibleCaretEventHub;
 class EventStates;
 class GeckoMVMContext;
 class OverflowChangedTracker;
 class StyleSheet;
 
 #ifdef ACCESSIBILITY
@@ -414,27 +412,27 @@ class PresShell final : public nsStubDoc
 
   /**
    * Gets nearest scrollable frame from the specified content node. The frame
    * is scrollable with overflow:scroll or overflow:auto in some direction when
    * aDirection is eEither.  Otherwise, this returns a nearest frame that is
    * scrollable in the specified direction.
    */
   nsIScrollableFrame* GetScrollableFrameToScrollForContent(
-      nsIContent* aContent, ScrollableDirection aDirection);
+      nsIContent* aContent, layers::ScrollDirections aDirections);
 
   /**
    * Gets nearest scrollable frame from current focused content or DOM
    * selection if there is no focused content. The frame is scrollable with
    * overflow:scroll or overflow:auto in some direction when aDirection is
    * eEither.  Otherwise, this returns a nearest frame that is scrollable in
    * the specified direction.
    */
   nsIScrollableFrame* GetScrollableFrameToScroll(
-      ScrollableDirection aDirection);
+      layers::ScrollDirections aDirections);
 
   /**
    * Returns the page sequence frame associated with the frame hierarchy.
    * Returns nullptr if not a paginated view.
    */
   nsPageSequenceFrame* GetPageSequenceFrame() const;
 
   /**
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1385,32 +1385,30 @@ ScrollableLayerGuid::ViewID nsLayoutUtil
       id = FindOrCreateIDFor(content);
     }
   }
   return id;
 }
 
 // static
 nsIScrollableFrame* nsLayoutUtils::GetNearestScrollableFrameForDirection(
-    nsIFrame* aFrame, ScrollableDirection aDirection) {
+    nsIFrame* aFrame, ScrollDirections aDirections) {
   NS_ASSERTION(
       aFrame, "GetNearestScrollableFrameForDirection expects a non-null frame");
   for (nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
     nsIScrollableFrame* scrollableFrame = do_QueryFrame(f);
     if (scrollableFrame) {
       uint32_t directions =
           scrollableFrame->GetAvailableScrollingDirectionsForUserInputEvents();
-      if (aDirection == ScrollableDirection::Vertical ||
-          aDirection == ScrollableDirection::Either) {
+      if (aDirections.contains(ScrollDirection::eVertical)) {
         if (directions & nsIScrollableFrame::VERTICAL) {
           return scrollableFrame;
         }
       }
-      if (aDirection == ScrollableDirection::Horizontal ||
-          aDirection == ScrollableDirection::Either) {
+      if (aDirections.contains(ScrollDirection::eHorizontal)) {
         if (directions & nsIScrollableFrame::HORIZONTAL) {
           return scrollableFrame;
         }
       }
     }
   }
   return nullptr;
 }
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -18,25 +18,27 @@
 #include "mozilla/SurfaceFromElementResult.h"
 #include "mozilla/SVGImageContext.h"
 #include "mozilla/ToString.h"
 #include "mozilla/TypedEnumBits.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/layout/FrameChildList.h"
 #include "mozilla/layers/ScrollableLayerGuid.h"
 #include "mozilla/gfx/2D.h"
+
 #include "gfx2DGlue.h"
 #include "gfxPoint.h"
 #include "nsBoundingMetrics.h"
 #include "nsCSSPropertyIDSet.h"
 #include "nsClassHashtable.h"
 #include "nsGkAtoms.h"
 #include "nsThreadUtils.h"
 #include "ImageContainer.h"  // for layers::Image
 #include "Units.h"
+#include "mozilla/layers/LayersTypes.h"
 #include <limits>
 #include <algorithm>
 // If you're thinking of adding a new include here, please try hard to not.
 // This header file gets included just about everywhere and adding headers here
 // can dramatically increase avoidable build activity. Try instead:
 // - using a forward declaration
 // - putting the include in the .cpp file, if it is only needed by the body
 // - putting your new functions in some other less-widely-used header
@@ -103,28 +105,27 @@ struct RectCornerRadii;
 enum class ShapedTextFlags : uint16_t;
 }  // namespace gfx
 namespace layers {
 struct FrameMetrics;
 struct ScrollMetadata;
 class Image;
 class StackingContextHelper;
 class Layer;
+
 }  // namespace layers
 }  // namespace mozilla
 
 // Flags to customize the behavior of nsLayoutUtils::DrawString.
 enum class DrawStringFlags {
   Default = 0x0,
   ForceHorizontal = 0x1  // Forces the text to be drawn horizontally.
 };
 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DrawStringFlags)
 
-enum class ScrollableDirection { Horizontal, Vertical, Either };
-
 namespace mozilla {
 
 class RectCallback {
  public:
   virtual void AddRect(const nsRect& aRect) = 0;
 };
 
 }  // namespace mozilla
@@ -526,17 +527,17 @@ class nsLayoutUtils {
    * positive amount in that direction.
    * The search extends across document boundaries.
    *
    * @param  aFrame the frame to start with
    * @param  aDirection Whether it's for horizontal or vertical scrolling.
    * @return the nearest scrollable frame or nullptr if not found
    */
   static nsIScrollableFrame* GetNearestScrollableFrameForDirection(
-      nsIFrame* aFrame, ScrollableDirection aDirection);
+      nsIFrame* aFrame, mozilla::layers::ScrollDirections aDirections);
 
   enum {
     /**
      * If the SCROLLABLE_SAME_DOC flag is set, then we only walk the frame tree
      * up to the root frame in the current document.
      */
     SCROLLABLE_SAME_DOC = 0x01,
     /**