nsSVGPatternFrame.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* -*- Mode: C++; tab-width: 2; 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 __NS_SVGPATTERNFRAME_H__
  6. #define __NS_SVGPATTERNFRAME_H__
  7. #include "mozilla/Attributes.h"
  8. #include "gfxMatrix.h"
  9. #include "mozilla/gfx/2D.h"
  10. #include "mozilla/RefPtr.h"
  11. #include "nsAutoPtr.h"
  12. #include "nsSVGPaintServerFrame.h"
  13. class nsIFrame;
  14. class nsSVGLength2;
  15. class nsSVGPathGeometryFrame;
  16. class nsSVGViewBox;
  17. namespace mozilla {
  18. class SVGAnimatedPreserveAspectRatio;
  19. class nsSVGAnimatedTransformList;
  20. } // namespace mozilla
  21. /**
  22. * Patterns can refer to other patterns. We create an nsSVGPaintingProperty
  23. * with property type nsGkAtoms::href to track the referenced pattern.
  24. */
  25. class nsSVGPatternFrame : public nsSVGPaintServerFrame
  26. {
  27. typedef mozilla::gfx::SourceSurface SourceSurface;
  28. public:
  29. NS_DECL_FRAMEARENA_HELPERS
  30. friend nsIFrame* NS_NewSVGPatternFrame(nsIPresShell* aPresShell,
  31. nsStyleContext* aContext);
  32. explicit nsSVGPatternFrame(nsStyleContext* aContext);
  33. // nsSVGPaintServerFrame methods:
  34. virtual already_AddRefed<gfxPattern>
  35. GetPaintServerPattern(nsIFrame *aSource,
  36. const DrawTarget* aDrawTarget,
  37. const gfxMatrix& aContextMatrix,
  38. nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
  39. float aOpacity,
  40. const gfxRect *aOverrideBounds) override;
  41. public:
  42. typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
  43. // nsSVGContainerFrame methods:
  44. virtual gfxMatrix GetCanvasTM() override;
  45. // nsIFrame interface:
  46. virtual nsresult AttributeChanged(int32_t aNameSpaceID,
  47. nsIAtom* aAttribute,
  48. int32_t aModType) override;
  49. #ifdef DEBUG
  50. virtual void Init(nsIContent* aContent,
  51. nsContainerFrame* aParent,
  52. nsIFrame* aPrevInFlow) override;
  53. #endif
  54. /**
  55. * Get the "type" of the frame
  56. *
  57. * @see nsGkAtoms::svgPatternFrame
  58. */
  59. virtual nsIAtom* GetType() const override;
  60. #ifdef DEBUG_FRAME_DUMP
  61. virtual nsresult GetFrameName(nsAString& aResult) const override
  62. {
  63. return MakeFrameName(NS_LITERAL_STRING("SVGPattern"), aResult);
  64. }
  65. #endif // DEBUG
  66. protected:
  67. // Internal methods for handling referenced patterns
  68. class AutoPatternReferencer;
  69. nsSVGPatternFrame* GetReferencedPattern();
  70. nsSVGPatternFrame* GetReferencedPatternIfNotInUse();
  71. // Accessors to lookup pattern attributes
  72. uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault);
  73. uint16_t GetEnumValue(uint32_t aIndex)
  74. {
  75. return GetEnumValue(aIndex, mContent);
  76. }
  77. mozilla::nsSVGAnimatedTransformList* GetPatternTransformList(
  78. nsIContent* aDefault);
  79. gfxMatrix GetPatternTransform();
  80. const nsSVGViewBox &GetViewBox(nsIContent *aDefault);
  81. const nsSVGViewBox &GetViewBox() { return GetViewBox(mContent); }
  82. const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio(
  83. nsIContent *aDefault);
  84. const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio()
  85. {
  86. return GetPreserveAspectRatio(mContent);
  87. }
  88. const nsSVGLength2 *GetLengthValue(uint32_t aIndex, nsIContent *aDefault);
  89. const nsSVGLength2 *GetLengthValue(uint32_t aIndex)
  90. {
  91. return GetLengthValue(aIndex, mContent);
  92. }
  93. already_AddRefed<SourceSurface>
  94. PaintPattern(const DrawTarget* aDrawTarget,
  95. Matrix *patternMatrix,
  96. const Matrix &aContextMatrix,
  97. nsIFrame *aSource,
  98. nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
  99. float aGraphicOpacity,
  100. const gfxRect *aOverrideBounds);
  101. /**
  102. * A <pattern> element may reference another <pattern> element using
  103. * xlink:href and, if it doesn't have any child content of its own, then it
  104. * will "inherit" the children of the referenced pattern (which may itself be
  105. * inheriting its children if it references another <pattern>). This
  106. * function returns this nsSVGPatternFrame or the first pattern along the
  107. * reference chain (if there is one) to have children.
  108. */
  109. nsSVGPatternFrame* GetPatternWithChildren();
  110. gfxRect GetPatternRect(uint16_t aPatternUnits,
  111. const gfxRect &bbox,
  112. const Matrix &callerCTM,
  113. nsIFrame *aTarget);
  114. gfxMatrix ConstructCTM(const nsSVGViewBox& aViewBox,
  115. uint16_t aPatternContentUnits,
  116. uint16_t aPatternUnits,
  117. const gfxRect &callerBBox,
  118. const Matrix &callerCTM,
  119. nsIFrame *aTarget);
  120. private:
  121. // this is a *temporary* reference to the frame of the element currently
  122. // referencing our pattern. This must be temporary because different
  123. // referencing frames will all reference this one frame
  124. nsSVGPathGeometryFrame *mSource;
  125. nsAutoPtr<gfxMatrix> mCTM;
  126. protected:
  127. // This flag is used to detect loops in xlink:href processing
  128. bool mLoopFlag;
  129. bool mNoHRefURI;
  130. };
  131. #endif