Added get/set document state API for use by session history.

This commit is contained in:
nisheeth%netscape.com 1999-08-30 22:38:58 +00:00
parent 4a79834ac3
commit a208673213
15 changed files with 427 additions and 2 deletions

View File

@ -0,0 +1,25 @@
#ifndef _nsILayoutHistoryState_h
#define _nsILayoutHistoryState_h
#include "nsISupports.h"
#define NS_ILAYOUTHISTORYSTATE_IID_STR "306c8ca0-5f0c-11d3-a9fb-000064657374"
#define NS_ILAYOUTHISTORYSTATE_IID \
{0x306c8ca0, 0x5f0c, 0x11d3, \
{0xa9, 0xfb, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
#define NS_HISTORY_STATE_TYPE_NONE -1
class nsILayoutHistoryState : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILAYOUTHISTORYSTATE_IID)
NS_IMETHOD AddState(PRUint32 aContentID, nsISupports* aState, PRInt32 aStateType) = 0;
NS_IMETHOD GetState(PRUint32 aContentID, nsISupports** aState, PRInt32 aStateType) = 0;
};
nsresult
NS_NewLayoutHistoryState(nsILayoutHistoryState** aState);
#endif /* _nsILayoutHistoryState_h */

View File

@ -40,6 +40,7 @@ class nsICaret;
class nsIStyleContext;
class nsIFrameSelection;
class nsIFrameManager;
class nsILayoutHistoryState;
#define NS_IPRESSHELL_IID \
{ 0x76e79c60, 0x944e, 0x11d1, \
@ -336,6 +337,18 @@ public:
// XXX events
// XXX selection
/**
* Get the history state for the current document
*/
NS_IMETHOD GetHistoryState(nsILayoutHistoryState** aLayoutHistoryState) = 0;
/**
* Capture frame state for the frame subtree rooted at aFrame.
* aState is the document state storage object onto which each frame
* stores its state.
*/
NS_IMETHOD CaptureFrameState(nsIFrame* aFrame, nsILayoutHistoryState* aState) = 0;
/**
* See if reflow verification is enabled. To enable reflow verification add
@ -349,6 +362,7 @@ public:
* Set the verify-reflow enable flag.
*/
static NS_LAYOUT void SetVerifyReflowEnable(PRBool aEnabled);
};
/**

View File

@ -0,0 +1,87 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsILayoutHistoryState.h"
#include "nsHashtable.h"
class nsLayoutHistoryState : public nsILayoutHistoryState
{
public:
nsLayoutHistoryState();
virtual ~nsLayoutHistoryState();
NS_DECL_ISUPPORTS
// nsILayoutHistoryState
NS_IMETHOD AddState(PRUint32 aContentID,
nsISupports* aState,
PRInt32 aStateType = NS_HISTORY_STATE_TYPE_NONE);
NS_IMETHOD GetState(PRUint32 aContentID,
nsISupports** aState,
PRInt32 aStateType = NS_HISTORY_STATE_TYPE_NONE);
private:
nsSupportsHashtable mStates;
};
nsresult
NS_NewLayoutHistoryState(nsILayoutHistoryState** aState)
{
NS_PRECONDITION(aState != nsnull, "null ptr");
if (! aState)
return NS_ERROR_NULL_POINTER;
*aState = new nsLayoutHistoryState();
if (! *aState)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aState);
return NS_OK;
}
nsLayoutHistoryState::nsLayoutHistoryState()
{
NS_INIT_REFCNT();
}
nsLayoutHistoryState::~nsLayoutHistoryState()
{
}
NS_IMPL_ISUPPORTS(nsLayoutHistoryState,
nsILayoutHistoryState::GetIID());
NS_IMETHODIMP
nsLayoutHistoryState::AddState(PRUint32 aContentID,
nsISupports* aState,
PRInt32 aStateType)
{
return NS_OK;
}
NS_IMETHODIMP
nsLayoutHistoryState::GetState(PRUint32 aContentID,
nsISupports** aState,
PRInt32 aStateType)
{
return NS_OK;
}

View File

@ -62,6 +62,8 @@
#include "nsViewsCID.h"
#include "nsIFrameManager.h"
#include "nsISupportsPrimitives.h"
#include "nsILayoutHistoryState.h"
#include "nsIStatefulFrame.h"
// Drag & Drop, Clipboard
#include "nsWidgetsCID.h"
@ -174,7 +176,9 @@ public:
NS_IMETHOD GetFrameManager(nsIFrameManager** aFrameManager) const;
NS_IMETHOD DoCopy();
NS_IMETHOD GetHistoryState(nsILayoutHistoryState** aLayoutHistoryState);
NS_IMETHOD CaptureFrameState(nsIFrame* aFrame, nsILayoutHistoryState* aState);
//nsIViewObserver interface
NS_IMETHOD Paint(nsIView *aView,
@ -1550,6 +1554,64 @@ PresShell::DoCopy()
return NS_OK;
}
NS_IMETHODIMP
PresShell::GetHistoryState(nsILayoutHistoryState** aState)
{
nsresult rv = NS_OK;
NS_PRECONDITION(nsnull != aState, "null state pointer");
// Create the document state object
rv = NS_NewLayoutHistoryState(aState);
if (NS_FAILED(rv)) {
*aState = nsnull;
return rv;
}
// Capture frame state for the entire frame hierarchy
nsIFrame* rootFrame = nsnull;
rv = GetRootFrame(&rootFrame);
if (NS_FAILED(rv) || nsnull == rootFrame) return rv;
rv = CaptureFrameState(rootFrame, *aState);
return rv;
}
NS_IMETHODIMP
PresShell::CaptureFrameState(nsIFrame* aFrame, nsILayoutHistoryState* aState)
{
nsresult rv = NS_OK;
NS_PRECONDITION(nsnull != aFrame && nsnull != aState, "null parameters passed in");
// See if the frame is stateful.
nsCOMPtr<nsIStatefulFrame> statefulFrame = do_QueryInterface(aFrame);
if (nsnull != statefulFrame) {
// If so, ask the frame to save its state
rv = statefulFrame->SaveState(aState);
}
// XXX We are only going through the principal child list right now.
// Need to talk to Troy to find out about other kinds of
// child lists and whether they will contain stateful frames.
// Capture frame state for the first child
nsIFrame* child = nsnull;
rv = aFrame->FirstChild(nsnull, &child);
if (NS_SUCCEEDED(rv) && nsnull != child) {
rv = CaptureFrameState(child, aState);
}
// Capture frame state for the next sibling
nsIFrame* sibling = nsnull;
rv = aFrame->GetNextSibling(&sibling);
if (NS_SUCCEEDED(rv) && nsnull != sibling) {
rv = CaptureFrameState(sibling, aState);
}
return rv;
}
NS_IMETHODIMP
PresShell::ContentChanged(nsIDocument *aDocument,

View File

@ -43,3 +43,5 @@ nsIStyleSheetLinkingElement.h
nsITextContent.h
nsTextFragment.h
nsIAnonymousContent.h
nsILayoutHistoryState.h
nsIStatefulFrame.h

View File

@ -67,6 +67,8 @@ EXPORTS = \
nsStyleCoord.h \
nsStyleStruct.h \
nsTextFragment.h \
nsILayoutHistoryState.h \
nsIStatefulFrame.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

View File

@ -60,6 +60,8 @@ EXPORTS = \
nsStyleCoord.h \
nsStyleStruct.h \
nsTextFragment.h \
nsILayoutHistoryState.h \
nsIStatefulFrame.h \
$(NULL)
MODULE=raptor

View File

@ -0,0 +1,25 @@
#ifndef _nsILayoutHistoryState_h
#define _nsILayoutHistoryState_h
#include "nsISupports.h"
#define NS_ILAYOUTHISTORYSTATE_IID_STR "306c8ca0-5f0c-11d3-a9fb-000064657374"
#define NS_ILAYOUTHISTORYSTATE_IID \
{0x306c8ca0, 0x5f0c, 0x11d3, \
{0xa9, 0xfb, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
#define NS_HISTORY_STATE_TYPE_NONE -1
class nsILayoutHistoryState : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILAYOUTHISTORYSTATE_IID)
NS_IMETHOD AddState(PRUint32 aContentID, nsISupports* aState, PRInt32 aStateType) = 0;
NS_IMETHOD GetState(PRUint32 aContentID, nsISupports** aState, PRInt32 aStateType) = 0;
};
nsresult
NS_NewLayoutHistoryState(nsILayoutHistoryState** aState);
#endif /* _nsILayoutHistoryState_h */

