Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / svg / SVGContainerFrame.h
blob59ace95aee650d30c6f923f88215650acb23a0df
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/. */
7 #ifndef LAYOUT_SVG_SVGCONTAINERFRAME_H_
8 #define LAYOUT_SVG_SVGCONTAINERFRAME_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ISVGDisplayableFrame.h"
12 #include "mozilla/UniquePtr.h"
13 #include "nsContainerFrame.h"
14 #include "nsIFrame.h"
15 #include "nsQueryFrame.h"
16 #include "nsRect.h"
18 class gfxContext;
19 class nsFrameList;
20 class nsIContent;
22 struct nsRect;
24 namespace mozilla {
25 class PresShell;
26 } // namespace mozilla
28 nsIFrame* NS_NewSVGContainerFrame(mozilla::PresShell* aPresShell,
29 mozilla::ComputedStyle* aStyle);
31 namespace mozilla {
33 /**
34 * Base class for SVG container frames. Frame sub-classes that do not
35 * display their contents directly (such as the frames for <marker> or
36 * <pattern>) just inherit this class. Frame sub-classes that do or can
37 * display their contents directly (such as the frames for inner-<svg> or
38 * <g>) inherit our SVGDisplayContainerFrame sub-class.
40 * *** WARNING ***
42 * Do *not* blindly cast to SVG element types in this class's methods (see the
43 * warning comment for SVGDisplayContainerFrame below).
45 class SVGContainerFrame : public nsContainerFrame {
46 friend nsIFrame* ::NS_NewSVGContainerFrame(mozilla::PresShell* aPresShell,
47 ComputedStyle* aStyle);
49 protected:
50 SVGContainerFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
51 ClassID aID)
52 : nsContainerFrame(aStyle, aPresContext, aID) {
53 AddStateBits(NS_FRAME_SVG_LAYOUT);
56 public:
57 NS_DECL_QUERYFRAME
58 NS_DECL_FRAMEARENA_HELPERS(SVGContainerFrame)
60 // Returns the transform to our gfxContext (to device pixels, not CSS px)
61 virtual gfxMatrix GetCanvasTM() { return gfxMatrix(); }
63 /**
64 * Returns true if the frame's content has a transform that applies only to
65 * its children, and not to the frame itself. For example, an implicit
66 * transform introduced by a 'viewBox' attribute, or an explicit transform
67 * due to a root-<svg> having its currentScale/currentTransform properties
68 * set. If aTransform is non-null, then it will be set to the transform.
70 virtual bool HasChildrenOnlyTransform(Matrix* aTransform) const {
71 return false;
74 // nsIFrame:
75 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
76 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
77 const nsLineList::iterator* aPrevFrameLine,
78 nsFrameList&& aFrameList) override;
79 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
81 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
82 const nsDisplayListSet& aLists) override {}
84 bool ComputeCustomOverflow(mozilla::OverflowAreas& aOverflowAreas) override;
86 protected:
87 /**
88 * Traverses a frame tree, marking any SVGTextFrame frames as dirty
89 * and calling InvalidateRenderingObservers() on it.
91 static void ReflowSVGNonDisplayText(nsIFrame* aContainer);
94 /**
95 * Frame class or base-class for SVG containers that can or do display their
96 * contents directly.
98 * *** WARNING ***
100 * This class's methods can *not* assume that mContent points to an instance of
101 * an SVG element class since this class is inherited by
102 * SVGGenericContainerFrame which is used for unrecognized elements in the
103 * SVG namespace. Do *not* blindly cast to SVG element types.
105 class SVGDisplayContainerFrame : public SVGContainerFrame,
106 public ISVGDisplayableFrame {
107 protected:
108 SVGDisplayContainerFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
109 nsIFrame::ClassID aID)
110 : SVGContainerFrame(aStyle, aPresContext, aID) {
111 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
114 public:
115 NS_DECL_QUERYFRAME
116 NS_DECL_QUERYFRAME_TARGET(SVGDisplayContainerFrame)
117 NS_DECL_ABSTRACT_FRAME(SVGDisplayContainerFrame)
119 // nsIFrame:
120 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
121 const nsLineList::iterator* aPrevFrameLine,
122 nsFrameList&& aFrameList) override;
123 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
124 void Init(nsIContent* aContent, nsContainerFrame* aParent,
125 nsIFrame* aPrevInFlow) override;
127 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
128 const nsDisplayListSet& aLists) override;
130 bool IsSVGTransformed(Matrix* aOwnTransform = nullptr,
131 Matrix* aFromParentTransform = nullptr) const override;
133 // ISVGDisplayableFrame interface:
134 void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
135 imgDrawingParams& aImgParams) override;
136 nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
137 void ReflowSVG() override;
138 void NotifySVGChanged(uint32_t aFlags) override;
139 SVGBBox GetBBoxContribution(const Matrix& aToBBoxUserspace,
140 uint32_t aFlags) override;
141 bool IsDisplayContainer() override { return true; }
142 gfxMatrix GetCanvasTM() override;
144 protected:
146 * Cached canvasTM value.
148 UniquePtr<gfxMatrix> mCanvasTM;
151 } // namespace mozilla
153 #endif // LAYOUT_SVG_SVGCONTAINERFRAME_H_