LCOV - code coverage report
Current view: directory - layout/base - nsLayoutHistoryState.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 30 0 0.0 %
Date: 2012-06-02 Functions: 12 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                 :  *   Pierre Phaneuf <pp@ludusdesign.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : /*
      40                 :  * container for information saved in session history when the document
      41                 :  * is not
      42                 :  */
      43                 : 
      44                 : #include "nsILayoutHistoryState.h"
      45                 : #include "nsWeakReference.h"
      46                 : #include "nsClassHashtable.h"
      47                 : #include "nsPresState.h"
      48                 : 
      49                 : class nsLayoutHistoryState : public nsILayoutHistoryState,
      50                 :                              public nsSupportsWeakReference
      51               0 : {
      52                 : public:
      53                 :   NS_HIDDEN_(nsresult) Init();
      54                 : 
      55                 :   NS_DECL_ISUPPORTS
      56                 : 
      57                 :   // nsILayoutHistoryState
      58                 :   NS_IMETHOD AddState(const nsCString& aKey, nsPresState* aState);
      59                 :   NS_IMETHOD GetState(const nsCString& aKey, nsPresState** aState);
      60                 :   NS_IMETHOD RemoveState(const nsCString& aKey);
      61                 :   NS_IMETHOD_(bool) HasStates() const;
      62                 :   NS_IMETHOD SetScrollPositionOnly(const bool aFlag);
      63                 : 
      64                 : 
      65                 : private:
      66               0 :   ~nsLayoutHistoryState() {}
      67                 :   bool mScrollPositionOnly;
      68                 : 
      69                 :   nsClassHashtable<nsCStringHashKey,nsPresState> mStates;
      70                 : };
      71                 : 
      72                 : 
      73                 : nsresult
      74               0 : NS_NewLayoutHistoryState(nsILayoutHistoryState** aState)
      75                 : {
      76                 :   nsLayoutHistoryState *state;
      77                 : 
      78               0 :   *aState = nsnull;
      79               0 :   state = new nsLayoutHistoryState();
      80                 : 
      81               0 :   NS_ADDREF(state);
      82               0 :   nsresult rv = state->Init();
      83               0 :   if (NS_SUCCEEDED(rv))
      84               0 :     *aState = state;
      85                 :   else
      86               0 :     NS_RELEASE(state);
      87                 : 
      88               0 :   return rv;
      89                 : }
      90                 : 
      91               0 : NS_IMPL_ISUPPORTS2(nsLayoutHistoryState,
      92                 :                    nsILayoutHistoryState,
      93                 :                    nsISupportsWeakReference)
      94                 : 
      95                 : nsresult
      96               0 : nsLayoutHistoryState::Init()
      97                 : {
      98               0 :   mScrollPositionOnly = false;
      99               0 :   return mStates.Init() ? NS_OK : NS_ERROR_FAILURE;
     100                 : }
     101                 : 
     102                 : NS_IMETHODIMP
     103               0 : nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState)
     104                 : {
     105               0 :   return mStates.Put(aStateKey, aState) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
     106                 : }
     107                 : 
     108                 : NS_IMETHODIMP
     109               0 : nsLayoutHistoryState::GetState(const nsCString& aKey, nsPresState** aState)
     110                 : {
     111               0 :   bool entryExists = mStates.Get(aKey, aState);
     112                 : 
     113               0 :   if (entryExists && mScrollPositionOnly) {
     114                 :     // Ensure any state that shouldn't be restored is removed
     115               0 :     (*aState)->ClearNonScrollState();
     116                 :   }
     117                 : 
     118               0 :   return NS_OK;
     119                 : }
     120                 : 
     121                 : NS_IMETHODIMP
     122               0 : nsLayoutHistoryState::RemoveState(const nsCString& aKey)
     123                 : {
     124               0 :   mStates.Remove(aKey);
     125               0 :   return NS_OK;
     126                 : }
     127                 : 
     128                 : NS_IMETHODIMP_(bool)
     129               0 : nsLayoutHistoryState::HasStates() const
     130                 : {
     131               0 :   return mStates.Count() != 0;
     132                 : }
     133                 : 
     134                 : NS_IMETHODIMP
     135               0 : nsLayoutHistoryState::SetScrollPositionOnly(const bool aFlag)
     136                 : {
     137               0 :   mScrollPositionOnly = aFlag;
     138               0 :   return NS_OK;
     139                 : }

Generated by: LCOV version 1.7