Bug 1245751 - Part 8: Allow href without xlink on SVG <textPath> elements. draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 07 Jul 2016 11:44:25 +0800
changeset 407859 1e9ce2fb08aac471c63e795adbae09eee8bf3eaa
parent 407858 aee87527798a948891de7415ae1f0a322d002fdf
child 407860 b8a2a9dc7b0b38e8ddcc0c2ecc1d791d2a170103
push id28064
push userbmo:boris.chiou@gmail.com
push dateWed, 31 Aug 2016 04:26:14 +0000
bugs1245751
milestone51.0a1
Bug 1245751 - Part 8: Allow href without xlink on SVG <textPath> elements. MozReview-Commit-ID: KObkvkctP4L
dom/svg/SVGTextPathElement.cpp
dom/svg/SVGTextPathElement.h
layout/svg/SVGTextFrame.cpp
--- a/dom/svg/SVGTextPathElement.cpp
+++ b/dom/svg/SVGTextPathElement.cpp
@@ -56,18 +56,19 @@ nsSVGElement::EnumInfo SVGTextPathElemen
     TEXTPATH_METHODTYPE_ALIGN
   },
   { &nsGkAtoms::spacing,
     sSpacingMap,
     TEXTPATH_SPACINGTYPE_EXACT
   }
 };
 
-nsSVGElement::StringInfo SVGTextPathElement::sStringInfo[1] =
+nsSVGElement::StringInfo SVGTextPathElement::sStringInfo[2] =
 {
+  { &nsGkAtoms::href, kNameSpaceID_None, true },
   { &nsGkAtoms::href, kNameSpaceID_XLink, true }
 };
 
 //----------------------------------------------------------------------
 // Implementation
 
 SVGTextPathElement::SVGTextPathElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
   : SVGTextPathElementBase(aNodeInfo)
@@ -77,17 +78,19 @@ SVGTextPathElement::SVGTextPathElement(a
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTextPathElement)
 
 already_AddRefed<SVGAnimatedString>
 SVGTextPathElement::Href()
 {
-  return mStringAttributes[HREF].ToDOMAnimatedString(this);
+  return mStringAttributes[HREF].IsExplicitlySet()
+         ? mStringAttributes[HREF].ToDOMAnimatedString(this)
+         : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
 }
 
 //----------------------------------------------------------------------
 
 already_AddRefed<SVGAnimatedLength>
 SVGTextPathElement::StartOffset()
 {
   return mLengthAttributes[STARTOFFSET].ToDOMAnimatedLength(this);
--- a/dom/svg/SVGTextPathElement.h
+++ b/dom/svg/SVGTextPathElement.h
@@ -69,17 +69,17 @@ public:
   enum { /* LENGTHADJUST, */ METHOD = 1, SPACING };
   nsSVGEnum mEnumAttributes[3];
   virtual nsSVGEnum* EnumAttributes() override
     { return mEnumAttributes; }
   static nsSVGEnumMapping sMethodMap[];
   static nsSVGEnumMapping sSpacingMap[];
   static EnumInfo sEnumInfo[3];
 
-  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_SVGTextPathElement_h
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -3380,17 +3380,18 @@ void
 SVGTextFrame::HandleAttributeChangeInDescendant(Element* aElement,
                                                 int32_t aNameSpaceID,
                                                 nsIAtom* aAttribute)
 {
   if (aElement->IsSVGElement(nsGkAtoms::textPath)) {
     if (aNameSpaceID == kNameSpaceID_None &&
         aAttribute == nsGkAtoms::startOffset) {
       NotifyGlyphMetricsChange();
-    } else if (aNameSpaceID == kNameSpaceID_XLink &&
+    } else if ((aNameSpaceID == kNameSpaceID_XLink ||
+                aNameSpaceID == kNameSpaceID_None) &&
                aAttribute == nsGkAtoms::href) {
       // Blow away our reference, if any
       nsIFrame* childElementFrame = aElement->GetPrimaryFrame();
       if (childElementFrame) {
         childElementFrame->Properties().Delete(
           nsSVGEffects::HrefAsTextPathProperty());
         NotifyGlyphMetricsChange();
       }
@@ -4817,17 +4818,24 @@ SVGTextFrame::GetTextPathPathElement(nsI
 {
   nsSVGTextPathProperty *property =
     aTextPathFrame->Properties().Get(nsSVGEffects::HrefAsTextPathProperty());
 
   if (!property) {
     nsIContent* content = aTextPathFrame->GetContent();
     dom::SVGTextPathElement* tp = static_cast<dom::SVGTextPathElement*>(content);
     nsAutoString href;
-    tp->mStringAttributes[dom::SVGTextPathElement::HREF].GetAnimValue(href, tp);
+    if (tp->mStringAttributes[dom::SVGTextPathElement::HREF].IsExplicitlySet()) {
+      tp->mStringAttributes[dom::SVGTextPathElement::HREF]
+        .GetAnimValue(href, tp);
+    } else {
+      tp->mStringAttributes[dom::SVGTextPathElement::XLINK_HREF]
+        .GetAnimValue(href, tp);
+    }
+
     if (href.IsEmpty()) {
       return nullptr; // no URL
     }
 
     nsCOMPtr<nsIURI> targetURI;
     nsCOMPtr<nsIURI> base = content->GetBaseURI();
     nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
                                               content->GetUncomposedDoc(), base);