gecko-dev/dom/svg/SVGSVGElement.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

311 строки
11 KiB
C
Исходник Обычный вид История

/* -*- 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/. */
#ifndef DOM_SVG_SVGSVGELEMENT_H_
#define DOM_SVG_SVGSVGELEMENT_H_
#include "SVGAnimatedEnumeration.h"
#include "SVGViewportElement.h"
nsresult NS_NewSVGSVGElement(
nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
mozilla::dom::FromParser aFromParser);
namespace mozilla {
class AutoSVGViewHandler;
class SMILTimeContainer;
class SVGFragmentIdentifier;
class EventChainPreVisitor;
namespace dom {
struct DOMMatrix2DInit;
class DOMSVGAngle;
class DOMSVGLength;
class DOMSVGNumber;
class SVGMatrix;
class SVGRect;
class SVGSVGElement;
// Stores svgView arguments of SVG fragment identifiers.
class SVGView {
public:
SVGView();
SVGAnimatedEnumeration mZoomAndPan;
SVGAnimatedViewBox mViewBox;
SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
UniquePtr<SVGAnimatedTransformList> mTransforms;
};
class DOMSVGTranslatePoint final : public nsISVGPoint {
public:
DOMSVGTranslatePoint(SVGPoint* aPt, SVGSVGElement* aElement)
: nsISVGPoint(aPt, true), mElement(aElement) {}
explicit DOMSVGTranslatePoint(DOMSVGTranslatePoint* aPt)
: nsISVGPoint(&aPt->mPt, true), mElement(aPt->mElement) {}
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMSVGTranslatePoint, nsISVGPoint)
virtual DOMSVGPoint* Copy() override;
// WebIDL
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(
const DOMMatrix2DInit& aMatrix, ErrorResult& aRv) override;
virtual nsISupports* GetParentObject() override;
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<SVGSVGElement> mElement;
private:
~DOMSVGTranslatePoint() = default;
};
using SVGSVGElementBase = SVGViewportElement;
class SVGSVGElement final : public SVGSVGElementBase {
friend class mozilla::SVGFragmentIdentifier;
friend class mozilla::SVGOuterSVGFrame;
friend class mozilla::AutoSVGViewHandler;
friend class mozilla::AutoPreserveAspectRatioOverride;
friend class mozilla::dom::SVGView;
protected:
SVGSVGElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
FromParser aFromParser);
virtual JSObject* WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
friend nsresult(::NS_NewSVGSVGElement(
nsIContent** aResult,
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
mozilla::dom::FromParser aFromParser));
~SVGSVGElement() = default;
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGSVGElement, SVGSVGElementBase)
/**
* 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?
*/
MOZ_CAN_RUN_SCRIPT_BOUNDARY void SetCurrentScaleTranslate(float s, float x,
float y);
// nsIContent interface
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
virtual bool IsEventAttributeNameInternal(nsAtom* aName) override;
// nsINode methods:
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
// WebIDL
already_AddRefed<DOMSVGAnimatedLength> X();
already_AddRefed<DOMSVGAnimatedLength> Y();
already_AddRefed<DOMSVGAnimatedLength> Width();
already_AddRefed<DOMSVGAnimatedLength> Height();
bool UseCurrentView();
float CurrentScale();
void SetCurrentScale(float aCurrentScale);
already_AddRefed<nsISVGPoint> CurrentTranslate();
void SetCurrentTranslate(float x, float y);
uint32_t SuspendRedraw(uint32_t max_wait_milliseconds);
void UnsuspendRedraw(uint32_t suspend_handle_id);
void UnsuspendRedrawAll();
void ForceRedraw();
void PauseAnimations();
void UnpauseAnimations();
bool AnimationsPaused();
float GetCurrentTimeAsFloat();
void SetCurrentTime(float seconds);
void DeselectAll();
already_AddRefed<DOMSVGNumber> CreateSVGNumber();
already_AddRefed<DOMSVGLength> CreateSVGLength();
already_AddRefed<DOMSVGAngle> CreateSVGAngle();
already_AddRefed<nsISVGPoint> CreateSVGPoint();
already_AddRefed<SVGMatrix> CreateSVGMatrix();
already_AddRefed<SVGRect> CreateSVGRect();
already_AddRefed<DOMSVGTransform> CreateSVGTransform();
already_AddRefed<DOMSVGTransform> CreateSVGTransformFromMatrix(
const DOMMatrix2DInit& matrix, ErrorResult& rv);
using nsINode::GetElementById; // This does what we want
uint16_t ZoomAndPan();
void SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv);
// SVGElement overrides
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky BindContext was going to have way more information at first, but then I realized that most of the things I wanted to know were basically a flag away using the parent node. Still I think it's worth it, now experimenting with BindToTree will only mean adding a field to a struct that's included from a couple cpp files, instead of a massive pain. I also think this is clearer, and doing this highlights quite a few inconsistencies in our code which I've left untouched, but commented with FIXMEs. Steps are: $ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done $ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done $ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done $ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done $ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done $ ./mach clang-format Then manual fixups. Depends on D32948 Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
virtual void UnbindFromTree(bool aNullParent) override;
virtual SVGAnimatedTransformList* GetAnimatedTransformList(
uint32_t aFlags = 0) override;
// SVGSVGElement methods:
// 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);
}
SMILTimeContainer* GetTimedDocumentRoot();
// public helpers:
/**
* 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.
*/
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:
/*
* 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
* set (both actions are performed by Element::BindToTree) so we
* 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.
*
* FIXME(bug 1596690): GetOwnerSVGElement() uses the flattened tree parent
* rather than the DOM tree parent nowadays.
*/
bool WillBeOutermostSVG(nsINode& aParent) const;
// invalidate viewbox -> viewport xform & inform frames
void InvalidateTransformNotifyFrame();
// 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();
virtual SVGPoint GetCurrentTranslate() const override {
return mCurrentTranslate;
}
virtual float GetCurrentScale() const override { return mCurrentScale; }
virtual const SVGAnimatedViewBox& GetViewBoxInternal() const override;
virtual SVGAnimatedTransformList* GetTransformInternal() const override;
virtual EnumAttributesInfo GetEnumInfo() override;
enum { ZOOMANDPAN };
SVGAnimatedEnumeration mEnumAttributes[1];
static SVGEnumMapping 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).
UniquePtr<SMILTimeContainer> 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;
// mCurrentViewID and mSVGView are mutually exclusive; we can have
// at most one non-null.
UniquePtr<nsString> mCurrentViewID;
UniquePtr<SVGView> mSVGView;
};
} // namespace dom
class MOZ_RAII AutoSVGTimeSetRestore {
public:
AutoSVGTimeSetRestore(dom::SVGSVGElement* aRootElem, float aFrameTime)
: mRootElem(aRootElem),
mOriginalTime(mRootElem->GetCurrentTimeAsFloat()) {
mRootElem->SetCurrentTime(
aFrameTime); // Does nothing if there's no change.
}
~AutoSVGTimeSetRestore() { mRootElem->SetCurrentTime(mOriginalTime); }
private:
const RefPtr<dom::SVGSVGElement> mRootElem;
const float mOriginalTime;
};
class MOZ_RAII AutoPreserveAspectRatioOverride {
public:
AutoPreserveAspectRatioOverride(const Maybe<SVGImageContext>& aSVGContext,
dom::SVGSVGElement* aRootElem)
: mRootElem(aRootElem), mDidOverride(false) {
MOZ_ASSERT(mRootElem, "No SVG/Symbol node to manage?");
if (aSVGContext.isSome() &&
aSVGContext->GetPreserveAspectRatio().isSome()) {
// 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(
*aSVGContext->GetPreserveAspectRatio());
mDidOverride = true;
}
}
~AutoPreserveAspectRatioOverride() {
if (mDidOverride) {
mRootElem->ClearImageOverridePreserveAspectRatio();
}
}
private:
const RefPtr<dom::SVGSVGElement> mRootElem;
bool mDidOverride;
};
} // namespace mozilla
#endif // DOM_SVG_SVGSVGELEMENT_H_