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