JS - make window.pageYOffset/pageXOffset/scrollX/scrollY double

This commit is contained in:
janekptacijarabaci 2017-08-10 18:01:49 +02:00 • committed by Roy Tam
commit 49ffafc979
16 changed files with 133 additions and 55 deletions

View file

@ -6187,7 +6187,7 @@ nsGlobalWindow::GetScrollMaxY(ErrorResult& aError)
FORWARD_TO_OUTER_OR_THROW(GetScrollBoundaryOuter, (eSideBottom), aError, 0);
}
CSSIntPoint
CSSPoint
nsGlobalWindow::GetScrollXY(bool aDoFlush)
{
MOZ_ASSERT(IsOuterWindow());
@ -6211,30 +6211,30 @@ nsGlobalWindow::GetScrollXY(bool aDoFlush)
return GetScrollXY(true);
}
return sf->GetScrollPositionCSSPixels();
return CSSPoint::FromAppUnits(scrollPos);
}
int32_t
double
nsGlobalWindow::GetScrollXOuter()
{
MOZ_RELEASE_ASSERT(IsOuterWindow());
return GetScrollXY(false).x;
}
int32_t
double
nsGlobalWindow::GetScrollX(ErrorResult& aError)
{
FORWARD_TO_OUTER_OR_THROW(GetScrollXOuter, (), aError, 0);
}
int32_t
double
nsGlobalWindow::GetScrollYOuter()
{
MOZ_RELEASE_ASSERT(IsOuterWindow());
return GetScrollXY(false).y;
}
int32_t
double
nsGlobalWindow::GetScrollY(ErrorResult& aError)
{
FORWARD_TO_OUTER_OR_THROW(GetScrollYOuter, (), aError, 0);

View file

@ -1050,15 +1050,15 @@ public:
void SetInnerHeight(JSContext* aCx, JS::Handle<JS::Value> aValue,
mozilla::dom::CallerType aCallerType,
mozilla::ErrorResult& aError);
int32_t GetScrollXOuter();
int32_t GetScrollX(mozilla::ErrorResult& aError);
int32_t GetPageXOffset(mozilla::ErrorResult& aError)
double GetScrollXOuter();
double GetScrollX(mozilla::ErrorResult& aError);
double GetPageXOffset(mozilla::ErrorResult& aError)
{
return GetScrollX(aError);
}
int32_t GetScrollYOuter();
int32_t GetScrollY(mozilla::ErrorResult& aError);
int32_t GetPageYOffset(mozilla::ErrorResult& aError)
double GetScrollYOuter();
double GetScrollY(mozilla::ErrorResult& aError);
double GetPageYOffset(mozilla::ErrorResult& aError)
{
return GetScrollY(aError);
}
@ -1579,7 +1579,7 @@ public:
// If aDoFlush is true, we'll flush our own layout; otherwise we'll try to
// just flush our parent and only flush ourselves if we think we need to.
// Outer windows only.
mozilla::CSSIntPoint GetScrollXY(bool aDoFlush);
mozilla::CSSPoint GetScrollXY(bool aDoFlush);
int32_t GetScrollBoundaryOuter(mozilla::Side aSide);

View file

@ -28,10 +28,10 @@ function subtest(winProp, elemProp, win, correctElement, elemToSet, otherElem1,
win.scrollTo(50, 50);
elemToSet[elemProp] = 100;
if (elemToSet == correctElement) {
is(win[winProp], 100, "Setting " + elemToSet.name + "." + elemProp + " should scroll");
is(Math.round(win[winProp]), 100, "Setting " + elemToSet.name + "." + elemProp + " should scroll");
is(elemToSet[elemProp], 100, "Reading back " + elemToSet.name + "." + elemProp + " after scrolling");
} else {
is(win[winProp], 50, "Setting " + elemToSet.name + "." + elemProp + " should not scroll");
is(Math.round(win[winProp]), 50, "Setting " + elemToSet.name + "." + elemProp + " should not scroll");
is(elemToSet[elemProp], 0, "Reading back " + elemToSet.name + "." + elemProp + " after not scrolling");
}
if (otherElem1 == correctElement) {

View file

@ -16,8 +16,8 @@ function runTest() {
iframe.addEventListener("mozbrowserscroll", function(e) {
ok(true, "got mozbrowserscroll event.");
ok(e.detail, "event.detail is not null.");
ok(e.detail.top === 4000, "top position is correct.");
ok(e.detail.left === 4000, "left position is correct.");
ok(Math.round(e.detail.top) == 4000, "top position is correct.");
ok(Math.round(e.detail.left) == 4000, "left position is correct.");
SimpleTest.finish();
});

View file

@ -31,13 +31,13 @@
function checkGetScrollXYState(flush, vals, testName) {
let scrollX = {}, scrollY = {};
domWindowUtils.getScrollXY(flush, scrollX, scrollY);
is(scrollX.value, vals[0], "getScrollXY x for test: " + testName);
is(scrollY.value, vals[1], "getScrollXY y for test: " + testName);
is(Math.round(scrollX.value), vals[0], "getScrollXY x for test: " + testName);
is(Math.round(scrollY.value), vals[1], "getScrollXY y for test: " + testName);
}
function checkWindowScrollState(vals, testName) {
is(cwindow.scrollX, vals[0], "scrollX for test: " + testName);
is(cwindow.scrollY, vals[1], "scrollY for test: " + testName);
is(Math.round(cwindow.scrollX), vals[0], "scrollX for test: " + testName);
is(Math.round(cwindow.scrollY), vals[1], "scrollY for test: " + testName);
}
// Check initial state (0, 0)
@ -67,8 +67,8 @@
let scrollX = {}, scrollY = {};
domWindowUtils.getScrollXY(false, scrollX, scrollY);
is(scrollX.value, 0, "scrollX is zero for display:none iframe");
is(scrollY.value, 0, "scrollY is zero for display:none iframe");
is(Math.round(scrollX.value), 0, "scrollX is zero for display:none iframe");
is(Math.round(scrollY.value), 0, "scrollY is zero for display:none iframe");
}
SimpleTest.waitForExplicitFinish();

View file

@ -182,14 +182,10 @@ partial interface Window {
[ChromeOnly] void mozScrollSnap();
// The four properties below are double per spec at the moment, but whether
// that will continue is unclear.
//[Replaceable, Throws] readonly attribute double scrollX;
//[Replaceable, Throws] readonly attribute double pageXOffset;
//[Replaceable, Throws] readonly attribute double scrollY;
//[Replaceable, Throws] readonly attribute double pageYOffset;
[Replaceable, Throws] readonly attribute long scrollX;
[Replaceable, Throws] readonly attribute long pageXOffset;
[Replaceable, Throws] readonly attribute long scrollY;
[Replaceable, Throws] readonly attribute long pageYOffset;
[Replaceable, Throws] readonly attribute double scrollX;
[Throws] readonly attribute double pageXOffset;
[Replaceable, Throws] readonly attribute double scrollY;
[Throws] readonly attribute double pageYOffset;
// client
// These are writable because we allow chrome to write them. And they need