2005-01-27 22:52:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
1999-08-30 22:38:58 +00:00
|
|
|
|
2006-03-30 05:56:38 +00:00
|
|
|
/*
|
|
|
|
* container for information saved in session history when the document
|
|
|
|
* is not
|
|
|
|
*/
|
|
|
|
|
2006-03-30 06:16:27 +00:00
|
|
|
#include "nsILayoutHistoryState.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsPresState.h"
|
2012-06-19 03:26:34 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2006-03-30 06:16:27 +00:00
|
|
|
|
2012-06-19 03:26:34 +00:00
|
|
|
class nsLayoutHistoryState MOZ_FINAL : public nsILayoutHistoryState,
|
|
|
|
public nsSupportsWeakReference
|
1999-08-30 22:38:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-07-24 07:38:13 +00:00
|
|
|
nsLayoutHistoryState()
|
|
|
|
: mScrollPositionOnly(false)
|
|
|
|
{
|
|
|
|
}
|
1999-08-30 22:38:58 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsILayoutHistoryState
|
2013-07-24 07:38:13 +00: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;
|
2000-01-14 09:28:54 +00:00
|
|
|
|
1999-08-30 22:38:58 +00:00
|
|
|
|
|
|
|
private:
|
2005-01-27 22:52:53 +00:00
|
|
|
~nsLayoutHistoryState() {}
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mScrollPositionOnly;
|
2005-01-27 22:52:53 +00:00
|
|
|
|
|
|
|
nsClassHashtable<nsCStringHashKey,nsPresState> mStates;
|
1999-08-30 22:38:58 +00:00
|
|
|
};
|
|
|
|
|
1999-09-03 22:10:57 +00:00
|
|
|
|
2013-07-24 07:38:13 +00:00
|
|
|
already_AddRefed<nsILayoutHistoryState>
|
|
|
|
NS_NewLayoutHistoryState()
|
1999-08-30 22:38:58 +00:00
|
|
|
{
|
2013-07-24 07:38:13 +00:00
|
|
|
nsRefPtr<nsLayoutHistoryState> state = new nsLayoutHistoryState();
|
|
|
|
return state.forget();
|
1999-08-30 22:38:58 +00:00
|
|
|
}
|
|
|
|
|
2001-05-12 15:52:06 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsLayoutHistoryState,
|
|
|
|
nsILayoutHistoryState,
|
2003-09-07 22:37:27 +00:00
|
|
|
nsISupportsWeakReference)
|
1999-08-30 22:38:58 +00:00
|
|
|
|
2013-07-24 07:38:13 +00:00
|
|
|
void
|
2005-01-27 22:52:53 +00:00
|
|
|
nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState)
|
|
|
|
{
|
2012-05-18 17:30:49 +00:00
|
|
|
mStates.Put(aStateKey, aState);
|
1999-08-30 22:38:58 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 07:38:13 +00:00
|
|
|
nsPresState*
|
|
|
|
nsLayoutHistoryState::GetState(const nsCString& aKey)
|
1999-08-30 22:38:58 +00:00
|
|
|
{
|
2013-07-24 07:38:13 +00:00
|
|
|
nsPresState* state = nullptr;
|
|
|
|
bool entryExists = mStates.Get(aKey, &state);
|
2008-12-03 17:55:14 +00:00
|
|
|
|
|
|
|
if (entryExists && mScrollPositionOnly) {
|
|
|
|
// Ensure any state that shouldn't be restored is removed
|
2013-07-24 07:38:13 +00:00
|
|
|
state->ClearNonScrollState();
|
2008-12-03 17:55:14 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 07:38:13 +00:00
|
|
|
return state;
|
1999-08-30 22:38:58 +00:00
|
|
|
}
|
2000-01-14 09:28:54 +00:00
|
|
|
|
2013-07-24 07:38:13 +00:00
|
|
|
void
|
2001-05-30 11:26:21 +00:00
|
|
|
nsLayoutHistoryState::RemoveState(const nsCString& aKey)
|
2000-01-14 09:28:54 +00:00
|
|
|
{
|
2005-01-27 22:52:53 +00:00
|
|
|
mStates.Remove(aKey);
|
2000-01-14 09:28:54 +00:00
|
|
|
}
|
2007-07-21 03:00:02 +00:00
|
|
|
|
2013-07-24 07:38:13 +00:00
|
|
|
bool
|
2007-07-21 03:00:02 +00:00
|
|
|
nsLayoutHistoryState::HasStates() const
|
|
|
|
{
|
|
|
|
return mStates.Count() != 0;
|
|
|
|
}
|
2008-12-03 17:55:14 +00:00
|
|
|
|
2013-07-24 07:38:13 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsLayoutHistoryState::SetScrollPositionOnly(const bool aFlag)
|
2008-12-03 17:55:14 +00:00
|
|
|
{
|
|
|
|
mScrollPositionOnly = aFlag;
|
|
|
|
}
|