1998-04-13 20:24:54 +00: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"
|
1999-05-21 23:11:16 +00:00
|
|
|
#include "nsIPresContext.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
1998-06-03 15:46:54 +00:00
|
|
|
#include "nsIDocumentObserver.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIStyleSet.h"
|
1998-11-26 01:34:53 +00:00
|
|
|
#include "nsICSSStyleSheet.h" // XXX for UA sheet loading hack, can this go away please?
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIStyleContext.h"
|
1998-05-20 16:24:54 +00:00
|
|
|
#include "nsFrame.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "plhash.h"
|
1998-06-03 15:46:54 +00:00
|
|
|
#include "prlog.h"
|
1998-12-12 19:21:05 +00:00
|
|
|
#include "prthread.h"
|
|
|
|
#include "prinrval.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
#include "nsVoidArray.h"
|
1998-07-31 05:54:59 +00:00
|
|
|
#include "nsIPref.h"
|
1998-08-28 02:54:06 +00:00
|
|
|
#include "nsIViewObserver.h"
|
1998-09-19 03:24:26 +00:00
|
|
|
#include "nsContainerFrame.h"
|
1998-10-01 04:46:11 +00:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-10-02 01:12:39 +00:00
|
|
|
#include "nsIDeviceContext.h"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsDOMEvent.h"
|
1998-11-17 02:14:38 +00:00
|
|
|
#include "nsHTMLParts.h"
|
1999-02-11 23:12:28 +00:00
|
|
|
#include "nsIDOMSelection.h"
|
1998-12-08 18:26:06 +00:00
|
|
|
#include "nsLayoutCID.h"
|
1998-12-14 18:34:14 +00:00
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMElement.h"
|
1999-01-07 04:47:43 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
1999-01-22 18:58:14 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-02-05 18:25:29 +00:00
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
1999-02-12 00:02:56 +00:00
|
|
|
#include "nsICaret.h"
|
1999-02-12 05:39:33 +00:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
1999-03-20 01:51:00 +00:00
|
|
|
#include "nsIXMLDocument.h"
|
1999-02-12 05:39:33 +00:00
|
|
|
#include "nsIScrollableView.h"
|
1999-02-19 23:47:36 +00:00
|
|
|
#include "nsIDOMSelectionListener.h"
|
1999-03-01 19:21:01 +00:00
|
|
|
#include "nsIParser.h"
|
|
|
|
#include "nsParserCIID.h"
|
|
|
|
#include "nsHTMLContentSinkStream.h"
|
1999-03-15 05:11:43 +00:00
|
|
|
#include "nsHTMLToTXTSinkStream.h"
|
1999-03-01 19:21:01 +00:00
|
|
|
#include "nsXIFDTD.h"
|
1999-03-12 00:17:14 +00:00
|
|
|
#include "nsIFrameSelection.h"
|
1999-04-03 18:58:04 +00:00
|
|
|
#include "nsViewsCID.h"
|
1999-04-25 17:00:24 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
1999-07-16 03:32:09 +00:00
|
|
|
#include "nsDST.h"
|
1999-02-19 23:47:36 +00:00
|
|
|
|
1999-03-23 21:32:48 +00:00
|
|
|
// Drag & Drop, Clipboard
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIClipboard.h"
|
|
|
|
#include "nsITransferable.h"
|
1999-04-01 14:22:00 +00:00
|
|
|
#include "nsIFormatConverter.h"
|
1999-04-29 20:24:21 +00:00
|
|
|
#include "nsIWebShell.h"
|
1999-07-04 04:09:54 +00:00
|
|
|
#include "nsIBrowserWindow.h"
|
1999-03-23 21:32:48 +00:00
|
|
|
|
|
|
|
// Drag & Drop, Clipboard Support
|
1999-05-04 14:55:24 +00:00
|
|
|
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
1999-05-13 21:53:57 +00:00
|
|
|
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
1999-05-04 14:55:24 +00:00
|
|
|
static NS_DEFINE_IID(kCXIFConverterCID, NS_XIFFORMATCONVERTER_CID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-09-14 20:46:42 +00:00
|
|
|
static PRBool gsNoisyRefs = PR_FALSE;
|
1998-04-13 20:24:54 +00:00
|
|
|
#undef NOISY
|
|
|
|
|
1999-02-12 00:02:56 +00:00
|
|
|
// comment out to hide caret
|
1999-03-02 04:26:49 +00:00
|
|
|
#define SHOW_CARET
|
1999-02-12 00:02:56 +00:00
|
|
|
|
1998-05-09 03:22:41 +00:00
|
|
|
static PLHashNumber
|
1999-07-06 03:52:33 +00:00
|
|
|
HashKey(void* key)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-07-06 03:52:33 +00:00
|
|
|
return (PLHashNumber)key;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:41 +00:00
|
|
|
static PRIntn
|
1999-07-06 03:52:33 +00:00
|
|
|
CompareKeys(void* key1, void* key2)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
return key1 == key2;
|
|
|
|
}
|
|
|
|
|
|
|
|
class FrameHashTable {
|
|
|
|
public:
|
1999-07-06 03:52:33 +00:00
|
|
|
FrameHashTable(PRUint32 aNumBuckets = 16);
|
1998-04-13 20:24:54 +00:00
|
|
|
~FrameHashTable();
|
|
|
|
|
1999-07-06 03:52:33 +00:00
|
|
|
void* Get(void* aKey);
|
|
|
|
void* Put(void* aKey, void* aValue);
|
|
|
|
void* Remove(void* aKey);
|
|
|
|
void Clear(); // remove all entries
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void Dump(FILE* fp);
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PLHashTable* mTable;
|
|
|
|
};
|
|
|
|
|
1999-07-06 03:52:33 +00:00
|
|
|
FrameHashTable::FrameHashTable(PRUint32 aNumBuckets)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-07-06 03:52:33 +00:00
|
|
|
mTable = PL_NewHashTable(aNumBuckets, (PLHashFunction)HashKey,
|
|
|
|
(PLHashComparator)CompareKeys,
|
|
|
|
(PLHashComparator)nsnull,
|
1998-04-13 20:24:54 +00:00
|
|
|
nsnull, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameHashTable::~FrameHashTable()
|
|
|
|
{
|
|
|
|
PL_HashTableDestroy(mTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data associated with a frame.
|
|
|
|
*/
|
1998-05-09 03:22:41 +00:00
|
|
|
void*
|
1999-07-06 03:52:33 +00:00
|
|
|
FrameHashTable::Get(void* aKey)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
PRInt32 hashCode = (PRInt32) aKey;
|
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(mTable, hashCode, aKey);
|
|
|
|
PLHashEntry* he = *hep;
|
|
|
|
if (nsnull != he) {
|
|
|
|
return he->value;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-06 03:52:33 +00:00
|
|
|
* Create an association between a key and some data. This call
|
1998-04-13 20:24:54 +00:00
|
|
|
* returns an old association if there was one (or nsnull if there
|
|
|
|
* wasn't).
|
|
|
|
*/
|
1998-05-09 03:22:41 +00:00
|
|
|
void*
|
1999-07-06 03:52:33 +00:00
|
|
|
FrameHashTable::Put(void* aKey, void* aData)
|
1998-04-13 20:24:54 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-06 03:52:33 +00:00
|
|
|
* Remove an association between a key and it's data. This returns
|
1998-04-13 20:24:54 +00:00
|
|
|
* the old associated data.
|
|
|
|
*/
|
1998-05-09 03:22:41 +00:00
|
|
|
void*
|
1999-07-06 03:52:33 +00:00
|
|
|
FrameHashTable::Remove(void* aKey)
|
1998-04-13 20:24:54 +00: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;
|
|
|
|
}
|
|
|
|
|
1999-07-06 03:52:33 +00:00
|
|
|
static PRIntn
|
|
|
|
RemoveEntry(PLHashEntry* he, PRIntn i, void* arg)
|
|
|
|
{
|
|
|
|
// Remove and free this entry and continue enumerating
|
|
|
|
return HT_ENUMERATE_REMOVE | HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all the entries in the hash table
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
FrameHashTable::Clear()
|
|
|
|
{
|
|
|
|
PL_HashTableEnumerateEntries(mTable, RemoveEntry, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static PRIntn
|
|
|
|
EnumEntries(PLHashEntry* he, PRIntn i, void* arg)
|
|
|
|
{
|
|
|
|
// Continue enumerating
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameHashTable::Dump(FILE* fp)
|
|
|
|
{
|
|
|
|
PL_HashTableDump(mTable, EnumEntries, fp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-02-05 18:25:29 +00:00
|
|
|
// Class IID's
|
1999-02-13 04:45:44 +00:00
|
|
|
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
1999-07-18 02:27:19 +00:00
|
|
|
static NS_DEFINE_IID(kFrameSelectionCID, NS_FRAMESELECTION_CID);
|
1999-02-05 18:25:29 +00:00
|
|
|
static NS_DEFINE_IID(kCRangeCID, NS_RANGE_CID);
|
|
|
|
|
|
|
|
// IID's
|
1998-04-13 20:24:54 +00:00
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIPresShellIID, NS_IPRESSHELL_IID);
|
1998-06-03 15:46:54 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentObserverIID, NS_IDOCUMENT_OBSERVER_IID);
|
1998-08-28 02:54:06 +00:00
|
|
|
static NS_DEFINE_IID(kIViewObserverIID, NS_IVIEWOBSERVER_IID);
|
1999-02-11 23:12:28 +00:00
|
|
|
static NS_DEFINE_IID(kIFrameSelectionIID, NS_IFRAMESELECTION_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID);
|
1998-12-14 18:34:14 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMRangeIID, NS_IDOMRANGE_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIFocusTrackerIID, NS_IFOCUSTRACKER_IID);
|
1999-02-19 23:47:36 +00:00
|
|
|
static NS_DEFINE_IID(kIDomSelectionListenerIID, NS_IDOMSELECTIONLISTENER_IID);
|
1999-02-05 18:25:29 +00:00
|
|
|
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
1999-02-13 04:45:44 +00:00
|
|
|
static NS_DEFINE_IID(kICaretIID, NS_ICARET_IID);
|
1999-02-12 00:02:56 +00:00
|
|
|
static NS_DEFINE_IID(kICaretID, NS_ICARET_IID);
|
1999-02-12 05:39:33 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
|
1999-03-20 01:51:00 +00:00
|
|
|
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
|
1999-02-12 05:39:33 +00:00
|
|
|
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
1999-04-03 18:58:04 +00:00
|
|
|
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
|
1999-05-20 23:16:53 +00:00
|
|
|
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
struct CantRenderReplacedElementEvent;
|
|
|
|
|
1998-08-28 02:54:06 +00:00
|
|
|
class PresShell : public nsIPresShell, public nsIViewObserver,
|
1999-02-19 23:47:36 +00:00
|
|
|
private nsIDocumentObserver, public nsIFocusTracker,
|
|
|
|
public nsIDOMSelectionListener
|
1998-08-28 02:54:06 +00:00
|
|
|
{
|
1998-04-13 20:24:54 +00:00
|
|
|
public:
|
|
|
|
PresShell();
|
|
|
|
|
1999-02-26 20:02:06 +00:00
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
1999-02-26 17:08:48 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIPresShell
|
1998-06-03 15:46:54 +00:00
|
|
|
NS_IMETHOD Init(nsIDocument* aDocument,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIStyleSet* aStyleSet);
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHOD GetDocument(nsIDocument** aResult);
|
|
|
|
NS_IMETHOD GetPresContext(nsIPresContext** aResult);
|
|
|
|
NS_IMETHOD GetViewManager(nsIViewManager** aResult);
|
|
|
|
NS_IMETHOD GetStyleSet(nsIStyleSet** aResult);
|
1999-01-23 07:03:46 +00:00
|
|
|
NS_IMETHOD GetActiveAlternateStyleSheet(nsString& aSheetTitle);
|
|
|
|
NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle);
|
|
|
|
NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList);
|
1999-07-18 02:27:19 +00:00
|
|
|
NS_IMETHOD GetSelection(SelectionType aType, nsIDOMSelection** aSelection);
|
|
|
|
NS_IMETHOD GetFrameSelection(nsIFrameSelection** aSelection);
|
|
|
|
|
1998-05-09 03:22:41 +00:00
|
|
|
NS_IMETHOD EnterReflowLock();
|
|
|
|
NS_IMETHOD ExitReflowLock();
|
1998-12-29 04:56:31 +00:00
|
|
|
NS_IMETHOD BeginObservingDocument();
|
|
|
|
NS_IMETHOD EndObservingDocument();
|
1998-09-10 19:32:14 +00:00
|
|
|
NS_IMETHOD InitialReflow(nscoord aWidth, nscoord aHeight);
|
1998-08-28 02:54:06 +00:00
|
|
|
NS_IMETHOD ResizeReflow(nscoord aWidth, nscoord aHeight);
|
1998-11-06 16:16:01 +00:00
|
|
|
NS_IMETHOD StyleChangeReflow();
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHOD GetRootFrame(nsIFrame** aFrame) const;
|
|
|
|
NS_IMETHOD GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const;
|
|
|
|
NS_IMETHOD GetPrimaryFrameFor(nsIContent* aContent,
|
|
|
|
nsIFrame** aPrimaryFrame) const;
|
1999-06-30 04:42:26 +00:00
|
|
|
NS_IMETHOD SetPrimaryFrameFor(nsIContent* aContent,
|
|
|
|
nsIFrame* aPrimaryFrame);
|
|
|
|
NS_IMETHOD ClearPrimaryFrameMap();
|
1999-02-25 19:55:06 +00:00
|
|
|
NS_IMETHOD GetStyleContextFor(nsIFrame* aFrame,
|
|
|
|
nsIStyleContext** aStyleContext) const;
|
1999-02-10 23:21:22 +00:00
|
|
|
NS_IMETHOD GetLayoutObjectFor(nsIContent* aContent,
|
|
|
|
nsISupports** aResult) const;
|
1998-12-29 03:38:16 +00:00
|
|
|
NS_IMETHOD GetPlaceholderFrameFor(nsIFrame* aFrame,
|
1999-02-12 17:45:58 +00:00
|
|
|
nsIFrame** aPlaceholderFrame) const;
|
1998-12-29 03:38:16 +00:00
|
|
|
NS_IMETHOD SetPlaceholderFrameFor(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aPlaceholderFrame);
|
1999-06-30 04:42:26 +00:00
|
|
|
NS_IMETHOD ClearPlaceholderFrameMap();
|
1998-12-29 04:56:31 +00:00
|
|
|
NS_IMETHOD AppendReflowCommand(nsIReflowCommand* aReflowCommand);
|
1999-04-23 20:01:20 +00:00
|
|
|
NS_IMETHOD CancelReflowCommand(nsIFrame* aTargetFrame);
|
1998-12-29 04:56:31 +00:00
|
|
|
NS_IMETHOD ProcessReflowCommands();
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame);
|
|
|
|
NS_IMETHOD CreateRenderingContext(nsIFrame *aFrame,
|
|
|
|
nsIRenderingContext** aContext);
|
1999-02-05 18:25:29 +00:00
|
|
|
NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame);
|
1999-02-12 05:39:33 +00:00
|
|
|
NS_IMETHOD GoToAnchor(const nsString& aAnchorName) const;
|
1998-08-28 02:54:06 +00:00
|
|
|
|
1999-02-18 22:52:21 +00:00
|
|
|
NS_IMETHOD ScrollFrameIntoView(nsIFrame *aFrame,
|
1999-07-19 18:38:33 +00:00
|
|
|
PRIntn aVPercent,
|
|
|
|
PRIntn aHPercent) const;
|
1999-04-07 03:56:07 +00:00
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
NS_IMETHOD NotifyDestroyingFrame(nsIFrame* aFrame);
|
|
|
|
|
1999-04-07 03:56:07 +00:00
|
|
|
NS_IMETHOD DoCopy();
|
1999-06-10 21:08:17 +00:00
|
|
|
|
1998-08-28 02:54:06 +00: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-12-14 18:34:14 +00:00
|
|
|
//nsIFocusTracker interface
|
1999-02-21 03:49:32 +00:00
|
|
|
NS_IMETHOD ScrollFrameIntoView(nsIFrame *aFrame);
|
1999-02-13 04:45:44 +00:00
|
|
|
// caret handling
|
|
|
|
NS_IMETHOD GetCaret(nsICaret **outCaret);
|
1999-04-01 23:58:11 +00:00
|
|
|
NS_IMETHOD SetCaretEnabled(PRBool inEnable);
|
1999-02-13 04:45:44 +00:00
|
|
|
|
1999-05-17 00:21:18 +00:00
|
|
|
NS_IMETHOD SetDisplayNonTextSelection(PRBool inEnable);
|
|
|
|
NS_IMETHOD GetDisplayNonTextSelection(PRBool *inEnable);
|
|
|
|
|
1999-02-19 23:47:36 +00:00
|
|
|
// nsIDOMSelectionListener interface
|
|
|
|
NS_IMETHOD NotifySelectionChanged();
|
1999-02-13 04:45:44 +00:00
|
|
|
|
1999-07-14 17:30:07 +00:00
|
|
|
// nsIDocumentObserver
|
|
|
|
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,
|
|
|
|
nsISupports* aSubContent);
|
|
|
|
NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2);
|
|
|
|
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint);
|
|
|
|
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer);
|
|
|
|
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet);
|
|
|
|
NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet);
|
|
|
|
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDisabled);
|
|
|
|
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint);
|
|
|
|
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
|
|
|
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
|
|
|
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
|
|
|
|
|
1999-02-05 18:25:29 +00:00
|
|
|
// implementation
|
1999-07-16 23:27:46 +00:00
|
|
|
void HandleCantRenderReplacedElementEvent(CantRenderReplacedElementEvent* aEvent);
|
1999-02-05 18:25:29 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
protected:
|
1999-02-12 17:45:58 +00:00
|
|
|
virtual ~PresShell();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
nsresult ReconstructFrames(void);
|
|
|
|
|
1999-02-13 04:45:44 +00:00
|
|
|
// turn the caret on and off.
|
1999-04-01 23:58:11 +00:00
|
|
|
nsresult RefreshCaret(nsIView *aView,
|
|
|
|
nsIRenderingContext& aRendContext,
|
|
|
|
const nsRect& aDirtyRect);
|
|
|
|
nsresult SuspendCaret();
|
|
|
|
nsresult ResumeCaret();
|
|
|
|
|
|
|
|
PRBool mCaretEnabled;
|
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
#ifdef NS_DEBUG
|
1999-04-03 18:58:04 +00:00
|
|
|
nsresult CloneStyleSet(nsIStyleSet* aSet, nsIStyleSet** aResult);
|
1998-07-13 19:49:42 +00:00
|
|
|
void VerifyIncrementalReflow();
|
1998-11-26 18:11:02 +00:00
|
|
|
PRBool mInVerifyReflow;
|
1998-07-13 19:49:42 +00:00
|
|
|
#endif
|
1998-05-20 16:24:54 +00:00
|
|
|
|
1999-04-30 09:04:36 +00:00
|
|
|
// IMPORTANT: The ownership implicit in the following member variables has been
|
|
|
|
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
|
|
|
|
// pointers for weak (ie, non owning) references. If you add any members to this
|
|
|
|
// class, please make the ownership explicit (pinkerton, scc).
|
1999-05-04 23:27:42 +00:00
|
|
|
|
|
|
|
// these are the same Document and PresContext owned by the DocViewer.
|
|
|
|
// we must share ownership.
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
|
|
|
nsCOMPtr<nsIPresContext> mPresContext;
|
1999-04-30 09:04:36 +00:00
|
|
|
nsCOMPtr<nsIStyleSet> mStyleSet;
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIFrame* mRootFrame;
|
1999-04-30 09:04:36 +00:00
|
|
|
nsIViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to
|
1998-04-13 20:24:54 +00:00
|
|
|
PRUint32 mUpdateCount;
|
|
|
|
nsVoidArray mReflowCommands;
|
1998-05-09 03:22:41 +00:00
|
|
|
PRUint32 mReflowLockCount;
|
1998-11-18 05:25:26 +00:00
|
|
|
PRBool mIsDestroying;
|
1998-11-21 00:19:36 +00:00
|
|
|
nsIFrame* mCurrentEventFrame;
|
1999-06-15 03:14:28 +00:00
|
|
|
nsIContent* mCurrentEventContent;
|
1999-02-12 00:02:56 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFrameSelection> mSelection;
|
|
|
|
nsCOMPtr<nsICaret> mCaret;
|
1999-05-17 00:21:18 +00:00
|
|
|
PRBool mDisplayNonTextSelection;
|
1999-02-21 19:43:40 +00:00
|
|
|
PRBool mScrollingEnabled; //used to disable programmable scrolling from outside
|
1999-07-16 03:32:09 +00:00
|
|
|
nsDST* mPrimaryFrameMap;
|
1999-02-12 00:02:56 +00:00
|
|
|
FrameHashTable* mPlaceholderMap;
|
1999-07-16 23:27:46 +00:00
|
|
|
CantRenderReplacedElementEvent* mPostedEvents;
|
|
|
|
|
1999-02-21 19:43:40 +00:00
|
|
|
private:
|
1999-07-16 23:27:46 +00:00
|
|
|
void RevokePostedEvents();
|
|
|
|
CantRenderReplacedElementEvent** FindPostedEventFor(nsIFrame* aFrame);
|
|
|
|
void DequeuePostedEventFor(nsIFrame* aFrame);
|
|
|
|
|
1999-02-21 19:43:40 +00:00
|
|
|
//helper funcs for disabing autoscrolling
|
|
|
|
void DisableScrolling(){mScrollingEnabled = PR_FALSE;}
|
|
|
|
void EnableScrolling(){mScrollingEnabled = PR_TRUE;}
|
|
|
|
PRBool IsScrollingEnabled(){return mScrollingEnabled;}
|
1999-06-15 03:14:28 +00:00
|
|
|
nsIFrame* GetCurrentEventFrame();
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
/**
|
|
|
|
* Note: the log module is created during library initialization which
|
|
|
|
* means that you cannot perform logging before then.
|
|
|
|
*/
|
1999-02-26 17:08:48 +00:00
|
|
|
static PRLogModuleInfo* gLogModule;
|
1998-07-13 19:49:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static PRBool gVerifyReflow = PRBool(0x55);
|
1999-04-27 22:14:17 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-11-25 18:41:02 +00:00
|
|
|
static PRBool gVerifyReflowAll;
|
1999-04-27 22:14:17 +00:00
|
|
|
#endif
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
NS_LAYOUT PRBool
|
|
|
|
nsIPresShell::GetVerifyReflowEnable()
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (gVerifyReflow == PRBool(0x55)) {
|
1999-02-26 17:08:48 +00:00
|
|
|
gLogModule = PR_NewLogModule("verifyreflow");
|
1998-07-13 19:49:42 +00:00
|
|
|
gVerifyReflow = 0 != gLogModule->level;
|
1998-11-25 18:41:02 +00:00
|
|
|
if (gLogModule->level > 1) {
|
|
|
|
gVerifyReflowAll = PR_TRUE;
|
|
|
|
}
|
|
|
|
printf("Note: verifyreflow is %sabled",
|
1998-07-13 19:49:42 +00:00
|
|
|
gVerifyReflow ? "en" : "dis");
|
1998-11-25 18:41:02 +00:00
|
|
|
if (gVerifyReflowAll) {
|
|
|
|
printf(" (diff all enabled)\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("\n");
|
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return gVerifyReflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_LAYOUT void
|
|
|
|
nsIPresShell::SetVerifyReflowEnable(PRBool aEnabled)
|
|
|
|
{
|
|
|
|
gVerifyReflow = aEnabled;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-07-13 19:49:42 +00: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-13 20:24:54 +00:00
|
|
|
PresShell::PresShell()
|
|
|
|
{
|
1998-11-18 05:25:26 +00:00
|
|
|
//XXX joki 11/17 - temporary event hack.
|
|
|
|
mIsDestroying = PR_FALSE;
|
1999-04-01 23:58:11 +00:00
|
|
|
mCaretEnabled = PR_FALSE;
|
1999-05-17 00:21:18 +00:00
|
|
|
mDisplayNonTextSelection = PR_FALSE;
|
1999-06-15 03:14:28 +00:00
|
|
|
mCurrentEventContent = nsnull;
|
1999-02-21 19:43:40 +00:00
|
|
|
EnableScrolling();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-09-14 20:46:42 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// for debugging only
|
|
|
|
nsrefcnt PresShell::AddRef(void)
|
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
if (gsNoisyRefs) {
|
|
|
|
printf("PresShell: AddRef: %p, cnt = %d \n",this, mRefCnt+1);
|
|
|
|
}
|
1998-09-14 20:46:42 +00:00
|
|
|
return ++mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for debugging only
|
|
|
|
nsrefcnt PresShell::Release(void)
|
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
if (gsNoisyRefs) {
|
|
|
|
printf("PresShell Release: %p, cnt = %d \n",this, mRefCnt-1);
|
|
|
|
}
|
1998-09-14 20:46:42 +00:00
|
|
|
if (--mRefCnt == 0) {
|
1999-02-12 17:45:58 +00:00
|
|
|
if (gsNoisyRefs) {
|
|
|
|
printf("PresShell Delete: %p, \n",this);
|
|
|
|
}
|
1998-09-14 20:46:42 +00:00
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
#else
|
1998-09-12 19:33:48 +00:00
|
|
|
NS_IMPL_ADDREF(PresShell)
|
|
|
|
NS_IMPL_RELEASE(PresShell)
|
1998-09-14 20:46:42 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-05-09 03:22:41 +00:00
|
|
|
nsresult
|
|
|
|
PresShell::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
if (aIID.Equals(kIPresShellIID)) {
|
1998-09-12 19:33:48 +00:00
|
|
|
nsIPresShell* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDocumentObserverIID)) {
|
1998-09-12 19:33:48 +00:00
|
|
|
nsIDocumentObserver* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-08-28 02:54:06 +00:00
|
|
|
if (aIID.Equals(kIViewObserverIID)) {
|
1998-09-12 19:33:48 +00:00
|
|
|
nsIViewObserver* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
1998-08-28 02:54:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-14 18:34:14 +00:00
|
|
|
if (aIID.Equals(kIFocusTrackerIID)) {
|
|
|
|
nsIFocusTracker* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-19 23:47:36 +00:00
|
|
|
if (aIID.Equals(kIDomSelectionListenerIID)) {
|
|
|
|
nsIDOMSelectionListener* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
1998-09-12 19:33:48 +00:00
|
|
|
nsIPresShell* tmp = this;
|
|
|
|
nsISupports* tmp2 = tmp;
|
|
|
|
*aInstancePtr = (void*) tmp2;
|
|
|
|
NS_ADDREF_THIS();
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PresShell::~PresShell()
|
|
|
|
{
|
1998-08-06 19:52:48 +00:00
|
|
|
mRefCnt = 99;/* XXX hack! get around re-entrancy bugs */
|
1999-04-30 00:08:17 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
mIsDestroying = PR_TRUE;
|
1999-06-15 03:14:28 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentEventContent);
|
1999-04-30 00:08:17 +00:00
|
|
|
if (mViewManager) {
|
|
|
|
// Disable paints during tear down of the frame tree
|
|
|
|
mViewManager->DisableRefresh();
|
|
|
|
}
|
1999-07-16 23:27:46 +00:00
|
|
|
// Revoke any events posted to the event queue that we haven't processed yet
|
|
|
|
RevokePostedEvents();
|
1999-04-30 09:04:36 +00:00
|
|
|
if (mRootFrame)
|
1998-08-28 02:54:06 +00:00
|
|
|
mRootFrame->DeleteFrame(*mPresContext);
|
1999-04-30 09:04:36 +00:00
|
|
|
if (mDocument)
|
1998-09-23 17:16:51 +00:00
|
|
|
mDocument->DeleteShell(this);
|
1998-08-06 19:52:48 +00:00
|
|
|
mRefCnt = 0;
|
1999-07-16 03:32:09 +00:00
|
|
|
#ifdef DEBUG_troy
|
|
|
|
if (mPrimaryFrameMap) {
|
|
|
|
mPrimaryFrameMap->Dump(stdout);
|
|
|
|
}
|
|
|
|
#endif
|
1999-07-06 03:52:33 +00:00
|
|
|
delete mPrimaryFrameMap;
|
1998-12-29 03:38:16 +00:00
|
|
|
delete mPlaceholderMap;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the presentation shell. Create view manager and style
|
|
|
|
* manager.
|
|
|
|
*/
|
1998-05-09 03:22:41 +00:00
|
|
|
nsresult
|
|
|
|
PresShell::Init(nsIDocument* aDocument,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIStyleSet* aStyleSet)
|
1998-04-13 20:24:54 +00: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;
|
|
|
|
}
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mDocument) {
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
1999-05-04 23:27:42 +00:00
|
|
|
mDocument = dont_QueryInterface(aDocument);
|
1998-04-13 20:24:54 +00:00
|
|
|
mViewManager = aViewManager;
|
|
|
|
|
1998-08-28 02:54:06 +00:00
|
|
|
//doesn't add a ref since we own it... MMP
|
|
|
|
mViewManager->SetViewObserver((nsIViewObserver *)this);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// Bind the context to the presentation shell.
|
1999-05-04 23:27:42 +00:00
|
|
|
mPresContext = dont_QueryInterface(aPresContext);
|
1998-04-13 20:24:54 +00:00
|
|
|
aPresContext->SetShell(this);
|
|
|
|
|
1999-04-30 09:04:36 +00:00
|
|
|
mStyleSet = dont_QueryInterface(aStyleSet);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-18 02:27:19 +00:00
|
|
|
nsresult result = nsComponentManager::CreateInstance(kFrameSelectionCID, nsnull,
|
|
|
|
nsIFrameSelection::GetIID(),
|
|
|
|
getter_AddRefs(mSelection));
|
1998-12-14 18:34:14 +00:00
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
1999-04-26 04:02:04 +00:00
|
|
|
|
1999-07-18 02:27:19 +00:00
|
|
|
nsCOMPtr<nsIDOMSelection> domSelection;
|
|
|
|
mSelection->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection));
|
|
|
|
domSelection->AddSelectionListener(this);//possible circular reference
|
1999-02-13 04:45:44 +00:00
|
|
|
|
1999-04-26 04:02:04 +00:00
|
|
|
result = mSelection->Init((nsIFocusTracker *) this);
|
|
|
|
if (!NS_SUCCEEDED(result))
|
|
|
|
return result;
|
1999-02-12 00:02:56 +00:00
|
|
|
// Important: this has to happen after the selection has been set up
|
|
|
|
#ifdef SHOW_CARET
|
|
|
|
// make the caret
|
|
|
|
nsresult err = NS_NewCaret(getter_AddRefs(mCaret));
|
|
|
|
if (NS_SUCCEEDED(err))
|
1999-04-01 23:58:11 +00:00
|
|
|
{
|
1999-07-14 22:18:29 +00:00
|
|
|
mCaret->Init(this);
|
1999-04-01 23:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//SetCaretEnabled(PR_TRUE); // make it show in browser windows
|
1999-02-12 00:02:56 +00:00
|
|
|
#endif
|
1999-04-29 20:24:21 +00:00
|
|
|
//set up selection to be displayed in document
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
result = aPresContext->GetContainer(getter_AddRefs(container));
|
|
|
|
if (NS_SUCCEEDED(result) && container) {
|
|
|
|
nsCOMPtr<nsIWebShell> webShell;
|
|
|
|
webShell = do_QueryInterface(container,&result);
|
|
|
|
if (NS_SUCCEEDED(result) && webShell){
|
|
|
|
nsWebShellType webShellType;
|
|
|
|
result = webShell->GetWebShellType(webShellType);
|
|
|
|
if (NS_SUCCEEDED(result)){
|
|
|
|
if (nsWebShellContent == webShellType){
|
|
|
|
mDocument->SetDisplaySelection(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-12 00:02:56 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
void
|
|
|
|
PresShell::RevokePostedEvents()
|
|
|
|
{
|
|
|
|
if (mPostedEvents) {
|
|
|
|
mPostedEvents = nsnull;
|
|
|
|
|
|
|
|
// Revoke any events in the event queue that are owned by us
|
|
|
|
nsIEventQueueService* eventService;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
|
|
|
kIEventQueueServiceIID,
|
|
|
|
(nsISupports **)&eventService);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIEventQueue> eventQueue;
|
|
|
|
rv = eventService->GetThreadEventQueue(PR_GetCurrentThread(),
|
|
|
|
getter_AddRefs(eventQueue));
|
|
|
|
nsServiceManager::ReleaseService(kEventQueueServiceCID, eventService);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && eventQueue) {
|
|
|
|
eventQueue->RevokeEvents(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
1998-05-09 03:22:41 +00:00
|
|
|
PresShell::EnterReflowLock()
|
|
|
|
{
|
|
|
|
++mReflowLockCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
1998-05-09 03:22:41 +00:00
|
|
|
PresShell::ExitReflowLock()
|
|
|
|
{
|
1998-05-12 01:30:40 +00:00
|
|
|
PRUint32 newReflowLockCount = mReflowLockCount - 1;
|
|
|
|
if (newReflowLockCount == 0) {
|
|
|
|
ProcessReflowCommands();
|
1998-05-09 03:22:41 +00:00
|
|
|
}
|
1998-05-12 01:30:40 +00:00
|
|
|
mReflowLockCount = newReflowLockCount;
|
1998-05-09 03:22:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetDocument(nsIDocument** aResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mDocument;
|
1999-05-04 23:27:42 +00:00
|
|
|
NS_IF_ADDREF(*aResult);
|
1999-02-12 17:45:58 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetPresContext(nsIPresContext** aResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mPresContext;
|
1999-05-04 23:27:42 +00:00
|
|
|
NS_IF_ADDREF(*aResult);
|
1999-02-12 17:45:58 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetViewManager(nsIViewManager** aResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mViewManager;
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_IF_ADDREF(mViewManager);
|
1999-02-12 17:45:58 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetStyleSet(nsIStyleSet** aResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mStyleSet;
|
1999-04-30 09:04:36 +00:00
|
|
|
NS_IF_ADDREF(*aResult);
|
1999-02-12 17:45:58 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-01-23 07:03:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetActiveAlternateStyleSheet(nsString& aSheetTitle)
|
|
|
|
{ // first non-html sheet in style set that has title
|
1999-04-30 09:04:36 +00:00
|
|
|
if (mStyleSet) {
|
1999-01-23 07:03:46 +00:00
|
|
|
PRInt32 count = mStyleSet->GetNumberOfDocStyleSheets();
|
|
|
|
PRInt32 index;
|
|
|
|
nsAutoString textHtml("text/html");
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIStyleSheet* sheet = mStyleSet->GetDocStyleSheetAt(index);
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
nsAutoString type;
|
|
|
|
sheet->GetType(type);
|
|
|
|
if (PR_FALSE == type.Equals(textHtml)) {
|
|
|
|
nsAutoString title;
|
|
|
|
sheet->GetTitle(title);
|
|
|
|
if (0 < title.Length()) {
|
|
|
|
aSheetTitle = title;
|
|
|
|
index = count; // stop looking
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::SelectAlternateStyleSheet(const nsString& aSheetTitle)
|
|
|
|
{
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mDocument && mStyleSet) {
|
1999-01-23 07:03:46 +00:00
|
|
|
PRInt32 count = mDocument->GetNumberOfStyleSheets();
|
|
|
|
PRInt32 index;
|
|
|
|
nsAutoString textHtml("text/html");
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIStyleSheet* sheet = mDocument->GetStyleSheetAt(index);
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
nsAutoString type;
|
|
|
|
sheet->GetType(type);
|
|
|
|
if (PR_FALSE == type.Equals(textHtml)) {
|
|
|
|
nsAutoString title;
|
|
|
|
sheet->GetTitle(title);
|
|
|
|
if (0 < title.Length()) {
|
|
|
|
if (title.EqualsIgnoreCase(aSheetTitle)) {
|
|
|
|
mStyleSet->AddDocStyleSheet(sheet, mDocument);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mStyleSet->RemoveDocStyleSheet(sheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReconstructFrames();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ListAlternateStyleSheets(nsStringArray& aTitleList)
|
|
|
|
{
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mDocument) {
|
1999-01-23 07:03:46 +00:00
|
|
|
PRInt32 count = mDocument->GetNumberOfStyleSheets();
|
|
|
|
PRInt32 index;
|
|
|
|
nsAutoString textHtml("text/html");
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIStyleSheet* sheet = mDocument->GetStyleSheetAt(index);
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
nsAutoString type;
|
|
|
|
sheet->GetType(type);
|
|
|
|
if (PR_FALSE == type.Equals(textHtml)) {
|
|
|
|
nsAutoString title;
|
|
|
|
sheet->GetTitle(title);
|
|
|
|
if (0 < title.Length()) {
|
|
|
|
if (-1 == aTitleList.IndexOfIgnoreCase(title)) {
|
|
|
|
aTitleList.AppendString(title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-08 18:26:06 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-18 02:27:19 +00:00
|
|
|
PresShell::GetSelection(SelectionType aType, nsIDOMSelection **aSelection)
|
1998-12-08 18:26:06 +00:00
|
|
|
{
|
|
|
|
if (!aSelection || !mSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-07-18 02:27:19 +00:00
|
|
|
return mSelection->GetSelection(aType, aSelection);
|
1998-12-08 18:26:06 +00:00
|
|
|
}
|
|
|
|
|
1999-07-18 02:27:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetFrameSelection(nsIFrameSelection** aSelection)
|
|
|
|
{
|
|
|
|
if (!aSelection || !mSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*aSelection = mSelection;
|
|
|
|
(*aSelection)->AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-08 18:26:06 +00:00
|
|
|
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// Make shell be a document observer
|
1998-12-29 04:56:31 +00:00
|
|
|
NS_IMETHODIMP
|
1998-05-09 03:22:41 +00:00
|
|
|
PresShell::BeginObservingDocument()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mDocument) {
|
1998-04-13 20:24:54 +00:00
|
|
|
mDocument->AddObserver(this);
|
|
|
|
}
|
1998-12-29 04:56:31 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make shell stop being a document observer
|
1998-12-29 04:56:31 +00:00
|
|
|
NS_IMETHODIMP
|
1998-05-09 03:22:41 +00:00
|
|
|
PresShell::EndObservingDocument()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mDocument) {
|
1998-04-13 20:24:54 +00:00
|
|
|
mDocument->RemoveObserver(this);
|
|
|
|
}
|
1999-02-19 23:47:36 +00:00
|
|
|
if (mSelection){
|
|
|
|
nsCOMPtr<nsIDOMSelection> domselection;
|
|
|
|
nsresult result;
|
1999-07-19 18:04:35 +00:00
|
|
|
result = mSelection->GetSelection(SELECTION_NORMAL, getter_AddRefs(domselection));
|
1999-02-19 23:47:36 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!domselection)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
domselection->RemoveSelectionListener(this);
|
1999-04-26 04:02:04 +00:00
|
|
|
mSelection->ShutDown();
|
1999-02-19 23:47:36 +00:00
|
|
|
}
|
1998-12-29 04:56:31 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 02:54:06 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-10 19:32:14 +00:00
|
|
|
PresShell::InitialReflow(nscoord aWidth, nscoord aHeight)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-02-03 19:38:16 +00:00
|
|
|
nsIContent* root = nsnull;
|
1998-09-10 19:32:14 +00:00
|
|
|
|
1999-04-01 23:58:11 +00:00
|
|
|
SuspendCaret();
|
1998-06-03 15:46:54 +00:00
|
|
|
EnterReflowLock();
|
|
|
|
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mPresContext) {
|
1998-04-13 20:24:54 +00:00
|
|
|
nsRect r(0, 0, aWidth, aHeight);
|
|
|
|
mPresContext->SetVisibleArea(r);
|
|
|
|
}
|
|
|
|
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mDocument) {
|
1999-02-03 19:38:16 +00:00
|
|
|
root = mDocument->GetRootContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != root) {
|
|
|
|
if (nsnull == mRootFrame) {
|
|
|
|
// Have style sheet processor construct a frame for the
|
|
|
|
// precursors to the root content object's frame
|
|
|
|
mStyleSet->ConstructRootFrame(mPresContext, root, mRootFrame);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-02-03 19:38:16 +00:00
|
|
|
|
|
|
|
// Have the style sheet processor construct frame for the root
|
|
|
|
// content object down
|
|
|
|
mStyleSet->ContentInserted(mPresContext, nsnull, root, 0);
|
|
|
|
NS_RELEASE(root);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-09-10 19:32:14 +00: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 01:12:39 +00:00
|
|
|
nsRect bounds;
|
1998-09-10 19:32:14 +00:00
|
|
|
mPresContext->GetVisibleArea(bounds);
|
1998-10-02 01:12:39 +00:00
|
|
|
nsSize maxSize(bounds.width, bounds.height);
|
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsReflowStatus status;
|
|
|
|
nsIHTMLReflow* htmlReflow;
|
|
|
|
nsIRenderingContext* rcx = nsnull;
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
CreateRenderingContext(mRootFrame, &rcx);
|
1998-10-02 01:12:39 +00:00
|
|
|
|
1998-10-12 14:48:02 +00:00
|
|
|
nsHTMLReflowState reflowState(*mPresContext, mRootFrame,
|
1999-03-05 04:29:11 +00:00
|
|
|
eReflowReason_Initial, rcx, maxSize);
|
1998-10-01 04:46:11 +00:00
|
|
|
|
|
|
|
if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
|
|
|
htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status);
|
|
|
|
mRootFrame->SizeTo(desiredSize.width, desiredSize.height);
|
1999-07-07 22:34:31 +00:00
|
|
|
mPresContext->SetVisibleArea(nsRect(0,0,desiredSize.width,desiredSize.height));
|
|
|
|
|
1998-09-10 19:32:14 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-10-01 04:46:11 +00:00
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
1998-09-10 19:32:14 +00:00
|
|
|
#endif
|
1998-10-01 04:46:11 +00:00
|
|
|
}
|
1998-10-02 01:12:39 +00:00
|
|
|
NS_IF_RELEASE(rcx);
|
1998-09-10 19:32:14 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("exit nsPresShell::InitialReflow"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitReflowLock();
|
1999-04-01 23:58:11 +00:00
|
|
|
ResumeCaret();
|
1998-09-10 19:32:14 +00:00
|
|
|
|
|
|
|
return NS_OK; //XXX this needs to be real. MMP
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
1999-04-01 23:58:11 +00:00
|
|
|
SuspendCaret();
|
1998-09-10 19:32:14 +00:00
|
|
|
EnterReflowLock();
|
|
|
|
|
1999-05-04 23:27:42 +00:00
|
|
|
if (mPresContext) {
|
1998-09-10 19:32:14 +00:00
|
|
|
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-13 20:24:54 +00:00
|
|
|
if (nsnull != mRootFrame) {
|
|
|
|
// Kick off a top-down reflow
|
1998-05-20 16:24:54 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsPresShell::ResizeReflow: %d,%d", aWidth, aHeight));
|
1998-04-13 20:24:54 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-05-20 16:24:54 +00:00
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
#endif
|
1998-10-02 01:12:39 +00:00
|
|
|
nsRect bounds;
|
1998-05-22 18:36:40 +00:00
|
|
|
mPresContext->GetVisibleArea(bounds);
|
1998-10-02 01:12:39 +00:00
|
|
|
nsSize maxSize(bounds.width, bounds.height);
|
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsReflowStatus status;
|
|
|
|
nsIHTMLReflow* htmlReflow;
|
|
|
|
nsIRenderingContext* rcx = nsnull;
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
CreateRenderingContext(mRootFrame, &rcx);
|
1998-10-02 01:12:39 +00:00
|
|
|
|
1998-10-12 14:48:02 +00:00
|
|
|
nsHTMLReflowState reflowState(*mPresContext, mRootFrame,
|
1999-03-05 04:29:11 +00:00
|
|
|
eReflowReason_Resize, rcx, maxSize);
|
1998-10-01 04:46:11 +00:00
|
|
|
|
|
|
|
if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
|
|
|
htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status);
|
|
|
|
mRootFrame->SizeTo(desiredSize.width, desiredSize.height);
|
1998-04-13 20:24:54 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-10-01 04:46:11 +00:00
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
#endif
|
1998-10-01 04:46:11 +00:00
|
|
|
}
|
1998-10-02 01:12:39 +00:00
|
|
|
NS_IF_RELEASE(rcx);
|
1998-05-20 16:24:54 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("exit nsPresShell::ResizeReflow"));
|
|
|
|
|
1998-04-13 20:24:54 +00: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 15:46:54 +00:00
|
|
|
ExitReflowLock();
|
1999-04-01 23:58:11 +00:00
|
|
|
ResumeCaret();
|
1999-02-13 04:45:44 +00:00
|
|
|
|
1998-08-28 02:54:06 +00:00
|
|
|
return NS_OK; //XXX this needs to be real. MMP
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ScrollFrameIntoView(nsIFrame *aFrame){
|
1999-02-21 03:49:32 +00:00
|
|
|
if (!aFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-21 19:43:40 +00:00
|
|
|
if (IsScrollingEnabled())
|
1999-07-19 18:38:33 +00:00
|
|
|
return ScrollFrameIntoView(aFrame, NS_PRESSHELL_SCROLL_ANYWHERE,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
1999-02-21 19:43:40 +00:00
|
|
|
return NS_OK;
|
1999-02-21 03:49:32 +00:00
|
|
|
}
|
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::NotifyDestroyingFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// Cancel any pending reflow commands targeted at this frame
|
|
|
|
CancelReflowCommand(aFrame);
|
|
|
|
|
|
|
|
// Dequeue and destroy and posted events for this frame
|
|
|
|
DequeuePostedEventFor(aFrame);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-13 04:45:44 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP PresShell::GetCaret(nsICaret **outCaret)
|
|
|
|
{
|
|
|
|
if (!outCaret || !mCaret)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
return mCaret->QueryInterface(kICaretIID,(void **)outCaret);
|
|
|
|
}
|
|
|
|
|
1999-04-02 01:14:30 +00:00
|
|
|
nsresult PresShell::RefreshCaret(nsIView *aView, nsIRenderingContext& aRendContext, const nsRect& aDirtyRect)
|
1999-02-13 04:45:44 +00:00
|
|
|
{
|
|
|
|
if (mCaret)
|
1999-04-01 23:58:11 +00:00
|
|
|
mCaret->Refresh(aView, aRendContext, aDirtyRect);
|
1999-02-13 04:45:44 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-01 23:58:11 +00:00
|
|
|
NS_IMETHODIMP PresShell::SetCaretEnabled(PRBool inEnable)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
PRBool oldEnabled = mCaretEnabled;
|
|
|
|
|
|
|
|
mCaretEnabled = inEnable;
|
|
|
|
|
|
|
|
if (mCaret && (mCaretEnabled != oldEnabled))
|
|
|
|
{
|
|
|
|
if (mCaretEnabled)
|
|
|
|
result = mCaret->SetCaretVisible(PR_TRUE);
|
|
|
|
else
|
|
|
|
result = mCaret->SetCaretVisible(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-17 00:21:18 +00:00
|
|
|
NS_IMETHODIMP PresShell::SetDisplayNonTextSelection(PRBool inEnable)
|
|
|
|
{
|
|
|
|
mDisplayNonTextSelection = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP PresShell::GetDisplayNonTextSelection(PRBool *inEnable)
|
|
|
|
{
|
|
|
|
if (!inEnable)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*inEnable = mDisplayNonTextSelection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-01 23:58:11 +00:00
|
|
|
|
1999-02-19 23:47:36 +00:00
|
|
|
/*implementation of the nsIDOMSelectionListener
|
|
|
|
it will invoke the resetselection to update the presentation shell's frames
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP PresShell::NotifySelectionChanged()
|
|
|
|
{
|
|
|
|
if (!mSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-04-01 23:58:11 +00:00
|
|
|
nsresult PresShell::SuspendCaret()
|
1999-02-13 04:45:44 +00:00
|
|
|
{
|
|
|
|
if (mCaret)
|
|
|
|
return mCaret->SetCaretVisible(PR_FALSE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-01 23:58:11 +00:00
|
|
|
nsresult PresShell::ResumeCaret()
|
1999-02-13 04:45:44 +00:00
|
|
|
{
|
1999-04-01 23:58:11 +00:00
|
|
|
if (mCaret && mCaretEnabled)
|
1999-02-13 04:45:44 +00:00
|
|
|
return mCaret->SetCaretVisible(PR_TRUE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-06 16:16:01 +00: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;
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
CreateRenderingContext(mRootFrame, &rcx);
|
1998-11-06 16:16:01 +00:00
|
|
|
|
|
|
|
// XXX We should be using eReflowReason_StyleChange
|
|
|
|
nsHTMLReflowState reflowState(*mPresContext, mRootFrame,
|
1999-03-05 04:29:11 +00:00
|
|
|
eReflowReason_Resize, rcx, maxSize);
|
1998-11-06 16:16:01 +00:00
|
|
|
|
|
|
|
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-12-29 04:45:18 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 17:45:58 +00:00
|
|
|
PresShell::GetRootFrame(nsIFrame** aResult) const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mRootFrame;
|
1998-12-29 04:45:18 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-07 03:43:02 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 17:45:58 +00:00
|
|
|
PresShell::GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const
|
1998-12-07 03:43:02 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-12-07 03:43:02 +00:00
|
|
|
nsIFrame* child;
|
|
|
|
nsIPageSequenceFrame* pageSequence;
|
|
|
|
|
|
|
|
// The page sequence frame should be either the immediate child or
|
|
|
|
// its child
|
1999-02-10 02:25:01 +00:00
|
|
|
mRootFrame->FirstChild(nsnull, &child);
|
1998-12-07 03:43:02 +00:00
|
|
|
if (nsnull != child) {
|
|
|
|
if (NS_SUCCEEDED(child->QueryInterface(kIPageSequenceFrameIID, (void**)&pageSequence))) {
|
1999-02-12 17:45:58 +00:00
|
|
|
*aResult = pageSequence;
|
1998-12-07 03:43:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-10 02:25:01 +00:00
|
|
|
child->FirstChild(nsnull, &child);
|
1998-12-07 03:43:02 +00:00
|
|
|
if (nsnull != child) {
|
|
|
|
if (NS_SUCCEEDED(child->QueryInterface(kIPageSequenceFrameIID, (void**)&pageSequence))) {
|
1999-02-12 17:45:58 +00:00
|
|
|
*aResult = pageSequence;
|
1998-12-07 03:43:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-12 17:45:58 +00:00
|
|
|
*aResult = nsnull;
|
1998-12-07 03:43:02 +00:00
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-06-03 15:46:54 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::BeginUpdate(nsIDocument *aDocument)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
mUpdateCount++;
|
1998-06-03 15:46:54 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 15:46:54 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::EndUpdate(nsIDocument *aDocument)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != mUpdateCount, "too many EndUpdate's");
|
|
|
|
if (--mUpdateCount == 0) {
|
|
|
|
// XXX do something here
|
|
|
|
}
|
1998-06-03 15:46:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::BeginLoad(nsIDocument *aDocument)
|
1998-06-03 15:46:54 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::EndLoad(nsIDocument *aDocument)
|
1998-06-03 15:46:54 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell)
|
1998-06-03 15:46:54 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::EndReflow(nsIDocument *aDocument, nsIPresShell* aShell)
|
1998-06-03 15:46:54 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-29 04:56:31 +00:00
|
|
|
NS_IMETHODIMP
|
1998-06-09 04:51:44 +00:00
|
|
|
PresShell::AppendReflowCommand(nsIReflowCommand* aReflowCommand)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-11-26 18:11:02 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (mInVerifyReflow) {
|
1998-12-29 04:56:31 +00:00
|
|
|
return NS_OK;
|
1998-11-26 18:11:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
1998-06-09 04:51:44 +00:00
|
|
|
NS_ADDREF(aReflowCommand);
|
1998-12-29 04:56:31 +00:00
|
|
|
return mReflowCommands.AppendElement(aReflowCommand);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-04-23 20:01:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::CancelReflowCommand(nsIFrame* aTargetFrame)
|
|
|
|
{
|
|
|
|
PRInt32 i, n = mReflowCommands.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIReflowCommand* rc = (nsIReflowCommand*) mReflowCommands.ElementAt(0);
|
|
|
|
if (rc) {
|
|
|
|
nsIFrame* target;
|
|
|
|
if (NS_SUCCEEDED(rc->GetTarget(target))) {
|
|
|
|
if (target == aTargetFrame) {
|
|
|
|
mReflowCommands.RemoveElementAt(i);
|
|
|
|
n--;
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-29 04:56:31 +00:00
|
|
|
NS_IMETHODIMP
|
1998-05-09 03:22:41 +00:00
|
|
|
PresShell::ProcessReflowCommands()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
if (0 != mReflowCommands.Count()) {
|
1998-10-02 01:12:39 +00:00
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
|
|
|
nsIRenderingContext* rcx;
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
CreateRenderingContext(mRootFrame, &rcx);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
while (0 != mReflowCommands.Count()) {
|
1998-06-09 04:51:44 +00:00
|
|
|
nsIReflowCommand* rc = (nsIReflowCommand*) mReflowCommands.ElementAt(0);
|
1998-04-13 20:24:54 +00:00
|
|
|
mReflowCommands.RemoveElementAt(0);
|
|
|
|
|
|
|
|
// Dispatch the reflow command
|
1998-04-17 01:41:24 +00:00
|
|
|
nsSize maxSize;
|
|
|
|
mRootFrame->GetSize(maxSize);
|
1998-06-09 04:51:44 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-07-02 21:26:00 +00:00
|
|
|
nsIReflowCommand::ReflowType type;
|
1998-06-09 04:51:44 +00:00
|
|
|
rc->GetType(type);
|
1998-07-02 21:26:00 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("PresShell::ProcessReflowCommands: begin reflow command type=%d",
|
|
|
|
type));
|
1998-06-09 04:51:44 +00:00
|
|
|
#endif
|
1998-10-02 01:12:39 +00:00
|
|
|
rc->Dispatch(*mPresContext, desiredSize, maxSize, *rcx);
|
1998-06-09 04:51:44 +00:00
|
|
|
NS_RELEASE(rc);
|
1998-07-02 21:26:00 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("PresShell::ProcessReflowCommands: end reflow command"));
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-11-26 18:11:02 +00:00
|
|
|
NS_IF_RELEASE(rcx);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
1998-05-20 16:24:54 +00:00
|
|
|
if (nsIFrame::GetVerifyTreeEnable()) {
|
|
|
|
mRootFrame->VerifyTree();
|
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
if (GetVerifyReflowEnable()) {
|
1998-12-12 19:21:05 +00:00
|
|
|
// First synchronously render what we have so far so that we can
|
|
|
|
// see it.
|
1999-04-20 00:24:21 +00:00
|
|
|
// if (gVerifyReflowAll) {
|
|
|
|
// printf("Before verify-reflow\n");
|
1998-12-12 19:21:05 +00:00
|
|
|
nsIView* rootView;
|
|
|
|
mViewManager->GetRootView(rootView);
|
|
|
|
mViewManager->UpdateView(rootView, nsnull, NS_VMREFRESH_IMMEDIATE);
|
1999-04-20 00:24:21 +00:00
|
|
|
// PR_Sleep(PR_SecondsToInterval(3));
|
|
|
|
// }
|
1998-12-12 19:21:05 +00:00
|
|
|
|
1998-11-26 18:11:02 +00:00
|
|
|
mInVerifyReflow = PR_TRUE;
|
1998-07-13 19:49:42 +00:00
|
|
|
VerifyIncrementalReflow();
|
1998-11-26 18:11:02 +00:00
|
|
|
mInVerifyReflow = PR_FALSE;
|
1998-12-12 19:21:05 +00:00
|
|
|
if (gVerifyReflowAll) {
|
|
|
|
printf("After verify-reflow\n");
|
|
|
|
}
|
1998-11-26 18:11:02 +00:00
|
|
|
|
|
|
|
if (0 != mReflowCommands.Count()) {
|
|
|
|
printf("XXX yikes!\n");
|
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
#endif
|
1998-10-02 01:12:39 +00:00
|
|
|
}
|
1998-12-29 04:56:31 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-10-02 01:12:39 +00:00
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
1998-11-19 00:43:36 +00:00
|
|
|
PresShell::ClearFrameRefs(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIEventStateManager *manager;
|
|
|
|
if (NS_OK == mPresContext->GetEventStateManager(&manager)) {
|
|
|
|
manager->ClearFrameRefs(aFrame);
|
|
|
|
NS_RELEASE(manager);
|
|
|
|
}
|
1999-04-01 23:58:11 +00:00
|
|
|
|
|
|
|
if (mCaret) {
|
|
|
|
mCaret->ClearFrameRefs(aFrame);
|
|
|
|
}
|
|
|
|
|
1998-11-21 00:19:36 +00:00
|
|
|
if (aFrame == mCurrentEventFrame) {
|
1999-06-15 03:14:28 +00:00
|
|
|
mCurrentEventFrame->GetContent(&mCurrentEventContent);
|
1998-11-21 00:19:36 +00:00
|
|
|
mCurrentEventFrame = nsnull;
|
|
|
|
}
|
1999-02-12 17:45:58 +00:00
|
|
|
return NS_OK;
|
1998-11-19 00:43:36 +00:00
|
|
|
}
|
|
|
|
|
1999-02-05 18:25:29 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 17:45:58 +00:00
|
|
|
PresShell::CreateRenderingContext(nsIFrame *aFrame,
|
|
|
|
nsIRenderingContext** aResult)
|
1998-10-02 01:12:39 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-10-02 01:12:39 +00:00
|
|
|
nsIWidget *widget = nsnull;
|
|
|
|
nsIView *view = nsnull;
|
|
|
|
nsPoint pt;
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-02-10 05:38:18 +00:00
|
|
|
aFrame->GetView(&view);
|
1998-10-02 01:12:39 +00:00
|
|
|
|
|
|
|
if (nsnull == view)
|
1999-02-10 05:38:18 +00:00
|
|
|
aFrame->GetOffsetFromView(pt, &view);
|
1998-10-02 01:12:39 +00:00
|
|
|
|
|
|
|
while (nsnull != view)
|
|
|
|
{
|
|
|
|
view->GetWidget(widget);
|
|
|
|
|
|
|
|
if (nsnull != widget)
|
|
|
|
{
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->GetParent(view);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-10-02 01:12:39 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIDeviceContext> dx;
|
1998-11-14 01:52:27 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
nsIRenderingContext* result = nsnull;
|
|
|
|
rv = mPresContext->GetDeviceContext(getter_AddRefs(dx));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && dx) {
|
1999-02-12 17:45:58 +00:00
|
|
|
if (nsnull != view) {
|
|
|
|
rv = dx->CreateRenderingContext(view, result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = dx->CreateRenderingContext(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aResult = result;
|
1998-10-02 01:12:39 +00:00
|
|
|
|
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
struct CantRenderReplacedElementEvent : public PLEvent {
|
|
|
|
CantRenderReplacedElementEvent(PresShell* aShell, nsIFrame* aFrame);
|
|
|
|
|
|
|
|
nsIFrame* mFrame; // the frame that can't be rendered
|
|
|
|
CantRenderReplacedElementEvent* mNext; // next event in the list
|
|
|
|
};
|
|
|
|
|
|
|
|
CantRenderReplacedElementEvent**
|
|
|
|
PresShell::FindPostedEventFor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
CantRenderReplacedElementEvent** event = &mPostedEvents;
|
|
|
|
|
|
|
|
while (*event) {
|
|
|
|
if ((*event)->mFrame == aFrame) {
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
event = &(*event)->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
1999-02-05 18:25:29 +00:00
|
|
|
void
|
1999-07-16 23:27:46 +00:00
|
|
|
PresShell::DequeuePostedEventFor(nsIFrame* aFrame)
|
1999-02-05 18:25:29 +00:00
|
|
|
{
|
1999-07-16 23:27:46 +00:00
|
|
|
// If there's a posted event for this frame, then remove it
|
|
|
|
CantRenderReplacedElementEvent** event = FindPostedEventFor(aFrame);
|
|
|
|
if (*event) {
|
|
|
|
CantRenderReplacedElementEvent* tmp = *event;
|
|
|
|
|
|
|
|
// Remove it from our linked list of posted events
|
|
|
|
*event = (*event)->mNext;
|
|
|
|
|
|
|
|
// Dequeue it from the event queue
|
|
|
|
nsIEventQueueService* eventService;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
|
|
|
kIEventQueueServiceIID,
|
|
|
|
(nsISupports **)&eventService);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIEventQueue> eventQueue;
|
|
|
|
rv = eventService->GetThreadEventQueue(PR_GetCurrentThread(),
|
|
|
|
getter_AddRefs(eventQueue));
|
|
|
|
nsServiceManager::ReleaseService(kEventQueueServiceCID, eventService);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && eventQueue) {
|
|
|
|
PLEventQueue* plqueue;
|
|
|
|
|
|
|
|
eventQueue->GetPLEventQueue(&plqueue);
|
|
|
|
if (plqueue) {
|
|
|
|
// Removes the event and destroys it
|
|
|
|
PL_DequeueEvent(tmp, plqueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-05 18:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
void
|
|
|
|
PresShell::HandleCantRenderReplacedElementEvent(CantRenderReplacedElementEvent* aEvent)
|
|
|
|
{
|
|
|
|
// Remove the posted event from our linked list
|
|
|
|
CantRenderReplacedElementEvent** events = &mPostedEvents;
|
|
|
|
while (*events) {
|
|
|
|
if (*events == aEvent) {
|
|
|
|
*events = (*events)->mNext;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
events = &(*events)->mNext;
|
|
|
|
}
|
|
|
|
}
|
1999-02-05 18:25:29 +00:00
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
// Notify the style system and then process any reflow commands that
|
|
|
|
// are generated
|
|
|
|
mStyleSet->CantRenderReplacedElement(mPresContext, aEvent->mFrame);
|
|
|
|
ProcessReflowCommands();
|
|
|
|
}
|
1999-02-05 18:25:29 +00:00
|
|
|
|
|
|
|
static void PR_CALLBACK
|
|
|
|
HandlePLEvent(CantRenderReplacedElementEvent* aEvent)
|
|
|
|
{
|
1999-07-16 23:27:46 +00:00
|
|
|
PresShell* shell = (PresShell*)aEvent->owner;
|
|
|
|
shell->HandleCantRenderReplacedElementEvent(aEvent);
|
1999-02-05 18:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK
|
|
|
|
DestroyPLEvent(CantRenderReplacedElementEvent* aEvent)
|
|
|
|
{
|
|
|
|
delete aEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
CantRenderReplacedElementEvent::CantRenderReplacedElementEvent(PresShell* aShell,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
1999-07-16 23:27:46 +00:00
|
|
|
// Note: because the pres shell owns us we don't hold a reference to the
|
|
|
|
// pres shell
|
|
|
|
PL_InitEvent(this, aShell, (PLHandleEventProc)::HandlePLEvent,
|
1999-02-05 18:25:29 +00:00
|
|
|
(PLDestroyEventProc)::DestroyPLEvent);
|
1999-07-16 23:27:46 +00:00
|
|
|
mFrame = aFrame;
|
1999-02-05 18:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::CantRenderReplacedElement(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIEventQueueService* eventService;
|
|
|
|
nsresult rv;
|
1999-07-16 23:27:46 +00:00
|
|
|
|
|
|
|
// We need to notify the style stystem, but post the notification so it
|
|
|
|
// doesn't happen now
|
1999-02-05 18:25:29 +00:00
|
|
|
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
|
|
|
kIEventQueueServiceIID,
|
|
|
|
(nsISupports **)&eventService);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-05-04 23:29:06 +00:00
|
|
|
nsCOMPtr<nsIEventQueue> eventQueue;
|
1999-02-05 18:25:29 +00:00
|
|
|
rv = eventService->GetThreadEventQueue(PR_GetCurrentThread(),
|
1999-05-04 23:29:06 +00:00
|
|
|
getter_AddRefs(eventQueue));
|
1999-02-05 18:25:29 +00:00
|
|
|
nsServiceManager::ReleaseService(kEventQueueServiceCID, eventService);
|
|
|
|
|
1999-05-04 23:29:06 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && eventQueue) {
|
1999-07-16 23:27:46 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Verify that there isn't already a posted event associated with
|
|
|
|
// this frame
|
|
|
|
NS_ASSERTION(!*FindPostedEventFor(aFrame), "frame already has posted event");
|
|
|
|
#endif
|
1999-02-05 18:25:29 +00:00
|
|
|
CantRenderReplacedElementEvent* ev;
|
|
|
|
|
1999-07-16 23:27:46 +00:00
|
|
|
// Create a new event
|
1999-02-05 18:25:29 +00:00
|
|
|
ev = new CantRenderReplacedElementEvent(this, aFrame);
|
1999-07-16 23:27:46 +00:00
|
|
|
|
|
|
|
// Add the event to our linked list of posted events
|
|
|
|
ev->mNext = mPostedEvents;
|
|
|
|
mPostedEvents = ev;
|
|
|
|
|
|
|
|
// Post the event
|
1999-05-04 23:29:06 +00:00
|
|
|
eventQueue->PostEvent(ev);
|
1999-02-05 18:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-12 05:39:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GoToAnchor(const nsString& aAnchorName) const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc;
|
1999-03-20 01:51:00 +00:00
|
|
|
nsCOMPtr<nsIXMLDocument> xmlDoc;
|
1999-04-13 21:50:47 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-03-20 01:51:00 +00:00
|
|
|
nsCOMPtr<nsIContent> content;
|
1999-02-12 05:39:33 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mDocument->QueryInterface(kIDOMHTMLDocumentIID,
|
1999-03-20 01:51:00 +00:00
|
|
|
getter_AddRefs(htmlDoc)))) {
|
1999-02-12 05:39:33 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
|
1999-03-20 01:51:00 +00:00
|
|
|
// Find the element with the specified id
|
|
|
|
rv = htmlDoc->GetElementById(aAnchorName, getter_AddRefs(element));
|
1999-04-09 04:28:15 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && element) {
|
1999-02-12 05:39:33 +00:00
|
|
|
// Get the nsIContent interface, because that's what we need to
|
|
|
|
// get the primary frame
|
1999-03-20 01:51:00 +00:00
|
|
|
rv = element->QueryInterface(kIContentIID, getter_AddRefs(content));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (NS_SUCCEEDED(mDocument->QueryInterface(kIXMLDocumentIID,
|
|
|
|
getter_AddRefs(xmlDoc)))) {
|
|
|
|
rv = xmlDoc->GetContentById(aAnchorName, getter_AddRefs(content));
|
|
|
|
}
|
1999-02-12 05:39:33 +00:00
|
|
|
|
1999-04-09 04:28:15 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && content) {
|
1999-03-20 01:51:00 +00:00
|
|
|
nsIFrame* frame;
|
|
|
|
|
|
|
|
// Get the primary frame
|
|
|
|
if (NS_SUCCEEDED(GetPrimaryFrameFor(content, &frame))) {
|
1999-07-19 18:38:33 +00:00
|
|
|
rv = ScrollFrameIntoView(frame, NS_PRESSHELL_SCROLL_TOP,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
1999-02-12 05:39:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-18 22:52:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ScrollFrameIntoView(nsIFrame *aFrame,
|
1999-07-19 18:38:33 +00:00
|
|
|
PRIntn aVPercent,
|
|
|
|
PRIntn aHPercent) const
|
1999-02-18 22:52:21 +00:00
|
|
|
{
|
1999-07-19 18:38:33 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!aFrame) {
|
1999-02-18 22:52:21 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-07-19 18:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mViewManager) {
|
|
|
|
// Get the viewport scroller
|
1999-02-18 22:52:21 +00:00
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
mViewManager->GetRootScrollableView(&scrollingView);
|
|
|
|
|
|
|
|
if (scrollingView) {
|
|
|
|
nsIView* scrolledView;
|
|
|
|
nsPoint offset;
|
1999-07-19 18:38:33 +00:00
|
|
|
nsIView* closestView;
|
1999-02-18 22:52:21 +00:00
|
|
|
|
1999-07-19 18:38:33 +00:00
|
|
|
// Determine the offset from aFrame to the scrolled view. We do that by
|
|
|
|
// getting the offset from its closest view and then walking up
|
1999-02-18 22:52:21 +00:00
|
|
|
scrollingView->GetScrolledView(scrolledView);
|
1999-07-19 18:38:33 +00:00
|
|
|
aFrame->GetOffsetFromView(offset, &closestView);
|
|
|
|
|
|
|
|
// XXX Deal with the case where there is a scrolled element, e.g., a
|
|
|
|
// DIV in the middle...
|
|
|
|
while (closestView != scrolledView) {
|
|
|
|
nscoord x, y;
|
|
|
|
|
|
|
|
// Update the offset
|
|
|
|
closestView->GetPosition(&x, &y);
|
|
|
|
offset.MoveBy(x, y);
|
|
|
|
|
|
|
|
// Get its parent view
|
|
|
|
closestView->GetParent(closestView);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the visible rect in the scrolled view's coordinate space.
|
|
|
|
// The size of the visible area is the clip view size
|
|
|
|
const nsIView* clipView;
|
|
|
|
nsRect visibleRect;
|
|
|
|
|
|
|
|
scrollingView->GetScrollPosition(visibleRect.x, visibleRect.y);
|
|
|
|
scrollingView->GetClipView(&clipView);
|
|
|
|
clipView->GetDimensions(&visibleRect.width, &visibleRect.height);
|
|
|
|
|
|
|
|
// The actual scroll offsets
|
|
|
|
nscoord scrollOffsetX = visibleRect.x;
|
|
|
|
nscoord scrollOffsetY = visibleRect.y;
|
|
|
|
|
|
|
|
// The frame's bounds in the coordinate space of the scrolled frame
|
|
|
|
nsRect frameBounds;
|
|
|
|
aFrame->GetRect(frameBounds);
|
|
|
|
frameBounds.x = offset.x;
|
|
|
|
frameBounds.y = offset.y;
|
|
|
|
|
|
|
|
// See how the frame should be positioned vertically
|
|
|
|
if (NS_PRESSHELL_SCROLL_ANYWHERE == aVPercent) {
|
|
|
|
// The caller doesn't care where the frame is positioned vertically,
|
|
|
|
// so long as it's fully visible
|
|
|
|
if (frameBounds.y < visibleRect.y) {
|
|
|
|
// Scroll up so the frame's top edge is visible
|
|
|
|
scrollOffsetY = frameBounds.y;
|
|
|
|
} else if (frameBounds.YMost() > visibleRect.YMost()) {
|
|
|
|
// Scroll down so the frame's bottom edge is visible. Make sure the
|
|
|
|
// frame's top edge is still visible
|
|
|
|
scrollOffsetY += frameBounds.YMost() - visibleRect.YMost();
|
|
|
|
if (scrollOffsetY > frameBounds.y) {
|
|
|
|
scrollOffsetY = frameBounds.y;
|
1999-02-19 23:43:41 +00:00
|
|
|
}
|
|
|
|
}
|
1999-07-19 18:38:33 +00:00
|
|
|
} else {
|
|
|
|
// Align the frame edge according to the specified percentage
|
|
|
|
nscoord frameAlignY = frameBounds.y + (frameBounds.height * aVPercent) / 100;
|
|
|
|
scrollOffsetY = frameAlignY - (visibleRect.height * aVPercent) / 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See how the frame should be positioned horizontally
|
|
|
|
if (NS_PRESSHELL_SCROLL_ANYWHERE == aHPercent) {
|
|
|
|
// The caller doesn't care where the frame is positioned horizontally,
|
|
|
|
// so long as it's fully visible
|
|
|
|
if (frameBounds.x < visibleRect.x) {
|
|
|
|
// Scroll left so the frame's left edge is visible
|
|
|
|
scrollOffsetX = frameBounds.x;
|
|
|
|
} else if (frameBounds.XMost() > visibleRect.XMost()) {
|
|
|
|
// Scroll right so the frame's right edge is visible. Make sure the
|
|
|
|
// frame's left edge is still visible
|
|
|
|
scrollOffsetX += frameBounds.XMost() - visibleRect.XMost();
|
|
|
|
if (scrollOffsetX > frameBounds.x) {
|
|
|
|
scrollOffsetX = frameBounds.x;
|
1999-02-20 21:27:28 +00:00
|
|
|
}
|
1999-02-19 23:43:41 +00:00
|
|
|
}
|
1999-07-19 18:38:33 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Align the frame edge according to the specified percentage
|
|
|
|
nscoord frameAlignX = frameBounds.x + (frameBounds.width * aHPercent) / 100;
|
|
|
|
scrollOffsetX = frameAlignX - (visibleRect.width * aHPercent) / 100;
|
1999-02-19 23:43:41 +00:00
|
|
|
}
|
1999-07-19 18:38:33 +00:00
|
|
|
|
|
|
|
scrollingView->ScrollTo(scrollOffsetX, scrollOffsetY, NS_VMREFRESH_IMMEDIATE);
|
1999-02-18 22:52:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-07 03:56:07 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::DoCopy()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
GetDocument(getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
|
|
|
nsString buffer;
|
|
|
|
|
|
|
|
nsIDOMSelection* sel = nsnull;
|
1999-07-18 02:27:19 +00:00
|
|
|
GetSelection(SELECTION_NORMAL, &sel);
|
1999-04-07 03:56:07 +00:00
|
|
|
|
|
|
|
if (sel != nsnull)
|
|
|
|
doc->CreateXIF(buffer,sel);
|
|
|
|
NS_IF_RELEASE(sel);
|
|
|
|
|
|
|
|
// Get the Clipboard
|
|
|
|
nsIClipboard* clipboard;
|
|
|
|
nsresult rv = nsServiceManager::GetService(kCClipboardCID,
|
1999-05-04 14:55:24 +00:00
|
|
|
nsIClipboard::GetIID(),
|
1999-04-07 03:56:07 +00:00
|
|
|
(nsISupports **)&clipboard);
|
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
|
|
|
|
// Create a data flavor to tell the transferable
|
|
|
|
// that it is about to receive XIF
|
1999-05-13 21:53:57 +00:00
|
|
|
nsAutoString flavor(kXIFMime);
|
|
|
|
|
|
|
|
// Create a transferable for putting data on the Clipboard
|
|
|
|
nsCOMPtr<nsITransferable> trans;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
|
|
|
|
nsITransferable::GetIID(),
|
|
|
|
(void**) getter_AddRefs(trans));
|
1999-04-07 03:56:07 +00:00
|
|
|
if (NS_OK == rv) {
|
1999-05-13 21:53:57 +00:00
|
|
|
// The data on the clipboard will be in "XIF" format
|
|
|
|
// so give the clipboard transferable a "XIFConverter" for
|
|
|
|
// converting from XIF to other formats
|
|
|
|
nsCOMPtr<nsIFormatConverter> xifConverter;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull,
|
|
|
|
nsIFormatConverter::GetIID(), (void**) getter_AddRefs(xifConverter));
|
1999-04-07 03:56:07 +00:00
|
|
|
if (NS_OK == rv) {
|
1999-05-13 21:53:57 +00:00
|
|
|
// Add the XIF DataFlavor to the transferable
|
|
|
|
// this tells the transferable that it can handle receiving the XIF format
|
|
|
|
trans->AddDataFlavor(&flavor);
|
|
|
|
|
|
|
|
// Add the converter for going from XIF to other formats
|
|
|
|
trans->SetConverter(xifConverter);
|
|
|
|
|
|
|
|
// Now add the XIF data to the transferable
|
1999-07-16 14:20:59 +00:00
|
|
|
trans->SetTransferData(&flavor, buffer.ToNewUnicode(), buffer.Length());
|
|
|
|
//trans->SetTransferData(&flavor, buffer.ToNewCString(), buffer.Length());
|
1999-05-13 21:53:57 +00:00
|
|
|
|
|
|
|
// put the transferable on the clipboard
|
|
|
|
clipboard->SetData(trans, nsnull);
|
1999-04-07 03:56:07 +00:00
|
|
|
}
|
|
|
|
}
|
1999-04-23 17:15:53 +00:00
|
|
|
nsServiceManager::ReleaseService(kCClipboardCID, clipboard);
|
1999-04-07 03:56:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-03 15:46:54 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::ContentChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
1998-05-09 03:22:41 +00:00
|
|
|
nsISupports* aSubContent)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-06 16:28:55 +00:00
|
|
|
NS_PRECONDITION(nsnull != mRootFrame, "null root frame");
|
1998-05-30 01:31:04 +00:00
|
|
|
|
|
|
|
EnterReflowLock();
|
1998-09-29 23:46:05 +00:00
|
|
|
nsresult rv = mStyleSet->ContentChanged(mPresContext, aContent, aSubContent);
|
1998-05-30 01:31:04 +00:00
|
|
|
ExitReflowLock();
|
1999-01-29 18:57:56 +00:00
|
|
|
|
1998-09-29 23:46:05 +00:00
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-02-27 07:15:09 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 00:06:58 +00:00
|
|
|
PresShell::ContentStatesChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2)
|
1999-02-27 07:15:09 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mRootFrame, "null root frame");
|
|
|
|
|
|
|
|
EnterReflowLock();
|
1999-04-20 00:06:58 +00:00
|
|
|
nsresult rv = mStyleSet->ContentStatesChanged(mPresContext, aContent1, aContent2);
|
1999-02-27 07:15:09 +00:00
|
|
|
ExitReflowLock();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-18 19:53:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
1998-09-29 23:46:05 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
1998-09-18 19:53:27 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mRootFrame, "null root frame");
|
|
|
|
|
|
|
|
EnterReflowLock();
|
1998-09-29 23:46:05 +00:00
|
|
|
nsresult rv = mStyleSet->AttributeChanged(mPresContext, aContent, aAttribute, aHint);
|
1998-09-18 19:53:27 +00:00
|
|
|
ExitReflowLock();
|
1998-09-29 23:46:05 +00:00
|
|
|
return rv;
|
1998-09-18 19:53:27 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 15:46:54 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-22 23:32:19 +00:00
|
|
|
PresShell::ContentAppended(nsIDocument *aDocument,
|
1998-09-10 19:32:14 +00:00
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-03 15:46:54 +00:00
|
|
|
EnterReflowLock();
|
1998-09-29 23:46:05 +00:00
|
|
|
nsresult rv = mStyleSet->ContentAppended(mPresContext, aContainer, aNewIndexInContainer);
|
1998-06-03 15:46:54 +00:00
|
|
|
ExitReflowLock();
|
1998-09-10 19:32:14 +00:00
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 15:46:54 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-10 19:32:14 +00:00
|
|
|
PresShell::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-09-10 19:32:14 +00:00
|
|
|
EnterReflowLock();
|
1998-09-29 23:46:05 +00:00
|
|
|
nsresult rv = mStyleSet->ContentInserted(mPresContext, aContainer, aChild, aIndexInContainer);
|
1998-09-10 19:32:14 +00:00
|
|
|
ExitReflowLock();
|
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 15:46:54 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-10 19:32:14 +00:00
|
|
|
PresShell::ContentReplaced(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-09-10 19:32:14 +00:00
|
|
|
EnterReflowLock();
|
1998-09-29 23:46:05 +00:00
|
|
|
nsresult rv = mStyleSet->ContentReplaced(mPresContext, aContainer, aOldChild,
|
|
|
|
aNewChild, aIndexInContainer);
|
1998-09-10 19:32:14 +00:00
|
|
|
ExitReflowLock();
|
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 15:46:54 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-24 21:39:47 +00:00
|
|
|
PresShell::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-09-25 05:13:06 +00:00
|
|
|
EnterReflowLock();
|
1998-09-29 23:46:05 +00:00
|
|
|
nsresult rv = mStyleSet->ContentRemoved(mPresContext, aContainer,
|
|
|
|
aChild, aIndexInContainer);
|
1998-09-25 05:13:06 +00:00
|
|
|
ExitReflowLock();
|
1998-09-10 19:32:14 +00:00
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
nsresult
|
|
|
|
PresShell::ReconstructFrames(void)
|
1998-11-17 02:14:38 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-01-26 00:05:21 +00:00
|
|
|
|
1999-03-01 16:57:35 +00:00
|
|
|
EnterReflowLock();
|
|
|
|
rv = mStyleSet->ReconstructDocElementHierarchy(mPresContext);
|
|
|
|
ExitReflowLock();
|
|
|
|
|
1998-11-17 02:14:38 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::StyleSheetAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet)
|
|
|
|
{
|
|
|
|
return ReconstructFrames();
|
|
|
|
}
|
|
|
|
|
1999-02-03 19:38:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::StyleSheetRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet)
|
|
|
|
{
|
|
|
|
return ReconstructFrames();
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDisabled)
|
|
|
|
{
|
|
|
|
return ReconstructFrames();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::StyleRuleChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
EnterReflowLock();
|
|
|
|
nsresult rv = mStyleSet->StyleRuleChanged(mPresContext, aStyleSheet,
|
|
|
|
aStyleRule, aHint);
|
|
|
|
ExitReflowLock();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::StyleRuleAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
EnterReflowLock();
|
1999-04-03 18:58:04 +00:00
|
|
|
nsresult rv = mStyleSet->StyleRuleAdded(mPresContext, aStyleSheet,
|
|
|
|
aStyleRule);
|
1998-11-26 01:34:53 +00:00
|
|
|
ExitReflowLock();
|
1999-04-03 18:58:04 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-03-10 01:17:49 +00:00
|
|
|
// XXX For now reconstruct everything
|
|
|
|
return ReconstructFrames();
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::StyleRuleRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
EnterReflowLock();
|
1999-04-03 18:58:04 +00:00
|
|
|
nsresult rv = mStyleSet->StyleRuleRemoved(mPresContext, aStyleSheet,
|
|
|
|
aStyleRule);
|
1998-11-26 01:34:53 +00:00
|
|
|
ExitReflowLock();
|
1999-04-03 18:58:04 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-03-10 01:17:49 +00:00
|
|
|
// XXX For now reconstruct everything
|
|
|
|
return ReconstructFrames();
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::DocumentWillBeDestroyed(nsIDocument *aDocument)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-03 15:46:54 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-29 04:45:18 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 17:45:58 +00:00
|
|
|
PresShell::GetPrimaryFrameFor(nsIContent* aContent,
|
1999-07-06 03:52:33 +00:00
|
|
|
nsIFrame** aResult) const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
1999-07-06 03:52:33 +00:00
|
|
|
NS_PRECONDITION(nsnull != aContent, "no content object");
|
1999-02-12 17:45:58 +00:00
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-07-06 03:52:33 +00:00
|
|
|
if (nsnull == mPrimaryFrameMap) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
} else {
|
1999-07-16 03:32:09 +00:00
|
|
|
*aResult = (nsIFrame*)mPrimaryFrameMap->Search(aContent);
|
1999-07-06 03:52:33 +00:00
|
|
|
if (!*aResult) {
|
|
|
|
// Give the frame construction code the opportunity to return the
|
|
|
|
// frame that maps the content object
|
|
|
|
mStyleSet->FindPrimaryFrameFor(mPresContext, aContent, aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-29 04:45:18 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-06-30 04:42:26 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::SetPrimaryFrameFor(nsIContent* aContent,
|
|
|
|
nsIFrame* aPrimaryFrame)
|
|
|
|
{
|
1999-07-16 03:32:09 +00:00
|
|
|
NS_PRECONDITION(aContent, "no content object");
|
1999-07-06 03:52:33 +00:00
|
|
|
|
1999-07-16 03:32:09 +00:00
|
|
|
// If aPrimaryFrame is NULL, then remove the mapping
|
|
|
|
if (!aPrimaryFrame) {
|
|
|
|
if (mPrimaryFrameMap) {
|
|
|
|
mPrimaryFrameMap->Remove(aContent);
|
1999-07-06 03:52:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
1999-07-16 03:32:09 +00:00
|
|
|
// Create a new DST if necessary
|
|
|
|
if (!mPrimaryFrameMap) {
|
|
|
|
mPrimaryFrameMap = new nsDST;
|
|
|
|
if (!mPrimaryFrameMap) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a mapping to the hash table
|
1999-07-06 03:52:33 +00:00
|
|
|
nsIFrame* oldPrimaryFrame;
|
|
|
|
|
1999-07-16 03:32:09 +00:00
|
|
|
oldPrimaryFrame = (nsIFrame*)mPrimaryFrameMap->Insert(aContent, (void*)aPrimaryFrame);
|
1999-07-06 03:52:33 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (oldPrimaryFrame && (oldPrimaryFrame != aPrimaryFrame)) {
|
|
|
|
NS_WARNING("overwriting current primary frame");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-06-30 04:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ClearPrimaryFrameMap()
|
|
|
|
{
|
1999-07-06 03:52:33 +00:00
|
|
|
if (mPrimaryFrameMap) {
|
|
|
|
mPrimaryFrameMap->Clear();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-06-30 04:42:26 +00:00
|
|
|
}
|
|
|
|
|
1999-02-25 19:55:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetStyleContextFor(nsIFrame* aFrame,
|
|
|
|
nsIStyleContext** aStyleContext) const
|
|
|
|
{
|
|
|
|
if (!aFrame || !aStyleContext) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
return (aFrame->GetStyleContext(aStyleContext));
|
|
|
|
}
|
1999-02-10 23:21:22 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetLayoutObjectFor(nsIContent* aContent,
|
|
|
|
nsISupports** aResult) const
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_NULL_POINTER;
|
|
|
|
if ((nsnull!=aResult) && (nsnull!=aContent))
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
nsIFrame *primaryFrame=nsnull;
|
1999-02-12 17:45:58 +00:00
|
|
|
result = GetPrimaryFrameFor(aContent, &primaryFrame);
|
1999-02-10 23:21:22 +00:00
|
|
|
if ((NS_SUCCEEDED(result)) && (nsnull!=primaryFrame))
|
|
|
|
{
|
|
|
|
result = primaryFrame->QueryInterface(kISupportsIID, (void**)aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-29 03:38:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::GetPlaceholderFrameFor(nsIFrame* aFrame,
|
1999-02-12 17:45:58 +00:00
|
|
|
nsIFrame** aResult) const
|
1998-12-29 03:38:16 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
1998-12-29 03:38:16 +00:00
|
|
|
NS_PRECONDITION(nsnull != aFrame, "no frame");
|
1999-02-12 17:45:58 +00:00
|
|
|
if ((nsnull == aResult) || (nsnull == aFrame)) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-12-29 03:38:16 +00:00
|
|
|
|
|
|
|
if (nsnull == mPlaceholderMap) {
|
1999-02-12 17:45:58 +00:00
|
|
|
*aResult = nsnull;
|
1998-12-29 03:38:16 +00:00
|
|
|
} else {
|
1999-07-06 03:52:33 +00:00
|
|
|
*aResult = (nsIFrame*)mPlaceholderMap->Get(aFrame);
|
1998-12-29 03:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::SetPlaceholderFrameFor(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aPlaceholderFrame)
|
|
|
|
{
|
1999-07-16 03:32:09 +00:00
|
|
|
NS_PRECONDITION(aFrame, "no frame");
|
1999-04-25 17:00:24 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Verify that the placeholder frame is of the correct type
|
|
|
|
if (aPlaceholderFrame) {
|
|
|
|
nsIAtom* frameType;
|
|
|
|
|
|
|
|
aPlaceholderFrame->GetFrameType(&frameType);
|
|
|
|
NS_PRECONDITION(nsLayoutAtoms::placeholderFrame == frameType, "unexpected frame type");
|
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
}
|
|
|
|
#endif
|
1998-12-29 03:38:16 +00:00
|
|
|
|
1999-07-16 03:32:09 +00:00
|
|
|
// If aPlaceholderFrame is NULL, then remove the mapping
|
|
|
|
if (!aPlaceholderFrame) {
|
|
|
|
if (mPlaceholderMap) {
|
|
|
|
mPlaceholderMap->Remove(aFrame);
|
1998-12-29 03:38:16 +00:00
|
|
|
}
|
1999-02-06 17:10:42 +00:00
|
|
|
} else {
|
1999-07-16 03:32:09 +00:00
|
|
|
// Create a new hash table if necessary
|
|
|
|
if (!mPlaceholderMap) {
|
|
|
|
mPlaceholderMap = new FrameHashTable;
|
|
|
|
if (!mPlaceholderMap) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a mapping to the hash table
|
1999-02-06 17:10:42 +00:00
|
|
|
mPlaceholderMap->Put(aFrame, (void*)aPlaceholderFrame);
|
|
|
|
}
|
1998-12-29 03:38:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-30 04:42:26 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ClearPlaceholderFrameMap()
|
|
|
|
{
|
1999-07-06 03:52:33 +00:00
|
|
|
if (mPlaceholderMap) {
|
|
|
|
mPlaceholderMap->Clear();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-06-30 04:42:26 +00:00
|
|
|
}
|
|
|
|
|
1998-08-28 02:54:06 +00:00
|
|
|
//nsIViewObserver
|
|
|
|
|
1998-12-18 15:54:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::Paint(nsIView *aView,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
1998-08-28 02:54:06 +00:00
|
|
|
{
|
1998-08-30 19:16:11 +00:00
|
|
|
void* clientData;
|
|
|
|
nsIFrame* frame;
|
1998-10-30 22:06:14 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-08-28 02:54:06 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(!(nsnull == aView), "null view");
|
|
|
|
|
1998-08-30 19:16:11 +00:00
|
|
|
aView->GetClientData(clientData);
|
|
|
|
frame = (nsIFrame *)clientData;
|
1998-08-28 02:54:06 +00:00
|
|
|
|
1998-10-30 22:06:14 +00:00
|
|
|
if (nsnull != frame) {
|
1998-12-18 15:54:23 +00:00
|
|
|
rv = frame->Paint(*mPresContext, aRenderingContext, aDirtyRect,
|
1999-03-26 00:39:35 +00:00
|
|
|
NS_FRAME_PAINT_LAYER_BACKGROUND);
|
1998-12-18 15:54:23 +00:00
|
|
|
rv = frame->Paint(*mPresContext, aRenderingContext, aDirtyRect,
|
1999-03-26 00:39:35 +00:00
|
|
|
NS_FRAME_PAINT_LAYER_FLOATERS);
|
1998-12-18 15:54:23 +00:00
|
|
|
rv = frame->Paint(*mPresContext, aRenderingContext, aDirtyRect,
|
1999-03-26 00:39:35 +00:00
|
|
|
NS_FRAME_PAINT_LAYER_FOREGROUND);
|
1998-10-30 22:06:14 +00: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
|
1999-04-01 23:58:11 +00:00
|
|
|
|
|
|
|
// ensure the caret gets redrawn
|
|
|
|
RefreshCaret(aView, aRenderingContext, aDirtyRect);
|
1998-10-30 22:06:14 +00:00
|
|
|
}
|
1998-08-28 02:54:06 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-15 03:14:28 +00:00
|
|
|
nsIFrame*
|
|
|
|
PresShell::GetCurrentEventFrame()
|
|
|
|
{
|
|
|
|
if (!mCurrentEventFrame && mCurrentEventContent) {
|
|
|
|
GetPrimaryFrameFor(mCurrentEventContent, &mCurrentEventFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mCurrentEventFrame;
|
|
|
|
}
|
|
|
|
|
1998-12-18 15:54:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::HandleEvent(nsIView *aView,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
1998-08-28 02:54:06 +00:00
|
|
|
{
|
1998-08-30 19:16:11 +00:00
|
|
|
void* clientData;
|
|
|
|
nsIFrame* frame;
|
1998-11-21 00:19:36 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-08-28 02:54:06 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(!(nsnull == aView), "null view");
|
|
|
|
|
1998-11-19 00:43:36 +00:00
|
|
|
if (mIsDestroying || mReflowLockCount > 0) {
|
1998-11-18 05:25:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-30 19:16:11 +00:00
|
|
|
aView->GetClientData(clientData);
|
|
|
|
frame = (nsIFrame *)clientData;
|
1998-08-28 02:54:06 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
if (nsnull != frame) {
|
1999-05-20 23:16:53 +00:00
|
|
|
|
|
|
|
nsIWebShell* webShell = nsnull;
|
|
|
|
nsISupports* container;
|
|
|
|
mPresContext->GetContainer(&container);
|
|
|
|
if (nsnull != container) {
|
|
|
|
if (NS_OK != container->QueryInterface(kIWebShellIID, (void**)&webShell)) {
|
|
|
|
NS_ASSERTION(webShell, "No webshell to grab during event dispatch");
|
|
|
|
}
|
|
|
|
NS_RELEASE(container);
|
|
|
|
}
|
|
|
|
|
1999-04-29 20:24:21 +00:00
|
|
|
if (mSelection && aEvent->eventStructType == NS_KEY_EVENT)
|
1998-12-08 18:26:06 +00:00
|
|
|
{
|
1999-02-19 23:47:36 +00:00
|
|
|
mSelection->EnableFrameNotification(PR_FALSE);
|
1999-04-26 04:02:04 +00:00
|
|
|
mSelection->HandleKeyEvent(aEvent);
|
1999-02-19 23:47:36 +00:00
|
|
|
mSelection->EnableFrameNotification(PR_TRUE); //prevents secondary reset selection called since
|
|
|
|
//we are a listener now.
|
1998-12-08 18:26:06 +00:00
|
|
|
}
|
1998-11-21 00:19:36 +00:00
|
|
|
frame->GetFrameForPoint(aEvent->point, &mCurrentEventFrame);
|
1999-06-15 03:14:28 +00:00
|
|
|
NS_IF_RELEASE(mCurrentEventContent);
|
|
|
|
if (nsnull != GetCurrentEventFrame()) {
|
1998-11-18 05:25:26 +00:00
|
|
|
//Once we have the targetFrame, handle the event in this order
|
|
|
|
nsIEventStateManager *manager;
|
|
|
|
if (NS_OK == mPresContext->GetEventStateManager(&manager)) {
|
1998-11-24 07:46:58 +00:00
|
|
|
//1. Give event to event manager for pre event state changes and generation of synthetic events.
|
1999-06-15 03:14:28 +00:00
|
|
|
rv = manager->PreHandleEvent(*mPresContext, aEvent, mCurrentEventFrame, aEventStatus, aView);
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
//2. Give event to the DOM for third party and JS use.
|
1999-06-15 03:14:28 +00:00
|
|
|
if (nsnull != GetCurrentEventFrame() && NS_OK == rv) {
|
1998-11-21 00:19:36 +00:00
|
|
|
nsIContent* targetContent;
|
1999-02-10 00:42:56 +00:00
|
|
|
if (NS_OK == mCurrentEventFrame->GetContent(&targetContent) && nsnull != targetContent) {
|
1998-11-21 00:19:36 +00:00
|
|
|
rv = targetContent->HandleDOMEvent(*mPresContext, (nsEvent*)aEvent, nsnull,
|
1999-03-28 22:22:54 +00:00
|
|
|
NS_EVENT_FLAG_INIT, aEventStatus);
|
1998-11-21 00:19:36 +00:00
|
|
|
NS_RELEASE(targetContent);
|
|
|
|
}
|
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
//3. Give event to the Frames for browser default processing.
|
|
|
|
// XXX The event isn't translated into the local coordinate space
|
|
|
|
// of the frame...
|
1999-06-15 03:14:28 +00:00
|
|
|
if (nsnull != GetCurrentEventFrame() && NS_OK == rv) {
|
1998-11-24 07:46:58 +00:00
|
|
|
rv = mCurrentEventFrame->HandleEvent(*mPresContext, aEvent, aEventStatus);
|
|
|
|
|
|
|
|
//4. Give event to event manager for post event state changes and generation of synthetic events.
|
1999-06-15 03:14:28 +00:00
|
|
|
if (nsnull != GetCurrentEventFrame() && NS_OK == rv) {
|
1999-04-30 19:38:39 +00:00
|
|
|
rv = manager->PostHandleEvent(*mPresContext, aEvent, mCurrentEventFrame, aEventStatus, aView);
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(manager);
|
|
|
|
}
|
|
|
|
}
|
1999-05-20 23:16:53 +00:00
|
|
|
NS_IF_RELEASE(webShell);
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
1998-11-21 00:19:36 +00:00
|
|
|
else {
|
1998-08-28 02:54:06 +00:00
|
|
|
rv = NS_OK;
|
1998-11-21 00:19:36 +00:00
|
|
|
}
|
1998-08-28 02:54:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-18 15:54:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::Scrolled(nsIView *aView)
|
1998-08-28 02:54:06 +00:00
|
|
|
{
|
1998-08-30 19:16:11 +00:00
|
|
|
void* clientData;
|
|
|
|
nsIFrame* frame;
|
1998-08-28 02:54:06 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(!(nsnull == aView), "null view");
|
|
|
|
|
1998-08-30 19:16:11 +00:00
|
|
|
aView->GetClientData(clientData);
|
|
|
|
frame = (nsIFrame *)clientData;
|
1998-08-28 02:54:06 +00:00
|
|
|
|
|
|
|
if (nsnull != frame)
|
1998-09-05 20:57:57 +00:00
|
|
|
rv = frame->Scrolled(aView);
|
1998-08-28 02:54:06 +00:00
|
|
|
else
|
|
|
|
rv = NS_OK;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-18 15:54:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresShell::ResizeReflow(nsIView *aView, nscoord aWidth, nscoord aHeight)
|
1998-08-28 02:54:06 +00:00
|
|
|
{
|
|
|
|
return ResizeReflow(aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIURL.h"
|
1999-04-03 21:54:32 +00:00
|
|
|
#include "nsILinkHandler.h"
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
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);
|
1999-04-03 21:54:32 +00:00
|
|
|
static NS_DEFINE_IID(kILinkHandlerIID, NS_ILINKHANDLER_IID);
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
static void
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg)
|
|
|
|
{
|
|
|
|
printf("verifyreflow: ");
|
|
|
|
nsAutoString name;
|
|
|
|
if (nsnull != k1) {
|
|
|
|
k1->GetFrameName(name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name = "(null)";
|
|
|
|
}
|
|
|
|
fputs(name, stdout);
|
|
|
|
|
|
|
|
printf(" != ");
|
|
|
|
|
|
|
|
if (nsnull != k2) {
|
|
|
|
k2->GetFrameName(name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name = "(null)";
|
|
|
|
}
|
|
|
|
fputs(name, stdout);
|
|
|
|
|
|
|
|
printf(" %s", aMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg,
|
|
|
|
const nsRect& r1, const nsRect& r2)
|
1998-07-13 19:49:42 +00:00
|
|
|
{
|
|
|
|
printf("verifyreflow: ");
|
1998-11-19 17:22:29 +00:00
|
|
|
nsAutoString name;
|
|
|
|
k1->GetFrameName(name);
|
|
|
|
fputs(name, stdout);
|
1998-07-13 19:49:42 +00:00
|
|
|
stdout << r1;
|
1998-11-25 18:41:02 +00:00
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
printf(" != ");
|
1998-11-25 18:41:02 +00:00
|
|
|
|
1998-11-19 17:22:29 +00:00
|
|
|
k2->GetFrameName(name);
|
|
|
|
fputs(name, stdout);
|
1998-07-13 19:49:42 +00:00
|
|
|
stdout << r2;
|
1998-11-25 18:41:02 +00:00
|
|
|
|
|
|
|
printf(" %s\n", aMsg);
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-04-03 18:58:04 +00:00
|
|
|
static PRBool
|
1998-07-13 19:49:42 +00:00
|
|
|
CompareTrees(nsIFrame* aA, nsIFrame* aB)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-04-03 18:58:04 +00:00
|
|
|
PRBool ok = PR_TRUE;
|
1998-11-25 18:41:02 +00:00
|
|
|
PRBool whoops = PR_FALSE;
|
|
|
|
nsIAtom* listName = nsnull;
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
do {
|
|
|
|
nsIFrame* k1, *k2;
|
1999-02-10 02:25:01 +00:00
|
|
|
aA->FirstChild(listName, &k1);
|
|
|
|
aB->FirstChild(listName, &k2);
|
1998-11-25 18:41:02 +00:00
|
|
|
PRInt32 l1 = nsContainerFrame::LengthOf(k1);
|
|
|
|
PRInt32 l2 = nsContainerFrame::LengthOf(k2);
|
|
|
|
if (l1 != l2) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "child counts don't match: ");
|
|
|
|
printf("%d != %d\n", l1, l2);
|
|
|
|
if (!gVerifyReflowAll) {
|
|
|
|
break;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-25 18:41:02 +00:00
|
|
|
nsRect r1, r2;
|
|
|
|
nsIView* v1, *v2;
|
|
|
|
nsIWidget* w1, *w2;
|
|
|
|
for (;;) {
|
|
|
|
if (((nsnull == k1) && (nsnull != k2)) ||
|
|
|
|
((nsnull != k1) && (nsnull == k2))) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "child lists are different\n");
|
|
|
|
whoops = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (nsnull != k1) {
|
|
|
|
// Verify that the frames are the same size
|
|
|
|
k1->GetRect(r1);
|
|
|
|
k2->GetRect(r2);
|
|
|
|
if (r1 != r2) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "(frame rects)", r1, r2);
|
|
|
|
whoops = PR_TRUE;
|
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
|
1998-11-25 18:41:02 +00:00
|
|
|
// Make sure either both have views or neither have views; if they
|
|
|
|
// 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.
|
1999-02-10 05:38:18 +00:00
|
|
|
k1->GetView(&v1);
|
|
|
|
k2->GetView(&v2);
|
1998-11-25 18:41:02 +00:00
|
|
|
if (((nsnull == v1) && (nsnull != v2)) ||
|
|
|
|
((nsnull != v1) && (nsnull == v2))) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "child views are not matched\n");
|
|
|
|
whoops = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (nsnull != v1) {
|
|
|
|
v1->GetBounds(r1);
|
|
|
|
v2->GetBounds(r2);
|
|
|
|
if (r1 != r2) {
|
1999-04-03 18:58:04 +00:00
|
|
|
// ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "(view rects)", r1, r2);
|
1999-04-03 18:58:04 +00:00
|
|
|
// whoops = PR_TRUE;
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
|
1998-11-25 18:41:02 +00:00
|
|
|
v1->GetWidget(w1);
|
|
|
|
v2->GetWidget(w2);
|
|
|
|
if (((nsnull == w1) && (nsnull != w2)) ||
|
|
|
|
((nsnull != w1) && (nsnull == w2))) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "child widgets are not matched\n");
|
|
|
|
whoops = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (nsnull != w1) {
|
|
|
|
w1->GetBounds(r1);
|
|
|
|
w2->GetBounds(r2);
|
|
|
|
if (r1 != r2) {
|
1999-04-03 18:58:04 +00:00
|
|
|
// ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "(widget rects)", r1, r2);
|
1999-04-03 18:58:04 +00:00
|
|
|
// whoops = PR_TRUE;
|
1998-11-25 18:41:02 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-25 18:41:02 +00:00
|
|
|
if (whoops && !gVerifyReflowAll) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare the sub-trees too
|
1999-04-03 18:58:04 +00:00
|
|
|
if (!CompareTrees(k1, k2)) {
|
|
|
|
if (!gVerifyReflowAll) {
|
|
|
|
ok = PR_FALSE;
|
|
|
|
whoops = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-11-25 18:41:02 +00:00
|
|
|
|
|
|
|
// Advance to next sibling
|
1999-02-10 06:13:38 +00:00
|
|
|
k1->GetNextSibling(&k1);
|
|
|
|
k2->GetNextSibling(&k2);
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-11-25 18:41:02 +00:00
|
|
|
break;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-25 18:41:02 +00:00
|
|
|
if (whoops && !gVerifyReflowAll) {
|
|
|
|
break;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
1998-11-25 18:41:02 +00:00
|
|
|
NS_IF_RELEASE(listName);
|
|
|
|
|
|
|
|
nsIAtom* listName1;
|
|
|
|
nsIAtom* listName2;
|
1999-02-10 02:25:01 +00:00
|
|
|
aA->GetAdditionalChildListName(listIndex, &listName1);
|
|
|
|
aB->GetAdditionalChildListName(listIndex, &listName2);
|
1998-11-25 18:41:02 +00:00
|
|
|
listIndex++;
|
|
|
|
if (listName1 != listName2) {
|
1999-04-03 18:58:04 +00:00
|
|
|
ok = PR_FALSE;
|
1998-11-25 18:41:02 +00:00
|
|
|
LogVerifyMessage(k1, k2, "child list names are not matched: ");
|
|
|
|
nsAutoString tmp;
|
|
|
|
if (nsnull != listName1) {
|
|
|
|
listName1->ToString(tmp);
|
|
|
|
fputs(tmp, stdout);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fputs("(null)", stdout);
|
|
|
|
printf(" != ");
|
|
|
|
if (nsnull != listName2) {
|
|
|
|
listName2->ToString(tmp);
|
|
|
|
fputs(tmp, stdout);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fputs("(null)", stdout);
|
|
|
|
printf("\n");
|
|
|
|
NS_IF_RELEASE(listName1);
|
|
|
|
NS_IF_RELEASE(listName2);
|
|
|
|
break;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
1998-11-25 18:41:02 +00:00
|
|
|
NS_IF_RELEASE(listName2);
|
|
|
|
listName = listName1;
|
1999-04-03 18:58:04 +00:00
|
|
|
} while (ok && (listName != nsnull));
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static nsIFrame*
|
|
|
|
FindTopFrame(nsIFrame* aRoot)
|
|
|
|
{
|
|
|
|
if (nsnull != aRoot) {
|
|
|
|
nsIContent* content;
|
|
|
|
aRoot->GetContent(&content);
|
|
|
|
if (nsnull != content) {
|
|
|
|
nsIAtom* tag;
|
|
|
|
content->GetTag(tag);
|
|
|
|
if (nsnull != tag) {
|
|
|
|
NS_RELEASE(tag);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
return aRoot;
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try one of the children
|
|
|
|
nsIFrame* kid;
|
|
|
|
aRoot->FirstChild(nsnull, &kid);
|
|
|
|
while (nsnull != kid) {
|
|
|
|
nsIFrame* result = FindTopFrame(kid);
|
|
|
|
if (nsnull != result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
kid->GetNextSibling(&kid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PresShell::CloneStyleSet(nsIStyleSet* aSet, nsIStyleSet** aResult)
|
|
|
|
{
|
|
|
|
nsIStyleSet* clone;
|
|
|
|
nsresult rv = NS_NewStyleSet(&clone);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 i, n;
|
|
|
|
n = aSet->GetNumberOfOverrideStyleSheets();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIStyleSheet* ss;
|
|
|
|
ss = aSet->GetOverrideStyleSheetAt(i);
|
|
|
|
if (nsnull != ss) {
|
|
|
|
clone->AppendOverrideStyleSheet(ss);
|
|
|
|
NS_RELEASE(ss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n = aSet->GetNumberOfDocStyleSheets();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIStyleSheet* ss;
|
|
|
|
ss = aSet->GetDocStyleSheetAt(i);
|
|
|
|
if (nsnull != ss) {
|
|
|
|
clone->AddDocStyleSheet(ss, mDocument);
|
|
|
|
NS_RELEASE(ss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n = aSet->GetNumberOfBackstopStyleSheets();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIStyleSheet* ss;
|
|
|
|
ss = aSet->GetBackstopStyleSheetAt(i);
|
|
|
|
if (nsnull != ss) {
|
|
|
|
clone->AppendBackstopStyleSheet(ss);
|
|
|
|
NS_RELEASE(ss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aResult = clone;
|
|
|
|
return NS_OK;
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
nsIPresShell* sh;
|
|
|
|
|
|
|
|
// Create a presentation context to view the new frame tree
|
|
|
|
nsresult rv;
|
1999-02-12 17:45:58 +00:00
|
|
|
PRBool isPaginated = PR_FALSE;
|
|
|
|
mPresContext->IsPaginated(&isPaginated);
|
|
|
|
if (isPaginated) {
|
1998-07-13 19:49:42 +00:00
|
|
|
rv = NS_NewPrintPreviewContext(&cx);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = NS_NewGalleyContext(&cx);
|
|
|
|
}
|
1999-04-03 18:58:04 +00:00
|
|
|
#if 1
|
|
|
|
nsISupports* container;
|
|
|
|
if (NS_SUCCEEDED(mPresContext->GetContainer(&container)) &&
|
|
|
|
(nsnull != container)) {
|
|
|
|
cx->SetContainer(container);
|
1999-04-03 21:54:32 +00:00
|
|
|
nsILinkHandler* lh;
|
|
|
|
if (NS_SUCCEEDED(container->QueryInterface(kILinkHandlerIID,
|
|
|
|
(void**)&lh))) {
|
|
|
|
cx->SetLinkHandler(lh);
|
|
|
|
NS_RELEASE(lh);
|
|
|
|
}
|
1999-04-03 18:58:04 +00:00
|
|
|
NS_RELEASE(container);
|
|
|
|
}
|
|
|
|
#endif
|
1998-07-13 19:49:42 +00:00
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create presentation context");
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
mPresContext->GetDeviceContext(getter_AddRefs(dc));
|
|
|
|
nsCOMPtr<nsIPref> prefs;
|
|
|
|
mPresContext->GetPrefs(getter_AddRefs(prefs));
|
1998-07-31 05:54:59 +00:00
|
|
|
cx->Init(dc, prefs);
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
// Get our scrolling preference
|
|
|
|
nsScrollPreference scrolling;
|
1998-08-28 04:56:56 +00:00
|
|
|
nsIView* rootView;
|
|
|
|
mViewManager->GetRootView(rootView);
|
1998-07-13 19:49:42 +00:00
|
|
|
nsIScrollableView* scrollView;
|
|
|
|
rv = rootView->QueryInterface(kScrollViewIID, (void**)&scrollView);
|
|
|
|
if (NS_OK == rv) {
|
1998-08-30 19:16:11 +00:00
|
|
|
scrollView->GetScrollPreference(scrolling);
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
1998-08-30 19:16:11 +00:00
|
|
|
nsIWidget* rootWidget;
|
|
|
|
rootView->GetWidget(rootWidget);
|
1998-07-13 19:49:42 +00:00
|
|
|
void* nativeParentWidget = rootWidget->GetNativeData(NS_NATIVE_WIDGET);
|
|
|
|
|
|
|
|
// Create a new view manager.
|
1999-04-03 18:58:04 +00:00
|
|
|
rv = nsComponentManager::CreateInstance(kViewManagerCID, nsnull,
|
|
|
|
kIViewManagerIID, (void**) &vm);
|
|
|
|
if (NS_FAILED(rv)) {
|
1998-07-13 19:49:42 +00:00
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create view manager");
|
|
|
|
}
|
1999-04-03 18:58:04 +00:00
|
|
|
rv = vm->Init(dc);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to init view manager");
|
|
|
|
}
|
1998-08-28 02:54:06 +00:00
|
|
|
|
1998-07-13 19:49:42 +00:00
|
|
|
// Create a child window of the parent that is our "root view/window"
|
|
|
|
// Create a view
|
|
|
|
nsRect tbounds;
|
|
|
|
mPresContext->GetVisibleArea(tbounds);
|
1999-04-03 18:58:04 +00:00
|
|
|
nsIView* view;
|
|
|
|
rv = nsComponentManager::CreateInstance(kViewCID, nsnull,
|
|
|
|
kIViewIID, (void **) &view);
|
|
|
|
if (NS_FAILED(rv)) {
|
1998-07-13 19:49:42 +00:00
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create scroll view");
|
|
|
|
}
|
1999-04-03 18:58:04 +00:00
|
|
|
rv = view->Init(vm, tbounds, nsnull);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to init scroll view");
|
|
|
|
}
|
1998-11-04 04:14:10 +00: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 19:49:42 +00:00
|
|
|
// 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);
|
1999-04-03 18:58:04 +00:00
|
|
|
|
1998-11-25 18:41:02 +00:00
|
|
|
// Create a new presentation shell to view the document. Use the
|
|
|
|
// exact same style information that this document has.
|
1999-04-30 09:04:36 +00:00
|
|
|
nsCOMPtr<nsIStyleSet> newSet;
|
|
|
|
rv = CloneStyleSet(mStyleSet, getter_AddRefs(newSet));
|
1999-04-03 18:58:04 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to clone style set");
|
|
|
|
rv = mDocument->CreateShell(cx, vm, newSet, &sh);
|
1998-07-13 19:49:42 +00:00
|
|
|
NS_ASSERTION(NS_OK == rv, "failed to create presentation shell");
|
1999-04-03 18:58:04 +00:00
|
|
|
vm->SetViewObserver((nsIViewObserver *)((PresShell*)sh));
|
1998-11-25 18:41:02 +00:00
|
|
|
sh->InitialReflow(r.width, r.height);
|
1998-07-13 19:49:42 +00:00
|
|
|
|
|
|
|
// Now that the document has been reflowed, use its frame tree to
|
|
|
|
// compare against our frame tree.
|
1998-12-29 04:45:18 +00:00
|
|
|
nsIFrame* root1;
|
1999-02-12 17:45:58 +00:00
|
|
|
GetRootFrame(&root1);
|
1999-04-03 18:58:04 +00:00
|
|
|
nsIFrame* root2;
|
1999-02-12 17:45:58 +00:00
|
|
|
sh->GetRootFrame(&root2);
|
1999-04-03 18:58:04 +00:00
|
|
|
#if 0
|
|
|
|
root1 = FindTopFrame(root1);
|
|
|
|
root2 = FindTopFrame(root2);
|
|
|
|
#endif
|
|
|
|
if (!CompareTrees(root1, root2)) {
|
1999-04-20 00:24:21 +00:00
|
|
|
printf("Verify reflow failed, primary tree:\n");
|
|
|
|
root1->List(stdout, 0);
|
|
|
|
printf("Verification tree:\n");
|
|
|
|
root2->List(stdout, 0);
|
1999-04-03 18:58:04 +00:00
|
|
|
}
|
1998-07-13 19:49:42 +00:00
|
|
|
|
1999-04-03 18:58:04 +00:00
|
|
|
// printf("Incremental reflow doomed view tree:\n");
|
|
|
|
// view->List(stdout, 1);
|
1999-04-20 00:24:21 +00:00
|
|
|
// view->SetVisibility(nsViewVisibility_kHide);
|
|
|
|
cx->Stop();
|
1999-04-03 18:58:04 +00:00
|
|
|
cx->SetContainer(nsnull);
|
1998-07-13 19:49:42 +00:00
|
|
|
NS_RELEASE(cx);
|
1999-04-03 18:58:04 +00:00
|
|
|
sh->EndObservingDocument();
|
1998-07-13 19:49:42 +00:00
|
|
|
NS_RELEASE(sh);
|
1999-04-03 18:58:04 +00:00
|
|
|
NS_RELEASE(vm);
|
1998-07-13 19:49:42 +00:00
|
|
|
}
|
|
|
|
#endif
|