LCOV - code coverage report
Current view: directory - content/svg/content/src - nsSVGLineElement.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 41 0 0.0 %
Date: 2012-06-02 Functions: 78 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 "nsIDOMSVGLineElement.h"
      44                 : #include "nsSVGLength2.h"
      45                 : #include "nsGkAtoms.h"
      46                 : #include "gfxContext.h"
      47                 : 
      48                 : using namespace mozilla;
      49                 : 
      50                 : typedef nsSVGPathGeometryElement nsSVGLineElementBase;
      51                 : 
      52                 : class nsSVGLineElement : public nsSVGLineElementBase,
      53                 :                          public nsIDOMSVGLineElement
      54               0 : {
      55                 : protected:
      56                 :   friend nsresult NS_NewSVGLineElement(nsIContent **aResult,
      57                 :                                        already_AddRefed<nsINodeInfo> aNodeInfo);
      58                 :   nsSVGLineElement(already_AddRefed<nsINodeInfo> aNodeInfo);
      59                 : 
      60                 : public:
      61                 :   // interfaces:
      62                 :   NS_DECL_ISUPPORTS_INHERITED
      63                 :   NS_DECL_NSIDOMSVGLINEELEMENT
      64                 : 
      65                 :   // xxx I wish we could use virtual inheritance
      66               0 :   NS_FORWARD_NSIDOMNODE(nsSVGLineElementBase::)
      67               0 :   NS_FORWARD_NSIDOMELEMENT(nsSVGLineElementBase::)
      68               0 :   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGLineElementBase::)
      69                 : 
      70                 :   // nsIContent interface
      71                 :   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
      72                 : 
      73                 :   // nsSVGPathGeometryElement methods:
      74               0 :   virtual bool IsMarkable() { return true; }
      75                 :   virtual void GetMarkPoints(nsTArray<nsSVGMark> *aMarks);
      76                 :   virtual void ConstructPath(gfxContext *aCtx);
      77                 : 
      78                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
      79                 : 
      80                 :   virtual nsXPCClassInfo* GetClassInfo();
      81                 : protected:
      82                 : 
      83                 :   virtual LengthAttributesInfo GetLengthInfo();
      84                 : 
      85                 :   enum { X1, Y1, X2, Y2 };
      86                 :   nsSVGLength2 mLengthAttributes[4];
      87                 :   static LengthInfo sLengthInfo[4];
      88                 : };
      89                 : 
      90                 : nsSVGElement::LengthInfo nsSVGLineElement::sLengthInfo[4] =
      91                 : {
      92                 :   { &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
      93                 :   { &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
      94                 :   { &nsGkAtoms::x2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::X },
      95                 :   { &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, nsSVGUtils::Y },
      96                 : };
      97                 : 
      98               0 : NS_IMPL_NS_NEW_SVG_ELEMENT(Line)
      99                 : 
     100                 : //----------------------------------------------------------------------
     101                 : // nsISupports methods
     102                 : 
     103               0 : NS_IMPL_ADDREF_INHERITED(nsSVGLineElement,nsSVGLineElementBase)
     104               0 : NS_IMPL_RELEASE_INHERITED(nsSVGLineElement,nsSVGLineElementBase)
     105                 : 
     106               0 : DOMCI_NODE_DATA(SVGLineElement, nsSVGLineElement)
     107                 : 
     108               0 : NS_INTERFACE_TABLE_HEAD(nsSVGLineElement)
     109               0 :   NS_NODE_INTERFACE_TABLE5(nsSVGLineElement, nsIDOMNode, nsIDOMElement,
     110                 :                            nsIDOMSVGElement, nsIDOMSVGTests,
     111                 :                            nsIDOMSVGLineElement)
     112               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGLineElement)
     113               0 : NS_INTERFACE_MAP_END_INHERITING(nsSVGLineElementBase)
     114                 : 
     115                 : //----------------------------------------------------------------------
     116                 : // Implementation
     117                 : 
     118               0 : nsSVGLineElement::nsSVGLineElement(already_AddRefed<nsINodeInfo> aNodeInfo)
     119               0 :   : nsSVGLineElementBase(aNodeInfo)
     120                 : {
     121               0 : }
     122                 : 
     123                 : //----------------------------------------------------------------------
     124                 : // nsIDOMNode methods
     125                 : 
     126               0 : NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGLineElement)
     127                 : 
     128                 : //----------------------------------------------------------------------
     129                 : // nsIDOMSVGLineElement methods
     130                 : 
     131                 : /* readonly attribute nsIDOMSVGAnimatedLength cx; */
     132               0 : NS_IMETHODIMP nsSVGLineElement::GetX1(nsIDOMSVGAnimatedLength * *aX1)
     133                 : {
     134               0 :   return mLengthAttributes[X1].ToDOMAnimatedLength(aX1, this);
     135                 : }
     136                 : 
     137                 : /* readonly attribute nsIDOMSVGAnimatedLength cy; */
     138               0 : NS_IMETHODIMP nsSVGLineElement::GetY1(nsIDOMSVGAnimatedLength * *aY1)
     139                 : {
     140               0 :   return mLengthAttributes[Y1].ToDOMAnimatedLength(aY1, this);
     141                 : }
     142                 : 
     143                 : /* readonly attribute nsIDOMSVGAnimatedLength rx; */
     144               0 : NS_IMETHODIMP nsSVGLineElement::GetX2(nsIDOMSVGAnimatedLength * *aX2)
     145                 : {
     146               0 :   return mLengthAttributes[X2].ToDOMAnimatedLength(aX2, this);
     147                 : }
     148                 : 
     149                 : /* readonly attribute nsIDOMSVGAnimatedLength ry; */
     150               0 : NS_IMETHODIMP nsSVGLineElement::GetY2(nsIDOMSVGAnimatedLength * *aY2)
     151                 : {
     152               0 :   return mLengthAttributes[Y2].ToDOMAnimatedLength(aY2, this);
     153                 : }
     154                 : 
     155                 : //----------------------------------------------------------------------
     156                 : // nsIContent methods
     157                 : 
     158                 : NS_IMETHODIMP_(bool)
     159               0 : nsSVGLineElement::IsAttributeMapped(const nsIAtom* name) const
     160                 : {
     161                 :   static const MappedAttributeEntry* const map[] = {
     162                 :     sMarkersMap
     163                 :   };
     164                 :   
     165               0 :   return FindAttributeDependence(name, map) ||
     166               0 :     nsSVGLineElementBase::IsAttributeMapped(name);
     167                 : }
     168                 : 
     169                 : //----------------------------------------------------------------------
     170                 : // nsSVGElement methods
     171                 : 
     172                 : nsSVGElement::LengthAttributesInfo
     173               0 : nsSVGLineElement::GetLengthInfo()
     174                 : {
     175                 :   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
     176               0 :                               ArrayLength(sLengthInfo));
     177                 : }
     178                 : 
     179                 : //----------------------------------------------------------------------
     180                 : // nsSVGPathGeometryElement methods
     181                 : 
     182                 : void
     183               0 : nsSVGLineElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks) {
     184                 :   float x1, y1, x2, y2;
     185                 : 
     186               0 :   GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nsnull);
     187                 : 
     188               0 :   float angle = atan2(y2 - y1, x2 - x1);
     189                 : 
     190               0 :   aMarks->AppendElement(nsSVGMark(x1, y1, angle));
     191               0 :   aMarks->AppendElement(nsSVGMark(x2, y2, angle));
     192               0 : }
     193                 : 
     194                 : void
     195               0 : nsSVGLineElement::ConstructPath(gfxContext *aCtx)
     196                 : {
     197                 :   float x1, y1, x2, y2;
     198                 : 
     199               0 :   GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nsnull);
     200                 : 
     201               0 :   aCtx->MoveTo(gfxPoint(x1, y1));
     202               0 :   aCtx->LineTo(gfxPoint(x2, y2));
     203               0 : }

Generated by: LCOV version 1.7