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/. */
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2013-01-17 00:50:58 +04:00
|
|
|
#ifndef mozilla_dom_SVGUseElement_h
|
|
|
|
#define mozilla_dom_SVGUseElement_h
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
2017-09-08 12:02:05 +03:00
|
|
|
#include "mozilla/dom/IDTracker.h"
|
2007-03-10 16:49:43 +03:00
|
|
|
#include "nsStubMutationObserver.h"
|
2013-01-17 00:50:58 +04:00
|
|
|
#include "mozilla/dom/SVGGraphicsElement.h"
|
2007-02-18 20:34:09 +03:00
|
|
|
#include "nsSVGLength2.h"
|
2008-06-14 13:01:02 +04:00
|
|
|
#include "nsSVGString.h"
|
2007-02-18 20:34:09 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
class nsIContent;
|
2013-01-17 00:50:59 +04:00
|
|
|
class nsSVGUseFrame;
|
2007-02-18 20:34:09 +03:00
|
|
|
|
|
|
|
nsresult
|
2010-07-23 13:49:57 +04:00
|
|
|
NS_NewSVGSVGElement(nsIContent **aResult,
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2010-10-25 16:17:38 +04:00
|
|
|
mozilla::dom::FromParser aFromParser);
|
2013-01-17 00:50:58 +04:00
|
|
|
nsresult NS_NewSVGUseElement(nsIContent **aResult,
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2013-01-17 00:50:58 +04:00
|
|
|
namespace mozilla {
|
2017-04-06 09:51:29 +03:00
|
|
|
struct URLExtraData;
|
|
|
|
|
2013-01-17 00:50:58 +04:00
|
|
|
namespace dom {
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2013-01-17 00:50:58 +04:00
|
|
|
typedef SVGGraphicsElement SVGUseElementBase;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class SVGUseElement final : public SVGUseElementBase,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsStubMutationObserver
|
2007-02-18 20:34:09 +03:00
|
|
|
{
|
2013-01-17 00:50:59 +04:00
|
|
|
friend class ::nsSVGUseFrame;
|
2007-02-18 20:34:09 +03:00
|
|
|
protected:
|
2013-01-17 00:50:58 +04:00
|
|
|
friend nsresult (::NS_NewSVGUseElement(nsIContent **aResult,
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit SVGUseElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2013-01-17 00:50:58 +04:00
|
|
|
virtual ~SVGUseElement();
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-01-17 00:50:58 +04:00
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
public:
|
2018-07-16 17:07:58 +03:00
|
|
|
NS_IMPL_FROMNODE_WITH_TAG(SVGUseElement, kNameSpaceID_SVG, use)
|
|
|
|
|
|
|
|
nsresult BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) override;
|
2018-07-16 17:07:58 +03:00
|
|
|
void UnbindFromTree(bool aDeep = true,
|
|
|
|
bool aNullParent = true) override;
|
2013-01-17 00:50:58 +04:00
|
|
|
|
2018-07-16 17:07:58 +03:00
|
|
|
// interfaces:
|
2007-02-18 20:34:09 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-01-17 00:50:58 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGUseElement, SVGUseElementBase)
|
2007-03-10 16:49:43 +03:00
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
2007-02-18 20:34:09 +03:00
|
|
|
|
|
|
|
// nsSVGElement specializations:
|
2015-12-03 01:36:23 +03:00
|
|
|
virtual gfxMatrix PrependLocalTransformsTo(
|
|
|
|
const gfxMatrix &aMatrix,
|
|
|
|
SVGTransformTypes aWhich = eAllTransforms) const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool HasValidDimensions() const override;
|
2007-02-18 20:34:09 +03:00
|
|
|
|
|
|
|
// nsIContent interface
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2017-10-03 01:05:19 +03:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2013-01-17 00:50:59 +04:00
|
|
|
// WebIDL
|
2013-06-15 02:37:27 +04:00
|
|
|
already_AddRefed<SVGAnimatedString> Href();
|
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-17 00:50:59 +04:00
|
|
|
|
2016-09-20 09:13:13 +03:00
|
|
|
nsIURI* GetSourceDocURI();
|
2017-04-06 09:51:29 +03:00
|
|
|
URLExtraData* GetContentURLData() const { return mContentURLData; }
|
2016-09-20 09:13:13 +03:00
|
|
|
|
2018-07-16 17:07:58 +03:00
|
|
|
// Updates the internal shadow tree to be an up-to-date clone of the
|
|
|
|
// referenced element.
|
|
|
|
void UpdateShadowTree();
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
protected:
|
2017-09-12 12:43:16 +03:00
|
|
|
/**
|
|
|
|
* Helper that provides a reference to the element with the ID that is
|
|
|
|
* referenced by the 'use' element's 'href' attribute, and that will update
|
|
|
|
* the 'use' element if the element that that ID identifies changes to a
|
|
|
|
* different element (or none).
|
|
|
|
*/
|
|
|
|
class ElementTracker final : public IDTracker {
|
2008-06-26 02:41:04 +04:00
|
|
|
public:
|
2017-09-12 12:43:16 +03:00
|
|
|
explicit ElementTracker(SVGUseElement* aOwningUseElement)
|
|
|
|
: mOwningUseElement(aOwningUseElement)
|
|
|
|
{}
|
2018-07-16 17:07:58 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void ElementChanged(Element* aFrom, Element* aTo) override
|
|
|
|
{
|
2017-09-08 12:02:05 +03:00
|
|
|
IDTracker::ElementChanged(aFrom, aTo);
|
2008-07-09 14:50:48 +04:00
|
|
|
if (aFrom) {
|
2017-09-12 12:43:16 +03:00
|
|
|
aFrom->RemoveMutationObserver(mOwningUseElement);
|
2008-07-09 14:50:48 +04:00
|
|
|
}
|
2017-09-12 12:43:16 +03:00
|
|
|
mOwningUseElement->TriggerReclone();
|
2008-06-26 02:41:04 +04:00
|
|
|
}
|
2018-07-16 17:07:58 +03:00
|
|
|
|
2017-09-12 12:43:16 +03:00
|
|
|
SVGUseElement* mOwningUseElement;
|
2008-06-26 02:41:04 +04:00
|
|
|
};
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2017-08-27 21:15:03 +03:00
|
|
|
nsSVGUseFrame* GetFrame() const;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual LengthAttributesInfo GetLengthInfo() override;
|
|
|
|
virtual StringAttributesInfo GetStringInfo() override;
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2012-06-23 20:36:46 +04:00
|
|
|
/**
|
|
|
|
* Returns true if our width and height should be used, or false if they
|
|
|
|
* should be ignored. As per the spec, this depends on the type of the
|
|
|
|
* element that we're referencing.
|
|
|
|
*/
|
|
|
|
bool OurWidthAndHeightAreUsed() const;
|
2017-10-03 01:05:19 +03:00
|
|
|
void SyncWidthOrHeight(nsAtom *aName);
|
2008-06-26 02:41:04 +04:00
|
|
|
void LookupHref();
|
2007-02-18 20:34:09 +03:00
|
|
|
void TriggerReclone();
|
2008-06-26 02:41:04 +04:00
|
|
|
void UnlinkSource();
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2013-01-17 00:50:59 +04:00
|
|
|
enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
|
2007-02-18 20:34:09 +03:00
|
|
|
nsSVGLength2 mLengthAttributes[4];
|
|
|
|
static LengthInfo sLengthInfo[4];
|
|
|
|
|
2016-07-05 11:37:17 +03:00
|
|
|
enum { HREF, XLINK_HREF };
|
|
|
|
nsSVGString mStringAttributes[2];
|
|
|
|
static StringInfo sStringInfo[2];
|
2007-02-18 20:34:09 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> mOriginal; // if we've been cloned, our "real" copy
|
2018-07-16 17:07:58 +03:00
|
|
|
ElementTracker mReferencedElementTracker;
|
2017-04-06 09:51:29 +03:00
|
|
|
RefPtr<URLExtraData> mContentURLData; // URL data for its anonymous content
|
2007-02-18 20:34:09 +03:00
|
|
|
};
|
|
|
|
|
2013-01-17 00:50:58 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2007-02-19 22:40:38 +03:00
|
|
|
|
2013-01-17 00:50:58 +04:00
|
|
|
#endif // mozilla_dom_SVGUseElement_h
|