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
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsLayoutHistoryState final : public nsILayoutHistoryState,
|
2015-03-27 18:52:19 +00:00
|
|
|
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
|
2015-03-21 16:28:04 +00:00
|
|
|
AddState(const nsCString& aKey, nsPresState* aState) override;
|
2013-07-24 07:38:13 +00:00
|
|
|
virtual nsPresState*
|
2015-03-21 16:28:04 +00:00
|
|
|
GetState(const nsCString& aKey) override;
|
2013-07-24 07:38:13 +00:00
|
|
|
virtual void
|
2015-03-21 16:28:04 +00:00
|
|
|
RemoveState(const nsCString& aKey) override;
|
2013-07-24 07:38:13 +00:00
|
|
|
virtual bool
|
2015-03-21 16:28:04 +00:00
|
|
|
HasStates() const override;
|
2013-07-24 07:38:13 +00:00
|
|
|
virtual void
|
2015-03-21 16:28:04 +00:00
|
|
|
SetScrollPositionOnly(const bool aFlag) override;
|
2015-12-26 10:59:09 +00:00
|
|
|
virtual void
|
|
|
|
ResetScrollState() override;
|
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
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsLayoutHistoryState> state = new nsLayoutHistoryState();
|
2013-07-24 07:38:13 +00:00
|
|
|
return state.forget();
|
1999-08-30 22:38:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsLayoutHistoryState,
|
|
|
|
nsILayoutHistoryState,
|
|
|
|
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;
|
|
|
|
}
|
2015-12-26 10:59:09 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutHistoryState::ResetScrollState()
|
|
|
|
{
|
|
|
|
for (auto iter = mStates.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsPresState* state = iter.UserData();
|
|
|
|
if (state) {
|
|
|
|
state->SetScrollState(nsPoint(0, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|