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
Родитель 7587904cce
Коммит ecf1650979
4 изменённых файлов: 32 добавлений и 14 удалений

Просмотреть файл

@ -7129,17 +7129,23 @@ nsGlobalWindow::GetTopWindowRoot()
}
void
nsGlobalWindow::Scroll(int32_t aXScroll, int32_t aYScroll,
nsGlobalWindow::Scroll(double aXScroll, double aYScroll,
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
nsGlobalWindow::ScrollTo(int32_t aXScroll, int32_t aYScroll,
nsGlobalWindow::ScrollTo(double aXScroll, double aYScroll,
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
@ -7196,19 +7202,20 @@ nsGlobalWindow::ScrollBy(int32_t aXScrollDif, int32_t aYScrollDif)
}
void
nsGlobalWindow::ScrollBy(int32_t aXScrollDif, int32_t aYScrollDif,
nsGlobalWindow::ScrollBy(double aXScrollDif, double aYScrollDif,
const ScrollOptions& aOptions)
{
FlushPendingNotifications(Flush_Layout);
nsIScrollableFrame *sf = GetScrollFrame();
if (sf) {
CSSIntPoint scrollPos =
sf->GetScrollPositionCSSPixels() + CSSIntPoint(aXScrollDif, aYScrollDif);
// Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast.
CSSIntPoint scrollDif(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(scrollPos, aOptions);
ScrollTo(sf->GetScrollPositionCSSPixels() + scrollDif, aOptions);
}
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -187,6 +187,17 @@ IsNegativeZero(T aValue)
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.
*