Line data Source code
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 :
6 : #ifndef NS_SVGCONTAINERFRAME_H
7 : #define NS_SVGCONTAINERFRAME_H
8 :
9 : #include "mozilla/Attributes.h"
10 : #include "nsContainerFrame.h"
11 : #include "nsFrame.h"
12 : #include "nsIFrame.h"
13 : #include "nsSVGDisplayableFrame.h"
14 : #include "nsQueryFrame.h"
15 : #include "nsRect.h"
16 : #include "nsSVGUtils.h"
17 :
18 : class gfxContext;
19 : class nsFrameList;
20 : class nsIContent;
21 : class nsIPresShell;
22 : class nsStyleContext;
23 :
24 : struct nsRect;
25 :
26 : /**
27 : * Base class for SVG container frames. Frame sub-classes that do not
28 : * display their contents directly (such as the frames for <marker> or
29 : * <pattern>) just inherit this class. Frame sub-classes that do or can
30 : * display their contents directly (such as the frames for inner-<svg> or
31 : * <g>) inherit our nsDisplayContainerFrame sub-class.
32 : *
33 : * *** WARNING ***
34 : *
35 : * Do *not* blindly cast to SVG element types in this class's methods (see the
36 : * warning comment for nsSVGDisplayContainerFrame below).
37 : */
38 0 : class nsSVGContainerFrame : public nsContainerFrame
39 : {
40 : friend nsIFrame* NS_NewSVGContainerFrame(nsIPresShell* aPresShell,
41 : nsStyleContext* aContext);
42 : protected:
43 91 : nsSVGContainerFrame(nsStyleContext* aContext, ClassID aID)
44 91 : : nsContainerFrame(aContext, aID)
45 : {
46 91 : AddStateBits(NS_FRAME_SVG_LAYOUT);
47 91 : }
48 :
49 : public:
50 : NS_DECL_QUERYFRAME
51 29 : NS_DECL_FRAMEARENA_HELPERS(nsSVGContainerFrame)
52 :
53 : // Returns the transform to our gfxContext (to device pixels, not CSS px)
54 0 : virtual gfxMatrix GetCanvasTM() {
55 0 : return gfxMatrix();
56 : }
57 :
58 : /**
59 : * Returns true if the frame's content has a transform that applies only to
60 : * its children, and not to the frame itself. For example, an implicit
61 : * transform introduced by a 'viewBox' attribute, or an explicit transform
62 : * due to a root-<svg> having its currentScale/currentTransform properties
63 : * set. If aTransform is non-null, then it will be set to the transform.
64 : */
65 585 : virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const {
66 585 : return false;
67 : }
68 :
69 : // nsIFrame:
70 : virtual void AppendFrames(ChildListID aListID,
71 : nsFrameList& aFrameList) override;
72 : virtual void InsertFrames(ChildListID aListID,
73 : nsIFrame* aPrevFrame,
74 : nsFrameList& aFrameList) override;
75 : virtual void RemoveFrame(ChildListID aListID,
76 : nsIFrame* aOldFrame) override;
77 :
78 3228 : virtual bool IsFrameOfType(uint32_t aFlags) const override
79 : {
80 3228 : return nsContainerFrame::IsFrameOfType(
81 3228 : aFlags & ~(nsIFrame::eSVG | nsIFrame::eSVGContainer));
82 : }
83 :
84 0 : virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
85 : const nsRect& aDirtyRect,
86 0 : const nsDisplayListSet& aLists) override {}
87 :
88 : virtual bool ComputeCustomOverflow(nsOverflowAreas& aOverflowAreas) override;
89 :
90 : protected:
91 : /**
92 : * Traverses a frame tree, marking any SVGTextFrame frames as dirty
93 : * and calling InvalidateRenderingObservers() on it.
94 : */
95 : static void ReflowSVGNonDisplayText(nsIFrame* aContainer);
96 : };
97 :
98 : /**
99 : * Frame class or base-class for SVG containers that can or do display their
100 : * contents directly.
101 : *
102 : * *** WARNING ***
103 : *
104 : * This class's methods can *not* assume that mContent points to an instance of
105 : * an SVG element class since this class is inherited by
106 : * nsSVGGenericContainerFrame which is used for unrecognized elements in the
107 : * SVG namespace. Do *not* blindly cast to SVG element types.
108 : */
109 0 : class nsSVGDisplayContainerFrame : public nsSVGContainerFrame,
110 : public nsSVGDisplayableFrame
111 : {
112 : protected:
113 78 : nsSVGDisplayContainerFrame(nsStyleContext* aContext, nsIFrame::ClassID aID)
114 78 : : nsSVGContainerFrame(aContext, aID)
115 : {
116 78 : AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
117 78 : }
118 :
119 : public:
120 : NS_DECL_QUERYFRAME
121 : NS_DECL_QUERYFRAME_TARGET(nsSVGDisplayContainerFrame)
122 : NS_DECL_ABSTRACT_FRAME(nsSVGDisplayContainerFrame)
123 :
124 : // nsIFrame:
125 : virtual void InsertFrames(ChildListID aListID,
126 : nsIFrame* aPrevFrame,
127 : nsFrameList& aFrameList) override;
128 : virtual void RemoveFrame(ChildListID aListID,
129 : nsIFrame* aOldFrame) override;
130 : virtual void Init(nsIContent* aContent,
131 : nsContainerFrame* aParent,
132 : nsIFrame* aPrevInFlow) override;
133 :
134 : virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
135 : const nsRect& aDirtyRect,
136 : const nsDisplayListSet& aLists) override;
137 :
138 : virtual bool IsSVGTransformed(Matrix *aOwnTransform = nullptr,
139 : Matrix *aFromParentTransform = nullptr) const override;
140 :
141 : // nsSVGDisplayableFrame interface:
142 : virtual void PaintSVG(gfxContext& aContext,
143 : const gfxMatrix& aTransform,
144 : imgDrawingParams& aImgParams,
145 : const nsIntRect* aDirtyRect = nullptr) override;
146 : virtual nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
147 : virtual void ReflowSVG() override;
148 : virtual void NotifySVGChanged(uint32_t aFlags) override;
149 : virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace,
150 : uint32_t aFlags) override;
151 0 : virtual bool IsDisplayContainer() override { return true; }
152 : };
153 :
154 : #endif
|