Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_SVGImageElement_h
8 : #define mozilla_dom_SVGImageElement_h
9 :
10 : #include "nsImageLoadingContent.h"
11 : #include "nsSVGLength2.h"
12 : #include "nsSVGString.h"
13 : #include "SVGGeometryElement.h"
14 : #include "SVGAnimatedPreserveAspectRatio.h"
15 :
16 : nsresult NS_NewSVGImageElement(nsIContent **aResult,
17 : already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
18 :
19 : class nsSVGImageFrame;
20 :
21 : namespace mozilla {
22 : namespace dom {
23 : class DOMSVGAnimatedPreserveAspectRatio;
24 :
25 : typedef SVGGeometryElement SVGImageElementBase;
26 :
27 : class SVGImageElement : public SVGImageElementBase,
28 : public nsImageLoadingContent
29 : {
30 : friend class ::nsSVGImageFrame;
31 :
32 : protected:
33 : explicit SVGImageElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
34 : virtual ~SVGImageElement();
35 : virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
36 : friend nsresult (::NS_NewSVGImageElement(nsIContent **aResult,
37 : already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
38 :
39 : public:
40 : // interfaces:
41 :
42 : NS_DECL_ISUPPORTS_INHERITED
43 :
44 : // EventTarget
45 : virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
46 :
47 : // nsIContent interface
48 : virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
49 : const nsAttrValue* aValue,
50 : const nsAttrValue* aOldValue,
51 : bool aNotify) override;
52 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
53 : nsIContent* aBindingParent,
54 : bool aCompileEventHandlers) override;
55 : virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
56 :
57 : virtual EventStates IntrinsicState() const override;
58 :
59 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const override;
60 :
61 : // SVGGeometryElement methods:
62 : virtual bool GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions,
63 : const Matrix& aToBoundsSpace,
64 : const Matrix* aToNonScalingStrokeSpace = nullptr) override;
65 : virtual already_AddRefed<Path> BuildPath(PathBuilder* aBuilder) override;
66 :
67 : // nsSVGSVGElement methods:
68 : virtual bool HasValidDimensions() const override;
69 :
70 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
71 : bool aPreallocateChildren) const override;
72 :
73 : nsresult CopyInnerTo(mozilla::dom::Element* aDest, bool aPreallocateChildren);
74 :
75 : void MaybeLoadSVGImage();
76 :
77 : // WebIDL
78 : already_AddRefed<SVGAnimatedLength> X();
79 : already_AddRefed<SVGAnimatedLength> Y();
80 : already_AddRefed<SVGAnimatedLength> Width();
81 : already_AddRefed<SVGAnimatedLength> Height();
82 : already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
83 : already_AddRefed<SVGAnimatedString> Href();
84 :
85 : protected:
86 : nsresult LoadSVGImage(bool aForce, bool aNotify);
87 :
88 : virtual LengthAttributesInfo GetLengthInfo() override;
89 : virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio() override;
90 : virtual StringAttributesInfo GetStringInfo() override;
91 :
92 : // Override for nsImageLoadingContent.
93 0 : nsIContent* AsContent() override { return this; }
94 :
95 : enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
96 : nsSVGLength2 mLengthAttributes[4];
97 : static LengthInfo sLengthInfo[4];
98 :
99 : SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
100 :
101 : enum { HREF, XLINK_HREF };
102 : nsSVGString mStringAttributes[2];
103 : static StringInfo sStringInfo[2];
104 : };
105 :
106 : } // namespace dom
107 : } // namespace mozilla
108 :
109 : #endif // mozilla_dom_SVGImageElement_h
|