LCOV - code coverage report
Current view: directory - content/svg/content/src - DOMSVGNumber.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 71 2 2.8 %
Date: 2012-06-02 Functions: 17 2 11.8 %

       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                 : #include "DOMSVGNumber.h"
      38                 : #include "DOMSVGNumberList.h"
      39                 : #include "DOMSVGAnimatedNumberList.h"
      40                 : #include "SVGAnimatedNumberList.h"
      41                 : #include "nsSVGElement.h"
      42                 : #include "nsIDOMSVGNumber.h"
      43                 : #include "nsDOMError.h"
      44                 : #include "nsContentUtils.h"
      45                 : 
      46                 : // See the architecture comment in DOMSVGAnimatedNumberList.h.
      47                 : 
      48                 : using namespace mozilla;
      49                 : 
      50                 : // We could use NS_IMPL_CYCLE_COLLECTION_1, except that in Unlink() we need to
      51                 : // clear our list's weak ref to us to be safe. (The other option would be to
      52                 : // not unlink and rely on the breaking of the other edges in the cycle, as
      53                 : // NS_SVG_VAL_IMPL_CYCLE_COLLECTION does.)
      54            1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGNumber)
      55               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGNumber)
      56                 :   // We may not belong to a list, so we must null check tmp->mList.
      57               0 :   if (tmp->mList) {
      58               0 :     tmp->mList->mItems[tmp->mListIndex] = nsnull;
      59                 :   }
      60               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mList)
      61               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
      62               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGNumber)
      63               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mList)
      64               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
      65                 : 
      66               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGNumber)
      67               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGNumber)
      68                 : 
      69                 : DOMCI_DATA(SVGNumber, DOMSVGNumber)
      70                 : 
      71               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGNumber)
      72               0 :   NS_INTERFACE_MAP_ENTRY(DOMSVGNumber) // pseudo-interface
      73               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGNumber)
      74               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
      75               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGNumber)
      76               0 : NS_INTERFACE_MAP_END
      77                 : 
      78               0 : DOMSVGNumber::DOMSVGNumber(DOMSVGNumberList *aList,
      79                 :                            PRUint8 aAttrEnum,
      80                 :                            PRUint32 aListIndex,
      81                 :                            PRUint8 aIsAnimValItem)
      82                 :   : mList(aList)
      83                 :   , mListIndex(aListIndex)
      84                 :   , mAttrEnum(aAttrEnum)
      85                 :   , mIsAnimValItem(aIsAnimValItem)
      86               0 :   , mValue(0.0f)
      87                 : {
      88                 :   // These shifts are in sync with the members in the header.
      89               0 :   NS_ABORT_IF_FALSE(aList &&
      90                 :                     aAttrEnum < (1 << 4) &&
      91                 :                     aListIndex <= MaxListIndex() &&
      92                 :                     aIsAnimValItem < (1 << 1), "bad arg");
      93                 : 
      94               0 :   NS_ABORT_IF_FALSE(IndexIsValid(), "Bad index for DOMSVGNumber!");
      95               0 : }
      96                 : 
      97               0 : DOMSVGNumber::DOMSVGNumber()
      98                 :   : mList(nsnull)
      99                 :   , mListIndex(0)
     100                 :   , mAttrEnum(0)
     101                 :   , mIsAnimValItem(false)
     102               0 :   , mValue(0.0f)
     103                 : {
     104               0 : }
     105                 : 
     106                 : NS_IMETHODIMP
     107               0 : DOMSVGNumber::GetValue(float* aValue)
     108                 : {
     109               0 :   if (mIsAnimValItem && HasOwner()) {
     110               0 :     Element()->FlushAnimations(); // May make HasOwner() == false
     111                 :   }
     112               0 :   *aValue = HasOwner() ? InternalItem() : mValue;
     113               0 :   return NS_OK;
     114                 : }
     115                 : 
     116                 : NS_IMETHODIMP
     117               0 : DOMSVGNumber::SetValue(float aValue)
     118                 : {
     119               0 :   if (mIsAnimValItem) {
     120               0 :     return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
     121                 :   }
     122                 : 
     123               0 :   NS_ENSURE_FINITE(aValue, NS_ERROR_ILLEGAL_VALUE);
     124                 : 
     125               0 :   if (HasOwner()) {
     126               0 :     if (InternalItem() == aValue) {
     127               0 :       return NS_OK;
     128                 :     }
     129               0 :     nsAttrValue emptyOrOldValue = Element()->WillChangeNumberList(mAttrEnum);
     130               0 :     InternalItem() = aValue;
     131               0 :     Element()->DidChangeNumberList(mAttrEnum, emptyOrOldValue);
     132               0 :     if (mList->mAList->IsAnimating()) {
     133               0 :       Element()->AnimationNeedsResample();
     134                 :     }
     135               0 :     return NS_OK;
     136                 :   }
     137               0 :   mValue = aValue;
     138               0 :   return NS_OK;
     139                 : }
     140                 : 
     141                 : void
     142               0 : DOMSVGNumber::InsertingIntoList(DOMSVGNumberList *aList,
     143                 :                                 PRUint8 aAttrEnum,
     144                 :                                 PRUint32 aListIndex,
     145                 :                                 PRUint8 aIsAnimValItem)
     146                 : {
     147               0 :   NS_ASSERTION(!HasOwner(), "Inserting item that is already in a list");
     148                 : 
     149               0 :   mList = aList;
     150               0 :   mAttrEnum = aAttrEnum;
     151               0 :   mListIndex = aListIndex;
     152               0 :   mIsAnimValItem = aIsAnimValItem;
     153                 : 
     154               0 :   NS_ABORT_IF_FALSE(IndexIsValid(), "Bad index for DOMSVGNumber!");
     155               0 : }
     156                 : 
     157                 : void
     158               0 : DOMSVGNumber::RemovingFromList()
     159                 : {
     160               0 :   mValue = InternalItem();
     161               0 :   mList = nsnull;
     162               0 :   mIsAnimValItem = false;
     163               0 : }
     164                 : 
     165                 : float
     166               0 : DOMSVGNumber::ToSVGNumber()
     167                 : {
     168               0 :   return HasOwner() ? InternalItem() : mValue;
     169                 : }
     170                 : 
     171                 : float&
     172               0 : DOMSVGNumber::InternalItem()
     173                 : {
     174               0 :   SVGAnimatedNumberList *alist = Element()->GetAnimatedNumberList(mAttrEnum);
     175               0 :   return mIsAnimValItem && alist->mAnimVal ?
     176               0 :     (*alist->mAnimVal)[mListIndex] :
     177               0 :     alist->mBaseVal[mListIndex];
     178                 : }
     179                 : 
     180                 : #ifdef DEBUG
     181                 : bool
     182               0 : DOMSVGNumber::IndexIsValid()
     183                 : {
     184               0 :   SVGAnimatedNumberList *alist = Element()->GetAnimatedNumberList(mAttrEnum);
     185                 :   return (mIsAnimValItem &&
     186               0 :           mListIndex < alist->GetAnimValue().Length()) ||
     187               0 :          (!mIsAnimValItem &&
     188               0 :           mListIndex < alist->GetBaseValue().Length());
     189            4392 : }
     190                 : #endif
     191                 : 

Generated by: LCOV version 1.7