Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 }