зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1453425 - Use ScrollByCSSPixels in relative scrolling DOM API's. r=botond
This commit changes `Window::ScrollBy` and `Element::ScrollBy` to use ScrollByCSSPixels in preparation for marking ScrollByCSSPixels as a relative scroll API. Differential Revision: https://phabricator.services.mozilla.com/D8233 --HG-- extra : rebase_source : fa82acc12395569bd332573718f8a8013ac20b60 extra : histedit_source : 7ac061e65a2522051ed73f3ba6349d5ea696e15f
This commit is contained in:
Родитель
accd024b8f
Коммит
d4c042f28a
|
@ -888,10 +888,10 @@ Element::ScrollBy(double aXScrollDif, double aYScrollDif)
|
|||
{
|
||||
nsIScrollableFrame *sf = GetScrollFrame();
|
||||
if (sf) {
|
||||
CSSIntPoint scrollPos = sf->GetScrollPositionCSSPixels();
|
||||
scrollPos += CSSIntPoint::Truncate(mozilla::ToZeroIfNonfinite(aXScrollDif),
|
||||
mozilla::ToZeroIfNonfinite(aYScrollDif));
|
||||
Scroll(scrollPos, ScrollOptions());
|
||||
ScrollToOptions options;
|
||||
options.mLeft.Construct(aXScrollDif);
|
||||
options.mTop.Construct(aYScrollDif);
|
||||
ScrollBy(options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -900,14 +900,25 @@ Element::ScrollBy(const ScrollToOptions& aOptions)
|
|||
{
|
||||
nsIScrollableFrame *sf = GetScrollFrame();
|
||||
if (sf) {
|
||||
CSSIntPoint scrollPos = sf->GetScrollPositionCSSPixels();
|
||||
CSSIntPoint scrollDelta;
|
||||
if (aOptions.mLeft.WasPassed()) {
|
||||
scrollPos.x += mozilla::ToZeroIfNonfinite(aOptions.mLeft.Value());
|
||||
scrollDelta.x = mozilla::ToZeroIfNonfinite(aOptions.mLeft.Value());
|
||||
}
|
||||
if (aOptions.mTop.WasPassed()) {
|
||||
scrollPos.y += mozilla::ToZeroIfNonfinite(aOptions.mTop.Value());
|
||||
scrollDelta.y = mozilla::ToZeroIfNonfinite(aOptions.mTop.Value());
|
||||
}
|
||||
Scroll(scrollPos, aOptions);
|
||||
|
||||
nsIScrollableFrame::ScrollMode scrollMode = nsIScrollableFrame::INSTANT;
|
||||
if (aOptions.mBehavior == ScrollBehavior::Smooth) {
|
||||
scrollMode = nsIScrollableFrame::SMOOTH_MSD;
|
||||
} else if (aOptions.mBehavior == ScrollBehavior::Auto) {
|
||||
ScrollStyles styles = sf->GetScrollStyles();
|
||||
if (styles.mScrollBehavior == NS_STYLE_SCROLL_BEHAVIOR_SMOOTH) {
|
||||
scrollMode = nsIScrollableFrame::SMOOTH_MSD;
|
||||
}
|
||||
}
|
||||
|
||||
sf->ScrollByCSSPixels(scrollDelta, scrollMode, nsGkAtoms::relative);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3942,13 +3942,13 @@ nsGlobalWindowInner::ScrollBy(double aXScrollDif, double aYScrollDif)
|
|||
nsIScrollableFrame *sf = GetScrollFrame();
|
||||
|
||||
if (sf) {
|
||||
// Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast.
|
||||
auto scrollDif = CSSIntPoint::Truncate(mozilla::ToZeroIfNonfinite(aXScrollDif),
|
||||
mozilla::ToZeroIfNonfinite(aYScrollDif));
|
||||
// It seems like it would make more sense for ScrollBy to use
|
||||
// SMOOTH mode, but tests seem to depend on the synchronous behaviour.
|
||||
// Perhaps Web content does too.
|
||||
ScrollTo(sf->GetScrollPositionCSSPixels() + scrollDif, ScrollOptions());
|
||||
ScrollToOptions options;
|
||||
options.mLeft.Construct(aXScrollDif);
|
||||
options.mTop.Construct(aYScrollDif);
|
||||
ScrollBy(options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3959,15 +3959,25 @@ nsGlobalWindowInner::ScrollBy(const ScrollToOptions& aOptions)
|
|||
nsIScrollableFrame *sf = GetScrollFrame();
|
||||
|
||||
if (sf) {
|
||||
CSSIntPoint scrollPos = sf->GetScrollPositionCSSPixels();
|
||||
CSSIntPoint scrollDelta;
|
||||
if (aOptions.mLeft.WasPassed()) {
|
||||
scrollPos.x += mozilla::ToZeroIfNonfinite(aOptions.mLeft.Value());
|
||||
scrollDelta.x = mozilla::ToZeroIfNonfinite(aOptions.mLeft.Value());
|
||||
}
|
||||
if (aOptions.mTop.WasPassed()) {
|
||||
scrollPos.y += mozilla::ToZeroIfNonfinite(aOptions.mTop.Value());
|
||||
scrollDelta.y = mozilla::ToZeroIfNonfinite(aOptions.mTop.Value());
|
||||
}
|
||||
|
||||
ScrollTo(scrollPos, aOptions);
|
||||
nsIScrollableFrame::ScrollMode scrollMode = nsIScrollableFrame::INSTANT;
|
||||
if (aOptions.mBehavior == ScrollBehavior::Smooth) {
|
||||
scrollMode = nsIScrollableFrame::SMOOTH_MSD;
|
||||
} else if (aOptions.mBehavior == ScrollBehavior::Auto) {
|
||||
ScrollStyles styles = sf->GetScrollStyles();
|
||||
if (styles.mScrollBehavior == NS_STYLE_SCROLL_BEHAVIOR_SMOOTH) {
|
||||
scrollMode = nsIScrollableFrame::SMOOTH_MSD;
|
||||
}
|
||||
}
|
||||
|
||||
sf->ScrollByCSSPixels(scrollDelta, scrollMode, nsGkAtoms::relative);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1525,7 +1525,7 @@ ScrollFrameHelper::ThumbMoved(nsScrollbarFrame* aScrollbar,
|
|||
return;
|
||||
}
|
||||
|
||||
ScrollTo(dest, nsIScrollableFrame::INSTANT, &allowedRange);
|
||||
ScrollTo(dest, nsIScrollableFrame::INSTANT, nsGkAtoms::other, &allowedRange);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2293,9 +2293,25 @@ ScrollFrameHelper::HasBgAttachmentLocal() const
|
|||
return bg->HasLocalBackground();
|
||||
}
|
||||
|
||||
void
|
||||
ScrollFrameHelper::ScrollTo(nsPoint aScrollPosition,
|
||||
nsIScrollableFrame::ScrollMode aMode,
|
||||
nsAtom* aOrigin,
|
||||
const nsRect* aRange,
|
||||
nsIScrollbarMediator::ScrollSnapMode aSnap)
|
||||
{
|
||||
if (aOrigin == nullptr) {
|
||||
aOrigin = nsGkAtoms::other;
|
||||
}
|
||||
ScrollToWithOrigin(aScrollPosition, aMode,
|
||||
aOrigin, aRange,
|
||||
aSnap);
|
||||
}
|
||||
|
||||
void
|
||||
ScrollFrameHelper::ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
|
||||
nsIScrollableFrame::ScrollMode aMode)
|
||||
nsIScrollableFrame::ScrollMode aMode,
|
||||
nsAtom* aOrigin)
|
||||
{
|
||||
nsPoint current = GetScrollPosition();
|
||||
CSSIntPoint currentCSSPixels = GetScrollPositionCSSPixels();
|
||||
|
@ -2315,7 +2331,10 @@ ScrollFrameHelper::ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
|
|||
range.y = pt.y;
|
||||
range.height = 0;
|
||||
}
|
||||
ScrollTo(pt, aMode, &range);
|
||||
if (aOrigin == nullptr) {
|
||||
aOrigin = nsGkAtoms::other;
|
||||
}
|
||||
ScrollTo(pt, aMode, aOrigin, &range);
|
||||
// 'this' might be destroyed here
|
||||
}
|
||||
|
||||
|
@ -4229,7 +4248,7 @@ ScrollFrameHelper::ScrollBy(nsIntPoint aDelta,
|
|||
if (aSnap == nsIScrollableFrame::ENABLE_SNAP) {
|
||||
GetSnapPointForDestination(aUnit, mDestination, pos);
|
||||
}
|
||||
ScrollTo(pos, aMode);
|
||||
ScrollTo(pos, aMode, nsGkAtoms::other);
|
||||
// 'this' might be destroyed here
|
||||
if (aOverflow) {
|
||||
*aOverflow = nsIntPoint(0, 0);
|
||||
|
@ -4294,6 +4313,36 @@ ScrollFrameHelper::ScrollBy(nsIntPoint aDelta,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ScrollFrameHelper::ScrollByCSSPixels(const CSSIntPoint& aDelta,
|
||||
nsIScrollableFrame::ScrollMode aMode,
|
||||
nsAtom* aOrigin)
|
||||
{
|
||||
nsPoint current = GetScrollPosition();
|
||||
nsPoint pt = current + CSSPoint::ToAppUnits(aDelta);
|
||||
nscoord halfPixel = nsPresContext::CSSPixelsToAppUnits(0.5f);
|
||||
nsRect range(pt.x - halfPixel, pt.y - halfPixel, 2*halfPixel - 1, 2*halfPixel - 1);
|
||||
// XXX I don't think the following blocks are needed anymore, now that
|
||||
// ScrollToImpl simply tries to scroll an integer number of layer
|
||||
// pixels from the current position
|
||||
if (aDelta.x == 0.0f) {
|
||||
pt.x = current.x;
|
||||
range.x = pt.x;
|
||||
range.width = 0;
|
||||
}
|
||||
if (aDelta.y == 0.0f) {
|
||||
pt.y = current.y;
|
||||
range.y = pt.y;
|
||||
range.height = 0;
|
||||
}
|
||||
if (aOrigin == nullptr) {
|
||||
aOrigin = nsGkAtoms::other;
|
||||
}
|
||||
ScrollToWithOrigin(pt, aMode, aOrigin, &range,
|
||||
nsIScrollbarMediator::DISABLE_SNAP);
|
||||
// 'this' might be destroyed here
|
||||
}
|
||||
|
||||
void
|
||||
ScrollFrameHelper::ScrollSnap(nsIScrollableFrame::ScrollMode aMode)
|
||||
{
|
||||
|
@ -4321,7 +4370,7 @@ ScrollFrameHelper::ScrollSnap(const nsPoint &aDestination,
|
|||
if (GetSnapPointForDestination(nsIScrollableFrame::DEVICE_PIXELS,
|
||||
pos,
|
||||
snapDestination)) {
|
||||
ScrollTo(snapDestination, aMode);
|
||||
ScrollTo(snapDestination, aMode, nsGkAtoms::other);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6620,7 +6669,7 @@ ScrollFrameHelper::DragScroll(WidgetEvent* aEvent)
|
|||
}
|
||||
|
||||
if (offset.x || offset.y) {
|
||||
ScrollTo(GetScrollPosition() + offset, nsIScrollableFrame::NORMAL);
|
||||
ScrollTo(GetScrollPosition() + offset, nsIScrollableFrame::NORMAL, nsGkAtoms::other);
|
||||
}
|
||||
|
||||
return willScroll;
|
||||
|
|
|
@ -237,18 +237,17 @@ public:
|
|||
* This is a closed-ended range --- aRange.XMost()/aRange.YMost() are allowed.
|
||||
*/
|
||||
void ScrollTo(nsPoint aScrollPosition, nsIScrollableFrame::ScrollMode aMode,
|
||||
nsAtom* aOrigin = nullptr,
|
||||
const nsRect* aRange = nullptr,
|
||||
nsIScrollbarMediator::ScrollSnapMode aSnap
|
||||
= nsIScrollbarMediator::DISABLE_SNAP) {
|
||||
ScrollToWithOrigin(aScrollPosition, aMode, nsGkAtoms::other, aRange,
|
||||
aSnap);
|
||||
}
|
||||
= nsIScrollbarMediator::DISABLE_SNAP);
|
||||
/**
|
||||
* @note This method might destroy the frame, pres shell and other objects.
|
||||
*/
|
||||
void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
|
||||
nsIScrollableFrame::ScrollMode aMode
|
||||
= nsIScrollableFrame::INSTANT);
|
||||
= nsIScrollableFrame::INSTANT,
|
||||
nsAtom* aOrigin = nullptr);
|
||||
/**
|
||||
* @note This method might destroy the frame, pres shell and other objects.
|
||||
*/
|
||||
|
@ -270,6 +269,10 @@ public:
|
|||
nsIScrollableFrame::ScrollMomentum aMomentum = nsIScrollableFrame::NOT_MOMENTUM,
|
||||
nsIScrollbarMediator::ScrollSnapMode aSnap
|
||||
= nsIScrollbarMediator::DISABLE_SNAP);
|
||||
void ScrollByCSSPixels(const CSSIntPoint& aDelta,
|
||||
nsIScrollableFrame::ScrollMode aMode
|
||||
= nsIScrollableFrame::INSTANT,
|
||||
nsAtom* aOrigin = nullptr);
|
||||
/**
|
||||
* @note This method might destroy the frame, pres shell and other objects.
|
||||
*/
|
||||
|
@ -877,15 +880,16 @@ public:
|
|||
nsIScrollbarMediator::ScrollSnapMode aSnap
|
||||
= nsIScrollbarMediator::DISABLE_SNAP)
|
||||
override {
|
||||
mHelper.ScrollTo(aScrollPosition, aMode, aRange, aSnap);
|
||||
mHelper.ScrollTo(aScrollPosition, aMode, nsGkAtoms::other, aRange, aSnap);
|
||||
}
|
||||
/**
|
||||
* @note This method might destroy the frame, pres shell and other objects.
|
||||
*/
|
||||
virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
|
||||
nsIScrollableFrame::ScrollMode aMode
|
||||
= nsIScrollableFrame::INSTANT) override {
|
||||
mHelper.ScrollToCSSPixels(aScrollPosition, aMode);
|
||||
= nsIScrollableFrame::INSTANT,
|
||||
nsAtom* aOrigin = nullptr) override {
|
||||
mHelper.ScrollToCSSPixels(aScrollPosition, aMode, aOrigin);
|
||||
}
|
||||
virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
|
||||
nsAtom* aOrigin = nullptr) override {
|
||||
|
@ -908,6 +912,12 @@ public:
|
|||
override {
|
||||
mHelper.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin, aMomentum, aSnap);
|
||||
}
|
||||
virtual void ScrollByCSSPixels(const CSSIntPoint& aDelta,
|
||||
nsIScrollableFrame::ScrollMode aMode
|
||||
= nsIScrollableFrame::INSTANT,
|
||||
nsAtom* aOrigin = nullptr) override {
|
||||
mHelper.ScrollByCSSPixels(aDelta, aMode, aOrigin);
|
||||
}
|
||||
virtual void ScrollSnap() override {
|
||||
mHelper.ScrollSnap();
|
||||
}
|
||||
|
@ -1331,15 +1341,16 @@ public:
|
|||
const nsRect* aRange = nullptr,
|
||||
ScrollSnapMode aSnap = nsIScrollbarMediator::DISABLE_SNAP)
|
||||
override {
|
||||
mHelper.ScrollTo(aScrollPosition, aMode, aRange, aSnap);
|
||||
mHelper.ScrollTo(aScrollPosition, aMode, nsGkAtoms::other, aRange, aSnap);
|
||||
}
|
||||
/**
|
||||
* @note This method might destroy the frame, pres shell and other objects.
|
||||
*/
|
||||
virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
|
||||
nsIScrollableFrame::ScrollMode aMode
|
||||
= nsIScrollableFrame::INSTANT) override {
|
||||
mHelper.ScrollToCSSPixels(aScrollPosition, aMode);
|
||||
= nsIScrollableFrame::INSTANT,
|
||||
nsAtom* aOrigin = nullptr) override {
|
||||
mHelper.ScrollToCSSPixels(aScrollPosition, aMode, aOrigin);
|
||||
}
|
||||
virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
|
||||
nsAtom* aOrigin = nullptr) override {
|
||||
|
@ -1359,6 +1370,12 @@ public:
|
|||
override {
|
||||
mHelper.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin, aMomentum, aSnap);
|
||||
}
|
||||
virtual void ScrollByCSSPixels(const CSSIntPoint& aDelta,
|
||||
nsIScrollableFrame::ScrollMode aMode
|
||||
= nsIScrollableFrame::INSTANT,
|
||||
nsAtom* aOrigin = nullptr) override {
|
||||
mHelper.ScrollByCSSPixels(aDelta, aMode, aOrigin);
|
||||
}
|
||||
virtual void ScrollSnap() override {
|
||||
mHelper.ScrollSnap();
|
||||
}
|
||||
|
|
|
@ -241,7 +241,8 @@ public:
|
|||
*/
|
||||
virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
|
||||
nsIScrollableFrame::ScrollMode aMode
|
||||
= nsIScrollableFrame::INSTANT) = 0;
|
||||
= nsIScrollableFrame::INSTANT,
|
||||
nsAtom* aOrigin = nullptr) = 0;
|
||||
/**
|
||||
* @note This method might destroy the frame, pres shell and other objects.
|
||||
* Scrolls to a particular position in float CSS pixels.
|
||||
|
@ -279,6 +280,11 @@ public:
|
|||
nsIScrollbarMediator::ScrollSnapMode aSnap
|
||||
= nsIScrollbarMediator::DISABLE_SNAP) = 0;
|
||||
|
||||
virtual void ScrollByCSSPixels(const CSSIntPoint& aDelta,
|
||||
nsIScrollableFrame::ScrollMode aMode
|
||||
= nsIScrollableFrame::INSTANT,
|
||||
nsAtom* aOrigin = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* Perform scroll snapping, possibly resulting in a smooth scroll to
|
||||
* maintain the scroll snap position constraints. Velocity sampled from
|
||||
|
|
Загрузка…
Ссылка в новой задаче