LCOV - code coverage report
Current view: directory - layout/base - nsStyleChangeList.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 65 0 0.0 %
Date: 2012-06-02 Functions: 6 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 mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : /*
      39                 :  * a list of the recomputation that needs to be done in response to a
      40                 :  * style change
      41                 :  */
      42                 : 
      43                 : #include "nsStyleChangeList.h"
      44                 : #include "nsStyleConsts.h"
      45                 : #include "nsIFrame.h"
      46                 : #include "nsIContent.h"
      47                 : #include "nsCRT.h"
      48                 : 
      49                 : static const PRUint32 kGrowArrayBy = 10;
      50                 : 
      51               0 : nsStyleChangeList::nsStyleChangeList()
      52                 :   : mArray(mBuffer),
      53                 :     mArraySize(kStyleChangeBufferSize),
      54               0 :     mCount(0)
      55                 : {
      56               0 :   MOZ_COUNT_CTOR(nsStyleChangeList);
      57               0 : }
      58                 : 
      59               0 : nsStyleChangeList::~nsStyleChangeList()
      60                 : {
      61               0 :   MOZ_COUNT_DTOR(nsStyleChangeList);
      62               0 :   Clear();
      63               0 : }
      64                 : 
      65                 : nsresult 
      66               0 : nsStyleChangeList::ChangeAt(PRInt32 aIndex, nsIFrame*& aFrame, nsIContent*& aContent, 
      67                 :                             nsChangeHint& aHint) const
      68                 : {
      69               0 :   if ((0 <= aIndex) && (aIndex < mCount)) {
      70               0 :     aFrame = mArray[aIndex].mFrame;
      71               0 :     aContent = mArray[aIndex].mContent;
      72               0 :     aHint = mArray[aIndex].mHint;
      73               0 :     return NS_OK;
      74                 :   }
      75               0 :   return NS_ERROR_ILLEGAL_VALUE;
      76                 : }
      77                 : 
      78                 : nsresult 
      79               0 : nsStyleChangeList::ChangeAt(PRInt32 aIndex, const nsStyleChangeData** aChangeData) const
      80                 : {
      81               0 :   if ((0 <= aIndex) && (aIndex < mCount)) {
      82               0 :     *aChangeData = &mArray[aIndex];
      83               0 :     return NS_OK;
      84                 :   }
      85               0 :   return NS_ERROR_ILLEGAL_VALUE;
      86                 : }
      87                 : 
      88                 : nsresult 
      89               0 : nsStyleChangeList::AppendChange(nsIFrame* aFrame, nsIContent* aContent, nsChangeHint aHint)
      90                 : {
      91               0 :   NS_ASSERTION(aFrame || (aHint & nsChangeHint_ReconstructFrame),
      92                 :                "must have frame");
      93               0 :   NS_ASSERTION(aContent || !(aHint & nsChangeHint_ReconstructFrame),
      94                 :                "must have content");
      95                 :   // XXXbz we should make this take Element instead of nsIContent
      96               0 :   NS_ASSERTION(!aContent || aContent->IsElement(),
      97                 :                "Shouldn't be trying to restyle non-elements directly");
      98               0 :   NS_ASSERTION(!(aHint & nsChangeHint_ReflowFrame) ||
      99                 :                (aHint & nsChangeHint_NeedReflow),
     100                 :                "Reflow hint bits set without actually asking for a reflow");
     101                 : 
     102               0 :   if ((0 < mCount) && (aHint & nsChangeHint_ReconstructFrame)) { // filter out all other changes for same content
     103               0 :     if (aContent) {
     104               0 :       for (PRInt32 index = mCount - 1; index >= 0; --index) {
     105               0 :         if (aContent == mArray[index].mContent) { // remove this change
     106               0 :           aContent->Release();
     107               0 :           mCount--;
     108               0 :           if (index < mCount) { // move later changes down
     109               0 :             ::memmove(&mArray[index], &mArray[index + 1], 
     110               0 :                       (mCount - index) * sizeof(nsStyleChangeData));
     111                 :           }
     112                 :         }
     113                 :       }
     114                 :     }
     115                 :   }
     116                 : 
     117               0 :   PRInt32 last = mCount - 1;
     118               0 :   if ((0 < mCount) && aFrame && (aFrame == mArray[last].mFrame)) { // same as last frame
     119               0 :     NS_UpdateHint(mArray[last].mHint, aHint);
     120                 :   }
     121                 :   else {
     122               0 :     if (mCount == mArraySize) {
     123               0 :       PRInt32 newSize = mArraySize + kGrowArrayBy;
     124               0 :       nsStyleChangeData* newArray = new nsStyleChangeData[newSize];
     125               0 :       if (newArray) {
     126               0 :         memcpy(newArray, mArray, mCount * sizeof(nsStyleChangeData));
     127               0 :         if (mArray != mBuffer) {
     128               0 :           delete [] mArray;
     129                 :         }
     130               0 :         mArray = newArray;
     131               0 :         mArraySize = newSize;
     132                 :       }
     133                 :       else {
     134               0 :         return NS_ERROR_OUT_OF_MEMORY;
     135                 :       }
     136                 :     }
     137               0 :     mArray[mCount].mFrame = aFrame;
     138               0 :     mArray[mCount].mContent = aContent;
     139               0 :     if (aContent) {
     140               0 :       aContent->AddRef();
     141                 :     }
     142               0 :     mArray[mCount].mHint = aHint;
     143               0 :     mCount++;
     144                 :   }
     145               0 :   return NS_OK;
     146                 : }
     147                 : 
     148                 : void
     149               0 : nsStyleChangeList::Clear()
     150                 : {
     151               0 :   for (PRInt32 index = mCount - 1; index >= 0; --index) {
     152               0 :     nsIContent* content = mArray[index].mContent;
     153               0 :     if (content) {
     154               0 :       content->Release();
     155                 :     }
     156                 :   }
     157               0 :   if (mArray != mBuffer) {
     158               0 :     delete [] mArray;
     159               0 :     mArray = mBuffer;
     160               0 :     mArraySize = kStyleChangeBufferSize;
     161                 :   }
     162               0 :   mCount = 0;
     163               0 : }
     164                 : 

Generated by: LCOV version 1.7