LCOV - code coverage report
Current view: directory - content/svg/content/src - nsSVGEllipseElement.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 40 0 0.0 %
Date: 2012-06-02 Functions: 76 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                 :  * Crocodile Clips Ltd..
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2001
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   William Cook <william.cook@crocodile-clips.com> (original author)
      24                 :  *   Alex Fritze <alex.fritze@crocodile-clips.com>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "mozilla/Util.h"
      41                 : 
      42                 : #include "nsSVGPathGeometryElement.h"
      43                 : #include "nsIDOMSVGEllipseElement.h"
      44                 : #include "nsSVGLength2.h"
      45                 : #include "nsGkAtoms.h"
      46                 : #include "nsSVGUtils.h"
      47                 : #include "gfxContext.h"
      48                 : 
      49                 : using namespace mozilla;
      50                 : 
      51                 : typedef nsSVGPathGeometryElement nsSVGEllipseElementBase;
      52                 : 
      53                 : class nsSVGEllipseElement : public nsSVGEllipseElementBase,
      54                 :                             public nsIDOMSVGEllipseElement
      55               0 : {
      56                 : protected:
      57                 :   friend nsresult NS_NewSVGEllipseElement(nsIContent **aResult,
      58                 :                                           already_AddRefed<nsINodeInfo> aNodeInfo);
      59                 :   nsSVGEllipseElement(already_AddRefed<nsINodeInfo> aNodeInfo);
      60                 : 
      61                 : public:
      62                 :   // interfaces:
      63                 :   NS_DECL_ISUPPORTS_INHERITED
      64                 :   NS_DECL_NSIDOMSVGELLIPSEELEMENT
      65                 : 
      66                 :   // xxx I wish we could use virtual inheritance
      67               0 :   NS_FORWARD_NSIDOMNODE(nsSVGEllipseElementBase::)
      68               0 :   NS_FORWARD_NSIDOMELEMENT(nsSVGEllipseElementBase::)
      69               0 :   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGEllipseElementBase::)
      70                 : 
      71                 :   // nsSVGSVGElement methods:
      72                 :   virtual bool HasValidDimensions() const;
      73                 : 
      74                 :   // nsSVGPathGeometryElement methods:
      75                 :   virtual void ConstructPath(gfxContext *aCtx);
      76                 : 
      77                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
      78                 : 
      79                 :   virtual nsXPCClassInfo* GetClassInfo();
      80                 : protected:
      81                 : 
      82                 :   virtual LengthAttributesInfo GetLengthInfo();
      83                 : 
      84                 :   enum { CX, CY, RX, RY };
      85                 :   nsSVGLength2 mLengthAttributes[4];
      86                 :   static LengthInfo sLengthInfo[4];
      87                 : };
      88                 : 
      89                 : nsSVGElement::LengthInfo nsSVGEllipseElement::sLengthInfo[4] =
      90                 : {
      91                 :   { &nsGkAtoms::cx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
      92                 :   { &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
      93                 :   { &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
      94                 :   { &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
      95                 : };
      96                 : 
      97               0 : NS_IMPL_NS_NEW_SVG_ELEMENT(Ellipse)
      98                 : 
      99                 : //----------------------------------------------------------------------
     100                 : // nsISupports methods
     101                 : 
     102               0 : NS_IMPL_ADDREF_INHERITED(nsSVGEllipseElement,nsSVGEllipseElementBase)
     103               0 : NS_IMPL_RELEASE_INHERITED(nsSVGEllipseElement,nsSVGEllipseElementBase)
     104                 : 
     105               0 : DOMCI_NODE_DATA(SVGEllipseElement, nsSVGEllipseElement)
     106                 : 
     107               0 : NS_INTERFACE_TABLE_HEAD(nsSVGEllipseElement)
     108               0 :   NS_NODE_INTERFACE_TABLE5(nsSVGEllipseElement, nsIDOMNode, nsIDOMElement,
     109                 :                            nsIDOMSVGElement, nsIDOMSVGTests,
     110                 :                            nsIDOMSVGEllipseElement)
     111               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGEllipseElement)
     112               0 : NS_INTERFACE_MAP_END_INHERITING(nsSVGEllipseElementBase)
     113                 : 
     114                 : //----------------------------------------------------------------------
     115                 : // Implementation
     116                 : 
     117               0 : nsSVGEllipseElement::nsSVGEllipseElement(already_AddRefed<nsINodeInfo> aNodeInfo)
     118               0 :   : nsSVGEllipseElementBase(aNodeInfo)
     119                 : {
     120               0 : }
     121                 : 
     122                 : //----------------------------------------------------------------------
     123                 : // nsIDOMNode methods
     124                 : 
     125               0 : NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGEllipseElement)
     126                 : 
     127                 : //----------------------------------------------------------------------
     128                 : // nsIDOMSVGEllipseElement methods
     129                 : 
     130                 : /* readonly attribute nsIDOMSVGAnimatedLength cx; */
     131               0 : NS_IMETHODIMP nsSVGEllipseElement::GetCx(nsIDOMSVGAnimatedLength * *aCx)
     132                 : {
     133               0 :   return mLengthAttributes[CX].ToDOMAnimatedLength(aCx, this);
     134                 : }
     135                 : 
     136                 : /* readonly attribute nsIDOMSVGAnimatedLength cy; */
     137               0 : NS_IMETHODIMP nsSVGEllipseElement::GetCy(nsIDOMSVGAnimatedLength * *aCy)
     138                 : {
     139               0 :   return mLengthAttributes[CY].ToDOMAnimatedLength(aCy, this);
     140                 : }
     141                 : 
     142                 : /* readonly attribute nsIDOMSVGAnimatedLength rx; */
     143               0 : NS_IMETHODIMP nsSVGEllipseElement::GetRx(nsIDOMSVGAnimatedLength * *aRx)
     144                 : {
     145               0 :   return mLengthAttributes[RX].ToDOMAnimatedLength(aRx, this);
     146                 : }
     147                 : 
     148                 : /* readonly attribute nsIDOMSVGAnimatedLength ry; */
     149               0 : NS_IMETHODIMP nsSVGEllipseElement::GetRy(nsIDOMSVGAnimatedLength * *aRy)
     150                 : {
     151               0 :   return mLengthAttributes[RY].ToDOMAnimatedLength(aRy, this);
     152                 : }
     153                 : 
     154                 : //----------------------------------------------------------------------
     155                 : // nsSVGElement methods
     156                 : 
     157                 : /* virtual */ bool
     158               0 : nsSVGEllipseElement::HasValidDimensions() const
     159                 : {
     160               0 :   return mLengthAttributes[RX].IsExplicitlySet() &&
     161               0 :          mLengthAttributes[RX].GetAnimValInSpecifiedUnits() > 0 &&
     162               0 :          mLengthAttributes[RY].IsExplicitlySet() &&
     163               0 :          mLengthAttributes[RY].GetAnimValInSpecifiedUnits() > 0;
     164                 : }
     165                 : 
     166                 : nsSVGElement::LengthAttributesInfo
     167               0 : nsSVGEllipseElement::GetLengthInfo()
     168                 : {
     169                 :   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
     170               0 :                               ArrayLength(sLengthInfo));
     171                 : }
     172                 : 
     173                 : //----------------------------------------------------------------------
     174                 : // nsSVGPathGeometryElement methods
     175                 : 
     176                 : void
     177               0 : nsSVGEllipseElement::ConstructPath(gfxContext *aCtx)
     178                 : {
     179                 :   float x, y, rx, ry;
     180                 : 
     181               0 :   GetAnimatedLengthValues(&x, &y, &rx, &ry, nsnull);
     182                 : 
     183               0 :   if (rx > 0.0f && ry > 0.0f) {
     184               0 :     aCtx->Save();
     185               0 :     aCtx->Translate(gfxPoint(x, y));
     186               0 :     aCtx->Scale(rx, ry);
     187               0 :     aCtx->Arc(gfxPoint(0, 0), 1, 0, 2 * M_PI);
     188               0 :     aCtx->Restore();
     189                 :   }
     190               0 : }

Generated by: LCOV version 1.7