|
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/. */ |
|
5 |
|
6 /* |
|
7 * container for information saved in session history when the document |
|
8 * is not |
|
9 */ |
|
10 |
|
11 #include "nsILayoutHistoryState.h" |
|
12 #include "nsWeakReference.h" |
|
13 #include "nsClassHashtable.h" |
|
14 #include "nsPresState.h" |
|
15 #include "mozilla/Attributes.h" |
|
16 |
|
17 class nsLayoutHistoryState MOZ_FINAL : public nsILayoutHistoryState, |
|
18 public nsSupportsWeakReference |
|
19 { |
|
20 public: |
|
21 nsLayoutHistoryState() |
|
22 : mScrollPositionOnly(false) |
|
23 { |
|
24 } |
|
25 |
|
26 NS_DECL_ISUPPORTS |
|
27 |
|
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; |
|
39 |
|
40 |
|
41 private: |
|
42 ~nsLayoutHistoryState() {} |
|
43 bool mScrollPositionOnly; |
|
44 |
|
45 nsClassHashtable<nsCStringHashKey,nsPresState> mStates; |
|
46 }; |
|
47 |
|
48 |
|
49 already_AddRefed<nsILayoutHistoryState> |
|
50 NS_NewLayoutHistoryState() |
|
51 { |
|
52 nsRefPtr<nsLayoutHistoryState> state = new nsLayoutHistoryState(); |
|
53 return state.forget(); |
|
54 } |
|
55 |
|
56 NS_IMPL_ISUPPORTS(nsLayoutHistoryState, |
|
57 nsILayoutHistoryState, |
|
58 nsISupportsWeakReference) |
|
59 |
|
60 void |
|
61 nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState) |
|
62 { |
|
63 mStates.Put(aStateKey, aState); |
|
64 } |
|
65 |
|
66 nsPresState* |
|
67 nsLayoutHistoryState::GetState(const nsCString& aKey) |
|
68 { |
|
69 nsPresState* state = nullptr; |
|
70 bool entryExists = mStates.Get(aKey, &state); |
|
71 |
|
72 if (entryExists && mScrollPositionOnly) { |
|
73 // Ensure any state that shouldn't be restored is removed |
|
74 state->ClearNonScrollState(); |
|
75 } |
|
76 |
|
77 return state; |
|
78 } |
|
79 |
|
80 void |
|
81 nsLayoutHistoryState::RemoveState(const nsCString& aKey) |
|
82 { |
|
83 mStates.Remove(aKey); |
|
84 } |
|
85 |
|
86 bool |
|
87 nsLayoutHistoryState::HasStates() const |
|
88 { |
|
89 return mStates.Count() != 0; |
|
90 } |
|
91 |
|
92 void |
|
93 nsLayoutHistoryState::SetScrollPositionOnly(const bool aFlag) |
|
94 { |
|
95 mScrollPositionOnly = aFlag; |
|
96 } |