1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/svg/nsSVGClipPathFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 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_SVGCLIPPATHFRAME_H__ 1.10 +#define __NS_SVGCLIPPATHFRAME_H__ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "gfxMatrix.h" 1.14 +#include "nsSVGContainerFrame.h" 1.15 +#include "nsSVGUtils.h" 1.16 + 1.17 +class nsRenderingContext; 1.18 +class nsISVGChildFrame; 1.19 + 1.20 +typedef nsSVGContainerFrame nsSVGClipPathFrameBase; 1.21 + 1.22 +class nsSVGClipPathFrame : public nsSVGClipPathFrameBase 1.23 +{ 1.24 + friend nsIFrame* 1.25 + NS_NewSVGClipPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.26 +protected: 1.27 + nsSVGClipPathFrame(nsStyleContext* aContext) 1.28 + : nsSVGClipPathFrameBase(aContext) 1.29 + , mInUse(false) 1.30 + { 1.31 + AddStateBits(NS_FRAME_IS_NONDISPLAY); 1.32 + } 1.33 + 1.34 +public: 1.35 + NS_DECL_FRAMEARENA_HELPERS 1.36 + 1.37 + // nsIFrame methods: 1.38 + virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.39 + const nsRect& aDirtyRect, 1.40 + const nsDisplayListSet& aLists) MOZ_OVERRIDE {} 1.41 + 1.42 + // nsSVGClipPathFrame methods: 1.43 + nsresult ClipPaint(nsRenderingContext* aContext, 1.44 + nsIFrame* aParent, 1.45 + const gfxMatrix &aMatrix); 1.46 + 1.47 + bool ClipHitTest(nsIFrame* aParent, 1.48 + const gfxMatrix &aMatrix, 1.49 + const nsPoint &aPoint); 1.50 + 1.51 + // Check if this clipPath is made up of more than one geometry object. 1.52 + // If so, the clipping API in cairo isn't enough and we need to use 1.53 + // mask based clipping. 1.54 + bool IsTrivial(nsISVGChildFrame **aSingleChild = nullptr); 1.55 + 1.56 + bool IsValid(); 1.57 + 1.58 + // nsIFrame interface: 1.59 + virtual nsresult AttributeChanged(int32_t aNameSpaceID, 1.60 + nsIAtom* aAttribute, 1.61 + int32_t aModType) MOZ_OVERRIDE; 1.62 + 1.63 + virtual void Init(nsIContent* aContent, 1.64 + nsIFrame* aParent, 1.65 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.66 + 1.67 + /** 1.68 + * Get the "type" of the frame 1.69 + * 1.70 + * @see nsGkAtoms::svgClipPathFrame 1.71 + */ 1.72 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.73 + 1.74 +#ifdef DEBUG_FRAME_DUMP 1.75 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE 1.76 + { 1.77 + return MakeFrameName(NS_LITERAL_STRING("SVGClipPath"), aResult); 1.78 + } 1.79 +#endif 1.80 + 1.81 + private: 1.82 + // A helper class to allow us to paint clip paths safely. The helper 1.83 + // automatically sets and clears the mInUse flag on the clip path frame 1.84 + // (to prevent nasty reference loops). It's easy to mess this up 1.85 + // and break things, so this helper makes the code far more robust. 1.86 + class MOZ_STACK_CLASS AutoClipPathReferencer 1.87 + { 1.88 + public: 1.89 + AutoClipPathReferencer(nsSVGClipPathFrame *aFrame 1.90 + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) 1.91 + : mFrame(aFrame) { 1.92 + MOZ_GUARD_OBJECT_NOTIFIER_INIT; 1.93 + NS_ASSERTION(!mFrame->mInUse, "reference loop!"); 1.94 + mFrame->mInUse = true; 1.95 + } 1.96 + ~AutoClipPathReferencer() { 1.97 + mFrame->mInUse = false; 1.98 + } 1.99 + private: 1.100 + nsSVGClipPathFrame *mFrame; 1.101 + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER 1.102 + }; 1.103 + 1.104 + nsIFrame *mClipParent; 1.105 + nsAutoPtr<gfxMatrix> mClipParentMatrix; 1.106 + // recursion prevention flag 1.107 + bool mInUse; 1.108 + 1.109 + // nsSVGContainerFrame methods: 1.110 + virtual gfxMatrix GetCanvasTM(uint32_t aFor, 1.111 + nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; 1.112 +}; 1.113 + 1.114 +#endif