View File

@ -40,6 +40,7 @@ class nsICaret;
class nsIStyleContext;
class nsIFrameSelection;
class nsIFrameManager;
class nsILayoutHistoryState;
#define NS_IPRESSHELL_IID \
{ 0x76e79c60, 0x944e, 0x11d1, \
@ -336,6 +337,18 @@ public:
// XXX events
// XXX selection
/**
* Get the history state for the current document
*/
NS_IMETHOD GetHistoryState(nsILayoutHistoryState** aLayoutHistoryState) = 0;
/**
* Capture frame state for the frame subtree rooted at aFrame.
* aState is the document state storage object onto which each frame
* stores its state.
*/
NS_IMETHOD CaptureFrameState(nsIFrame* aFrame, nsILayoutHistoryState* aState) = 0;
/**
* See if reflow verification is enabled. To enable reflow verification add
@ -349,6 +362,7 @@ public:
* Set the verify-reflow enable flag.
*/
static NS_LAYOUT void SetVerifyReflowEnable(PRBool aEnabled);
};
/**

View File

@ -0,0 +1,20 @@
#ifndef _nsIStatefulFrame_h
#define _nsIStatefulFrame_h
#include "nsISupports.h"
#define NS_ISTATEFULFRAME_IID_STR "306c8ca0-5f0c-11d3-a9fb-000064657374"
#define NS_ISTATEFULFRAME_IID \
{0x306c8ca0, 0x5f0c, 0x11d3, \
{0xa9, 0xfb, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
class nsIStatefulFrame : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTATEFULFRAME_IID)
NS_IMETHOD SaveState(nsILayoutHistoryState* aState);
NS_IMETHOD RestoreState(nsILayoutHistoryState* aState);
};
#endif /* _nsIStatefulFrame_h */

