1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/svg/nsSVGMarkerFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,188 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef __NS_SVGMARKERFRAME_H__ 1.10 +#define __NS_SVGMARKERFRAME_H__ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "gfxMatrix.h" 1.14 +#include "gfxRect.h" 1.15 +#include "nsFrame.h" 1.16 +#include "nsLiteralString.h" 1.17 +#include "nsQueryFrame.h" 1.18 +#include "nsSVGContainerFrame.h" 1.19 +#include "nsSVGUtils.h" 1.20 + 1.21 +class nsIAtom; 1.22 +class nsIContent; 1.23 +class nsIFrame; 1.24 +class nsIPresShell; 1.25 +class nsRenderingContext; 1.26 +class nsStyleContext; 1.27 +class nsSVGPathGeometryFrame; 1.28 + 1.29 +namespace mozilla { 1.30 +namespace dom { 1.31 +class SVGSVGElement; 1.32 +} 1.33 +} 1.34 + 1.35 +struct nsSVGMark; 1.36 + 1.37 +typedef nsSVGContainerFrame nsSVGMarkerFrameBase; 1.38 + 1.39 +class nsSVGMarkerFrame : public nsSVGMarkerFrameBase 1.40 +{ 1.41 + friend class nsSVGMarkerAnonChildFrame; 1.42 + friend nsIFrame* 1.43 + NS_NewSVGMarkerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.44 +protected: 1.45 + nsSVGMarkerFrame(nsStyleContext* aContext) 1.46 + : nsSVGMarkerFrameBase(aContext) 1.47 + , mMarkedFrame(nullptr) 1.48 + , mInUse(false) 1.49 + , mInUse2(false) 1.50 + { 1.51 + AddStateBits(NS_FRAME_IS_NONDISPLAY); 1.52 + } 1.53 + 1.54 +public: 1.55 + NS_DECL_FRAMEARENA_HELPERS 1.56 + 1.57 + // nsIFrame interface: 1.58 +#ifdef DEBUG 1.59 + virtual void Init(nsIContent* aContent, 1.60 + nsIFrame* aParent, 1.61 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.62 +#endif 1.63 + 1.64 + virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.65 + const nsRect& aDirtyRect, 1.66 + const nsDisplayListSet& aLists) MOZ_OVERRIDE {} 1.67 + 1.68 + virtual nsresult AttributeChanged(int32_t aNameSpaceID, 1.69 + nsIAtom* aAttribute, 1.70 + int32_t aModType) MOZ_OVERRIDE; 1.71 + /** 1.72 + * Get the "type" of the frame 1.73 + * 1.74 + * @see nsGkAtoms::svgMarkerFrame 1.75 + */ 1.76 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.77 + 1.78 +#ifdef DEBUG_FRAME_DUMP 1.79 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE 1.80 + { 1.81 + return MakeFrameName(NS_LITERAL_STRING("SVGMarker"), aResult); 1.82 + } 1.83 +#endif 1.84 + 1.85 + virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE { 1.86 + // Any children must be added to our single anonymous inner frame kid. 1.87 + NS_ABORT_IF_FALSE(GetFirstPrincipalChild() && 1.88 + GetFirstPrincipalChild()->GetType() == 1.89 + nsGkAtoms::svgMarkerAnonChildFrame, 1.90 + "Where is our anonymous child?"); 1.91 + return GetFirstPrincipalChild()->GetContentInsertionFrame(); 1.92 + } 1.93 + 1.94 + // nsSVGMarkerFrame methods: 1.95 + nsresult PaintMark(nsRenderingContext *aContext, 1.96 + nsSVGPathGeometryFrame *aMarkedFrame, 1.97 + nsSVGMark *aMark, 1.98 + float aStrokeWidth); 1.99 + 1.100 + SVGBBox GetMarkBBoxContribution(const Matrix &aToBBoxUserspace, 1.101 + uint32_t aFlags, 1.102 + nsSVGPathGeometryFrame *aMarkedFrame, 1.103 + const nsSVGMark *aMark, 1.104 + float aStrokeWidth); 1.105 + 1.106 +private: 1.107 + // stuff needed for callback 1.108 + nsSVGPathGeometryFrame *mMarkedFrame; 1.109 + float mStrokeWidth, mX, mY, mAutoAngle; 1.110 + bool mIsStart; // whether the callback is for a marker-start marker 1.111 + 1.112 + // nsSVGContainerFrame methods: 1.113 + virtual gfxMatrix GetCanvasTM(uint32_t aFor, 1.114 + nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; 1.115 + 1.116 + // A helper class to allow us to paint markers safely. The helper 1.117 + // automatically sets and clears the mInUse flag on the marker frame (to 1.118 + // prevent nasty reference loops) as well as the reference to the marked 1.119 + // frame and its coordinate context. It's easy to mess this up 1.120 + // and break things, so this helper makes the code far more robust. 1.121 + class MOZ_STACK_CLASS AutoMarkerReferencer 1.122 + { 1.123 + public: 1.124 + AutoMarkerReferencer(nsSVGMarkerFrame *aFrame, 1.125 + nsSVGPathGeometryFrame *aMarkedFrame 1.126 + MOZ_GUARD_OBJECT_NOTIFIER_PARAM); 1.127 + ~AutoMarkerReferencer(); 1.128 + private: 1.129 + nsSVGMarkerFrame *mFrame; 1.130 + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER 1.131 + }; 1.132 + 1.133 + // nsSVGMarkerFrame methods: 1.134 + void SetParentCoordCtxProvider(mozilla::dom::SVGSVGElement *aContext); 1.135 + 1.136 + // recursion prevention flag 1.137 + bool mInUse; 1.138 + 1.139 + // second recursion prevention flag, for GetCanvasTM() 1.140 + bool mInUse2; 1.141 +}; 1.142 + 1.143 +//////////////////////////////////////////////////////////////////////// 1.144 +// nsMarkerAnonChildFrame class 1.145 + 1.146 +typedef nsSVGDisplayContainerFrame nsSVGMarkerAnonChildFrameBase; 1.147 + 1.148 +/** 1.149 + */ 1.150 +class nsSVGMarkerAnonChildFrame 1.151 + : public nsSVGMarkerAnonChildFrameBase 1.152 +{ 1.153 + friend nsIFrame* 1.154 + NS_NewSVGMarkerAnonChildFrame(nsIPresShell* aPresShell, 1.155 + nsStyleContext* aContext); 1.156 + 1.157 + nsSVGMarkerAnonChildFrame(nsStyleContext* aContext) 1.158 + : nsSVGMarkerAnonChildFrameBase(aContext) 1.159 + {} 1.160 + 1.161 +public: 1.162 + NS_DECL_FRAMEARENA_HELPERS 1.163 + 1.164 +#ifdef DEBUG 1.165 + virtual void Init(nsIContent* aContent, 1.166 + nsIFrame* aParent, 1.167 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.168 +#endif 1.169 + 1.170 +#ifdef DEBUG_FRAME_DUMP 1.171 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { 1.172 + return MakeFrameName(NS_LITERAL_STRING("SVGMarkerAnonChild"), aResult); 1.173 + } 1.174 +#endif 1.175 + 1.176 + /** 1.177 + * Get the "type" of the frame 1.178 + * 1.179 + * @see nsGkAtoms::svgMarkerAnonChildFrame 1.180 + */ 1.181 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.182 + 1.183 + // nsSVGContainerFrame methods: 1.184 + virtual gfxMatrix GetCanvasTM(uint32_t aFor, 1.185 + nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE 1.186 + { 1.187 + nsSVGMarkerFrame* marker = static_cast<nsSVGMarkerFrame*>(mParent); 1.188 + return marker->GetCanvasTM(aFor, aTransformRoot); 1.189 + } 1.190 +}; 1.191 +#endif