commit c69cfb0f0867e2ebc9f344bce378d6560bb5f241
parent 80aeb4d9892253de1e227ce1810398b73885e046
Author: longsonr <longsonr@gmail.com>
Date: Thu, 11 Dec 2025 19:53:01 +0000
Bug 2005612 - More consistent naming and usage of GetSVGRootElement r=emilio,layout-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D276064
Diffstat:
7 files changed, 21 insertions(+), 33 deletions(-)
diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp
@@ -9758,8 +9758,7 @@ Element* Document::GetTitleElement() {
return nullptr;
}
- Element* root = GetRootElement();
- if (root && root->IsSVGElement(nsGkAtoms::svg)) {
+ if (Element* root = GetSVGRootElement()) {
// In SVG, the document's title must be a child
for (nsIContent* child = root->GetFirstChild(); child;
child = child->GetNextSibling()) {
diff --git a/dom/svg/SVGFragmentIdentifier.cpp b/dom/svg/SVGFragmentIdentifier.cpp
@@ -198,8 +198,7 @@ bool SVGFragmentIdentifier::ProcessMediaFragment(
bool SVGFragmentIdentifier::ProcessFragmentIdentifier(
Document* aDocument, const nsAString& aAnchorName) {
- MOZ_ASSERT(aDocument->GetRootElement()->IsSVGElement(nsGkAtoms::svg),
- "expecting an SVG root element");
+ MOZ_ASSERT(aDocument->GetSVGRootElement(), "expecting an SVG root element");
auto* rootElement = SVGSVGElement::FromNode(aDocument->GetRootElement());
diff --git a/image/AutoRestoreSVGState.h b/image/AutoRestoreSVGState.h
@@ -33,9 +33,9 @@ class MOZ_STACK_CLASS AutoRestoreSVGState final {
: mIsDrawing(aSVGDocumentWrapper->mIsDrawing),
// Apply any 'preserveAspectRatio' override (if specified) to the root
// element:
- mPAR(aSVGContext, aSVGDocumentWrapper->GetRootSVGElem()),
+ mPAR(aSVGContext, aSVGDocumentWrapper->GetSVGRootElement()),
// Set the animation time:
- mTime(aSVGDocumentWrapper->GetRootSVGElem(), aAnimationTime) {
+ mTime(aSVGDocumentWrapper->GetSVGRootElement(), aAnimationTime) {
MOZ_ASSERT(!mIsDrawing.SavedValue());
MOZ_ASSERT(aSVGDocumentWrapper->GetDocument());
diff --git a/image/SVGDocumentWrapper.cpp b/image/SVGDocumentWrapper.cpp
@@ -63,7 +63,7 @@ void SVGDocumentWrapper::DestroyViewer() {
}
nsIFrame* SVGDocumentWrapper::GetRootLayoutFrame() const {
- Element* rootElem = GetRootSVGElem();
+ Element* rootElem = GetSVGRootElement();
return rootElem ? rootElem->GetPrimaryFrame() : nullptr;
}
@@ -88,7 +88,7 @@ void SVGDocumentWrapper::UpdateViewportBounds(const nsIntSize& aViewportSize) {
void SVGDocumentWrapper::FlushImageTransformInvalidation() {
MOZ_ASSERT(!mIgnoreInvalidation, "shouldn't be reentrant");
- SVGSVGElement* svgElem = GetRootSVGElem();
+ SVGSVGElement* svgElem = GetSVGRootElement();
if (!svgElem) {
return;
}
@@ -158,7 +158,7 @@ void SVGDocumentWrapper::StopAnimation() {
}
void SVGDocumentWrapper::ResetAnimation() {
- SVGSVGElement* svgElem = GetRootSVGElem();
+ SVGSVGElement* svgElem = GetSVGRootElement();
if (!svgElem) {
return;
}
@@ -167,12 +167,12 @@ void SVGDocumentWrapper::ResetAnimation() {
}
float SVGDocumentWrapper::GetCurrentTimeAsFloat() const {
- SVGSVGElement* svgElem = GetRootSVGElem();
+ SVGSVGElement* svgElem = GetSVGRootElement();
return svgElem ? svgElem->GetCurrentTimeAsFloat() : 0.0f;
}
void SVGDocumentWrapper::SetCurrentTime(float aTime) {
- SVGSVGElement* svgElem = GetRootSVGElem();
+ SVGSVGElement* svgElem = GetSVGRootElement();
if (svgElem && svgElem->GetCurrentTimeAsFloat() != aTime) {
svgElem->SetCurrentTime(aTime);
}
@@ -231,7 +231,7 @@ SVGDocumentWrapper::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
// Sever ties from rendering observers to helper-doc's root SVG node
- SVGSVGElement* svgElem = GetRootSVGElem();
+ SVGSVGElement* svgElem = GetSVGRootElement();
if (svgElem) {
SVGObserverUtils::RemoveAllRenderingObservers(svgElem);
}
@@ -374,22 +374,13 @@ SVGDocument* SVGDocumentWrapper::GetDocument() const {
return doc->AsSVGDocument();
}
-SVGSVGElement* SVGDocumentWrapper::GetRootSVGElem() const {
+SVGSVGElement* SVGDocumentWrapper::GetSVGRootElement() const {
if (!mViewer) {
return nullptr; // Can happen during destruction
}
Document* doc = mViewer->GetDocument();
- if (!doc) {
- return nullptr; // Can happen during destruction
- }
-
- Element* rootElem = mViewer->GetDocument()->GetRootElement();
- if (!rootElem || !rootElem->IsSVGElement(nsGkAtoms::svg)) {
- return nullptr;
- }
-
- return static_cast<SVGSVGElement*>(rootElem);
+ return doc ? doc->GetSVGRootElement() : nullptr;
}
} // namespace image
diff --git a/image/SVGDocumentWrapper.h b/image/SVGDocumentWrapper.h
@@ -51,7 +51,7 @@ class SVGDocumentWrapper final : public nsIStreamListener,
* Returns the root <svg> element for the wrapped document, or nullptr on
* failure.
*/
- mozilla::dom::SVGSVGElement* GetRootSVGElem() const;
+ mozilla::dom::SVGSVGElement* GetSVGRootElement() const;
/**
* Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
diff --git a/image/VectorImage.cpp b/image/VectorImage.cpp
@@ -87,7 +87,7 @@ class SVGRootRenderingObserver final : public SVGRenderingObserver {
}
Element* GetReferencedElementWithoutObserving() final {
- return mDocWrapper->GetRootSVGElem();
+ return mDocWrapper->GetSVGRootElement();
}
virtual void OnRenderingChange() override {
@@ -458,7 +458,7 @@ VectorImage::GetWidth(int32_t* aWidth) {
return NS_ERROR_FAILURE;
}
- SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
+ SVGSVGElement* rootElem = mSVGDocumentWrapper->GetSVGRootElement();
if (MOZ_UNLIKELY(!rootElem)) {
// Unlikely to reach this code; we should have a root SVG elem, since we
// finished loading without errors. But we can sometimes get here during
@@ -489,7 +489,7 @@ VectorImage::GetHeight(int32_t* aHeight) {
return NS_ERROR_FAILURE;
}
- SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
+ SVGSVGElement* rootElem = mSVGDocumentWrapper->GetSVGRootElement();
if (MOZ_UNLIKELY(!rootElem)) {
// Unlikely to reach this code; we should have a root SVG elem, since we
// finished loading without errors. But we can sometimes get here during
@@ -514,7 +514,7 @@ VectorImage::GetIntrinsicSize(ImageIntrinsicSize* aIntrinsicSize) {
if (mError || !mIsFullyLoaded) {
return NS_ERROR_FAILURE;
}
- SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
+ SVGSVGElement* rootElem = mSVGDocumentWrapper->GetSVGRootElement();
if (MOZ_UNLIKELY(!rootElem)) {
return NS_ERROR_FAILURE;
}
@@ -620,7 +620,7 @@ VectorImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) {
// Look up height & width
// ----------------------
- SVGSVGElement* svgElem = mSVGDocumentWrapper->GetRootSVGElem();
+ SVGSVGElement* svgElem = mSVGDocumentWrapper->GetSVGRootElement();
MOZ_ASSERT(svgElem,
"Should have a root SVG elem, since we finished "
"loading without errors");
@@ -1495,7 +1495,7 @@ void VectorImage::OnSVGDocumentParsed() {
MOZ_ASSERT(mParseCompleteListener, "Should have the parse complete listener");
MOZ_ASSERT(mLoadEventListener, "Should have the load event listener");
- if (!mSVGDocumentWrapper->GetRootSVGElem()) {
+ if (!mSVGDocumentWrapper->GetSVGRootElement()) {
// This is an invalid SVG document. It may have failed to parse, or it may
// be missing the <svg> root element, or the <svg> root element may not
// declare the correct namespace. In any of these cases, we'll never be
@@ -1548,7 +1548,7 @@ void VectorImage::SendInvalidationNotifications() {
}
void VectorImage::OnSVGDocumentLoaded() {
- MOZ_ASSERT(mSVGDocumentWrapper->GetRootSVGElem(),
+ MOZ_ASSERT(mSVGDocumentWrapper->GetSVGRootElement(),
"Should have parsed successfully");
MOZ_ASSERT(!mIsFullyLoaded && !mHaveAnimations,
"These flags shouldn't get set until OnSVGDocumentLoaded. "
diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp
@@ -3055,8 +3055,7 @@ nsresult PresShell::GoToAnchor(const nsAString& aAnchorName,
return NS_ERROR_FAILURE;
}
- const Element* root = mDocument->GetRootElement();
- if (root && root->IsSVGElement(nsGkAtoms::svg)) {
+ if (mDocument->GetSVGRootElement()) {
// We need to execute this even if there is an empty anchor name
// so that any existing SVG fragment identifier effect is removed
if (SVGFragmentIdentifier::ProcessFragmentIdentifier(mDocument,