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 __SVGGEOMETRYFRAME_H__
7 : #define __SVGGEOMETRYFRAME_H__
8 :
9 : #include "mozilla/Attributes.h"
10 : #include "gfxMatrix.h"
11 : #include "gfxRect.h"
12 : #include "nsFrame.h"
13 : #include "nsSVGDisplayableFrame.h"
14 : #include "nsLiteralString.h"
15 : #include "nsQueryFrame.h"
16 : #include "nsSVGUtils.h"
17 :
18 : namespace mozilla {
19 : class SVGGeometryFrame;
20 : namespace gfx {
21 : class DrawTarget;
22 : } // namespace gfx
23 : } // namespace mozilla
24 :
25 : class gfxContext;
26 : class nsDisplaySVGGeometry;
27 : class nsIAtom;
28 : class nsIFrame;
29 : class nsIPresShell;
30 : class nsStyleContext;
31 : class nsSVGMarkerFrame;
32 : class nsSVGMarkerProperty;
33 :
34 : struct nsRect;
35 :
36 : nsIFrame*
37 : NS_NewSVGGeometryFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
38 :
39 : namespace mozilla {
40 :
41 0 : class SVGGeometryFrame : public nsFrame
42 : , public nsSVGDisplayableFrame
43 : {
44 : typedef mozilla::gfx::DrawTarget DrawTarget;
45 :
46 : friend nsIFrame*
47 : ::NS_NewSVGGeometryFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
48 :
49 : friend class ::nsDisplaySVGGeometry;
50 :
51 : protected:
52 73 : SVGGeometryFrame(nsStyleContext* aContext, nsIFrame::ClassID aID)
53 73 : : nsFrame(aContext, aID)
54 : {
55 73 : AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_MAY_BE_TRANSFORMED);
56 73 : }
57 :
58 73 : explicit SVGGeometryFrame(nsStyleContext* aContext)
59 73 : : SVGGeometryFrame(aContext, kClassID)
60 73 : {}
61 :
62 : public:
63 : NS_DECL_QUERYFRAME
64 163 : NS_DECL_FRAMEARENA_HELPERS(SVGGeometryFrame)
65 :
66 : // nsIFrame interface:
67 : virtual void Init(nsIContent* aContent,
68 : nsContainerFrame* aParent,
69 : nsIFrame* aPrevInFlow) override;
70 :
71 594 : virtual bool IsFrameOfType(uint32_t aFlags) const override
72 : {
73 594 : return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG | nsIFrame::eSVGGeometry));
74 : }
75 :
76 : virtual nsresult AttributeChanged(int32_t aNameSpaceID,
77 : nsIAtom* aAttribute,
78 : int32_t aModType) override;
79 :
80 : virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
81 :
82 : virtual bool IsSVGTransformed(Matrix *aOwnTransforms = nullptr,
83 : Matrix *aFromParentTransforms = nullptr) const override;
84 :
85 : #ifdef DEBUG_FRAME_DUMP
86 0 : virtual nsresult GetFrameName(nsAString& aResult) const override
87 : {
88 0 : return MakeFrameName(NS_LITERAL_STRING("SVGGeometry"), aResult);
89 : }
90 : #endif
91 :
92 : virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
93 : const nsRect& aDirtyRect,
94 : const nsDisplayListSet& aLists) override;
95 :
96 : // SVGGeometryFrame methods
97 : gfxMatrix GetCanvasTM();
98 : protected:
99 : // nsSVGDisplayableFrame interface:
100 : virtual void PaintSVG(gfxContext& aContext,
101 : const gfxMatrix& aTransform,
102 : imgDrawingParams& aImgParams,
103 : const nsIntRect* aDirtyRect = nullptr) override;
104 : virtual nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
105 : virtual void ReflowSVG() override;
106 : virtual void NotifySVGChanged(uint32_t aFlags) override;
107 : virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace,
108 : uint32_t aFlags) override;
109 6 : virtual bool IsDisplayContainer() override { return false; }
110 :
111 : /**
112 : * This function returns a set of bit flags indicating which parts of the
113 : * element (fill, stroke, bounds) should intercept pointer events. It takes
114 : * into account the type of element and the value of the 'pointer-events'
115 : * property on the element.
116 : */
117 : virtual uint16_t GetHitTestFlags();
118 : private:
119 : enum { eRenderFill = 1, eRenderStroke = 2 };
120 : void Render(gfxContext* aContext, uint32_t aRenderComponents,
121 : const gfxMatrix& aTransform, imgDrawingParams& aImgParams);
122 :
123 : /**
124 : * @param aMatrix The transform that must be multiplied onto aContext to
125 : * establish this frame's SVG user space.
126 : */
127 : void PaintMarkers(gfxContext& aContext, const gfxMatrix& aMatrix,
128 : imgDrawingParams& aImgParams);
129 :
130 : struct MarkerProperties {
131 : nsSVGMarkerProperty* mMarkerStart;
132 : nsSVGMarkerProperty* mMarkerMid;
133 : nsSVGMarkerProperty* mMarkerEnd;
134 :
135 90 : bool MarkersExist() const {
136 90 : return mMarkerStart || mMarkerMid || mMarkerEnd;
137 : }
138 :
139 : nsSVGMarkerFrame *GetMarkerStartFrame();
140 : nsSVGMarkerFrame *GetMarkerMidFrame();
141 : nsSVGMarkerFrame *GetMarkerEndFrame();
142 : };
143 :
144 : /**
145 : * @param aFrame should be the first continuation
146 : */
147 : static MarkerProperties GetMarkerProperties(SVGGeometryFrame *aFrame);
148 : };
149 : } // namespace mozilla
150 :
151 : #endif // __SVGGEOMETRYFRAME_H__
|