Bug 1075125 - GetCurrentDoc fixes in content/svg, r=wchen
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 03 Oct 2014 15:32:26 +0300
changeset 208765 9b157630e5abcc12a740021a03a19d8bbd01223f
parent 208764 b35c63fe50da7796b61edb3ff67f03ee804ce7ac
child 208766 7fa34faa8330b1258eeefaebdfa94e6f01ae9a9a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerswchen
bugs1075125
milestone35.0a1
Bug 1075125 - GetCurrentDoc fixes in content/svg, r=wchen
content/svg/content/src/SVGAElement.cpp
content/svg/content/src/SVGAnimationElement.cpp
content/svg/content/src/SVGContentUtils.cpp
content/svg/content/src/SVGMPathElement.cpp
content/svg/content/src/SVGSVGElement.cpp
content/svg/content/src/SVGStyleElement.cpp
content/svg/content/src/SVGTitleElement.cpp
content/svg/content/src/SVGTransformableElement.cpp
content/svg/content/src/SVGUseElement.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGFeatures.cpp
--- a/content/svg/content/src/SVGAElement.cpp
+++ b/content/svg/content/src/SVGAElement.cpp
@@ -129,31 +129,34 @@ SVGAElement::BindToTree(nsIDocument *aDo
 {
   Link::ResetLinkState(false, Link::ElementHasHref());
 
   nsresult rv = SVGAElementBase::BindToTree(aDocument, aParent,
                                             aBindingParent,
                                             aCompileEventHandlers);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (aDocument) {
-    aDocument->RegisterPendingLinkUpdate(this);
+  nsIDocument* doc = GetComposedDoc();
+  if (doc) {
+    doc->RegisterPendingLinkUpdate(this);
   }
 
   return NS_OK;
 }
 
 void
 SVGAElement::UnbindFromTree(bool aDeep, bool aNullParent)
 {
   // If this link is ever reinserted into a document, it might
   // be under a different xml:base, so forget the cached state now.
   Link::ResetLinkState(false, Link::ElementHasHref());
 
-  nsIDocument* doc = GetCurrentDoc();
+  // Note, we need to use OwnerDoc() here since GetComposedDoc() may
+  // return null already at this point.
+  nsIDocument* doc = OwnerDoc();
   if (doc) {
     doc->UnregisterPendingLinkUpdate(this);
   }
 
   SVGAElementBase::UnbindFromTree(aDeep, aNullParent);
 }
 
 already_AddRefed<nsIURI>
--- a/content/svg/content/src/SVGAnimationElement.cpp
+++ b/content/svg/content/src/SVGAnimationElement.cpp
@@ -216,17 +216,17 @@ SVGAnimationElement::BindToTree(nsIDocum
     }
     const nsAttrValue* href = mAttrsAndChildren.GetAttr(nsGkAtoms::href,
                                                         kNameSpaceID_XLink);
     if (href) {
       nsAutoString hrefStr;
       href->ToString(hrefStr);
 
       // Pass in |aParent| instead of |this| -- first argument is only used
-      // for a call to GetCurrentDoc(), and |this| might not have a current
+      // for a call to GetComposedDoc(), and |this| might not have a current
       // document yet.
       UpdateHrefTarget(aParent, hrefStr);
     }
 
     mTimedElement.BindToTree(aParent);
   }
 
   AnimationNeedsResample();
--- a/content/svg/content/src/SVGContentUtils.cpp
+++ b/content/svg/content/src/SVGContentUtils.cpp
@@ -421,17 +421,17 @@ GetCTMInternal(nsSVGElement *aElement, b
   }
   if (ancestor->IsSVG()) {
     return
       gfx::ToMatrix(matrix) * GetCTMInternal(static_cast<nsSVGElement*>(ancestor), true, true);
   }
 
   // XXX this does not take into account CSS transform, or that the non-SVG
   // content that we've hit may itself be inside an SVG foreignObject higher up
-  nsIDocument* currentDoc = aElement->GetCurrentDoc();
+  nsIDocument* currentDoc = aElement->GetComposedDoc();
   float x = 0.0f, y = 0.0f;
   if (currentDoc && element->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG)) {
     nsIPresShell *presShell = currentDoc->GetShell();
     if (presShell) {
       nsIFrame* frame = element->GetPrimaryFrame();
       nsIFrame* ancestorFrame = presShell->GetRootFrame();
       if (frame && ancestorFrame) {
         nsPoint point = frame->GetOffsetTo(ancestorFrame);
--- a/content/svg/content/src/SVGMPathElement.cpp
+++ b/content/svg/content/src/SVGMPathElement.cpp
@@ -208,17 +208,17 @@ SVGMPathElement::UpdateHrefTarget(nsICon
 
   // Stop observing old target (if any)
   if (mHrefTarget.get()) {
     mHrefTarget.get()->RemoveMutationObserver(this);
   }
 
   if (aParent) {
     // Pass in |aParent| instead of |this| -- first argument is only used
-    // for a call to GetCurrentDoc(), and |this| might not have a current
+    // for a call to GetComposedDoc(), and |this| might not have a current
     // document yet (if our caller is BindToTree).
     mHrefTarget.Reset(aParent, targetURI);
   } else {
     // if we don't have a parent, then there's no animateMotion element
     // depending on our target, so there's no point tracking it right now.
     mHrefTarget.Unlink();
   }
 
--- a/content/svg/content/src/SVGSVGElement.cpp
+++ b/content/svg/content/src/SVGSVGElement.cpp
@@ -302,17 +302,17 @@ void
 SVGSVGElement::UnsuspendRedrawAll()
 {
   // no-op
 }
 
 void
 SVGSVGElement::ForceRedraw(ErrorResult& rv)
 {
-  nsIDocument* doc = GetCurrentDoc();
+  nsIDocument* doc = GetComposedDoc();
   if (!doc) {
     rv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   doc->FlushPendingNotifications(Flush_Display);
 }
 
@@ -509,17 +509,17 @@ SVGSVGElement::SetCurrentScaleTranslate(
   // their own last change.
   mPreviousScale = mCurrentScale;
   mPreviousTranslate = mCurrentTranslate;
   
   mCurrentScale = s;
   mCurrentTranslate = SVGPoint(x, y);
 
   // now dispatch the appropriate event if we are the root element
-  nsIDocument* doc = GetCurrentDoc();
+  nsIDocument* doc = GetUncomposedDoc();
   if (doc) {
     nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
     if (presShell && IsRoot()) {
       nsEventStatus status = nsEventStatus_eIgnore;
       if (mPreviousScale != mCurrentScale) {
         InternalSVGZoomEvent svgZoomEvent(true, NS_SVG_ZOOM);
         presShell->HandleDOMEventWithTarget(this, &svgZoomEvent, &status);
       } else {
@@ -826,17 +826,18 @@ SVGSVGElement::HasPreserveAspectRatio()
   return HasAttr(kNameSpaceID_None, nsGkAtoms::preserveAspectRatio) ||
     mPreserveAspectRatio.IsAnimated();
 }
 
 SVGViewElement*
 SVGSVGElement::GetCurrentViewElement() const
 {
   if (mCurrentViewID) {
-    nsIDocument* doc = GetCurrentDoc();
+    //XXXsmaug It is unclear how this should work in case we're in Shadow DOM.
+    nsIDocument* doc = GetUncomposedDoc();
     if (doc) {
       Element *element = doc->GetElementById(*mCurrentViewID);
       if (element && element->IsSVG(nsGkAtoms::view)) {
         return static_cast<SVGViewElement*>(element);
       }
     }
   }
   return nullptr;
@@ -869,17 +870,17 @@ SVGSVGElement::GetViewBoxWithSynthesis(
   // No viewBox attribute, so we shouldn't auto-scale. This is equivalent
   // to having a viewBox that exactly matches our viewport size.
   return nsSVGViewBoxRect(0, 0, aViewportWidth, aViewportHeight);
 }
 
 SVGPreserveAspectRatio
 SVGSVGElement::GetPreserveAspectRatioWithOverride() const
 {
-  nsIDocument* doc = GetCurrentDoc();
+  nsIDocument* doc = GetUncomposedDoc();
   if (doc && doc->IsBeingUsedAsImage()) {
     const SVGPreserveAspectRatio *pAROverridePtr = GetPreserveAspectRatioProperty();
     if (pAROverridePtr) {
       return *pAROverridePtr;
     }
   }
 
   SVGViewElement* viewElement = GetCurrentViewElement();
@@ -1032,17 +1033,17 @@ SVGSVGElement::HasViewBoxRect() const
 }
 
 bool
 SVGSVGElement::ShouldSynthesizeViewBox() const
 {
   NS_ABORT_IF_FALSE(!HasViewBoxRect(),
                     "Should only be called if we lack a viewBox");
 
-  nsIDocument* doc = GetCurrentDoc();
+  nsIDocument* doc = GetUncomposedDoc();
   return doc &&
     doc->IsBeingUsedAsImage() &&
     !mIsPaintingSVGImageElement &&
     !GetParent();
 }
 
 bool
 SVGSVGElement::SetPreserveAspectRatioProperty(const SVGPreserveAspectRatio& aPAR)
@@ -1081,17 +1082,17 @@ SVGSVGElement::ClearPreserveAspectRatioP
   return valPtr;
 }
 
 void
 SVGSVGElement::
   SetImageOverridePreserveAspectRatio(const SVGPreserveAspectRatio& aPAR)
 {
 #ifdef DEBUG
-  NS_ABORT_IF_FALSE(GetCurrentDoc()->IsBeingUsedAsImage(),
+  NS_ABORT_IF_FALSE(OwnerDoc()->IsBeingUsedAsImage(),
                     "should only override preserveAspectRatio in images");
 #endif
 
   bool hasViewBoxRect = HasViewBoxRect();
   if (!hasViewBoxRect && ShouldSynthesizeViewBox()) {
     // My non-<svg:image> clients will have been painting me with a synthesized
     // viewBox, but my <svg:image> client that's about to paint me now does NOT
     // want that.  Need to tell ourselves to flush our transform.
@@ -1111,17 +1112,17 @@ SVGSVGElement::
     mImageNeedsTransformInvalidation = true;
   }
 }
 
 void
 SVGSVGElement::ClearImageOverridePreserveAspectRatio()
 {
 #ifdef DEBUG
-  NS_ABORT_IF_FALSE(GetCurrentDoc()->IsBeingUsedAsImage(),
+  NS_ABORT_IF_FALSE(OwnerDoc()->IsBeingUsedAsImage(),
                     "should only override image preserveAspectRatio in images");
 #endif
 
   mIsPaintingSVGImageElement = false;
   if (!HasViewBoxRect() && ShouldSynthesizeViewBox()) {
     // My non-<svg:image> clients will want to paint me with a synthesized
     // viewBox, but my <svg:image> client that just painted me did NOT
     // use that.  Need to tell ourselves to flush our transform.
@@ -1132,17 +1133,17 @@ SVGSVGElement::ClearImageOverridePreserv
     mImageNeedsTransformInvalidation = true;
   }
 }
 
 void
 SVGSVGElement::FlushImageTransformInvalidation()
 {
   NS_ABORT_IF_FALSE(!GetParent(), "Should only be called on root node");
-  NS_ABORT_IF_FALSE(GetCurrentDoc()->IsBeingUsedAsImage(),
+  NS_ABORT_IF_FALSE(OwnerDoc()->IsBeingUsedAsImage(),
                     "Should only be called on image documents");
 
   if (mImageNeedsTransformInvalidation) {
     InvalidateTransformNotifyFrame();
     mImageNeedsTransformInvalidation = false;
   }
 }
 
--- a/content/svg/content/src/SVGStyleElement.cpp
+++ b/content/svg/content/src/SVGStyleElement.cpp
@@ -80,17 +80,17 @@ SVGStyleElement::BindToTree(nsIDocument*
   nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update));
 
   return rv;
 }
 
 void
 SVGStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
 {
-  nsCOMPtr<nsIDocument> oldDoc = GetCurrentDoc();
+  nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
   ShadowRoot* oldShadow = GetContainingShadow();
   SVGStyleElementBase::UnbindFromTree(aDeep, aNullParent);
   UpdateStyleSheetInternal(oldDoc, oldShadow);
 }
 
 nsresult
 SVGStyleElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
                          nsIAtom* aPrefix, const nsAString& aValue,
--- a/content/svg/content/src/SVGTitleElement.cpp
+++ b/content/svg/content/src/SVGTitleElement.cpp
@@ -106,17 +106,17 @@ SVGTitleElement::DoneAddingChildren(bool
   if (!aHaveNotified) {
     SendTitleChangeEvent(false);
   }
 }
 
 void
 SVGTitleElement::SendTitleChangeEvent(bool aBound)
 {
-  nsIDocument* doc = GetCurrentDoc();
+  nsIDocument* doc = GetUncomposedDoc();
   if (doc) {
     doc->NotifyPossibleTitleChange(aBound);
   }
 }
 
 //----------------------------------------------------------------------
 // nsIDOMNode methods
 
--- a/content/svg/content/src/SVGTransformableElement.cpp
+++ b/content/svg/content/src/SVGTransformableElement.cpp
@@ -220,30 +220,30 @@ SVGTransformableElement::GetBBox(const S
     }
     return NS_NewSVGRect(this, ToRect(nsSVGUtils::GetBBox(frame, aFlags)));
   }
 }
 
 already_AddRefed<SVGMatrix>
 SVGTransformableElement::GetCTM()
 {
-  nsIDocument* currentDoc = GetCurrentDoc();
+  nsIDocument* currentDoc = GetComposedDoc();
   if (currentDoc) {
     // Flush all pending notifications so that our frames are up to date
     currentDoc->FlushPendingNotifications(Flush_Layout);
   }
   gfx::Matrix m = SVGContentUtils::GetCTM(this, false);
   nsRefPtr<SVGMatrix> mat = m.IsSingular() ? nullptr : new SVGMatrix(ThebesMatrix(m));
   return mat.forget();
 }
 
 already_AddRefed<SVGMatrix>
 SVGTransformableElement::GetScreenCTM()
 {
-  nsIDocument* currentDoc = GetCurrentDoc();
+  nsIDocument* currentDoc = GetComposedDoc();
   if (currentDoc) {
     // Flush all pending notifications so that our frames are up to date
     currentDoc->FlushPendingNotifications(Flush_Layout);
   }
   gfx::Matrix m = SVGContentUtils::GetCTM(this, true);
   nsRefPtr<SVGMatrix> mat = m.IsSingular() ? nullptr : new SVGMatrix(ThebesMatrix(m));
   return mat.forget();
 }
--- a/content/svg/content/src/SVGUseElement.cpp
+++ b/content/svg/content/src/SVGUseElement.cpp
@@ -264,17 +264,17 @@ SVGUseElement::CreateAnonymousContent()
                      getter_AddRefs(newnode));
 
   nsCOMPtr<nsIContent> newcontent = do_QueryInterface(newnode);
 
   if (!newcontent)
     return nullptr;
 
   if (newcontent->IsSVG(nsGkAtoms::symbol)) {
-    nsIDocument *document = GetCurrentDoc();
+    nsIDocument *document = GetComposedDoc();
     if (!document)
       return nullptr;
 
     nsNodeInfoManager *nodeInfoManager = document->NodeInfoManager();
     if (!nodeInfoManager)
       return nullptr;
 
     nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
@@ -387,25 +387,25 @@ SVGUseElement::LookupHref()
   nsAutoString href;
   mStringAttributes[HREF].GetAnimValue(href, this);
   if (href.IsEmpty())
     return;
 
   nsCOMPtr<nsIURI> targetURI;
   nsCOMPtr<nsIURI> baseURI = mOriginal ? mOriginal->GetBaseURI() : GetBaseURI();
   nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
-                                            GetCurrentDoc(), baseURI);
+                                            GetComposedDoc(), baseURI);
 
   mSource.Reset(this, targetURI);
 }
 
 void
 SVGUseElement::TriggerReclone()
 {
-  nsIDocument *doc = GetCurrentDoc();
+  nsIDocument *doc = GetComposedDoc();
   if (!doc)
     return;
   nsIPresShell *presShell = doc->GetShell();
   if (!presShell)
     return;
   presShell->PostRecreateFramesFor(this);
 }
 
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -2700,22 +2700,22 @@ nsSVGElement::GetAnimatedAttr(int32_t aN
   }
 
   return nullptr;
 }
 
 void
 nsSVGElement::AnimationNeedsResample()
 {
-  nsIDocument* doc = GetCurrentDoc();
+  nsIDocument* doc = GetComposedDoc();
   if (doc && doc->HasAnimationController()) {
     doc->GetAnimationController()->SetResampleNeeded();
   }
 }
 
 void
 nsSVGElement::FlushAnimations()
 {
-  nsIDocument* doc = GetCurrentDoc();
+  nsIDocument* doc = GetComposedDoc();
   if (doc && doc->HasAnimationController()) {
     doc->GetAnimationController()->FlushResampleRequests();
   }
 }
--- a/content/svg/content/src/nsSVGFeatures.cpp
+++ b/content/svg/content/src/nsSVGFeatures.cpp
@@ -20,17 +20,17 @@
 using namespace mozilla;
 
 /*static*/ bool
 nsSVGFeatures::HasFeature(nsISupports* aObject, const nsAString& aFeature)
 {
   if (aFeature.EqualsLiteral("http://www.w3.org/TR/SVG11/feature#Script")) {
     nsCOMPtr<nsIContent> content(do_QueryInterface(aObject));
     if (content) {
-      nsIDocument *doc = content->GetCurrentDoc();
+      nsIDocument* doc = content->GetUncomposedDoc();
       if (doc && doc->IsResourceDoc()) {
         // no scripting in SVG images or external resource documents
         return false;
       }
     }
     return Preferences::GetBool("javascript.enabled", false);
   }
 #define SVG_SUPPORTED_FEATURE(str) if (aFeature.EqualsLiteral(str)) return true;