Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 7480046

Browse files
committed
Bug 1915971 - Simplify PrependLocalTransformsTo. r=longsonr
Now that there's only one transform kind seems worth doing this. Differential Revision: https://phabricator.services.mozilla.com/D220733
1 parent 1996897 commit 7480046

18 files changed

+49
-124
lines changed

dom/svg/SVGContentUtils.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,15 +496,12 @@ static gfx::Matrix GetCTMInternal(SVGElement* aElement, CTMType aCTMType,
496496
auto getLocalTransformHelper =
497497
[](SVGElement const* e, bool shouldIncludeChildToUserSpace) -> gfxMatrix {
498498
gfxMatrix ret;
499-
500499
if (auto* f = e->GetPrimaryFrame()) {
501500
ret = SVGUtils::GetTransformMatrixInUserSpace(f);
502501
}
503-
504502
if (shouldIncludeChildToUserSpace) {
505-
ret = e->PrependLocalTransformsTo({}, eChildToUserSpace) * ret;
503+
ret = e->ChildToUserSpaceTransform() * ret;
506504
}
507-
508505
return ret;
509506
};
510507

dom/svg/SVGContentUtils.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,6 @@ class SVGViewportElement;
4141

4242
#define SVG_ZERO_LENGTH_PATH_FIX_FACTOR 512
4343

44-
/**
45-
* SVGTransformTypes controls the transforms that PrependLocalTransformsTo
46-
* applies.
47-
*
48-
* If aWhich is eAllTransforms, then all the transforms from the coordinate
49-
* space established by this element for its children to the coordinate
50-
* space established by this element's parent element for this element, are
51-
* included.
52-
*
53-
* If aWhich is eChildToUserSpace, then only the transforms from the
54-
* coordinate space established by this element for its childre to this
55-
* elements userspace are included. This includes any offsets due to e.g.
56-
* 'x'/'y' attributes, and any transform due to a 'viewBox' attribute, but
57-
* does not include any transforms due to the 'transform' attribute.
58-
*/
59-
enum SVGTransformTypes {
60-
eAllTransforms,
61-
eChildToUserSpace
62-
};
63-
6444
/**
6545
* Functions generally used by SVG Content classes. Functions here
6646
* should not generally depend on layout methods/classes e.g. SVGUtils

dom/svg/SVGElement.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,10 +1564,7 @@ SVGViewportElement* SVGElement::GetCtx() const {
15641564
}
15651565

15661566
/* virtual */
1567-
gfxMatrix SVGElement::PrependLocalTransformsTo(const gfxMatrix& aMatrix,
1568-
SVGTransformTypes aWhich) const {
1569-
return aMatrix;
1570-
}
1567+
gfxMatrix SVGElement::ChildToUserSpaceTransform() const { return {}; }
15711568

15721569
SVGElement::LengthAttributesInfo SVGElement::GetLengthInfo() {
15731570
return LengthAttributesInfo(nullptr, nullptr, 0);

dom/svg/SVGElement.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,12 @@ class SVGElement : public SVGElementBase // nsIContent
135135
mozilla::dom::SVGViewportElement* GetCtx() const;
136136

137137
/**
138-
* Returns aMatrix pre-multiplied by (explicit or implicit) transforms that
139-
* are introduced by attributes on this element.
140-
*
141-
* If aWhich is eAllTransforms, then all the transforms from the coordinate
142-
* space established by this element for its children to the coordinate
143-
* space established by this element's parent element for this element, are
144-
* included.
145-
*
146-
* If aWhich is eChildToUserSpace, then only the transforms from the
147-
* coordinate space established by this element for its childre to this
148-
* elements userspace are included. This includes any offsets due to e.g.
149-
* 'x'/'y' attributes, and any transform due to a 'viewBox' attribute, but
150-
* does not include any transforms due to the 'transform' attribute.
138+
* Returns the transforms from the coordinate space established by this
139+
* element for its children to this element's userspace. This includes any
140+
* offsets due to e.g. 'x'/'y' attributes, and any transform due to a
141+
* 'viewBox' attribute.
151142
*/
152-
virtual gfxMatrix PrependLocalTransformsTo(
153-
const gfxMatrix& aMatrix,
154-
SVGTransformTypes aWhich = eAllTransforms) const;
143+
virtual gfxMatrix ChildToUserSpaceTransform() const;
155144

156145
// Setter for to set the current <animateMotion> transformation
157146
// Only visible for SVGGraphicElement, so it's a no-op here, and that

dom/svg/SVGForeignObjectElement.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,16 @@ already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::Height() {
6868
//----------------------------------------------------------------------
6969
// SVGElement methods
7070

71-
/* virtual */
72-
gfxMatrix SVGForeignObjectElement::PrependLocalTransformsTo(
73-
const gfxMatrix& aMatrix, SVGTransformTypes aWhich) const {
71+
gfxMatrix SVGForeignObjectElement::ChildToUserSpaceTransform() const {
7472
// our 'x' and 'y' attributes:
7573
float x, y;
76-
7774
if (!SVGGeometryProperty::ResolveAll<SVGT::X, SVGT::Y>(this, &x, &y)) {
7875
// This function might be called for element in display:none subtree
7976
// (e.g. getScreenCTM), we fall back to use SVG attributes.
8077
const_cast<SVGForeignObjectElement*>(this)->GetAnimatedLengthValues(
8178
&x, &y, nullptr);
8279
}
83-
84-
gfxMatrix toUserSpace = gfxMatrix::Translation(x, y);
85-
MOZ_ASSERT(aWhich == eAllTransforms || aWhich == eChildToUserSpace,
86-
"Unknown TransformTypes");
87-
return toUserSpace * aMatrix;
80+
return gfxMatrix::Translation(x, y);
8881
}
8982

9083
/* virtual */

dom/svg/SVGForeignObjectElement.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class SVGForeignObjectElement final : public SVGGraphicsElement {
3232

3333
public:
3434
// SVGElement specializations:
35-
gfxMatrix PrependLocalTransformsTo(
36-
const gfxMatrix& aMatrix,
37-
SVGTransformTypes aWhich = eAllTransforms) const override;
35+
gfxMatrix ChildToUserSpaceTransform() const override;
3836
bool HasValidDimensions() const override;
3937

4038
// nsIContent interface

dom/svg/SVGSVGElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "SVGAnimatedEnumeration.h"
1111
#include "SVGViewportElement.h"
12+
#include "mozilla/SVGImageContext.h"
1213

1314
nsresult NS_NewSVGSVGElement(
1415
nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,

dom/svg/SVGUseElement.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,18 +604,12 @@ void SVGUseElement::UnlinkSource() {
604604
// SVGElement methods
605605

606606
/* virtual */
607-
gfxMatrix SVGUseElement::PrependLocalTransformsTo(
608-
const gfxMatrix& aMatrix, SVGTransformTypes aWhich) const {
609-
// our 'x' and 'y' attributes:
607+
gfxMatrix SVGUseElement::ChildToUserSpaceTransform() const {
610608
float x, y;
611609
if (!SVGGeometryProperty::ResolveAll<SVGT::X, SVGT::Y>(this, &x, &y)) {
612610
const_cast<SVGUseElement*>(this)->GetAnimatedLengthValues(&x, &y, nullptr);
613611
}
614-
615-
gfxMatrix childToUser = gfxMatrix::Translation(x, y);
616-
MOZ_ASSERT(aWhich == eChildToUserSpace || aWhich == eAllTransforms,
617-
"Unknown TransformTypes");
618-
return childToUser * aMatrix;
612+
return gfxMatrix::Translation(x, y);
619613
}
620614

621615
/* virtual */

dom/svg/SVGUseElement.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ class SVGUseElement final : public SVGUseElementBase,
6464
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
6565

6666
// SVGElement specializations:
67-
gfxMatrix PrependLocalTransformsTo(
68-
const gfxMatrix& aMatrix,
69-
SVGTransformTypes aWhich = eAllTransforms) const override;
67+
gfxMatrix ChildToUserSpaceTransform() const override;
7068
bool HasValidDimensions() const override;
7169

7270
// nsIContent interface

dom/svg/SVGViewportElement.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,31 +237,23 @@ float SVGViewportElement::GetLength(uint8_t aCtxType) const {
237237
// SVGElement methods
238238

239239
/* virtual */
240-
gfxMatrix SVGViewportElement::PrependLocalTransformsTo(
241-
const gfxMatrix& aMatrix, SVGTransformTypes aWhich) const {
242-
gfxMatrix childToUser;
243-
240+
gfxMatrix SVGViewportElement::ChildToUserSpaceTransform() const {
241+
auto viewBox = GetViewBoxTransform();
244242
if (IsInner()) {
245243
float x, y;
246244
const_cast<SVGViewportElement*>(this)->GetAnimatedLengthValues(&x, &y,
247245
nullptr);
248-
childToUser = ThebesMatrix(GetViewBoxTransform().PostTranslate(x, y));
249-
} else if (IsRootSVGSVGElement()) {
246+
return ThebesMatrix(viewBox.PostTranslate(x, y));
247+
}
248+
if (IsRootSVGSVGElement()) {
250249
const auto* svg = static_cast<const SVGSVGElement*>(this);
251250
const SVGPoint& translate = svg->GetCurrentTranslate();
252251
float scale = svg->CurrentScale();
253-
childToUser =
254-
ThebesMatrix(GetViewBoxTransform()
255-
.PostScale(scale, scale)
256-
.PostTranslate(translate.GetX(), translate.GetY()));
257-
} else {
258-
// outer-<svg>, but inline in some other content:
259-
childToUser = ThebesMatrix(GetViewBoxTransform());
252+
return ThebesMatrix(viewBox.PostScale(scale, scale)
253+
.PostTranslate(translate.GetX(), translate.GetY()));
260254
}
261-
262-
MOZ_ASSERT(aWhich == eAllTransforms || aWhich == eChildToUserSpace,
263-
"Unknown TransformTypes");
264-
return childToUser * aMatrix;
255+
// outer-<svg>, but inline in some other content:
256+
return ThebesMatrix(viewBox);
265257
}
266258

267259
/* virtual */

0 commit comments

Comments
 (0)