From 5495bbbd030e841daff3f7bc2894ca37d3b74f3f Mon Sep 17 00:00:00 2001 From: Joe Drew Date: Fri, 17 May 2013 16:57:20 -0400 Subject: [PATCH] Bug 867758 - Add imgIContainer::SetAnimationStartTime, which lets us explicitly set the time animation starts (rather than using TimeStamp::Now()). r=seth --HG-- extra : rebase_source : 4660937d5eb06bf83b749826d2f13da29583e9e7 --- image/public/imgIContainer.idl | 15 ++++++++++++++- image/src/ImageWrapper.cpp | 6 ++++++ image/src/RasterImage.cpp | 15 ++++++++++++++- image/src/VectorImage.cpp | 6 ++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/image/public/imgIContainer.idl b/image/public/imgIContainer.idl index 2b50e4b6b6e..8cdac3facd4 100644 --- a/image/public/imgIContainer.idl +++ b/image/public/imgIContainer.idl @@ -57,7 +57,7 @@ native nsSize(nsSize); * * Internally, imgIContainer also manages animation of images. */ -[scriptable, builtinclass, uuid(4c04b27c-7a4b-4676-b04f-402ace3c3dca)] +[scriptable, builtinclass, uuid(b56906e9-830c-45f4-b572-8c71e7619dad)] interface imgIContainer : nsISupports { /** @@ -303,4 +303,17 @@ interface imgIContainer : nsISupports * animated), returns -1. */ [notxpcom] int32_t getFirstFrameDelay(); + + /* + * If this is an animated image that hasn't started animating already, this + * sets the animation's start time to the indicated time. + * + * This has no effect if the image isn't animated or it has started animating + * already; it also has no effect if the image format doesn't care about + * animation start time. + * + * In all cases, animation does not actually begin until startAnimation(), + * resetAnimation(), or requestRefresh() is called for the first time. + */ + [notxpcom] void setAnimationStartTime([const] in TimeStamp aTime); }; diff --git a/image/src/ImageWrapper.cpp b/image/src/ImageWrapper.cpp index 58abe90785a..cd929145a1e 100644 --- a/image/src/ImageWrapper.cpp +++ b/image/src/ImageWrapper.cpp @@ -285,5 +285,11 @@ ImageWrapper::GetFirstFrameDelay() return mInnerImage->GetFirstFrameDelay(); } +NS_IMETHODIMP_(void) +ImageWrapper::SetAnimationStartTime(const mozilla::TimeStamp& aTime) +{ + mInnerImage->SetAnimationStartTime(aTime); +} + } // namespace image } // namespace mozilla diff --git a/image/src/RasterImage.cpp b/image/src/RasterImage.cpp index 5151ee1cd78..6217f99ae19 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -1560,7 +1560,9 @@ RasterImage::StartAnimation() // We need to set the time that this initial frame was first displayed, as // this is used in AdvanceFrame(). - mAnim->currentAnimationFrameTime = TimeStamp::Now(); + if (mAnim->currentAnimationFrameTime.IsNull()) { + mAnim->currentAnimationFrameTime = TimeStamp::Now(); + } } return NS_OK; @@ -1619,6 +1621,17 @@ RasterImage::ResetAnimation() return NS_OK; } +//****************************************************************************** +// [notxpcom] void requestRefresh ([const] in TimeStamp aTime); +NS_IMETHODIMP_(void) +RasterImage::SetAnimationStartTime(const mozilla::TimeStamp& aTime) +{ + if (mError || mAnimating || !mAnim) + return; + + mAnim->currentAnimationFrameTime = aTime; +} + NS_IMETHODIMP_(float) RasterImage::GetFrameIndex(uint32_t aWhichFrame) { diff --git a/image/src/VectorImage.cpp b/image/src/VectorImage.cpp index e1850511d54..04305d8b061 100644 --- a/image/src/VectorImage.cpp +++ b/image/src/VectorImage.cpp @@ -438,6 +438,12 @@ VectorImage::ShouldAnimate() return ImageResource::ShouldAnimate() && mIsFullyLoaded && mHaveAnimations; } +NS_IMETHODIMP_(void) +VectorImage::SetAnimationStartTime(const mozilla::TimeStamp& aTime) +{ + // We don't care about animation start time. +} + //------------------------------------------------------------------------------ // imgIContainer methods