1998-04-14 00:24:54 +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/
|
1998-04-14 00:24:54 +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.
|
1998-04-14 00:24:54 +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
|
1998-04-14 00:24:54 +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):
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
1999-10-08 07:09:31 +04:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIStyleRule.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIFrame.h"
|
1998-09-10 23:32:14 +04:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIContent.h"
|
1999-01-23 10:01:57 +03:00
|
|
|
#include "nsIDocument.h"
|
1998-09-10 23:32:14 +04:00
|
|
|
#include "nsIStyleFrameConstruction.h"
|
1998-12-02 03:30:42 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-11-10 06:41:09 +03:00
|
|
|
#include "nsTimer.h"
|
2000-06-03 01:45:06 +04:00
|
|
|
#include "nsICSSStyleSheet.h"
|
|
|
|
#include "nsNetUtil.h"
|
2000-08-12 10:28:02 +04:00
|
|
|
#include "nsIStyleRuleSupplier.h"
|
|
|
|
|
1999-10-20 02:27:20 +04:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
2000-02-11 04:21:36 +03:00
|
|
|
#include "nsITimeRecorder.h"
|
|
|
|
#define STYLESET_START_TIMER(a) \
|
|
|
|
StartTimer(a)
|
|
|
|
#define STYLESET_STOP_TIMER(a) \
|
|
|
|
StopTimer(a)
|
|
|
|
#else
|
|
|
|
#define STYLESET_START_TIMER(a) ((void)0)
|
|
|
|
#define STYLESET_STOP_TIMER(a) ((void)0)
|
1999-09-20 10:53:40 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsISizeOfHandler.h"
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-12-22 02:34:44 +03:00
|
|
|
// - fast cache uses a CRC32 on the style context to quickly find sharing candidates.
|
|
|
|
// Enabling it by defining USE_FAST_CACHE makes style sharing significantly faster
|
|
|
|
// but introduces more code and logic, and is thus potentially more error-prone
|
|
|
|
// - Enabled by default: disable to determine if there are problems in the fast-cache
|
|
|
|
// NOTE: make sure the define COMPUTE_STYLEDATA_CRC is ON in nsStyleContext.cpp for
|
|
|
|
// this to be affective...
|
|
|
|
#define USE_FAST_CACHE
|
2000-06-22 00:44:59 +04:00
|
|
|
|
2000-12-22 02:34:44 +03:00
|
|
|
#ifdef USE_FAST_CACHE
|
|
|
|
///////////////////////////////////////
|
|
|
|
// DEBUG defines for the fast cache:
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
|
|
|
// - define DUMP_CACHE_STATS to get a dump of the cache's depth and breadth
|
2000-06-22 00:44:59 +04:00
|
|
|
//#define DUMP_CACHE_STATS
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-12-22 02:34:44 +03:00
|
|
|
// - define ENABLE_FAST_CACHE_TICKLE to enable tickling of each element in the cache
|
|
|
|
// whenever the cache is accessed (to find stale pointers)
|
|
|
|
//#define ENABLE_FAST_CACHE_TICKLE
|
|
|
|
|
|
|
|
#endif //ifdef USE_FAST_CACHE
|
|
|
|
|
|
|
|
|
2001-01-03 02:13:49 +03:00
|
|
|
#ifdef USE_FAST_CACHE
|
|
|
|
|
|
|
|
PRBool PR_CALLBACK HashTableEnumDestroy(nsHashKey *aKey, void *aData, void* closure);
|
|
|
|
PRBool PR_CALLBACK HashTableEnumDump(nsHashKey *aKey, void *aData, void* closure);
|
|
|
|
PRBool PR_CALLBACK HashTableEnumTickle(nsHashKey *aKey, void *aData, void* closure);
|
|
|
|
|
|
|
|
class StyleContextCache
|
|
|
|
{
|
|
|
|
// friendship for the Destroy method...
|
|
|
|
friend PRBool PR_CALLBACK HashTableEnumDestroy(nsHashKey *aKey, void *aData, void* closure);
|
|
|
|
|
|
|
|
public :
|
|
|
|
StyleContextCache(void);
|
|
|
|
~StyleContextCache(void);
|
|
|
|
|
|
|
|
nsresult AddContext(scKey aKey, nsIStyleContext *aContext);
|
|
|
|
nsresult RemoveContext(scKey aKey, nsIStyleContext *aContext);
|
|
|
|
nsresult RemoveAllContexts(scKey aKey);
|
|
|
|
nsresult GetContexts(scKey aKey, nsVoidArray **aResults); // do not munge list
|
|
|
|
PRUint32 Count(void);
|
|
|
|
private:
|
|
|
|
StyleContextCache(StyleContextCache &aNoSrcAllowed); // Not Implemented
|
|
|
|
|
|
|
|
void DumpStats(void);
|
|
|
|
void Tickle(const char *msg = nsnull);
|
|
|
|
|
|
|
|
// make sure there is a list for the specified key (allocates one if necessary)
|
|
|
|
nsresult VerifyList(scKey aKey);
|
|
|
|
// returns the list for the key, may be null
|
|
|
|
nsVoidArray *GetList(scKey aKey);
|
|
|
|
|
|
|
|
// allocate / destroy the list
|
|
|
|
static nsVoidArray *AllocateList(void);
|
|
|
|
static nsresult DestroyList(nsVoidArray* aList);
|
|
|
|
|
|
|
|
nsObjectHashtable mHashTable;
|
|
|
|
PRUint32 mCount;
|
|
|
|
};
|
|
|
|
#endif /* USE_FSAT_CACHE */
|
|
|
|
|
|
|
|
|
1999-09-20 10:53:40 +04:00
|
|
|
class StyleSetImpl : public nsIStyleSet
|
1999-10-20 02:27:20 +04:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
1999-09-20 10:53:40 +04:00
|
|
|
, public nsITimeRecorder
|
|
|
|
#endif
|
|
|
|
{
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
|
|
|
StyleSetImpl();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
virtual void AppendOverrideStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual void InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aAfterSheet);
|
|
|
|
virtual void InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aBeforeSheet);
|
|
|
|
virtual void RemoveOverrideStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual PRInt32 GetNumberOfOverrideStyleSheets();
|
|
|
|
virtual nsIStyleSheet* GetOverrideStyleSheetAt(PRInt32 aIndex);
|
|
|
|
|
1999-01-23 10:01:57 +03:00
|
|
|
virtual void AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument);
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual void RemoveDocStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual PRInt32 GetNumberOfDocStyleSheets();
|
|
|
|
virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex);
|
|
|
|
|
|
|
|
virtual void AppendBackstopStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual void InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aAfterSheet);
|
|
|
|
virtual void InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aBeforeSheet);
|
|
|
|
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual PRInt32 GetNumberOfBackstopStyleSheets();
|
|
|
|
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex);
|
2000-05-28 00:03:14 +04:00
|
|
|
virtual void ReplaceBackstopStyleSheets(nsISupportsArray* aNewSheets);
|
2000-06-22 00:44:59 +04:00
|
|
|
|
2000-06-03 01:45:06 +04:00
|
|
|
NS_IMETHOD EnableQuirkStyleSheet(PRBool aEnable);
|
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
NS_IMETHOD NotifyStyleSheetStateChanged(PRBool aDisabled);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual nsIStyleContext* ResolveStyleFor(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-06-05 10:00:55 +04:00
|
|
|
PRBool aForceUnique = PR_FALSE);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 01:05:52 +04:00
|
|
|
virtual nsIStyleContext* ResolvePseudoStyleFor(nsIPresContext* aPresContext,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIContent* aParentContent,
|
1998-05-19 01:05:52 +04:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
2001-02-16 00:24:47 +03:00
|
|
|
PRBool aForceUnique = PR_FALSE,
|
|
|
|
nsICSSPseudoComparator* aComparator = nsnull);
|
1998-05-19 01:05:52 +04:00
|
|
|
|
|
|
|
virtual nsIStyleContext* ProbePseudoStyleFor(nsIPresContext* aPresContext,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIContent* aParentContent,
|
1998-05-19 01:05:52 +04:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-06-05 10:00:55 +04:00
|
|
|
PRBool aForceUnique = PR_FALSE);
|
1998-05-19 01:05:52 +04:00
|
|
|
|
1999-09-04 03:35:41 +04:00
|
|
|
NS_IMETHOD ReParentStyleContext(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIStyleContext* aNewParentContext,
|
|
|
|
nsIStyleContext** aNewStyleContext);
|
|
|
|
|
1999-04-20 04:02:22 +04:00
|
|
|
NS_IMETHOD HasStateDependentStyle(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent);
|
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
NS_IMETHOD ConstructRootFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame*& aFrameSubTree);
|
1999-03-01 19:57:35 +03:00
|
|
|
NS_IMETHOD ReconstructDocElementHierarchy(nsIPresContext* aPresContext);
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IMETHOD ContentAppended(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer);
|
|
|
|
NS_IMETHOD ContentInserted(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
NS_IMETHOD ContentReplaced(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
NS_IMETHOD ContentRemoved(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
|
1998-09-30 03:47:03 +04:00
|
|
|
NS_IMETHOD ContentChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsISupports* aSubContent);
|
1999-04-20 04:02:22 +04:00
|
|
|
NS_IMETHOD ContentStatesChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2);
|
1998-09-30 03:47:03 +04:00
|
|
|
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
1999-10-16 03:16:45 +04:00
|
|
|
PRInt32 aNameSpaceID,
|
1998-09-30 03:47:03 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint); // See nsStyleConsts fot hint values
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// xxx style rules enumeration
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// Style change notifications
|
|
|
|
NS_IMETHOD StyleRuleChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint); // See nsStyleConsts fot hint values
|
|
|
|
NS_IMETHOD StyleRuleAdded(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
|
|
|
NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
|
|
|
|
1999-02-04 20:03:46 +03:00
|
|
|
// Notification that we were unable to render a replaced element.
|
|
|
|
NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame);
|
|
|
|
|
1999-02-24 07:03:50 +03:00
|
|
|
// Request to create a continuing frame
|
|
|
|
NS_IMETHOD CreateContinuingFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame** aContinuingFrame);
|
|
|
|
|
1999-07-02 08:46:19 +04:00
|
|
|
// Request to find the primary frame associated with a given content object.
|
|
|
|
// This is typically called by the pres shell when there is no mapping in
|
|
|
|
// the pres shell hash table
|
1999-08-05 07:09:22 +04:00
|
|
|
NS_IMETHOD FindPrimaryFrameFor(nsIPresContext* aPresContext,
|
|
|
|
nsIFrameManager* aFrameManager,
|
|
|
|
nsIContent* aContent,
|
2001-01-17 01:10:04 +03:00
|
|
|
nsIFrame** aFrame,
|
|
|
|
nsFindFrameHint* aHint);
|
1999-07-02 08:46:19 +04:00
|
|
|
|
2000-08-12 10:28:02 +04:00
|
|
|
// APIs for registering objects that can supply additional
|
|
|
|
// rules during processing.
|
|
|
|
NS_IMETHOD SetStyleRuleSupplier(nsIStyleRuleSupplier* aSupplier);
|
|
|
|
NS_IMETHOD GetStyleRuleSupplier(nsIStyleRuleSupplier** aSupplier);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0);
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize);
|
|
|
|
virtual void ResetUniqueStyleItems(void);
|
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef SHARE_STYLECONTEXTS
|
2000-03-31 11:08:36 +04:00
|
|
|
// add and remove from the cache of all contexts
|
|
|
|
NS_IMETHOD AddStyleContext(nsIStyleContext *aNewStyleContext);
|
|
|
|
NS_IMETHOD RemoveStyleContext(nsIStyleContext *aNewStyleContext);
|
2000-06-22 00:44:59 +04:00
|
|
|
NS_IMETHOD FindMatchingContext(nsIStyleContext *aStyleContextToMatch,
|
|
|
|
nsIStyleContext **aMatchingContext);
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
|
|
|
|
1999-10-20 02:27:20 +04:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
1999-09-20 10:53:40 +04:00
|
|
|
NS_DECL_NSITIMERECORDER
|
|
|
|
#endif
|
|
|
|
|
2000-05-16 06:43:33 +04:00
|
|
|
NS_IMETHOD AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
|
|
|
|
PRBool &aAffects);
|
|
|
|
|
2000-08-12 10:28:02 +04:00
|
|
|
void WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, void* aData,
|
|
|
|
nsIContent* aContent);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
private:
|
2000-11-08 06:13:53 +03:00
|
|
|
static nsrefcnt gInstances;
|
|
|
|
static nsIURI *gQuirkURI;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// These are not supported and are not implemented!
|
|
|
|
StyleSetImpl(const StyleSetImpl& aCopy);
|
|
|
|
StyleSetImpl& operator=(const StyleSetImpl& aCopy);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~StyleSetImpl();
|
|
|
|
PRBool EnsureArray(nsISupportsArray** aArray);
|
1999-10-08 07:09:31 +04:00
|
|
|
void RecycleArray(nsISupportsArray** aArray);
|
2000-08-12 10:28:02 +04:00
|
|
|
|
|
|
|
void ClearRuleProcessors(void);
|
|
|
|
void ClearOverrideRuleProcessors(void);
|
|
|
|
void ClearBackstopRuleProcessors(void);
|
|
|
|
void ClearDocRuleProcessors(void);
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
nsresult GatherRuleProcessors(void);
|
|
|
|
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* GetContext(nsIPresContext* aPresContext, nsIStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag, nsISupportsArray* aRules, PRBool aForceUnique,
|
|
|
|
PRBool& aUsedRules);
|
1998-04-14 00:24:54 +04:00
|
|
|
void List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets);
|
1998-06-26 09:49:01 +04:00
|
|
|
void ListContexts(nsIStyleContext* aRootContext, FILE* out, PRInt32 aIndent);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
nsISupportsArray* mOverrideSheets; // most significant first
|
|
|
|
nsISupportsArray* mDocSheets; // " "
|
|
|
|
nsISupportsArray* mBackstopSheets; // " "
|
|
|
|
|
2000-08-12 10:28:02 +04:00
|
|
|
nsISupportsArray* mBackstopRuleProcessors; // least significant first
|
|
|
|
nsISupportsArray* mDocRuleProcessors; // " "
|
|
|
|
nsISupportsArray* mOverrideRuleProcessors; // " "
|
1999-10-08 07:09:31 +04:00
|
|
|
|
1998-10-13 23:09:39 +04:00
|
|
|
nsISupportsArray* mRecycler;
|
1998-11-03 23:19:28 +03:00
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
nsIStyleFrameConstruction* mFrameConstructor;
|
2000-06-03 01:45:06 +04:00
|
|
|
nsIStyleSheet* mQuirkStyleSheet; // cached instance for enabling/disabling
|
|
|
|
|
2000-08-12 10:28:02 +04:00
|
|
|
nsCOMPtr<nsIStyleRuleSupplier> mStyleRuleSupplier;
|
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef SHARE_STYLECONTEXTS
|
|
|
|
|
|
|
|
#ifdef USE_FAST_CACHE
|
|
|
|
// a cache of all style contexts for faster searching
|
|
|
|
// when we want to find style contexts in GetContext
|
|
|
|
StyleContextCache mStyleContextCache;
|
|
|
|
#else
|
|
|
|
nsVoidArray mStyleContextCache;
|
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
|
|
|
|
1999-11-12 00:35:34 +03:00
|
|
|
MOZ_TIMER_DECLARE(mStyleResolutionWatch)
|
2000-02-11 04:21:36 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_PERF_METRICS
|
|
|
|
PRBool mTimerEnabled; // true if timing is enabled, false if disabled
|
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2000-11-08 06:13:53 +03:00
|
|
|
nsrefcnt StyleSetImpl::gInstances = 0;
|
|
|
|
nsIURI *StyleSetImpl::gQuirkURI = 0;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
StyleSetImpl::StyleSetImpl()
|
|
|
|
: mOverrideSheets(nsnull),
|
|
|
|
mDocSheets(nsnull),
|
1998-09-10 23:32:14 +04:00
|
|
|
mBackstopSheets(nsnull),
|
2000-08-12 10:28:02 +04:00
|
|
|
mBackstopRuleProcessors(nsnull),
|
|
|
|
mDocRuleProcessors(nsnull),
|
|
|
|
mOverrideRuleProcessors(nsnull),
|
1999-02-12 20:45:58 +03:00
|
|
|
mRecycler(nsnull),
|
2000-06-22 00:44:59 +04:00
|
|
|
mFrameConstructor(nsnull),
|
2000-08-12 10:28:02 +04:00
|
|
|
mQuirkStyleSheet(nsnull),
|
|
|
|
mStyleRuleSupplier(nsnull)
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef SHARE_STYLECONTEXTS
|
|
|
|
#ifdef USE_FAST_CACHE
|
|
|
|
,mStyleContextCache()
|
|
|
|
#else
|
2000-03-31 11:08:36 +04:00
|
|
|
,mStyleContextCache(0)
|
2000-06-22 00:44:59 +04:00
|
|
|
#endif // USE_FAST_CACHE
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
2000-02-11 04:21:36 +03:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
|
|
|
,mTimerEnabled(PR_FALSE)
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
2000-11-08 06:13:53 +03:00
|
|
|
if (gInstances++ == 0)
|
|
|
|
{
|
|
|
|
const char kQuirk_href[] = "resource:/res/quirk.css";
|
|
|
|
NS_NewURI (&gQuirkURI, kQuirk_href);
|
|
|
|
NS_ASSERTION (gQuirkURI != 0, "Cannot allocate nsStyleSetImpl::gQuirkURI");
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
StyleSetImpl::~StyleSetImpl()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mOverrideSheets);
|
|
|
|
NS_IF_RELEASE(mDocSheets);
|
|
|
|
NS_IF_RELEASE(mBackstopSheets);
|
2000-08-12 10:28:02 +04:00
|
|
|
NS_IF_RELEASE(mBackstopRuleProcessors);
|
|
|
|
NS_IF_RELEASE(mDocRuleProcessors);
|
|
|
|
NS_IF_RELEASE(mOverrideRuleProcessors);
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IF_RELEASE(mFrameConstructor);
|
1998-10-13 23:09:39 +04:00
|
|
|
NS_IF_RELEASE(mRecycler);
|
2000-06-03 01:45:06 +04:00
|
|
|
NS_IF_RELEASE(mQuirkStyleSheet);
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef SHARE_STYLECONTEXTS
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION( mStyleContextCache.Count() == 0, "StyleContextCache is not empty in StyleSet destructor: style contexts are being leaked");
|
|
|
|
if (mStyleContextCache.Count() > 0) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("*** Leaking %d style context instances (reported by the StyleContextCache) ***\n", mStyleContextCache.Count());
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
2000-11-08 06:13:53 +03:00
|
|
|
if (--gInstances == 0)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE (gQuirkURI);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-10-20 02:27:20 +04:00
|
|
|
#ifndef MOZ_PERF_METRICS
|
2001-01-04 23:44:42 +03:00
|
|
|
NS_IMPL_ISUPPORTS(StyleSetImpl, NS_GET_IID(nsIStyleSet))
|
1999-09-20 10:53:40 +04:00
|
|
|
#else
|
|
|
|
NS_IMPL_ISUPPORTS2(StyleSetImpl, nsIStyleSet, nsITimeRecorder)
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
PRBool StyleSetImpl::EnsureArray(nsISupportsArray** aArray)
|
|
|
|
{
|
|
|
|
if (nsnull == *aArray) {
|
1999-10-08 07:09:31 +04:00
|
|
|
(*aArray) = mRecycler;
|
|
|
|
mRecycler = nsnull;
|
|
|
|
if (nsnull == *aArray) {
|
|
|
|
if (NS_OK != NS_NewISupportsArray(aArray)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleSetImpl::RecycleArray(nsISupportsArray** aArray)
|
|
|
|
{
|
|
|
|
if (! mRecycler) {
|
|
|
|
mRecycler = *aArray; // take ref
|
|
|
|
mRecycler->Clear();
|
|
|
|
*aArray = nsnull;
|
|
|
|
}
|
|
|
|
else { // already have a recycled array
|
|
|
|
NS_RELEASE(*aArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleSetImpl::ClearRuleProcessors(void)
|
|
|
|
{
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearBackstopRuleProcessors();
|
|
|
|
ClearDocRuleProcessors();
|
|
|
|
ClearOverrideRuleProcessors();
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
2000-08-12 10:28:02 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
StyleSetImpl::ClearBackstopRuleProcessors(void)
|
|
|
|
{
|
|
|
|
if (mBackstopRuleProcessors)
|
|
|
|
RecycleArray(&mBackstopRuleProcessors);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleSetImpl::ClearDocRuleProcessors(void)
|
|
|
|
{
|
|
|
|
if (mDocRuleProcessors)
|
|
|
|
RecycleArray(&mDocRuleProcessors);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleSetImpl::ClearOverrideRuleProcessors(void)
|
|
|
|
{
|
|
|
|
if (mOverrideRuleProcessors)
|
|
|
|
RecycleArray(&mOverrideRuleProcessors);
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
struct RuleProcessorData {
|
|
|
|
RuleProcessorData(nsISupportsArray* aRuleProcessors)
|
|
|
|
: mRuleProcessors(aRuleProcessors),
|
|
|
|
mPrevProcessor(nsnull)
|
|
|
|
{}
|
|
|
|
|
|
|
|
nsISupportsArray* mRuleProcessors;
|
|
|
|
nsIStyleRuleProcessor* mPrevProcessor;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
EnumRuleProcessor(nsISupports* aSheet, void* aData)
|
|
|
|
{
|
|
|
|
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheet;
|
|
|
|
RuleProcessorData* data = (RuleProcessorData*)aData;
|
|
|
|
|
|
|
|
nsIStyleRuleProcessor* processor = nsnull;
|
|
|
|
nsresult result = sheet->GetStyleRuleProcessor(processor, data->mPrevProcessor);
|
|
|
|
if (NS_SUCCEEDED(result) && processor) {
|
|
|
|
if (processor != data->mPrevProcessor) {
|
|
|
|
data->mRuleProcessors->AppendElement(processor);
|
|
|
|
data->mPrevProcessor = processor; // ref is held by array
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_RELEASE(processor);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
nsresult
|
|
|
|
StyleSetImpl::GatherRuleProcessors(void)
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_OUT_OF_MEMORY;
|
2000-08-12 10:28:02 +04:00
|
|
|
if (mBackstopSheets && !mBackstopRuleProcessors) {
|
|
|
|
if (EnsureArray(&mBackstopRuleProcessors)) {
|
|
|
|
RuleProcessorData data(mBackstopRuleProcessors);
|
1999-10-08 07:09:31 +04:00
|
|
|
mBackstopSheets->EnumerateBackwards(EnumRuleProcessor, &data);
|
2000-08-12 10:28:02 +04:00
|
|
|
PRUint32 count;
|
|
|
|
mBackstopRuleProcessors->Count(&count);
|
|
|
|
if (0 == count) {
|
|
|
|
RecycleArray(&mBackstopRuleProcessors);
|
|
|
|
}
|
|
|
|
} else return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDocSheets && !mDocRuleProcessors) {
|
|
|
|
if (EnsureArray(&mDocRuleProcessors)) {
|
|
|
|
RuleProcessorData data(mDocRuleProcessors);
|
1999-10-08 07:09:31 +04:00
|
|
|
mDocSheets->EnumerateBackwards(EnumRuleProcessor, &data);
|
2000-08-12 10:28:02 +04:00
|
|
|
PRUint32 count;
|
|
|
|
mDocRuleProcessors->Count(&count);
|
|
|
|
if (0 == count) {
|
|
|
|
RecycleArray(&mDocRuleProcessors);
|
|
|
|
}
|
|
|
|
} else return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOverrideSheets && !mOverrideRuleProcessors) {
|
|
|
|
if (EnsureArray(&mOverrideRuleProcessors)) {
|
|
|
|
RuleProcessorData data(mOverrideRuleProcessors);
|
1999-10-08 07:09:31 +04:00
|
|
|
mOverrideSheets->EnumerateBackwards(EnumRuleProcessor, &data);
|
2000-08-12 10:28:02 +04:00
|
|
|
PRUint32 count;
|
|
|
|
mOverrideRuleProcessors->Count(&count);
|
|
|
|
if (0 == count) {
|
|
|
|
RecycleArray(&mOverrideRuleProcessors);
|
|
|
|
}
|
|
|
|
} else return result;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
2000-08-12 10:28:02 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// ----- Override sheets
|
|
|
|
|
|
|
|
void StyleSetImpl::AppendOverrideStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(&mOverrideSheets)) {
|
1999-01-23 10:01:57 +03:00
|
|
|
mOverrideSheets->RemoveElement(aSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
mOverrideSheets->AppendElement(aSheet);
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearOverrideRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aAfterSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(&mOverrideSheets)) {
|
1999-01-23 10:01:57 +03:00
|
|
|
mOverrideSheets->RemoveElement(aSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 index = mOverrideSheets->IndexOf(aAfterSheet);
|
|
|
|
mOverrideSheets->InsertElementAt(aSheet, ++index);
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearOverrideRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aBeforeSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(&mOverrideSheets)) {
|
1999-01-23 10:01:57 +03:00
|
|
|
mOverrideSheets->RemoveElement(aSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 index = mOverrideSheets->IndexOf(aBeforeSheet);
|
|
|
|
mOverrideSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearOverrideRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::RemoveOverrideStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
|
|
|
if (nsnull != mOverrideSheets) {
|
|
|
|
mOverrideSheets->RemoveElement(aSheet);
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearOverrideRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 StyleSetImpl::GetNumberOfOverrideStyleSheets()
|
|
|
|
{
|
|
|
|
if (nsnull != mOverrideSheets) {
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mOverrideSheets->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return 0; // XXX error?
|
|
|
|
return cnt;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleSheet* StyleSetImpl::GetOverrideStyleSheetAt(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsIStyleSheet* sheet = nsnull;
|
1999-04-03 22:56:45 +04:00
|
|
|
if (nsnull != mOverrideSheets) {
|
1998-04-14 00:24:54 +04:00
|
|
|
sheet = (nsIStyleSheet*)mOverrideSheets->ElementAt(aIndex);
|
|
|
|
}
|
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------- Doc Sheets
|
|
|
|
|
1999-01-23 10:01:57 +03:00
|
|
|
void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-01-23 10:01:57 +03:00
|
|
|
NS_PRECONDITION((nsnull != aSheet) && (nsnull != aDocument), "null arg");
|
1998-04-14 00:24:54 +04:00
|
|
|
if (EnsureArray(&mDocSheets)) {
|
1999-01-23 10:01:57 +03:00
|
|
|
mDocSheets->RemoveElement(aSheet);
|
|
|
|
// lowest index last
|
|
|
|
PRInt32 newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet);
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 count;
|
|
|
|
nsresult rv = mDocSheets->Count(&count);
|
|
|
|
if (NS_FAILED(rv)) return; // XXX error?
|
1999-02-23 11:10:24 +03:00
|
|
|
PRUint32 index;
|
1999-01-23 10:01:57 +03:00
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIStyleSheet* sheet = (nsIStyleSheet*)mDocSheets->ElementAt(index);
|
|
|
|
PRInt32 sheetDocIndex = aDocument->GetIndexOfStyleSheet(sheet);
|
|
|
|
if (sheetDocIndex < newDocIndex) {
|
|
|
|
mDocSheets->InsertElementAt(aSheet, index);
|
|
|
|
index = count; // break loop
|
|
|
|
}
|
|
|
|
NS_RELEASE(sheet);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 cnt;
|
|
|
|
rv = mDocSheets->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return; // XXX error?
|
|
|
|
if (cnt == count) { // didn't insert it
|
1999-01-23 10:01:57 +03:00
|
|
|
mDocSheets->AppendElement(aSheet);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
if (nsnull == mFrameConstructor) {
|
|
|
|
aSheet->QueryInterface(kIStyleFrameConstructionIID, (void **)&mFrameConstructor);
|
|
|
|
}
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearDocRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::RemoveDocStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
|
|
|
if (nsnull != mDocSheets) {
|
|
|
|
mDocSheets->RemoveElement(aSheet);
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearDocRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 StyleSetImpl::GetNumberOfDocStyleSheets()
|
|
|
|
{
|
|
|
|
if (nsnull != mDocSheets) {
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mDocSheets->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return 0; // XXX error?
|
|
|
|
return cnt;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleSheet* StyleSetImpl::GetDocStyleSheetAt(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsIStyleSheet* sheet = nsnull;
|
1999-01-23 10:01:57 +03:00
|
|
|
if (nsnull != mDocSheets) {
|
1998-04-14 00:24:54 +04:00
|
|
|
sheet = (nsIStyleSheet*)mDocSheets->ElementAt(aIndex);
|
|
|
|
}
|
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------ backstop sheets
|
|
|
|
|
|
|
|
void StyleSetImpl::AppendBackstopStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(&mBackstopSheets)) {
|
1999-01-23 10:01:57 +03:00
|
|
|
mBackstopSheets->RemoveElement(aSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
mBackstopSheets->AppendElement(aSheet);
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearBackstopRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aAfterSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(&mBackstopSheets)) {
|
1999-01-23 10:01:57 +03:00
|
|
|
mBackstopSheets->RemoveElement(aSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 index = mBackstopSheets->IndexOf(aAfterSheet);
|
|
|
|
mBackstopSheets->InsertElementAt(aSheet, ++index);
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearBackstopRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aBeforeSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(&mBackstopSheets)) {
|
1999-01-23 10:01:57 +03:00
|
|
|
mBackstopSheets->RemoveElement(aSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 index = mBackstopSheets->IndexOf(aBeforeSheet);
|
|
|
|
mBackstopSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearBackstopRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::RemoveBackstopStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
|
|
|
if (nsnull != mBackstopSheets) {
|
|
|
|
mBackstopSheets->RemoveElement(aSheet);
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearBackstopRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 StyleSetImpl::GetNumberOfBackstopStyleSheets()
|
|
|
|
{
|
|
|
|
if (nsnull != mBackstopSheets) {
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mBackstopSheets->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return 0; // XXX error?
|
|
|
|
return cnt;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-03 01:45:06 +04:00
|
|
|
NS_IMETHODIMP StyleSetImpl::EnableQuirkStyleSheet(PRBool aEnable)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (nsnull == mQuirkStyleSheet) {
|
|
|
|
// first find the quirk sheet:
|
|
|
|
// - run through all of the backstop sheets and check for a CSSStyleSheet that
|
|
|
|
// has the URL we want
|
|
|
|
PRUint32 i, nSheets = GetNumberOfBackstopStyleSheets();
|
|
|
|
for (i=0; i< nSheets; i++) {
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
|
|
|
sheet = getter_AddRefs(GetBackstopStyleSheetAt(i));
|
|
|
|
if (sheet) {
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> cssSheet;
|
2001-01-04 23:44:42 +03:00
|
|
|
sheet->QueryInterface(NS_GET_IID(nsICSSStyleSheet), getter_AddRefs(cssSheet));
|
2000-06-03 01:45:06 +04:00
|
|
|
if (cssSheet) {
|
|
|
|
nsCOMPtr<nsIStyleSheet> quirkSheet;
|
|
|
|
PRBool bHasSheet = PR_FALSE;
|
2000-11-08 06:13:53 +03:00
|
|
|
NS_ASSERTION(gQuirkURI != nsnull, "StyleSetImpl::gQuirkStyleSet is not initialized!");
|
|
|
|
if (gQuirkURI != nsnull
|
|
|
|
&& NS_SUCCEEDED(cssSheet->ContainsStyleSheet(gQuirkURI, bHasSheet,
|
|
|
|
getter_AddRefs(quirkSheet)))
|
|
|
|
&& bHasSheet) {
|
2000-06-03 01:45:06 +04:00
|
|
|
NS_ASSERTION(quirkSheet, "QuirkSheet must be set: ContainsStyleSheet is hosed");
|
|
|
|
// cache the sheet for faster lookup next time
|
|
|
|
mQuirkStyleSheet = quirkSheet.get();
|
|
|
|
// addref for our cached reference
|
|
|
|
NS_ADDREF(mQuirkStyleSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mQuirkStyleSheet) {
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf( "%s Quirk StyleSheet\n", aEnable ? "Enabling" : "Disabling" );
|
|
|
|
#endif
|
2000-06-03 01:45:06 +04:00
|
|
|
mQuirkStyleSheet->SetEnabled(aEnable);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled)
|
|
|
|
{
|
|
|
|
ClearRuleProcessors();
|
|
|
|
GatherRuleProcessors();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIStyleSheet* StyleSetImpl::GetBackstopStyleSheetAt(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsIStyleSheet* sheet = nsnull;
|
1999-04-03 22:56:45 +04:00
|
|
|
if (nsnull != mBackstopSheets) {
|
1998-04-14 00:24:54 +04:00
|
|
|
sheet = (nsIStyleSheet*)mBackstopSheets->ElementAt(aIndex);
|
|
|
|
}
|
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
2000-05-28 00:03:14 +04:00
|
|
|
void
|
|
|
|
StyleSetImpl::ReplaceBackstopStyleSheets(nsISupportsArray* aNewBackstopSheets)
|
|
|
|
{
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearBackstopRuleProcessors();
|
2000-05-28 00:03:14 +04:00
|
|
|
NS_IF_RELEASE(mBackstopSheets);
|
|
|
|
mBackstopSheets = aNewBackstopSheets;
|
|
|
|
NS_IF_ADDREF(mBackstopSheets);
|
|
|
|
}
|
2000-06-22 00:44:59 +04:00
|
|
|
|
1999-06-15 10:15:51 +04:00
|
|
|
struct RulesMatchingData {
|
|
|
|
RulesMatchingData(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aParentContext,
|
|
|
|
nsISupportsArray* aResults)
|
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mMedium(aMedium),
|
|
|
|
mContent(aContent),
|
|
|
|
mParentContext(aParentContext),
|
1999-10-08 07:09:31 +04:00
|
|
|
mResults(aResults)
|
1999-06-15 10:15:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
nsIPresContext* mPresContext;
|
|
|
|
nsIAtom* mMedium;
|
|
|
|
nsIContent* mContent;
|
|
|
|
nsIStyleContext* mParentContext;
|
|
|
|
nsISupportsArray* mResults;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool
|
1999-10-08 07:09:31 +04:00
|
|
|
EnumRulesMatching(nsISupports* aProcessor, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-08 07:09:31 +04:00
|
|
|
nsIStyleRuleProcessor* processor = (nsIStyleRuleProcessor*)aProcessor;
|
1999-06-15 10:15:51 +04:00
|
|
|
RulesMatchingData* data = (RulesMatchingData*)aData;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
processor->RulesMatching(data->mPresContext, data->mMedium, data->mContent,
|
|
|
|
data->mParentContext, data->mResults);
|
1999-06-15 10:15:51 +04:00
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef SHARE_STYLECONTEXTS
|
2000-06-22 09:14:32 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
static int gNewCount=0;
|
|
|
|
static int gSharedCount=0;
|
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
1999-06-15 10:15:51 +04:00
|
|
|
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* StyleSetImpl::GetContext(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleContext* aParentContext, nsIAtom* aPseudoTag,
|
|
|
|
nsISupportsArray* aRules,
|
|
|
|
PRBool aForceUnique, PRBool& aUsedRules)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
aUsedRules = PR_FALSE;
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-09-21 11:50:16 +04:00
|
|
|
if ((PR_FALSE == aForceUnique) && (nsnull != aParentContext)) {
|
|
|
|
aParentContext->FindChildWithRules(aPseudoTag, aRules, result);
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1998-11-03 23:19:28 +03:00
|
|
|
if (nsnull == result) {
|
2000-06-22 00:44:59 +04:00
|
|
|
if (NS_SUCCEEDED(NS_NewStyleContext(&result, aParentContext, aPseudoTag, aRules, aPresContext))) {
|
1999-09-21 11:50:16 +04:00
|
|
|
if (PR_TRUE == aForceUnique) {
|
|
|
|
result->ForceUnique();
|
1998-06-05 10:00:55 +04:00
|
|
|
}
|
1999-09-21 11:50:16 +04:00
|
|
|
aUsedRules = PRBool(nsnull != aRules);
|
1998-05-27 03:14:56 +04:00
|
|
|
}
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "+++ NewSC %d +++\n", ++gNewCount);
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
1999-09-21 11:50:16 +04:00
|
|
|
}
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
1999-09-21 11:50:16 +04:00
|
|
|
else {
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "--- SharedSC %d ---\n", ++gSharedCount);
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
|
|
|
|
1998-05-19 01:05:52 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-09-11 06:05:30 +04:00
|
|
|
// XXX for now only works for strength 0 & 1
|
1999-10-08 07:09:31 +04:00
|
|
|
static void SortRulesByStrength(nsISupportsArray* aRules)
|
1998-09-11 06:05:30 +04:00
|
|
|
{
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = aRules->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return; // XXX error?
|
|
|
|
PRInt32 count = (PRInt32)cnt;
|
1998-09-11 06:05:30 +04:00
|
|
|
|
|
|
|
if (1 < count) {
|
|
|
|
PRInt32 index;
|
|
|
|
PRInt32 strength;
|
|
|
|
for (index = 0; index < count; ) {
|
|
|
|
nsIStyleRule* rule = (nsIStyleRule*)aRules->ElementAt(index);
|
|
|
|
rule->GetStrength(strength);
|
|
|
|
if (0 < strength) {
|
|
|
|
aRules->RemoveElementAt(index);
|
|
|
|
aRules->AppendElement(rule);
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
NS_RELEASE(rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-03 23:19:28 +03:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) { \
|
|
|
|
nsrefcnt count = ptr->AddRef(); \
|
|
|
|
ptr->Release(); \
|
|
|
|
NS_ASSERTION(--count == cnt, msg); \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) {}
|
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-06-05 10:00:55 +04:00
|
|
|
PRBool aForceUnique)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-11-10 06:41:09 +03:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ResolveStyleFor(), this=%p\n", this));
|
2000-02-11 04:21:36 +03:00
|
|
|
STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
1999-06-22 23:16:40 +04:00
|
|
|
NS_ASSERTION(aContent, "must have content");
|
|
|
|
NS_ASSERTION(aPresContext, "must have pres context");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-06-22 23:16:40 +04:00
|
|
|
if (aContent && aPresContext) {
|
2000-08-12 10:28:02 +04:00
|
|
|
GatherRuleProcessors();
|
|
|
|
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) {
|
1999-10-08 07:09:31 +04:00
|
|
|
nsISupportsArray* rules = nsnull;
|
|
|
|
if (EnsureArray(&rules)) {
|
|
|
|
nsIAtom* medium = nsnull;
|
|
|
|
aPresContext->GetMedium(&medium);
|
|
|
|
RulesMatchingData data(aPresContext, medium, aContent, aParentContext, rules);
|
2000-08-12 10:28:02 +04:00
|
|
|
WalkRuleProcessors(EnumRulesMatching, &data, aContent);
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
PRBool usedRules = PR_FALSE;
|
|
|
|
PRUint32 ruleCount = 0;
|
|
|
|
rules->Count(&ruleCount);
|
|
|
|
if (0 < ruleCount) {
|
|
|
|
SortRulesByStrength(rules);
|
|
|
|
result = GetContext(aPresContext, aParentContext, nsnull, rules, aForceUnique, usedRules);
|
|
|
|
if (usedRules) {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 2, "rules array was used elsewhere");
|
|
|
|
NS_RELEASE(rules);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 1, "rules array was used elsewhere");
|
|
|
|
RecycleArray(&rules);
|
|
|
|
}
|
1998-11-03 23:19:28 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 1, "rules array was used elsewhere");
|
1999-10-08 07:09:31 +04:00
|
|
|
RecycleArray(&rules);
|
|
|
|
result = GetContext(aPresContext, aParentContext, nsnull, nsnull, aForceUnique, usedRules);
|
1998-10-13 23:09:39 +04:00
|
|
|
}
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_RELEASE(medium);
|
1998-10-13 23:09:39 +04:00
|
|
|
}
|
1998-07-17 09:43:31 +04:00
|
|
|
}
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
|
|
|
|
1999-11-10 06:41:09 +03:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ResolveStyleFor(), this=%p\n", this));
|
2000-02-11 04:21:36 +03:00
|
|
|
STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION);
|
1998-05-19 01:05:52 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-06-15 10:15:51 +04:00
|
|
|
struct PseudoRulesMatchingData {
|
|
|
|
PseudoRulesMatchingData(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsIStyleContext* aParentContext,
|
2001-02-16 00:24:47 +03:00
|
|
|
nsICSSPseudoComparator* aComparator,
|
1999-06-15 10:15:51 +04:00
|
|
|
nsISupportsArray* aResults)
|
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mMedium(aMedium),
|
|
|
|
mParentContent(aParentContent),
|
|
|
|
mPseudoTag(aPseudoTag),
|
|
|
|
mParentContext(aParentContext),
|
2001-02-16 00:24:47 +03:00
|
|
|
mComparator(aComparator),
|
1999-10-08 07:09:31 +04:00
|
|
|
mResults(aResults)
|
1999-06-15 10:15:51 +04:00
|
|
|
{
|
|
|
|
}
|
2001-02-16 00:24:47 +03:00
|
|
|
nsIPresContext* mPresContext;
|
|
|
|
nsIAtom* mMedium;
|
|
|
|
nsIContent* mParentContent;
|
|
|
|
nsIAtom* mPseudoTag;
|
|
|
|
nsIStyleContext* mParentContext;
|
|
|
|
nsICSSPseudoComparator* mComparator;
|
|
|
|
nsISupportsArray* mResults;
|
1999-06-15 10:15:51 +04:00
|
|
|
};
|
1998-05-19 01:05:52 +04:00
|
|
|
|
1999-06-15 10:15:51 +04:00
|
|
|
static PRBool
|
1999-10-08 07:09:31 +04:00
|
|
|
EnumPseudoRulesMatching(nsISupports* aProcessor, void* aData)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
1999-10-08 07:09:31 +04:00
|
|
|
nsIStyleRuleProcessor* processor = (nsIStyleRuleProcessor*)aProcessor;
|
1999-06-15 10:15:51 +04:00
|
|
|
PseudoRulesMatchingData* data = (PseudoRulesMatchingData*)aData;
|
1998-05-19 01:05:52 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
processor->RulesMatching(data->mPresContext, data->mMedium,
|
|
|
|
data->mParentContent, data->mPseudoTag,
|
2001-02-16 00:24:47 +03:00
|
|
|
data->mParentContext, data->mComparator, data->mResults);
|
1999-06-15 10:15:51 +04:00
|
|
|
return PR_TRUE;
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleContext* StyleSetImpl::ResolvePseudoStyleFor(nsIPresContext* aPresContext,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIContent* aParentContent,
|
1998-05-19 01:05:52 +04:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
2001-02-16 00:24:47 +03:00
|
|
|
PRBool aForceUnique,
|
|
|
|
nsICSSPseudoComparator* aComparator)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
1999-11-10 06:41:09 +03:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ResolvePseudoStyleFor(), this=%p\n", this));
|
2000-02-11 04:21:36 +03:00
|
|
|
STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION);
|
|
|
|
|
1998-05-19 01:05:52 +04:00
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
1999-06-22 23:16:40 +04:00
|
|
|
NS_ASSERTION(aPseudoTag, "must have pseudo tag");
|
|
|
|
NS_ASSERTION(aPresContext, "must have pres context");
|
1998-05-19 01:05:52 +04:00
|
|
|
|
1999-06-22 23:16:40 +04:00
|
|
|
if (aPseudoTag && aPresContext) {
|
2000-08-12 10:28:02 +04:00
|
|
|
GatherRuleProcessors();
|
|
|
|
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) {
|
1999-10-08 07:09:31 +04:00
|
|
|
nsISupportsArray* rules = nsnull;
|
|
|
|
if (EnsureArray(&rules)) {
|
|
|
|
nsIAtom* medium = nsnull;
|
|
|
|
aPresContext->GetMedium(&medium);
|
|
|
|
PseudoRulesMatchingData data(aPresContext, medium, aParentContent,
|
2001-02-16 00:24:47 +03:00
|
|
|
aPseudoTag, aParentContext, aComparator, rules);
|
2000-08-12 10:28:02 +04:00
|
|
|
WalkRuleProcessors(EnumPseudoRulesMatching, &data, aParentContent);
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
PRBool usedRules = PR_FALSE;
|
|
|
|
PRUint32 ruleCount = 0;
|
|
|
|
rules->Count(&ruleCount);
|
|
|
|
if (0 < ruleCount) {
|
|
|
|
SortRulesByStrength(rules);
|
|
|
|
result = GetContext(aPresContext, aParentContext, aPseudoTag, rules, aForceUnique, usedRules);
|
|
|
|
if (usedRules) {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 2, "rules array was used elsewhere");
|
|
|
|
NS_RELEASE(rules);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 1, "rules array was used elsewhere");
|
|
|
|
rules->Clear();
|
|
|
|
RecycleArray(&rules);
|
|
|
|
}
|
1999-06-22 23:16:40 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 1, "rules array was used elsewhere");
|
1999-10-08 07:09:31 +04:00
|
|
|
RecycleArray(&rules);
|
|
|
|
result = GetContext(aPresContext, aParentContext, aPseudoTag, nsnull, aForceUnique, usedRules);
|
1999-06-22 23:16:40 +04:00
|
|
|
}
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IF_RELEASE(medium);
|
1998-11-03 23:19:28 +03:00
|
|
|
}
|
1998-10-13 23:09:39 +04:00
|
|
|
}
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
|
|
|
|
1999-11-10 06:41:09 +03:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ResolvePseudoStyleFor(), this=%p\n", this));
|
2000-02-11 04:21:36 +03:00
|
|
|
STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION);
|
1998-05-19 01:05:52 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleContext* StyleSetImpl::ProbePseudoStyleFor(nsIPresContext* aPresContext,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIContent* aParentContent,
|
1998-05-19 01:05:52 +04:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-06-05 10:00:55 +04:00
|
|
|
PRBool aForceUnique)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
1999-11-10 06:41:09 +03:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ProbePseudoStyleFor(), this=%p\n", this));
|
2000-02-11 04:21:36 +03:00
|
|
|
STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION);
|
|
|
|
|
1998-05-19 01:05:52 +04:00
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
1999-06-22 23:16:40 +04:00
|
|
|
NS_ASSERTION(aPseudoTag, "must have pseudo tag");
|
|
|
|
NS_ASSERTION(aPresContext, "must have pres context");
|
1998-05-19 01:05:52 +04:00
|
|
|
|
1999-06-22 23:16:40 +04:00
|
|
|
if (aPseudoTag && aPresContext) {
|
2000-08-12 10:28:02 +04:00
|
|
|
GatherRuleProcessors();
|
|
|
|
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) {
|
1999-10-08 07:09:31 +04:00
|
|
|
nsISupportsArray* rules = nsnull;
|
|
|
|
if (EnsureArray(&rules)) {
|
|
|
|
nsIAtom* medium = nsnull;
|
|
|
|
aPresContext->GetMedium(&medium);
|
|
|
|
PseudoRulesMatchingData data(aPresContext, medium, aParentContent,
|
2001-02-16 00:24:47 +03:00
|
|
|
aPseudoTag, aParentContext, nsnull, rules);
|
2000-08-12 10:28:02 +04:00
|
|
|
WalkRuleProcessors(EnumPseudoRulesMatching, &data, aParentContent);
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
PRBool usedRules = PR_FALSE;
|
|
|
|
PRUint32 ruleCount;
|
|
|
|
rules->Count(&ruleCount);
|
|
|
|
if (0 < ruleCount) {
|
|
|
|
SortRulesByStrength(rules);
|
|
|
|
result = GetContext(aPresContext, aParentContext, aPseudoTag, rules, aForceUnique, usedRules);
|
|
|
|
if (usedRules) {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 2, "rules array was used elsewhere");
|
|
|
|
NS_RELEASE(rules);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 1, "rules array was used elsewhere");
|
|
|
|
rules->Clear();
|
|
|
|
RecycleArray(&rules);
|
|
|
|
}
|
1999-06-22 23:16:40 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERT_REFCOUNT(rules, 1, "rules array was used elsewhere");
|
1999-10-08 07:09:31 +04:00
|
|
|
RecycleArray(&rules);
|
1999-06-22 23:16:40 +04:00
|
|
|
}
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IF_RELEASE(medium);
|
1998-11-03 23:19:28 +03:00
|
|
|
}
|
1998-10-13 23:09:39 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-10-12 03:42:56 +04:00
|
|
|
|
1999-11-10 06:41:09 +03:00
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ProbePseudoStyleFor(), this=%p\n", this));
|
2000-02-11 04:21:36 +03:00
|
|
|
STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION);
|
1998-04-14 00:24:54 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-09-04 03:35:41 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::ReParentStyleContext(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIStyleContext* aNewParentContext,
|
|
|
|
nsIStyleContext** aNewStyleContext)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aPresContext, "must have pres context");
|
2000-03-31 11:08:36 +04:00
|
|
|
NS_ASSERTION(aStyleContext, "must have style context");
|
|
|
|
NS_ASSERTION(aNewStyleContext, "must have new style context");
|
1999-09-04 03:35:41 +04:00
|
|
|
|
|
|
|
nsresult result = NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (aPresContext && aStyleContext && aNewStyleContext) {
|
|
|
|
nsIStyleContext* oldParent = aStyleContext->GetParent();
|
|
|
|
|
|
|
|
if (oldParent == aNewParentContext) {
|
|
|
|
result = NS_OK;
|
|
|
|
NS_ADDREF(aStyleContext); // for return
|
|
|
|
*aNewStyleContext = aStyleContext;
|
|
|
|
}
|
|
|
|
else { // really a new parent
|
|
|
|
nsIStyleContext* newChild = nsnull;
|
|
|
|
nsIAtom* pseudoTag = nsnull;
|
|
|
|
aStyleContext->GetPseudoType(pseudoTag);
|
|
|
|
nsISupportsArray* rules = aStyleContext->GetStyleRules();
|
|
|
|
if (aNewParentContext) {
|
|
|
|
result = aNewParentContext->FindChildWithRules(pseudoTag, rules, newChild);
|
|
|
|
}
|
|
|
|
if (newChild) { // new parent already has one
|
|
|
|
*aNewStyleContext = newChild;
|
|
|
|
}
|
|
|
|
else { // need to make one in the new parent
|
|
|
|
nsISupportsArray* newRules = nsnull;
|
|
|
|
if (rules) {
|
1999-10-08 07:09:31 +04:00
|
|
|
if (EnsureArray(&newRules)) {
|
1999-09-04 03:35:41 +04:00
|
|
|
newRules->AppendElements(rules);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = NS_NewStyleContext(aNewStyleContext, aNewParentContext, pseudoTag,
|
|
|
|
newRules, aPresContext);
|
|
|
|
NS_IF_RELEASE(newRules);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(rules);
|
|
|
|
NS_IF_RELEASE(pseudoTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(oldParent);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:02:22 +04:00
|
|
|
struct StatefulData {
|
1999-10-08 07:09:31 +04:00
|
|
|
StatefulData(nsIPresContext* aPresContext, nsIAtom* aMedium, nsIContent* aContent)
|
1999-04-20 04:02:22 +04:00
|
|
|
: mPresContext(aPresContext),
|
1999-10-08 07:09:31 +04:00
|
|
|
mMedium(aMedium),
|
1999-04-20 04:02:22 +04:00
|
|
|
mContent(aContent),
|
|
|
|
mStateful(PR_FALSE)
|
|
|
|
{}
|
|
|
|
nsIPresContext* mPresContext;
|
1999-10-08 07:09:31 +04:00
|
|
|
nsIAtom* mMedium;
|
1999-04-20 04:02:22 +04:00
|
|
|
nsIContent* mContent;
|
|
|
|
PRBool mStateful;
|
|
|
|
};
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
static PRBool SheetHasStatefulStyle(nsISupports* aProcessor, void *aData)
|
1999-04-20 04:02:22 +04:00
|
|
|
{
|
1999-10-08 07:09:31 +04:00
|
|
|
nsIStyleRuleProcessor* processor = (nsIStyleRuleProcessor*)aProcessor;
|
1999-04-20 04:02:22 +04:00
|
|
|
StatefulData* data = (StatefulData*)aData;
|
1999-10-08 07:09:31 +04:00
|
|
|
if (NS_OK == processor->HasStateDependentStyle(data->mPresContext, data->mMedium,
|
|
|
|
data->mContent)) {
|
1999-04-20 04:02:22 +04:00
|
|
|
data->mStateful = PR_TRUE;
|
|
|
|
return PR_FALSE; // stop iteration
|
|
|
|
}
|
|
|
|
return PR_TRUE; // continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::HasStateDependentStyle(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
2000-08-12 10:28:02 +04:00
|
|
|
GatherRuleProcessors();
|
|
|
|
if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) {
|
1999-10-08 07:09:31 +04:00
|
|
|
nsIAtom* medium = nsnull;
|
|
|
|
aPresContext->GetMedium(&medium);
|
|
|
|
StatefulData data(aPresContext, medium, aContent);
|
2000-08-12 10:28:02 +04:00
|
|
|
WalkRuleProcessors(SheetHasStatefulStyle, &data, aContent);
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IF_RELEASE(medium);
|
|
|
|
return ((data.mStateful) ? NS_OK : NS_COMFALSE);
|
|
|
|
}
|
|
|
|
return NS_COMFALSE;
|
1999-04-20 04:02:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
NS_IMETHODIMP StyleSetImpl::ConstructRootFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aDocElement,
|
|
|
|
nsIFrame*& aFrameSubTree)
|
1998-09-10 23:32:14 +04:00
|
|
|
{
|
1999-12-05 02:49:50 +03:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
return mFrameConstructor->ConstructRootFrame(shell, aPresContext, aDocElement,
|
1998-12-29 06:38:16 +03:00
|
|
|
aFrameSubTree);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
NS_IMETHODIMP
|
1999-03-01 19:57:35 +03:00
|
|
|
StyleSetImpl::ReconstructDocElementHierarchy(nsIPresContext* aPresContext)
|
1998-11-17 05:14:38 +03:00
|
|
|
{
|
1999-03-01 19:57:35 +03:00
|
|
|
return mFrameConstructor->ReconstructDocElementHierarchy(aPresContext);
|
1998-11-17 05:14:38 +03:00
|
|
|
}
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IMETHODIMP StyleSetImpl::ContentAppended(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
|
|
|
{
|
1998-09-30 03:47:03 +04:00
|
|
|
return mFrameConstructor->ContentAppended(aPresContext,
|
1998-09-10 23:32:14 +04:00
|
|
|
aContainer, aNewIndexInContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP StyleSetImpl::ContentInserted(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
1998-09-30 03:47:03 +04:00
|
|
|
return mFrameConstructor->ContentInserted(aPresContext, aContainer,
|
1999-12-06 10:44:18 +03:00
|
|
|
aChild, aIndexInContainer, nsnull);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP StyleSetImpl::ContentReplaced(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
1998-09-30 03:47:03 +04:00
|
|
|
return mFrameConstructor->ContentReplaced(aPresContext, aContainer,
|
1998-09-10 23:32:14 +04:00
|
|
|
aOldChild, aNewChild, aIndexInContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP StyleSetImpl::ContentRemoved(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
1998-09-30 03:47:03 +04:00
|
|
|
return mFrameConstructor->ContentRemoved(aPresContext, aContainer,
|
1998-09-10 23:32:14 +04:00
|
|
|
aChild, aIndexInContainer);
|
|
|
|
}
|
|
|
|
|
1998-09-30 03:47:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::ContentChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
|
|
|
return mFrameConstructor->ContentChanged(aPresContext,
|
|
|
|
aContent, aSubContent);
|
|
|
|
}
|
|
|
|
|
1999-02-27 10:11:04 +03:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:02:22 +04:00
|
|
|
StyleSetImpl::ContentStatesChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2)
|
1999-02-27 10:11:04 +03:00
|
|
|
{
|
1999-04-20 04:02:22 +04:00
|
|
|
return mFrameConstructor->ContentStatesChanged(aPresContext, aContent1, aContent2);
|
1999-02-27 10:11:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-30 03:47:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
1999-10-16 03:16:45 +04:00
|
|
|
PRInt32 aNameSpaceID,
|
1998-09-30 03:47:03 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
return mFrameConstructor->AttributeChanged(aPresContext, aContent,
|
1999-10-16 03:16:45 +04:00
|
|
|
aNameSpaceID, aAttribute, aHint);
|
1998-09-30 03:47:03 +04:00
|
|
|
}
|
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// Style change notifications
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
return mFrameConstructor->StyleRuleChanged(aPresContext, aStyleSheet, aStyleRule, aHint);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::StyleRuleAdded(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
return mFrameConstructor->StyleRuleAdded(aPresContext, aStyleSheet, aStyleRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::StyleRuleRemoved(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
return mFrameConstructor->StyleRuleRemoved(aPresContext, aStyleSheet, aStyleRule);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-02-04 20:03:46 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::CantRenderReplacedElement(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
1999-12-05 02:49:50 +03:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
return mFrameConstructor->CantRenderReplacedElement(shell, aPresContext, aFrame);
|
1999-02-04 20:03:46 +03:00
|
|
|
}
|
|
|
|
|
1999-02-24 07:03:50 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::CreateContinuingFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame** aContinuingFrame)
|
|
|
|
{
|
1999-12-05 02:49:50 +03:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
return mFrameConstructor->CreateContinuingFrame(shell, aPresContext, aFrame, aParentFrame,
|
1999-02-24 07:03:50 +03:00
|
|
|
aContinuingFrame);
|
|
|
|
}
|
|
|
|
|
1999-07-02 08:46:19 +04:00
|
|
|
// Request to find the primary frame associated with a given content object.
|
|
|
|
// This is typically called by the pres shell when there is no mapping in
|
|
|
|
// the pres shell hash table
|
|
|
|
NS_IMETHODIMP
|
1999-08-05 07:09:22 +04:00
|
|
|
StyleSetImpl::FindPrimaryFrameFor(nsIPresContext* aPresContext,
|
|
|
|
nsIFrameManager* aFrameManager,
|
|
|
|
nsIContent* aContent,
|
2001-01-17 01:10:04 +03:00
|
|
|
nsIFrame** aFrame,
|
|
|
|
nsFindFrameHint* aHint)
|
1999-07-02 08:46:19 +04:00
|
|
|
{
|
1999-08-05 07:09:22 +04:00
|
|
|
return mFrameConstructor->FindPrimaryFrameFor(aPresContext, aFrameManager,
|
2001-01-17 01:10:04 +03:00
|
|
|
aContent, aFrame, aHint);
|
1999-07-02 08:46:19 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets)
|
|
|
|
{
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 cnt = 0;
|
|
|
|
if (aSheets) {
|
|
|
|
nsresult rv = aSheets->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return; // XXX error?
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-05-13 08:56:04 +04:00
|
|
|
for (PRInt32 index = 0; index < (PRInt32)cnt; index++) {
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
|
|
|
sheet->List(out, aIndent);
|
|
|
|
fputs("\n", out);
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-12 10:28:02 +04:00
|
|
|
// APIs for registering objects that can supply additional
|
|
|
|
// rules during processing.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::SetStyleRuleSupplier(nsIStyleRuleSupplier* aSupplier)
|
|
|
|
{
|
|
|
|
mStyleRuleSupplier = aSupplier;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::GetStyleRuleSupplier(nsIStyleRuleSupplier** aSupplier)
|
|
|
|
{
|
|
|
|
*aSupplier = mStyleRuleSupplier;
|
|
|
|
NS_IF_ADDREF(*aSupplier);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
void StyleSetImpl::List(FILE* out, PRInt32 aIndent)
|
|
|
|
{
|
1999-02-27 10:11:04 +03:00
|
|
|
// List(out, aIndent, mOverrideSheets);
|
1998-04-14 00:24:54 +04:00
|
|
|
List(out, aIndent, mDocSheets);
|
1999-02-27 10:11:04 +03:00
|
|
|
// List(out, aIndent, mBackstopSheets);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-09-20 10:53:40 +04:00
|
|
|
|
1998-06-26 09:49:01 +04:00
|
|
|
void StyleSetImpl::ListContexts(nsIStyleContext* aRootContext, FILE* out, PRInt32 aIndent)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
1998-06-26 09:49:01 +04:00
|
|
|
aRootContext->List(out, aIndent);
|
1998-05-19 01:05:52 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
NS_LAYOUT nsresult
|
|
|
|
NS_NewStyleSet(nsIStyleSet** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
if (aInstancePtrResult == nsnull) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleSetImpl *it = new StyleSetImpl();
|
|
|
|
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:42 +03:00
|
|
|
return it->QueryInterface(NS_GET_IID(nsIStyleSet), (void **) aInstancePtrResult);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-09-20 10:53:40 +04:00
|
|
|
|
|
|
|
// nsITimeRecorder implementation
|
|
|
|
|
1999-10-20 02:27:20 +04:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
2000-02-11 04:21:36 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::EnableTimer(PRUint32 aTimerID)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_TIMER_STYLE_RESOLUTION == aTimerID) {
|
|
|
|
mTimerEnabled = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::DisableTimer(PRUint32 aTimerID)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_TIMER_STYLE_RESOLUTION == aTimerID) {
|
|
|
|
mTimerEnabled = PR_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::IsTimerEnabled(PRBool *aIsEnabled, PRUint32 aTimerID)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aIsEnabled != nsnull, "aIsEnabled paramter cannot be null" );
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_TIMER_STYLE_RESOLUTION == aTimerID) {
|
|
|
|
if (*aIsEnabled != nsnull) {
|
|
|
|
*aIsEnabled = mTimerEnabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-20 10:53:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::ResetTimer(PRUint32 aTimerID)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_TIMER_STYLE_RESOLUTION == aTimerID) {
|
1999-11-10 06:41:09 +03:00
|
|
|
MOZ_TIMER_RESET(mStyleResolutionWatch);
|
1999-09-20 10:53:40 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::StartTimer(PRUint32 aTimerID)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_TIMER_STYLE_RESOLUTION == aTimerID) {
|
2000-02-11 04:21:36 +03:00
|
|
|
// only do it if enabled
|
|
|
|
if (mTimerEnabled) {
|
|
|
|
MOZ_TIMER_START(mStyleResolutionWatch);
|
|
|
|
} else {
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
printf( "Attempt to start timer while disabled - ignoring\n" );
|
|
|
|
#endif
|
2000-02-11 04:21:36 +03:00
|
|
|
}
|
1999-09-20 10:53:40 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::StopTimer(PRUint32 aTimerID)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_TIMER_STYLE_RESOLUTION == aTimerID) {
|
2000-02-11 04:21:36 +03:00
|
|
|
// only do it if enabled
|
|
|
|
if (mTimerEnabled) {
|
|
|
|
MOZ_TIMER_STOP(mStyleResolutionWatch);
|
|
|
|
} else {
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
printf( "Attempt to stop timer while disabled - ignoring\n" );
|
|
|
|
#endif
|
2000-02-11 04:21:36 +03:00
|
|
|
}
|
1999-09-20 10:53:40 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::PrintTimer(PRUint32 aTimerID)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_TIMER_STYLE_RESOLUTION == aTimerID) {
|
1999-11-10 06:41:09 +03:00
|
|
|
MOZ_TIMER_PRINT(mStyleResolutionWatch);
|
1999-09-20 10:53:40 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-21 01:36:53 +04:00
|
|
|
#endif
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef SHARE_STYLECONTEXTS
|
|
|
|
#ifdef USE_FAST_CACHE
|
|
|
|
// StyleContextCache is a hash table based data structure that maintains
|
|
|
|
// a list of entries on each hashkey. Thus, multiple items with the same
|
|
|
|
// ID (key) can be stored in the hash table. The hash-lookup gets the list of
|
|
|
|
// items having that ID (key). The list is unsorted and vector-based so it is
|
|
|
|
// best if kept short.
|
|
|
|
//
|
|
|
|
// This choice of data structures was based upon knowledge that there are not
|
|
|
|
// many items sharing the same ID, and that there are many unique IDs, so
|
|
|
|
// this is a comprimise between a sorted-list based lookup and a hash-type
|
|
|
|
// lookup which is not possible due to non-guaranteed-unique keys.
|
2000-06-24 01:57:39 +04:00
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(StyleContextCache)
|
2000-06-24 01:57:39 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
StyleContextCache::StyleContextCache(void)
|
2001-01-03 02:13:49 +03:00
|
|
|
:mHashTable(nsnull, nsnull, HashTableEnumDestroy, nsnull),
|
|
|
|
mCount(0)
|
2000-06-24 01:57:39 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(StyleContextCache);
|
|
|
|
}
|
2000-06-22 00:44:59 +04:00
|
|
|
|
2001-01-03 02:13:49 +03:00
|
|
|
StyleContextCache::~StyleContextCache(void)
|
2000-06-24 01:57:39 +04:00
|
|
|
{
|
2001-01-03 02:13:49 +03:00
|
|
|
// mHashTable memeber is reset automatically in nsObjectHashTable's dtor
|
|
|
|
|
2000-06-24 01:57:39 +04:00
|
|
|
MOZ_COUNT_DTOR(StyleContextCache);
|
|
|
|
}
|
2000-06-22 00:44:59 +04:00
|
|
|
|
|
|
|
PRUint32 StyleContextCache::Count(void)
|
|
|
|
{
|
2000-12-22 02:34:44 +03:00
|
|
|
#ifdef ENABLE_FAST_CACHE_TICKLE
|
|
|
|
// Tickle will test the integrity of the elements in the chace...
|
|
|
|
// - use if it is in question (has already been tested so it is now being commented-out)
|
2000-06-22 00:44:59 +04:00
|
|
|
Tickle("From Count()");
|
|
|
|
#endif
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
printf("StyleContextCache count: %ld\n", (long)mCount);
|
|
|
|
#endif
|
2000-06-22 00:44:59 +04:00
|
|
|
|
|
|
|
return mCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult StyleContextCache::AddContext(scKey aKey, nsIStyleContext *aContext)
|
|
|
|
{
|
|
|
|
// verify we have a list
|
|
|
|
nsresult rv = VerifyList(aKey);
|
|
|
|
if (NS_SUCCEEDED(rv)){
|
|
|
|
nsVoidArray *pList = GetList(aKey);
|
|
|
|
NS_ASSERTION(pList != nsnull, "VerifyList failed me!");
|
|
|
|
NS_ASSERTION(pList->IndexOf(aContext) == -1, "Context already in list");
|
2001-03-28 23:58:51 +04:00
|
|
|
if (!(pList->AppendElement(aContext))) {
|
2000-06-22 00:44:59 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2001-03-28 23:58:51 +04:00
|
|
|
} else {
|
|
|
|
mCount++;
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
2001-03-28 23:58:51 +04:00
|
|
|
DumpStats();
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult StyleContextCache::RemoveContext(scKey aKey, nsIStyleContext *aContext)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
nsVoidArray *pResults = nsnull;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(GetContexts(aKey,&pResults)) && pResults) {
|
|
|
|
PRUint32 nCountBefore = Count();
|
2000-12-22 02:34:44 +03:00
|
|
|
if (nCountBefore > 0){
|
|
|
|
if(pResults->RemoveElement(aContext)) {
|
|
|
|
mCount--;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(PR_FALSE,"Failure to remove context at provided key!");
|
|
|
|
}
|
|
|
|
#endif
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
DumpStats();
|
|
|
|
|
|
|
|
static PRBool bRemoveEmptyLists = PR_FALSE;
|
|
|
|
// if no more entries left, remove the list and all...
|
|
|
|
if (bRemoveEmptyLists && pResults->Count() == 0) {
|
|
|
|
rv = RemoveAllContexts(aKey);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NS_ASSERTION(GetList(aKey) == nsnull, "Failed to delete list in StyleContextCache::RemoveContext");
|
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef DEBUG
|
2000-06-22 00:44:59 +04:00
|
|
|
else {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf( "Error removing all contexts in StyleContextCache::RemoveContext\n");
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
2000-12-22 02:34:44 +03:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(PR_FALSE, "Failure to find any contexts at provided key!");
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
2000-12-22 02:34:44 +03:00
|
|
|
#endif
|
2000-06-22 00:44:59 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult StyleContextCache::RemoveAllContexts(scKey aKey)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-12-22 02:34:44 +03:00
|
|
|
nsVoidKey key((void *)aKey);
|
2000-06-22 00:44:59 +04:00
|
|
|
nsVoidArray *pResults = (nsVoidArray *)mHashTable.Remove(&key);
|
|
|
|
if (pResults) {
|
|
|
|
delete pResults;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult StyleContextCache::GetContexts(scKey aKey, nsVoidArray **aResults)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
*aResults = GetList(aKey);
|
|
|
|
if (nsnull==aResults) rv = NS_ERROR_FAILURE;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure there is a list for the specified key
|
|
|
|
nsresult StyleContextCache::VerifyList(scKey aKey)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-12-22 02:34:44 +03:00
|
|
|
nsVoidKey key((void *)aKey);
|
2000-06-22 00:44:59 +04:00
|
|
|
if (GetList(aKey) == nsnull) {
|
2001-01-03 02:13:49 +03:00
|
|
|
nsVoidArray *pList = AllocateList();
|
2000-06-22 00:44:59 +04:00
|
|
|
if (pList) {
|
|
|
|
mHashTable.Put(&key,pList);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-01-03 02:13:49 +03:00
|
|
|
nsVoidArray *StyleContextCache::AllocateList(void)
|
|
|
|
{
|
|
|
|
// we allocate it using 'new'
|
|
|
|
return new nsVoidArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult StyleContextCache::DestroyList(nsVoidArray* aList)
|
|
|
|
{
|
|
|
|
if(aList) {
|
|
|
|
// we free it using 'delete'
|
|
|
|
delete aList;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
// returns the list for the key, may be null
|
|
|
|
nsVoidArray *StyleContextCache::GetList(scKey aKey)
|
|
|
|
{
|
2000-12-22 02:34:44 +03:00
|
|
|
nsVoidKey key((void *)aKey);
|
2000-06-22 00:44:59 +04:00
|
|
|
return (nsVoidArray *)mHashTable.Get(&key);
|
|
|
|
}
|
|
|
|
|
2001-01-03 02:13:49 +03:00
|
|
|
|
|
|
|
// called to destroy each list in the hash table:
|
|
|
|
// - must free the list passed in as aData
|
|
|
|
PRBool PR_CALLBACK HashTableEnumDestroy(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
|
|
|
if(aData) {
|
|
|
|
StyleContextCache::DestroyList((nsVoidArray*)aData);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool PR_CALLBACK HashTableEnumDump(nsHashKey *aKey, void *aData, void* closure)
|
2000-06-22 00:44:59 +04:00
|
|
|
{
|
|
|
|
static PRUint32 nTotal, nCount, nMax, nMin, nUnary;
|
|
|
|
if (nsnull == aKey && nsnull == aData && nsnull == closure) {
|
|
|
|
// reset the counters
|
|
|
|
nTotal = nCount = nMax = nMin = nUnary = 0;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (nsnull == aKey && nsnull == aData && closure != nsnull) {
|
|
|
|
// dump the cumulatives
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("----------------------------------------------------------------------------------\n");
|
|
|
|
printf("(%d lists, %ld contexts) List Lengths: Min=%ld Max=%ld Average=%ld Unary=%ld\n",
|
2000-06-22 00:44:59 +04:00
|
|
|
(int)nCount, (long)nTotal, (long)nMin, (long)nMax, (long)(nCount>0 ? nTotal/nCount : 0), (long)nUnary);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("----------------------------------------------------------------------------------\n");
|
2000-06-22 00:44:59 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// actually do the dump
|
|
|
|
nsVoidArray *pList = (nsVoidArray *)aData;
|
|
|
|
if (pList) {
|
|
|
|
PRUint32 count = pList->Count();
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("List Length at key %lu:\t%ld\n",
|
2000-12-22 02:34:44 +03:00
|
|
|
(unsigned long)aKey->HashCode(),
|
2000-06-22 00:44:59 +04:00
|
|
|
(long)count );
|
|
|
|
nCount++;
|
|
|
|
nTotal += count;
|
|
|
|
if (count > nMax) nMax = count;
|
|
|
|
if (count < nMin) nMin = count;
|
|
|
|
if (count == 1) nUnary++;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-12-22 05:39:03 +03:00
|
|
|
PRBool PR_CALLBACK HashTableEnumTickle(nsHashKey *aKey, void *aData, void* closure)
|
2000-06-22 00:44:59 +04:00
|
|
|
{
|
|
|
|
PRUint32 nCount = 0;
|
|
|
|
|
|
|
|
// each entry is a list
|
|
|
|
nsVoidArray *pList = (nsVoidArray *)aData;
|
|
|
|
if (pList) {
|
|
|
|
PRUint32 count = pList->Count();
|
|
|
|
PRUint32 i;
|
|
|
|
// walk the list and get each context's key (just a way to tickle it)
|
|
|
|
for (i=0; i < count; i++) {
|
|
|
|
nsIStyleContext *pContext = (nsIStyleContext *)pList->ElementAt(i);
|
|
|
|
if (pContext) {
|
|
|
|
scKey key;
|
|
|
|
pContext->GetStyleContextKey(key);
|
2000-12-22 02:34:44 +03:00
|
|
|
if((PRUint32)key != (PRUint32)aKey->HashCode()){
|
|
|
|
NS_ASSERTION(PR_FALSE,"Key Changed in context!");
|
|
|
|
}
|
|
|
|
// printf( "%p tickled\n", pContext);
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleContextCache::DumpStats(void)
|
|
|
|
{
|
|
|
|
#ifdef DUMP_CACHE_STATS
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("StyleContextCache DumpStats BEGIN\n");
|
2000-06-22 00:44:59 +04:00
|
|
|
HashTableEnumDump(nsnull, nsnull, nsnull);
|
|
|
|
mHashTable.Enumerate(HashTableEnumDump);
|
|
|
|
HashTableEnumDump(nsnull, nsnull, "HACK!");
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("StyleContextCache DumpStats END\n");
|
2000-06-22 00:44:59 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleContextCache::Tickle(const char *msg)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2000-12-22 02:34:44 +03:00
|
|
|
// printf("Tickling: %s\n", msg ? msg : "");
|
2000-06-22 00:44:59 +04:00
|
|
|
mHashTable.Enumerate(HashTableEnumTickle);
|
2000-12-22 02:34:44 +03:00
|
|
|
// printf("Tickle done.\n");
|
2000-06-22 00:44:59 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_FASTCACHE
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::AddStyleContext(nsIStyleContext *aNewStyleContext)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// ASSERT the input is valid
|
|
|
|
NS_ASSERTION(aNewStyleContext != nsnull, "NULL style context not allowed in AddStyleContext");
|
2000-06-22 00:44:59 +04:00
|
|
|
|
|
|
|
#ifdef USE_FAST_CACHE
|
|
|
|
|
|
|
|
if (aNewStyleContext) {
|
|
|
|
scKey key;
|
|
|
|
aNewStyleContext->GetStyleContextKey(key);
|
|
|
|
rv = mStyleContextCache.AddContext(key,aNewStyleContext);
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
printf( "StyleContextCount: %ld\n", (long)mStyleContextCache.Count());
|
|
|
|
#endif
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // DONT USE_FAST_CACHE
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
// ASSERT it is not already in the collection
|
|
|
|
NS_ASSERTION((mStyleContextCache.IndexOf(aNewStyleContext) == -1), "StyleContext added in AddStyleContext is already in cache");
|
|
|
|
if (aNewStyleContext) {
|
|
|
|
rv = mStyleContextCache.AppendElement(aNewStyleContext);
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
printf( "StyleContextCount: %ld\n", (long)mStyleContextCache.Count());
|
|
|
|
#endif
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_FAST_CACHE
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::RemoveStyleContext(nsIStyleContext *aNewStyleContext)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// ASSERT the input is valid
|
|
|
|
NS_ASSERTION(aNewStyleContext != nsnull, "NULL style context not allowed in RemoveStyleContext");
|
2000-06-22 00:44:59 +04:00
|
|
|
|
|
|
|
#ifdef USE_FAST_CACHE
|
|
|
|
|
|
|
|
if (aNewStyleContext) {
|
|
|
|
scKey key;
|
|
|
|
aNewStyleContext->GetStyleContextKey(key);
|
|
|
|
rv = mStyleContextCache.RemoveContext(key,aNewStyleContext);
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
printf( "StyleContextCount: %ld\n", (long)mStyleContextCache.Count());
|
|
|
|
#endif
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else //DONT USE_FAST_CACHE
|
|
|
|
|
|
|
|
// ASSERT it is already in the collection
|
2000-03-31 11:08:36 +04:00
|
|
|
NS_ASSERTION((mStyleContextCache.IndexOf(aNewStyleContext) != -1), "StyleContext removed in AddStyleContext is not in cache");
|
|
|
|
if (aNewStyleContext) {
|
|
|
|
rv = mStyleContextCache.RemoveElement(aNewStyleContext);
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
|
|
|
printf( "StyleContextCount: %ld\n", (long)mStyleContextCache.Count());
|
|
|
|
#endif
|
2000-06-22 00:44:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //#ifdef USE_FAST_CACHE
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2000-06-22 00:44:59 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::FindMatchingContext(nsIStyleContext *aStyleContextToMatch,
|
|
|
|
nsIStyleContext **aMatchingContext)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
*aMatchingContext = nsnull;
|
|
|
|
|
|
|
|
#ifdef USE_FAST_CACHE
|
|
|
|
nsVoidArray *pList = nsnull;
|
|
|
|
scKey key;
|
|
|
|
aStyleContextToMatch->GetStyleContextKey(key);
|
|
|
|
if (NS_SUCCEEDED(mStyleContextCache.GetContexts(key, &pList)) && pList) {
|
|
|
|
PRInt32 count = pList->Count();
|
|
|
|
PRInt32 i;
|
|
|
|
for (i=0; i<count;i++) {
|
|
|
|
nsIStyleContext *pContext = (nsIStyleContext *)pList->ElementAt(i);
|
|
|
|
if (pContext && pContext != aStyleContextToMatch) {
|
|
|
|
PRBool bMatches = PR_FALSE;
|
|
|
|
NS_ADDREF(pContext);
|
|
|
|
if (NS_SUCCEEDED(pContext->StyleDataMatches(aStyleContextToMatch, &bMatches)) &&
|
|
|
|
bMatches) {
|
|
|
|
*aMatchingContext = pContext;
|
|
|
|
rv = NS_OK;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
NS_RELEASE(pContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // DONT USE_FAST_CACHE
|
|
|
|
|
|
|
|
PRInt32 count = mStyleContextCache.Count();
|
|
|
|
PRInt32 i;
|
|
|
|
for (i=0; i<count;i++) {
|
|
|
|
nsIStyleContext *pContext = (nsIStyleContext *)mStyleContextCache.ElementAt(i);
|
|
|
|
if (pContext && pContext != aStyleContextToMatch) {
|
|
|
|
PRBool bMatches = PR_FALSE;
|
|
|
|
NS_ADDREF(pContext);
|
|
|
|
if (NS_SUCCEEDED(pContext->StyleDataMatches(aStyleContextToMatch, &bMatches)) &&
|
|
|
|
bMatches) {
|
|
|
|
*aMatchingContext = pContext;
|
|
|
|
rv = NS_OK;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
NS_RELEASE(pContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // #ifdef USE_FAST_CACHE
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SHARE_STYLECONTEXTS
|
2000-03-31 11:08:36 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsUniqueStyleItems *nsUniqueStyleItems ::mInstance = nsnull;
|
|
|
|
|
|
|
|
void StyleSetImpl::ResetUniqueStyleItems(void)
|
|
|
|
{
|
|
|
|
UNIQUE_STYLE_ITEMS(uniqueItems);
|
|
|
|
uniqueItems->Clear();
|
|
|
|
}
|
|
|
|
|
2000-05-16 06:43:33 +04:00
|
|
|
struct AttributeContentPair {
|
|
|
|
nsIAtom *attribute;
|
|
|
|
nsIContent *content;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
EnumAffectsStyle(nsISupports *aElement, void *aData)
|
|
|
|
{
|
|
|
|
nsIStyleSheet *sheet = NS_STATIC_CAST(nsIStyleSheet *, aElement);
|
|
|
|
AttributeContentPair *pair = (AttributeContentPair *)aData;
|
|
|
|
PRBool affects;
|
|
|
|
if (NS_FAILED(sheet->AttributeAffectsStyle(pair->attribute, pair->content,
|
|
|
|
affects)) || affects)
|
|
|
|
return PR_FALSE; // stop checking
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
|
|
|
|
PRBool &aAffects)
|
|
|
|
{
|
|
|
|
AttributeContentPair pair;
|
|
|
|
pair.attribute = aAttribute;
|
|
|
|
pair.content = aContent;
|
|
|
|
|
2001-03-29 05:30:03 +04:00
|
|
|
/* scoped sheets should be checked first, since - if present - they will contain
|
|
|
|
the bulk of the applicable rules for the content node. */
|
|
|
|
if (mStyleRuleSupplier)
|
|
|
|
mStyleRuleSupplier->AttributeAffectsStyle(EnumAffectsStyle, &pair, aContent, &aAffects);
|
|
|
|
|
|
|
|
if (!aAffects) {
|
|
|
|
/* check until we find a sheet that will be affected */
|
|
|
|
if ((mDocSheets && !mDocSheets->EnumerateForwards(EnumAffectsStyle, &pair)) ||
|
|
|
|
(mOverrideSheets && !mOverrideSheets->EnumerateForwards(EnumAffectsStyle,
|
|
|
|
&pair)) ||
|
|
|
|
(mBackstopSheets && !mBackstopSheets->EnumerateForwards(EnumAffectsStyle,
|
|
|
|
&pair))) {
|
|
|
|
aAffects = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
aAffects = PR_FALSE;
|
|
|
|
}
|
2000-05-16 06:43:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* SizeOf method:
|
|
|
|
*
|
|
|
|
* Self (reported as StyleSetImpl's size):
|
|
|
|
* 1) sizeof(*this) + sizeof (overhead only) each collection that exists
|
|
|
|
* and the FrameConstructor overhead
|
|
|
|
*
|
|
|
|
* Contained / Aggregated data (not reported as StyleSetImpl's size):
|
|
|
|
* 1) Override Sheets, DocSheets, BackstopSheets, RuleProcessors, Recycler
|
|
|
|
* are all delegated to.
|
|
|
|
*
|
|
|
|
* Children / siblings / parents:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
void StyleSetImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aSizeOfHandler != nsnull, "SizeOf handler cannot be null");
|
|
|
|
|
|
|
|
// first get the unique items collection
|
|
|
|
UNIQUE_STYLE_ITEMS(uniqueItems);
|
|
|
|
|
|
|
|
if(! uniqueItems->AddItem((void*)this) ){
|
|
|
|
NS_ASSERTION(0, "StyleSet has already been conted in SizeOf operation");
|
|
|
|
// styleset has already been accounted for
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// get or create a tag for this instance
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
tag = getter_AddRefs(NS_NewAtom("StyleSet"));
|
|
|
|
// get the size of an empty instance and add to the sizeof handler
|
|
|
|
aSize = sizeof(StyleSetImpl);
|
|
|
|
|
|
|
|
// Next get the size of the OVERHEAD of objects we will delegate to:
|
|
|
|
if (mOverrideSheets && uniqueItems->AddItem(mOverrideSheets)){
|
|
|
|
aSize += sizeof(*mOverrideSheets);
|
|
|
|
}
|
|
|
|
if (mDocSheets && uniqueItems->AddItem(mDocSheets)){
|
|
|
|
aSize += sizeof(*mDocSheets);
|
|
|
|
}
|
|
|
|
if (mBackstopSheets && uniqueItems->AddItem(mBackstopSheets)){
|
|
|
|
aSize += sizeof(*mBackstopSheets);
|
|
|
|
}
|
2000-08-12 10:28:02 +04:00
|
|
|
if (mBackstopRuleProcessors && uniqueItems->AddItem(mBackstopRuleProcessors)){
|
|
|
|
aSize += sizeof(*mBackstopRuleProcessors);
|
|
|
|
}
|
|
|
|
if (mDocRuleProcessors && uniqueItems->AddItem(mDocRuleProcessors)){
|
|
|
|
aSize += sizeof(*mDocRuleProcessors);
|
|
|
|
}
|
|
|
|
if (mOverrideRuleProcessors && uniqueItems->AddItem(mOverrideRuleProcessors)){
|
|
|
|
aSize += sizeof(*mOverrideRuleProcessors);
|
2000-03-31 11:08:36 +04:00
|
|
|
}
|
|
|
|
if (mRecycler && uniqueItems->AddItem(mRecycler)){
|
|
|
|
aSize += sizeof(*mRecycler);
|
|
|
|
}
|
2000-06-03 01:45:06 +04:00
|
|
|
if (mQuirkStyleSheet) {
|
|
|
|
aSize += sizeof(mQuirkStyleSheet); // just the pointer: the sheet is counted elsewhere
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
2000-03-31 11:08:36 +04:00
|
|
|
// now the FrameConstructor
|
|
|
|
if(mFrameConstructor && uniqueItems->AddItem((void*)mFrameConstructor)){
|
|
|
|
aSize += sizeof(mFrameConstructor);
|
|
|
|
}
|
|
|
|
aSizeOfHandler->AddSize(tag,aSize);
|
|
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
// Now travers the collections and delegate
|
|
|
|
PRInt32 numSheets, curSheet;
|
|
|
|
PRUint32 localSize=0;
|
|
|
|
numSheets = GetNumberOfOverrideStyleSheets();
|
|
|
|
for(curSheet=0; curSheet < numSheets; curSheet++){
|
|
|
|
nsIStyleSheet* pSheet = GetOverrideStyleSheetAt(curSheet); //addref
|
|
|
|
if(pSheet){
|
|
|
|
localSize=0;
|
|
|
|
pSheet->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
numSheets = GetNumberOfDocStyleSheets();
|
|
|
|
for(curSheet=0; curSheet < numSheets; curSheet++){
|
|
|
|
nsIStyleSheet* pSheet = GetDocStyleSheetAt(curSheet);
|
|
|
|
if(pSheet){
|
|
|
|
localSize=0;
|
|
|
|
pSheet->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
numSheets = GetNumberOfBackstopStyleSheets();
|
|
|
|
for(curSheet=0; curSheet < numSheets; curSheet++){
|
|
|
|
nsIStyleSheet* pSheet = GetBackstopStyleSheetAt(curSheet);
|
|
|
|
if(pSheet){
|
|
|
|
localSize=0;
|
|
|
|
pSheet->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pSheet);
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
// rule processors
|
|
|
|
PRUint32 numRuleProcessors,curRuleProcessor;
|
2000-08-12 10:28:02 +04:00
|
|
|
if(mBackstopRuleProcessors){
|
|
|
|
mBackstopRuleProcessors->Count(&numRuleProcessors);
|
|
|
|
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
|
|
|
|
nsIStyleRuleProcessor* processor =
|
|
|
|
(nsIStyleRuleProcessor* )mBackstopRuleProcessors->ElementAt(curRuleProcessor);
|
|
|
|
if(processor){
|
|
|
|
localSize=0;
|
|
|
|
processor->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(processor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(mDocRuleProcessors){
|
|
|
|
mDocRuleProcessors->Count(&numRuleProcessors);
|
|
|
|
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
|
|
|
|
nsIStyleRuleProcessor* processor =
|
|
|
|
(nsIStyleRuleProcessor* )mDocRuleProcessors->ElementAt(curRuleProcessor);
|
|
|
|
if(processor){
|
|
|
|
localSize=0;
|
|
|
|
processor->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(processor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(mOverrideRuleProcessors){
|
|
|
|
mOverrideRuleProcessors->Count(&numRuleProcessors);
|
2000-03-31 11:08:36 +04:00
|
|
|
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
|
|
|
|
nsIStyleRuleProcessor* processor =
|
2000-08-12 10:28:02 +04:00
|
|
|
(nsIStyleRuleProcessor* )mOverrideRuleProcessors->ElementAt(curRuleProcessor);
|
2000-03-31 11:08:36 +04:00
|
|
|
if(processor){
|
|
|
|
localSize=0;
|
|
|
|
processor->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(processor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
// and the recycled ones too
|
|
|
|
if(mRecycler){
|
|
|
|
mRecycler->Count(&numRuleProcessors);
|
|
|
|
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
|
|
|
|
nsIStyleRuleProcessor* processor =
|
|
|
|
(nsIStyleRuleProcessor* )mRecycler->ElementAt(curRuleProcessor);
|
|
|
|
if(processor && uniqueItems->AddItem((void*)processor)){
|
|
|
|
localSize=0;
|
|
|
|
processor->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(processor);
|
|
|
|
}
|
|
|
|
}
|
2000-06-22 00:44:59 +04:00
|
|
|
|
|
|
|
// XXX - do the stylecontext cache too
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
// now delegate the sizeof to the larger or more complex aggregated objects
|
|
|
|
// - none
|
|
|
|
}
|
2000-08-12 10:28:02 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc, void* aData,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
// Walk the backstop rules first.
|
|
|
|
if (mBackstopRuleProcessors)
|
|
|
|
mBackstopRuleProcessors->EnumerateForwards(aFunc, aData);
|
|
|
|
|
|
|
|
PRBool useRuleProcessors = PR_TRUE;
|
|
|
|
if (mStyleRuleSupplier) {
|
|
|
|
// We can supply additional document-level sheets that should be walked.
|
|
|
|
mStyleRuleSupplier->WalkRules(this, aFunc, aData, aContent);
|
|
|
|
mStyleRuleSupplier->UseDocumentRules(aContent, &useRuleProcessors);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk the doc rules next.
|
|
|
|
if (mDocRuleProcessors && useRuleProcessors)
|
|
|
|
mDocRuleProcessors->EnumerateForwards(aFunc, aData);
|
|
|
|
|
|
|
|
// Walk the override rules last.
|
|
|
|
if (mOverrideRuleProcessors)
|
|
|
|
mOverrideRuleProcessors->EnumerateForwards(aFunc, aData);
|
|
|
|
}
|