Bug 1062406 - Part 1 - Change x and y parameters of window.scroll* CSSOM-View DOM calls from double to unrestricted double. r=bz

- WebIDL updated so that x and y parameters of window.scroll, window.scrollTo,
  and window.ScrollBy are changed from "double" to "unrestricted double".
- Implemented mozilla::ToZeroIfNonfinite
- Updated nsGlobalWindow::Scroll, ScrollTo, and ScrollBy methods so that they
  replace non-finite numbers with 0.
This commit is contained in:
Kearwood (Kip) Gilbert 2014-09-09 12:02:00 +02:00
parent a2bdaaa971
commit 7d4f4b04ca
4 changed files with 32 additions and 14 deletions

View File

@ -7129,17 +7129,23 @@ nsGlobalWindow::GetTopWindowRoot()
} }
void void
nsGlobalWindow::Scroll(int32_t aXScroll, int32_t aYScroll, nsGlobalWindow::Scroll(double aXScroll, double aYScroll,
const ScrollOptions& aOptions) const ScrollOptions& aOptions)
{ {
ScrollTo(CSSIntPoint(aXScroll, aYScroll), aOptions); // Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast.
CSSIntPoint scrollPos(mozilla::ToZeroIfNonfinite(aXScroll),
mozilla::ToZeroIfNonfinite(aYScroll));
ScrollTo(scrollPos, aOptions);
} }
void void
nsGlobalWindow::ScrollTo(int32_t aXScroll, int32_t aYScroll, nsGlobalWindow::ScrollTo(double aXScroll, double aYScroll,
const ScrollOptions& aOptions) const ScrollOptions& aOptions)
{ {
ScrollTo(CSSIntPoint(aXScroll, aYScroll), aOptions); // Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast.
CSSIntPoint scrollPos(mozilla::ToZeroIfNonfinite(aXScroll),
mozilla::ToZeroIfNonfinite(aYScroll));
ScrollTo(scrollPos, aOptions);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -7196,19 +7202,20 @@ nsGlobalWindow::ScrollBy(int32_t aXScrollDif, int32_t aYScrollDif)
} }
void void
nsGlobalWindow::ScrollBy(int32_t aXScrollDif, int32_t aYScrollDif, nsGlobalWindow::ScrollBy(double aXScrollDif, double aYScrollDif,
const ScrollOptions& aOptions) const ScrollOptions& aOptions)
{ {
FlushPendingNotifications(Flush_Layout); FlushPendingNotifications(Flush_Layout);
nsIScrollableFrame *sf = GetScrollFrame(); nsIScrollableFrame *sf = GetScrollFrame();
if (sf) { if (sf) {
CSSIntPoint scrollPos = // Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast.
sf->GetScrollPositionCSSPixels() + CSSIntPoint(aXScrollDif, aYScrollDif); CSSIntPoint scrollDif(mozilla::ToZeroIfNonfinite(aXScrollDif),
mozilla::ToZeroIfNonfinite(aYScrollDif));
// It seems like it would make more sense for ScrollBy to use // It seems like it would make more sense for ScrollBy to use
// SMOOTH mode, but tests seem to depend on the synchronous behaviour. // SMOOTH mode, but tests seem to depend on the synchronous behaviour.
// Perhaps Web content does too. // Perhaps Web content does too.
ScrollTo(scrollPos, aOptions); ScrollTo(sf->GetScrollPositionCSSPixels() + scrollDif, aOptions);
} }
} }

View File

@ -897,11 +897,11 @@ public:
mozilla::ErrorResult& aError); mozilla::ErrorResult& aError);
void ResizeBy(int32_t aWidthDif, int32_t aHeightDif, void ResizeBy(int32_t aWidthDif, int32_t aHeightDif,
mozilla::ErrorResult& aError); mozilla::ErrorResult& aError);
void Scroll(int32_t aXScroll, int32_t aYScroll, void Scroll(double aXScroll, double aYScroll,
const mozilla::dom::ScrollOptions& aOptions); const mozilla::dom::ScrollOptions& aOptions);
void ScrollTo(int32_t aXScroll, int32_t aYScroll, void ScrollTo(double aXScroll, double aYScroll,
const mozilla::dom::ScrollOptions& aOptions); const mozilla::dom::ScrollOptions& aOptions);
void ScrollBy(int32_t aXScrollDif, int32_t aYScrollDif, void ScrollBy(double aXScrollDif, double aYScrollDif,
const mozilla::dom::ScrollOptions& aOptions); const mozilla::dom::ScrollOptions& aOptions);
void ScrollByLines(int32_t numLines, void ScrollByLines(int32_t numLines,
const mozilla::dom::ScrollOptions& aOptions); const mozilla::dom::ScrollOptions& aOptions);

View File

@ -179,9 +179,9 @@ partial interface Window {
//[Throws] readonly attribute double pageXOffset; //[Throws] readonly attribute double pageXOffset;
//[Throws] readonly attribute double scrollY; //[Throws] readonly attribute double scrollY;
//[Throws] readonly attribute double pageYOffset; //[Throws] readonly attribute double pageYOffset;
void scroll(double x, double y, optional ScrollOptions options); void scroll(unrestricted double x, unrestricted double y, optional ScrollOptions options);
void scrollTo(double x, double y, optional ScrollOptions options); void scrollTo(unrestricted double x, unrestricted double y, optional ScrollOptions options);
void scrollBy(double x, double y, optional ScrollOptions options); void scrollBy(unrestricted double x, unrestricted double y, optional ScrollOptions options);
[Replaceable, Throws] readonly attribute long scrollX; [Replaceable, Throws] readonly attribute long scrollX;
[Throws] readonly attribute long pageXOffset; [Throws] readonly attribute long pageXOffset;
[Replaceable, Throws] readonly attribute long scrollY; [Replaceable, Throws] readonly attribute long scrollY;

View File

@ -187,6 +187,17 @@ IsNegativeZero(T aValue)
return bits == Traits::kSignBit; return bits == Traits::kSignBit;
} }
/**
* Returns 0 if a float/double is NaN or infinite;
* otherwise, the float/double is returned.
*/
template<typename T>
static MOZ_ALWAYS_INLINE T
ToZeroIfNonfinite(T aValue)
{
return IsFinite(aValue) ? aValue : 0;
}
/** /**
* Returns the exponent portion of the float/double. * Returns the exponent portion of the float/double.
* *