LCOV - code coverage report
Current view: directory - layout/xul/base/src/tree/src - nsTreeStyleCache.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 37 0 0.0 %
Date: 2012-06-02 Functions: 3 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) 2003
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Dave Hyatt <hyatt@mozilla.org> (Original Author)
      24                 :  *   Jan Varga <varga@ku.sk>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "nsTreeStyleCache.h"
      41                 : #include "nsISupportsArray.h"
      42                 : #include "nsStyleSet.h"
      43                 : #include "mozilla/dom/Element.h"
      44                 : 
      45                 : // The style context cache impl
      46                 : nsStyleContext*
      47               0 : nsTreeStyleCache::GetStyleContext(nsICSSPseudoComparator* aComparator,
      48                 :                                   nsPresContext* aPresContext,
      49                 :                                   nsIContent* aContent, 
      50                 :                                   nsStyleContext* aContext,
      51                 :                                   nsIAtom* aPseudoElement,
      52                 :                                   nsISupportsArray* aInputWord)
      53                 : {
      54                 :   PRUint32 count;
      55               0 :   aInputWord->Count(&count);
      56               0 :   nsDFAState startState(0);
      57               0 :   nsDFAState* currState = &startState;
      58                 : 
      59                 :   // Go ahead and init the transition table.
      60               0 :   if (!mTransitionTable) {
      61                 :     // Automatic miss. Build the table
      62                 :     mTransitionTable =
      63               0 :       new nsObjectHashtable(nsnull, nsnull, DeleteDFAState, nsnull);
      64                 :   }
      65                 : 
      66                 :   // The first transition is always made off the supplied pseudo-element.
      67               0 :   nsTransitionKey key(currState->GetStateID(), aPseudoElement);
      68               0 :   currState = static_cast<nsDFAState*>(mTransitionTable->Get(&key));
      69                 : 
      70               0 :   if (!currState) {
      71                 :     // We had a miss. Make a new state and add it to our hash.
      72               0 :     currState = new nsDFAState(mNextState);
      73               0 :     mNextState++;
      74               0 :     mTransitionTable->Put(&key, currState);
      75                 :   }
      76                 : 
      77               0 :   for (PRUint32 i = 0; i < count; i++) {
      78               0 :     nsCOMPtr<nsIAtom> pseudo = getter_AddRefs(static_cast<nsIAtom*>(aInputWord->ElementAt(i)));
      79               0 :     nsTransitionKey key(currState->GetStateID(), pseudo);
      80               0 :     currState = static_cast<nsDFAState*>(mTransitionTable->Get(&key));
      81                 : 
      82               0 :     if (!currState) {
      83                 :       // We had a miss. Make a new state and add it to our hash.
      84               0 :       currState = new nsDFAState(mNextState);
      85               0 :       mNextState++;
      86               0 :       mTransitionTable->Put(&key, currState);
      87                 :     }
      88                 :   }
      89                 : 
      90                 :   // We're in a final state.
      91                 :   // Look up our style context for this state.
      92               0 :   nsStyleContext* result = nsnull;
      93               0 :   if (mCache)
      94               0 :     result = static_cast<nsStyleContext*>(mCache->Get(currState));
      95               0 :   if (!result) {
      96                 :     // We missed the cache. Resolve this pseudo-style.
      97                 :     result = aPresContext->StyleSet()->
      98                 :       ResolveXULTreePseudoStyle(aContent->AsElement(), aPseudoElement,
      99               0 :                                 aContext, aComparator).get();
     100                 : 
     101                 :     // Put the style context in our table, transferring the owning reference to the table.
     102               0 :     if (!mCache) {
     103               0 :       mCache = new nsObjectHashtable(nsnull, nsnull, ReleaseStyleContext, nsnull);
     104                 :     }
     105               0 :     mCache->Put(currState, result);
     106                 :   }
     107                 : 
     108               0 :   return result;
     109                 : }
     110                 : 
     111                 : bool
     112               0 : nsTreeStyleCache::DeleteDFAState(nsHashKey *aKey,
     113                 :                                  void *aData,
     114                 :                                  void *closure)
     115                 : {
     116               0 :   nsDFAState* entry = static_cast<nsDFAState*>(aData);
     117               0 :   delete entry;
     118               0 :   return true;
     119                 : }
     120                 : 
     121                 : bool
     122               0 : nsTreeStyleCache::ReleaseStyleContext(nsHashKey *aKey,
     123                 :                                       void *aData,
     124                 :                                       void *closure)
     125                 : {
     126               0 :   nsStyleContext* context = static_cast<nsStyleContext*>(aData);
     127               0 :   context->Release();
     128               0 :   return true;
     129                 : }

Generated by: LCOV version 1.7