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 "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
{

View File

@ -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];

View File

@ -47,6 +47,9 @@
#include "nsIInterfaceRequestorUtils.h"
#include "gfxPlatform.h"
#include "nsSVGSVGElement.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
class nsSVGImageFrame;
@ -72,14 +75,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 +172,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 +199,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<nsSVGImageElement*>(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 +446,7 @@ nsSVGImageFrame::GetFrameForPoint(const nsPoint &aPoint)
// just fall back on our <image> element's own bounds here.
}
return nsSVGPathGeometryFrame::GetFrameForPoint(aPoint);
return nsSVGImageFrameBase::GetFrameForPoint(aPoint);
}
nsIAtom *