LCOV - code coverage report
Current view: directory - content/svg/content/src - DOMSVGTransform.h (source / functions) Found Hit Coverage
Test: app.info Lines: 33 1 3.0 %
Date: 2012-06-02 Functions: 17 1 5.9 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is the Mozilla SVG project.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Crocodile Clips Ltd..
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2001
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
      25                 :  *   Brian Birtles <birtles@gmail.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      29                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #ifndef MOZILLA_DOMSVGTRANSFORM_H__
      42                 : #define MOZILLA_DOMSVGTRANSFORM_H__
      43                 : 
      44                 : #include "DOMSVGTransformList.h"
      45                 : #include "nsAutoPtr.h"
      46                 : #include "nsCycleCollectionParticipant.h"
      47                 : #include "nsDebug.h"
      48                 : #include "nsID.h"
      49                 : #include "nsIDOMSVGTransform.h"
      50                 : #include "nsTArray.h"
      51                 : #include "SVGTransform.h"
      52                 : 
      53                 : class nsSVGElement;
      54                 : 
      55                 : struct gfxMatrix;
      56                 : 
      57                 : // We make DOMSVGTransform a pseudo-interface to allow us to QI to it in order
      58                 : // to check that the objects that scripts pass in are our our *native* transform
      59                 : // objects.
      60                 : //
      61                 : // {0A799862-9469-41FE-B4CD-2019E65D8DA6}
      62                 : #define MOZILLA_DOMSVGTRANSFORM_IID \
      63                 :   { 0x0A799862, 0x9469, 0x41FE, \
      64                 :     { 0xB4, 0xCD, 0x20, 0x19, 0xE6, 0x5D, 0x8D, 0xA6 } }
      65                 : 
      66                 : #define MOZ_SVG_LIST_INDEX_BIT_COUNT 22 // supports > 4 million list items
      67                 : 
      68                 : namespace mozilla {
      69                 : 
      70                 : class DOMSVGMatrix;
      71                 : 
      72                 : /**
      73                 :  * DOM wrapper for an SVG transform. See DOMSVGLength.h.
      74                 :  */
      75                 : class DOMSVGTransform : public nsIDOMSVGTransform
      76                 : {
      77                 : public:
      78                 :   NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOMSVGTRANSFORM_IID)
      79               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      80            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS(DOMSVGTransform)
      81                 :   NS_DECL_NSIDOMSVGTRANSFORM
      82                 : 
      83                 :   /**
      84                 :    * Generic ctor for DOMSVGTransform objects that are created for an attribute.
      85                 :    */
      86                 :   DOMSVGTransform(DOMSVGTransformList *aList,
      87                 :                   PRUint32 aListIndex,
      88                 :                   bool aIsAnimValItem);
      89                 : 
      90                 :   /**
      91                 :    * Ctors for creating the objects returned by:
      92                 :    *   SVGSVGElement.createSVGTransform(),
      93                 :    *   SVGSVGElement.createSVGTransformFromMatrix(in SVGMatrix matrix),
      94                 :    *   SVGTransformList.createSVGTransformFromMatrix(in SVGMatrix matrix)
      95                 :    * which do not initially belong to an attribute.
      96                 :    */
      97                 :   DOMSVGTransform();
      98                 :   DOMSVGTransform(const gfxMatrix &aMatrix);
      99                 : 
     100                 :   /**
     101                 :    * Ctor for creating an unowned copy. Used with Clone().
     102                 :    */
     103                 :   DOMSVGTransform(const SVGTransform &aMatrix);
     104                 : 
     105               0 :   ~DOMSVGTransform() {
     106                 :     // Our matrix tear-off pointer should be cleared before we are destroyed
     107                 :     // (since matrix tear-offs keep an owning reference to their transform, and
     108                 :     // clear the tear-off pointer themselves if unlinked).
     109               0 :     NS_ABORT_IF_FALSE(!mMatrixTearoff, "Matrix tear-off pointer not cleared."
     110                 :         " Transform being destroyed before matrix?");
     111                 :     // Our mList's weak ref to us must be nulled out when we die. If GC has
     112                 :     // unlinked us using the cycle collector code, then that has already
     113                 :     // happened, and mList is null.
     114               0 :     if (mList) {
     115               0 :       mList->mItems[mListIndex] = nsnull;
     116                 :     }
     117               0 :   };
     118                 : 
     119                 :   /**
     120                 :    * Create an unowned copy of an owned transform. The caller is responsible for
     121                 :    * the first AddRef().
     122                 :    */
     123               0 :   DOMSVGTransform* Clone() {
     124               0 :     NS_ASSERTION(mList, "unexpected caller");
     125               0 :     return new DOMSVGTransform(InternalItem());
     126                 :   }
     127                 : 
     128                 :   bool IsInList() const {
     129                 :     return !!mList;
     130                 :   }
     131                 : 
     132                 :   /**
     133                 :    * In future, if this class is used for non-list transforms, this will be
     134                 :    * different to IsInList().
     135                 :    */
     136               0 :   bool HasOwner() const {
     137               0 :     return !!mList;
     138                 :   }
     139                 : 
     140                 :   /**
     141                 :    * This method is called to notify this DOM object that it is being inserted
     142                 :    * into a list, and give it the information it needs as a result.
     143                 :    *
     144                 :    * This object MUST NOT already belong to a list when this method is called.
     145                 :    * That's not to say that script can't move these DOM objects between
     146                 :    * lists - it can - it's just that the logic to handle that (and send out
     147                 :    * the necessary notifications) is located elsewhere (in
     148                 :    * DOMSVGTransformList).)
     149                 :    */
     150                 :   void InsertingIntoList(DOMSVGTransformList *aList,
     151                 :                          PRUint32 aListIndex,
     152                 :                          bool aIsAnimValItem);
     153                 : 
     154               0 :   static PRUint32 MaxListIndex() {
     155               0 :     return (1U << MOZ_SVG_LIST_INDEX_BIT_COUNT) - 1;
     156                 :   }
     157                 : 
     158                 :   /// This method is called to notify this object that its list index changed.
     159               0 :   void UpdateListIndex(PRUint32 aListIndex) {
     160               0 :     mListIndex = aListIndex;
     161               0 :   }
     162                 : 
     163                 :   /**
     164                 :    * This method is called to notify this DOM object that it is about to be
     165                 :    * removed from its current DOM list so that it can first make a copy of its
     166                 :    * internal counterpart's values. (If it didn't do this, then it would
     167                 :    * "lose" its value on being removed.)
     168                 :    */
     169                 :   void RemovingFromList();
     170                 : 
     171               0 :   SVGTransform ToSVGTransform() const {
     172               0 :     return Transform();
     173                 :   }
     174                 : 
     175                 : protected:
     176                 :   // Interface for DOMSVGMatrix's use
     177                 :   friend class DOMSVGMatrix;
     178               0 :   const bool IsAnimVal() const {
     179               0 :     return mIsAnimValItem;
     180                 :   }
     181               0 :   const gfxMatrix& Matrix() const {
     182               0 :     return Transform().Matrix();
     183                 :   }
     184                 :   void SetMatrix(const gfxMatrix& aMatrix);
     185                 :   void ClearMatrixTearoff(DOMSVGMatrix* aMatrix);
     186                 : 
     187                 : private:
     188               0 :   nsSVGElement* Element() {
     189               0 :     return mList->Element();
     190                 :   }
     191                 : 
     192                 :   /**
     193                 :    * Get a reference to the internal SVGTransform list item that this DOM
     194                 :    * wrapper object currently wraps.
     195                 :    */
     196                 :   SVGTransform& InternalItem();
     197                 :   const SVGTransform& InternalItem() const;
     198                 : 
     199                 : #ifdef DEBUG
     200                 :   bool IndexIsValid();
     201                 : #endif
     202                 : 
     203               0 :   const SVGTransform& Transform() const {
     204               0 :     return HasOwner() ? InternalItem() : *mTransform;
     205                 :   }
     206               0 :   SVGTransform& Transform() {
     207               0 :     return HasOwner() ? InternalItem() : *mTransform;
     208                 :   }
     209                 :   inline nsAttrValue NotifyElementWillChange();
     210                 :   void NotifyElementDidChange(const nsAttrValue& aEmptyOrOldValue);
     211                 : 
     212                 :   nsRefPtr<DOMSVGTransformList> mList;
     213                 : 
     214                 :   // Bounds for the following are checked in the ctor, so be sure to update
     215                 :   // that if you change the capacity of any of the following.
     216                 : 
     217                 :   PRUint32 mListIndex:MOZ_SVG_LIST_INDEX_BIT_COUNT;
     218                 :   bool mIsAnimValItem:1;
     219                 : 
     220                 :   // Usually this class acts as a wrapper for an SVGTransform object which is
     221                 :   // part of a list and is accessed by going via the owning Element.
     222                 :   //
     223                 :   // However, in some circumstances, objects of this class may not be associated
     224                 :   // with any particular list and thus, no internal SVGTransform object. In
     225                 :   // that case we allocate an SVGTransform object on the heap to store the data.
     226                 :   nsAutoPtr<SVGTransform> mTransform;
     227                 : 
     228                 :   // Weak ref to DOMSVGMatrix tearoff. The DOMSVGMatrix object will take of
     229                 :   // clearing this pointer when it is destroyed (by calling ClearMatrixTearoff).
     230                 :   //
     231                 :   // If this extra pointer member proves undesirable, it can be replaced with
     232                 :   // a hashmap (nsSVGAttrTearoffTable) to map from DOMSVGTransform to
     233                 :   // DOMSVGMatrix.
     234                 :   DOMSVGMatrix* mMatrixTearoff;
     235                 : };
     236                 : 
     237                 : NS_DEFINE_STATIC_IID_ACCESSOR(DOMSVGTransform, MOZILLA_DOMSVGTRANSFORM_IID)
     238                 : 
     239                 : nsAttrValue
     240               0 : DOMSVGTransform::NotifyElementWillChange()
     241                 : {
     242               0 :   nsAttrValue result;
     243               0 :   if (HasOwner()) {
     244               0 :     result = Element()->WillChangeTransformList();
     245                 :   }
     246                 :   return result;
     247                 : }
     248                 : 
     249                 : } // namespace mozilla
     250                 : 
     251                 : #undef MOZ_SVG_LIST_INDEX_BIT_COUNT
     252                 : 
     253                 : #endif // MOZILLA_DOMSVGTRANSFORM_H__

Generated by: LCOV version 1.7