2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
#ifndef mozilla_dom_SVGSVGElement_h
|
|
|
|
#define mozilla_dom_SVGSVGElement_h
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
#include "SVGViewportElement.h"
|
2007-06-21 01:56:03 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
nsresult NS_NewSVGSVGElement(
|
2014-06-20 06:01:40 +04:00
|
|
|
nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-01-10 03:02:45 +04:00
|
|
|
mozilla::dom::FromParser aFromParser);
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
class nsSMILTimeContainer;
|
2013-01-08 07:22:41 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
namespace mozilla {
|
2017-06-14 15:38:10 +03:00
|
|
|
class AutoSVGViewHandler;
|
|
|
|
class SVGFragmentIdentifier;
|
|
|
|
class EventChainPreVisitor;
|
2014-04-12 01:26:29 +04:00
|
|
|
class DOMSVGLength;
|
2014-05-30 11:36:52 +04:00
|
|
|
class DOMSVGNumber;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
namespace dom {
|
2013-01-10 03:02:47 +04:00
|
|
|
class SVGAngle;
|
2013-01-12 00:30:21 +04:00
|
|
|
class SVGMatrix;
|
2013-03-26 19:53:13 +04:00
|
|
|
class SVGIRect;
|
2013-01-10 03:02:45 +04:00
|
|
|
class SVGSVGElement;
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// Stores svgView arguments of SVG fragment identifiers.
|
|
|
|
class SVGView {
|
|
|
|
public:
|
|
|
|
SVGView();
|
|
|
|
|
|
|
|
nsSVGEnum mZoomAndPan;
|
|
|
|
nsSVGViewBox mViewBox;
|
|
|
|
SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
|
|
|
|
nsAutoPtr<nsSVGAnimatedTransformList> mTransforms;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMSVGTranslatePoint final : public nsISVGPoint {
|
2009-04-28 17:25:03 +04:00
|
|
|
public:
|
2017-06-14 15:38:10 +03:00
|
|
|
DOMSVGTranslatePoint(SVGPoint* aPt, SVGSVGElement* aElement)
|
2014-08-06 17:58:57 +04:00
|
|
|
: nsISVGPoint(aPt, true), mElement(aElement) {}
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit DOMSVGTranslatePoint(DOMSVGTranslatePoint* aPt)
|
2014-08-06 17:58:57 +04:00
|
|
|
: nsISVGPoint(&aPt->mPt, true), mElement(aPt->mElement) {}
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2013-03-04 19:40:25 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMSVGTranslatePoint, nsISVGPoint)
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual DOMSVGPoint* Copy() override;
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
// WebIDL
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual float X() override { return mPt.GetX(); }
|
|
|
|
virtual float Y() override { return mPt.GetY(); }
|
|
|
|
virtual void SetX(float aValue, ErrorResult& rv) override;
|
|
|
|
virtual void SetY(float aValue, ErrorResult& rv) override;
|
|
|
|
virtual already_AddRefed<nsISVGPoint> MatrixTransform(
|
|
|
|
SVGMatrix& matrix) override;
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsISupports* GetParentObject() override;
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGSVGElement> mElement;
|
2014-07-09 01:23:16 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~DOMSVGTranslatePoint() {}
|
2009-04-28 17:25:03 +04:00
|
|
|
};
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
typedef SVGViewportElement SVGSVGElementBase;
|
2013-01-10 03:02:45 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class SVGSVGElement final : public SVGSVGElementBase {
|
2013-01-10 03:02:45 +04:00
|
|
|
friend class ::nsSVGOuterSVGFrame;
|
2012-05-17 14:02:41 +04:00
|
|
|
friend class mozilla::SVGFragmentIdentifier;
|
2015-12-14 03:58:01 +03:00
|
|
|
friend class mozilla::AutoSVGViewHandler;
|
2017-06-14 15:38:10 +03:00
|
|
|
friend class mozilla::AutoPreserveAspectRatioOverride;
|
|
|
|
friend class mozilla::dom::SVGView;
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
protected:
|
2018-09-21 23:45:49 +03:00
|
|
|
SVGSVGElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-01-10 03:02:45 +04:00
|
|
|
FromParser aFromParser);
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2007-03-09 19:27:01 +03:00
|
|
|
|
2017-10-24 10:06:56 +03:00
|
|
|
friend nsresult(::NS_NewSVGSVGElement(
|
|
|
|
nsIContent** aResult,
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
|
|
|
mozilla::dom::FromParser aFromParser));
|
2013-01-10 03:02:45 +04:00
|
|
|
|
2014-06-24 20:36:45 +04:00
|
|
|
~SVGSVGElement();
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
public:
|
2006-04-14 19:09:39 +04:00
|
|
|
// interfaces:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-01-10 03:02:45 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGSVGElement, SVGSVGElementBase)
|
|
|
|
|
2007-06-21 01:56:03 +04:00
|
|
|
/**
|
|
|
|
* 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).
|
2017-03-28 15:55:05 +03:00
|
|
|
*
|
|
|
|
* XXX SVGZoomEvent is no more, is this needed?
|
2007-06-21 01:56:03 +04:00
|
|
|
*/
|
2013-02-08 23:55:07 +04:00
|
|
|
void SetCurrentScaleTranslate(float s, float x, float y);
|
2007-06-21 01:56:03 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
// nsIContent interface
|
2018-04-05 20:42:41 +03:00
|
|
|
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual bool IsEventAttributeNameInternal(nsAtom* aName) override;
|
2013-01-03 00:24:07 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// nsINode methods:
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2006-04-27 01:02:25 +04:00
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
// WebIDL
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength> X();
|
|
|
|
already_AddRefed<SVGAnimatedLength> Y();
|
|
|
|
already_AddRefed<SVGAnimatedLength> Width();
|
|
|
|
already_AddRefed<SVGAnimatedLength> Height();
|
2013-01-10 03:02:47 +04:00
|
|
|
bool UseCurrentView();
|
|
|
|
float CurrentScale();
|
2013-02-08 23:55:07 +04:00
|
|
|
void SetCurrentScale(float aCurrentScale);
|
2013-01-10 03:02:47 +04:00
|
|
|
already_AddRefed<nsISVGPoint> CurrentTranslate();
|
2013-02-08 23:55:07 +04:00
|
|
|
void SetCurrentTranslate(float x, float y);
|
2013-01-10 03:02:47 +04:00
|
|
|
uint32_t SuspendRedraw(uint32_t max_wait_milliseconds);
|
2013-02-08 23:55:07 +04:00
|
|
|
void UnsuspendRedraw(uint32_t suspend_handle_id);
|
|
|
|
void UnsuspendRedrawAll();
|
2015-01-24 12:35:22 +03:00
|
|
|
void ForceRedraw();
|
2013-02-08 23:55:07 +04:00
|
|
|
void PauseAnimations();
|
|
|
|
void UnpauseAnimations();
|
|
|
|
bool AnimationsPaused();
|
|
|
|
float GetCurrentTime();
|
|
|
|
void SetCurrentTime(float seconds);
|
2013-07-03 11:41:53 +04:00
|
|
|
void DeselectAll();
|
2014-05-30 11:36:52 +04:00
|
|
|
already_AddRefed<DOMSVGNumber> CreateSVGNumber();
|
2014-04-12 01:26:29 +04:00
|
|
|
already_AddRefed<DOMSVGLength> CreateSVGLength();
|
2013-01-10 03:02:47 +04:00
|
|
|
already_AddRefed<SVGAngle> CreateSVGAngle();
|
|
|
|
already_AddRefed<nsISVGPoint> CreateSVGPoint();
|
2013-01-12 00:30:21 +04:00
|
|
|
already_AddRefed<SVGMatrix> CreateSVGMatrix();
|
2013-03-26 19:53:13 +04:00
|
|
|
already_AddRefed<SVGIRect> CreateSVGRect();
|
2013-04-02 23:17:41 +04:00
|
|
|
already_AddRefed<SVGTransform> CreateSVGTransform();
|
|
|
|
already_AddRefed<SVGTransform> CreateSVGTransformFromMatrix(
|
|
|
|
SVGMatrix& matrix);
|
2013-11-01 23:39:24 +04:00
|
|
|
using nsINode::GetElementById; // This does what we want
|
2013-01-10 03:02:47 +04:00
|
|
|
uint16_t ZoomAndPan();
|
|
|
|
void SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv);
|
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
// nsSVGElement overrides
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
|
2017-06-14 15:38:10 +03:00
|
|
|
virtual nsSVGAnimatedTransformList* GetAnimatedTransformList(
|
|
|
|
uint32_t aFlags = 0) override;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// SVGSVGElement methods:
|
2012-09-09 15:44:03 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// Returns true IFF our attributes are currently overridden by a <view>
|
|
|
|
// element and that element's ID matches the passed-in string.
|
|
|
|
bool IsOverriddenBy(const nsAString& aViewID) const {
|
|
|
|
return mCurrentViewID && mCurrentViewID->Equals(aViewID);
|
|
|
|
}
|
2012-05-17 14:02:41 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
nsSMILTimeContainer* GetTimedDocumentRoot();
|
2012-05-17 14:02:41 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// public helpers:
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2011-02-26 13:21:11 +03:00
|
|
|
/**
|
2017-06-14 15:38:10 +03:00
|
|
|
* Returns -1 if the width/height is a percentage, else returns the user unit
|
|
|
|
* length clamped to fit in a int32_t.
|
|
|
|
* XXX see bug 1112533 comment 3 - we should fix drawImage so that we can
|
|
|
|
* change these methods to make zero the error flag for percentages.
|
2011-02-26 13:21:11 +03:00
|
|
|
*/
|
2017-06-14 15:38:10 +03:00
|
|
|
int32_t GetIntrinsicWidth();
|
|
|
|
int32_t GetIntrinsicHeight();
|
|
|
|
|
|
|
|
// This services any pending notifications for the transform on on this root
|
|
|
|
// <svg> node needing to be recalculated. (Only applicable in
|
|
|
|
// SVG-as-an-image documents.)
|
|
|
|
virtual void FlushImageTransformInvalidation();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// SVGViewportElement methods:
|
|
|
|
|
|
|
|
virtual SVGViewElement* GetCurrentViewElement() const;
|
|
|
|
virtual SVGPreserveAspectRatio GetPreserveAspectRatioWithOverride()
|
|
|
|
const override;
|
|
|
|
|
|
|
|
// implementation helpers:
|
|
|
|
|
|
|
|
/*
|
2009-01-15 07:38:07 +03:00
|
|
|
* While binding to the tree we need to determine if we will be the outermost
|
|
|
|
* <svg> element _before_ the children are bound (as they want to know what
|
|
|
|
* timed document root to register with) and therefore _before_ our parent is
|
2012-11-15 02:10:08 +04:00
|
|
|
* set (both actions are performed by Element::BindToTree) so we
|
2009-01-15 07:38:07 +03:00
|
|
|
* can't use GetOwnerSVGElement() as it relies on GetParent(). This code is
|
|
|
|
* basically a simplified version of GetOwnerSVGElement that uses the parent
|
|
|
|
* parameters passed in instead.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool WillBeOutermostSVG(nsIContent* aParent,
|
2012-05-17 14:02:41 +04:00
|
|
|
nsIContent* aBindingParent) const;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2007-01-04 17:39:54 +03:00
|
|
|
// invalidate viewbox -> viewport xform & inform frames
|
|
|
|
void InvalidateTransformNotifyFrame();
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// Methods for <image> elements to override my "PreserveAspectRatio" value.
|
|
|
|
// These are private so that only our friends
|
|
|
|
// (AutoPreserveAspectRatioOverride in particular) have access.
|
|
|
|
void SetImageOverridePreserveAspectRatio(const SVGPreserveAspectRatio& aPAR);
|
|
|
|
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();
|
2012-05-17 14:02:41 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
virtual SVGPoint GetCurrentTranslate() const override {
|
|
|
|
return mCurrentTranslate;
|
|
|
|
}
|
|
|
|
virtual float GetCurrentScale() const override { return mCurrentScale; }
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
virtual const nsSVGViewBox& GetViewBoxInternal() const override;
|
|
|
|
virtual nsSVGAnimatedTransformList* GetTransformInternal() const override;
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual EnumAttributesInfo GetEnumInfo() override;
|
2007-08-28 03:11:14 +04:00
|
|
|
|
|
|
|
enum { ZOOMANDPAN };
|
|
|
|
nsSVGEnum mEnumAttributes[1];
|
|
|
|
static nsSVGEnumMapping sZoomAndPanMap[];
|
|
|
|
static EnumInfo sEnumInfo[1];
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
// The time container for animations within this SVG document fragment. Set
|
|
|
|
// for all outermost <svg> elements (not nested <svg> elements).
|
|
|
|
nsAutoPtr<nsSMILTimeContainer> mTimedDocumentRoot;
|
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
// zoom and pan
|
2009-04-28 17:25:03 +04:00
|
|
|
// IMPORTANT: see the comment in RecordCurrentScaleTranslate before writing
|
|
|
|
// code to change any of these!
|
2013-01-17 05:35:24 +04:00
|
|
|
SVGPoint mCurrentTranslate;
|
|
|
|
float mCurrentScale;
|
|
|
|
SVGPoint mPreviousTranslate;
|
|
|
|
float mPreviousScale;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// 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.
|
2013-01-17 05:35:24 +04:00
|
|
|
bool mStartAnimationOnBindToTree;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
bool mImageNeedsTransformInvalidation;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
// mCurrentViewID and mSVGView are mutually exclusive; we can have
|
|
|
|
// at most one non-null.
|
|
|
|
nsAutoPtr<nsString> mCurrentViewID;
|
|
|
|
nsAutoPtr<SVGView> mSVGView;
|
2006-04-14 19:09:39 +04:00
|
|
|
};
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
} // namespace dom
|
2013-03-01 00:22:43 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
class MOZ_RAII AutoSVGTimeSetRestore {
|
|
|
|
public:
|
|
|
|
AutoSVGTimeSetRestore(dom::SVGSVGElement* aRootElem,
|
|
|
|
float aFrameTime MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: mRootElem(aRootElem), mOriginalTime(mRootElem->GetCurrentTime()) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
mRootElem->SetCurrentTime(
|
|
|
|
aFrameTime); // Does nothing if there's no change.
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSVGTimeSetRestore() { mRootElem->SetCurrentTime(mOriginalTime); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const RefPtr<dom::SVGSVGElement> mRootElem;
|
|
|
|
const float mOriginalTime;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2017-04-03 12:40:13 +03:00
|
|
|
class MOZ_RAII AutoPreserveAspectRatioOverride {
|
2013-03-01 00:22:43 +04:00
|
|
|
public:
|
2017-04-03 12:40:13 +03:00
|
|
|
AutoPreserveAspectRatioOverride(const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
dom::SVGSVGElement* aRootElem
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: mRootElem(aRootElem), mDidOverride(false) {
|
2013-03-01 00:22:43 +04:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2017-06-14 15:38:10 +03:00
|
|
|
MOZ_ASSERT(mRootElem, "No SVG/Symbol node to manage?");
|
2017-04-03 12:40:13 +03:00
|
|
|
|
|
|
|
if (aSVGContext.isSome() &&
|
|
|
|
aSVGContext->GetPreserveAspectRatio().isSome()) {
|
2013-03-01 00:22:43 +04:00
|
|
|
// Override preserveAspectRatio in our helper document.
|
|
|
|
// XXXdholbert We should technically be overriding the helper doc's clip
|
|
|
|
// and overflow properties here, too. See bug 272288 comment 36.
|
|
|
|
mRootElem->SetImageOverridePreserveAspectRatio(
|
2017-04-03 12:40:13 +03:00
|
|
|
*aSVGContext->GetPreserveAspectRatio());
|
|
|
|
mDidOverride = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoPreserveAspectRatioOverride() {
|
|
|
|
if (mDidOverride) {
|
|
|
|
mRootElem->ClearImageOverridePreserveAspectRatio();
|
2013-03-01 00:22:43 +04:00
|
|
|
}
|
2017-04-03 12:40:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const RefPtr<dom::SVGSVGElement> mRootElem;
|
|
|
|
bool mDidOverride;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
2013-03-11 05:43:37 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // SVGSVGElement_h
|