Bug 1245751 - Part 3: Allow href without xlink on SVG <image> elements.
MozReview-Commit-ID: 1DGZUcJsrDY
--- a/dom/svg/SVGImageElement.cpp
+++ b/dom/svg/SVGImageElement.cpp
@@ -32,18 +32,19 @@ SVGImageElement::WrapNode(JSContext *aCx
nsSVGElement::LengthInfo SVGImageElement::sLengthInfo[4] =
{
{ &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
{ &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
{ &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
};
-nsSVGElement::StringInfo SVGImageElement::sStringInfo[1] =
+nsSVGElement::StringInfo SVGImageElement::sStringInfo[2] =
{
+ { &nsGkAtoms::href, kNameSpaceID_None, true },
{ &nsGkAtoms::href, kNameSpaceID_XLink, true }
};
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ISUPPORTS_INHERITED(SVGImageElement, SVGImageElementBase,
nsIDOMNode, nsIDOMElement,
@@ -103,45 +104,53 @@ already_AddRefed<DOMSVGAnimatedPreserveA
SVGImageElement::PreserveAspectRatio()
{
return mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(this);
}
already_AddRefed<SVGAnimatedString>
SVGImageElement::Href()
{
- return mStringAttributes[HREF].ToDOMAnimatedString(this);
+ return mStringAttributes[HREF].IsExplicitlySet()
+ ? mStringAttributes[HREF].ToDOMAnimatedString(this)
+ : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
}
//----------------------------------------------------------------------
nsresult
SVGImageElement::LoadSVGImage(bool aForce, bool aNotify)
{
// resolve href attribute
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsAutoString href;
- mStringAttributes[HREF].GetAnimValue(href, this);
+ if (mStringAttributes[HREF].IsExplicitlySet()) {
+ mStringAttributes[HREF].GetAnimValue(href, this);
+ } else {
+ mStringAttributes[XLINK_HREF].GetAnimValue(href, this);
+ }
href.Trim(" \t\n\r");
if (baseURI && !href.IsEmpty())
NS_MakeAbsoluteURI(href, href, baseURI);
return LoadImage(href, aForce, aNotify, eImageLoadType_Normal);
}
//----------------------------------------------------------------------
// nsIContent methods:
nsresult
SVGImageElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)
{
- if (aNamespaceID == kNameSpaceID_XLink && aName == nsGkAtoms::href) {
+ if (aName == nsGkAtoms::href &&
+ (aNamespaceID == kNameSpaceID_None ||
+ aNamespaceID == kNameSpaceID_XLink)) {
// If there isn't a frame we still need to load the image in case
// the frame is created later e.g. by attaching to a document.
// If there is a frame then it should deal with loading as the image
// url may be animated
if (!GetPrimaryFrame()) {
if (aValue) {
LoadSVGImage(true, aNotify);
@@ -152,17 +161,18 @@ SVGImageElement::AfterSetAttr(int32_t aN
}
return SVGImageElementBase::AfterSetAttr(aNamespaceID, aName,
aValue, aNotify);
}
void
SVGImageElement::MaybeLoadSVGImage()
{
- if (mStringAttributes[HREF].IsExplicitlySet() &&
+ if ((mStringAttributes[HREF].IsExplicitlySet() ||
+ mStringAttributes[XLINK_HREF].IsExplicitlySet()) &&
(NS_FAILED(LoadSVGImage(false, true)) ||
!LoadingEnabled())) {
CancelImageRequests(true);
}
}
nsresult
SVGImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
@@ -172,17 +182,18 @@ SVGImageElement::BindToTree(nsIDocument*
nsresult rv = SVGImageElementBase::BindToTree(aDocument, aParent,
aBindingParent,
aCompileEventHandlers);
NS_ENSURE_SUCCESS(rv, rv);
nsImageLoadingContent::BindToTree(aDocument, aParent, aBindingParent,
aCompileEventHandlers);
- if (mStringAttributes[HREF].IsExplicitlySet()) {
+ if (mStringAttributes[HREF].IsExplicitlySet() ||
+ mStringAttributes[XLINK_HREF].IsExplicitlySet()) {
// FIXME: Bug 660963 it would be nice if we could just have
// ClearBrokenState update our state and do it fast...
ClearBrokenState();
RemoveStatesSilently(NS_EVENT_STATE_BROKEN);
nsContentUtils::AddScriptRunner(
NewRunnableMethod(this, &SVGImageElement::MaybeLoadSVGImage));
}
--- a/dom/svg/SVGImageElement.h
+++ b/dom/svg/SVGImageElement.h
@@ -84,17 +84,17 @@ protected:
virtual StringAttributesInfo GetStringInfo() override;
enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
nsSVGLength2 mLengthAttributes[4];
static LengthInfo sLengthInfo[4];
SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
- enum { HREF };
- nsSVGString mStringAttributes[1];
- static StringInfo sStringInfo[1];
+ enum { HREF, XLINK_HREF };
+ nsSVGString mStringAttributes[2];
+ static StringInfo sStringInfo[2];
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_SVGImageElement_h
--- a/layout/svg/nsSVGImageFrame.cpp
+++ b/layout/svg/nsSVGImageFrame.cpp
@@ -221,21 +221,25 @@ nsSVGImageFrame::AttributeChanged(int32_
// We don't paint the content of the image using display lists, therefore
// we have to invalidate for this children-only transform changes since
// there is no layer tree to notice that the transform changed and
// recomposite.
InvalidateFrame();
return NS_OK;
}
}
- if (aNameSpaceID == kNameSpaceID_XLink &&
+ if ((aNameSpaceID == kNameSpaceID_XLink ||
+ aNameSpaceID == kNameSpaceID_None) &&
aAttribute == nsGkAtoms::href) {
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
- if (element->mStringAttributes[SVGImageElement::HREF].IsExplicitlySet()) {
+ bool hrefIsSet =
+ element->mStringAttributes[SVGImageElement::HREF].IsExplicitlySet() ||
+ element->mStringAttributes[SVGImageElement::XLINK_HREF].IsExplicitlySet();
+ if (hrefIsSet) {
element->LoadSVGImage(true, true);
} else {
element->CancelImageRequests(true);
}
}
return nsSVGPathGeometryFrame::AttributeChanged(aNameSpaceID,
aAttribute, aModType);