From f2c48c50e8c4e64c5ebc5a65fee9d9926e67a039 Mon Sep 17 00:00:00 2001 From: Robert Longson Date: Wed, 19 Oct 2011 14:40:58 +0100 Subject: [PATCH] Bug 693183 - Simplify class animation processing. r=jwatt --- content/svg/content/src/nsSVGImageElement.cpp | 34 ------------- content/svg/content/src/nsSVGImageElement.h | 3 -- layout/svg/base/src/nsSVGImageFrame.cpp | 48 +++++++++++++------ 3 files changed, 33 insertions(+), 52 deletions(-) diff --git a/content/svg/content/src/nsSVGImageElement.cpp b/content/svg/content/src/nsSVGImageElement.cpp index 9fefc872c709..b097bdeb722d 100644 --- a/content/svg/content/src/nsSVGImageElement.cpp +++ b/content/svg/content/src/nsSVGImageElement.cpp @@ -45,7 +45,6 @@ #include "imgIContainer.h" #include "imgIDecoderObserver.h" #include "gfxContext.h" -#include "mozilla/Preferences.h" using namespace mozilla; @@ -168,28 +167,6 @@ nsSVGImageElement::LoadSVGImage(bool aForce, bool aNotify) //---------------------------------------------------------------------- // nsIContent methods: -nsresult -nsSVGImageElement::AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, - const nsAString* aValue, bool aNotify) -{ - if (aNamespaceID == kNameSpaceID_XLink && aName == nsGkAtoms::href) { - // If caller is not chrome and dom.disable_image_src_set is true, - // prevent setting image.src by exiting early - if (Preferences::GetBool("dom.disable_image_src_set") && - !nsContentUtils::IsCallerChrome()) { - return NS_OK; - } - - if (aValue) { - LoadSVGImage(true, aNotify); - } else { - CancelImageRequests(aNotify); - } - } - return nsSVGImageElementBase::AfterSetAttr(aNamespaceID, aName, - aValue, aNotify); -} - void nsSVGImageElement::MaybeLoadSVGImage() { @@ -281,17 +258,6 @@ nsSVGImageElement::GetStringInfo() ArrayLength(sStringInfo)); } -void -nsSVGImageElement::DidAnimateString(PRUint8 aAttrEnum) -{ - if (aAttrEnum == HREF) { - LoadSVGImage(true, false); - return; - } - - nsSVGImageElementBase::DidAnimateString(aAttrEnum); -} - nsresult nsSVGImageElement::CopyInnerTo(nsGenericElement* aDest) const { diff --git a/content/svg/content/src/nsSVGImageElement.h b/content/svg/content/src/nsSVGImageElement.h index 3e59da4949c3..8893bf519650 100644 --- a/content/svg/content/src/nsSVGImageElement.h +++ b/content/svg/content/src/nsSVGImageElement.h @@ -77,8 +77,6 @@ public: NS_FORWARD_NSIDOMSVGELEMENT(nsSVGImageElementBase::) // nsIContent interface - virtual nsresult AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName, - const nsAString* aValue, bool aNotify); virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, bool aCompileEventHandlers); @@ -103,7 +101,6 @@ protected: virtual LengthAttributesInfo GetLengthInfo(); virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio(); virtual StringAttributesInfo GetStringInfo(); - virtual void DidAnimateString(PRUint8 aAttrEnum); enum { X, Y, WIDTH, HEIGHT }; nsSVGLength2 mLengthAttributes[4]; diff --git a/layout/svg/base/src/nsSVGImageFrame.cpp b/layout/svg/base/src/nsSVGImageFrame.cpp index 1bd37c3b8162..cdb85df4804f 100644 --- a/layout/svg/base/src/nsSVGImageFrame.cpp +++ b/layout/svg/base/src/nsSVGImageFrame.cpp @@ -47,6 +47,7 @@ #include "nsIInterfaceRequestorUtils.h" #include "gfxPlatform.h" #include "nsSVGSVGElement.h" +#include "mozilla/Preferences.h" class nsSVGImageFrame; @@ -72,14 +73,15 @@ private: nsSVGImageFrame *mFrame; }; +typedef nsSVGPathGeometryFrame nsSVGImageFrameBase; -class nsSVGImageFrame : public nsSVGPathGeometryFrame +class nsSVGImageFrame : public nsSVGImageFrameBase { friend nsIFrame* NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); protected: - nsSVGImageFrame(nsStyleContext* aContext) : nsSVGPathGeometryFrame(aContext) {} + nsSVGImageFrame(nsStyleContext* aContext) : nsSVGImageFrameBase(aContext) {} virtual ~nsSVGImageFrame(); public: @@ -168,7 +170,7 @@ nsSVGImageFrame::Init(nsIContent* aContent, NS_ASSERTION(image, "Content is not an SVG image!"); #endif - nsresult rv = nsSVGPathGeometryFrame::Init(aContent, aParent, aPrevInFlow); + nsresult rv = nsSVGImageFrameBase::Init(aContent, aParent, aPrevInFlow); if (NS_FAILED(rv)) return rv; mListener = new nsSVGImageListener(this); @@ -195,18 +197,34 @@ nsSVGImageFrame::AttributeChanged(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aModType) { - if (aNameSpaceID == kNameSpaceID_None && - (aAttribute == nsGkAtoms::x || - aAttribute == nsGkAtoms::y || - aAttribute == nsGkAtoms::width || - aAttribute == nsGkAtoms::height || - aAttribute == nsGkAtoms::preserveAspectRatio)) { - nsSVGUtils::UpdateGraphic(this); - return NS_OK; - } + if (aNameSpaceID == kNameSpaceID_None && + (aAttribute == nsGkAtoms::x || + aAttribute == nsGkAtoms::y || + aAttribute == nsGkAtoms::width || + aAttribute == nsGkAtoms::height || + aAttribute == nsGkAtoms::preserveAspectRatio)) { + nsSVGUtils::UpdateGraphic(this); + return NS_OK; + } + if (aNameSpaceID == kNameSpaceID_XLink && + aAttribute == nsGkAtoms::href) { + // If caller is not chrome and dom.disable_image_src_set is true, + // prevent setting image.src by exiting early + if (Preferences::GetBool("dom.disable_image_src_set") && + !nsContentUtils::IsCallerChrome()) { + return NS_OK; + } + nsSVGImageElement *element = static_cast(mContent); - return nsSVGPathGeometryFrame::AttributeChanged(aNameSpaceID, - aAttribute, aModType); + if (element->mStringAttributes[nsSVGImageElement::HREF].IsExplicitlySet()) { + element->LoadSVGImage(true, true); + } else { + element->CancelImageRequests(true); + } + } + + return nsSVGImageFrameBase::AttributeChanged(aNameSpaceID, + aAttribute, aModType); } gfxMatrix @@ -426,7 +444,7 @@ nsSVGImageFrame::GetFrameForPoint(const nsPoint &aPoint) // just fall back on our element's own bounds here. } - return nsSVGPathGeometryFrame::GetFrameForPoint(aPoint); + return nsSVGImageFrameBase::GetFrameForPoint(aPoint); } nsIAtom *