1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* 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 "nsIPresShell.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
1998-06-03 19:46:54 +04:00
|
|
|
#include "nsIDocumentObserver.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsIStyleContext.h"
|
1998-05-20 20:24:54 +04:00
|
|
|
#include "nsFrame.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "plhash.h"
|
1998-06-03 19:46:54 +04:00
|
|
|
#include "prlog.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsVoidArray.h"
|
1998-07-31 09:54:59 +04:00
|
|
|
#include "nsIPref.h"
|
1998-08-28 06:54:06 +04:00
|
|
|
#include "nsIViewObserver.h"
|
1998-09-19 07:24:26 +04:00
|
|
|
#include "nsContainerFrame.h"
|
1998-10-01 08:46:11 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-10-02 05:12:39 +04:00
|
|
|
#include "nsIDeviceContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-15 00:46:42 +04:00
|
|
|
static PRBool gsNoisyRefs = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
#undef NOISY
|
|
|
|
|
1998-06-26 20:26:24 +04:00
|
|
|
#if 0
|
1998-05-09 07:22:41 +04:00
|
|
|
static PLHashNumber
|
|
|
|
HashKey(nsIFrame* key)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
return (PLHashNumber) key;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
static PRIntn
|
|
|
|
CompareKeys(nsIFrame* key1, nsIFrame* key2)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
return key1 == key2;
|
|
|
|
}
|
|
|
|
|
|
|
|
class FrameHashTable {
|
|
|
|
public:
|
|
|
|
FrameHashTable();
|
|
|
|
~FrameHashTable();
|
|
|
|
|
|
|
|
void* Get(nsIFrame* aKey);
|
|
|
|
void* Put(nsIFrame* aKey, void* aValue);
|
|
|
|
void* Remove(nsIFrame* aKey);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PLHashTable* mTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
FrameHashTable::FrameHashTable()
|
|
|
|
{
|
|
|
|
mTable = PL_NewHashTable(8, (PLHashFunction) HashKey,
|
|
|
|
(PLHashComparator) CompareKeys,
|
|
|
|
(PLHashComparator) nsnull,
|
|
|
|
nsnull, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameHashTable::~FrameHashTable()
|
|
|
|
{
|
|
|
|
// XXX if debugging then we should assert that the table is empty
|
|
|
|
PL_HashTableDestroy(mTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data associated with a frame.
|
|
|
|
*/
|
1998-05-09 07:22:41 +04:00
|
|
|
void*
|
|
|
|
FrameHashTable::Get(nsIFrame* aKey)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 hashCode = (PRInt32) aKey;
|
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(mTable, hashCode, aKey);
|
|
|
|
PLHashEntry* he = *hep;
|
|
|
|
if (nsnull != he) {
|
|
|
|
return he->value;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an association between a frame and some data. This call
|
|
|
|
* returns an old association if there was one (or nsnull if there
|
|
|
|
* wasn't).
|
|
|
|
*/
|
1998-05-09 07:22:41 +04:00
|
|
|
void*
|
|
|
|
FrameHashTable::Put(nsIFrame* aKey, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 hashCode = (PRInt32) aKey;
|
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(mTable, hashCode, aKey);
|
|
|
|
PLHashEntry* he = *hep;
|
|
|
|
if (nsnull != he) {
|
|
|
|
void* oldValue = he->value;
|
|
|
|
he->value = aData;
|
|
|
|
return oldValue;
|
|
|
|
}
|
|
|
|
PL_HashTableRawAdd(mTable, hep, hashCode, aKey, aData);
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an association between a frame and it's data. This returns
|
|
|
|
* the old associated data.
|
|
|
|
*/
|
1998-05-09 07:22:41 +04:00
|
|
|
void*
|
|
|
|
FrameHashTable::Remove(nsIFrame* aKey)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 hashCode = (PRInt32) aKey;
|
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(mTable, hashCode, aKey);
|
|
|
|
PLHashEntry* he = *hep;
|
|
|
|
void* oldValue = nsnull;
|
|
|
|
if (nsnull != he) {
|
|
|
|
oldValue = he->value;
|
|
|
|
PL_HashTableRawRemove(mTable, hep, he);
|
|
|
|
}
|
|
|
|
return oldValue;
|
|
|
|
}
|
1998-06-26 20:26:24 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIPresShellIID, NS_IPRESSHELL_IID);
|
1998-06-03 19:46:54 +04:00
|
|
|
static NS_DEFINE_IID(kIDocumentObserverIID, NS_IDOCUMENT_OBSERVER_IID);
|
1998-08-28 06:54:06 +04:00
|
|
|
static NS_DEFINE_IID(kIViewObserverIID, NS_IVIEWOBSERVER_IID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-28 06:54:06 +04:00
|
|
|
class PresShell : public nsIPresShell, public nsIViewObserver,
|
|
|
|
private nsIDocumentObserver
|
|
|
|
|
|
|
|
{
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
|
|
|
PresShell();
|
|
|
|
|
|
|
|
void* operator new(size_t sz) {
|
|
|
|
void* rv = new char[sz];
|
|
|
|
nsCRT::zero(rv, sz);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDocumentObserver
|
1998-07-23 03:32:19 +04:00
|
|
|
NS_IMETHOD BeginUpdate(nsIDocument *aDocument);
|
|
|
|
NS_IMETHOD EndUpdate(nsIDocument *aDocument);
|
|
|
|
NS_IMETHOD BeginLoad(nsIDocument *aDocument);
|
|
|
|
NS_IMETHOD EndLoad(nsIDocument *aDocument);
|
|
|
|
NS_IMETHOD BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell);
|
|
|
|
NS_IMETHOD EndReflow(nsIDocument *aDocument, nsIPresShell* aShell);
|
|
|
|
NS_IMETHOD ContentChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
1998-06-03 19:46:54 +04:00
|
|
|
nsISupports* aSubContent);
|
1998-09-18 23:53:27 +04:00
|
|
|
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
1998-09-30 03:46:05 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint);
|
1998-07-23 03:32:19 +04:00
|
|
|
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
|
1998-09-10 23:32:14 +04:00
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer);
|
1998-07-23 03:32:19 +04:00
|
|
|
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
1998-06-03 19:46:54 +04:00
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
1998-07-23 03:32:19 +04:00
|
|
|
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
1998-06-03 19:46:54 +04:00
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
1998-09-25 01:39:47 +04:00
|
|
|
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
1998-07-23 03:32:19 +04:00
|
|
|
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet);
|
|
|
|
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// nsIPresShell
|
1998-06-03 19:46:54 +04:00
|
|
|
NS_IMETHOD Init(nsIDocument* aDocument,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIStyleSet* aStyleSet);
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual nsIDocument* GetDocument();
|
|
|
|
virtual nsIPresContext* GetPresContext();
|
|
|
|
virtual nsIViewManager* GetViewManager();
|
|
|
|
virtual nsIStyleSet* GetStyleSet();
|
1998-05-09 07:22:41 +04:00
|
|
|
NS_IMETHOD EnterReflowLock();
|
|
|
|
NS_IMETHOD ExitReflowLock();
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual void BeginObservingDocument();
|
|
|
|
virtual void EndObservingDocument();
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IMETHOD InitialReflow(nscoord aWidth, nscoord aHeight);
|
1998-08-28 06:54:06 +04:00
|
|
|
NS_IMETHOD ResizeReflow(nscoord aWidth, nscoord aHeight);
|
1998-11-06 19:16:01 +03:00
|
|
|
NS_IMETHOD StyleChangeReflow();
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual nsIFrame* GetRootFrame();
|
|
|
|
virtual nsIFrame* FindFrameWithContent(nsIContent* aContent);
|
1998-06-09 08:51:44 +04:00
|
|
|
virtual void AppendReflowCommand(nsIReflowCommand* aReflowCommand);
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual void ProcessReflowCommands();
|
1998-10-02 05:12:39 +04:00
|
|
|
NS_IMETHOD CreateRenderingContext(nsIFrame *aFrame, nsIRenderingContext *&aContext);
|
1998-08-28 06:54:06 +04:00
|
|
|
|
|
|
|
//nsIViewObserver interface
|
|
|
|
|
|
|
|
NS_IMETHOD Paint(nsIView *aView,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect);
|
|
|
|
NS_IMETHOD HandleEvent(nsIView* aView,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus);
|
|
|
|
NS_IMETHOD Scrolled(nsIView *aView);
|
|
|
|
NS_IMETHOD ResizeReflow(nsIView *aView, nscoord aWidth, nscoord aHeight);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
protected:
|
|
|
|
~PresShell();
|
|
|
|
|
1998-07-13 23:49:42 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void VerifyIncrementalReflow();
|
|
|
|
#endif
|
1998-05-20 20:24:54 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIDocument* mDocument;
|
|
|
|
nsIPresContext* mPresContext;
|
|
|
|
nsIStyleSet* mStyleSet;
|
|
|
|
nsIFrame* mRootFrame;
|
|
|
|
nsIViewManager* mViewManager;
|
|
|
|
PRUint32 mUpdateCount;
|
|
|
|
nsVoidArray mReflowCommands;
|
1998-05-09 07:22:41 +04:00
|
|
|
PRUint32 mReflowLockCount;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1998-07-13 23:49:42 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
/**
|
|
|
|
* Note: the log module is created during library initialization which
|
|
|
|
* means that you cannot perform logging before then.
|
|
|
|
*/
|
|
|
|
static PRLogModuleInfo* gLogModule = PR_NewLogModule("verifyreflow");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static PRBool gVerifyReflow = PRBool(0x55);
|
|
|
|
|
|
|
|
NS_LAYOUT PRBool
|
|
|
|
nsIPresShell::GetVerifyReflowEnable()
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (gVerifyReflow == PRBool(0x55)) {
|
|
|
|
gVerifyReflow = 0 != gLogModule->level;
|
|
|
|
printf("Note: verifyreflow is %sabled\n",
|
|
|
|
gVerifyReflow ? "en" : "dis");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return gVerifyReflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_LAYOUT void
|
|
|
|
nsIPresShell::SetVerifyReflowEnable(PRBool aEnabled)
|
|
|
|
{
|
|
|
|
gVerifyReflow = aEnabled;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-07-13 23:49:42 +04:00
|
|
|
NS_LAYOUT nsresult
|
|
|
|
NS_NewPresShell(nsIPresShell** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
PresShell* it = new PresShell();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return it->QueryInterface(kIPresShellIID, (void **) aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
PresShell::PresShell()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-09-15 00:46:42 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// for debugging only
|
|
|
|
nsrefcnt PresShell::AddRef(void)
|
|
|
|
{
|
|
|
|
if (gsNoisyRefs) printf("PresShell: AddRef: %x, cnt = %d \n",this, mRefCnt+1);
|
|
|
|
return ++mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for debugging only
|
|
|
|
nsrefcnt PresShell::Release(void)
|
|
|
|
{
|
|
|
|
if (gsNoisyRefs==PR_TRUE) printf("PresShell Release: %x, cnt = %d \n",this, mRefCnt-1);
|
|
|
|
if (--mRefCnt == 0) {
|
|
|
|
if (gsNoisyRefs==PR_TRUE) printf("PresShell Delete: %x, \n",this);
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
#else
|
1998-09-12 23:33:48 +04:00
|
|
|
NS_IMPL_ADDREF(PresShell)
|
|
|
|
NS_IMPL_RELEASE(PresShell)
|
1998-09-15 00:46:42 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
nsresult
|
|
|
|
PresShell::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (aIID.Equals(kIPresShellIID)) {
|
1998-09-12 23:33:48 +04:00
|
|
|
nsIPresShell* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDocumentObserverIID)) {
|
1998-09-12 23:33:48 +04:00
|
|
|
nsIDocumentObserver* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-08-28 06:54:06 +04:00
|
|
|
if (aIID.Equals(kIViewObserverIID)) {
|
1998-09-12 23:33:48 +04:00
|
|
|
nsIViewObserver* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
1998-08-28 06:54:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
1998-09-12 23:33:48 +04:00
|
|
|
nsIPresShell* tmp = this;
|
|
|
|
nsISupports* tmp2 = tmp;
|
|
|
|
*aInstancePtr = (void*) tmp2;
|
|
|
|
NS_ADDREF_THIS();
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PresShell::~PresShell()
|
|
|
|
{
|
1998-08-06 23:52:48 +04:00
|
|
|
mRefCnt = 99;/* XXX hack! get around re-entrancy bugs */
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull != mRootFrame) {
|
1998-08-28 06:54:06 +04:00
|
|
|
mRootFrame->DeleteFrame(*mPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
NS_IF_RELEASE(mViewManager);
|
1998-08-09 11:43:22 +04:00
|
|
|
//Release mPresContext after mViewManager
|
|
|
|
NS_IF_RELEASE(mPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_IF_RELEASE(mStyleSet);
|
1998-09-23 21:16:51 +04:00
|
|
|
if (nsnull != mDocument) {
|
|
|
|
mDocument->DeleteShell(this);
|
|
|
|
NS_RELEASE(mDocument);
|
|
|
|
}
|
1998-08-06 23:52:48 +04:00
|
|
|
mRefCnt = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the presentation shell. Create view manager and style
|
|
|
|
* manager.
|
|
|
|
*/
|
1998-05-09 07:22:41 +04:00
|
|
|
nsresult
|
|
|
|
PresShell::Init(nsIDocument* aDocument,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIStyleSet* aStyleSet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aDocument, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aViewManager, "null ptr");
|
|
|
|
if ((nsnull == aDocument) || (nsnull == aPresContext) ||
|
|
|
|
(nsnull == aViewManager)) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (nsnull != mDocument) {
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocument = aDocument;
|
|
|
|
NS_ADDREF(aDocument);
|
|
|
|
mViewManager = aViewManager;
|
|
|
|
NS_ADDREF(mViewManager);
|
|
|
|
|
1998-08-28 06:54:06 +04:00
|
|
|
//doesn't add a ref since we own it... MMP
|
|
|
|
mViewManager->SetViewObserver((nsIViewObserver *)this);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Bind the context to the presentation shell.
|
|
|
|
mPresContext = aPresContext;
|
|
|
|
NS_ADDREF(aPresContext);
|
|
|
|
aPresContext->SetShell(this);
|
|
|
|
|
|
|
|
mStyleSet = aStyleSet;
|
|
|
|
NS_ADDREF(aStyleSet);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
NS_METHOD
|
|
|
|
PresShell::EnterReflowLock()
|
|
|
|
{
|
|
|
|
++mReflowLockCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
PresShell::ExitReflowLock()
|
|
|
|
{
|
1998-05-12 05:30:40 +04:00
|
|
|
PRUint32 newReflowLockCount = mReflowLockCount - 1;
|
|
|
|
if (newReflowLockCount == 0) {
|
|
|
|
ProcessReflowCommands();
|
1998-05-09 07:22:41 +04:00
|
|
|
}
|
1998-05-12 05:30:40 +04:00
|
|
|
mReflowLockCount = newReflowLockCount;
|
1998-05-09 07:22:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument*
|
|
|
|
PresShell::GetDocument()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
nsIPresContext*
|
|
|
|
PresShell::GetPresContext()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mPresContext);
|
|
|
|
return mPresContext;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
nsIViewManager*
|
|
|
|
PresShell::GetViewManager()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mViewManager);
|
|
|
|
return mViewManager;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
nsIStyleSet*
|
|
|
|
PresShell::GetStyleSet()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mStyleSet);
|
|
|
|
return mStyleSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make shell be a document observer
|
1998-05-09 07:22:41 +04:00
|
|
|
void
|
|
|
|
PresShell::BeginObservingDocument()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (nsnull != mDocument) {
|
|
|
|
mDocument->AddObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make shell stop being a document observer
|
1998-05-09 07:22:41 +04:00
|
|
|
void
|
|
|
|
PresShell::EndObservingDocument()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (nsnull != mDocument) {
|
|
|
|
mDocument->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-28 06:54:06 +04:00
|
|
|
NS_IMETHODIMP
|
1998-09-10 23:32:14 +04:00
|
|
|
PresShell::InitialReflow(nscoord aWidth, nscoord aHeight)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_PRECONDITION(nsnull == mRootFrame, "unexpected root frame");
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
EnterReflowLock();
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull != mPresContext) {
|
|
|
|
nsRect r(0, 0, aWidth, aHeight);
|
|
|
|
mPresContext->SetVisibleArea(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull == mRootFrame) {
|
|
|
|
if (nsnull != mDocument) {
|
|
|
|
nsIContent* root = mDocument->GetRootContent();
|
|
|
|
if (nsnull != root) {
|
1998-09-10 23:32:14 +04:00
|
|
|
// Have style sheet processor construct a frame for the
|
|
|
|
// root content object
|
1998-09-30 03:46:05 +04:00
|
|
|
mStyleSet->ConstructFrame(mPresContext, root, nsnull, mRootFrame);
|
1998-09-24 00:59:57 +04:00
|
|
|
NS_RELEASE(root);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
if (nsnull != mRootFrame) {
|
|
|
|
// Kick off a top-down reflow
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsPresShell::InitialReflow: %d,%d", aWidth, aHeight));
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
|
|
|
#endif
|
1998-10-02 05:12:39 +04:00
|
|
|
nsRect bounds;
|
1998-09-10 23:32:14 +04:00
|
|
|
mPresContext->GetVisibleArea(bounds);
|
1998-10-02 05:12:39 +04:00
|
|
|
nsSize maxSize(bounds.width, bounds.height);
|
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsReflowStatus status;
|
|
|
|
nsIHTMLReflow* htmlReflow;
|
|
|
|
nsIRenderingContext* rcx = nsnull;
|
|
|
|
|
|
|
|
CreateRenderingContext(mRootFrame, rcx);
|
|
|
|
|
1998-10-12 18:48:02 +04:00
|
|
|
nsHTMLReflowState reflowState(*mPresContext, mRootFrame,
|
|
|
|
eReflowReason_Initial, maxSize, rcx);
|
1998-10-01 08:46:11 +04:00
|
|
|
|
|
|
|
if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
|
|
|
htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status);
|
|
|
|
mRootFrame->SizeTo(desiredSize.width, desiredSize.height);
|
1998-09-10 23:32:14 +04:00
|
|
|
#ifdef NS_DEBUG
|
1998-10-01 08:46:11 +04:00
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
1998-09-10 23:32:14 +04:00
|
|
|
#endif
|
1998-10-01 08:46:11 +04:00
|
|
|
}
|
1998-10-02 05:12:39 +04:00
|
|
|
NS_IF_RELEASE(rcx);
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("exit nsPresShell::InitialReflow"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitReflowLock();
|
|
|
|
|
|
|
|
return NS_OK; //XXX this needs to be real. MMP
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
|
|
|
EnterReflowLock();
|
|
|
|
|
|
|
|
if (nsnull != mPresContext) {
|
|
|
|
nsRect r(0, 0, aWidth, aHeight);
|
|
|
|
mPresContext->SetVisibleArea(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we don't have a root frame yet, that means we haven't had our initial
|
|
|
|
// reflow...
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull != mRootFrame) {
|
|
|
|
// Kick off a top-down reflow
|
1998-05-20 20:24:54 +04:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsPresShell::ResizeReflow: %d,%d", aWidth, aHeight));
|
1998-04-14 00:24:54 +04:00
|
|
|
#ifdef NS_DEBUG
|
1998-05-20 20:24:54 +04:00
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
1998-10-02 05:12:39 +04:00
|
|
|
nsRect bounds;
|
1998-05-22 22:36:40 +04:00
|
|
|
mPresContext->GetVisibleArea(bounds);
|
1998-10-02 05:12:39 +04:00
|
|
|
nsSize maxSize(bounds.width, bounds.height);
|
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsReflowStatus status;
|
|
|
|
nsIHTMLReflow* htmlReflow;
|
|
|
|
nsIRenderingContext* rcx = nsnull;
|
|
|
|
|
|
|
|
CreateRenderingContext(mRootFrame, rcx);
|
|
|
|
|
1998-10-12 18:48:02 +04:00
|
|
|
nsHTMLReflowState reflowState(*mPresContext, mRootFrame,
|
|
|
|
eReflowReason_Resize, maxSize, rcx);
|
1998-10-01 08:46:11 +04:00
|
|
|
|
|
|
|
if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
|
|
|
htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status);
|
|
|
|
mRootFrame->SizeTo(desiredSize.width, desiredSize.height);
|
1998-04-14 00:24:54 +04:00
|
|
|
#ifdef NS_DEBUG
|
1998-10-01 08:46:11 +04:00
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
1998-10-01 08:46:11 +04:00
|
|
|
}
|
1998-10-02 05:12:39 +04:00
|
|
|
NS_IF_RELEASE(rcx);
|
1998-05-20 20:24:54 +04:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("exit nsPresShell::ResizeReflow"));
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// XXX if debugging then we should assert that the cache is empty
|
|
|
|
} else {
|
|
|
|
#ifdef NOISY
|
|
|
|
printf("PresShell::ResizeReflow: null root frame\n");
|
|
|
|
#endif
|
|
|
|
}
|
1998-06-03 19:46:54 +04:00
|
|
|
|
|
|
|
ExitReflowLock();
|
1998-08-28 06:54:06 +04:00
|
|
|
|
|
|
|
return NS_OK; //XXX this needs to be real. MMP
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-11-06 19:16:01 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::StyleChangeReflow()
|
|
|
|
{
|
|
|
|
EnterReflowLock();
|
|
|
|
|
|
|
|
if (nsnull != mRootFrame) {
|
|
|
|
// Kick off a top-down reflow
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsPresShell::StyleChangeReflow"));
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
nsRect bounds;
|
|
|
|
mPresContext->GetVisibleArea(bounds);
|
|
|
|
nsSize maxSize(bounds.width, bounds.height);
|
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsReflowStatus status;
|
|
|
|
nsIHTMLReflow* htmlReflow;
|
|
|
|
nsIRenderingContext* rcx = nsnull;
|
|
|
|
|
|
|
|
CreateRenderingContext(mRootFrame, rcx);
|
|
|
|
|
|
|
|
// XXX We should be using eReflowReason_StyleChange
|
|
|
|
nsHTMLReflowState reflowState(*mPresContext, mRootFrame,
|
|
|
|
eReflowReason_Resize, maxSize, rcx);
|
|
|
|
|
|
|
|
if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
|
|
|
htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status);
|
|
|
|
mRootFrame->SizeTo(desiredSize.width, desiredSize.height);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(rcx);
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("exit nsPresShell::StyleChangeReflow"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitReflowLock();
|
|
|
|
|
|
|
|
return NS_OK; //XXX this needs to be real. MMP
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
nsIFrame*
|
|
|
|
PresShell::GetRootFrame()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
return mRootFrame;
|
|
|
|
}
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::BeginUpdate(nsIDocument *aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
mUpdateCount++;
|
1998-06-03 19:46:54 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::EndUpdate(nsIDocument *aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != mUpdateCount, "too many EndUpdate's");
|
|
|
|
if (--mUpdateCount == 0) {
|
|
|
|
// XXX do something here
|
|
|
|
}
|
1998-06-03 19:46:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::BeginLoad(nsIDocument *aDocument)
|
1998-06-03 19:46:54 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::EndLoad(nsIDocument *aDocument)
|
1998-06-03 19:46:54 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell)
|
1998-06-03 19:46:54 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::EndReflow(nsIDocument *aDocument, nsIPresShell* aShell)
|
1998-06-03 19:46:54 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
void
|
1998-06-09 08:51:44 +04:00
|
|
|
PresShell::AppendReflowCommand(nsIReflowCommand* aReflowCommand)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
mReflowCommands.AppendElement(aReflowCommand);
|
1998-06-09 08:51:44 +04:00
|
|
|
NS_ADDREF(aReflowCommand);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
void
|
|
|
|
PresShell::ProcessReflowCommands()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (0 != mReflowCommands.Count()) {
|
1998-10-02 05:12:39 +04:00
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsIRenderingContext* rcx;
|
|
|
|
|
|
|
|
CreateRenderingContext(mRootFrame, rcx);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
while (0 != mReflowCommands.Count()) {
|
1998-06-09 08:51:44 +04:00
|
|
|
nsIReflowCommand* rc = (nsIReflowCommand*) mReflowCommands.ElementAt(0);
|
1998-04-14 00:24:54 +04:00
|
|
|
mReflowCommands.RemoveElementAt(0);
|
|
|
|
|
|
|
|
// Dispatch the reflow command
|
1998-04-17 05:41:24 +04:00
|
|
|
nsSize maxSize;
|
|
|
|
mRootFrame->GetSize(maxSize);
|
1998-06-09 08:51:44 +04:00
|
|
|
#ifdef NS_DEBUG
|
1998-07-03 01:26:00 +04:00
|
|
|
nsIReflowCommand::ReflowType type;
|
1998-06-09 08:51:44 +04:00
|
|
|
rc->GetType(type);
|
1998-07-03 01:26:00 +04:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("PresShell::ProcessReflowCommands: begin reflow command type=%d",
|
|
|
|
type));
|
1998-06-09 08:51:44 +04:00
|
|
|
#endif
|
1998-10-02 05:12:39 +04:00
|
|
|
rc->Dispatch(*mPresContext, desiredSize, maxSize, *rcx);
|
1998-06-09 08:51:44 +04:00
|
|
|
NS_RELEASE(rc);
|
1998-07-03 01:26:00 +04:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("PresShell::ProcessReflowCommands: end reflow command"));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Place and size the root frame
|
|
|
|
mRootFrame->SizeTo(desiredSize.width, desiredSize.height);
|
|
|
|
#ifdef NS_DEBUG
|
1998-05-20 20:24:54 +04:00
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
1998-07-13 23:49:42 +04:00
|
|
|
if (GetVerifyReflowEnable()) {
|
|
|
|
VerifyIncrementalReflow();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
1998-10-02 05:12:39 +04:00
|
|
|
NS_IF_RELEASE(rcx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP PresShell :: CreateRenderingContext(nsIFrame *aFrame,
|
|
|
|
nsIRenderingContext *&aContext)
|
|
|
|
{
|
|
|
|
nsIWidget *widget = nsnull;
|
|
|
|
nsIView *view = nsnull;
|
|
|
|
nsPoint pt;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
aFrame->GetView(view);
|
|
|
|
|
|
|
|
if (nsnull == view)
|
|
|
|
aFrame->GetOffsetFromView(pt, view);
|
|
|
|
|
|
|
|
while (nsnull != view)
|
|
|
|
{
|
|
|
|
view->GetWidget(widget);
|
|
|
|
|
|
|
|
if (nsnull != widget)
|
|
|
|
{
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->GetParent(view);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-10-02 05:12:39 +04:00
|
|
|
|
|
|
|
if (nsnull != view)
|
|
|
|
{
|
|
|
|
nsIDeviceContext *dx;
|
|
|
|
|
|
|
|
dx = mPresContext->GetDeviceContext();
|
|
|
|
rv = dx->CreateRenderingContext(view, aContext);
|
|
|
|
NS_RELEASE(dx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
aContext = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static char*
|
|
|
|
ContentTag(nsIContent* aContent, PRIntn aSlot)
|
|
|
|
{
|
|
|
|
static char buf0[100], buf1[100], buf2[100];
|
|
|
|
static char* bufs[] = { buf0, buf1, buf2 };
|
|
|
|
char* buf = bufs[aSlot];
|
1998-08-30 00:20:38 +04:00
|
|
|
nsIAtom* atom;
|
|
|
|
aContent->GetTag(atom);
|
1998-06-03 19:46:54 +04:00
|
|
|
if (nsnull != atom) {
|
|
|
|
nsAutoString tmp;
|
|
|
|
atom->ToString(tmp);
|
|
|
|
tmp.ToCString(buf, 100);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf[0] = 0;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::ContentChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
1998-05-09 07:22:41 +04:00
|
|
|
nsISupports* aSubContent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-06 20:28:55 +04:00
|
|
|
NS_PRECONDITION(nsnull != mRootFrame, "null root frame");
|
1998-05-30 05:31:04 +04:00
|
|
|
|
|
|
|
EnterReflowLock();
|
1998-09-30 03:46:05 +04:00
|
|
|
nsresult rv = mStyleSet->ContentChanged(mPresContext, aContent, aSubContent);
|
1998-05-30 05:31:04 +04:00
|
|
|
ExitReflowLock();
|
1998-09-30 03:46:05 +04:00
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-09-18 23:53:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
1998-09-30 03:46:05 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
1998-09-18 23:53:27 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mRootFrame, "null root frame");
|
|
|
|
|
|
|
|
EnterReflowLock();
|
1998-09-30 03:46:05 +04:00
|
|
|
nsresult rv = mStyleSet->AttributeChanged(mPresContext, aContent, aAttribute, aHint);
|
1998-09-18 23:53:27 +04:00
|
|
|
ExitReflowLock();
|
1998-09-30 03:46:05 +04:00
|
|
|
return rv;
|
1998-09-18 23:53:27 +04:00
|
|
|
}
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::ContentAppended(nsIDocument *aDocument,
|
1998-09-10 23:32:14 +04:00
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-03 19:46:54 +04:00
|
|
|
EnterReflowLock();
|
1998-09-30 03:46:05 +04:00
|
|
|
nsresult rv = mStyleSet->ContentAppended(mPresContext, aContainer, aNewIndexInContainer);
|
1998-06-03 19:46:54 +04:00
|
|
|
ExitReflowLock();
|
1998-09-10 23:32:14 +04:00
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
NS_IMETHODIMP
|
1998-09-10 23:32:14 +04:00
|
|
|
PresShell::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-09-10 23:32:14 +04:00
|
|
|
EnterReflowLock();
|
1998-09-30 03:46:05 +04:00
|
|
|
nsresult rv = mStyleSet->ContentInserted(mPresContext, aContainer, aChild, aIndexInContainer);
|
1998-09-10 23:32:14 +04:00
|
|
|
ExitReflowLock();
|
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
NS_IMETHODIMP
|
1998-09-10 23:32:14 +04:00
|
|
|
PresShell::ContentReplaced(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-09-10 23:32:14 +04:00
|
|
|
EnterReflowLock();
|
1998-09-30 03:46:05 +04:00
|
|
|
nsresult rv = mStyleSet->ContentReplaced(mPresContext, aContainer, aOldChild,
|
|
|
|
aNewChild, aIndexInContainer);
|
1998-09-10 23:32:14 +04:00
|
|
|
ExitReflowLock();
|
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
NS_IMETHODIMP
|
1998-09-25 01:39:47 +04:00
|
|
|
PresShell::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-09-25 09:13:06 +04:00
|
|
|
EnterReflowLock();
|
1998-09-30 03:46:05 +04:00
|
|
|
nsresult rv = mStyleSet->ContentRemoved(mPresContext, aContainer,
|
|
|
|
aChild, aIndexInContainer);
|
1998-09-25 09:13:06 +04:00
|
|
|
ExitReflowLock();
|
1998-09-10 23:32:14 +04:00
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-06-03 19:46:54 +04:00
|
|
|
NS_IMETHODIMP
|
1998-07-23 03:32:19 +04:00
|
|
|
PresShell::StyleSheetAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::DocumentWillBeDestroyed(nsIDocument *aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-03 19:46:54 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-10-16 00:26:54 +04:00
|
|
|
static PRBool
|
|
|
|
IsZeroSizedFrame(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsSize size;
|
|
|
|
aFrame->GetSize(size);
|
|
|
|
return ((0 == size.width) && (0 == size.height));
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
static nsIFrame*
|
|
|
|
FindFrameWithContent(nsIFrame* aFrame, nsIContent* aContent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIContent* frameContent;
|
|
|
|
|
|
|
|
aFrame->GetContent(frameContent);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (frameContent == aContent) {
|
1998-10-16 00:26:54 +04:00
|
|
|
// XXX Sleazy hack to check whether this is a placeholder frame.
|
|
|
|
// If it is, we skip it and go on to (hopefully) find the
|
|
|
|
// absolutely positioned frame.
|
|
|
|
const nsStylePosition* position;
|
|
|
|
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Position, (nsStyleStruct*&)position);
|
|
|
|
if ((NS_STYLE_POSITION_ABSOLUTE != position->mPosition) ||
|
|
|
|
!IsZeroSizedFrame(aFrame)) {
|
|
|
|
NS_RELEASE(frameContent);
|
|
|
|
return aFrame;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(frameContent);
|
|
|
|
|
1998-11-09 22:40:27 +03:00
|
|
|
aFrame->FirstChild(nsnull, aFrame);
|
1998-04-14 00:24:54 +04:00
|
|
|
while (aFrame) {
|
|
|
|
nsIFrame* result = FindFrameWithContent(aFrame, aContent);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
aFrame->GetNextSibling(aFrame);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:41 +04:00
|
|
|
nsIFrame*
|
|
|
|
PresShell::FindFrameWithContent(nsIContent* aContent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// For the time being do a brute force depth-first search of
|
|
|
|
// the frame tree
|
|
|
|
return ::FindFrameWithContent(mRootFrame, aContent);
|
|
|
|
}
|
|
|
|
|
1998-08-28 06:54:06 +04:00
|
|
|
//nsIViewObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP PresShell :: Paint(nsIView *aView,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
1998-08-30 23:16:11 +04:00
|
|
|
void* clientData;
|
|
|
|
nsIFrame* frame;
|
1998-10-31 01:06:14 +03:00
|
|
|
nsresult rv = NS_OK;
|
1998-08-28 06:54:06 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(!(nsnull == aView), "null view");
|
|
|
|
|
1998-08-30 23:16:11 +04:00
|
|
|
aView->GetClientData(clientData);
|
|
|
|
frame = (nsIFrame *)clientData;
|
1998-08-28 06:54:06 +04:00
|
|
|
|
1998-10-31 01:06:14 +03:00
|
|
|
if (nsnull != frame) {
|
1998-08-28 06:54:06 +04:00
|
|
|
rv = frame->Paint(*mPresContext, aRenderingContext, aDirtyRect);
|
1998-10-31 01:06:14 +03:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Draw a border around the frame
|
|
|
|
if (nsIFrame::GetShowFrameBorders()) {
|
|
|
|
nsRect r;
|
|
|
|
frame->GetRect(r);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,255));
|
|
|
|
aRenderingContext.DrawRect(0, 0, r.width, r.height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1998-08-28 06:54:06 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP PresShell :: HandleEvent(nsIView *aView,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
1998-08-30 23:16:11 +04:00
|
|
|
void* clientData;
|
|
|
|
nsIFrame* frame;
|
1998-08-28 06:54:06 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(!(nsnull == aView), "null view");
|
|
|
|
|
1998-08-30 23:16:11 +04:00
|
|
|
aView->GetClientData(clientData);
|
|
|
|
frame = (nsIFrame *)clientData;
|
1998-08-28 06:54:06 +04:00
|
|
|
|
|
|
|
if (nsnull != frame)
|
|
|
|
rv = frame->HandleEvent(*mPresContext, aEvent, aEventStatus);
|
|
|
|
else
|
|
|
|
rv = NS_OK;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP PresShell :: Scrolled(nsIView *aView)
|
|
|
|
{
|
1998-08-30 23:16:11 +04:00
|
|
|
void* clientData;
|
|
|
|
nsIFrame* frame;
|
1998-08-28 06:54:06 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(!(nsnull == aView), "null view");
|
|
|
|
|
1998-08-30 23:16:11 +04:00
|
|
|
aView->GetClientData(clientData);
|
|
|
|
frame = (nsIFrame *)clientData;
|
1998-08-28 06:54:06 +04:00
|
|
|
|
|
|
|
if (nsnull != frame)
|
1998-09-06 00:57:57 +04:00
|
|
|
rv = frame->Scrolled(aView);
|
1998-08-28 06:54:06 +04:00
|
|
|
else
|
|
|
|
rv = NS_OK;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP PresShell :: ResizeReflow(nsIView *aView, nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
|
|
|
return ResizeReflow(aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
1998-07-13 23:49:42 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsICSSParser.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kViewManagerCID, NS_VIEW_MANAGER_CID);
|
|
|
|
static NS_DEFINE_IID(kIViewManagerIID, NS_IVIEWMANAGER_IID);
|
|
|
|
static NS_DEFINE_IID(kScrollingViewCID, NS_SCROLLING_VIEW_CID);
|
|
|
|
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
|
|
|
|
static NS_DEFINE_IID(kScrollViewIID, NS_ISCROLLABLEVIEW_IID);
|
|
|
|
static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID);
|
|
|
|
|
|
|
|
static void
|
|
|
|
ShowDiffs(nsIFrame* k1, nsIFrame* k2, const nsRect& r1, const nsRect& r2)
|
|
|
|
{
|
|
|
|
printf("verifyreflow: ");
|
|
|
|
k1->ListTag(stdout);
|
|
|
|
printf(" ");
|
|
|
|
stdout << r1;
|
|
|
|
printf(" != ");
|
|
|
|
k2->ListTag(stdout);
|
|
|
|
printf(" ");
|
|
|
|
stdout << r2;
|
|
|
|
printf("\n");
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-13 23:49:42 +04:00
|
|
|
static void
|
|
|
|
CompareTrees(nsIFrame* aA, nsIFrame* aB)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-07-13 23:49:42 +04:00
|
|
|
nsIFrame* k1, *k2;
|
1998-11-09 22:40:27 +03:00
|
|
|
aA->FirstChild(nsnull, k1);
|
|
|
|
aB->FirstChild(nsnull, k2);
|
1998-09-19 07:24:26 +04:00
|
|
|
NS_ASSERTION(nsContainerFrame::LengthOf(k1) == nsContainerFrame::LengthOf(k2),
|
|
|
|
"child counts don't match");
|
|
|
|
|
1998-07-13 23:49:42 +04:00
|
|
|
nsRect r1, r2;
|
|
|
|
nsIView* v1, *v2;
|
|
|
|
nsIWidget* w1, *w2;
|
|
|
|
for (;;) {
|
|
|
|
if (nsnull == k1) {
|
|
|
|
NS_ASSERTION(nsnull == k2, "child lists are different");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(nsnull != k2, "child lists are different");
|
|
|
|
|
|
|
|
// Verify that the frames are the same size
|
|
|
|
k1->GetRect(r1);
|
|
|
|
k2->GetRect(r2);
|
|
|
|
if (r1 != r2) {
|
|
|
|
ShowDiffs(k1, k2, r1, r2);
|
|
|
|
}
|
|
|
|
else {
|
1998-08-08 08:23:33 +04:00
|
|
|
// Make sure either both have views or neither have views; if they
|
1998-07-13 23:49:42 +04:00
|
|
|
// do have views, make sure the views are the same size. If the
|
|
|
|
// views have widgets, make sure they both do or neither does. If
|
|
|
|
// they do, make sure the widgets are the same size.
|
|
|
|
k1->GetView(v1);
|
|
|
|
k2->GetView(v2);
|
|
|
|
if (nsnull != v1) {
|
|
|
|
NS_ASSERTION(nsnull != v2, "child views are not matched");
|
|
|
|
v1->GetBounds(r1);
|
|
|
|
v2->GetBounds(r2);
|
|
|
|
NS_ASSERTION(r1 == r2, "child views are different sizes");
|
|
|
|
|
1998-08-30 23:16:11 +04:00
|
|
|
v1->GetWidget(w1);
|
|
|
|
v2->GetWidget(w2);
|
1998-07-13 23:49:42 +04:00
|
|
|
if (nsnull != w1) {
|
|
|
|
NS_ASSERTION(nsnull != w2, "child widgets are not matched");
|
|
|
|
w1->GetBounds(r1);
|
|
|
|
w2->GetBounds(r2);
|
|
|
|
NS_ASSERTION(r1 == r2, "child widgets are different sizes");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(nsnull == w2, "child widgets are not matched");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(nsnull == v2, "child views are not matched");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare the sub-trees too
|
|
|
|
CompareTrees(k1, k2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Advance to next sibling
|
|
|
|
k1->GetNextSibling(k1);
|
|
|
|
k2->GetNextSibling(k2);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-07-13 23:49:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: copy of nsWebWidget's ua.css loading code!!!
|
|
|
|
#define UA_CSS_URL "resource:/res/ua.css"
|
|
|
|
|
|
|
|
static nsIStyleSheet* gUAStyleSheet;
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
InitUAStyleSheet()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == gUAStyleSheet) { // snarf one
|
|
|
|
nsIURL* uaURL;
|
|
|
|
rv = NS_NewURL(&uaURL, nsnull, UA_CSS_URL); // XXX this bites, fix it
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Get an input stream from the url
|
|
|
|
PRInt32 ec;
|
|
|
|
nsIInputStream* in = uaURL->Open(&ec);
|
|
|
|
if (nsnull != in) {
|
|
|
|
// Translate the input using the argument character set id into unicode
|
|
|
|
nsIUnicharInputStream* uin;
|
|
|
|
rv = NS_NewConverterStream(&uin, nsnull, in);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Create parser and set it up to process the input file
|
|
|
|
nsICSSParser* css;
|
|
|
|
rv = NS_NewCSSParser(&css);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Parse the input and produce a style set
|
|
|
|
// XXX note: we are ignoring rv until the error code stuff in the
|
|
|
|
// input routines is converted to use nsresult's
|
|
|
|
css->Parse(uin, uaURL, gUAStyleSheet);
|
|
|
|
NS_RELEASE(css);
|
|
|
|
}
|
|
|
|
NS_RELEASE(uin);
|
|
|
|
}
|
|
|
|
NS_RELEASE(in);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// printf("open of %s failed: error=%x\n", UA_CSS_URL, ec);
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE; // XXX need a better error code here
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(uaURL);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-07-13 23:49:42 +04:00
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-07-13 23:49:42 +04:00
|
|
|
|
|
|
|
static nsresult
|
|
|
|
CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet)
|
|
|
|
{
|
|
|
|
nsresult rv = InitUAStyleSheet();
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_WARNING("unable to load UA style sheet");
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NS_NewStyleSet(aStyleSet);
|
|
|
|
if (NS_OK == rv) {
|
1998-09-02 06:02:53 +04:00
|
|
|
PRInt32 index = aDocument->GetNumberOfStyleSheets();
|
|
|
|
while (0 < index--) {
|
|
|
|
// NOTE: turn the order around for the set
|
1998-07-13 23:49:42 +04:00
|
|
|
nsIStyleSheet* sheet = aDocument->GetStyleSheetAt(index);
|
|
|
|
(*aStyleSet)->AppendDocStyleSheet(sheet);
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
1998-09-02 06:02:53 +04:00
|
|
|
// XXX this is just wrong, the UA style sheet should be owned by the UA
|
|
|
|
// for that matter, the style set should be created by the UA too
|
1998-07-13 23:49:42 +04:00
|
|
|
if (nsnull != gUAStyleSheet) {
|
|
|
|
(*aStyleSet)->AppendBackstopStyleSheet(gUAStyleSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// After an incremental reflow, we verify the correctness by doing a
|
|
|
|
// full reflow into a fresh frame tree.
|
|
|
|
void
|
|
|
|
PresShell::VerifyIncrementalReflow()
|
|
|
|
{
|
|
|
|
// All the stuff we are creating that needs releasing
|
|
|
|
nsIPresContext* cx;
|
|
|
|
nsIViewManager* vm;
|
|
|
|
nsIView* view;
|
|
|
|
nsIPresShell* sh;
|
|
|
|
nsIStyleSet* ss;
|
|
|
|
|
|
|
|
// Create a presentation context to view the new frame tree
|
|
|
|
nsresult rv;
|
|
|
|
if (mPresContext->IsPaginated()) {
|
|
|
|
rv = NS_NewPrintPreviewContext(&cx);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = NS_NewGalleyContext(&cx);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create presentation context");
|
|
|
|
nsIDeviceContext* dc = mPresContext->GetDeviceContext();
|
1998-07-31 09:54:59 +04:00
|
|
|
nsIPref* prefs;
|
|
|
|
mPresContext->GetPrefs(prefs);
|
|
|
|
cx->Init(dc, prefs);
|
|
|
|
NS_IF_RELEASE(prefs);
|
1998-07-13 23:49:42 +04:00
|
|
|
|
|
|
|
rv = CreateStyleSet(mDocument, &ss);
|
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create style set");
|
|
|
|
|
|
|
|
// Get our scrolling preference
|
|
|
|
nsScrollPreference scrolling;
|
1998-08-28 08:56:56 +04:00
|
|
|
nsIView* rootView;
|
|
|
|
mViewManager->GetRootView(rootView);
|
1998-07-13 23:49:42 +04:00
|
|
|
nsIScrollableView* scrollView;
|
|
|
|
rv = rootView->QueryInterface(kScrollViewIID, (void**)&scrollView);
|
|
|
|
if (NS_OK == rv) {
|
1998-08-30 23:16:11 +04:00
|
|
|
scrollView->GetScrollPreference(scrolling);
|
1998-07-13 23:49:42 +04:00
|
|
|
}
|
1998-08-30 23:16:11 +04:00
|
|
|
nsIWidget* rootWidget;
|
|
|
|
rootView->GetWidget(rootWidget);
|
1998-07-13 23:49:42 +04:00
|
|
|
void* nativeParentWidget = rootWidget->GetNativeData(NS_NATIVE_WIDGET);
|
|
|
|
|
|
|
|
// Create a new view manager.
|
1998-09-01 04:26:28 +04:00
|
|
|
rv = nsRepository::CreateInstance(kViewManagerCID, nsnull, kIViewManagerIID,
|
1998-07-13 23:49:42 +04:00
|
|
|
(void**) &vm);
|
1998-08-28 06:54:06 +04:00
|
|
|
if ((NS_OK != rv) || (NS_OK != vm->Init(dc))) {
|
1998-07-13 23:49:42 +04:00
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create view manager");
|
|
|
|
}
|
|
|
|
|
1998-09-06 00:57:57 +04:00
|
|
|
NS_RELEASE(dc);
|
|
|
|
|
1998-08-28 06:54:06 +04:00
|
|
|
vm->SetViewObserver((nsIViewObserver *)this);
|
|
|
|
|
1998-07-13 23:49:42 +04:00
|
|
|
// Create a child window of the parent that is our "root view/window"
|
|
|
|
// Create a view
|
|
|
|
nsRect tbounds;
|
|
|
|
mPresContext->GetVisibleArea(tbounds);
|
|
|
|
// tbounds *= mPresContext->GetPixelsToTwips();
|
1998-09-01 04:26:28 +04:00
|
|
|
rv = nsRepository::CreateInstance(kScrollingViewCID, nsnull, kIViewIID,
|
1998-07-13 23:49:42 +04:00
|
|
|
(void **) &view);
|
1998-11-04 07:14:10 +03:00
|
|
|
if ((NS_OK != rv) || (NS_OK != view->Init(vm, tbounds, nsnull))) {
|
1998-07-13 23:49:42 +04:00
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create scroll view");
|
|
|
|
}
|
1998-11-04 07:14:10 +03:00
|
|
|
|
|
|
|
//now create the widget for the view
|
|
|
|
rv = view->CreateWidget(kWidgetCID, nsnull, nativeParentWidget);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create scroll view widget");
|
|
|
|
}
|
|
|
|
|
1998-07-13 23:49:42 +04:00
|
|
|
rv = view->QueryInterface(kScrollViewIID, (void**)&scrollView);
|
|
|
|
if (NS_OK == rv) {
|
1998-11-04 07:14:10 +03:00
|
|
|
scrollView->CreateScrollControls(nativeParentWidget);
|
1998-07-13 23:49:42 +04:00
|
|
|
scrollView->SetScrollPreference(scrolling);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(0, "invalid scrolling view");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup hierarchical relationship in view manager
|
|
|
|
vm->SetRootView(view);
|
|
|
|
|
|
|
|
// Make the new presentation context the same size as our
|
|
|
|
// presentation context.
|
|
|
|
nsRect r;
|
|
|
|
mPresContext->GetVisibleArea(r);
|
|
|
|
cx->SetVisibleArea(r);
|
|
|
|
|
|
|
|
// Create a new presentation shell to view the document
|
|
|
|
rv = mDocument->CreateShell(cx, vm, ss, &sh);
|
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create presentation shell");
|
|
|
|
sh->ResizeReflow(r.width, r.height);
|
|
|
|
|
|
|
|
// Now that the document has been reflowed, use its frame tree to
|
|
|
|
// compare against our frame tree.
|
|
|
|
CompareTrees(GetRootFrame(), sh->GetRootFrame());
|
|
|
|
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
|
|
|
|
NS_RELEASE(cx);
|
|
|
|
NS_RELEASE(sh);
|
|
|
|
|
|
|
|
NS_RELEASE(ss);
|
|
|
|
}
|
|
|
|
#endif
|