ISVGDisplayableFrame.h (6432B)
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 LAYOUT_SVG_ISVGDISPLAYABLEFRAME_H_ 8 #define LAYOUT_SVG_ISVGDISPLAYABLEFRAME_H_ 9 10 #include "gfxMatrix.h" 11 #include "gfxPoint.h" 12 #include "gfxRect.h" 13 #include "mozilla/EnumSet.h" 14 #include "mozilla/gfx/MatrixFwd.h" 15 #include "nsQueryFrame.h" 16 #include "nsRect.h" 17 18 class gfxContext; 19 class nsIFrame; 20 21 namespace mozilla { 22 class SVGAnimatedLengthList; 23 class SVGAnimatedNumberList; 24 class SVGBBox; 25 class SVGLengthList; 26 class SVGNumberList; 27 class SVGUserUnitList; 28 29 namespace image { 30 struct imgDrawingParams; 31 } // namespace image 32 33 /** 34 * This class is used for elements that can be part of a directly displayable 35 * section of a document. This includes SVGGeometryFrame and SVGGFrame. 36 * (Even though the latter doesn't display anything itself, if it contains 37 * SVGGeometryFrame descendants it is can still be part of a displayable 38 * section of a document) This class is not used for elements that can never 39 * display directly, including SVGGradientFrame and SVGPatternFrame. (The 40 * latter may contain displayable content, but it and its content are never 41 * *directly* displayed in a document. It can only end up being displayed by 42 * means of a reference from other content.) 43 * 44 * Note specifically that SVG frames that inherit SVGContainerFrame do *not* 45 * implement this class (only those that inherit SVGDisplayContainerFrame 46 * do.) 47 */ 48 class ISVGDisplayableFrame : public nsQueryFrame { 49 public: 50 using imgDrawingParams = image::imgDrawingParams; 51 52 NS_DECL_QUERYFRAME_TARGET(ISVGDisplayableFrame) 53 54 /** 55 * Paint this frame. 56 * 57 * SVG is painted using a combination of display lists (trees of 58 * nsDisplayItem built by BuildDisplayList() implementations) and recursive 59 * PaintSVG calls. SVG frames with the NS_FRAME_IS_NONDISPLAY bit set are 60 * always painted using recursive PaintSVG calls since display list painting 61 * would provide no advantages (they wouldn't be retained for invalidation). 62 * Displayed SVG is normally painted via a display list tree created under 63 * SVGOuterSVGFrame::BuildDisplayList, In future we may use a PaintSVG() call 64 * that recurses over the entire SVG frame tree on SVG container frames to 65 * avoid display list construction when it is expensive and unnecessary (see 66 * bug 934411). 67 * 68 * @param aTransform The transform that has to be multiplied onto the 69 * DrawTarget in order for drawing to be in this frame's SVG user space. 70 * Implementations of this method should avoid multiplying aTransform onto 71 * the DrawTarget when possible and instead just pass a transform down to 72 * their children. This is preferable because changing the transform is 73 * very expensive for certain DrawTarget backends so it is best to minimize 74 * the number of transform changes. 75 * 76 * @param aImgParams imagelib parameters that may be used when painting 77 * feImage. 78 */ 79 virtual void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform, 80 imgDrawingParams& aImgParams) = 0; 81 82 /** 83 * Returns the frame that should handle pointer events at aPoint. aPoint is 84 * expected to be in the SVG user space of the frame on which this method is 85 * called. The frame returned may be the frame on which this method is 86 * called, any of its descendants or else nullptr. 87 */ 88 virtual nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) = 0; 89 90 // Called on SVG child frames (except NS_FRAME_IS_NONDISPLAY frames) 91 // to update and then invalidate their cached bounds. This method is not 92 // called until after the SVGOuterSVGFrame has had its initial reflow 93 // (i.e. once the SVG viewport dimensions are known). It should also only 94 // be called by SVGOuterSVGFrame during its reflow. 95 virtual void ReflowSVG() = 0; 96 97 // Flags to pass to NotifySVGChange: 98 // 99 // TransformChanged: 100 // the current transform matrix for this frame has changed 101 // CoordContextChanged: 102 // the dimensions of this frame's coordinate context has changed (percentage 103 // lengths must be reevaluated) 104 // FullZoomChanged: 105 // the page's zoom level has changed 106 enum class ChangeFlag { 107 TransformChanged, 108 CoordContextChanged, 109 FullZoomChanged 110 }; 111 using ChangeFlags = EnumSet<ChangeFlag>; 112 113 /** 114 * This is called on a frame when there has been a change to one of its 115 * ancestors that might affect the frame too. ChangeFlags are passed 116 * to indicate what changed. 117 * 118 * Implementations do not need to invalidate, since the caller will 119 * invalidate the entire area of the ancestor that changed. However, they 120 * may need to update their bounds. 121 */ 122 virtual void NotifySVGChanged(ChangeFlags aFlags) = 0; 123 124 /** 125 * Get this frame's contribution to the rect returned by a GetBBox() call 126 * that occurred either on this element, or on one of its ancestors. 127 * 128 * SVG defines an element's bbox to be the element's fill bounds in the 129 * userspace established by that element. By allowing callers to pass in the 130 * transform from the userspace established by this element to the userspace 131 * established by an ancestor, this method allows callers to obtain this 132 * element's fill bounds in the userspace established by that ancestor 133 * instead. In that case, since we return the bounds in a different userspace 134 * (the ancestor's), the bounds we return are not this element's bbox, but 135 * rather this element's contribution to the bbox of the ancestor. 136 * 137 * @param aToBBoxUserspace The transform from the userspace established by 138 * this element to the userspace established by the ancestor on which 139 * getBBox was called. This will be the identity matrix if we are the 140 * element on which getBBox was called. 141 * 142 * @param aFlags Flags indicating whether, stroke, for example, should be 143 * included in the bbox calculation. 144 */ 145 virtual SVGBBox GetBBoxContribution(const gfx::Matrix& aToBBoxUserspace, 146 uint32_t aFlags) = 0; 147 148 // Are we a container frame? 149 virtual bool IsDisplayContainer() = 0; 150 }; 151 152 } // namespace mozilla 153 154 #endif // LAYOUT_SVG_ISVGDISPLAYABLEFRAME_H_