Bug 1507189 - Replace nsIPresShell::ScrollDirection with an enumset over layers::ScrollDirection r=botond

Differential Revision: https://phabricator.services.mozilla.com/D94146
This commit is contained in:
Alaa Emad 2020-10-26 04:04:16 +00:00
parent 3d2a8005c8
commit aa2ac69761
8 changed files with 32 additions and 30 deletions

View File

@ -2694,6 +2694,7 @@ nsIFrame* EventStateManager::ComputeScrollTargetAndMayAdjustWheelEvent(
// 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) {
@ -5887,7 +5888,7 @@ nsresult EventStateManager::DoContentCommandScrollEvent(
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)

View File

@ -16,6 +16,7 @@
#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
@ -374,6 +375,13 @@ MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollDirection, uint32_t, (
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

View File

@ -43,8 +43,6 @@ inline CancelAnimationFlags operator|(CancelAnimationFlags a,
static_cast<int>(b));
}
typedef EnumSet<ScrollDirection> ScrollDirections;
// clang-format off
enum class ScrollSource {
// scrollTo() or something similar.

View File

@ -5,7 +5,6 @@
* 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
@ -189,10 +188,10 @@ FocusTarget::FocusTarget(PresShell* aRootPresShell,
// 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.

View File

@ -2338,8 +2338,7 @@ 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) {
@ -2359,7 +2358,7 @@ PresShell::PageMove(bool aForward, bool aExtend) {
NS_IMETHODIMP
PresShell::ScrollPage(bool aForward) {
nsIScrollableFrame* scrollFrame =
GetScrollableFrameToScroll(ScrollableDirection::Vertical);
GetScrollableFrameToScroll(VerticalScollDirection);
if (scrollFrame) {
mozilla::Telemetry::Accumulate(
mozilla::Telemetry::SCROLL_INPUT_METHODS,
@ -2375,7 +2374,7 @@ PresShell::ScrollPage(bool aForward) {
NS_IMETHODIMP
PresShell::ScrollLine(bool aForward) {
nsIScrollableFrame* scrollFrame =
GetScrollableFrameToScroll(ScrollableDirection::Vertical);
GetScrollableFrameToScroll(VerticalScollDirection);
if (scrollFrame) {
mozilla::Telemetry::Accumulate(
mozilla::Telemetry::SCROLL_INPUT_METHODS,
@ -2394,7 +2393,7 @@ PresShell::ScrollLine(bool aForward) {
NS_IMETHODIMP
PresShell::ScrollCharacter(bool aRight) {
nsIScrollableFrame* scrollFrame =
GetScrollableFrameToScroll(ScrollableDirection::Horizontal);
GetScrollableFrameToScroll(HorizontalScrollDirection);
if (scrollFrame) {
mozilla::Telemetry::Accumulate(
mozilla::Telemetry::SCROLL_INPUT_METHODS,
@ -2413,7 +2412,7 @@ PresShell::ScrollCharacter(bool aRight) {
NS_IMETHODIMP
PresShell::CompleteScroll(bool aForward) {
nsIScrollableFrame* scrollFrame =
GetScrollableFrameToScroll(ScrollableDirection::Vertical);
GetScrollableFrameToScroll(VerticalScollDirection);
if (scrollFrame) {
mozilla::Telemetry::Accumulate(
mozilla::Telemetry::SCROLL_INPUT_METHODS,
@ -2881,7 +2880,7 @@ already_AddRefed<nsIContent> PresShell::GetSelectedContentForScrolling() const {
}
nsIScrollableFrame* PresShell::GetScrollableFrameToScrollForContent(
nsIContent* aContent, ScrollableDirection aDirection) {
nsIContent* aContent, ScrollDirections aDirections) {
nsIScrollableFrame* scrollFrame = nullptr;
if (aContent) {
nsIFrame* startFrame = aContent->GetPrimaryFrame();
@ -2891,7 +2890,7 @@ nsIScrollableFrame* PresShell::GetScrollableFrameToScrollForContent(
startFrame = scrollFrame->GetScrolledFrame();
}
scrollFrame = nsLayoutUtils::GetNearestScrollableFrameForDirection(
startFrame, aDirection);
startFrame, aDirections);
}
}
if (!scrollFrame) {
@ -2900,15 +2899,15 @@ nsIScrollableFrame* PresShell::GetScrollableFrameToScrollForContent(
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() {

View File

@ -87,8 +87,6 @@ class ZoomConstraintsClient;
struct nsCallbackEventRequest;
enum class ScrollableDirection;
namespace mozilla {
class AccessibleCaretEventHub;
class EventStates;
@ -419,7 +417,7 @@ class PresShell final : public nsStubDocumentObserver,
* 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
@ -429,7 +427,7 @@ class PresShell final : public nsStubDocumentObserver,
* the specified direction.
*/
nsIScrollableFrame* GetScrollableFrameToScroll(
ScrollableDirection aDirection);
layers::ScrollDirections aDirections);
/**
* Returns the page sequence frame associated with the frame hierarchy.

View File

@ -1390,7 +1390,7 @@ ScrollableLayerGuid::ViewID nsLayoutUtils::ScrollIdForRootScrollFrame(
// 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)) {
@ -1398,14 +1398,12 @@ nsIScrollableFrame* nsLayoutUtils::GetNearestScrollableFrameForDirection(
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;
}

View File

@ -23,6 +23,7 @@
#include "mozilla/layout/FrameChildList.h"
#include "mozilla/layers/ScrollableLayerGuid.h"
#include "mozilla/gfx/2D.h"
#include "gfx2DGlue.h"
#include "gfxPoint.h"
#include "nsBoundingMetrics.h"
@ -32,6 +33,7 @@
#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.
@ -108,6 +110,7 @@ struct ScrollMetadata;
class Image;
class StackingContextHelper;
class Layer;
} // namespace layers
} // namespace mozilla
@ -118,8 +121,6 @@ enum class DrawStringFlags {
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(DrawStringFlags)
enum class ScrollableDirection { Horizontal, Vertical, Either };
namespace mozilla {
class RectCallback {
@ -531,7 +532,7 @@ class nsLayoutUtils {
* @return the nearest scrollable frame or nullptr if not found
*/
static nsIScrollableFrame* GetNearestScrollableFrameForDirection(
nsIFrame* aFrame, ScrollableDirection aDirection);
nsIFrame* aFrame, mozilla::layers::ScrollDirections aDirections);
enum {
/**