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