LCOV - code coverage report
Current view: directory - content/svg/content/src - DOMSVGNumber.h (source / functions) Found Hit Coverage
Test: app.info Lines: 19 1 5.3 %
Date: 2012-06-02 Functions: 11 1 9.1 %

       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 Mozilla SVG Project code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is the Mozilla Foundation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *
      23                 :  * Alternatively, the contents of this file may be used under the terms of
      24                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      25                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      26                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      27                 :  * of those above. If you wish to allow use of your version of this file only
      28                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      29                 :  * use your version of this file under the terms of the MPL, indicate your
      30                 :  * decision by deleting the provisions above and replace them with the notice
      31                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      32                 :  * the provisions above, a recipient may use your version of this file under
      33                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : #ifndef MOZILLA_DOMSVGNUMBER_H__
      38                 : #define MOZILLA_DOMSVGNUMBER_H__
      39                 : 
      40                 : #include "DOMSVGNumberList.h"
      41                 : #include "nsAutoPtr.h"
      42                 : #include "nsCycleCollectionParticipant.h"
      43                 : #include "nsIDOMSVGNumber.h"
      44                 : #include "nsTArray.h"
      45                 : 
      46                 : class nsSVGElement;
      47                 : 
      48                 : // We make DOMSVGNumber a pseudo-interface to allow us to QI to it in order to
      49                 : // check that the objects that scripts pass to DOMSVGNumberList methods are our
      50                 : // *native* number objects.
      51                 : //
      52                 : // {2CA92412-2E1F-4DDB-A16C-52B3B582270D}
      53                 : #define MOZILLA_DOMSVGNUMBER_IID \
      54                 :   { 0x2CA92412, 0x2E1F, 0x4DDB, \
      55                 :     { 0xA1, 0x6C, 0x52, 0xB3, 0xB5, 0x82, 0x27, 0x0D } }
      56                 : 
      57                 : #define MOZ_SVG_LIST_INDEX_BIT_COUNT 27 // supports > 134 million list items
      58                 : 
      59                 : namespace mozilla {
      60                 : 
      61                 : /**
      62                 :  * Class DOMSVGNumber
      63                 :  *
      64                 :  * This class creates the DOM objects that wrap internal SVGNumber objects that
      65                 :  * are in an SVGNumberList. It is also used to create the objects returned by
      66                 :  * SVGSVGElement.createSVGNumber().
      67                 :  *
      68                 :  * For the DOM wrapper classes for non-list SVGNumber, see nsSVGNumber2.h.
      69                 :  *
      70                 :  * See the architecture comment in DOMSVGAnimatedNumberList.h.
      71                 :  *
      72                 :  * See the comment in DOMSVGLength.h (yes, LENGTH), which applies here too.
      73                 :  */
      74                 : class DOMSVGNumber : public nsIDOMSVGNumber
      75                 : {
      76                 : public:
      77                 :   NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOMSVGNUMBER_IID)
      78               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      79            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS(DOMSVGNumber)
      80                 :   NS_DECL_NSIDOMSVGNUMBER
      81                 : 
      82                 :   /**
      83                 :    * Generic ctor for DOMSVGNumber objects that are created for an attribute.
      84                 :    */
      85                 :   DOMSVGNumber(DOMSVGNumberList *aList,
      86                 :                PRUint8 aAttrEnum,
      87                 :                PRUint32 aListIndex,
      88                 :                PRUint8 aIsAnimValItem);
      89                 : 
      90                 :   /**
      91                 :    * Ctor for creating the objects returned by SVGSVGElement.createSVGNumber(),
      92                 :    * which do not initially belong to an attribute.
      93                 :    */
      94                 :   DOMSVGNumber();
      95                 : 
      96               0 :   ~DOMSVGNumber() {
      97                 :     // Our mList's weak ref to us must be nulled out when we die. If GC has
      98                 :     // unlinked us using the cycle collector code, then that has already
      99                 :     // happened, and mList is null.
     100               0 :     if (mList) {
     101               0 :       mList->mItems[mListIndex] = nsnull;
     102                 :     }
     103               0 :   };
     104                 : 
     105                 :   /**
     106                 :    * Create an unowned copy. The caller is responsible for the first AddRef().
     107                 :    */
     108               0 :   DOMSVGNumber* Clone() {
     109               0 :     DOMSVGNumber *clone = new DOMSVGNumber();
     110               0 :     clone->mValue = ToSVGNumber();
     111               0 :     return clone;
     112                 :   }
     113                 : 
     114                 :   bool IsInList() const {
     115                 :     return !!mList;
     116                 :   }
     117                 : 
     118                 :   /**
     119                 :    * In future, if this class is used for non-list numbers, this will be
     120                 :    * different to IsInList().
     121                 :    */
     122               0 :   bool HasOwner() const {
     123               0 :     return !!mList;
     124                 :   }
     125                 : 
     126                 :   /**
     127                 :    * This method is called to notify this DOM object that it is being inserted
     128                 :    * into a list, and give it the information it needs as a result.
     129                 :    *
     130                 :    * This object MUST NOT already belong to a list when this method is called.
     131                 :    * That's not to say that script can't move these DOM objects between
     132                 :    * lists - it can - it's just that the logic to handle that (and send out
     133                 :    * the necessary notifications) is located elsewhere (in DOMSVGNumberList).)
     134                 :    */
     135                 :   void InsertingIntoList(DOMSVGNumberList *aList,
     136                 :                          PRUint8 aAttrEnum,
     137                 :                          PRUint32 aListIndex,
     138                 :                          PRUint8 aIsAnimValItem);
     139                 : 
     140               0 :   static PRUint32 MaxListIndex() {
     141               0 :     return (1U << MOZ_SVG_LIST_INDEX_BIT_COUNT) - 1;
     142                 :   }
     143                 : 
     144                 :   /// This method is called to notify this object that its list index changed.
     145               0 :   void UpdateListIndex(PRUint32 aListIndex) {
     146               0 :     mListIndex = aListIndex;
     147               0 :   }
     148                 : 
     149                 :   /**
     150                 :    * This method is called to notify this DOM object that it is about to be
     151                 :    * removed from its current DOM list so that it can first make a copy of its
     152                 :    * internal counterpart's value. (If it didn't do this, then it would
     153                 :    * "lose" its value on being removed.)
     154                 :    */
     155                 :   void RemovingFromList();
     156                 : 
     157                 :   float ToSVGNumber();
     158                 : 
     159                 : private:
     160                 : 
     161               0 :   nsSVGElement* Element() {
     162               0 :     return mList->Element();
     163                 :   }
     164                 : 
     165                 :   PRUint8 AttrEnum() const {
     166                 :     return mAttrEnum;
     167                 :   }
     168                 : 
     169                 :   /**
     170                 :    * Get a reference to the internal SVGNumber list item that this DOM wrapper
     171                 :    * object currently wraps.
     172                 :    *
     173                 :    * To simplify the code we just have this one method for obtaining both
     174                 :    * baseVal and animVal internal items. This means that animVal items don't
     175                 :    * get const protection, but then our setter methods guard against changing
     176                 :    * animVal items.
     177                 :    */
     178                 :   float& InternalItem();
     179                 : 
     180                 : #ifdef DEBUG
     181                 :   bool IndexIsValid();
     182                 : #endif
     183                 : 
     184                 :   nsRefPtr<DOMSVGNumberList> mList;
     185                 : 
     186                 :   // Bounds for the following are checked in the ctor, so be sure to update
     187                 :   // that if you change the capacity of any of the following.
     188                 : 
     189                 :   PRUint32 mListIndex:MOZ_SVG_LIST_INDEX_BIT_COUNT;
     190                 :   PRUint32 mAttrEnum:4; // supports up to 16 attributes
     191                 :   PRUint32 mIsAnimValItem:1;
     192                 : 
     193                 :   // The following member is only used when we're not in a list:
     194                 :   float mValue;
     195                 : };
     196                 : 
     197                 : NS_DEFINE_STATIC_IID_ACCESSOR(DOMSVGNumber, MOZILLA_DOMSVGNUMBER_IID)
     198                 : 
     199                 : } // namespace mozilla
     200                 : 
     201                 : #undef MOZ_SVG_LIST_INDEX_BIT_COUNT
     202                 : 
     203                 : #endif // MOZILLA_DOMSVGNUMBER_H__

Generated by: LCOV version 1.7