Bug 693183 - move image processing to the frame class. r=jwatt

This commit is contained in:
Robert Longson 2011-10-19 16:37:49 +01:00
parent 516cb9f7f6
commit 9139d5704e
3 changed files with 35 additions and 52 deletions

View File

@ -45,7 +45,6 @@
#include "imgIContainer.h" #include "imgIContainer.h"
#include "imgIDecoderObserver.h" #include "imgIDecoderObserver.h"
#include "gfxContext.h" #include "gfxContext.h"
#include "mozilla/Preferences.h"
using namespace mozilla; using namespace mozilla;
@ -168,28 +167,6 @@ nsSVGImageElement::LoadSVGImage(bool aForce, bool aNotify)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// nsIContent methods: // 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 void
nsSVGImageElement::MaybeLoadSVGImage() nsSVGImageElement::MaybeLoadSVGImage()
{ {
@ -281,17 +258,6 @@ nsSVGImageElement::GetStringInfo()
ArrayLength(sStringInfo)); ArrayLength(sStringInfo));
} }
void
nsSVGImageElement::DidAnimateString(PRUint8 aAttrEnum)
{
if (aAttrEnum == HREF) {
LoadSVGImage(true, false);
return;
}
nsSVGImageElementBase::DidAnimateString(aAttrEnum);
}
nsresult nsresult
nsSVGImageElement::CopyInnerTo(nsGenericElement* aDest) const nsSVGImageElement::CopyInnerTo(nsGenericElement* aDest) const
{ {

View File

@ -77,8 +77,6 @@ public:
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGImageElementBase::) NS_FORWARD_NSIDOMSVGELEMENT(nsSVGImageElementBase::)
// nsIContent interface // nsIContent interface
virtual nsresult AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
const nsAString* aValue, bool aNotify);
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent, nsIContent* aBindingParent,
bool aCompileEventHandlers); bool aCompileEventHandlers);
@ -103,7 +101,6 @@ protected:
virtual LengthAttributesInfo GetLengthInfo(); virtual LengthAttributesInfo GetLengthInfo();
virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio(); virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio();
virtual StringAttributesInfo GetStringInfo(); virtual StringAttributesInfo GetStringInfo();
virtual void DidAnimateString(PRUint8 aAttrEnum);
enum { X, Y, WIDTH, HEIGHT }; enum { X, Y, WIDTH, HEIGHT };
nsSVGLength2 mLengthAttributes[4]; nsSVGLength2 mLengthAttributes[4];

View File

@ -47,6 +47,9 @@
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
#include "gfxPlatform.h" #include "gfxPlatform.h"
#include "nsSVGSVGElement.h" #include "nsSVGSVGElement.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
class nsSVGImageFrame; class nsSVGImageFrame;
@ -72,14 +75,15 @@ private:
nsSVGImageFrame *mFrame; nsSVGImageFrame *mFrame;
}; };
typedef nsSVGPathGeometryFrame nsSVGImageFrameBase;
class nsSVGImageFrame : public nsSVGPathGeometryFrame class nsSVGImageFrame : public nsSVGImageFrameBase
{ {
friend nsIFrame* friend nsIFrame*
NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
protected: protected:
nsSVGImageFrame(nsStyleContext* aContext) : nsSVGPathGeometryFrame(aContext) {} nsSVGImageFrame(nsStyleContext* aContext) : nsSVGImageFrameBase(aContext) {}
virtual ~nsSVGImageFrame(); virtual ~nsSVGImageFrame();
public: public:
@ -168,7 +172,7 @@ nsSVGImageFrame::Init(nsIContent* aContent,
NS_ASSERTION(image, "Content is not an SVG image!"); NS_ASSERTION(image, "Content is not an SVG image!");
#endif #endif
nsresult rv = nsSVGPathGeometryFrame::Init(aContent, aParent, aPrevInFlow); nsresult rv = nsSVGImageFrameBase::Init(aContent, aParent, aPrevInFlow);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
mListener = new nsSVGImageListener(this); mListener = new nsSVGImageListener(this);
@ -204,8 +208,24 @@ nsSVGImageFrame::AttributeChanged(PRInt32 aNameSpaceID,
nsSVGUtils::UpdateGraphic(this); nsSVGUtils::UpdateGraphic(this);
return NS_OK; 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<nsSVGImageElement*>(mContent);
return nsSVGPathGeometryFrame::AttributeChanged(aNameSpaceID, if (element->mStringAttributes[nsSVGImageElement::HREF].IsExplicitlySet()) {
element->LoadSVGImage(true, true);
} else {
element->CancelImageRequests(true);
}
}
return nsSVGImageFrameBase::AttributeChanged(aNameSpaceID,
aAttribute, aModType); aAttribute, aModType);
} }
@ -426,7 +446,7 @@ nsSVGImageFrame::GetFrameForPoint(const nsPoint &aPoint)
// just fall back on our <image> element's own bounds here. // just fall back on our <image> element's own bounds here.
} }
return nsSVGPathGeometryFrame::GetFrameForPoint(aPoint); return nsSVGImageFrameBase::GetFrameForPoint(aPoint);
} }
nsIAtom * nsIAtom *