View File

@ -63,6 +63,7 @@ CPPSRCS = \
nsTextFragment.cpp \
nsTextNode.cpp \
nsXIFConverter.cpp \
nsLayoutHistoryState.cpp \
$(NULL)
EXPORTS = \

View File

@ -59,6 +59,7 @@ CPPSRCS = \
nsCaret.cpp \
nsRange.cpp \
nsTextNode.cpp \
nsLayoutHistoryState.cpp \
$(NULL)
MODULE=raptor
@ -101,6 +102,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsCaret.obj \
.\$(OBJDIR)\nsRange.obj \
.\$(OBJDIR)\nsTextNode.obj \
.\$(OBJDIR)\nsLayoutHistoryState.obj \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \

View File

@ -0,0 +1,87 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsILayoutHistoryState.h"
#include "nsHashtable.h"
class nsLayoutHistoryState : public nsILayoutHistoryState
{
public:
nsLayoutHistoryState();
virtual ~nsLayoutHistoryState();
NS_DECL_ISUPPORTS
// nsILayoutHistoryState
NS_IMETHOD AddState(PRUint32 aContentID,
nsISupports* aState,
PRInt32 aStateType = NS_HISTORY_STATE_TYPE_NONE);
NS_IMETHOD GetState(PRUint32 aContentID,
nsISupports** aState,
PRInt32 aStateType = NS_HISTORY_STATE_TYPE_NONE);
private:
nsSupportsHashtable mStates;
};
nsresult
NS_NewLayoutHistoryState(nsILayoutHistoryState** aState)
{
NS_PRECONDITION(aState != nsnull, "null ptr");
if (! aState)
return NS_ERROR_NULL_POINTER;
*aState = new nsLayoutHistoryState();
if (! *aState)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aState);
return NS_OK;
}
nsLayoutHistoryState::nsLayoutHistoryState()
{
NS_INIT_REFCNT();
}
nsLayoutHistoryState::~nsLayoutHistoryState()
{
}
NS_IMPL_ISUPPORTS(nsLayoutHistoryState,
nsILayoutHistoryState::GetIID());
NS_IMETHODIMP
nsLayoutHistoryState::AddState(PRUint32 aContentID,
nsISupports* aState,
PRInt32 aStateType)
{
return NS_OK;
}
NS_IMETHODIMP
nsLayoutHistoryState::GetState(PRUint32 aContentID,
nsISupports** aState,
PRInt32 aStateType)
{
return NS_OK;
}

