Bug 1245751 - Part 6: Allow href without xlink on SVG <pattern> elements.
MozReview-Commit-ID: 4oODGIKEnE2
--- a/dom/svg/SVGPatternElement.cpp
+++ b/dom/svg/SVGPatternElement.cpp
@@ -40,18 +40,19 @@ nsSVGElement::EnumInfo SVGPatternElement
SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
},
{ &nsGkAtoms::patternContentUnits,
sSVGUnitTypesMap,
SVG_UNIT_TYPE_USERSPACEONUSE
}
};
-nsSVGElement::StringInfo SVGPatternElement::sStringInfo[1] =
+nsSVGElement::StringInfo SVGPatternElement::sStringInfo[2] =
{
+ { &nsGkAtoms::href, kNameSpaceID_None, true },
{ &nsGkAtoms::href, kNameSpaceID_XLink, true }
};
//----------------------------------------------------------------------
// Implementation
SVGPatternElement::SVGPatternElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: SVGPatternElementBase(aNodeInfo)
@@ -122,17 +123,19 @@ already_AddRefed<SVGAnimatedLength>
SVGPatternElement::Height()
{
return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
}
already_AddRefed<SVGAnimatedString>
SVGPatternElement::Href()
{
- return mStringAttributes[HREF].ToDOMAnimatedString(this);
+ return mStringAttributes[HREF].IsExplicitlySet()
+ ? mStringAttributes[HREF].ToDOMAnimatedString(this)
+ : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
}
//----------------------------------------------------------------------
// nsIContent methods
NS_IMETHODIMP_(bool)
SVGPatternElement::IsAttributeMapped(const nsIAtom* name) const
{
--- a/dom/svg/SVGPatternElement.h
+++ b/dom/svg/SVGPatternElement.h
@@ -79,19 +79,19 @@ protected:
static LengthInfo sLengthInfo[4];
enum { PATTERNUNITS, PATTERNCONTENTUNITS };
nsSVGEnum mEnumAttributes[2];
static EnumInfo sEnumInfo[2];
nsAutoPtr<mozilla::nsSVGAnimatedTransformList> mPatternTransform;
- enum { HREF };
- nsSVGString mStringAttributes[1];
- static StringInfo sStringInfo[1];
+ enum { HREF, XLINK_HREF };
+ nsSVGString mStringAttributes[2];
+ static StringInfo sStringInfo[2];
// SVGFitToViewbox properties
nsSVGViewBox mViewBox;
SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
};
} // namespace dom
} // namespace mozilla
--- a/layout/svg/nsSVGPatternFrame.cpp
+++ b/layout/svg/nsSVGPatternFrame.cpp
@@ -80,17 +80,18 @@ nsSVGPatternFrame::AttributeChanged(int3
aAttribute == nsGkAtoms::y ||
aAttribute == nsGkAtoms::width ||
aAttribute == nsGkAtoms::height ||
aAttribute == nsGkAtoms::preserveAspectRatio ||
aAttribute == nsGkAtoms::viewBox)) {
nsSVGEffects::InvalidateDirectRenderingObservers(this);
}
- if (aNameSpaceID == kNameSpaceID_XLink &&
+ if ((aNameSpaceID == kNameSpaceID_XLink ||
+ aNameSpaceID == kNameSpaceID_None) &&
aAttribute == nsGkAtoms::href) {
// Blow away our reference, if any
Properties().Delete(nsSVGEffects::HrefAsPaintingProperty());
mNoHRefURI = false;
// And update whoever references us
nsSVGEffects::InvalidateDirectRenderingObservers(this);
}
@@ -548,20 +549,27 @@ nsSVGPatternFrame::GetReferencedPattern(
{
if (mNoHRefURI)
return nullptr;
nsSVGPaintingProperty *property =
Properties().Get(nsSVGEffects::HrefAsPaintingProperty());
if (!property) {
- // Fetch our pattern element's xlink:href attribute
+ // Fetch our pattern element's href or xlink:href attribute
SVGPatternElement *pattern = static_cast<SVGPatternElement *>(mContent);
nsAutoString href;
- pattern->mStringAttributes[SVGPatternElement::HREF].GetAnimValue(href, pattern);
+ if (pattern->mStringAttributes[SVGPatternElement::HREF].IsExplicitlySet()) {
+ pattern->mStringAttributes[SVGPatternElement::HREF]
+ .GetAnimValue(href, pattern);
+ } else {
+ pattern->mStringAttributes[SVGPatternElement::XLINK_HREF]
+ .GetAnimValue(href, pattern);
+ }
+
if (href.IsEmpty()) {
mNoHRefURI = true;
return nullptr; // no URL
}
// Convert href to an nsIURI
nsCOMPtr<nsIURI> targetURI;
nsCOMPtr<nsIURI> base = mContent->GetBaseURI();