From 7dca09d0d13fcb88efa64fb8bb3c2e7a6f80c2c9 Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Wed, 14 Nov 2001 11:21:54 +0000 Subject: [PATCH] The PresContext must walk the content tree and find all the images and turn them back "on" for animation It must also walk it's own list that contains the background images Bug 2586 r=dcone sr=attinasi --- layout/base/nsPresContext.cpp | 78 +++++++++++++++++++++++++++++++ layout/base/src/nsPresContext.cpp | 78 +++++++++++++++++++++++++++++++ layout/base/src/nsPresContext.h | 2 + 3 files changed, 158 insertions(+) diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 3a688e0971d2..300029864285 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -70,6 +70,12 @@ #include "nsBidiPresUtils.h" #endif // IBMBIDI +// Needed for Start/Stop of Image Animation +#include "imgIContainer.h" +#include "nsIDOMHTMLImageElement.h" +#include "nsIImageFrame.h" + + static nscolor MakeColorPref(const char *colstr) { @@ -827,10 +833,82 @@ nsPresContext::GetImageAnimationMode(nsImageAnimation* aModeResult) return NS_OK; } +// Helper function for setting Anim Mode on image +static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, PRUint16 aMode) +{ + if (aImgReq != nsnull) { + nsCOMPtr imgCon; + aImgReq->GetImage(getter_AddRefs(imgCon)); + if (imgCon) { + imgCon->SetAnimationMode(aMode); + } + } +} + + // Enumeration call back for HashTable +PR_STATIC_CALLBACK(PRBool) set_animation_mode(nsHashKey *aKey, void *aData, void* closure) +{ + nsISupports *sup = NS_REINTERPRET_CAST(nsISupports*, aData); + nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, sup); + nsCOMPtr imgReq; + loader->GetRequest(getter_AddRefs(imgReq)); + SetImgAnimModeOnImgReq(imgReq, (PRUint16)closure); + return PR_TRUE; +} + +// IMPORTANT: Assumption is that all images for a Presentation +// have the same Animation Mode (pavlov said this was OK) +// +// Walks content and set the animation mode +// this is a way to turn on/off image animations +void nsPresContext::SetImgAnimations(nsCOMPtr& aParent, nsImageAnimation aMode) +{ + nsCOMPtr imgContent(do_QueryInterface(aParent)); + if (imgContent) { + nsIFrame* frame; + mShell->GetPrimaryFrameFor(aParent, &frame); + if (frame != nsnull) { + nsIImageFrame* imgFrame = nsnull; + CallQueryInterface(frame, &imgFrame); + if (imgFrame != nsnull) { + nsCOMPtr imgReq; + imgFrame->GetImageRequest(getter_AddRefs(imgReq)); + SetImgAnimModeOnImgReq(imgReq, aMode); + } + } + } + PRInt32 count; + aParent->ChildCount(count); + for (PRInt32 i=0;i child; + aParent->ChildAt(i, *getter_AddRefs(child)); + if (child) { + SetImgAnimations(child, aMode); + } + } +} NS_IMETHODIMP nsPresContext::SetImageAnimationMode(nsImageAnimation aMode) { + // This hash table contains a list of background images + // so iterate over it and set the mode + mImageLoaders.Enumerate(set_animation_mode, (void*)aMode); + + // Now walk the content tree and set the animation mode + // on all the images + nsCOMPtr doc; + if (mShell != nsnull) { + mShell->GetDocument(getter_AddRefs(doc)); + if (doc) { + nsCOMPtr rootContent; + doc->GetRootContent(getter_AddRefs(rootContent)); + if (rootContent) { + SetImgAnimations(rootContent, aMode); + } + } + } + mImageAnimationMode = aMode; return NS_OK; } diff --git a/layout/base/src/nsPresContext.cpp b/layout/base/src/nsPresContext.cpp index 3a688e0971d2..300029864285 100644 --- a/layout/base/src/nsPresContext.cpp +++ b/layout/base/src/nsPresContext.cpp @@ -70,6 +70,12 @@ #include "nsBidiPresUtils.h" #endif // IBMBIDI +// Needed for Start/Stop of Image Animation +#include "imgIContainer.h" +#include "nsIDOMHTMLImageElement.h" +#include "nsIImageFrame.h" + + static nscolor MakeColorPref(const char *colstr) { @@ -827,10 +833,82 @@ nsPresContext::GetImageAnimationMode(nsImageAnimation* aModeResult) return NS_OK; } +// Helper function for setting Anim Mode on image +static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, PRUint16 aMode) +{ + if (aImgReq != nsnull) { + nsCOMPtr imgCon; + aImgReq->GetImage(getter_AddRefs(imgCon)); + if (imgCon) { + imgCon->SetAnimationMode(aMode); + } + } +} + + // Enumeration call back for HashTable +PR_STATIC_CALLBACK(PRBool) set_animation_mode(nsHashKey *aKey, void *aData, void* closure) +{ + nsISupports *sup = NS_REINTERPRET_CAST(nsISupports*, aData); + nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, sup); + nsCOMPtr imgReq; + loader->GetRequest(getter_AddRefs(imgReq)); + SetImgAnimModeOnImgReq(imgReq, (PRUint16)closure); + return PR_TRUE; +} + +// IMPORTANT: Assumption is that all images for a Presentation +// have the same Animation Mode (pavlov said this was OK) +// +// Walks content and set the animation mode +// this is a way to turn on/off image animations +void nsPresContext::SetImgAnimations(nsCOMPtr& aParent, nsImageAnimation aMode) +{ + nsCOMPtr imgContent(do_QueryInterface(aParent)); + if (imgContent) { + nsIFrame* frame; + mShell->GetPrimaryFrameFor(aParent, &frame); + if (frame != nsnull) { + nsIImageFrame* imgFrame = nsnull; + CallQueryInterface(frame, &imgFrame); + if (imgFrame != nsnull) { + nsCOMPtr imgReq; + imgFrame->GetImageRequest(getter_AddRefs(imgReq)); + SetImgAnimModeOnImgReq(imgReq, aMode); + } + } + } + PRInt32 count; + aParent->ChildCount(count); + for (PRInt32 i=0;i child; + aParent->ChildAt(i, *getter_AddRefs(child)); + if (child) { + SetImgAnimations(child, aMode); + } + } +} NS_IMETHODIMP nsPresContext::SetImageAnimationMode(nsImageAnimation aMode) { + // This hash table contains a list of background images + // so iterate over it and set the mode + mImageLoaders.Enumerate(set_animation_mode, (void*)aMode); + + // Now walk the content tree and set the animation mode + // on all the images + nsCOMPtr doc; + if (mShell != nsnull) { + mShell->GetDocument(getter_AddRefs(doc)); + if (doc) { + nsCOMPtr rootContent; + doc->GetRootContent(getter_AddRefs(rootContent)); + if (rootContent) { + SetImgAnimations(rootContent, aMode); + } + } + } + mImageAnimationMode = aMode; return NS_OK; } diff --git a/layout/base/src/nsPresContext.h b/layout/base/src/nsPresContext.h index 3d93a879712e..400ca7c170dc 100644 --- a/layout/base/src/nsPresContext.h +++ b/layout/base/src/nsPresContext.h @@ -55,6 +55,7 @@ #endif #include "nsHashtable.h" +#include "nsIContent.h" // Base class for concrete presentation context classes class nsPresContext : public nsIPresContext, public nsIObserver { @@ -278,6 +279,7 @@ protected: void GetFontPreferences(); void GetDocumentColorPreferences(); void UpdateCharSet(const PRUnichar* aCharSet); + void SetImgAnimations(nsCOMPtr& aParent, nsImageAnimation aMode); private: static int PR_CALLBACK PrefChangedCallback(const char*, void*);