layout/base/nsLayoutHistoryState.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  * container for information saved in session history when the document
     8  * is not
     9  */
    11 #include "nsILayoutHistoryState.h"
    12 #include "nsWeakReference.h"
    13 #include "nsClassHashtable.h"
    14 #include "nsPresState.h"
    15 #include "mozilla/Attributes.h"
    17 class nsLayoutHistoryState MOZ_FINAL : public nsILayoutHistoryState,
    18                                        public nsSupportsWeakReference
    19 {
    20 public:
    21   nsLayoutHistoryState()
    22     : mScrollPositionOnly(false)
    23   {
    24   }
    26   NS_DECL_ISUPPORTS
    28   // nsILayoutHistoryState
    29   virtual void
    30   AddState(const nsCString& aKey, nsPresState* aState) MOZ_OVERRIDE;
    31   virtual nsPresState*
    32   GetState(const nsCString& aKey) MOZ_OVERRIDE;
    33   virtual void
    34   RemoveState(const nsCString& aKey) MOZ_OVERRIDE;
    35   virtual bool
    36   HasStates() const MOZ_OVERRIDE;
    37   virtual void
    38   SetScrollPositionOnly(const bool aFlag) MOZ_OVERRIDE;
    41 private:
    42   ~nsLayoutHistoryState() {}
    43   bool mScrollPositionOnly;
    45   nsClassHashtable<nsCStringHashKey,nsPresState> mStates;
    46 };
    49 already_AddRefed<nsILayoutHistoryState>
    50 NS_NewLayoutHistoryState()
    51 {
    52   nsRefPtr<nsLayoutHistoryState> state = new nsLayoutHistoryState();
    53   return state.forget();
    54 }
    56 NS_IMPL_ISUPPORTS(nsLayoutHistoryState,
    57                   nsILayoutHistoryState,
    58                   nsISupportsWeakReference)
    60 void
    61 nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState)
    62 {
    63   mStates.Put(aStateKey, aState);
    64 }
    66 nsPresState*
    67 nsLayoutHistoryState::GetState(const nsCString& aKey)
    68 {
    69   nsPresState* state = nullptr;
    70   bool entryExists = mStates.Get(aKey, &state);
    72   if (entryExists && mScrollPositionOnly) {
    73     // Ensure any state that shouldn't be restored is removed
    74     state->ClearNonScrollState();
    75   }
    77   return state;
    78 }
    80 void
    81 nsLayoutHistoryState::RemoveState(const nsCString& aKey)
    82 {
    83   mStates.Remove(aKey);
    84 }
    86 bool
    87 nsLayoutHistoryState::HasStates() const
    88 {
    89   return mStates.Count() != 0;
    90 }
    92 void
    93 nsLayoutHistoryState::SetScrollPositionOnly(const bool aFlag)
    94 {
    95   mScrollPositionOnly = aFlag;
    96 }

mercurial