This commit is contained in:
Robert Longson 2011-10-19 14:55:27 +01:00
Родитель f2c48c50e8
Коммит 2d83ed6c08
3 изменённых файлов: 52 добавлений и 33 удалений

Просмотреть файл

@ -45,6 +45,7 @@
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
#include "gfxContext.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
@ -167,6 +168,28 @@ 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()
{
@ -258,6 +281,17 @@ 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
{

Просмотреть файл

@ -77,6 +77,8 @@ 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);
@ -101,6 +103,7 @@ protected:
virtual LengthAttributesInfo GetLengthInfo();
virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio();
virtual StringAttributesInfo GetStringInfo();
virtual void DidAnimateString(PRUint8 aAttrEnum);
enum { X, Y, WIDTH, HEIGHT };
nsSVGLength2 mLengthAttributes[4];

Просмотреть файл

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