SVGImageElement.h 3.6 KB

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