2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* container for information saved in session history when the document
|
|
|
|
* is not
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsILayoutHistoryState.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsPresState.h"
|
2012-06-18 20:26:34 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-18 20:26:34 -07:00
|
|
|
class nsLayoutHistoryState MOZ_FINAL : public nsILayoutHistoryState,
|
|
|
|
public nsSupportsWeakReference
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-07-24 00:38:13 -07:00
|
|
|
nsLayoutHistoryState()
|
|
|
|
: mScrollPositionOnly(false)
|
|
|
|
{
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsILayoutHistoryState
|
2013-07-24 00:38:13 -07:00
|
|
|
virtual void
|
|
|
|
AddState(const nsCString& aKey, nsPresState* aState) MOZ_OVERRIDE;
|
|
|
|
virtual nsPresState*
|
|
|
|
GetState(const nsCString& aKey) MOZ_OVERRIDE;
|
|
|
|
virtual void
|
|
|
|
RemoveState(const nsCString& aKey) MOZ_OVERRIDE;
|
|
|
|
virtual bool
|
|
|
|
HasStates() const MOZ_OVERRIDE;
|
|
|
|
virtual void
|
|
|
|
SetScrollPositionOnly(const bool aFlag) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsLayoutHistoryState() {}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mScrollPositionOnly;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsClassHashtable<nsCStringHashKey,nsPresState> mStates;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-07-24 00:38:13 -07:00
|
|
|
already_AddRefed<nsILayoutHistoryState>
|
|
|
|
NS_NewLayoutHistoryState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-24 00:38:13 -07:00
|
|
|
nsRefPtr<nsLayoutHistoryState> state = new nsLayoutHistoryState();
|
|
|
|
return state.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(nsLayoutHistoryState,
|
|
|
|
nsILayoutHistoryState,
|
|
|
|
nsISupportsWeakReference)
|
|
|
|
|
2013-07-24 00:38:13 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState)
|
|
|
|
{
|
2012-05-18 10:30:49 -07:00
|
|
|
mStates.Put(aStateKey, aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-24 00:38:13 -07:00
|
|
|
nsPresState*
|
|
|
|
nsLayoutHistoryState::GetState(const nsCString& aKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-24 00:38:13 -07:00
|
|
|
nsPresState* state = nullptr;
|
|
|
|
bool entryExists = mStates.Get(aKey, &state);
|
2008-12-03 09:55:14 -08:00
|
|
|
|
|
|
|
if (entryExists && mScrollPositionOnly) {
|
|
|
|
// Ensure any state that shouldn't be restored is removed
|
2013-07-24 00:38:13 -07:00
|
|
|
state->ClearNonScrollState();
|
2008-12-03 09:55:14 -08:00
|
|
|
}
|
|
|
|
|
2013-07-24 00:38:13 -07:00
|
|
|
return state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-24 00:38:13 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLayoutHistoryState::RemoveState(const nsCString& aKey)
|
|
|
|
{
|
|
|
|
mStates.Remove(aKey);
|
|
|
|
}
|
2007-07-20 20:00:02 -07:00
|
|
|
|
2013-07-24 00:38:13 -07:00
|
|
|
bool
|
2007-07-20 20:00:02 -07:00
|
|
|
nsLayoutHistoryState::HasStates() const
|
|
|
|
{
|
|
|
|
return mStates.Count() != 0;
|
|
|
|
}
|
2008-12-03 09:55:14 -08:00
|
|
|
|
2013-07-24 00:38:13 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsLayoutHistoryState::SetScrollPositionOnly(const bool aFlag)
|
2008-12-03 09:55:14 -08:00
|
|
|
{
|
|
|
|
mScrollPositionOnly = aFlag;
|
|
|
|
}
|