зеркало из https://github.com/mozilla/gecko-dev.git
Bug 611797 part 2: Shift shared code from VectorImage/RasterImage to Image superclass, and add impl for VectorImage::ShouldAnimate. r+a=joe
This commit is contained in:
Родитель
270fe09e87
Коммит
b34bc7fce4
|
@ -43,6 +43,7 @@ namespace imagelib {
|
|||
// Constructor
|
||||
Image::Image(imgStatusTracker* aStatusTracker) :
|
||||
mAnimationConsumers(0),
|
||||
mAnimationMode(kNormalAnimMode),
|
||||
mInitialized(PR_FALSE),
|
||||
mAnimating(PR_FALSE),
|
||||
mError(PR_FALSE)
|
||||
|
@ -125,6 +126,40 @@ Image::DecrementAnimationConsumers()
|
|||
EvaluateAnimation();
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* attribute unsigned short animationMode; */
|
||||
NS_IMETHODIMP
|
||||
Image::GetAnimationMode(PRUint16* aAnimationMode)
|
||||
{
|
||||
if (mError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aAnimationMode);
|
||||
|
||||
*aAnimationMode = mAnimationMode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* attribute unsigned short animationMode; */
|
||||
NS_IMETHODIMP
|
||||
Image::SetAnimationMode(PRUint16 aAnimationMode)
|
||||
{
|
||||
if (mError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ASSERTION(aAnimationMode == kNormalAnimMode ||
|
||||
aAnimationMode == kDontAnimMode ||
|
||||
aAnimationMode == kLoopOnceAnimMode,
|
||||
"Wrong Animation Mode is being set!");
|
||||
|
||||
mAnimationMode = aAnimationMode;
|
||||
|
||||
EvaluateAnimation();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
Image::EvaluateAnimation()
|
||||
{
|
||||
|
|
|
@ -48,6 +48,10 @@ namespace imagelib {
|
|||
class Image : public imgIContainer
|
||||
{
|
||||
public:
|
||||
// From NS_DECL_IMGICONTAINER:
|
||||
NS_SCRIPTABLE NS_IMETHOD GetAnimationMode(PRUint16 *aAnimationMode);
|
||||
NS_SCRIPTABLE NS_IMETHOD SetAnimationMode(PRUint16 aAnimationMode);
|
||||
|
||||
imgStatusTracker& GetStatusTracker() { return *mStatusTracker; }
|
||||
|
||||
/**
|
||||
|
@ -134,15 +138,18 @@ protected:
|
|||
// Member data shared by all implementations of this abstract class
|
||||
nsAutoPtr<imgStatusTracker> mStatusTracker;
|
||||
PRUint32 mAnimationConsumers;
|
||||
PRPackedBool mInitialized; // Have we been initalized?
|
||||
PRPackedBool mAnimating;
|
||||
PRPackedBool mError; // Error handling
|
||||
PRUint16 mAnimationMode; // Enum values in imgIContainer
|
||||
PRPackedBool mInitialized:1; // Have we been initalized?
|
||||
PRPackedBool mAnimating:1; // Are we currently animating?
|
||||
PRPackedBool mError:1; // Error handling
|
||||
|
||||
/**
|
||||
* Extended by child classes, if they have additional
|
||||
* conditions for being able to animate
|
||||
*/
|
||||
virtual PRBool ShouldAnimate() { return mAnimationConsumers > 0; }
|
||||
virtual PRBool ShouldAnimate() {
|
||||
return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace imagelib
|
||||
|
|
|
@ -179,7 +179,6 @@ RasterImage::RasterImage(imgStatusTracker* aStatusTracker) :
|
|||
Image(aStatusTracker), // invoke superclass's constructor
|
||||
mSize(0,0),
|
||||
mAnim(nsnull),
|
||||
mAnimationMode(kNormalAnimMode),
|
||||
mLoopCount(-1),
|
||||
mObserver(nsnull),
|
||||
mLockCount(0),
|
||||
|
@ -1051,40 +1050,6 @@ RasterImage::DecodingComplete()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* attribute unsigned short animationMode; */
|
||||
NS_IMETHODIMP
|
||||
RasterImage::GetAnimationMode(PRUint16 *aAnimationMode)
|
||||
{
|
||||
if (mError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aAnimationMode);
|
||||
|
||||
*aAnimationMode = mAnimationMode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* attribute unsigned short animationMode; */
|
||||
NS_IMETHODIMP
|
||||
RasterImage::SetAnimationMode(PRUint16 aAnimationMode)
|
||||
{
|
||||
if (mError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ASSERTION(aAnimationMode == kNormalAnimMode ||
|
||||
aAnimationMode == kDontAnimMode ||
|
||||
aAnimationMode == kLoopOnceAnimMode,
|
||||
"Wrong Animation Mode is being set!");
|
||||
|
||||
mAnimationMode = aAnimationMode;
|
||||
|
||||
EvaluateAnimation();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* void StartAnimation () */
|
||||
nsresult
|
||||
|
@ -2707,7 +2672,7 @@ PRBool
|
|||
RasterImage::ShouldAnimate()
|
||||
{
|
||||
return Image::ShouldAnimate() && mFrames.Length() >= 2 &&
|
||||
mAnimationMode != kDontAnimMode && !mAnimationFinished;
|
||||
!mAnimationFinished;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
|
|
|
@ -164,7 +164,7 @@ public:
|
|||
NS_DECL_IMGICONTAINERDEBUG
|
||||
#endif
|
||||
|
||||
// BEGIN NS_DECL_IMGICONTAINER
|
||||
// BEGIN NS_DECL_IMGICONTAINER (minus GetAnimationMode/SetAnimationMode)
|
||||
// ** Don't edit this chunk except to mirror changes in imgIContainer.idl **
|
||||
NS_SCRIPTABLE NS_IMETHOD GetWidth(PRInt32 *aWidth);
|
||||
NS_SCRIPTABLE NS_IMETHOD GetHeight(PRInt32 *aHeight);
|
||||
|
@ -179,8 +179,6 @@ public:
|
|||
NS_SCRIPTABLE NS_IMETHOD RequestDecode(void);
|
||||
NS_SCRIPTABLE NS_IMETHOD LockImage(void);
|
||||
NS_SCRIPTABLE NS_IMETHOD UnlockImage(void);
|
||||
NS_SCRIPTABLE NS_IMETHOD GetAnimationMode(PRUint16 *aAnimationMode);
|
||||
NS_SCRIPTABLE NS_IMETHOD SetAnimationMode(PRUint16 aAnimationMode);
|
||||
NS_SCRIPTABLE NS_IMETHOD ResetAnimation(void);
|
||||
// END NS_DECL_IMGICONTAINER
|
||||
|
||||
|
@ -468,9 +466,6 @@ private: // data
|
|||
// we maybe decoding on draw).
|
||||
RasterImage::Anim* mAnim;
|
||||
|
||||
//! See imgIContainer for mode constants
|
||||
PRUint16 mAnimationMode;
|
||||
|
||||
//! # loops remaining before animation stops (-1 no stop)
|
||||
PRInt32 mLoopCount;
|
||||
|
||||
|
|
|
@ -210,7 +210,6 @@ VectorImage::VectorImage(imgStatusTracker* aStatusTracker) :
|
|||
Image(aStatusTracker), // invoke superclass's constructor
|
||||
mRestrictedRegion(0, 0, 0, 0),
|
||||
mLastRenderedSize(0, 0),
|
||||
mAnimationMode(kNormalAnimMode),
|
||||
mIsInitialized(PR_FALSE),
|
||||
mIsFullyLoaded(PR_FALSE),
|
||||
mHaveAnimations(PR_FALSE),
|
||||
|
@ -275,14 +274,9 @@ VectorImage::StartAnimation()
|
|||
if (mError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (mAnimationMode == kDontAnimMode ||
|
||||
!mIsFullyLoaded || !mHaveAnimations) {
|
||||
// Animation disabled, or helper-document not finished or lacks animations.
|
||||
return NS_OK;
|
||||
}
|
||||
NS_ABORT_IF_FALSE(ShouldAnimate(), "Should not animate!");
|
||||
|
||||
mSVGDocumentWrapper->StartAnimation();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -292,15 +286,19 @@ VectorImage::StopAnimation()
|
|||
if (mError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!mIsFullyLoaded || !mHaveAnimations) {
|
||||
return NS_OK;
|
||||
}
|
||||
NS_ABORT_IF_FALSE(mIsFullyLoaded && mHaveAnimations,
|
||||
"Should not have been animating!");
|
||||
|
||||
mSVGDocumentWrapper->StopAnimation();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
VectorImage::ShouldAnimate()
|
||||
{
|
||||
return Image::ShouldAnimate() && mIsFullyLoaded && mHaveAnimations;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// imgIContainer methods
|
||||
|
||||
|
@ -592,46 +590,6 @@ VectorImage::UnlockImage()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* attribute unsigned short animationMode; */
|
||||
NS_IMETHODIMP
|
||||
VectorImage::GetAnimationMode(PRUint16* aAnimationMode)
|
||||
{
|
||||
if (mError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aAnimationMode);
|
||||
|
||||
*aAnimationMode = mAnimationMode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* attribute unsigned short animationMode; */
|
||||
NS_IMETHODIMP
|
||||
VectorImage::SetAnimationMode(PRUint16 aAnimationMode)
|
||||
{
|
||||
// NOTE: This is just a simpler form of RasterImage::SetAnimationMode.
|
||||
// (Simpler because SVG animations don't have a concept of "loop once" mode)
|
||||
if (mError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ASSERTION(aAnimationMode == kNormalAnimMode ||
|
||||
aAnimationMode == kDontAnimMode ||
|
||||
aAnimationMode == kLoopOnceAnimMode,
|
||||
"An unrecognized Animation Mode is being set!");
|
||||
|
||||
mAnimationMode = aAnimationMode;
|
||||
|
||||
if (mAnimationMode == kDontAnimMode) {
|
||||
StopAnimation();
|
||||
} else { // kNormalAnimMode or kLoopOnceAnimMode (treated the same here)
|
||||
StartAnimation();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* void resetAnimation (); */
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
|
||||
// BEGIN NS_DECL_IMGICONTAINER
|
||||
// BEGIN NS_DECL_IMGICONTAINER (minus GetAnimationMode/SetAnimationMode)
|
||||
// ** Don't edit this chunk except to mirror changes in imgIContainer.idl **
|
||||
NS_SCRIPTABLE NS_IMETHOD GetWidth(PRInt32 *aWidth);
|
||||
NS_SCRIPTABLE NS_IMETHOD GetHeight(PRInt32 *aHeight);
|
||||
|
@ -74,8 +74,6 @@ public:
|
|||
NS_SCRIPTABLE NS_IMETHOD RequestDecode(void);
|
||||
NS_SCRIPTABLE NS_IMETHOD LockImage(void);
|
||||
NS_SCRIPTABLE NS_IMETHOD UnlockImage(void);
|
||||
NS_SCRIPTABLE NS_IMETHOD GetAnimationMode(PRUint16 *aAnimationMode);
|
||||
NS_SCRIPTABLE NS_IMETHOD SetAnimationMode(PRUint16 aAnimationMode);
|
||||
NS_SCRIPTABLE NS_IMETHOD ResetAnimation(void);
|
||||
// END NS_DECL_IMGICONTAINER
|
||||
|
||||
|
@ -100,6 +98,7 @@ public:
|
|||
protected:
|
||||
virtual nsresult StartAnimation();
|
||||
virtual nsresult StopAnimation();
|
||||
virtual PRBool ShouldAnimate();
|
||||
|
||||
private:
|
||||
nsWeakPtr mObserver; //! imgIDecoderObserver
|
||||
|
@ -118,8 +117,6 @@ private:
|
|||
// mSVGDocumentWrapper as its
|
||||
// viewport-bounds.
|
||||
|
||||
PRUint16 mAnimationMode; // Are we allowed to animate?
|
||||
|
||||
PRPackedBool mIsInitialized:1; // Have we been initalized?
|
||||
PRPackedBool mIsFullyLoaded:1; // Has OnStopRequest been called?
|
||||
PRPackedBool mHaveAnimations:1; // Is our SVG content SMIL-animated?
|
||||
|
|
Загрузка…
Ссылка в новой задаче