LCOV - app.info - content/svg/content/src/DOMSVGPoint.cpp

LCOV - code coverage report
| Current view: | directory - content/svg/content/src - DOMSVGPoint.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 85 | 2 | 2.4 %
| Date: | 2012-04-21 | 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 "DOMSVGPoint.h"
          38                 : #include "DOMSVGPointList.h"
          39                 : #include "SVGPoint.h"
          40                 : #include "SVGAnimatedPointList.h"
          41                 : #include "nsSVGElement.h"
          42                 : #include "nsIDOMSVGPoint.h"
          43                 : #include "nsDOMError.h"
          44                 : #include "nsIDOMSVGMatrix.h"
          45                 : #include "nsContentUtils.h" // NS_ENSURE_FINITE
          46                 : #include "DOMSVGMatrix.h"
          47                 :
          48                 : // See the architecture comment in DOMSVGPointList.h.
          49                 :
          50                 : using namespace mozilla;
          51                 :
          52                 : // We could use NS_IMPL_CYCLE_COLLECTION_1, except that in Unlink() we need to
          53                 : // clear our list's weak ref to us to be safe. (The other option would be to
          54                 : // not unlink and rely on the breaking of the other edges in the cycle, as
          55                 : // NS_SVG_VAL_IMPL_CYCLE_COLLECTION does.)
          56            1396 : NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGPoint)
          57               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGPoint)
          58                 :   // We may not belong to a list, so we must null check tmp->mList.
          59               0 :   if (tmp->mList) {
          60               0 :     tmp->mList->mItems[tmp->mListIndex] = nsnull;
          61                 :   }
          62               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mList)
          63               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
          64               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGPoint)
          65               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mList)
          66               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
          67                 :
          68               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGPoint)
          69               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGPoint)
          70                 :
          71                 : DOMCI_DATA(SVGPoint, DOMSVGPoint)
          72                 :
          73               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGPoint)
          74               0 :   NS_INTERFACE_MAP_ENTRY(DOMSVGPoint) // pseudo-interface
          75               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGPoint)
          76               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
          77               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGPoint)
          78               0 : NS_INTERFACE_MAP_END
          79                 :
          80                 :
          81                 : NS_IMETHODIMP
          82               0 : DOMSVGPoint::GetX(float* aX)
          83                 : {
          84               0 :   if (mIsAnimValItem && HasOwner()) {
          85               0 :     Element()->FlushAnimations(); // May make HasOwner() == false
          86                 :   }
          87               0 :   *aX = HasOwner() ? InternalItem().mX : mPt.mX;
          88               0 :   return NS_OK;
          89                 : }
          90                 :
          91                 : NS_IMETHODIMP
          92               0 : DOMSVGPoint::SetX(float aX)
          93                 : {
          94               0 :   if (mIsAnimValItem || mIsReadonly) {
          95               0 :     return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
          96                 :   }
          97                 :
          98               0 :   NS_ENSURE_FINITE(aX, NS_ERROR_ILLEGAL_VALUE);
          99                 :
         100               0 :   if (HasOwner()) {
         101               0 :     if (InternalItem().mX == aX) {
         102               0 :       return NS_OK;
         103                 :     }
         104               0 :     nsAttrValue emptyOrOldValue = Element()->WillChangePointList();
         105               0 :     InternalItem().mX = aX;
         106               0 :     Element()->DidChangePointList(emptyOrOldValue);
         107               0 :     if (mList->AttrIsAnimating()) {
         108               0 :       Element()->AnimationNeedsResample();
         109                 :     }
         110               0 :     return NS_OK;
         111                 :   }
         112               0 :   mPt.mX = aX;
         113               0 :   return NS_OK;
         114                 : }
         115                 :
         116                 : NS_IMETHODIMP
         117               0 : DOMSVGPoint::GetY(float* aY)
         118                 : {
         119               0 :   if (mIsAnimValItem && HasOwner()) {
         120               0 :     Element()->FlushAnimations(); // May make HasOwner() == false
         121                 :   }
         122               0 :   *aY = HasOwner() ? InternalItem().mY : mPt.mY;
         123               0 :   return NS_OK;
         124                 : }
         125                 :
         126                 : NS_IMETHODIMP
         127               0 : DOMSVGPoint::SetY(float aY)
         128                 : {
         129               0 :   if (mIsAnimValItem || mIsReadonly) {
         130               0 :     return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
         131                 :   }
         132                 :
         133               0 :   NS_ENSURE_FINITE(aY, NS_ERROR_ILLEGAL_VALUE);
         134                 :
         135               0 :   if (HasOwner()) {
         136               0 :     if (InternalItem().mY == aY) {
         137               0 :       return NS_OK;
         138                 :     }
         139               0 :     nsAttrValue emptyOrOldValue = Element()->WillChangePointList();
         140               0 :     InternalItem().mY = aY;
         141               0 :     Element()->DidChangePointList(emptyOrOldValue);
         142               0 :     if (mList->AttrIsAnimating()) {
         143               0 :       Element()->AnimationNeedsResample();
         144                 :     }
         145               0 :     return NS_OK;
         146                 :   }
         147               0 :   mPt.mY = aY;
         148               0 :   return NS_OK;
         149                 : }
         150                 :
         151                 : NS_IMETHODIMP
         152               0 : DOMSVGPoint::MatrixTransform(nsIDOMSVGMatrix *matrix,
         153                 :                              nsIDOMSVGPoint **_retval)
         154                 : {
         155               0 :   nsCOMPtr<DOMSVGMatrix> domMatrix = do_QueryInterface(matrix);
         156               0 :   if (!domMatrix)
         157               0 :     return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
         158                 :
         159               0 :   float x = HasOwner() ? InternalItem().mX : mPt.mX;
         160               0 :   float y = HasOwner() ? InternalItem().mY : mPt.mY;
         161                 :
         162               0 :   gfxPoint pt = domMatrix->Matrix().Transform(gfxPoint(x, y));
         163               0 :   NS_ADDREF(*_retval = new DOMSVGPoint(pt));
         164                 :
         165               0 :   return NS_OK;
         166                 : }
         167                 :
         168                 : void
         169               0 : DOMSVGPoint::InsertingIntoList(DOMSVGPointList *aList,
         170                 :                                PRUint32 aListIndex,
         171                 :                                bool aIsAnimValItem)
         172                 : {
         173               0 :   NS_ABORT_IF_FALSE(!HasOwner(), "Inserting item that already has an owner");
         174                 :
         175               0 :   mList = aList;
         176               0 :   mListIndex = aListIndex;
         177               0 :   mIsReadonly = false;
         178               0 :   mIsAnimValItem = aIsAnimValItem;
         179                 :
         180               0 :   NS_ABORT_IF_FALSE(IndexIsValid(), "Bad index for DOMSVGPoint!");
         181               0 : }
         182                 :
         183                 : void
         184               0 : DOMSVGPoint::RemovingFromList()
         185                 : {
         186               0 :   mPt = InternalItem();
         187               0 :   mList = nsnull;
         188               0 :   NS_ABORT_IF_FALSE(!mIsReadonly, "mIsReadonly set for list");
         189               0 :   mIsAnimValItem = false;
         190               0 : }
         191                 :
         192                 : SVGPoint&
         193               0 : DOMSVGPoint::InternalItem()
         194                 : {
         195               0 :   return mList->InternalList().mItems[mListIndex];
         196                 : }
         197                 :
         198                 : #ifdef DEBUG
         199                 : bool
         200               0 : DOMSVGPoint::IndexIsValid()
         201                 : {
         202               0 :   return mListIndex < mList->InternalList().Length();
         203            4188 : }
         204                 : #endif
         205                 :

Generated by: LCOV version 1.7