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
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_SVGSVGELEMENT_H_
|
|
|
|
#define DOM_SVG_SVGSVGELEMENT_H_
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedEnumeration.h"
|
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);
|
|
|
|
|
2020-08-25 17:38:32 +03:00
|
|
|
// {4b83982c-e5e9-4ca1-abd4-14d27e8b3531}
|
|
|
|
#define MOZILLA_SVGSVGELEMENT_IID \
|
|
|
|
{ \
|
|
|
|
0x4b83982c, 0xe5e9, 0x4ca1, { \
|
|
|
|
0xab, 0xd4, 0x14, 0xd2, 0x7e, 0x8b, 0x35, 0x31 \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
namespace mozilla {
|
2017-06-14 15:38:10 +03:00
|
|
|
class AutoSVGViewHandler;
|
2019-01-02 10:21:13 +03:00
|
|
|
class SMILTimeContainer;
|
2017-06-14 15:38:10 +03:00
|
|
|
class SVGFragmentIdentifier;
|
|
|
|
class EventChainPreVisitor;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
namespace dom {
|
2020-06-14 10:26:27 +03:00
|
|
|
struct DOMMatrix2DInit;
|
2018-12-30 21:18:30 +03:00
|
|
|
class DOMSVGAngle;
|
2018-12-28 16:42:46 +03:00
|
|
|
class DOMSVGLength;
|
|
|
|
class DOMSVGNumber;
|
2020-08-25 17:38:32 +03:00
|
|
|
class DOMSVGPoint;
|
2013-01-12 00:30:21 +04:00
|
|
|
class SVGMatrix;
|
2019-06-20 17:03:54 +03:00
|
|
|
class SVGRect;
|
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();
|
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedEnumeration mZoomAndPan;
|
|
|
|
SVGAnimatedViewBox mViewBox;
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
|
2020-02-25 23:03:26 +03:00
|
|
|
UniquePtr<SVGAnimatedTransformList> mTransforms;
|
2017-06-14 15:38:10 +03:00
|
|
|
};
|
|
|
|
|
2020-07-15 13:37:55 +03:00
|
|
|
using SVGSVGElementBase = SVGViewportElement;
|
2013-01-10 03:02:45 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class SVGSVGElement final : public SVGSVGElementBase {
|
2012-05-17 14:02:41 +04:00
|
|
|
friend class mozilla::SVGFragmentIdentifier;
|
2020-07-09 04:33:33 +03:00
|
|
|
friend class mozilla::SVGOuterSVGFrame;
|
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);
|
2022-12-03 22:18:26 +03:00
|
|
|
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
|
|
|
|
2019-04-18 01:38:02 +03:00
|
|
|
~SVGSVGElement() = default;
|
2014-06-24 20:36:45 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
public:
|
2023-01-24 01:15:15 +03:00
|
|
|
NS_IMPL_FROMNODE_WITH_TAG(SVGSVGElement, kNameSpaceID_SVG, svg)
|
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
// interfaces:
|
2020-08-25 17:38:32 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_SVGSVGELEMENT_IID)
|
2006-04-14 19:09:39 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-01-10 03:02:45 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGSVGElement, SVGSVGElementBase)
|
|
|
|
|
2020-08-25 17:38:32 +03:00
|
|
|
/*
|
|
|
|
* Send appropriate events and updates if our root translate
|
|
|
|
* has changed.
|
2007-06-21 01:56:03 +04:00
|
|
|
*/
|
2020-08-25 17:38:32 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
void DidChangeTranslate();
|
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;
|
2022-12-03 22:18:26 +03:00
|
|
|
bool IsEventAttributeNameInternal(nsAtom* aName) override;
|
2013-01-03 00:24:07 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// nsINode methods:
|
2022-12-03 22:18:26 +03:00
|
|
|
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
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> X();
|
|
|
|
already_AddRefed<DOMSVGAnimatedLength> Y();
|
|
|
|
already_AddRefed<DOMSVGAnimatedLength> Width();
|
|
|
|
already_AddRefed<DOMSVGAnimatedLength> Height();
|
2020-08-25 17:38:32 +03:00
|
|
|
bool UseCurrentView() const;
|
|
|
|
float CurrentScale() const;
|
2013-02-08 23:55:07 +04:00
|
|
|
void SetCurrentScale(float aCurrentScale);
|
2020-08-25 17:38:32 +03:00
|
|
|
already_AddRefed<DOMSVGPoint> CurrentTranslate();
|
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();
|
2018-12-21 08:37:58 +03:00
|
|
|
float GetCurrentTimeAsFloat();
|
2013-02-08 23:55:07 +04:00
|
|
|
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();
|
2018-12-30 21:18:30 +03:00
|
|
|
already_AddRefed<DOMSVGAngle> CreateSVGAngle();
|
2020-08-25 17:38:32 +03:00
|
|
|
already_AddRefed<DOMSVGPoint> CreateSVGPoint();
|
2013-01-12 00:30:21 +04:00
|
|
|
already_AddRefed<SVGMatrix> CreateSVGMatrix();
|
2019-06-20 17:03:54 +03:00
|
|
|
already_AddRefed<SVGRect> CreateSVGRect();
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> CreateSVGTransform();
|
|
|
|
already_AddRefed<DOMSVGTransform> CreateSVGTransformFromMatrix(
|
2020-06-14 10:26:27 +03:00
|
|
|
const DOMMatrix2DInit& matrix, ErrorResult& rv);
|
2013-11-01 23:39:24 +04:00
|
|
|
using nsINode::GetElementById; // This does what we want
|
2020-08-25 17:38:32 +03:00
|
|
|
uint16_t ZoomAndPan() const;
|
2013-01-10 03:02:47 +04:00
|
|
|
void SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv);
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement overrides
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2022-12-03 22:18:26 +03:00
|
|
|
nsresult BindToTree(BindContext&, nsINode& aParent) override;
|
|
|
|
void UnbindFromTree(bool aNullParent) override;
|
|
|
|
SVGAnimatedTransformList* GetAnimatedTransformList(
|
2017-06-14 15:38:10 +03:00
|
|
|
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
|
|
|
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* 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
|
|
|
|
2020-08-25 17:38:32 +03:00
|
|
|
const SVGPoint& GetCurrentTranslate() const { return mCurrentTranslate; }
|
|
|
|
bool IsScaledOrTranslated() const {
|
|
|
|
return mCurrentTranslate != SVGPoint() || mCurrentScale != 1.0f;
|
|
|
|
}
|
|
|
|
|
2023-09-26 23:28:06 +03:00
|
|
|
LengthPercentage GetIntrinsicWidth();
|
|
|
|
LengthPercentage GetIntrinsicHeight();
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
// 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;
|
2022-12-03 22:18:26 +03:00
|
|
|
SVGPreserveAspectRatio GetPreserveAspectRatioWithOverride() const override;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
// 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.
|
2019-11-15 13:19:55 +03:00
|
|
|
*
|
|
|
|
* FIXME(bug 1596690): GetOwnerSVGElement() uses the flattened tree parent
|
|
|
|
* rather than the DOM tree parent nowadays.
|
2009-01-15 07:38:07 +03:00
|
|
|
*/
|
2019-11-15 13:19:55 +03:00
|
|
|
bool WillBeOutermostSVG(nsINode& aParent) const;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2023-09-26 23:28:06 +03:00
|
|
|
LengthPercentage GetIntrinsicWidthOrHeight(int aAttr);
|
|
|
|
|
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
|
|
|
|
2022-12-03 22:18:26 +03:00
|
|
|
const SVGAnimatedViewBox& GetViewBoxInternal() const override;
|
|
|
|
SVGAnimatedTransformList* GetTransformInternal() const override;
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2022-12-03 22:18:26 +03:00
|
|
|
EnumAttributesInfo GetEnumInfo() override;
|
2007-08-28 03:11:14 +04:00
|
|
|
|
|
|
|
enum { ZOOMANDPAN };
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedEnumeration mEnumAttributes[1];
|
|
|
|
static SVGEnumMapping sZoomAndPanMap[];
|
2007-08-28 03:11:14 +04:00
|
|
|
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).
|
2020-02-25 23:03:26 +03:00
|
|
|
UniquePtr<SMILTimeContainer> mTimedDocumentRoot;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
SVGPoint mCurrentTranslate;
|
|
|
|
float mCurrentScale;
|
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.
|
2020-02-25 23:03:26 +03:00
|
|
|
UniquePtr<nsString> mCurrentViewID;
|
|
|
|
UniquePtr<SVGView> mSVGView;
|
2006-04-14 19:09:39 +04:00
|
|
|
};
|
|
|
|
|
2020-08-25 17:38:32 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(SVGSVGElement, MOZILLA_SVGSVGELEMENT_IID)
|
|
|
|
|
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:
|
2020-07-30 17:22:38 +03:00
|
|
|
AutoSVGTimeSetRestore(dom::SVGSVGElement* aRootElem, float aFrameTime)
|
2018-12-21 08:37:58 +03:00
|
|
|
: mRootElem(aRootElem),
|
|
|
|
mOriginalTime(mRootElem->GetCurrentTimeAsFloat()) {
|
2017-06-14 15:38:10 +03:00
|
|
|
mRootElem->SetCurrentTime(
|
|
|
|
aFrameTime); // Does nothing if there's no change.
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSVGTimeSetRestore() { mRootElem->SetCurrentTime(mOriginalTime); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const RefPtr<dom::SVGSVGElement> mRootElem;
|
|
|
|
const float mOriginalTime;
|
|
|
|
};
|
|
|
|
|
2017-04-03 12:40:13 +03:00
|
|
|
class MOZ_RAII AutoPreserveAspectRatioOverride {
|
2013-03-01 00:22:43 +04:00
|
|
|
public:
|
2022-07-14 19:03:25 +03:00
|
|
|
AutoPreserveAspectRatioOverride(const SVGImageContext& aSVGContext,
|
2020-07-30 17:22:38 +03:00
|
|
|
dom::SVGSVGElement* aRootElem)
|
2017-04-03 12:40:13 +03:00
|
|
|
: mRootElem(aRootElem), mDidOverride(false) {
|
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
|
|
|
|
2022-07-14 19:03:25 +03:00
|
|
|
if (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(
|
2022-07-14 19:03:25 +03:00
|
|
|
*aSVGContext.GetPreserveAspectRatio());
|
2017-04-03 12:40:13 +03:00
|
|
|
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;
|
|
|
|
};
|
2013-03-11 05:43:37 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_SVGSVGELEMENT_H_
|