michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * container for information saved in session history when the document michael@0: * is not michael@0: */ michael@0: michael@0: #include "nsILayoutHistoryState.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsClassHashtable.h" michael@0: #include "nsPresState.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsLayoutHistoryState MOZ_FINAL : public nsILayoutHistoryState, michael@0: public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: nsLayoutHistoryState() michael@0: : mScrollPositionOnly(false) michael@0: { michael@0: } michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsILayoutHistoryState michael@0: virtual void michael@0: AddState(const nsCString& aKey, nsPresState* aState) MOZ_OVERRIDE; michael@0: virtual nsPresState* michael@0: GetState(const nsCString& aKey) MOZ_OVERRIDE; michael@0: virtual void michael@0: RemoveState(const nsCString& aKey) MOZ_OVERRIDE; michael@0: virtual bool michael@0: HasStates() const MOZ_OVERRIDE; michael@0: virtual void michael@0: SetScrollPositionOnly(const bool aFlag) MOZ_OVERRIDE; michael@0: michael@0: michael@0: private: michael@0: ~nsLayoutHistoryState() {} michael@0: bool mScrollPositionOnly; michael@0: michael@0: nsClassHashtable mStates; michael@0: }; michael@0: michael@0: michael@0: already_AddRefed michael@0: NS_NewLayoutHistoryState() michael@0: { michael@0: nsRefPtr state = new nsLayoutHistoryState(); michael@0: return state.forget(); michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS(nsLayoutHistoryState, michael@0: nsILayoutHistoryState, michael@0: nsISupportsWeakReference) michael@0: michael@0: void michael@0: nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState) michael@0: { michael@0: mStates.Put(aStateKey, aState); michael@0: } michael@0: michael@0: nsPresState* michael@0: nsLayoutHistoryState::GetState(const nsCString& aKey) michael@0: { michael@0: nsPresState* state = nullptr; michael@0: bool entryExists = mStates.Get(aKey, &state); michael@0: michael@0: if (entryExists && mScrollPositionOnly) { michael@0: // Ensure any state that shouldn't be restored is removed michael@0: state->ClearNonScrollState(); michael@0: } michael@0: michael@0: return state; michael@0: } michael@0: michael@0: void michael@0: nsLayoutHistoryState::RemoveState(const nsCString& aKey) michael@0: { michael@0: mStates.Remove(aKey); michael@0: } michael@0: michael@0: bool michael@0: nsLayoutHistoryState::HasStates() const michael@0: { michael@0: return mStates.Count() != 0; michael@0: } michael@0: michael@0: void michael@0: nsLayoutHistoryState::SetScrollPositionOnly(const bool aFlag) michael@0: { michael@0: mScrollPositionOnly = aFlag; michael@0: }