nsISVGChildFrame.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_ISVGCHILDFRAME_H__
  6. #define __NS_ISVGCHILDFRAME_H__
  7. #include "gfxRect.h"
  8. #include "nsQueryFrame.h"
  9. #include "imgIContainer.h"
  10. class gfxContext;
  11. class gfxMatrix;
  12. class nsIFrame;
  13. class SVGBBox;
  14. struct nsRect;
  15. namespace mozilla {
  16. class SVGAnimatedLengthList;
  17. class SVGAnimatedNumberList;
  18. class SVGLengthList;
  19. class SVGNumberList;
  20. class SVGUserUnitList;
  21. namespace gfx {
  22. class Matrix;
  23. } // namespace gfx
  24. } // namespace mozilla
  25. /**
  26. * This class is not particularly well named. It is inherited by some, but
  27. * not all SVG frame classes that can be descendants of an
  28. * nsSVGOuterSVGFrame in the frame tree. Note specifically that SVG container
  29. * frames that do not inherit nsSVGDisplayContainerFrame do not inherit this
  30. * class (so that's classes that only inherit nsSVGContainerFrame).
  31. */
  32. class nsISVGChildFrame : public nsQueryFrame
  33. {
  34. public:
  35. typedef mozilla::SVGAnimatedNumberList SVGAnimatedNumberList;
  36. typedef mozilla::SVGNumberList SVGNumberList;
  37. typedef mozilla::SVGAnimatedLengthList SVGAnimatedLengthList;
  38. typedef mozilla::SVGLengthList SVGLengthList;
  39. typedef mozilla::SVGUserUnitList SVGUserUnitList;
  40. typedef mozilla::image::DrawResult DrawResult;
  41. NS_DECL_QUERYFRAME_TARGET(nsISVGChildFrame)
  42. /**
  43. * Paint this frame.
  44. *
  45. * SVG is painted using a combination of display lists (trees of
  46. * nsDisplayItem built by BuildDisplayList() implementations) and recursive
  47. * PaintSVG calls. SVG frames with the NS_FRAME_IS_NONDISPLAY bit set are
  48. * always painted using recursive PaintSVG calls since display list painting
  49. * would provide no advantages (they wouldn't be retained for invalidation).
  50. * Displayed SVG is normally painted via a display list tree created under
  51. * nsSVGOuterSVGFrame::BuildDisplayList, unless the
  52. * svg.display-lists.painting.enabled pref has been set to false by the user
  53. * in which case it is done via an nsSVGOuterSVGFrame::PaintSVG() call that
  54. * recurses over the entire SVG frame tree. In future we may use PaintSVG()
  55. * calls on SVG container frames to avoid display list construction when it
  56. * is expensive and unnecessary (see bug 934411).
  57. *
  58. * @param aTransform The transform that has to be multiplied onto the
  59. * DrawTarget in order for drawing to be in this frame's SVG user space.
  60. * Implementations of this method should avoid multiplying aTransform onto
  61. * the DrawTarget when possible and instead just pass a transform down to
  62. * their children. This is preferable because changing the transform is
  63. * very expensive for certain DrawTarget backends so it is best to minimize
  64. * the number of transform changes.
  65. *
  66. * @param aDirtyRect The area being redrawn, in frame offset pixel
  67. * coordinates.
  68. */
  69. virtual DrawResult PaintSVG(gfxContext& aContext,
  70. const gfxMatrix& aTransform,
  71. const nsIntRect* aDirtyRect = nullptr) = 0;
  72. /**
  73. * Returns the frame that should handle pointer events at aPoint. aPoint is
  74. * expected to be in the SVG user space of the frame on which this method is
  75. * called. The frame returned may be the frame on which this method is
  76. * called, any of its descendants or else nullptr.
  77. */
  78. virtual nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) = 0;
  79. // Get bounds in our nsSVGOuterSVGFrame's coordinates space (in app units)
  80. virtual nsRect GetCoveredRegion()=0;
  81. // Called on SVG child frames (except NS_FRAME_IS_NONDISPLAY frames)
  82. // to update and then invalidate their cached bounds. This method is not
  83. // called until after the nsSVGOuterSVGFrame has had its initial reflow
  84. // (i.e. once the SVG viewport dimensions are known). It should also only
  85. // be called by nsSVGOuterSVGFrame during its reflow.
  86. virtual void ReflowSVG()=0;
  87. // Flags to pass to NotifySVGChange:
  88. //
  89. // DO_NOT_NOTIFY_RENDERING_OBSERVERS - this should only be used when
  90. // updating the descendant frames of a clipPath,
  91. // mask, pattern or marker frame (or other similar
  92. // NS_FRAME_IS_NONDISPLAY frame) immediately
  93. // prior to painting that frame's descendants.
  94. // TRANSFORM_CHANGED - the current transform matrix for this frame has changed
  95. // COORD_CONTEXT_CHANGED - the dimensions of this frame's coordinate context has
  96. // changed (percentage lengths must be reevaluated)
  97. enum SVGChangedFlags {
  98. TRANSFORM_CHANGED = 0x01,
  99. COORD_CONTEXT_CHANGED = 0x02,
  100. FULL_ZOOM_CHANGED = 0x04
  101. };
  102. /**
  103. * This is called on a frame when there has been a change to one of its
  104. * ancestors that might affect the frame too. SVGChangedFlags are passed
  105. * to indicate what changed.
  106. *
  107. * Implementations do not need to invalidate, since the caller will
  108. * invalidate the entire area of the ancestor that changed. However, they
  109. * may need to update their bounds.
  110. */
  111. virtual void NotifySVGChanged(uint32_t aFlags)=0;
  112. /**
  113. * Get this frame's contribution to the rect returned by a GetBBox() call
  114. * that occurred either on this element, or on one of its ancestors.
  115. *
  116. * SVG defines an element's bbox to be the element's fill bounds in the
  117. * userspace established by that element. By allowing callers to pass in the
  118. * transform from the userspace established by this element to the userspace
  119. * established by an an ancestor, this method allows callers to obtain this
  120. * element's fill bounds in the userspace established by that ancestor
  121. * instead. In that case, since we return the bounds in a different userspace
  122. * (the ancestor's), the bounds we return are not this element's bbox, but
  123. * rather this element's contribution to the bbox of the ancestor.
  124. *
  125. * @param aToBBoxUserspace The transform from the userspace established by
  126. * this element to the userspace established by the ancestor on which
  127. * getBBox was called. This will be the identity matrix if we are the
  128. * element on which getBBox was called.
  129. *
  130. * @param aFlags Flags indicating whether, stroke, for example, should be
  131. * included in the bbox calculation.
  132. */
  133. virtual SVGBBox GetBBoxContribution(const mozilla::gfx::Matrix &aToBBoxUserspace,
  134. uint32_t aFlags) = 0;
  135. // Are we a container frame?
  136. virtual bool IsDisplayContainer()=0;
  137. };
  138. #endif // __NS_ISVGCHILDFRAME_H__