LCOV - code coverage report
Current view: directory - layout/svg/base/src - nsSVGGradientFrame.h (source / functions) Found Hit Coverage
Test: app.info Lines: 19 0 0.0 %
Date: 2012-06-02 Functions: 14 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is the Mozilla SVG project.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Scooter Morris.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2004
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Scooter Morris <scootermorris@comcast.net>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef __NS_SVGGRADIENTFRAME_H__
      40                 : #define __NS_SVGGRADIENTFRAME_H__
      41                 : 
      42                 : #include "nsSVGPaintServerFrame.h"
      43                 : #include "nsSVGElement.h"
      44                 : #include "gfxPattern.h"
      45                 : 
      46                 : class nsIDOMSVGStopElement;
      47                 : 
      48                 : typedef nsSVGPaintServerFrame nsSVGGradientFrameBase;
      49                 : 
      50                 : /**
      51                 :  * Gradients can refer to other gradients. We create an nsSVGPaintingProperty
      52                 :  * with property type nsGkAtoms::href to track the referenced gradient.
      53                 :  */
      54                 : class nsSVGGradientFrame : public nsSVGGradientFrameBase
      55               0 : {
      56                 : protected:
      57                 :   nsSVGGradientFrame(nsStyleContext* aContext);
      58                 : 
      59                 : public:
      60                 :   NS_DECL_FRAMEARENA_HELPERS
      61                 : 
      62                 :   // nsSVGPaintServerFrame methods:
      63                 :   virtual already_AddRefed<gfxPattern>
      64                 :     GetPaintServerPattern(nsIFrame *aSource,
      65                 :                           float aGraphicOpacity,
      66                 :                           const gfxRect *aOverrideBounds);
      67                 : 
      68                 :   // nsIFrame interface:
      69                 :   virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
      70                 : 
      71                 :   NS_IMETHOD AttributeChanged(PRInt32         aNameSpaceID,
      72                 :                               nsIAtom*        aAttribute,
      73                 :                               PRInt32         aModType);
      74                 : 
      75                 : #ifdef DEBUG
      76               0 :   NS_IMETHOD GetFrameName(nsAString& aResult) const
      77                 :   {
      78               0 :     return MakeFrameName(NS_LITERAL_STRING("SVGGradient"), aResult);
      79                 :   }
      80                 : #endif // DEBUG
      81                 : 
      82                 : private:
      83                 : 
      84                 :   // Parse our xlink:href and set up our nsSVGPaintingProperty if we
      85                 :   // reference another gradient and we don't have a property. Return
      86                 :   // the referenced gradient's frame if available, null otherwise.
      87                 :   nsSVGGradientFrame* GetReferencedGradient();
      88                 : 
      89                 :   // Optionally get a stop frame (returns stop index/count)
      90                 :   PRInt32 GetStopFrame(PRInt32 aIndex, nsIFrame * *aStopFrame);
      91                 : 
      92                 :   PRUint32 GetStopCount();
      93                 :   void GetStopInformation(PRInt32 aIndex,
      94                 :                           float *aOffset, nscolor *aColor, float *aStopOpacity);
      95                 : 
      96                 :   const mozilla::SVGAnimatedTransformList* GetGradientTransformList(
      97                 :     nsIContent* aDefault);
      98                 :   // Will be singular for gradientUnits="objectBoundingBox" with an empty bbox.
      99                 :   gfxMatrix GetGradientTransform(nsIFrame *aSource,
     100                 :                                  const gfxRect *aOverrideBounds);
     101                 : 
     102                 : protected:
     103                 :   virtual already_AddRefed<gfxPattern> CreateGradient() = 0;
     104                 : 
     105                 :   // Internal methods for handling referenced gradients
     106                 :   class AutoGradientReferencer;
     107                 :   nsSVGGradientFrame* GetReferencedGradientIfNotInUse();
     108                 : 
     109                 :   // Accessors to lookup gradient attributes
     110                 :   PRUint16 GetEnumValue(PRUint32 aIndex, nsIContent *aDefault);
     111               0 :   PRUint16 GetEnumValue(PRUint32 aIndex)
     112                 :   {
     113               0 :     return GetEnumValue(aIndex, mContent);
     114                 :   }
     115               0 :   PRUint16 GetGradientUnits()
     116                 :   {
     117                 :     // This getter is called every time the others are called - maybe cache it?
     118               0 :     return GetEnumValue(nsSVGGradientElement::GRADIENTUNITS);
     119                 :   }
     120               0 :   PRUint16 GetSpreadMethod()
     121                 :   {
     122               0 :     return GetEnumValue(nsSVGGradientElement::SPREADMETHOD);
     123                 :   }
     124                 : 
     125                 :   // Gradient-type-specific lookups since the length values differ between
     126                 :   // linear and radial gradients
     127                 :   virtual nsSVGLinearGradientElement * GetLinearGradientWithLength(
     128                 :     PRUint32 aIndex, nsSVGLinearGradientElement* aDefault);
     129                 :   virtual nsSVGRadialGradientElement * GetRadialGradientWithLength(
     130                 :     PRUint32 aIndex, nsSVGRadialGradientElement* aDefault);
     131                 : 
     132                 :   // The frame our gradient is (currently) being applied to
     133                 :   nsIFrame*                              mSource;
     134                 : 
     135                 : private:
     136                 :   // Flag to mark this frame as "in use" during recursive calls along our
     137                 :   // gradient's reference chain so we can detect reference loops. See:
     138                 :   // http://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
     139                 :   bool                                   mLoopFlag;
     140                 :   // Gradients often don't reference other gradients, so here we cache
     141                 :   // the fact that that isn't happening.
     142                 :   bool                                   mNoHRefURI;
     143                 : };
     144                 : 
     145                 : 
     146                 : // -------------------------------------------------------------------------
     147                 : // Linear Gradients
     148                 : // -------------------------------------------------------------------------
     149                 : 
     150                 : typedef nsSVGGradientFrame nsSVGLinearGradientFrameBase;
     151                 : 
     152                 : class nsSVGLinearGradientFrame : public nsSVGLinearGradientFrameBase
     153               0 : {
     154                 :   friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
     155                 :                                                 nsStyleContext* aContext);
     156                 : protected:
     157               0 :   nsSVGLinearGradientFrame(nsStyleContext* aContext) :
     158               0 :     nsSVGLinearGradientFrameBase(aContext) {}
     159                 : 
     160                 : public:
     161                 :   NS_DECL_FRAMEARENA_HELPERS
     162                 : 
     163                 :   // nsIFrame interface:
     164                 : #ifdef DEBUG
     165                 :   NS_IMETHOD Init(nsIContent*      aContent,
     166                 :                   nsIFrame*        aParent,
     167                 :                   nsIFrame*        aPrevInFlow);
     168                 : #endif
     169                 : 
     170                 :   virtual nsIAtom* GetType() const;  // frame type: nsGkAtoms::svgLinearGradientFrame
     171                 : 
     172                 :   NS_IMETHOD AttributeChanged(PRInt32         aNameSpaceID,
     173                 :                               nsIAtom*        aAttribute,
     174                 :                               PRInt32         aModType);
     175                 : 
     176                 : #ifdef DEBUG
     177               0 :   NS_IMETHOD GetFrameName(nsAString& aResult) const
     178                 :   {
     179               0 :     return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
     180                 :   }
     181                 : #endif // DEBUG
     182                 : 
     183                 : protected:
     184                 :   float GetLengthValue(PRUint32 aIndex);
     185                 :   virtual nsSVGLinearGradientElement * GetLinearGradientWithLength(
     186                 :     PRUint32 aIndex, nsSVGLinearGradientElement* aDefault);
     187                 :   virtual already_AddRefed<gfxPattern> CreateGradient();
     188                 : };
     189                 : 
     190                 : // -------------------------------------------------------------------------
     191                 : // Radial Gradients
     192                 : // -------------------------------------------------------------------------
     193                 : 
     194                 : typedef nsSVGGradientFrame nsSVGRadialGradientFrameBase;
     195                 : 
     196                 : class nsSVGRadialGradientFrame : public nsSVGRadialGradientFrameBase
     197               0 : {
     198                 :   friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
     199                 :                                                 nsStyleContext* aContext);
     200                 : protected:
     201               0 :   nsSVGRadialGradientFrame(nsStyleContext* aContext) :
     202               0 :     nsSVGRadialGradientFrameBase(aContext) {}
     203                 : 
     204                 : public:
     205                 :   NS_DECL_FRAMEARENA_HELPERS
     206                 : 
     207                 :   // nsIFrame interface:
     208                 : #ifdef DEBUG
     209                 :   NS_IMETHOD Init(nsIContent*      aContent,
     210                 :                   nsIFrame*        aParent,
     211                 :                   nsIFrame*        aPrevInFlow);
     212                 : #endif
     213                 : 
     214                 :   virtual nsIAtom* GetType() const;  // frame type: nsGkAtoms::svgRadialGradientFrame
     215                 : 
     216                 :   NS_IMETHOD AttributeChanged(PRInt32         aNameSpaceID,
     217                 :                               nsIAtom*        aAttribute,
     218                 :                               PRInt32         aModType);
     219                 : 
     220                 : #ifdef DEBUG
     221               0 :   NS_IMETHOD GetFrameName(nsAString& aResult) const
     222                 :   {
     223               0 :     return MakeFrameName(NS_LITERAL_STRING("SVGRadialGradient"), aResult);
     224                 :   }
     225                 : #endif // DEBUG
     226                 : 
     227                 : protected:
     228                 :   float GetLengthValue(PRUint32 aIndex);
     229                 :   float GetLengthValue(PRUint32 aIndex, float aDefaultValue);
     230                 :   float GetLengthValueFromElement(PRUint32 aIndex,
     231                 :                                   nsSVGRadialGradientElement& aElement);
     232                 :   virtual nsSVGRadialGradientElement * GetRadialGradientWithLength(
     233                 :     PRUint32 aIndex, nsSVGRadialGradientElement* aDefault);
     234                 :   virtual already_AddRefed<gfxPattern> CreateGradient();
     235                 : };
     236                 : 
     237                 : #endif // __NS_SVGGRADIENTFRAME_H__
     238                 : 

Generated by: LCOV version 1.7