1999-08-04 07:39:34 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-08-04 07:39:34 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-08-04 07:39:34 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-08-04 07:39:34 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2000-05-03 03:07:11 +04:00
|
|
|
*
|
|
|
|
* This Original Code has been modified by IBM Corporation. Modifications made by IBM
|
|
|
|
* described herein are Copyright (c) International Business Machines Corporation, 2000.
|
|
|
|
* Modifications to Mozilla code or documentation identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
|
1999-08-04 07:39:34 +04:00
|
|
|
*/
|
|
|
|
#include "nsIFrameManager.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIStyleSet.h"
|
1999-09-04 03:35:41 +04:00
|
|
|
#include "nsIStyleContext.h"
|
1999-09-21 11:53:14 +04:00
|
|
|
#include "nsStyleChangeList.h"
|
1999-08-06 00:17:44 +04:00
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
1999-08-04 07:39:34 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-08-06 00:17:44 +04:00
|
|
|
#include "prthread.h"
|
1999-08-04 07:39:34 +04:00
|
|
|
#include "plhash.h"
|
|
|
|
#include "nsDST.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
2000-05-17 02:05:47 +04:00
|
|
|
#include "nsHTMLAtoms.h"
|
1999-09-21 11:53:14 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIStyleRule.h"
|
1999-08-04 07:39:34 +04:00
|
|
|
#endif
|
1999-08-31 18:35:50 +04:00
|
|
|
#include "nsILayoutHistoryState.h"
|
|
|
|
#include "nsIStatefulFrame.h"
|
2000-01-14 12:28:54 +03:00
|
|
|
#include "nsIPresState.h"
|
1999-08-31 18:35:50 +04:00
|
|
|
#include "nsIContent.h"
|
1999-10-16 03:14:44 +04:00
|
|
|
#include "nsINameSpaceManager.h"
|
2000-05-26 03:02:31 +04:00
|
|
|
#include "nsIXMLContent.h"
|
2000-11-28 01:00:33 +03:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIBindingManager.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
1999-08-04 07:39:34 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
#include "nsIHTMLDocument.h"
|
|
|
|
#include "nsIDOMHTMLDocument.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
|
|
|
#include "nsIForm.h"
|
|
|
|
#include "nsIContentList.h"
|
|
|
|
|
2000-09-13 02:47:09 +04:00
|
|
|
#define NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
|
|
|
|
#ifdef NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#undef NOISY_DEBUG
|
|
|
|
#else
|
|
|
|
#undef NOISY_DEBUG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
#define NOISY_TRACE(_msg) \
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("%s",_msg);
|
2000-09-13 02:47:09 +04:00
|
|
|
#define NOISY_TRACE_FRAME(_msg,_frame) \
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("%s ",_msg); nsFrame::ListTag(stdout,_frame); printf("\n");
|
2000-09-13 02:47:09 +04:00
|
|
|
#else
|
|
|
|
#define NOISY_TRACE(_msg);
|
|
|
|
#define NOISY_TRACE_FRAME(_msg,_frame);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
// Class IID's
|
|
|
|
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
1999-08-04 07:39:34 +04:00
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
// IID's
|
1999-08-04 07:39:34 +04:00
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
1999-08-04 07:39:34 +04:00
|
|
|
|
|
|
|
// Thin veneer around an NSPR hash table. Provides a map from a key that's
|
|
|
|
// a pointer to a value that's also a pointer.
|
|
|
|
class FrameHashTable {
|
|
|
|
public:
|
|
|
|
FrameHashTable(PRUint32 aNumBuckets = 16);
|
|
|
|
~FrameHashTable();
|
|
|
|
|
|
|
|
// Gets the value associated with the specified key
|
|
|
|
void* Get(void* aKey);
|
|
|
|
|
|
|
|
// Creates an association between the key and value. Returns the previous
|
|
|
|
// value associated with the key, or NULL if there was none
|
|
|
|
void* Put(void* aKey, void* aValue);
|
|
|
|
|
|
|
|
// Removes association for the key, and returns its associated value
|
|
|
|
void* Remove(void* aKey);
|
|
|
|
|
|
|
|
// Removes all entries from the hash table
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void Dump(FILE* fp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PLHashTable* mTable;
|
|
|
|
};
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(UndisplayedNode)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
2000-03-25 00:50:40 +03:00
|
|
|
class UndisplayedNode {
|
|
|
|
public:
|
1999-10-02 08:25:29 +04:00
|
|
|
UndisplayedNode(nsIContent* aContent, nsIStyleContext* aStyle)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(UndisplayedNode);
|
1999-10-02 08:25:29 +04:00
|
|
|
mContent = aContent;
|
|
|
|
mStyle = aStyle;
|
|
|
|
NS_ADDREF(mStyle);
|
|
|
|
mNext = nsnull;
|
|
|
|
}
|
|
|
|
UndisplayedNode(nsIStyleContext* aPseudoStyle)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(UndisplayedNode);
|
1999-10-02 08:25:29 +04:00
|
|
|
mContent = nsnull;
|
|
|
|
mStyle = aPseudoStyle;
|
|
|
|
NS_ADDREF(mStyle);
|
|
|
|
mNext = nsnull;
|
|
|
|
}
|
|
|
|
~UndisplayedNode(void)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(UndisplayedNode);
|
1999-10-02 08:25:29 +04:00
|
|
|
NS_RELEASE(mStyle);
|
1999-10-05 03:33:23 +04:00
|
|
|
if (mNext) {
|
|
|
|
delete mNext;
|
|
|
|
}
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* mContent;
|
|
|
|
nsIStyleContext* mStyle;
|
|
|
|
UndisplayedNode* mNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
class UndisplayedMap {
|
|
|
|
public:
|
|
|
|
UndisplayedMap(PRUint32 aNumBuckets = 16);
|
|
|
|
~UndisplayedMap(void);
|
|
|
|
|
|
|
|
UndisplayedNode* GetFirstNode(nsIContent* aParentContent);
|
|
|
|
|
|
|
|
nsresult AddNodeFor(nsIContent* aParentContent, nsIContent* aChild, nsIStyleContext* aStyle);
|
|
|
|
nsresult AddNodeFor(nsIContent* aParentContent, nsIStyleContext* aPseudoStyle);
|
|
|
|
|
|
|
|
nsresult RemoveNodeFor(nsIContent* aParentContent, UndisplayedNode* aNode);
|
|
|
|
nsresult RemoveNodesFor(nsIContent* aParentContent);
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
nsresult GetNodeFor(nsIContent* aContent, nsIStyleContext** aResult);
|
|
|
|
|
1999-10-02 08:25:29 +04:00
|
|
|
// Removes all entries from the hash table
|
|
|
|
void Clear(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PLHashEntry** GetEntryFor(nsIContent* aParentContent);
|
|
|
|
nsresult AppendNodeFor(UndisplayedNode* aNode, nsIContent* aParentContent);
|
|
|
|
|
|
|
|
PLHashTable* mTable;
|
|
|
|
PLHashEntry** mLastLookup;
|
|
|
|
};
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
1999-08-04 07:39:34 +04:00
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
class FrameManager;
|
1999-08-04 07:39:34 +04:00
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
// A CantRenderReplacedElementEvent has a weak pointer to the frame
|
|
|
|
// manager, and the frame manager has a weak pointer to the event.
|
|
|
|
// The event queue owns the event and the FrameManager will delete
|
|
|
|
// the event if it's going to go away.
|
1999-08-06 00:17:44 +04:00
|
|
|
struct CantRenderReplacedElementEvent : public PLEvent {
|
|
|
|
CantRenderReplacedElementEvent(FrameManager* aFrameManager, nsIFrame* aFrame);
|
1999-08-04 07:39:34 +04:00
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
nsIFrame* mFrame; // the frame that can't be rendered
|
|
|
|
CantRenderReplacedElementEvent* mNext; // next event in the list
|
|
|
|
};
|
1999-08-04 07:39:34 +04:00
|
|
|
|
|
|
|
class FrameManager : public nsIFrameManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FrameManager();
|
|
|
|
virtual ~FrameManager();
|
|
|
|
|
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIFrameManager
|
1999-08-06 00:17:44 +04:00
|
|
|
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIStyleSet* aStyleSet);
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_IMETHOD Destroy();
|
1999-08-04 07:39:34 +04:00
|
|
|
|
1999-10-19 02:20:37 +04:00
|
|
|
// Gets and sets the root frame
|
|
|
|
NS_IMETHOD GetRootFrame(nsIFrame** aRootFrame) const;
|
|
|
|
NS_IMETHOD SetRootFrame(nsIFrame* aRootFrame);
|
|
|
|
|
2000-06-01 02:33:12 +04:00
|
|
|
// Get the canvas frame: searches from the Root frame down, may be null
|
|
|
|
NS_IMETHOD GetCanvasFrame(nsIPresContext* aPresContext, nsIFrame** aCanvasFrame) const;
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
// Primary frame functions
|
1999-08-05 07:09:22 +04:00
|
|
|
NS_IMETHOD GetPrimaryFrameFor(nsIContent* aContent, nsIFrame** aPrimaryFrame);
|
1999-08-04 07:39:34 +04:00
|
|
|
NS_IMETHOD SetPrimaryFrameFor(nsIContent* aContent,
|
|
|
|
nsIFrame* aPrimaryFrame);
|
|
|
|
NS_IMETHOD ClearPrimaryFrameMap();
|
|
|
|
|
|
|
|
// Placeholder frame functions
|
|
|
|
NS_IMETHOD GetPlaceholderFrameFor(nsIFrame* aFrame,
|
|
|
|
nsIFrame** aPlaceholderFrame) const;
|
|
|
|
NS_IMETHOD SetPlaceholderFrameFor(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aPlaceholderFrame);
|
|
|
|
NS_IMETHOD ClearPlaceholderFrameMap();
|
|
|
|
|
1999-10-02 08:25:29 +04:00
|
|
|
// Undisplayed content functions
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHOD GetUndisplayedContent(nsIContent* aContent, nsIStyleContext** aStyleContext);
|
1999-10-02 08:25:29 +04:00
|
|
|
NS_IMETHOD SetUndisplayedContent(nsIContent* aContent, nsIStyleContext* aStyleContext);
|
|
|
|
NS_IMETHOD SetUndisplayedPseudoIn(nsIStyleContext* aPseudoContext,
|
|
|
|
nsIContent* aParentContent);
|
|
|
|
NS_IMETHOD ClearUndisplayedContentIn(nsIContent* aContent, nsIContent* aParentContent);
|
|
|
|
NS_IMETHOD ClearAllUndisplayedContentIn(nsIContent* aParentContent);
|
|
|
|
NS_IMETHOD ClearUndisplayedContentMap();
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
// Functions for manipulating the frame model
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD AppendFrames(nsIPresContext* aPresContext,
|
1999-08-04 07:39:34 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList);
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD InsertFrames(nsIPresContext* aPresContext,
|
1999-08-04 07:39:34 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList);
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD RemoveFrame(nsIPresContext* aPresContext,
|
1999-08-04 07:39:34 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame);
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD ReplaceFrame(nsIPresContext* aPresContext,
|
1999-08-04 07:39:34 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame,
|
|
|
|
nsIFrame* aNewFrame);
|
1999-08-06 00:17:44 +04:00
|
|
|
|
|
|
|
NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame);
|
|
|
|
|
|
|
|
NS_IMETHOD NotifyDestroyingFrame(nsIFrame* aFrame);
|
1999-08-04 07:39:34 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD ReParentStyleContext(nsIPresContext* aPresContext,
|
1999-09-04 03:35:41 +04:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIStyleContext* aNewParentContext);
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD ComputeStyleChangeFor(nsIPresContext* aPresContext,
|
1999-09-21 11:53:14 +04:00
|
|
|
nsIFrame* aFrame,
|
1999-10-16 03:14:44 +04:00
|
|
|
PRInt32 aAttrNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
1999-09-21 11:53:14 +04:00
|
|
|
nsStyleChangeList& aChangeList,
|
|
|
|
PRInt32 aMinChange,
|
|
|
|
PRInt32& aTopLevelChange);
|
2000-05-16 06:43:33 +04:00
|
|
|
NS_IMETHOD AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
|
|
|
|
PRBool &aAffects);
|
1999-09-04 03:35:41 +04:00
|
|
|
|
2000-06-15 04:35:46 +04:00
|
|
|
// Capture state from the entire frame heirarchy and store in aState
|
1999-10-26 08:44:41 +04:00
|
|
|
NS_IMETHOD CaptureFrameState(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState);
|
|
|
|
NS_IMETHOD RestoreFrameState(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState);
|
2000-06-15 04:35:46 +04:00
|
|
|
// Add/restore state for one frame (special, global type, like scroll position)
|
|
|
|
NS_IMETHOD CaptureFrameStateFor(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState,
|
|
|
|
nsIStatefulFrame::SpecialStateID aID = nsIStatefulFrame::eNoID);
|
|
|
|
NS_IMETHOD RestoreFrameStateFor(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState,
|
|
|
|
nsIStatefulFrame::SpecialStateID aID = nsIStatefulFrame::eNoID);
|
2001-05-30 15:26:21 +04:00
|
|
|
NS_IMETHOD GenerateStateKey(nsIContent* aContent,
|
|
|
|
nsIStatefulFrame::SpecialStateID aID,
|
|
|
|
nsCString& aString);
|
1999-08-31 18:35:50 +04:00
|
|
|
|
1999-10-16 04:55:48 +04:00
|
|
|
// Gets and sets properties on a given frame
|
|
|
|
NS_IMETHOD GetFrameProperty(nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPropertyName,
|
1999-10-19 08:52:33 +04:00
|
|
|
PRUint32 aOptions,
|
1999-10-16 04:55:48 +04:00
|
|
|
void** aPropertyValue);
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_IMETHOD SetFrameProperty(nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue,
|
|
|
|
NSFMPropertyDtorFunc aPropDtorFunc);
|
1999-10-16 04:55:48 +04:00
|
|
|
NS_IMETHOD RemoveFrameProperty(nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPropertyName);
|
|
|
|
|
2001-06-04 04:22:43 +04:00
|
|
|
NS_IMETHOD GetInsertionPoint(nsIPresShell* aShell, nsIFrame* aParent, nsIContent* aChild, nsIFrame** aResult);
|
2000-11-28 01:00:33 +03:00
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
#ifdef NS_DEBUG
|
2000-01-22 04:16:50 +03:00
|
|
|
NS_IMETHOD DebugVerifyStyleTree(nsIPresContext* aPresContext, nsIFrame* aFrame);
|
1999-09-21 11:53:14 +04:00
|
|
|
#endif
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
private:
|
1999-10-16 04:55:48 +04:00
|
|
|
struct PropertyList {
|
1999-10-21 09:11:43 +04:00
|
|
|
nsCOMPtr<nsIAtom> mName; // property name
|
|
|
|
nsDST* mFrameValueMap; // map of frame/value pairs
|
|
|
|
NSFMPropertyDtorFunc mDtorFunc; // property specific value dtor function
|
|
|
|
PropertyList* mNext;
|
|
|
|
|
|
|
|
PropertyList(nsIAtom* aName,
|
|
|
|
NSFMPropertyDtorFunc aDtorFunc,
|
|
|
|
nsDST::NodeArena* aDSTNodeArena);
|
1999-10-16 04:55:48 +04:00
|
|
|
~PropertyList();
|
|
|
|
|
|
|
|
// Removes the property associated with the given frame, and destroys
|
|
|
|
// the property value
|
1999-10-21 09:11:43 +04:00
|
|
|
PRBool RemovePropertyForFrame(nsIPresContext* aPresContext, nsIFrame* aFrame);
|
1999-10-19 18:41:55 +04:00
|
|
|
|
|
|
|
// Remove and destroy all remaining properties
|
1999-10-21 09:11:43 +04:00
|
|
|
void RemoveAllProperties(nsIPresContext* aPresContext);
|
1999-10-16 04:55:48 +04:00
|
|
|
};
|
|
|
|
|
1999-10-18 23:02:09 +04:00
|
|
|
nsIPresShell* mPresShell; // weak link, because the pres shell owns us
|
|
|
|
nsIStyleSet* mStyleSet; // weak link. pres shell holds a reference
|
1999-10-19 02:20:37 +04:00
|
|
|
nsIFrame* mRootFrame;
|
1999-10-18 23:02:09 +04:00
|
|
|
nsDST::NodeArena* mDSTNodeArena; // weak link. DST owns
|
1999-08-06 00:17:44 +04:00
|
|
|
nsDST* mPrimaryFrameMap;
|
|
|
|
FrameHashTable* mPlaceholderMap;
|
1999-10-02 08:25:29 +04:00
|
|
|
UndisplayedMap* mUndisplayedMap;
|
1999-08-06 00:17:44 +04:00
|
|
|
CantRenderReplacedElementEvent* mPostedEvents;
|
1999-10-16 04:55:48 +04:00
|
|
|
PropertyList* mPropertyList;
|
2001-05-30 15:26:21 +04:00
|
|
|
nsCOMPtr<nsIContentList> mHTMLForms;
|
|
|
|
nsCOMPtr<nsIContentList> mHTMLFormControls;
|
1999-10-02 08:25:29 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
void ReResolveStyleContext(nsIPresContext* aPresContext,
|
1999-09-21 11:53:14 +04:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIStyleContext* aParentContext,
|
|
|
|
nsIContent* aParentContent,
|
1999-10-16 03:14:44 +04:00
|
|
|
PRInt32 aAttrNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
1999-09-21 11:53:14 +04:00
|
|
|
nsStyleChangeList& aChangeList,
|
|
|
|
PRInt32 aMinChange,
|
|
|
|
PRInt32& aResultChange);
|
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
nsresult RevokePostedEvents();
|
1999-08-06 00:17:44 +04:00
|
|
|
CantRenderReplacedElementEvent** FindPostedEventFor(nsIFrame* aFrame);
|
|
|
|
void DequeuePostedEventFor(nsIFrame* aFrame);
|
1999-10-19 18:41:55 +04:00
|
|
|
void DestroyPropertyList(nsIPresContext* aPresContext);
|
1999-10-16 04:55:48 +04:00
|
|
|
PropertyList* GetPropertyListFor(nsIAtom* aPropertyName) const;
|
1999-10-19 18:41:55 +04:00
|
|
|
void RemoveAllPropertiesFor(nsIPresContext* aPresContext, nsIFrame* aFrame);
|
1999-08-06 00:17:44 +04:00
|
|
|
|
1999-08-06 18:34:32 +04:00
|
|
|
friend struct CantRenderReplacedElementEvent;
|
|
|
|
static void HandlePLEvent(CantRenderReplacedElementEvent* aEvent);
|
|
|
|
static void DestroyPLEvent(CantRenderReplacedElementEvent* aEvent);
|
1999-08-04 07:39:34 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_LAYOUT nsresult
|
|
|
|
NS_NewFrameManager(nsIFrameManager** aInstancePtrResult)
|
|
|
|
{
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
1999-08-06 18:34:32 +04:00
|
|
|
if (!aInstancePtrResult) {
|
1999-08-04 07:39:34 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
FrameManager* it = new FrameManager;
|
1999-08-06 18:34:32 +04:00
|
|
|
if (!it) {
|
1999-08-04 07:39:34 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2000-02-03 01:24:56 +03:00
|
|
|
return it->QueryInterface(NS_GET_IID(nsIFrameManager), (void **)aInstancePtrResult);
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FrameManager::FrameManager()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
NS_INIT_REFCNT();
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FrameManager::~FrameManager()
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ASSERTION(!mPresShell, "FrameManager::Destroy never called");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(FrameManager, nsIFrameManager)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::Init(nsIPresShell* aPresShell,
|
|
|
|
nsIStyleSet* aStyleSet)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aPresShell, "null aPresShell");
|
|
|
|
NS_ASSERTION(aStyleSet, "null aStyleSet");
|
|
|
|
|
|
|
|
mPresShell = aPresShell;
|
|
|
|
mStyleSet = aStyleSet;
|
|
|
|
|
|
|
|
// Allocate the node arena that's shared by all the DST objects
|
|
|
|
mDSTNodeArena = nsDST::NewMemoryArena();
|
|
|
|
if (!mDSTNodeArena) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Force the forms and form control content lists to be added as
|
|
|
|
// document observers *before* us (pres shell) so they will be
|
|
|
|
// up to date when we try to use them.
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
mPresShell->GetDocument(getter_AddRefs(document));
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDocument(do_QueryInterface(document));
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> domHtmlDocument(do_QueryInterface(htmlDocument));
|
|
|
|
if (domHtmlDocument) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> forms;
|
|
|
|
domHtmlDocument->GetForms(getter_AddRefs(forms));
|
|
|
|
mHTMLForms = do_QueryInterface(forms);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> formControls;
|
|
|
|
htmlDocument->GetFormControlElements(getter_AddRefs(formControls));
|
|
|
|
mHTMLFormControls = do_QueryInterface(formControls);
|
|
|
|
}
|
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::Destroy()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mPresShell, "Frame manager already shut down.");
|
|
|
|
|
1999-10-19 18:41:55 +04:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
mPresShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
1999-10-19 02:20:37 +04:00
|
|
|
// Destroy the frame hierarchy. Don't destroy the property lists until after
|
|
|
|
// we've destroyed the frame hierarchy because some frames may expect to be
|
|
|
|
// able to retrieve their properties during destruction
|
|
|
|
if (mRootFrame) {
|
1999-11-24 09:03:41 +03:00
|
|
|
mRootFrame->Destroy(presContext);
|
1999-10-19 02:20:37 +04:00
|
|
|
mRootFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-10-19 23:06:37 +04:00
|
|
|
delete mPrimaryFrameMap;
|
|
|
|
delete mPlaceholderMap;
|
|
|
|
delete mUndisplayedMap;
|
1999-10-19 18:41:55 +04:00
|
|
|
DestroyPropertyList(presContext);
|
1999-08-04 07:39:34 +04:00
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
// If we're not going to be used anymore, we should revoke the
|
|
|
|
// pending |CantRenderReplacedElementEvent|s being sent to us.
|
|
|
|
nsresult rv = RevokePostedEvents();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "RevokePostedEvents failed: might crash");
|
1999-10-18 23:02:09 +04:00
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
mPresShell = nsnull; // mPresShell isn't valid anymore. We
|
|
|
|
// won't use it, either, but we check it
|
|
|
|
// at the start of every function so that we'll
|
|
|
|
// be OK when nsIPresShell is converted to IDL.
|
1999-10-18 23:02:09 +04:00
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
return rv;
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
|
|
|
|
1999-10-19 02:20:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::GetRootFrame(nsIFrame** aRootFrame) const
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-19 02:20:37 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aRootFrame);
|
|
|
|
*aRootFrame = mRootFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::SetRootFrame(nsIFrame* aRootFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-19 02:20:37 +04:00
|
|
|
NS_PRECONDITION(!mRootFrame, "already have a root frame");
|
|
|
|
if (mRootFrame) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRootFrame = aRootFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-01 02:33:12 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::GetCanvasFrame(nsIPresContext* aPresContext, nsIFrame** aCanvasFrame) const
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2000-06-01 02:33:12 +04:00
|
|
|
NS_PRECONDITION(aCanvasFrame, "aCanvasFrame argument cannot be null");
|
|
|
|
NS_PRECONDITION(aPresContext, "aPresContext argument cannot be null");
|
|
|
|
|
|
|
|
*aCanvasFrame = nsnull;
|
|
|
|
if (mRootFrame) {
|
|
|
|
// walk the children of the root frame looking for a frame with type==canvas
|
|
|
|
// start at the root
|
|
|
|
nsIFrame* childFrame = mRootFrame;
|
|
|
|
while (childFrame) {
|
|
|
|
// get each sibling of the child and check them, startig at the child
|
|
|
|
nsIFrame *siblingFrame = childFrame;
|
|
|
|
while (siblingFrame) {
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
siblingFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (frameType.get() == nsLayoutAtoms::canvasFrame) {
|
|
|
|
// this is it: set the out-arg and stop looking
|
|
|
|
*aCanvasFrame = siblingFrame;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
siblingFrame->GetNextSibling(&siblingFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// move on to the child's child
|
|
|
|
childFrame->FirstChild(aPresContext, nsnull, &childFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
// Primary frame functions
|
|
|
|
NS_IMETHODIMP
|
1999-08-05 07:09:22 +04:00
|
|
|
FrameManager::GetPrimaryFrameFor(nsIContent* aContent, nsIFrame** aResult)
|
1999-08-04 07:39:34 +04:00
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_ARG_POINTER(aContent);
|
2001-01-17 01:10:04 +03:00
|
|
|
if (!aContent || !aResult) {
|
1999-08-04 07:39:34 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-01-17 01:10:04 +03:00
|
|
|
*aResult = nsnull; // initialize out param
|
1999-08-04 07:39:34 +04:00
|
|
|
|
2001-01-17 01:10:04 +03:00
|
|
|
nsresult rv;
|
1999-08-06 18:34:32 +04:00
|
|
|
if (mPrimaryFrameMap) {
|
1999-10-21 09:11:43 +04:00
|
|
|
mPrimaryFrameMap->Search(aContent, 0, (void**)aResult);
|
1999-08-04 07:39:34 +04:00
|
|
|
if (!*aResult) {
|
2001-01-17 01:10:04 +03:00
|
|
|
// XXX: todo: Add a lookup into the undisplay map to skip searches
|
|
|
|
// if we already know the content has no frame.
|
|
|
|
// nsCSSFrameConstructor calls SetUndisplayedContent() for every
|
|
|
|
// content node that has display: none.
|
|
|
|
// Today, the undisplay map doesn't quite support what we need.
|
|
|
|
// We need to see if we can add a method to make a search for aContent
|
|
|
|
// very fast in the embedded hash table.
|
|
|
|
// This would almost completely remove the lookup penalty for things
|
|
|
|
// like <SCRIPT> and comments in very large documents.
|
1999-08-04 07:39:34 +04:00
|
|
|
nsCOMPtr<nsIStyleSet> styleSet;
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
|
|
|
|
// Give the frame construction code the opportunity to return the
|
|
|
|
// frame that maps the content object
|
|
|
|
mPresShell->GetStyleSet(getter_AddRefs(styleSet));
|
2001-01-17 01:10:04 +03:00
|
|
|
NS_ASSERTION(styleSet, "bad style set");
|
1999-08-04 07:39:34 +04:00
|
|
|
mPresShell->GetPresContext(getter_AddRefs(presContext));
|
2001-01-17 01:10:04 +03:00
|
|
|
NS_ASSERTION(presContext, "bad presContext");
|
|
|
|
if (!styleSet || !presContext) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the prev sibling of aContent has a cached primary frame,
|
|
|
|
// pass that data in to the style set to speed things up
|
|
|
|
// if any methods in here fail, don't report that failure
|
|
|
|
// we're just trying to enhance performance here, not test for correctness
|
|
|
|
nsFindFrameHint hint;
|
|
|
|
nsCOMPtr<nsIContent> prevSibling, parent;
|
|
|
|
rv = aContent->GetParent(*getter_AddRefs(parent));
|
|
|
|
if (NS_SUCCEEDED(rv) && parent)
|
|
|
|
{
|
|
|
|
PRInt32 index;
|
|
|
|
rv = parent->IndexOf(aContent, index);
|
|
|
|
if (NS_SUCCEEDED(rv) && index>0) // no use looking if it's the first child
|
|
|
|
{
|
|
|
|
rv = parent->ChildAt(index-1, *getter_AddRefs(prevSibling));
|
|
|
|
if (NS_SUCCEEDED(rv) && prevSibling)
|
|
|
|
{
|
|
|
|
mPrimaryFrameMap->Search(prevSibling.get(), 0, (void**)&hint.mPrimaryFrameForPrevSibling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk the frame tree to find the frame that maps aContent.
|
|
|
|
// Use the hint if we have it.
|
|
|
|
styleSet->FindPrimaryFrameFor(presContext, this, aContent, aResult,
|
|
|
|
hint.mPrimaryFrameForPrevSibling ? &hint : nsnull);
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::SetPrimaryFrameFor(nsIContent* aContent,
|
|
|
|
nsIFrame* aPrimaryFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aContent);
|
2001-01-17 01:10:04 +03:00
|
|
|
// it's ok if aPrimaryFrame is null
|
1999-08-04 07:39:34 +04:00
|
|
|
|
|
|
|
// If aPrimaryFrame is NULL, then remove the mapping
|
|
|
|
if (!aPrimaryFrame) {
|
|
|
|
if (mPrimaryFrameMap) {
|
|
|
|
mPrimaryFrameMap->Remove(aContent);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Create a new DST if necessary
|
|
|
|
if (!mPrimaryFrameMap) {
|
1999-10-18 23:02:09 +04:00
|
|
|
mPrimaryFrameMap = new nsDST(mDSTNodeArena);
|
1999-08-04 07:39:34 +04:00
|
|
|
if (!mPrimaryFrameMap) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a mapping to the hash table
|
1999-10-21 09:11:43 +04:00
|
|
|
mPrimaryFrameMap->Insert(aContent, (void*)aPrimaryFrame, nsnull);
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
2001-01-17 01:10:04 +03:00
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::ClearPrimaryFrameMap()
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-08-04 07:39:34 +04:00
|
|
|
if (mPrimaryFrameMap) {
|
|
|
|
mPrimaryFrameMap->Clear();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Placeholder frame functions
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::GetPlaceholderFrameFor(nsIFrame* aFrame,
|
|
|
|
nsIFrame** aResult) const
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_ARG_POINTER(aFrame);
|
1999-08-06 18:34:32 +04:00
|
|
|
if (!aResult || !aFrame) {
|
1999-08-04 07:39:34 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-08-06 18:34:32 +04:00
|
|
|
if (mPlaceholderMap) {
|
1999-08-04 07:39:34 +04:00
|
|
|
*aResult = (nsIFrame*)mPlaceholderMap->Get(aFrame);
|
1999-08-06 18:34:32 +04:00
|
|
|
} else {
|
|
|
|
*aResult = nsnull;
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::SetPlaceholderFrameFor(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aPlaceholderFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aFrame);
|
1999-08-04 07:39:34 +04: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
|
|
|
|
|
|
|
|
// If aPlaceholderFrame is NULL, then remove the mapping
|
|
|
|
if (!aPlaceholderFrame) {
|
|
|
|
if (mPlaceholderMap) {
|
|
|
|
mPlaceholderMap->Remove(aFrame);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 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
|
|
|
|
mPlaceholderMap->Put(aFrame, (void*)aPlaceholderFrame);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::ClearPlaceholderFrameMap()
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-08-04 07:39:34 +04:00
|
|
|
if (mPlaceholderMap) {
|
|
|
|
mPlaceholderMap->Clear();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::GetUndisplayedContent(nsIContent* aContent, nsIStyleContext** aResult)
|
|
|
|
{
|
|
|
|
if (!aContent || !aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = nsnull; // initialize out param
|
|
|
|
|
|
|
|
if (mUndisplayedMap)
|
|
|
|
mUndisplayedMap->GetNodeFor(aContent, aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-02 08:25:29 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::SetUndisplayedContent(nsIContent* aContent,
|
|
|
|
nsIStyleContext* aStyleContext)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-02 08:25:29 +04:00
|
|
|
if (! mUndisplayedMap) {
|
|
|
|
mUndisplayedMap = new UndisplayedMap;
|
|
|
|
}
|
|
|
|
if (mUndisplayedMap) {
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIContent* parent = nsnull;
|
|
|
|
aContent->GetParent(parent);
|
|
|
|
if (parent) {
|
|
|
|
result = mUndisplayedMap->AddNodeFor(parent, aContent, aStyleContext);
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::SetUndisplayedPseudoIn(nsIStyleContext* aPseudoContext,
|
|
|
|
nsIContent* aParentContent)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-02 08:25:29 +04:00
|
|
|
if (! mUndisplayedMap) {
|
|
|
|
mUndisplayedMap = new UndisplayedMap;
|
|
|
|
}
|
|
|
|
if (mUndisplayedMap) {
|
|
|
|
return mUndisplayedMap->AddNodeFor(aParentContent, aPseudoContext);
|
|
|
|
}
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::ClearUndisplayedContentIn(nsIContent* aContent, nsIContent* aParentContent)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-02 08:25:29 +04:00
|
|
|
if (mUndisplayedMap) {
|
|
|
|
UndisplayedNode* node = mUndisplayedMap->GetFirstNode(aParentContent);
|
|
|
|
while (node) {
|
|
|
|
if (node->mContent == aContent) {
|
|
|
|
return mUndisplayedMap->RemoveNodeFor(aParentContent, node);
|
|
|
|
}
|
|
|
|
node = node->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::ClearAllUndisplayedContentIn(nsIContent* aParentContent)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-02 08:25:29 +04:00
|
|
|
if (mUndisplayedMap) {
|
|
|
|
return mUndisplayedMap->RemoveNodesFor(aParentContent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::ClearUndisplayedContentMap()
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-02 08:25:29 +04:00
|
|
|
if (mUndisplayedMap) {
|
|
|
|
mUndisplayedMap->Clear();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
FrameManager::AppendFrames(nsIPresContext* aPresContext,
|
1999-08-04 07:39:34 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2000-11-28 01:00:33 +03:00
|
|
|
nsIFrame* insertionPoint = nsnull;
|
2001-06-04 04:22:43 +04:00
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
aFrameList->GetContent(getter_AddRefs(child));
|
|
|
|
GetInsertionPoint(&aPresShell, aParentFrame, child, &insertionPoint);
|
|
|
|
if (insertionPoint && (insertionPoint != aParentFrame)) {
|
2000-11-28 01:00:33 +03:00
|
|
|
// First append the frames.
|
|
|
|
nsresult rv = insertionPoint->AppendFrames(aPresContext, aPresShell, aListName, aFrameList);
|
|
|
|
|
|
|
|
// Now reparent the style contexts to keep the frames in sync.
|
|
|
|
nsIFrame* walkit = aFrameList;
|
|
|
|
nsCOMPtr<nsIStyleContext> styleContext;
|
|
|
|
insertionPoint->GetStyleContext(getter_AddRefs(styleContext));
|
|
|
|
while (walkit) {
|
2000-11-28 13:10:41 +03:00
|
|
|
walkit->SetParent(insertionPoint);
|
2000-11-28 01:00:33 +03:00
|
|
|
aPresContext->ReParentStyleContext(walkit, styleContext);
|
|
|
|
walkit->GetNextSibling(&walkit);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
return aParentFrame->AppendFrames(aPresContext, aPresShell, aListName,
|
|
|
|
aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
FrameManager::InsertFrames(nsIPresContext* aPresContext,
|
1999-08-04 07:39:34 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2000-11-28 01:00:33 +03:00
|
|
|
nsIFrame* insertionPoint = nsnull;
|
2001-06-04 04:22:43 +04:00
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
aFrameList->GetContent(getter_AddRefs(child));
|
|
|
|
GetInsertionPoint(&aPresShell, aParentFrame, child, &insertionPoint);
|
|
|
|
if (insertionPoint && (insertionPoint != aParentFrame)) {
|
2000-11-28 01:00:33 +03:00
|
|
|
// First insert the frames.
|
|
|
|
nsresult rv = insertionPoint->InsertFrames(aPresContext, aPresShell, aListName, aPrevFrame, aFrameList);
|
|
|
|
|
|
|
|
// Now reparent the style contexts to keep the frames in sync.
|
|
|
|
nsIFrame* walkit = aFrameList;
|
|
|
|
nsCOMPtr<nsIStyleContext> styleContext;
|
|
|
|
insertionPoint->GetStyleContext(getter_AddRefs(styleContext));
|
|
|
|
while (walkit) {
|
2000-11-28 13:10:41 +03:00
|
|
|
walkit->SetParent(insertionPoint);
|
2000-11-28 01:00:33 +03:00
|
|
|
aPresContext->ReParentStyleContext(walkit, styleContext);
|
|
|
|
walkit->GetNextSibling(&walkit);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (aPrevFrame) {
|
|
|
|
// Insert aFrameList after the last bidi continuation of aPrevFrame.
|
|
|
|
nsIFrame* nextBidi;
|
|
|
|
for (; ;) {
|
|
|
|
GetFrameProperty(aPrevFrame, nsLayoutAtoms::nextBidi, 0, (void**) &nextBidi);
|
|
|
|
if (!nextBidi) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aPrevFrame = nextBidi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
return aParentFrame->InsertFrames(aPresContext, aPresShell, aListName,
|
|
|
|
aPrevFrame, aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
FrameManager::RemoveFrame(nsIPresContext* aPresContext,
|
1999-08-04 07:39:34 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2000-11-28 01:00:33 +03:00
|
|
|
nsIFrame* insertionPoint = nsnull;
|
2001-06-04 04:22:43 +04:00
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
aOldFrame->GetContent(getter_AddRefs(child));
|
|
|
|
GetInsertionPoint(&aPresShell, aParentFrame, child, &insertionPoint);
|
|
|
|
if (insertionPoint && (insertionPoint != aParentFrame))
|
2000-11-28 01:00:33 +03:00
|
|
|
return insertionPoint->RemoveFrame(aPresContext, aPresShell, aListName, aOldFrame);
|
|
|
|
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
// Don't let the parent remove next bidi. In the other cases the it should NOT be removed.
|
|
|
|
nsIFrame* nextBidi;
|
|
|
|
GetFrameProperty(aOldFrame, nsLayoutAtoms::nextBidi, 0, (void**) &nextBidi);
|
|
|
|
if (nextBidi) {
|
|
|
|
RemoveFrame(aPresContext, aPresShell, aParentFrame, aListName, nextBidi);
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
return aParentFrame->RemoveFrame(aPresContext, aPresShell, aListName,
|
|
|
|
aOldFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
FrameManager::ReplaceFrame(nsIPresContext* aPresContext,
|
1999-08-04 07:39:34 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame,
|
|
|
|
nsIFrame* aNewFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-08-04 07:39:34 +04:00
|
|
|
return aParentFrame->ReplaceFrame(aPresContext, aPresShell, aListName,
|
|
|
|
aOldFrame, aNewFrame);
|
|
|
|
}
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::NotifyDestroyingFrame(nsIFrame* aFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-08-06 00:17:44 +04:00
|
|
|
// Dequeue and destroy and posted events for this frame
|
|
|
|
DequeuePostedEventFor(aFrame);
|
1999-10-16 04:55:48 +04:00
|
|
|
|
|
|
|
// Remove all properties associated with the frame
|
1999-10-19 18:41:55 +04:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
mPresShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
RemoveAllPropertiesFor(presContext, aFrame);
|
1999-08-06 00:17:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
nsresult
|
1999-08-06 00:17:44 +04:00
|
|
|
FrameManager::RevokePostedEvents()
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
nsresult rv = NS_OK;
|
2000-06-05 07:37:33 +04:00
|
|
|
#ifdef NOISY_EVENTS
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("%p ~RevokePostedEvents() start\n", this);
|
2000-06-05 07:37:33 +04:00
|
|
|
#endif
|
1999-08-06 00:17:44 +04:00
|
|
|
if (mPostedEvents) {
|
|
|
|
mPostedEvents = nsnull;
|
|
|
|
|
|
|
|
// Revoke any events in the event queue that are owned by us
|
|
|
|
nsIEventQueueService* eventService;
|
|
|
|
|
|
|
|
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
2001-01-04 23:44:42 +03:00
|
|
|
NS_GET_IID(nsIEventQueueService),
|
1999-08-06 00:17:44 +04:00
|
|
|
(nsISupports **)&eventService);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIEventQueue> eventQueue;
|
1999-11-30 03:32:43 +03:00
|
|
|
rv = eventService->GetThreadEventQueue(NS_CURRENT_THREAD,
|
1999-08-06 00:17:44 +04:00
|
|
|
getter_AddRefs(eventQueue));
|
|
|
|
nsServiceManager::ReleaseService(kEventQueueServiceCID, eventService);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && eventQueue) {
|
2001-03-06 04:46:03 +03:00
|
|
|
rv = eventQueue->RevokeEvents(this);
|
1999-08-06 00:17:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-06-05 07:37:33 +04:00
|
|
|
#ifdef NOISY_EVENTS
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("%p ~RevokePostedEvents() end\n", this);
|
2000-06-05 07:37:33 +04:00
|
|
|
#endif
|
2001-03-06 04:46:03 +03:00
|
|
|
return rv;
|
1999-08-06 00:17:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CantRenderReplacedElementEvent**
|
|
|
|
FrameManager::FindPostedEventFor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
CantRenderReplacedElementEvent** event = &mPostedEvents;
|
|
|
|
|
|
|
|
while (*event) {
|
|
|
|
if ((*event)->mFrame == aFrame) {
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
event = &(*event)->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameManager::DequeuePostedEventFor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// 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,
|
2001-01-04 23:44:42 +03:00
|
|
|
NS_GET_IID(nsIEventQueueService),
|
1999-08-06 00:17:44 +04:00
|
|
|
(nsISupports **)&eventService);
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"will crash soon due to event holding dangling pointer to frame");
|
1999-08-06 00:17:44 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIEventQueue> eventQueue;
|
1999-11-30 03:32:43 +03:00
|
|
|
rv = eventService->GetThreadEventQueue(NS_CURRENT_THREAD,
|
1999-08-06 00:17:44 +04:00
|
|
|
getter_AddRefs(eventQueue));
|
|
|
|
nsServiceManager::ReleaseService(kEventQueueServiceCID, eventService);
|
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && eventQueue,
|
|
|
|
"will crash soon due to event holding dangling pointer to frame");
|
1999-08-06 00:17:44 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && eventQueue) {
|
|
|
|
PLEventQueue* plqueue;
|
|
|
|
|
|
|
|
eventQueue->GetPLEventQueue(&plqueue);
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ASSERTION(plqueue,
|
|
|
|
"will crash soon due to event holding dangling pointer to frame");
|
1999-08-06 00:17:44 +04:00
|
|
|
if (plqueue) {
|
|
|
|
// Removes the event and destroys it
|
|
|
|
PL_DequeueEvent(tmp, plqueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-03-06 04:46:03 +03:00
|
|
|
FrameManager::HandlePLEvent(CantRenderReplacedElementEvent* aEvent)
|
|
|
|
{
|
2000-06-05 07:37:33 +04:00
|
|
|
#ifdef NOISY_EVENTS
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("FrameManager::HandlePLEvent() start for FM %p\n", aEvent->owner);
|
2000-06-05 07:37:33 +04:00
|
|
|
#endif
|
1999-08-06 18:34:32 +04:00
|
|
|
FrameManager* frameManager = (FrameManager*)aEvent->owner;
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ASSERTION(frameManager, "null frame manager");
|
2000-03-28 05:08:36 +04:00
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
if (!frameManager->mPresShell) {
|
|
|
|
NS_ASSERTION(frameManager->mPresShell,
|
|
|
|
"event not removed from queue on shutdown");
|
|
|
|
return;
|
|
|
|
}
|
1999-08-06 00:17:44 +04:00
|
|
|
|
2001-03-06 04:46:03 +03:00
|
|
|
// Remove the posted event from the linked list
|
|
|
|
CantRenderReplacedElementEvent** events = &frameManager->mPostedEvents;
|
|
|
|
while (*events) {
|
|
|
|
if (*events == aEvent) {
|
|
|
|
*events = (*events)->mNext;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
events = &(*events)->mNext;
|
|
|
|
NS_ASSERTION(*events, "event not in queue");
|
2000-03-28 05:08:36 +04:00
|
|
|
}
|
2001-03-06 04:46:03 +03:00
|
|
|
|
|
|
|
// Notify the style system and then process any reflow commands that
|
|
|
|
// are generated
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
frameManager->mPresShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
frameManager->mStyleSet->CantRenderReplacedElement(presContext,
|
|
|
|
aEvent->mFrame);
|
2000-06-05 07:37:33 +04:00
|
|
|
#ifdef NOISY_EVENTS
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("FrameManager::HandlePLEvent() end for FM %p\n", aEvent->owner);
|
2000-06-05 07:37:33 +04:00
|
|
|
#endif
|
1999-08-06 00:17:44 +04:00
|
|
|
}
|
|
|
|
|
1999-08-06 18:34:32 +04:00
|
|
|
void
|
|
|
|
FrameManager::DestroyPLEvent(CantRenderReplacedElementEvent* aEvent)
|
1999-08-06 00:17:44 +04:00
|
|
|
{
|
|
|
|
delete aEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
CantRenderReplacedElementEvent::CantRenderReplacedElementEvent(FrameManager* aFrameManager,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
PL_InitEvent(this, aFrameManager,
|
|
|
|
(PLHandleEventProc)&FrameManager::HandlePLEvent,
|
1999-08-06 18:34:32 +04:00
|
|
|
(PLDestroyEventProc)&FrameManager::DestroyPLEvent);
|
1999-08-06 00:17:44 +04:00
|
|
|
mFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::CantRenderReplacedElement(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2000-06-05 07:37:33 +04:00
|
|
|
#ifdef NOISY_EVENTS
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("%p FrameManager::CantRenderReplacedElement called\n", this);
|
2000-06-05 07:37:33 +04:00
|
|
|
#endif
|
1999-08-06 00:17:44 +04:00
|
|
|
|
|
|
|
// We need to notify the style stystem, but post the notification so it
|
|
|
|
// doesn't happen now
|
2001-04-24 04:05:33 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIEventQueueService> eventService = do_GetService(kEventQueueServiceCID, &rv);
|
|
|
|
|
|
|
|
if (eventService) {
|
1999-08-06 00:17:44 +04:00
|
|
|
nsCOMPtr<nsIEventQueue> eventQueue;
|
1999-11-30 03:32:43 +03:00
|
|
|
rv = eventService->GetThreadEventQueue(NS_CURRENT_THREAD,
|
1999-08-06 00:17:44 +04:00
|
|
|
getter_AddRefs(eventQueue));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && eventQueue) {
|
|
|
|
// Verify that there isn't already a posted event associated with
|
2001-04-24 04:05:33 +04:00
|
|
|
// this frame.
|
|
|
|
if (*FindPostedEventFor(aFrame))
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
CantRenderReplacedElementEvent* ev;
|
|
|
|
|
|
|
|
// Create a new event
|
|
|
|
ev = new CantRenderReplacedElementEvent(this, aFrame);
|
|
|
|
|
|
|
|
// Add the event to our linked list of posted events
|
|
|
|
ev->mNext = mPostedEvents;
|
|
|
|
mPostedEvents = ev;
|
|
|
|
|
|
|
|
// Post the event
|
|
|
|
eventQueue->PostEvent(ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static void
|
|
|
|
DumpContext(nsIFrame* aFrame, nsIStyleContext* aContext)
|
|
|
|
{
|
|
|
|
if (aFrame) {
|
|
|
|
fputs("frame: ", stdout);
|
|
|
|
nsAutoString name;
|
1999-11-02 01:12:45 +03:00
|
|
|
nsIFrameDebug* frameDebug;
|
|
|
|
|
2000-02-03 01:24:56 +03:00
|
|
|
if (NS_SUCCEEDED(aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
|
1999-11-02 01:12:45 +03:00
|
|
|
frameDebug->GetFrameName(name);
|
|
|
|
fputs(name, stdout);
|
|
|
|
}
|
2001-03-06 04:46:03 +03:00
|
|
|
fprintf(stdout, " (%p)", NS_STATIC_CAST(void*, aFrame));
|
1999-09-21 11:53:14 +04:00
|
|
|
}
|
|
|
|
if (aContext) {
|
2001-03-06 04:46:03 +03:00
|
|
|
fprintf(stdout, " style: %p ", NS_STATIC_CAST(void*, aContext));
|
1999-09-21 11:53:14 +04:00
|
|
|
|
|
|
|
nsIAtom* pseudoTag;
|
|
|
|
aContext->GetPseudoType(pseudoTag);
|
|
|
|
if (pseudoTag) {
|
|
|
|
nsAutoString buffer;
|
|
|
|
pseudoTag->ToString(buffer);
|
|
|
|
fputs(buffer, stdout);
|
|
|
|
fputs(" ", stdout);
|
|
|
|
NS_RELEASE(pseudoTag);
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
/* XXXdwh fix debugging here. Need to add a List method to nsIRuleNode
|
|
|
|
and have the context call list on its rule node.
|
1999-09-21 11:53:14 +04:00
|
|
|
PRInt32 count = aContext->GetStyleRuleCount();
|
|
|
|
if (0 < count) {
|
|
|
|
fputs("{\n", stdout);
|
|
|
|
nsISupportsArray* rules = aContext->GetStyleRules();
|
|
|
|
PRInt32 ix;
|
|
|
|
for (ix = 0; ix < count; ix++) {
|
|
|
|
nsIStyleRule* rule = (nsIStyleRule*)rules->ElementAt(ix);
|
|
|
|
rule->List(stdout, 1);
|
|
|
|
NS_RELEASE(rule);
|
|
|
|
}
|
|
|
|
NS_RELEASE(rules);
|
|
|
|
fputs("}\n", stdout);
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
else
|
|
|
|
*/
|
|
|
|
{
|
1999-09-21 11:53:14 +04:00
|
|
|
fputs("{}\n", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-13 02:47:09 +04:00
|
|
|
#ifdef NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
static void
|
|
|
|
VerifyContextParent(nsIPresContext* aPresContext, nsIFrame* aFrame,
|
|
|
|
nsIStyleContext* aContext, nsIStyleContext* aParentContext)
|
|
|
|
{
|
|
|
|
nsIAtom* frameType;
|
|
|
|
|
|
|
|
// get the contexts not provided
|
|
|
|
if (!aContext) {
|
|
|
|
aFrame->GetStyleContext(&aContext);
|
|
|
|
} else {
|
|
|
|
// addref here so we can release at end
|
|
|
|
NS_ADDREF(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aParentContext) {
|
|
|
|
// Get the correct parent context from the frame
|
|
|
|
// - if the frame is a placeholder, we get the out of flow frame's context
|
|
|
|
// as the parent context instead of asking the frame
|
|
|
|
aFrame->GetFrameType(&frameType);
|
|
|
|
if (nsLayoutAtoms::placeholderFrame == frameType) { // placeholder
|
|
|
|
// get out of flow frame's context as the parent context
|
|
|
|
nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)aFrame)->GetOutOfFlowFrame();
|
|
|
|
NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");
|
|
|
|
outOfFlowFrame->GetStyleContext(&aParentContext);
|
|
|
|
} else {
|
|
|
|
// get the parent context from the frame (indirectly)
|
|
|
|
nsIFrame* providerFrame = nsnull;
|
|
|
|
nsContextProviderRelationship relationship;
|
|
|
|
aFrame->GetParentStyleContextProvider(aPresContext,&providerFrame,relationship);
|
|
|
|
if (providerFrame) {
|
|
|
|
providerFrame->GetStyleContext(&aParentContext);
|
|
|
|
} else {
|
|
|
|
// no parent context provider: it is OK, some frames' contexts do not have parents
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
} else {
|
|
|
|
// addref the parent context so we can release it at end
|
|
|
|
NS_ADDREF(aParentContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aContext, "Failure to get required contexts");
|
|
|
|
nsIStyleContext* actualParentContext = aContext->GetParent();
|
|
|
|
|
|
|
|
if (aParentContext) {
|
|
|
|
if (aParentContext != actualParentContext) {
|
|
|
|
DumpContext(aFrame, aContext);
|
|
|
|
if (aContext == aParentContext) {
|
|
|
|
fputs("Using parent's style context\n\n", stdout);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("Wrong parent style context: ", stdout);
|
|
|
|
DumpContext(nsnull, actualParentContext);
|
|
|
|
fputs("should be using: ", stdout);
|
|
|
|
DumpContext(nsnull, aParentContext);
|
|
|
|
fputs("\n", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (actualParentContext) {
|
|
|
|
DumpContext(aFrame, aContext);
|
|
|
|
fputs("Has parent context: ", stdout);
|
|
|
|
DumpContext(nsnull, actualParentContext);
|
|
|
|
fputs("Should be null\n\n", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(actualParentContext);
|
|
|
|
NS_IF_RELEASE(aParentContext);
|
|
|
|
NS_IF_RELEASE(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VerifyStyleTree(nsIPresContext* aPresContext, nsIFrame* aFrame, nsIStyleContext* aParentContext)
|
|
|
|
{
|
|
|
|
nsIStyleContext* context;
|
|
|
|
aFrame->GetStyleContext(&context);
|
|
|
|
|
|
|
|
VerifyContextParent(aPresContext, aFrame, context, aParentContext);
|
|
|
|
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
nsIAtom* childList = nsnull;
|
|
|
|
nsIFrame* child;
|
|
|
|
nsIAtom* frameType;
|
|
|
|
|
|
|
|
do {
|
|
|
|
child = nsnull;
|
|
|
|
nsresult result = aFrame->FirstChild(aPresContext, childList, &child);
|
|
|
|
while ((NS_SUCCEEDED(result)) && child) {
|
|
|
|
nsFrameState state;
|
|
|
|
child->GetFrameState(&state);
|
|
|
|
if (NS_FRAME_OUT_OF_FLOW != (state & NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
// only do frames that are in flow
|
|
|
|
child->GetFrameType(&frameType);
|
|
|
|
if (nsLayoutAtoms::placeholderFrame == frameType) {
|
|
|
|
// placeholder: first recirse and verify the out of flow frame,
|
|
|
|
// then verify the placeholder's context
|
|
|
|
nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)child)->GetOutOfFlowFrame();
|
|
|
|
NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");
|
|
|
|
nsIStyleContext* outOfFlowContext;
|
|
|
|
|
|
|
|
// recurse to out of flow frame, letting the parent context get resolved
|
|
|
|
VerifyStyleTree(aPresContext, outOfFlowFrame, nsnull);
|
|
|
|
|
|
|
|
// verify placeholder using the out of flow's context as parent context
|
|
|
|
outOfFlowFrame->GetStyleContext(&outOfFlowContext);
|
|
|
|
VerifyContextParent(aPresContext,child, nsnull, outOfFlowContext);
|
|
|
|
NS_IF_RELEASE(outOfFlowContext);
|
|
|
|
}
|
|
|
|
else { // regular frame
|
|
|
|
VerifyStyleTree(aPresContext, child, nsnull);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
}
|
|
|
|
child->GetNextSibling(&child);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(childList);
|
|
|
|
aFrame->GetAdditionalChildListName(listIndex++, &childList);
|
|
|
|
} while (childList);
|
|
|
|
|
|
|
|
// do additional contexts
|
|
|
|
PRInt32 contextIndex = -1;
|
|
|
|
while (1 == 1) {
|
|
|
|
nsIStyleContext* extraContext = nsnull;
|
|
|
|
aFrame->GetAdditionalStyleContext(++contextIndex, &extraContext);
|
|
|
|
if (extraContext) {
|
|
|
|
VerifyContextParent(aPresContext, aFrame, extraContext, context);
|
|
|
|
NS_RELEASE(extraContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::DebugVerifyStyleTree(nsIPresContext* aPresContext, nsIFrame* aFrame)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2000-09-13 02:47:09 +04:00
|
|
|
if (aFrame) {
|
|
|
|
nsIStyleContext* context;
|
|
|
|
aFrame->GetStyleContext(&context);
|
|
|
|
nsIStyleContext* parentContext = context->GetParent();
|
|
|
|
VerifyStyleTree(aPresContext, aFrame, parentContext);
|
|
|
|
NS_IF_RELEASE(parentContext);
|
|
|
|
NS_RELEASE(context);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
static void
|
|
|
|
VerifyContextParent(nsIFrame* aFrame, nsIStyleContext* aContext, nsIStyleContext* aParentContext)
|
|
|
|
{
|
|
|
|
nsIStyleContext* actualParentContext = aContext->GetParent();
|
|
|
|
|
|
|
|
if (aParentContext) {
|
|
|
|
if (aParentContext != actualParentContext) {
|
|
|
|
DumpContext(aFrame, aContext);
|
|
|
|
if (aContext == aParentContext) {
|
|
|
|
fputs("Using parent's style context\n\n", stdout);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("Wrong parent style context: ", stdout);
|
|
|
|
DumpContext(nsnull, actualParentContext);
|
|
|
|
fputs("should be using: ", stdout);
|
|
|
|
DumpContext(nsnull, aParentContext);
|
|
|
|
fputs("\n", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (actualParentContext) {
|
|
|
|
DumpContext(aFrame, aContext);
|
|
|
|
fputs("Has parent context: ", stdout);
|
|
|
|
DumpContext(nsnull, actualParentContext);
|
|
|
|
fputs("Should be null\n\n", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(actualParentContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VerifyContextParent(nsIFrame* aFrame, nsIStyleContext* aParentContext)
|
|
|
|
{
|
|
|
|
nsIStyleContext* context;
|
|
|
|
aFrame->GetStyleContext(&context);
|
|
|
|
VerifyContextParent(aFrame, context, aParentContext);
|
|
|
|
NS_RELEASE(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-22 04:16:50 +03:00
|
|
|
VerifyStyleTree(nsIPresContext* aPresContext, nsIFrame* aFrame, nsIStyleContext* aParentContext)
|
1999-09-21 11:53:14 +04:00
|
|
|
{
|
|
|
|
nsIStyleContext* context;
|
|
|
|
aFrame->GetStyleContext(&context);
|
|
|
|
|
|
|
|
VerifyContextParent(aFrame, aParentContext);
|
|
|
|
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
nsIAtom* childList = nsnull;
|
|
|
|
nsIFrame* child;
|
|
|
|
nsIAtom* frameType;
|
|
|
|
|
|
|
|
do {
|
|
|
|
child = nsnull;
|
2000-01-22 04:16:50 +03:00
|
|
|
nsresult result = aFrame->FirstChild(aPresContext, childList, &child);
|
1999-09-21 11:53:14 +04:00
|
|
|
while ((NS_SUCCEEDED(result)) && child) {
|
|
|
|
nsFrameState state;
|
|
|
|
child->GetFrameState(&state);
|
|
|
|
if (NS_FRAME_OUT_OF_FLOW != (state & NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
// only do frames that are in flow
|
|
|
|
child->GetFrameType(&frameType);
|
|
|
|
if (nsLayoutAtoms::placeholderFrame == frameType) { // placeholder
|
|
|
|
// get out of flow frame and recurse there
|
|
|
|
nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)child)->GetOutOfFlowFrame();
|
|
|
|
NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");
|
|
|
|
|
|
|
|
nsIStyleContext* outOfFlowContext;
|
|
|
|
outOfFlowFrame->GetStyleContext(&outOfFlowContext);
|
|
|
|
VerifyContextParent(child, outOfFlowContext);
|
|
|
|
NS_RELEASE(outOfFlowContext);
|
|
|
|
|
2000-01-22 04:16:50 +03:00
|
|
|
VerifyStyleTree(aPresContext, outOfFlowFrame, context);
|
1999-09-21 11:53:14 +04:00
|
|
|
}
|
|
|
|
else { // regular frame
|
2000-01-22 04:16:50 +03:00
|
|
|
VerifyStyleTree(aPresContext, child, context);
|
1999-09-21 11:53:14 +04:00
|
|
|
}
|
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
}
|
|
|
|
|
|
|
|
child->GetNextSibling(&child);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(childList);
|
|
|
|
aFrame->GetAdditionalChildListName(listIndex++, &childList);
|
|
|
|
} while (childList);
|
|
|
|
|
|
|
|
// do additional contexts
|
|
|
|
PRInt32 contextIndex = -1;
|
|
|
|
while (1 == 1) {
|
|
|
|
nsIStyleContext* extraContext = nsnull;
|
|
|
|
aFrame->GetAdditionalStyleContext(++contextIndex, &extraContext);
|
|
|
|
if (extraContext) {
|
|
|
|
VerifyContextParent(aFrame, extraContext, context);
|
|
|
|
NS_RELEASE(extraContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-22 04:16:50 +03:00
|
|
|
FrameManager::DebugVerifyStyleTree(nsIPresContext* aPresContext, nsIFrame* aFrame)
|
1999-09-21 11:53:14 +04:00
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-09-21 11:53:14 +04:00
|
|
|
if (aFrame) {
|
|
|
|
nsIStyleContext* context;
|
|
|
|
aFrame->GetStyleContext(&context);
|
|
|
|
nsIStyleContext* parentContext = context->GetParent();
|
2000-01-22 04:16:50 +03:00
|
|
|
VerifyStyleTree(aPresContext, aFrame, parentContext);
|
1999-09-21 11:53:14 +04:00
|
|
|
NS_IF_RELEASE(parentContext);
|
|
|
|
NS_RELEASE(context);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-13 02:47:09 +04:00
|
|
|
#endif //NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
#endif // DEBUG
|
1999-09-21 11:53:14 +04:00
|
|
|
|
1999-09-04 03:35:41 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
FrameManager::ReParentStyleContext(nsIPresContext* aPresContext,
|
1999-09-04 03:35:41 +04:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIStyleContext* aNewParentContext)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-09-04 03:35:41 +04:00
|
|
|
nsresult result = NS_ERROR_NULL_POINTER;
|
|
|
|
if (aFrame) {
|
1999-09-21 11:53:14 +04:00
|
|
|
#ifdef NS_DEBUG
|
2000-01-22 04:16:50 +03:00
|
|
|
DebugVerifyStyleTree(aPresContext, aFrame);
|
1999-09-21 11:53:14 +04:00
|
|
|
#endif
|
|
|
|
|
1999-09-04 03:35:41 +04:00
|
|
|
nsIStyleContext* oldContext = nsnull;
|
|
|
|
aFrame->GetStyleContext(&oldContext);
|
|
|
|
|
|
|
|
if (oldContext) {
|
|
|
|
nsIStyleContext* newContext = nsnull;
|
1999-11-24 09:03:41 +03:00
|
|
|
result = mStyleSet->ReParentStyleContext(aPresContext,
|
1999-09-04 03:35:41 +04:00
|
|
|
oldContext, aNewParentContext,
|
|
|
|
&newContext);
|
|
|
|
if (NS_SUCCEEDED(result) && newContext) {
|
|
|
|
if (newContext != oldContext) {
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
nsIAtom* childList = nsnull;
|
|
|
|
nsIFrame* child;
|
1999-09-21 11:53:14 +04:00
|
|
|
nsIAtom* frameType;
|
1999-09-04 03:35:41 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
child = nsnull;
|
2000-01-22 04:16:50 +03:00
|
|
|
result = aFrame->FirstChild(aPresContext, childList, &child);
|
1999-09-04 03:35:41 +04:00
|
|
|
while ((NS_SUCCEEDED(result)) && child) {
|
1999-09-21 11:53:14 +04:00
|
|
|
nsFrameState state;
|
|
|
|
child->GetFrameState(&state);
|
|
|
|
if (NS_FRAME_OUT_OF_FLOW != (state & NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
// only do frames that are in flow
|
|
|
|
child->GetFrameType(&frameType);
|
|
|
|
if (nsLayoutAtoms::placeholderFrame == frameType) { // placeholder
|
|
|
|
// get out of flow frame and recurse there
|
|
|
|
nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)child)->GetOutOfFlowFrame();
|
|
|
|
NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");
|
|
|
|
|
|
|
|
result = ReParentStyleContext(aPresContext, outOfFlowFrame, newContext);
|
|
|
|
|
|
|
|
// reparent placeholder's context under out of flow frame
|
|
|
|
nsIStyleContext* outOfFlowContext;
|
|
|
|
outOfFlowFrame->GetStyleContext(&outOfFlowContext);
|
|
|
|
ReParentStyleContext(aPresContext, child, outOfFlowContext);
|
|
|
|
NS_RELEASE(outOfFlowContext);
|
|
|
|
}
|
|
|
|
else { // regular frame
|
|
|
|
result = ReParentStyleContext(aPresContext, child, newContext);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
}
|
|
|
|
|
1999-09-04 03:35:41 +04:00
|
|
|
child->GetNextSibling(&child);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(childList);
|
|
|
|
aFrame->GetAdditionalChildListName(listIndex++, &childList);
|
|
|
|
} while (childList);
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
aFrame->SetStyleContext(aPresContext, newContext);
|
1999-09-04 03:35:41 +04:00
|
|
|
|
|
|
|
// do additional contexts
|
|
|
|
PRInt32 contextIndex = -1;
|
|
|
|
while (1 == 1) {
|
|
|
|
nsIStyleContext* oldExtraContext = nsnull;
|
1999-09-21 11:53:14 +04:00
|
|
|
result = aFrame->GetAdditionalStyleContext(++contextIndex, &oldExtraContext);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
if (oldExtraContext) {
|
|
|
|
nsIStyleContext* newExtraContext = nsnull;
|
1999-11-24 09:03:41 +03:00
|
|
|
result = mStyleSet->ReParentStyleContext(aPresContext,
|
1999-09-21 11:53:14 +04:00
|
|
|
oldExtraContext, newContext,
|
|
|
|
&newExtraContext);
|
|
|
|
if (NS_SUCCEEDED(result) && newExtraContext) {
|
|
|
|
aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);
|
|
|
|
NS_RELEASE(newExtraContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(oldExtraContext);
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1999-09-21 11:53:14 +04:00
|
|
|
result = NS_OK; // ok not to have extras (or run out)
|
1999-09-04 03:35:41 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-09-21 11:53:14 +04:00
|
|
|
#ifdef NS_DEBUG
|
2000-01-22 04:16:50 +03:00
|
|
|
VerifyStyleTree(aPresContext, aFrame, aNewParentContext);
|
1999-09-21 11:53:14 +04:00
|
|
|
#endif
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(newContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(oldContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-10-16 03:14:44 +04:00
|
|
|
static PRBool
|
|
|
|
HasAttributeContent(nsIStyleContext* aStyleContext,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute)
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
if (aStyleContext) {
|
|
|
|
const nsStyleContent* content = (const nsStyleContent*)aStyleContext->GetStyleData(eStyleStruct_Content);
|
|
|
|
PRUint32 count = content->ContentCount();
|
|
|
|
while ((0 < count) && (! result)) {
|
|
|
|
nsStyleContentType contentType;
|
|
|
|
nsAutoString contentString;
|
|
|
|
content->GetContentAt(--count, contentType, contentString);
|
|
|
|
if (eStyleContentType_Attr == contentType) {
|
|
|
|
nsIAtom* attrName = nsnull;
|
|
|
|
PRInt32 attrNameSpace = kNameSpaceID_None;
|
|
|
|
PRInt32 barIndex = contentString.FindChar('|'); // CSS namespace delimiter
|
|
|
|
if (-1 != barIndex) {
|
|
|
|
nsAutoString nameSpaceVal;
|
|
|
|
contentString.Left(nameSpaceVal, barIndex);
|
|
|
|
PRInt32 error;
|
|
|
|
attrNameSpace = nameSpaceVal.ToInteger(&error, 10);
|
|
|
|
contentString.Cut(0, barIndex + 1);
|
|
|
|
if (contentString.Length()) {
|
|
|
|
attrName = NS_NewAtom(contentString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
attrName = NS_NewAtom(contentString);
|
|
|
|
}
|
|
|
|
if ((attrName == aAttribute) &&
|
|
|
|
((attrNameSpace == aNameSpaceID) ||
|
|
|
|
(attrNameSpace == kNameSpaceID_Unknown))) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(attrName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
static PRInt32
|
|
|
|
CaptureChange(nsIStyleContext* aOldContext, nsIStyleContext* aNewContext,
|
1999-10-02 08:25:29 +04:00
|
|
|
nsIFrame* aFrame, nsIContent* aContent,
|
|
|
|
nsStyleChangeList& aChangeList, PRInt32 aMinChange)
|
1999-09-21 11:53:14 +04:00
|
|
|
{
|
|
|
|
PRInt32 ourChange = NS_STYLE_HINT_NONE;
|
|
|
|
aNewContext->CalcStyleDifference(aOldContext, ourChange);
|
|
|
|
if (aMinChange < ourChange) {
|
1999-10-02 08:25:29 +04:00
|
|
|
aChangeList.AppendChange(aFrame, aContent, ourChange);
|
1999-09-21 11:53:14 +04:00
|
|
|
aMinChange = ourChange;
|
|
|
|
}
|
|
|
|
return aMinChange;
|
|
|
|
}
|
|
|
|
|
2000-09-13 02:47:09 +04:00
|
|
|
#ifdef NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext,
|
1999-09-21 11:53:14 +04:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIStyleContext* aParentContext,
|
|
|
|
nsIContent* aParentContent,
|
1999-10-16 03:14:44 +04:00
|
|
|
PRInt32 aAttrNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
1999-09-21 11:53:14 +04:00
|
|
|
nsStyleChangeList& aChangeList,
|
|
|
|
PRInt32 aMinChange,
|
|
|
|
PRInt32& aResultChange)
|
|
|
|
{
|
2000-09-13 02:47:09 +04:00
|
|
|
nsIFrame *resolvedDescendant = nsnull;
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
nsIStyleContext* oldContext = nsnull;
|
|
|
|
nsresult result = aFrame->GetStyleContext(&oldContext);
|
|
|
|
if (NS_SUCCEEDED(result) && oldContext) {
|
|
|
|
nsIAtom* pseudoTag = nsnull;
|
|
|
|
oldContext->GetPseudoType(pseudoTag);
|
|
|
|
nsIContent* localContent = nsnull;
|
|
|
|
nsIContent* content = nsnull;
|
|
|
|
result = aFrame->GetContent(&localContent);
|
|
|
|
if (NS_SUCCEEDED(result) && localContent) {
|
|
|
|
content = localContent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
content = aParentContent;
|
|
|
|
}
|
1999-10-16 03:14:44 +04:00
|
|
|
if (aParentContent && aAttribute) { // attribute came from parent, we don't care about it here when recursing
|
|
|
|
nsFrameState frameState;
|
|
|
|
aFrame->GetFrameState(&frameState);
|
|
|
|
if (0 == (frameState & NS_FRAME_GENERATED_CONTENT)) { // keep it for generated content
|
|
|
|
aAttribute = nsnull;
|
|
|
|
}
|
|
|
|
}
|
1999-09-21 11:53:14 +04:00
|
|
|
|
2000-09-13 02:47:09 +04:00
|
|
|
if (aParentContext == nsnull) {
|
|
|
|
NOISY_TRACE_FRAME("null parent context in ReResolveStyle: getting provider frame for",aFrame);
|
|
|
|
// get the parent context from the frame (indirectly)
|
|
|
|
nsIFrame* providerFrame = nsnull;
|
|
|
|
nsContextProviderRelationship relationship;
|
|
|
|
aFrame->GetParentStyleContextProvider(aPresContext,&providerFrame,relationship);
|
|
|
|
if (providerFrame) {
|
|
|
|
NOISY_TRACE("provider frame retrieved in ReResolveStyle: ");
|
|
|
|
|
|
|
|
// see if we need to recurse and resolve the provider frame first
|
|
|
|
if (relationship != eContextProvider_Ancestor) {
|
|
|
|
NOISY_TRACE("non-ancestor provider, recursing.\n");
|
|
|
|
// provider is not an ancestor, so assume we have to reresolve it first
|
|
|
|
ReResolveStyleContext(aPresContext, providerFrame, nsnull, content,
|
|
|
|
aAttrNameSpaceID, aAttribute,
|
|
|
|
aChangeList, aMinChange, aResultChange);
|
|
|
|
resolvedDescendant = providerFrame;
|
|
|
|
NOISY_TRACE("returned from recursion, descendant parent context provider resolved.\n");
|
|
|
|
} else {
|
|
|
|
NOISY_TRACE("ancestor provider, assuming already resolved.\n");
|
|
|
|
}
|
|
|
|
providerFrame->GetStyleContext(&aParentContext);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// addref the parent passed in so we can release it at the end
|
|
|
|
NS_ADDREF(aParentContext);
|
|
|
|
NOISY_TRACE_FRAME("non-null parent context provided: using it and assuming already resolved",aFrame);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(aParentContext, "Failed to resolve parent context");
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
// do primary context
|
|
|
|
nsIStyleContext* newContext = nsnull;
|
|
|
|
if (pseudoTag) {
|
2000-09-11 07:58:22 +04:00
|
|
|
nsIContent* pseudoContent = (aParentContent ? aParentContent : localContent);
|
|
|
|
aPresContext->ResolvePseudoStyleContextFor(pseudoContent, pseudoTag, aParentContext, PR_FALSE,
|
1999-09-21 11:53:14 +04:00
|
|
|
&newContext);
|
|
|
|
NS_RELEASE(pseudoTag);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(localContent, "non pseudo-element frame without content node");
|
2000-12-22 01:16:38 +03:00
|
|
|
aPresContext->ResolveStyleContextFor(content, aParentContext, PR_TRUE, &newContext);
|
1999-09-21 11:53:14 +04:00
|
|
|
}
|
|
|
|
NS_ASSERTION(newContext, "failed to get new style context");
|
|
|
|
if (newContext) {
|
|
|
|
if (newContext != oldContext) {
|
1999-10-02 08:25:29 +04:00
|
|
|
aMinChange = CaptureChange(oldContext, newContext, aFrame, content, aChangeList, aMinChange);
|
1999-09-25 09:00:41 +04:00
|
|
|
if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) { // if frame gets regenerated, let it keep old context
|
1999-11-24 09:03:41 +03:00
|
|
|
aFrame->SetStyleContext(aPresContext, newContext);
|
1999-09-25 09:00:41 +04:00
|
|
|
}
|
2000-02-16 05:49:01 +03:00
|
|
|
// if old context had image and new context does not have the same image,
|
|
|
|
// stop the image load for the frame
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleBackground* oldColor = (const nsStyleBackground*)oldContext->GetStyleData(eStyleStruct_Background);
|
|
|
|
const nsStyleBackground* newColor = (const nsStyleBackground*)newContext->GetStyleData(eStyleStruct_Background);
|
|
|
|
|
|
|
|
if(oldColor->mBackgroundImage.Length() > 0 &&
|
|
|
|
oldColor->mBackgroundImage != newColor->mBackgroundImage ){
|
2000-02-16 05:49:01 +03:00
|
|
|
// stop the image loading for the frame, the image has changed
|
2001-08-10 00:22:39 +04:00
|
|
|
aPresContext->StopImagesFor(aFrame);
|
2000-02-16 05:49:01 +03:00
|
|
|
}
|
1999-09-21 11:53:14 +04:00
|
|
|
}
|
1999-09-29 07:32:19 +04:00
|
|
|
else {
|
2001-07-25 10:33:06 +04:00
|
|
|
// XXXdwh figure this out.
|
|
|
|
// oldContext->RemapStyle(aPresContext, PR_FALSE);
|
1999-10-16 03:14:44 +04:00
|
|
|
if (aAttribute && (aMinChange < NS_STYLE_HINT_REFLOW) &&
|
|
|
|
HasAttributeContent(oldContext, aAttrNameSpaceID, aAttribute)) {
|
1999-12-02 12:19:16 +03:00
|
|
|
aChangeList.AppendChange(aFrame, content, NS_STYLE_HINT_REFLOW);
|
1999-10-16 03:14:44 +04:00
|
|
|
}
|
1999-09-29 07:32:19 +04:00
|
|
|
}
|
1999-09-21 11:53:14 +04:00
|
|
|
NS_RELEASE(oldContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ERROR("resolve style context failed");
|
|
|
|
newContext = oldContext; // new context failed, recover... (take ref)
|
|
|
|
}
|
|
|
|
|
|
|
|
// do additional contexts
|
|
|
|
PRInt32 contextIndex = -1;
|
|
|
|
while (1 == 1) {
|
|
|
|
nsIStyleContext* oldExtraContext = nsnull;
|
|
|
|
result = aFrame->GetAdditionalStyleContext(++contextIndex, &oldExtraContext);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
if (oldExtraContext) {
|
|
|
|
nsIStyleContext* newExtraContext = nsnull;
|
|
|
|
oldExtraContext->GetPseudoType(pseudoTag);
|
|
|
|
NS_ASSERTION(pseudoTag, "extra style context is not pseudo element");
|
1999-11-24 09:03:41 +03:00
|
|
|
result = aPresContext->ResolvePseudoStyleContextFor(content, pseudoTag, newContext,
|
1999-09-21 11:53:14 +04:00
|
|
|
PR_FALSE, &newExtraContext);
|
|
|
|
NS_RELEASE(pseudoTag);
|
|
|
|
if (NS_SUCCEEDED(result) && newExtraContext) {
|
|
|
|
if (oldExtraContext != newExtraContext) {
|
|
|
|
aMinChange = CaptureChange(oldExtraContext, newExtraContext, aFrame,
|
1999-10-02 08:25:29 +04:00
|
|
|
content, aChangeList, aMinChange);
|
1999-09-25 09:00:41 +04:00
|
|
|
if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) {
|
|
|
|
aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);
|
|
|
|
}
|
1999-09-21 11:53:14 +04:00
|
|
|
}
|
1999-10-02 08:25:29 +04:00
|
|
|
else {
|
2001-07-25 10:33:06 +04:00
|
|
|
// XXXdwh figure this out.
|
|
|
|
// oldExtraContext->RemapStyle(aPresContext, PR_FALSE);
|
1999-10-16 03:14:44 +04:00
|
|
|
if (aAttribute && (aMinChange < NS_STYLE_HINT_REFLOW) &&
|
|
|
|
HasAttributeContent(oldContext, aAttrNameSpaceID, aAttribute)) {
|
1999-12-02 12:19:16 +03:00
|
|
|
aChangeList.AppendChange(aFrame, content, NS_STYLE_HINT_REFLOW);
|
1999-10-16 03:14:44 +04:00
|
|
|
}
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
1999-09-21 11:53:14 +04:00
|
|
|
NS_RELEASE(newExtraContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(oldExtraContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-02 08:25:29 +04:00
|
|
|
// now look for undisplayed child content and pseudos
|
1999-10-02 23:45:18 +04:00
|
|
|
if (localContent && mUndisplayedMap) {
|
1999-10-02 08:25:29 +04:00
|
|
|
UndisplayedNode* undisplayed = mUndisplayedMap->GetFirstNode(localContent);
|
|
|
|
while (undisplayed) {
|
|
|
|
nsIStyleContext* undisplayedContext = nsnull;
|
2000-01-28 18:03:00 +03:00
|
|
|
undisplayed->mStyle->GetPseudoType(pseudoTag);
|
|
|
|
if (undisplayed->mContent && pseudoTag == nsnull) { // child content
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->ResolveStyleContextFor(undisplayed->mContent, newContext,
|
2000-12-22 01:16:38 +03:00
|
|
|
PR_TRUE, &undisplayedContext);
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
else { // pseudo element
|
|
|
|
NS_ASSERTION(pseudoTag, "pseudo element without tag");
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->ResolvePseudoStyleContextFor(localContent, pseudoTag, newContext, PR_FALSE,
|
1999-10-02 08:25:29 +04:00
|
|
|
&undisplayedContext);
|
|
|
|
}
|
2000-01-28 18:03:00 +03:00
|
|
|
NS_IF_RELEASE(pseudoTag);
|
1999-10-02 08:25:29 +04:00
|
|
|
if (undisplayedContext) {
|
|
|
|
if (undisplayedContext == undisplayed->mStyle) {
|
2001-07-25 10:33:06 +04:00
|
|
|
// XXXdwh figure this out.
|
|
|
|
// undisplayedContext->RemapStyle(aPresContext);
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
const nsStyleDisplay* display =
|
|
|
|
(const nsStyleDisplay*)undisplayedContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (display->mDisplay != NS_STYLE_DISPLAY_NONE) {
|
|
|
|
aChangeList.AppendChange(nsnull, ((undisplayed->mContent) ? undisplayed->mContent : localContent),
|
1999-12-02 12:19:16 +03:00
|
|
|
NS_STYLE_HINT_FRAMECHANGE);
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(undisplayedContext);
|
|
|
|
}
|
|
|
|
undisplayed = undisplayed->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
aResultChange = aMinChange;
|
|
|
|
|
|
|
|
// now do children
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
nsIAtom* childList = nsnull;
|
|
|
|
PRInt32 childChange;
|
|
|
|
nsIFrame* child;
|
|
|
|
|
2000-09-13 02:47:09 +04:00
|
|
|
do {
|
|
|
|
child = nsnull;
|
|
|
|
result = aFrame->FirstChild(aPresContext, childList, &child);
|
|
|
|
while ((NS_SUCCEEDED(result)) && (child)) {
|
|
|
|
nsFrameState state;
|
|
|
|
child->GetFrameState(&state);
|
|
|
|
if (NS_FRAME_OUT_OF_FLOW != (state & NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
// only do frames that are in flow
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
child->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (nsLayoutAtoms::placeholderFrame == frameType.get()) { // placeholder
|
|
|
|
// get out of flow frame and recurse there
|
|
|
|
nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)child)->GetOutOfFlowFrame();
|
|
|
|
NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");
|
|
|
|
|
|
|
|
if (outOfFlowFrame != resolvedDescendant) {
|
|
|
|
ReResolveStyleContext(aPresContext, outOfFlowFrame, nsnull, content,
|
|
|
|
aAttrNameSpaceID, aAttribute,
|
|
|
|
aChangeList, aMinChange, childChange);
|
|
|
|
} else {
|
|
|
|
NOISY_TRACE("out of flow frame already resolved as descendent\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// reresolve placeholder's context under out of flow frame
|
|
|
|
nsIStyleContext* outOfFlowContext;
|
|
|
|
outOfFlowFrame->GetStyleContext(&outOfFlowContext);
|
|
|
|
ReResolveStyleContext(aPresContext, child, outOfFlowContext, content,
|
|
|
|
kNameSpaceID_Unknown, nsnull,
|
|
|
|
aChangeList, aMinChange, childChange);
|
|
|
|
NS_RELEASE(outOfFlowContext);
|
|
|
|
}
|
|
|
|
else { // regular child frame
|
|
|
|
if (child != resolvedDescendant) {
|
|
|
|
ReResolveStyleContext(aPresContext, child, nsnull, content,
|
|
|
|
aAttrNameSpaceID, aAttribute,
|
|
|
|
aChangeList, aMinChange, childChange);
|
|
|
|
} else {
|
|
|
|
NOISY_TRACE_FRAME("child frame already resolved as descendent, skipping",aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
child->GetNextSibling(&child);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(childList);
|
|
|
|
aFrame->GetAdditionalChildListName(listIndex++, &childList);
|
|
|
|
} while (childList);
|
|
|
|
// XXX need to do overflow frames???
|
|
|
|
|
|
|
|
NS_RELEASE(newContext);
|
|
|
|
NS_IF_RELEASE(localContent);
|
|
|
|
NS_IF_RELEASE(aParentContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIStyleContext* aParentContext,
|
|
|
|
nsIContent* aParentContent,
|
|
|
|
PRInt32 aAttrNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
nsStyleChangeList& aChangeList,
|
|
|
|
PRInt32 aMinChange,
|
|
|
|
PRInt32& aResultChange)
|
|
|
|
{
|
|
|
|
nsIStyleContext* oldContext = nsnull;
|
|
|
|
nsresult result = aFrame->GetStyleContext(&oldContext);
|
|
|
|
if (NS_SUCCEEDED(result) && oldContext) {
|
|
|
|
nsIAtom* pseudoTag = nsnull;
|
|
|
|
oldContext->GetPseudoType(pseudoTag);
|
|
|
|
nsIContent* localContent = nsnull;
|
|
|
|
nsIContent* content = nsnull;
|
|
|
|
result = aFrame->GetContent(&localContent);
|
|
|
|
if (NS_SUCCEEDED(result) && localContent) {
|
|
|
|
content = localContent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
content = aParentContent;
|
|
|
|
}
|
|
|
|
if (aParentContent && aAttribute) { // attribute came from parent, we don't care about it here when recursing
|
|
|
|
nsFrameState frameState;
|
|
|
|
aFrame->GetFrameState(&frameState);
|
|
|
|
if (0 == (frameState & NS_FRAME_GENERATED_CONTENT)) { // keep it for generated content
|
|
|
|
aAttribute = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do primary context
|
|
|
|
nsIStyleContext* newContext = nsnull;
|
|
|
|
if (pseudoTag) {
|
|
|
|
aPresContext->ResolvePseudoStyleContextFor(aParentContent, pseudoTag, aParentContext, PR_FALSE,
|
|
|
|
&newContext);
|
|
|
|
NS_RELEASE(pseudoTag);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(localContent, "non pseudo-element frame without content node");
|
2000-12-22 01:16:38 +03:00
|
|
|
aPresContext->ResolveStyleContextFor(content, aParentContext, PR_TRUE, &newContext);
|
2000-09-13 02:47:09 +04:00
|
|
|
}
|
|
|
|
NS_ASSERTION(newContext, "failed to get new style context");
|
|
|
|
if (newContext) {
|
|
|
|
if (newContext != oldContext) {
|
|
|
|
aMinChange = CaptureChange(oldContext, newContext, aFrame, content, aChangeList, aMinChange);
|
|
|
|
if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) { // if frame gets regenerated, let it keep old context
|
|
|
|
aFrame->SetStyleContext(aPresContext, newContext);
|
|
|
|
}
|
|
|
|
// if old context had image and new context does not have the same image,
|
|
|
|
// stop the image load for the frame
|
2001-06-01 02:19:43 +04:00
|
|
|
nsStyleColor* oldColor;
|
|
|
|
nsStyleColor* newColor;
|
|
|
|
oldContext->GetStyle(eStyleStruct_Color, &oldColor);
|
|
|
|
newContext->GetStyle(eStyleStruct_Color, &newColor);
|
2000-09-13 02:47:09 +04:00
|
|
|
if(oldColor.mBackgroundImage.Length() > 0 &&
|
|
|
|
oldColor.mBackgroundImage != newColor.mBackgroundImage ){
|
|
|
|
// stop the image loading for the frame, the image has changed
|
2001-08-10 00:22:39 +04:00
|
|
|
aPresContext->StopImagesFor(aFrame);
|
2000-09-13 02:47:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-07-25 10:33:06 +04:00
|
|
|
// XXXdwh figure this out.
|
|
|
|
// oldContext->RemapStyle(aPresContext, PR_FALSE);
|
2000-09-13 02:47:09 +04:00
|
|
|
if (aAttribute && (aMinChange < NS_STYLE_HINT_REFLOW) &&
|
|
|
|
HasAttributeContent(oldContext, aAttrNameSpaceID, aAttribute)) {
|
|
|
|
aChangeList.AppendChange(aFrame, content, NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(oldContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ERROR("resolve style context failed");
|
|
|
|
newContext = oldContext; // new context failed, recover... (take ref)
|
|
|
|
}
|
|
|
|
|
|
|
|
// do additional contexts
|
|
|
|
PRInt32 contextIndex = -1;
|
|
|
|
while (1 == 1) {
|
|
|
|
nsIStyleContext* oldExtraContext = nsnull;
|
|
|
|
result = aFrame->GetAdditionalStyleContext(++contextIndex, &oldExtraContext);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
if (oldExtraContext) {
|
|
|
|
nsIStyleContext* newExtraContext = nsnull;
|
|
|
|
oldExtraContext->GetPseudoType(pseudoTag);
|
|
|
|
NS_ASSERTION(pseudoTag, "extra style context is not pseudo element");
|
|
|
|
result = aPresContext->ResolvePseudoStyleContextFor(content, pseudoTag, newContext,
|
|
|
|
PR_FALSE, &newExtraContext);
|
|
|
|
NS_RELEASE(pseudoTag);
|
|
|
|
if (NS_SUCCEEDED(result) && newExtraContext) {
|
|
|
|
if (oldExtraContext != newExtraContext) {
|
|
|
|
aMinChange = CaptureChange(oldExtraContext, newExtraContext, aFrame,
|
|
|
|
content, aChangeList, aMinChange);
|
|
|
|
if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) {
|
|
|
|
aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-07-25 10:33:06 +04:00
|
|
|
// XXXdwh figure this out.
|
|
|
|
// oldExtraContext->RemapStyle(aPresContext, PR_FALSE);
|
2000-09-13 02:47:09 +04:00
|
|
|
if (aAttribute && (aMinChange < NS_STYLE_HINT_REFLOW) &&
|
|
|
|
HasAttributeContent(oldContext, aAttrNameSpaceID, aAttribute)) {
|
|
|
|
aChangeList.AppendChange(aFrame, content, NS_STYLE_HINT_REFLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(newExtraContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(oldExtraContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now look for undisplayed child content and pseudos
|
|
|
|
if (localContent && mUndisplayedMap) {
|
|
|
|
UndisplayedNode* undisplayed = mUndisplayedMap->GetFirstNode(localContent);
|
|
|
|
while (undisplayed) {
|
|
|
|
nsIStyleContext* undisplayedContext = nsnull;
|
|
|
|
undisplayed->mStyle->GetPseudoType(pseudoTag);
|
|
|
|
if (undisplayed->mContent && pseudoTag == nsnull) { // child content
|
|
|
|
aPresContext->ResolveStyleContextFor(undisplayed->mContent, newContext,
|
2000-12-22 01:16:38 +03:00
|
|
|
PR_TRUE, &undisplayedContext);
|
2000-09-13 02:47:09 +04:00
|
|
|
}
|
|
|
|
else { // pseudo element
|
|
|
|
NS_ASSERTION(pseudoTag, "pseudo element without tag");
|
|
|
|
aPresContext->ResolvePseudoStyleContextFor(localContent, pseudoTag, newContext, PR_FALSE,
|
|
|
|
&undisplayedContext);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pseudoTag);
|
|
|
|
if (undisplayedContext) {
|
|
|
|
if (undisplayedContext == undisplayed->mStyle) {
|
2001-07-25 10:33:06 +04:00
|
|
|
// XXXdwh figure this out.
|
|
|
|
// undisplayedContext->RemapStyle(aPresContext);
|
2000-09-13 02:47:09 +04:00
|
|
|
}
|
|
|
|
const nsStyleDisplay* display =
|
|
|
|
(const nsStyleDisplay*)undisplayedContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (display->mDisplay != NS_STYLE_DISPLAY_NONE) {
|
|
|
|
aChangeList.AppendChange(nsnull, ((undisplayed->mContent) ? undisplayed->mContent : localContent),
|
|
|
|
NS_STYLE_HINT_FRAMECHANGE);
|
|
|
|
}
|
|
|
|
NS_RELEASE(undisplayedContext);
|
|
|
|
}
|
|
|
|
undisplayed = undisplayed->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResultChange = aMinChange;
|
|
|
|
|
|
|
|
// now do children
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
nsIAtom* childList = nsnull;
|
|
|
|
PRInt32 childChange;
|
|
|
|
nsIFrame* child;
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
do {
|
|
|
|
child = nsnull;
|
2000-01-22 04:16:50 +03:00
|
|
|
result = aFrame->FirstChild(aPresContext, childList, &child);
|
1999-09-21 11:53:14 +04:00
|
|
|
while ((NS_SUCCEEDED(result)) && (child)) {
|
|
|
|
nsFrameState state;
|
|
|
|
child->GetFrameState(&state);
|
|
|
|
if (NS_FRAME_OUT_OF_FLOW != (state & NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
// only do frames that are in flow
|
2000-02-15 04:17:18 +03:00
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
child->GetFrameType(getter_AddRefs(frameType));
|
2000-02-15 05:55:23 +03:00
|
|
|
if (nsLayoutAtoms::placeholderFrame == frameType.get()) { // placeholder
|
1999-09-21 11:53:14 +04:00
|
|
|
// get out of flow frame and recurse there
|
|
|
|
nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)child)->GetOutOfFlowFrame();
|
|
|
|
NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");
|
|
|
|
|
|
|
|
ReResolveStyleContext(aPresContext, outOfFlowFrame, newContext, content,
|
1999-10-16 03:14:44 +04:00
|
|
|
aAttrNameSpaceID, aAttribute,
|
1999-09-21 11:53:14 +04:00
|
|
|
aChangeList, aMinChange, childChange);
|
|
|
|
|
|
|
|
// reresolve placeholder's context under out of flow frame
|
|
|
|
nsIStyleContext* outOfFlowContext;
|
|
|
|
outOfFlowFrame->GetStyleContext(&outOfFlowContext);
|
|
|
|
ReResolveStyleContext(aPresContext, child, outOfFlowContext, content,
|
1999-10-16 03:14:44 +04:00
|
|
|
kNameSpaceID_Unknown, nsnull,
|
1999-09-21 11:53:14 +04:00
|
|
|
aChangeList, aMinChange, childChange);
|
|
|
|
NS_RELEASE(outOfFlowContext);
|
|
|
|
}
|
|
|
|
else { // regular child frame
|
|
|
|
ReResolveStyleContext(aPresContext, child, newContext, content,
|
1999-10-16 03:14:44 +04:00
|
|
|
aAttrNameSpaceID, aAttribute,
|
1999-09-21 11:53:14 +04:00
|
|
|
aChangeList, aMinChange, childChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
child->GetNextSibling(&child);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(childList);
|
|
|
|
aFrame->GetAdditionalChildListName(listIndex++, &childList);
|
|
|
|
} while (childList);
|
|
|
|
// XXX need to do overflow frames???
|
|
|
|
|
|
|
|
NS_RELEASE(newContext);
|
|
|
|
NS_IF_RELEASE(localContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-13 02:47:09 +04:00
|
|
|
#endif // NEW_CONTEXT_PARENTAGE_INVARIANT
|
|
|
|
|
1999-09-21 11:53:14 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
FrameManager::ComputeStyleChangeFor(nsIPresContext* aPresContext,
|
1999-09-21 11:53:14 +04:00
|
|
|
nsIFrame* aFrame,
|
1999-10-16 03:14:44 +04:00
|
|
|
PRInt32 aAttrNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
1999-09-21 11:53:14 +04:00
|
|
|
nsStyleChangeList& aChangeList,
|
|
|
|
PRInt32 aMinChange,
|
|
|
|
PRInt32& aTopLevelChange)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-09-21 11:53:14 +04:00
|
|
|
aTopLevelChange = NS_STYLE_HINT_NONE;
|
1999-10-16 03:14:44 +04:00
|
|
|
nsIFrame* frame = aFrame;
|
1999-09-21 11:53:14 +04:00
|
|
|
|
1999-10-16 03:14:44 +04:00
|
|
|
do {
|
|
|
|
nsIStyleContext* styleContext = nsnull;
|
|
|
|
frame->GetStyleContext(&styleContext);
|
|
|
|
nsIStyleContext* parentContext = styleContext->GetParent();
|
|
|
|
PRInt32 frameChange;
|
|
|
|
ReResolveStyleContext(aPresContext, frame, parentContext, nsnull,
|
|
|
|
aAttrNameSpaceID, aAttribute,
|
|
|
|
aChangeList, aMinChange, frameChange);
|
1999-09-21 11:53:14 +04:00
|
|
|
#ifdef NS_DEBUG
|
2000-01-22 04:16:50 +03:00
|
|
|
VerifyStyleTree(aPresContext, frame, parentContext);
|
1999-09-21 11:53:14 +04:00
|
|
|
#endif
|
1999-10-16 03:14:44 +04:00
|
|
|
NS_IF_RELEASE(parentContext);
|
|
|
|
NS_RELEASE(styleContext);
|
|
|
|
if (aTopLevelChange < frameChange) {
|
|
|
|
aTopLevelChange = frameChange;
|
|
|
|
}
|
1999-09-21 11:53:14 +04:00
|
|
|
|
2001-05-23 10:39:34 +04:00
|
|
|
if (aTopLevelChange >= NS_STYLE_HINT_REFLOW) {
|
|
|
|
// If it's going to cause a reflow (or worse), then don't touch
|
|
|
|
// the any continuations: they must be taken care of by the reflow.
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsIFrame* prevInFlow;
|
|
|
|
frame->GetPrevInFlow(&prevInFlow);
|
|
|
|
NS_ASSERTION(!prevInFlow, "continuing frame had more severe impact than first-in-flow");
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-10-16 03:14:44 +04:00
|
|
|
frame->GetNextInFlow(&frame);
|
|
|
|
} while (frame);
|
1999-09-21 11:53:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-09-13 02:47:09 +04:00
|
|
|
|
2000-05-16 06:43:33 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
|
|
|
|
PRBool &aAffects)
|
|
|
|
{
|
2000-05-26 03:02:31 +04:00
|
|
|
nsresult rv = NS_OK;
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2000-05-26 03:02:31 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIXMLContent> xml(do_QueryInterface(aContent));
|
|
|
|
if (xml) {
|
|
|
|
rv = mStyleSet->AttributeAffectsStyle(aAttribute, aContent, aAffects);
|
|
|
|
} else {
|
|
|
|
// not an XML element, so assume it is an HTML element and further assume that
|
|
|
|
// any attribute may affect style
|
|
|
|
// NOTE: we could list all of the presentation-hint attributes and check them,
|
|
|
|
// but there are a lot of them and this is safer.
|
2000-05-17 02:05:47 +04:00
|
|
|
aAffects = PR_TRUE;
|
2000-05-26 03:02:31 +04:00
|
|
|
rv = NS_OK;
|
2000-05-17 02:05:47 +04:00
|
|
|
}
|
2000-05-26 03:02:31 +04:00
|
|
|
return rv;
|
2000-05-16 06:43:33 +04:00
|
|
|
}
|
1999-09-04 03:35:41 +04:00
|
|
|
|
2000-06-15 04:35:46 +04:00
|
|
|
// Capture state for a given frame.
|
|
|
|
// Accept a content id here, in some cases we may not have content (scroll position)
|
|
|
|
NS_IMETHODIMP
|
2001-05-30 15:26:21 +04:00
|
|
|
FrameManager::CaptureFrameStateFor(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState,
|
|
|
|
nsIStatefulFrame::SpecialStateID aID)
|
1999-08-31 18:35:50 +04:00
|
|
|
{
|
2001-05-30 15:26:21 +04:00
|
|
|
NS_ENSURE_TRUE(mPresShell && aFrame && aState, NS_ERROR_FAILURE);
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Only capture state for stateful frames
|
1999-10-23 05:43:49 +04:00
|
|
|
nsIStatefulFrame* statefulFrame = nsnull;
|
2000-02-03 01:24:56 +03:00
|
|
|
aFrame->QueryInterface(NS_GET_IID(nsIStatefulFrame), (void**) &statefulFrame);
|
2001-05-30 15:26:21 +04:00
|
|
|
if (!statefulFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Capture the state, exit early if we get null (nothing to save)
|
|
|
|
nsCOMPtr<nsIPresState> frameState;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
rv = statefulFrame->SaveState(aPresContext, getter_AddRefs(frameState));
|
|
|
|
if (!frameState) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Generate the hash key to store the state under
|
|
|
|
// Exit early if we get empty key
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
rv = aFrame->GetContent(getter_AddRefs(content));
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
nsCAutoString stateKey;
|
|
|
|
rv = GenerateStateKey(content, aID, stateKey);
|
|
|
|
if(NS_FAILED(rv) || stateKey.IsEmpty()) {
|
|
|
|
return rv;
|
1999-08-31 18:35:50 +04:00
|
|
|
}
|
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Store the state
|
|
|
|
return aState->AddState(stateKey, frameState);
|
1999-10-23 05:43:49 +04:00
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
|
1999-10-23 05:43:49 +04:00
|
|
|
NS_IMETHODIMP
|
2001-05-30 15:26:21 +04:00
|
|
|
FrameManager::CaptureFrameState(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState)
|
1999-10-23 05:43:49 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-23 05:43:49 +04:00
|
|
|
NS_PRECONDITION(nsnull != aFrame && nsnull != aState, "null parameters passed in");
|
1999-08-31 18:35:50 +04:00
|
|
|
|
1999-10-26 08:44:41 +04:00
|
|
|
rv = CaptureFrameStateFor(aPresContext, aFrame, aState);
|
1999-10-23 05:43:49 +04:00
|
|
|
|
|
|
|
// Now capture state recursively for the frame hierarchy rooted at aFrame
|
|
|
|
nsIAtom* childListName = nsnull;
|
|
|
|
PRInt32 childListIndex = 0;
|
|
|
|
do {
|
|
|
|
nsIFrame* childFrame;
|
2000-01-22 04:16:50 +03:00
|
|
|
aFrame->FirstChild(aPresContext, childListName, &childFrame);
|
1999-10-23 05:43:49 +04:00
|
|
|
while (childFrame) {
|
1999-10-26 08:44:41 +04:00
|
|
|
rv = CaptureFrameState(aPresContext, childFrame, aState);
|
1999-10-23 05:43:49 +04:00
|
|
|
// Get the next sibling child frame
|
|
|
|
childFrame->GetNextSibling(&childFrame);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(childListName);
|
|
|
|
aFrame->GetAdditionalChildListName(childListIndex++, &childListName);
|
|
|
|
} while (childListName);
|
1999-08-31 18:35:50 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-06-15 04:35:46 +04:00
|
|
|
// Restore state for a given frame.
|
|
|
|
// Accept a content id here, in some cases we may not have content (scroll position)
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::RestoreFrameStateFor(nsIPresContext* aPresContext, nsIFrame* aFrame, nsILayoutHistoryState* aState, nsIStatefulFrame::SpecialStateID aID)
|
1999-08-31 18:35:50 +04:00
|
|
|
{
|
2001-05-30 15:26:21 +04:00
|
|
|
NS_ENSURE_TRUE(mPresShell && aFrame && aState, NS_ERROR_FAILURE);
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Only capture state for stateful frames
|
1999-10-23 05:43:49 +04:00
|
|
|
nsIStatefulFrame* statefulFrame = nsnull;
|
2000-02-03 01:24:56 +03:00
|
|
|
aFrame->QueryInterface(NS_GET_IID(nsIStatefulFrame), (void**) &statefulFrame);
|
2001-05-30 15:26:21 +04:00
|
|
|
if (!statefulFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Generate the hash key the state was stored under
|
|
|
|
// Exit early if we get empty key
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
rv = aFrame->GetContent(getter_AddRefs(content));
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
nsCAutoString stateKey;
|
|
|
|
rv = GenerateStateKey(content, aID, stateKey);
|
|
|
|
if(NS_FAILED(rv) || stateKey.IsEmpty()) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Get the state from the hash
|
|
|
|
nsCOMPtr<nsIPresState> frameState;
|
|
|
|
rv = aState->GetState(stateKey, getter_AddRefs(frameState));
|
|
|
|
if (!frameState) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Restore it
|
|
|
|
rv = statefulFrame->RestoreState(aPresContext, frameState);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// If we restore ok, remove the state from the state table
|
|
|
|
return aState->RemoveState(stateKey);
|
1999-10-23 05:43:49 +04:00
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
|
1999-10-23 05:43:49 +04:00
|
|
|
NS_IMETHODIMP
|
1999-10-26 08:44:41 +04:00
|
|
|
FrameManager::RestoreFrameState(nsIPresContext* aPresContext, nsIFrame* aFrame, nsILayoutHistoryState* aState)
|
1999-10-23 05:43:49 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-23 05:43:49 +04:00
|
|
|
NS_PRECONDITION(nsnull != aFrame && nsnull != aState, "null parameters passed in");
|
|
|
|
|
1999-10-26 08:44:41 +04:00
|
|
|
rv = RestoreFrameStateFor(aPresContext, aFrame, aState);
|
1999-10-23 05:43:49 +04:00
|
|
|
|
|
|
|
// Now restore state recursively for the frame hierarchy rooted at aFrame
|
|
|
|
nsIAtom* childListName = nsnull;
|
|
|
|
PRInt32 childListIndex = 0;
|
|
|
|
do {
|
|
|
|
nsIFrame* childFrame;
|
2000-01-22 04:16:50 +03:00
|
|
|
aFrame->FirstChild(aPresContext, childListName, &childFrame);
|
2001-05-30 15:26:21 +04:00
|
|
|
while (childFrame) {
|
1999-10-26 08:44:41 +04:00
|
|
|
rv = RestoreFrameState(aPresContext, childFrame, aState);
|
1999-10-23 05:43:49 +04:00
|
|
|
// Get the next sibling child frame
|
|
|
|
childFrame->GetNextSibling(&childFrame);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(childListName);
|
|
|
|
aFrame->GetAdditionalChildListName(childListIndex++, &childListName);
|
|
|
|
} while (childListName);
|
1999-08-31 18:35:50 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
|
|
|
|
static inline void KeyAppendSep(nsCString& aKey)
|
|
|
|
{
|
|
|
|
if (!aKey.IsEmpty()) {
|
|
|
|
aKey.Append(">");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void KeyAppendString(nsAReadableString& aString, nsCString& aKey)
|
|
|
|
{
|
|
|
|
KeyAppendSep(aKey);
|
|
|
|
|
|
|
|
// Could escape separator here if collisions happen. > is not a legal char
|
|
|
|
// for a name or type attribute, so we should be safe avoiding that extra work.
|
|
|
|
|
|
|
|
aKey.Append(NS_ConvertUCS2toUTF8(aString));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void KeyAppendInt(PRInt32 aInt, nsCString& aKey)
|
|
|
|
{
|
|
|
|
KeyAppendSep(aKey);
|
|
|
|
|
|
|
|
aKey.AppendInt(aInt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void KeyAppendAtom(nsIAtom* aAtom, nsCString& aKey)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aAtom, "KeyAppendAtom: aAtom can not be null!\n");
|
|
|
|
|
|
|
|
const PRUnichar* atomString = nsnull;
|
|
|
|
aAtom->GetUnicode(&atomString);
|
|
|
|
|
|
|
|
KeyAppendString(nsDependentString(atomString), aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::GenerateStateKey(nsIContent* aContent,
|
|
|
|
nsIStatefulFrame::SpecialStateID aID,
|
|
|
|
nsCString& aKey)
|
|
|
|
{
|
|
|
|
aKey.Truncate();
|
|
|
|
|
|
|
|
// SpecialStateID case - e.g. scrollbars around the content window
|
|
|
|
// The key in this case is the special state id (always < min(contentID))
|
|
|
|
if (nsIStatefulFrame::eNoID != aID) {
|
|
|
|
KeyAppendInt(aID, aKey);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We must have content if we're not using a special state id
|
|
|
|
NS_ENSURE_TRUE(aContent, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Don't capture state for anonymous content
|
|
|
|
PRUint32 contentID;
|
|
|
|
aContent->GetContentID(&contentID);
|
|
|
|
if (!contentID) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a dom element, add tag/type/name to hash key
|
|
|
|
// This is paranoia, but guarantees that we won't restore
|
|
|
|
// state to the wrong type of control.
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
if (aContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
|
|
|
|
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
KeyAppendAtom(tag, aKey);
|
|
|
|
|
|
|
|
nsAutoString name;
|
|
|
|
aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::name, name);
|
|
|
|
KeyAppendString(name, aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a form control and can calculate form information, use
|
|
|
|
// that as the key - it is more reliable than contentID.
|
|
|
|
// Important to have a unique key, and tag/type/name may not be.
|
|
|
|
nsCOMPtr<nsIFormControl> control(do_QueryInterface(aContent));
|
|
|
|
PRBool generatedUniqueKey = PR_FALSE;
|
|
|
|
if (control && mHTMLFormControls && mHTMLForms) {
|
|
|
|
|
|
|
|
if (tag == nsHTMLAtoms::input) {
|
|
|
|
PRInt32 type;
|
|
|
|
control->GetType(&type);
|
|
|
|
KeyAppendInt(type, aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If in a form, add form name / index of form / index in form
|
|
|
|
PRInt32 index = -1;
|
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> formElement;
|
|
|
|
control->GetForm(getter_AddRefs(formElement));
|
|
|
|
if (formElement) {
|
|
|
|
|
|
|
|
nsAutoString formName;
|
|
|
|
formElement->GetName(formName);
|
|
|
|
KeyAppendString(formName, aKey);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> formContent(do_QueryInterface(formElement));
|
|
|
|
mHTMLForms->IndexOf(formContent, index, PR_FALSE);
|
|
|
|
NS_ASSERTION(index > -1,
|
|
|
|
"nsFrameManager::GenerateStateKey didn't find form index!");
|
|
|
|
if (index > -1) {
|
|
|
|
KeyAppendInt(index, aKey);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIForm> form(do_QueryInterface(formElement));
|
|
|
|
form->IndexOfControl(control, &index);
|
|
|
|
NS_ASSERTION(index > -1,
|
|
|
|
"nsFrameManager::GenerateStateKey didn't find form control index!");
|
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
KeyAppendInt(index, aKey);
|
|
|
|
generatedUniqueKey = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// If not in a form, add index of control in document
|
|
|
|
// Less desirable than indexing by form info.
|
|
|
|
|
|
|
|
// Hash by index of control in doc (we are not in a form)
|
|
|
|
// These are important as they are unique, and type/name may not be.
|
|
|
|
mHTMLFormControls->IndexOf(aContent, index, PR_FALSE);
|
|
|
|
NS_ASSERTION(index > -1,
|
|
|
|
"nsFrameManager::GenerateStateKey didn't find content by type!");
|
|
|
|
if (index > -1) {
|
|
|
|
KeyAppendInt(index, aKey);
|
|
|
|
generatedUniqueKey = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!generatedUniqueKey) {
|
|
|
|
|
|
|
|
// Either we didn't have a form control or we aren't in an HTML document
|
|
|
|
// so we can't figure out form info, hash by content ID instead :(
|
|
|
|
KeyAppendInt(contentID, aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
static PLHashNumber
|
|
|
|
HashKey(void* key)
|
|
|
|
{
|
|
|
|
return (PLHashNumber)key;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRIntn
|
|
|
|
CompareKeys(void* key1, void* key2)
|
|
|
|
{
|
|
|
|
return key1 == key2;
|
|
|
|
}
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(FrameHashTable)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
FrameHashTable::FrameHashTable(PRUint32 aNumBuckets)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(FrameHashTable);
|
1999-08-06 00:17:44 +04:00
|
|
|
mTable = PL_NewHashTable(aNumBuckets, (PLHashFunction)HashKey,
|
|
|
|
(PLHashComparator)CompareKeys,
|
|
|
|
(PLHashComparator)nsnull,
|
|
|
|
nsnull, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameHashTable::~FrameHashTable()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(FrameHashTable);
|
1999-08-06 00:17:44 +04:00
|
|
|
PL_HashTableDestroy(mTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
FrameHashTable::Get(void* aKey)
|
|
|
|
{
|
|
|
|
PRInt32 hashCode = (PRInt32) aKey;
|
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(mTable, hashCode, aKey);
|
|
|
|
PLHashEntry* he = *hep;
|
1999-08-06 18:34:32 +04:00
|
|
|
if (he) {
|
1999-08-06 00:17:44 +04:00
|
|
|
return he->value;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
FrameHashTable::Put(void* aKey, void* aData)
|
|
|
|
{
|
|
|
|
PRInt32 hashCode = (PRInt32) aKey;
|
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(mTable, hashCode, aKey);
|
|
|
|
PLHashEntry* he = *hep;
|
1999-08-06 18:34:32 +04:00
|
|
|
if (he) {
|
1999-08-06 00:17:44 +04:00
|
|
|
void* oldValue = he->value;
|
|
|
|
he->value = aData;
|
|
|
|
return oldValue;
|
|
|
|
}
|
|
|
|
PL_HashTableRawAdd(mTable, hep, hashCode, aKey, aData);
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
FrameHashTable::Remove(void* aKey)
|
|
|
|
{
|
|
|
|
PRInt32 hashCode = (PRInt32) aKey;
|
|
|
|
PLHashEntry** hep = PL_HashTableRawLookup(mTable, hashCode, aKey);
|
|
|
|
PLHashEntry* he = *hep;
|
|
|
|
void* oldValue = nsnull;
|
1999-08-06 18:34:32 +04:00
|
|
|
if (he) {
|
1999-08-06 00:17:44 +04:00
|
|
|
oldValue = he->value;
|
|
|
|
PL_HashTableRawRemove(mTable, hep, he);
|
|
|
|
}
|
|
|
|
return oldValue;
|
|
|
|
}
|
|
|
|
|
2000-05-03 03:07:11 +04:00
|
|
|
static PRIntn PR_CALLBACK
|
1999-08-06 00:17:44 +04:00
|
|
|
RemoveEntry(PLHashEntry* he, PRIntn i, void* arg)
|
|
|
|
{
|
|
|
|
// Remove and free this entry and continue enumerating
|
|
|
|
return HT_ENUMERATE_REMOVE | HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameHashTable::Clear()
|
|
|
|
{
|
|
|
|
PL_HashTableEnumerateEntries(mTable, RemoveEntry, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
2000-05-03 03:07:11 +04:00
|
|
|
static PRIntn PR_CALLBACK
|
1999-08-06 00:17:44 +04:00
|
|
|
EnumEntries(PLHashEntry* he, PRIntn i, void* arg)
|
|
|
|
{
|
|
|
|
// Continue enumerating
|
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameHashTable::Dump(FILE* fp)
|
|
|
|
{
|
|
|
|
PL_HashTableDump(mTable, EnumEntries, fp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-16 04:55:48 +04:00
|
|
|
void
|
1999-10-19 18:41:55 +04:00
|
|
|
FrameManager::DestroyPropertyList(nsIPresContext* aPresContext)
|
1999-10-16 04:55:48 +04:00
|
|
|
{
|
|
|
|
if (mPropertyList) {
|
|
|
|
while (mPropertyList) {
|
|
|
|
PropertyList* tmp = mPropertyList;
|
|
|
|
|
|
|
|
mPropertyList = mPropertyList->mNext;
|
1999-10-19 18:41:55 +04:00
|
|
|
tmp->RemoveAllProperties(aPresContext);
|
1999-10-19 08:52:33 +04:00
|
|
|
delete tmp;
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameManager::PropertyList*
|
|
|
|
FrameManager::GetPropertyListFor(nsIAtom* aPropertyName) const
|
|
|
|
{
|
|
|
|
PropertyList* result;
|
|
|
|
|
|
|
|
for (result = mPropertyList; result; result = result->mNext) {
|
|
|
|
if (result->mName.get() == aPropertyName) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-10-19 18:41:55 +04:00
|
|
|
FrameManager::RemoveAllPropertiesFor(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame)
|
1999-10-16 04:55:48 +04:00
|
|
|
{
|
|
|
|
for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) {
|
1999-10-19 18:41:55 +04:00
|
|
|
prop->RemovePropertyForFrame(aPresContext, aFrame);
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::GetFrameProperty(nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPropertyName,
|
1999-10-19 08:52:33 +04:00
|
|
|
PRUint32 aOptions,
|
1999-10-16 04:55:48 +04:00
|
|
|
void** aPropertyValue)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aPropertyName);
|
1999-10-16 04:55:48 +04:00
|
|
|
PropertyList* propertyList = GetPropertyListFor(aPropertyName);
|
1999-10-21 09:11:43 +04:00
|
|
|
nsresult result;
|
1999-10-16 04:55:48 +04:00
|
|
|
|
|
|
|
if (propertyList) {
|
1999-10-21 09:11:43 +04:00
|
|
|
result = propertyList->mFrameValueMap->Search(aFrame, aOptions, aPropertyValue);
|
|
|
|
|
1999-10-16 04:55:48 +04:00
|
|
|
} else {
|
|
|
|
*aPropertyValue = 0;
|
1999-10-21 09:11:43 +04:00
|
|
|
result = NS_IFRAME_MGR_PROP_NOT_THERE;
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
|
1999-10-21 09:11:43 +04:00
|
|
|
return result;
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-21 09:11:43 +04:00
|
|
|
FrameManager::SetFrameProperty(nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue,
|
|
|
|
NSFMPropertyDtorFunc aPropDtorFunc)
|
1999-10-16 04:55:48 +04:00
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aPropertyName);
|
1999-10-16 04:55:48 +04:00
|
|
|
PropertyList* propertyList = GetPropertyListFor(aPropertyName);
|
1999-10-21 09:11:43 +04:00
|
|
|
nsresult result = NS_OK;
|
1999-10-16 04:55:48 +04:00
|
|
|
|
|
|
|
if (propertyList) {
|
|
|
|
// Make sure the dtor function matches
|
|
|
|
if (aPropDtorFunc != propertyList->mDtorFunc) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
1999-10-18 23:02:09 +04:00
|
|
|
propertyList = new PropertyList(aPropertyName, aPropDtorFunc, mDSTNodeArena);
|
1999-10-16 04:55:48 +04:00
|
|
|
if (!propertyList) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
propertyList->mNext = mPropertyList;
|
|
|
|
mPropertyList = propertyList;
|
|
|
|
}
|
|
|
|
|
1999-10-19 08:52:33 +04:00
|
|
|
// The current property value (if there is one) is replaced and the current
|
|
|
|
// value is destroyed
|
1999-10-21 09:11:43 +04:00
|
|
|
void* oldValue;
|
|
|
|
result = propertyList->mFrameValueMap->Insert(aFrame, aPropertyValue, &oldValue);
|
|
|
|
if (NS_DST_VALUE_OVERWRITTEN == result) {
|
|
|
|
if (propertyList->mDtorFunc) {
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
mPresShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
propertyList->mDtorFunc(presContext, aFrame, aPropertyName, oldValue);
|
|
|
|
}
|
1999-10-19 08:52:33 +04:00
|
|
|
}
|
|
|
|
|
1999-10-21 09:11:43 +04:00
|
|
|
return result;
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FrameManager::RemoveFrameProperty(nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPropertyName)
|
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
1999-10-21 09:11:43 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aPropertyName);
|
1999-10-16 04:55:48 +04:00
|
|
|
PropertyList* propertyList = GetPropertyListFor(aPropertyName);
|
1999-10-21 09:11:43 +04:00
|
|
|
nsresult result = NS_IFRAME_MGR_PROP_NOT_THERE;
|
1999-10-16 04:55:48 +04:00
|
|
|
|
|
|
|
if (propertyList) {
|
1999-10-19 18:41:55 +04:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
mPresShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
1999-10-21 09:11:43 +04:00
|
|
|
if (propertyList->RemovePropertyForFrame(presContext, aFrame)) {
|
|
|
|
result = NS_OK;
|
|
|
|
}
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
|
1999-10-21 09:11:43 +04:00
|
|
|
return result;
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
|
2000-11-28 01:00:33 +03:00
|
|
|
NS_IMETHODIMP
|
2001-06-04 04:22:43 +04:00
|
|
|
FrameManager::GetInsertionPoint(nsIPresShell* aShell, nsIFrame* aParent, nsIContent* aChild, nsIFrame** aResult)
|
2000-11-28 01:00:33 +03:00
|
|
|
{
|
2001-03-06 04:46:03 +03:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2001-06-04 04:22:43 +04:00
|
|
|
*aResult = aParent;
|
2000-11-28 01:00:33 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
aParent->GetContent(getter_AddRefs(content));
|
|
|
|
if (!content)
|
|
|
|
return NS_OK;
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
content->GetDocument(*getter_AddRefs(document));
|
|
|
|
if (!document)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBindingManager> bindingManager;
|
|
|
|
document->GetBindingManager(getter_AddRefs(bindingManager));
|
|
|
|
if (!bindingManager)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> insertionElement;
|
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
if (aChild) {
|
|
|
|
// Check to see if the content is anonymous.
|
|
|
|
nsCOMPtr<nsIContent> bindingParent;
|
2001-06-04 04:22:43 +04:00
|
|
|
aChild->GetBindingParent(getter_AddRefs(bindingParent));
|
2000-11-28 01:00:33 +03:00
|
|
|
if (bindingParent == content)
|
|
|
|
return NS_OK; // It is anonymous. Don't use the insertion point, since that's only
|
|
|
|
// for the explicit kids.
|
|
|
|
|
2001-02-02 03:54:47 +03:00
|
|
|
PRUint32 index;
|
2001-06-04 04:22:43 +04:00
|
|
|
bindingManager->GetInsertionPoint(content, aChild, getter_AddRefs(insertionElement), &index);
|
2000-11-28 01:00:33 +03:00
|
|
|
if (insertionElement) {
|
|
|
|
aShell->GetPrimaryFrameFor(insertionElement, &frame);
|
|
|
|
if (frame) {
|
|
|
|
nsCOMPtr<nsIScrollableFrame> scroll(do_QueryInterface(frame));
|
|
|
|
if (scroll)
|
|
|
|
scroll->GetScrolledFrame(nsnull, frame);
|
2001-06-04 04:22:43 +04:00
|
|
|
if (frame != aParent)
|
|
|
|
GetInsertionPoint(aShell, frame, aChild, aResult);
|
2000-11-28 01:00:33 +03:00
|
|
|
}
|
2001-06-04 04:22:43 +04:00
|
|
|
else
|
|
|
|
*aResult = nsnull; // There was no frame created yet for the insertion point.
|
2000-11-28 01:00:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRBool dummy;
|
2001-02-02 03:54:47 +03:00
|
|
|
PRUint32 index;
|
|
|
|
bindingManager->GetSingleInsertionPoint(content, getter_AddRefs(insertionElement), &index, &dummy);
|
2000-11-28 01:00:33 +03:00
|
|
|
if (insertionElement) {
|
|
|
|
aShell->GetPrimaryFrameFor(insertionElement, &frame);
|
|
|
|
if (frame) {
|
|
|
|
nsCOMPtr<nsIScrollableFrame> scroll(do_QueryInterface(frame));
|
|
|
|
if (scroll)
|
|
|
|
scroll->GetScrolledFrame(nsnull, frame);
|
2001-06-04 04:22:43 +04:00
|
|
|
if (frame != aParent)
|
|
|
|
GetInsertionPoint(aShell, frame, aChild, aResult);
|
2000-11-28 01:00:33 +03:00
|
|
|
}
|
2001-06-04 04:22:43 +04:00
|
|
|
else
|
|
|
|
*aResult = nsnull; // No frame yet.
|
2000-11-28 01:00:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(UndisplayedMap)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
1999-10-02 08:25:29 +04:00
|
|
|
UndisplayedMap::UndisplayedMap(PRUint32 aNumBuckets)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(UndisplayedMap);
|
1999-10-02 08:25:29 +04:00
|
|
|
mTable = PL_NewHashTable(aNumBuckets, (PLHashFunction)HashKey,
|
|
|
|
(PLHashComparator)CompareKeys,
|
|
|
|
(PLHashComparator)nsnull,
|
|
|
|
nsnull, nsnull);
|
|
|
|
mLastLookup = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndisplayedMap::~UndisplayedMap(void)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(UndisplayedMap);
|
1999-10-02 08:25:29 +04:00
|
|
|
Clear();
|
|
|
|
PL_HashTableDestroy(mTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLHashEntry**
|
|
|
|
UndisplayedMap::GetEntryFor(nsIContent* aParentContent)
|
|
|
|
{
|
|
|
|
if (mLastLookup && (aParentContent == (*mLastLookup)->key)) {
|
|
|
|
return mLastLookup;
|
|
|
|
}
|
|
|
|
PLHashNumber hashCode = (PLHashNumber)(void*)aParentContent;
|
|
|
|
PLHashEntry** entry = PL_HashTableRawLookup(mTable, hashCode, aParentContent);
|
|
|
|
if (*entry) {
|
|
|
|
mLastLookup = entry;
|
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndisplayedNode*
|
|
|
|
UndisplayedMap::GetFirstNode(nsIContent* aParentContent)
|
|
|
|
{
|
|
|
|
PLHashEntry** entry = GetEntryFor(aParentContent);
|
|
|
|
if (*entry) {
|
|
|
|
return (UndisplayedNode*)((*entry)->value);
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
UndisplayedMap::AppendNodeFor(UndisplayedNode* aNode, nsIContent* aParentContent)
|
|
|
|
{
|
|
|
|
PLHashEntry** entry = GetEntryFor(aParentContent);
|
|
|
|
if (*entry) {
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)((*entry)->value);
|
|
|
|
while (node->mNext) {
|
|
|
|
NS_ASSERTION((node->mContent != aNode->mContent) ||
|
|
|
|
((node->mContent == nsnull) &&
|
|
|
|
(node->mStyle != aNode->mStyle)), "node in map twice");
|
|
|
|
node = node->mNext;
|
|
|
|
}
|
|
|
|
node->mNext = aNode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PLHashNumber hashCode = (PLHashNumber)(void*)aParentContent;
|
|
|
|
PL_HashTableRawAdd(mTable, entry, hashCode, aParentContent, aNode);
|
|
|
|
mLastLookup = nsnull; // hashtable may have shifted bucket out from under us
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
UndisplayedMap::AddNodeFor(nsIContent* aParentContent, nsIContent* aChild,
|
|
|
|
nsIStyleContext* aStyle)
|
|
|
|
{
|
|
|
|
UndisplayedNode* node = new UndisplayedNode(aChild, aStyle);
|
|
|
|
if (! node) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return AppendNodeFor(node, aParentContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
UndisplayedMap::AddNodeFor(nsIContent* aParentContent, nsIStyleContext* aPseudoStyle)
|
|
|
|
{
|
|
|
|
UndisplayedNode* node = new UndisplayedNode(aPseudoStyle);
|
|
|
|
if (! node) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return AppendNodeFor(node, aParentContent);
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
nsresult
|
|
|
|
UndisplayedMap::GetNodeFor(nsIContent* aContent, nsIStyleContext** aResult)
|
|
|
|
{
|
|
|
|
PLHashEntry** entry = GetEntryFor(aContent);
|
|
|
|
if (*entry) {
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)((*entry)->value);
|
|
|
|
*aResult = node->mStyle;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*aResult = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-02 08:25:29 +04:00
|
|
|
nsresult
|
|
|
|
UndisplayedMap::RemoveNodeFor(nsIContent* aParentContent, UndisplayedNode* aNode)
|
|
|
|
{
|
|
|
|
PLHashEntry** entry = GetEntryFor(aParentContent);
|
|
|
|
NS_ASSERTION(*entry, "content not in map");
|
|
|
|
if (*entry) {
|
|
|
|
if ((UndisplayedNode*)((*entry)->value) == aNode) { // first node
|
|
|
|
if (aNode->mNext) {
|
|
|
|
(*entry)->value = aNode->mNext;
|
|
|
|
aNode->mNext = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PL_HashTableRawRemove(mTable, entry, *entry);
|
|
|
|
mLastLookup = nsnull; // hashtable may have shifted bucket out from under us
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)((*entry)->value);
|
|
|
|
while (node->mNext) {
|
|
|
|
if (node->mNext == aNode) {
|
|
|
|
node->mNext = aNode->mNext;
|
|
|
|
aNode->mNext = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = node->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete aNode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
UndisplayedMap::RemoveNodesFor(nsIContent* aParentContent)
|
|
|
|
{
|
|
|
|
PLHashEntry** entry = GetEntryFor(aParentContent);
|
|
|
|
NS_ASSERTION(entry, "content not in map");
|
|
|
|
if (*entry) {
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)((*entry)->value);
|
|
|
|
delete node;
|
|
|
|
if (entry == mLastLookup) {
|
|
|
|
mLastLookup = nsnull;
|
|
|
|
}
|
|
|
|
PL_HashTableRawRemove(mTable, entry, *entry);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-03 03:07:11 +04:00
|
|
|
static PRIntn PR_CALLBACK
|
1999-10-02 08:25:29 +04:00
|
|
|
RemoveUndisplayedEntry(PLHashEntry* he, PRIntn i, void* arg)
|
|
|
|
{
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)(he->value);
|
|
|
|
delete node;
|
|
|
|
// Remove and free this entry and continue enumerating
|
|
|
|
return HT_ENUMERATE_REMOVE | HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UndisplayedMap::Clear(void)
|
|
|
|
{
|
|
|
|
mLastLookup = nsnull;
|
|
|
|
PL_HashTableEnumerateEntries(mTable, RemoveUndisplayedEntry, 0);
|
|
|
|
}
|
1999-10-16 04:55:48 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-10-21 09:11:43 +04:00
|
|
|
FrameManager::PropertyList::PropertyList(nsIAtom* aName,
|
|
|
|
NSFMPropertyDtorFunc aDtorFunc,
|
|
|
|
nsDST::NodeArena* aDSTNodeArena)
|
1999-10-18 23:02:09 +04:00
|
|
|
: mName(aName), mFrameValueMap(new nsDST(aDSTNodeArena)),
|
|
|
|
mDtorFunc(aDtorFunc), mNext(nsnull)
|
1999-10-16 04:55:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-10-19 18:41:55 +04:00
|
|
|
FrameManager::PropertyList::~PropertyList()
|
|
|
|
{
|
|
|
|
delete mFrameValueMap;
|
|
|
|
}
|
|
|
|
|
1999-10-16 04:55:48 +04:00
|
|
|
class DestroyPropertyValuesFunctor : public nsDSTNodeFunctor {
|
|
|
|
public:
|
1999-10-21 09:11:43 +04:00
|
|
|
DestroyPropertyValuesFunctor(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aPropertyName,
|
|
|
|
NSFMPropertyDtorFunc aDtorFunc)
|
1999-10-19 18:41:55 +04:00
|
|
|
: mPresContext(aPresContext), mPropertyName(aPropertyName), mDtorFunc(aDtorFunc) {}
|
1999-10-16 04:55:48 +04:00
|
|
|
|
|
|
|
virtual void operator () (void *aKey, void *aValue) {
|
1999-10-19 18:41:55 +04:00
|
|
|
mDtorFunc(mPresContext, (nsIFrame*)aKey, mPropertyName, aValue);
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
|
1999-10-21 09:11:43 +04:00
|
|
|
nsIPresContext* mPresContext;
|
|
|
|
nsIAtom* mPropertyName;
|
|
|
|
NSFMPropertyDtorFunc mDtorFunc;
|
1999-10-16 04:55:48 +04:00
|
|
|
};
|
|
|
|
|
1999-10-19 18:41:55 +04:00
|
|
|
void
|
|
|
|
FrameManager::PropertyList::RemoveAllProperties(nsIPresContext* aPresContext)
|
1999-10-16 04:55:48 +04:00
|
|
|
{
|
|
|
|
if (mDtorFunc) {
|
1999-10-19 18:41:55 +04:00
|
|
|
DestroyPropertyValuesFunctor functor(aPresContext, mName, mDtorFunc);
|
1999-10-16 04:55:48 +04:00
|
|
|
|
|
|
|
// Enumerate any remaining frame/value pairs and destroy the value object
|
|
|
|
mFrameValueMap->Enumerate(functor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-21 09:11:43 +04:00
|
|
|
PRBool
|
1999-10-19 18:41:55 +04:00
|
|
|
FrameManager::PropertyList::RemovePropertyForFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame)
|
1999-10-16 04:55:48 +04:00
|
|
|
{
|
1999-10-21 09:11:43 +04:00
|
|
|
void* value;
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
// If the property exists, then we need to run the dtor function so
|
|
|
|
// do a search with the option to remove the key/value pair
|
|
|
|
result = mFrameValueMap->Search(aFrame, NS_DST_REMOVE_KEY_VALUE, &value);
|
|
|
|
|
|
|
|
if (NS_OK == result) {
|
|
|
|
// The property was set
|
|
|
|
if (mDtorFunc) {
|
|
|
|
// Destroy the property value
|
|
|
|
mDtorFunc(aPresContext, aFrame, mName, value);
|
|
|
|
}
|
1999-10-16 04:55:48 +04:00
|
|
|
|
1999-10-21 09:11:43 +04:00
|
|
|
return PR_TRUE;
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
1999-10-21 09:11:43 +04:00
|
|
|
|
|
|
|
return PR_FALSE;
|
1999-10-16 04:55:48 +04:00
|
|
|
}
|
|
|
|
|