Bug 265894 - Part 4. Move translate/scale back to SVGSVGElement.
MozReview-Commit-ID: W8rjQjXAxW
--- a/dom/svg/SVGSVGElement.cpp
+++ b/dom/svg/SVGSVGElement.cpp
@@ -129,16 +129,20 @@ NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION
NS_INTERFACE_TABLE_TAIL_INHERITING(SVGSVGElementBase)
//----------------------------------------------------------------------
// Implementation
SVGSVGElement::SVGSVGElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser)
: SVGSVGElementBase(aNodeInfo),
+ mCurrentTranslate(0.0f, 0.0f),
+ mCurrentScale(1.0f),
+ mPreviousTranslate(0.0f, 0.0f),
+ mPreviousScale(1.0f),
mStartAnimationOnBindToTree(aFromParser == NOT_FROM_PARSER ||
aFromParser == FROM_PARSER_FRAGMENT ||
aFromParser == FROM_PARSER_XSLT),
mImageNeedsTransformInvalidation(false)
{
}
SVGSVGElement::~SVGSVGElement()
--- a/dom/svg/SVGSVGElement.h
+++ b/dom/svg/SVGSVGElement.h
@@ -85,22 +85,16 @@ public:
* For use by zoom controls to allow currentScale, currentTranslate.x and
* currentTranslate.y to be set by a single operation that dispatches a
* single SVGZoom event (instead of one SVGZoom and two SVGScroll events).
*
* XXX SVGZoomEvent is no more, is this needed?
*/
void SetCurrentScaleTranslate(float s, float x, float y);
- /**
- * Retrieve the value of currentScale and currentTranslate.
- */
- const SVGPoint& GetCurrentTranslate() { return mCurrentTranslate; }
- float GetCurrentScale() { return mCurrentScale; }
-
// nsIContent interface
virtual nsresult GetEventTargetParent(
EventChainPreVisitor& aVisitor) override;
// nsINode methods:
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
bool aPreallocateChildren) const override;
@@ -216,26 +210,39 @@ private:
void ClearImageOverridePreserveAspectRatio();
// Set/Clear properties to hold old version of preserveAspectRatio
// when it's being overridden by an <image> element that we are inside of.
bool SetPreserveAspectRatioProperty(const SVGPreserveAspectRatio& aPAR);
const SVGPreserveAspectRatio* GetPreserveAspectRatioProperty() const;
bool ClearPreserveAspectRatioProperty();
+ virtual SVGPoint GetCurrentTranslate() const override
+ { return mCurrentTranslate; }
+ virtual float GetCurrentScale() const override
+ { return mCurrentScale; }
+
virtual EnumAttributesInfo GetEnumInfo() override;
nsSVGEnum mEnumAttributes[1];
static nsSVGEnumMapping sZoomAndPanMap[];
static EnumInfo sEnumInfo[1];
// The time container for animations within this SVG document fragment. Set
// for all outermost <svg> elements (not nested <svg> elements).
nsAutoPtr<nsSMILTimeContainer> mTimedDocumentRoot;
+ // zoom and pan
+ // IMPORTANT: see the comment in RecordCurrentScaleTranslate before writing
+ // code to change any of these!
+ SVGPoint mCurrentTranslate;
+ float mCurrentScale;
+ SVGPoint mPreviousTranslate;
+ float mPreviousScale;
+
// For outermost <svg> elements created from parsing, animation is started by
// the onload event in accordance with the SVG spec, but for <svg> elements
// created by script or promoted from inner <svg> to outermost <svg> we need
// to manually kick off animation when they are bound to the tree.
bool mStartAnimationOnBindToTree;
bool mImageNeedsTransformInvalidation;
};
--- a/dom/svg/SVGViewportElement.cpp
+++ b/dom/svg/SVGViewportElement.cpp
@@ -55,20 +55,16 @@ SVGView::SVGView()
//----------------------------------------------------------------------
// Implementation
SVGViewportElement::SVGViewportElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: SVGGraphicsElement(aNodeInfo),
mViewportWidth(0),
mViewportHeight(0),
- mCurrentTranslate(0.0f, 0.0f),
- mCurrentScale(1.0f),
- mPreviousTranslate(0.0f, 0.0f),
- mPreviousScale(1.0f),
mHasChildrenOnlyTransform(false)
{
}
SVGViewportElement::~SVGViewportElement()
{
}
@@ -162,18 +158,18 @@ ComputeSynthesizedViewBoxDimension(const
//----------------------------------------------------------------------
// public helpers:
void
SVGViewportElement::UpdateHasChildrenOnlyTransform()
{
bool hasChildrenOnlyTransform =
HasViewBoxOrSyntheticViewBox() ||
- (IsRoot() && (mCurrentTranslate != SVGPoint(0.0f, 0.0f) ||
- mCurrentScale != 1.0f));
+ (IsRoot() && (GetCurrentTranslate() != SVGPoint(0.0f, 0.0f) ||
+ GetCurrentScale() != 1.0f));
mHasChildrenOnlyTransform = hasChildrenOnlyTransform;
}
void
SVGViewportElement::ChildrenOnlyTransformChanged(uint32_t aFlags)
{
// Avoid wasteful calls:
MOZ_ASSERT(!(GetPrimaryFrame()->GetStateBits() & NS_FRAME_IS_NONDISPLAY),
@@ -308,20 +304,22 @@ SVGViewportElement::PrependLocalTransfor
gfxMatrix childToUser;
if (IsInner()) {
float x, y;
const_cast<SVGViewportElement*>(this)->GetAnimatedLengthValues(&x, &y, nullptr);
childToUser = ThebesMatrix(GetViewBoxTransform().PostTranslate(x, y));
} else if (IsRoot()) {
+ SVGPoint translate = GetCurrentTranslate();
+ float scale = GetCurrentScale();
childToUser = ThebesMatrix(GetViewBoxTransform()
- .PostScale(mCurrentScale, mCurrentScale)
- .PostTranslate(mCurrentTranslate.GetX(),
- mCurrentTranslate.GetY()));
+ .PostScale(scale, scale)
+ .PostTranslate(translate.GetX(),
+ translate.GetY()));
} else {
// outer-<svg>, but inline in some other content:
childToUser = ThebesMatrix(GetViewBoxTransform());
}
if (aWhich == eAllTransforms) {
return childToUser * userToParent * aMatrix;
}
--- a/dom/svg/SVGViewportElement.h
+++ b/dom/svg/SVGViewportElement.h
@@ -178,16 +178,24 @@ protected:
/**
* Returns the explicit viewBox rect, if specified, or else a synthesized
* viewBox, if appropriate, or else a viewBox matching the dimensions of the
* SVG viewport.
*/
nsSVGViewBoxRect GetViewBoxWithSynthesis(
float aViewportWidth, float aViewportHeight) const;
+ /**
+ * Retrieve the value of currentScale and currentTranslate.
+ */
+ virtual SVGPoint GetCurrentTranslate() const
+ { return SVGPoint(0.0f, 0.0f); }
+ virtual float GetCurrentScale() const
+ { return 1.0f; }
+
enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
nsSVGLength2 mLengthAttributes[4];
static LengthInfo sLengthInfo[4];
virtual LengthAttributesInfo GetLengthInfo() override;
enum { ZOOMANDPAN };
virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio() override;
@@ -205,24 +213,16 @@ protected:
//
// http://www.w3.org/TR/SVG11/coords.html#ViewportSpace
//
// XXXjwatt Currently only used for outer <svg>, but maybe we could use -1 to
// flag this as an inner <svg> to save the overhead of GetCtx calls?
// XXXjwatt our frame should probably reset these when it's destroyed.
float mViewportWidth, mViewportHeight;
- // zoom and pan
- // IMPORTANT: see the comment in RecordCurrentScaleTranslate before writing
- // code to change any of these!
- SVGPoint mCurrentTranslate;
- float mCurrentScale;
- SVGPoint mPreviousTranslate;
- float mPreviousScale;
-
bool mHasChildrenOnlyTransform;
};
} // namespace dom
} // namespace mozilla
#endif // SVGViewportElement_h