@@ -489,7 +489,9 @@ SVGViewportElement* SVGContentUtils::GetNearestViewportElement(
489489 return nullptr ;
490490}
491491
492- static gfx::Matrix GetCTMInternal (SVGElement* aElement, bool aScreenCTM,
492+ enum class CTMType { NearestViewport, OuterViewport, Screen };
493+
494+ static gfx::Matrix GetCTMInternal (SVGElement* aElement, CTMType aCTMType,
493495 bool aHaveRecursed) {
494496 auto getLocalTransformHelper =
495497 [](SVGElement const * e, bool shouldIncludeChildToUserSpace) -> gfxMatrix {
@@ -530,7 +532,8 @@ static gfx::Matrix GetCTMInternal(SVGElement* aElement, bool aScreenCTM,
530532 !ancestor->IsSVGElement (nsGkAtoms::foreignObject)) {
531533 element = static_cast <SVGElement*>(ancestor);
532534 matrix *= getLocalTransformHelper (element, true );
533- if (!aScreenCTM && SVGContentUtils::EstablishesViewport (element)) {
535+ if (aCTMType == CTMType::NearestViewport &&
536+ SVGContentUtils::EstablishesViewport (element)) {
534537 if (!element->IsAnyOfSVGElements (nsGkAtoms::svg, nsGkAtoms::symbol)) {
535538 NS_ERROR (" New (SVG > 1.1) SVG viewport establishing element?" );
536539 return gfx::Matrix (0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ); // singular
@@ -540,7 +543,7 @@ static gfx::Matrix GetCTMInternal(SVGElement* aElement, bool aScreenCTM,
540543 }
541544 ancestor = ancestor->GetFlattenedTreeParent ();
542545 }
543- if (!aScreenCTM ) {
546+ if (aCTMType == CTMType::NearestViewport ) {
544547 // didn't find a nearestViewportElement
545548 return gfx::Matrix (0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ); // singular
546549 }
@@ -568,13 +571,16 @@ static gfx::Matrix GetCTMInternal(SVGElement* aElement, bool aScreenCTM,
568571 int32_t appUnitsPerCSSPixel = AppUnitsPerCSSPixel ();
569572 tm.PostTranslate (NSAppUnitsToFloatPixels(bp.left , appUnitsPerCSSPixel),
570573 NSAppUnitsToFloatPixels (bp.top, appUnitsPerCSSPixel));
574+ if (aCTMType == CTMType::OuterViewport) {
575+ return tm;
576+ }
571577 }
572578
573579 if (!ancestor || !ancestor->IsElement ()) {
574580 return tm;
575581 }
576582 if (auto * ancestorSVG = SVGElement::FromNode (ancestor)) {
577- return tm * GetCTMInternal (ancestorSVG, true , true );
583+ return tm * GetCTMInternal (ancestorSVG, aCTMType , true );
578584 }
579585 nsIFrame* parentFrame = frame->GetParent ();
580586 if (!parentFrame) {
@@ -612,16 +618,20 @@ static gfx::Matrix GetCTMInternal(SVGElement* aElement, bool aScreenCTM,
612618 }
613619 return nearestSVGAncestor
614620 ? tm * GetCTMInternal (static_cast <SVGElement*>(nearestSVGAncestor),
615- true , true )
621+ aCTMType , true )
616622 : tm;
617623}
618624
619625gfx::Matrix SVGContentUtils::GetCTM (SVGElement* aElement) {
620- return GetCTMInternal (aElement, false , false );
626+ return GetCTMInternal (aElement, CTMType::NearestViewport, false );
627+ }
628+
629+ gfx::Matrix SVGContentUtils::GetOuterViewportCTM (SVGElement* aElement) {
630+ return GetCTMInternal (aElement, CTMType::OuterViewport, false );
621631}
622632
623633gfx::Matrix SVGContentUtils::GetScreenCTM (SVGElement* aElement) {
624- return GetCTMInternal (aElement, true , false );
634+ return GetCTMInternal (aElement, CTMType::Screen , false );
625635}
626636
627637void SVGContentUtils::RectilinearGetStrokeBounds (
0 commit comments