View File

@ -0,0 +1,20 @@
#ifndef _nsIStatefulFrame_h
#define _nsIStatefulFrame_h
#include "nsISupports.h"
#define NS_ISTATEFULFRAME_IID_STR "306c8ca0-5f0c-11d3-a9fb-000064657374"
#define NS_ISTATEFULFRAME_IID \
{0x306c8ca0, 0x5f0c, 0x11d3, \
{0xa9, 0xfb, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
class nsIStatefulFrame : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTATEFULFRAME_IID)
NS_IMETHOD SaveState(nsILayoutHistoryState* aState);
NS_IMETHOD RestoreState(nsILayoutHistoryState* aState);
};
#endif /* _nsIStatefulFrame_h */

View File

@ -62,6 +62,8 @@
#include "nsViewsCID.h"
#include "nsIFrameManager.h"
#include "nsISupportsPrimitives.h"
#include "nsILayoutHistoryState.h"
#include "nsIStatefulFrame.h"
// Drag & Drop, Clipboard
#include "nsWidgetsCID.h"
@ -174,7 +176,9 @@ public:
NS_IMETHOD GetFrameManager(nsIFrameManager** aFrameManager) const;
NS_IMETHOD DoCopy();
NS_IMETHOD GetHistoryState(nsILayoutHistoryState** aLayoutHistoryState);
NS_IMETHOD CaptureFrameState(nsIFrame* aFrame, nsILayoutHistoryState* aState);
//nsIViewObserver interface
NS_IMETHOD Paint(nsIView *aView,
@ -1550,6 +1554,64 @@ PresShell::DoCopy()
return NS_OK;
}
NS_IMETHODIMP
PresShell::GetHistoryState(nsILayoutHistoryState** aState)
{
nsresult rv = NS_OK;
NS_PRECONDITION(nsnull != aState, "null state pointer");
// Create the document state object
rv = NS_NewLayoutHistoryState(aState);
if (NS_FAILED(rv)) {
*aState = nsnull;
return rv;
}
// Capture frame state for the entire frame hierarchy
nsIFrame* rootFrame = nsnull;
rv = GetRootFrame(&rootFrame);
if (NS_FAILED(rv) || nsnull == rootFrame) return rv;
rv = CaptureFrameState(rootFrame, *aState);
return rv;
}
NS_IMETHODIMP
PresShell::CaptureFrameState(nsIFrame* aFrame, nsILayoutHistoryState* aState)
{
nsresult rv = NS_OK;
NS_PRECONDITION(nsnull != aFrame && nsnull != aState, "null parameters passed in");
// See if the frame is stateful.
nsCOMPtr<nsIStatefulFrame> statefulFrame = do_QueryInterface(aFrame);
if (nsnull != statefulFrame) {
// If so, ask the frame to save its state
rv = statefulFrame->SaveState(aState);
}
// XXX We are only going through the principal child list right now.
// Need to talk to Troy to find out about other kinds of
// child lists and whether they will contain stateful frames.
// Capture frame state for the first child
nsIFrame* child = nsnull;
rv = aFrame->FirstChild(nsnull, &child);
if (NS_SUCCEEDED(rv) && nsnull != child) {
rv = CaptureFrameState(child, aState);
}
// Capture frame state for the next sibling
nsIFrame* sibling = nsnull;
rv = aFrame->GetNextSibling(&sibling);
if (NS_SUCCEEDED(rv) && nsnull != sibling) {
rv = CaptureFrameState(sibling, aState);
}
return rv;
}
NS_IMETHODIMP
PresShell::ContentChanged(nsIDocument *aDocument,