From b13cf1150592f900fd83e9abb58b79365af2b108 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Thu, 11 May 2017 10:13:53 +0200 Subject: [PATCH] Fix clamping of scroll position in window.scrollBy For rightward and downward overflow the spec says: Let x be max(0, min(x, viewport scrolling area width - viewport width)). Let y be max(0, min(y, viewport scrolling area height - viewport height)). Previously, those operations were reversed, which created negative overflow even when the overflow direction was downward. This change ensures that Servo matches spec behavior. --- components/script/dom/window.rs | 4 +-- tests/wpt/mozilla/meta/MANIFEST.json | 10 +++++++ tests/wpt/mozilla/tests/mozilla/scrollBy.html | 26 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/wpt/mozilla/tests/mozilla/scrollBy.html diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 6b8857b81b1..a2af04ad1cc 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -1066,8 +1066,8 @@ impl Window { let content_size = e.upcast::().bounding_content_box_or_zero(); let content_height = content_size.size.height.to_f64_px(); let content_width = content_size.size.width.to_f64_px(); - (xfinite.max(0.0f64).min(content_width - width), - yfinite.max(0.0f64).min(content_height - height)) + (xfinite.min(content_width - width).max(0.0f64), + yfinite.min(content_height - height).max(0.0f64)) }, None => { (xfinite.max(0.0f64), yfinite.max(0.0f64)) diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 1b33db843e9..ffeefb946e7 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -19783,6 +19783,12 @@ {} ] ], + "mozilla/scrollBy.html": [ + [ + "/_mozilla/mozilla/scrollBy.html", + {} + ] + ], "mozilla/scrollTo.html": [ [ "/_mozilla/mozilla/scrollTo.html", @@ -31354,6 +31360,10 @@ "b247e3a0ba733c1a8b129ce2994b862d8ed3a423", "testharness" ], + "mozilla/scrollBy.html": [ + "0243d584bc615a73ea1667fc35f5d73b5165d19f", + "testharness" + ], "mozilla/scrollTo.html": [ "b9917be5fed364dbc46264f641f54f275b5c054a", "testharness" diff --git a/tests/wpt/mozilla/tests/mozilla/scrollBy.html b/tests/wpt/mozilla/tests/mozilla/scrollBy.html new file mode 100644 index 00000000000..24e6d108e24 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/scrollBy.html @@ -0,0 +1,26 @@ + + +Ensure that the window.scrollBy function affects scroll position as expected + + + + This is some link text. +
+ +