2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04: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
|
|
|
*
|
2001-09-25 05:32:19 +04: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.
|
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-08-02 18:34:55 +04:00
|
|
|
* Contributor(s):
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
2001-06-01 02:19:43 +04:00
|
|
|
#include "nsICSSStyleRule.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#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"
|
2001-06-01 02:19:43 +04:00
|
|
|
#include "nsRuleNode.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsRuleWalker.h"
|
2001-08-02 18:34:55 +04:00
|
|
|
#include "nsIHTMLDocument.h"
|
|
|
|
#include "nsIDOMHTMLBodyElement.h"
|
2002-03-27 05:38:13 +03:00
|
|
|
#include "nsHTMLAtoms.h"
|
2002-04-05 12:05:33 +04:00
|
|
|
#include "nsHashtable.h"
|
2000-08-12 10:28:02 +04:00
|
|
|
|
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
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
#include "nsISizeOfHandler.h"
|
2001-01-03 02:13:49 +03:00
|
|
|
|
2002-04-05 12:05:33 +04:00
|
|
|
// =====================================================
|
|
|
|
// nsRuleNodeList
|
|
|
|
// A class that represents a chain of rule nodes
|
|
|
|
|
|
|
|
struct nsRuleNodeList
|
|
|
|
{
|
|
|
|
nsRuleNodeList(nsRuleNode* aRuleNode, nsRuleNodeList* aNext = nsnull)
|
|
|
|
:mRuleNode(aRuleNode), mNext(aNext)
|
|
|
|
{};
|
|
|
|
|
2002-07-03 00:25:30 +04:00
|
|
|
void* operator new(size_t sz, nsIPresContext* aContext) CPP_THROW_NEW {
|
2002-04-05 12:05:33 +04:00
|
|
|
void* result = nsnull;
|
|
|
|
aContext->AllocateFromShell(sz, &result);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Destroy() {
|
|
|
|
if (mNext)
|
|
|
|
mNext->Destroy();
|
|
|
|
mRuleNode->PresContext()->FreeToShell(sizeof(nsRuleNodeList), this);
|
|
|
|
};
|
|
|
|
|
|
|
|
nsRuleNode* mRuleNode;
|
|
|
|
nsRuleNodeList* mNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
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);
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
virtual void AppendUserStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual void InsertUserStyleSheetAfter(nsIStyleSheet* aSheet,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIStyleSheet* aAfterSheet);
|
2001-11-06 13:04:05 +03:00
|
|
|
virtual void InsertUserStyleSheetBefore(nsIStyleSheet* aSheet,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIStyleSheet* aBeforeSheet);
|
2001-11-06 13:04:05 +03:00
|
|
|
virtual void RemoveUserStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual PRInt32 GetNumberOfUserStyleSheets();
|
|
|
|
virtual nsIStyleSheet* GetUserStyleSheetAt(PRInt32 aIndex);
|
|
|
|
virtual void ReplaceUserStyleSheets(nsISupportsArray* aNewSheets);
|
|
|
|
|
|
|
|
virtual void AppendAgentStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual void InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aAfterSheet);
|
|
|
|
virtual void InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aBeforeSheet);
|
|
|
|
virtual void RemoveAgentStyleSheet(nsIStyleSheet* aSheet);
|
|
|
|
virtual PRInt32 GetNumberOfAgentStyleSheets();
|
|
|
|
virtual nsIStyleSheet* GetAgentStyleSheetAt(PRInt32 aIndex);
|
|
|
|
virtual void ReplaceAgentStyleSheets(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,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsIStyleContext* aParentContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-10-30 09:02:05 +03:00
|
|
|
virtual nsIStyleContext* ResolveStyleForNonElement(
|
|
|
|
nsIPresContext* aPresContext,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsIStyleContext* aParentContext);
|
2001-10-30 09:02:05 +03: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
|
|
|
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,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsIStyleContext* aParentContext);
|
1998-05-19 01:05:52 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHOD Shutdown();
|
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
// The following two methods can be used to tear down and reconstruct a rule tree. The idea
|
|
|
|
// is to first call BeginRuleTreeReconstruct, which will set aside the old rule
|
|
|
|
// tree. The entire frame tree should then have ReResolveStyleContext
|
|
|
|
// called on it. With the old rule tree hidden from view, the newly resolved style contexts will
|
|
|
|
// resolve to rule nodes in a fresh rule tree, and the re-resolve system will properly compute
|
|
|
|
// the visual impact of the changes.
|
|
|
|
//
|
|
|
|
// After re-resolution, call EndRuleTreeReconstruct() to finally discard the old rule tree.
|
|
|
|
// This trick can be used in lieu of a full frame reconstruction when drastic style changes
|
|
|
|
// happen (e.g., stylesheets being added/removed in the DOM, theme switching in the Mozilla app,
|
|
|
|
// etc.
|
|
|
|
virtual nsresult BeginRuleTreeReconstruct();
|
|
|
|
virtual nsresult EndRuleTreeReconstruct();
|
|
|
|
|
2001-10-24 04:01:09 +04:00
|
|
|
virtual nsresult GetRuleTree(nsRuleNode** aResult);
|
|
|
|
virtual nsresult ClearCachedDataInRuleTree(nsIStyleRule* aRule);
|
2002-04-05 12:05:33 +04:00
|
|
|
|
|
|
|
virtual nsresult AddRuleNodeMapping(nsRuleNode* aRuleNode);
|
2001-10-24 04:01:09 +04:00
|
|
|
|
2001-07-25 10:33:06 +04:00
|
|
|
virtual nsresult ClearStyleData(nsIPresContext* aPresContext, nsIStyleRule* aRule, nsIStyleContext* aContext);
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
virtual nsresult GetStyleFrameConstruction(nsIStyleFrameConstruction** aResult) {
|
|
|
|
*aResult = mFrameConstructor;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-04 03:35:41 +04:00
|
|
|
NS_IMETHOD ReParentStyleContext(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIStyleContext* aNewParentContext,
|
|
|
|
nsIStyleContext** aNewStyleContext);
|
|
|
|
|
2002-04-11 07:49:30 +04:00
|
|
|
NS_IMETHOD HasStateDependentStyle(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
PRInt32 aStateMask,
|
|
|
|
PRBool* aResult);
|
1999-04-20 04:02:22 +04:00
|
|
|
|
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,
|
2002-03-07 06:34:29 +03:00
|
|
|
nsIContent* aContent2,
|
2002-04-11 07:49:30 +04:00
|
|
|
PRInt32 aStateMask);
|
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,
|
2001-08-25 06:01:08 +04:00
|
|
|
PRInt32 aModType,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint aHint); // See nsStyleConsts fot hint values
|
1998-09-30 03:47:03 +04:00
|
|
|
|
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,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint aHint); // See nsStyleConsts fot hint values
|
1998-11-26 04:34:53 +03:00
|
|
|
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
|
|
|
|
2001-09-13 00:19:41 +04:00
|
|
|
// Get the XBL insertion point for a child
|
|
|
|
NS_IMETHOD GetInsertionPoint(nsIPresShell* aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
nsIFrame** aInsertionPoint);
|
|
|
|
|
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);
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
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);
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
virtual void ResetUniqueStyleItems(void);
|
|
|
|
|
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);
|
|
|
|
|
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();
|
2001-11-06 13:04:05 +03:00
|
|
|
PRBool EnsureArray(nsCOMPtr<nsISupportsArray> &aArray);
|
|
|
|
void RecycleArray(nsCOMPtr<nsISupportsArray> &aArray);
|
2000-08-12 10:28:02 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
void EnsureRuleWalker(nsIPresContext* aPresContext);
|
|
|
|
|
2000-08-12 10:28:02 +04:00
|
|
|
void ClearRuleProcessors(void);
|
2001-11-06 13:04:05 +03:00
|
|
|
void ClearAgentRuleProcessors(void);
|
|
|
|
void ClearUserRuleProcessors(void);
|
2000-08-12 10:28:02 +04:00
|
|
|
void ClearDocRuleProcessors(void);
|
2001-11-06 13:04:05 +03:00
|
|
|
void ClearOverrideRuleProcessors(void);
|
|
|
|
|
|
|
|
nsresult GatherRuleProcessors(void);
|
2000-08-12 10:28:02 +04:00
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void AddImportantRules(nsRuleNode* aCurrLevelNode, nsRuleNode* aLastPrevLevelNode);
|
2001-11-11 02:51:45 +03:00
|
|
|
|
|
|
|
// Enumerate the rules in a way that cares about the order of the
|
|
|
|
// rules.
|
|
|
|
void FileRules(nsISupportsArrayEnumFunc aCollectorFunc,
|
|
|
|
RuleProcessorData* aData);
|
|
|
|
|
|
|
|
// Enumerate all the rules in a way that doesn't care about the order
|
|
|
|
// of the rules and break out if the enumeration is halted.
|
|
|
|
void WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc,
|
|
|
|
RuleProcessorData* aData);
|
1999-10-08 07:09:31 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
nsIStyleContext* GetContext(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleContext* aParentContext,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsIAtom* aPseudoTag);
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
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);
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
nsCOMPtr<nsISupportsArray> mOverrideSheets; // most significant first
|
|
|
|
nsCOMPtr<nsISupportsArray> mDocSheets; // " "
|
|
|
|
nsCOMPtr<nsISupportsArray> mUserSheets; // " "
|
|
|
|
nsCOMPtr<nsISupportsArray> mAgentSheets; // " "
|
1999-10-08 07:09:31 +04:00
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
nsCOMPtr<nsISupportsArray> mAgentRuleProcessors; // least significant first
|
|
|
|
nsCOMPtr<nsISupportsArray> mUserRuleProcessors; // " "
|
|
|
|
nsCOMPtr<nsISupportsArray> mDocRuleProcessors; // " "
|
|
|
|
nsCOMPtr<nsISupportsArray> mOverrideRuleProcessors; // " "
|
1999-10-08 07:09:31 +04:00
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
nsCOMPtr<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;
|
|
|
|
|
2001-10-24 04:01:09 +04:00
|
|
|
nsRuleNode* mRuleTree; // This is the root of our rule tree. It is a lexicographic tree of
|
|
|
|
// matched rules that style contexts use to look up properties.
|
2001-12-18 01:51:39 +03:00
|
|
|
nsRuleNode* mOldRuleTree; // Used during rule tree reconstruction.
|
2001-10-24 04:01:09 +04:00
|
|
|
nsRuleWalker* mRuleWalker; // This is an instance of a rule walker that can be used
|
|
|
|
// to navigate through our tree.
|
2002-04-05 12:05:33 +04:00
|
|
|
nsHashtable mRuleMappings; // A hashtable from rules to rule node lists.
|
2000-03-31 11:08:36 +04:00
|
|
|
|
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()
|
2001-11-06 13:04:05 +03:00
|
|
|
: mFrameConstructor(nsnull),
|
2000-08-12 10:28:02 +04:00
|
|
|
mQuirkStyleSheet(nsnull),
|
2001-10-24 04:01:09 +04:00
|
|
|
mRuleTree(nsnull),
|
2001-12-18 01:51:39 +03:00
|
|
|
mOldRuleTree(nsnull),
|
2002-04-05 12:05:33 +04:00
|
|
|
mRuleWalker(nsnull),
|
|
|
|
mRuleMappings(32)
|
2000-02-11 04:21:36 +03:00
|
|
|
#ifdef MOZ_PERF_METRICS
|
|
|
|
,mTimerEnabled(PR_FALSE)
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2002-09-07 21:13:19 +04:00
|
|
|
NS_INIT_ISUPPORTS();
|
2000-11-08 06:13:53 +03:00
|
|
|
if (gInstances++ == 0)
|
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
static const char kQuirk_href[] = "resource:/res/quirk.css";
|
|
|
|
NS_NewURI (&gQuirkURI, NS_LITERAL_CSTRING(kQuirk_href));
|
2000-11-08 06:13:53 +03:00
|
|
|
NS_ASSERTION (gQuirkURI != 0, "Cannot allocate nsStyleSetImpl::gQuirkURI");
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
StyleSetImpl::~StyleSetImpl()
|
|
|
|
{
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IF_RELEASE(mFrameConstructor);
|
2000-06-03 01:45:06 +04:00
|
|
|
NS_IF_RELEASE(mQuirkStyleSheet);
|
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-08-21 05:48:11 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(StyleSetImpl, 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
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
PRBool StyleSetImpl::EnsureArray(nsCOMPtr<nsISupportsArray> &aArray)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-11-06 13:04:05 +03:00
|
|
|
if (nsnull == aArray) {
|
|
|
|
aArray = mRecycler;
|
1999-10-08 07:09:31 +04:00
|
|
|
mRecycler = nsnull;
|
2001-11-06 13:04:05 +03:00
|
|
|
if (nsnull == aArray) {
|
|
|
|
if (NS_OK != NS_NewISupportsArray(getter_AddRefs(aArray))) {
|
1999-10-08 07:09:31 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-06 13:04:05 +03:00
|
|
|
StyleSetImpl::RecycleArray(nsCOMPtr<nsISupportsArray> &aArray)
|
1999-10-08 07:09:31 +04:00
|
|
|
{
|
2001-11-06 13:04:05 +03:00
|
|
|
if (!mRecycler) {
|
|
|
|
mRecycler = aArray; // take ref
|
1999-10-08 07:09:31 +04:00
|
|
|
mRecycler->Clear();
|
2001-11-06 13:04:05 +03:00
|
|
|
aArray = nsnull;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
|
|
|
else { // already have a recycled array
|
2001-11-06 13:04:05 +03:00
|
|
|
aArray = nsnull;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
1999-10-08 07:09:31 +04:00
|
|
|
StyleSetImpl::ClearRuleProcessors(void)
|
|
|
|
{
|
2001-11-06 13:04:05 +03:00
|
|
|
ClearAgentRuleProcessors();
|
|
|
|
ClearUserRuleProcessors();
|
2000-08-12 10:28:02 +04:00
|
|
|
ClearDocRuleProcessors();
|
|
|
|
ClearOverrideRuleProcessors();
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
2000-08-12 10:28:02 +04:00
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
|
|
|
StyleSetImpl::ClearAgentRuleProcessors(void)
|
2000-08-12 10:28:02 +04:00
|
|
|
{
|
2001-11-06 13:04:05 +03:00
|
|
|
if (mAgentRuleProcessors)
|
|
|
|
RecycleArray(mAgentRuleProcessors);
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
|
|
|
StyleSetImpl::ClearUserRuleProcessors(void)
|
|
|
|
{
|
|
|
|
if (mUserRuleProcessors)
|
|
|
|
RecycleArray(mUserRuleProcessors);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-12 10:28:02 +04:00
|
|
|
StyleSetImpl::ClearDocRuleProcessors(void)
|
|
|
|
{
|
|
|
|
if (mDocRuleProcessors)
|
2001-11-06 13:04:05 +03:00
|
|
|
RecycleArray(mDocRuleProcessors);
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
2000-08-12 10:28:02 +04:00
|
|
|
StyleSetImpl::ClearOverrideRuleProcessors(void)
|
|
|
|
{
|
|
|
|
if (mOverrideRuleProcessors)
|
2001-11-06 13:04:05 +03:00
|
|
|
RecycleArray(mOverrideRuleProcessors);
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
struct RuleProcessorEnumData {
|
|
|
|
RuleProcessorEnumData(nsISupportsArray* aRuleProcessors)
|
1999-10-08 07:09:31 +04:00
|
|
|
: mRuleProcessors(aRuleProcessors),
|
|
|
|
mPrevProcessor(nsnull)
|
|
|
|
{}
|
|
|
|
|
|
|
|
nsISupportsArray* mRuleProcessors;
|
|
|
|
nsIStyleRuleProcessor* mPrevProcessor;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
EnumRuleProcessor(nsISupports* aSheet, void* aData)
|
|
|
|
{
|
|
|
|
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheet;
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorEnumData* data = (RuleProcessorEnumData*)aData;
|
1999-10-08 07:09:31 +04:00
|
|
|
|
|
|
|
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;
|
2001-11-06 13:04:05 +03:00
|
|
|
if (mAgentSheets && !mAgentRuleProcessors) {
|
|
|
|
if (EnsureArray(mAgentRuleProcessors)) {
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorEnumData data(mAgentRuleProcessors);
|
2001-11-06 13:04:05 +03:00
|
|
|
mAgentSheets->EnumerateBackwards(EnumRuleProcessor, &data);
|
2000-08-12 10:28:02 +04:00
|
|
|
PRUint32 count;
|
2001-11-06 13:04:05 +03:00
|
|
|
mAgentRuleProcessors->Count(&count);
|
2000-08-12 10:28:02 +04:00
|
|
|
if (0 == count) {
|
2001-11-06 13:04:05 +03:00
|
|
|
RecycleArray(mAgentRuleProcessors);
|
|
|
|
}
|
|
|
|
} else return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUserSheets && !mUserRuleProcessors) {
|
|
|
|
if (EnsureArray(mUserRuleProcessors)) {
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorEnumData data(mUserRuleProcessors);
|
2001-11-06 13:04:05 +03:00
|
|
|
mUserSheets->EnumerateBackwards(EnumRuleProcessor, &data);
|
|
|
|
PRUint32 count;
|
|
|
|
mUserRuleProcessors->Count(&count);
|
|
|
|
if (0 == count) {
|
|
|
|
RecycleArray(mUserRuleProcessors);
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
} else return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDocSheets && !mDocRuleProcessors) {
|
2001-11-06 13:04:05 +03:00
|
|
|
if (EnsureArray(mDocRuleProcessors)) {
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorEnumData 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) {
|
2001-11-06 13:04:05 +03:00
|
|
|
RecycleArray(mDocRuleProcessors);
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
} else return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOverrideSheets && !mOverrideRuleProcessors) {
|
2001-11-06 13:04:05 +03:00
|
|
|
if (EnsureArray(mOverrideRuleProcessors)) {
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorEnumData 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) {
|
2001-11-06 13:04:05 +03:00
|
|
|
RecycleArray(mOverrideRuleProcessors);
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
} 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");
|
2001-11-06 13:04:05 +03:00
|
|
|
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");
|
2001-11-06 13:04:05 +03:00
|
|
|
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");
|
2001-11-06 13:04:05 +03:00
|
|
|
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");
|
2001-11-06 13:04:05 +03:00
|
|
|
if (EnsureArray(mDocSheets)) {
|
1999-01-23 10:01:57 +03:00
|
|
|
mDocSheets->RemoveElement(aSheet);
|
|
|
|
// lowest index last
|
2001-06-20 07:27:48 +04:00
|
|
|
PRInt32 newDocIndex = 0;
|
|
|
|
aDocument->GetIndexOfStyleSheet(aSheet, &newDocIndex);
|
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);
|
2001-06-20 07:27:48 +04:00
|
|
|
PRInt32 sheetDocIndex = 0;
|
|
|
|
aDocument->GetIndexOfStyleSheet(sheet, &sheetDocIndex);
|
1999-01-23 10:01:57 +03:00
|
|
|
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) {
|
2002-10-09 05:46:15 +04:00
|
|
|
CallQueryInterface(aSheet, &mFrameConstructor);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
// ------ user sheets
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void StyleSetImpl::AppendUserStyleSheet(nsIStyleSheet* aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
2001-11-06 13:04:05 +03:00
|
|
|
if (EnsureArray(mUserSheets)) {
|
|
|
|
mUserSheets->RemoveElement(aSheet);
|
|
|
|
mUserSheets->AppendElement(aSheet);
|
|
|
|
ClearUserRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void StyleSetImpl::InsertUserStyleSheetAfter(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aAfterSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
2001-11-06 13:04:05 +03:00
|
|
|
if (EnsureArray(mUserSheets)) {
|
|
|
|
mUserSheets->RemoveElement(aSheet);
|
|
|
|
PRInt32 index = mUserSheets->IndexOf(aAfterSheet);
|
|
|
|
mUserSheets->InsertElementAt(aSheet, ++index);
|
|
|
|
ClearUserRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void StyleSetImpl::InsertUserStyleSheetBefore(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aBeforeSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
2001-11-06 13:04:05 +03:00
|
|
|
if (EnsureArray(mUserSheets)) {
|
|
|
|
mUserSheets->RemoveElement(aSheet);
|
|
|
|
PRInt32 index = mUserSheets->IndexOf(aBeforeSheet);
|
|
|
|
mUserSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
|
|
|
|
ClearUserRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
void StyleSetImpl::RemoveUserStyleSheet(nsIStyleSheet* aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
if (nsnull != mUserSheets) {
|
|
|
|
mUserSheets->RemoveElement(aSheet);
|
|
|
|
ClearUserRuleProcessors();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
PRInt32 StyleSetImpl::GetNumberOfUserStyleSheets()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-11-06 13:04:05 +03:00
|
|
|
if (nsnull != mUserSheets) {
|
1999-05-13 08:56:04 +04:00
|
|
|
PRUint32 cnt;
|
2001-11-06 13:04:05 +03:00
|
|
|
nsresult rv = mUserSheets->Count(&cnt);
|
1999-05-13 08:56:04 +04:00
|
|
|
if (NS_FAILED(rv)) return 0; // XXX error?
|
|
|
|
return cnt;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
nsIStyleSheet* StyleSetImpl::GetUserStyleSheetAt(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsIStyleSheet* sheet = nsnull;
|
|
|
|
if (nsnull != mUserSheets) {
|
|
|
|
sheet = (nsIStyleSheet*)mUserSheets->ElementAt(aIndex);
|
|
|
|
}
|
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleSetImpl::ReplaceUserStyleSheets(nsISupportsArray* aNewUserSheets)
|
|
|
|
{
|
|
|
|
ClearUserRuleProcessors();
|
|
|
|
mUserSheets = aNewUserSheets;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------ agent sheets
|
|
|
|
|
|
|
|
void StyleSetImpl::AppendAgentStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(mAgentSheets)) {
|
|
|
|
mAgentSheets->RemoveElement(aSheet);
|
|
|
|
mAgentSheets->AppendElement(aSheet);
|
|
|
|
ClearAgentRuleProcessors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::InsertAgentStyleSheetAfter(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aAfterSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(mAgentSheets)) {
|
|
|
|
mAgentSheets->RemoveElement(aSheet);
|
|
|
|
PRInt32 index = mAgentSheets->IndexOf(aAfterSheet);
|
|
|
|
mAgentSheets->InsertElementAt(aSheet, ++index);
|
|
|
|
ClearAgentRuleProcessors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::InsertAgentStyleSheetBefore(nsIStyleSheet* aSheet,
|
|
|
|
nsIStyleSheet* aBeforeSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
if (EnsureArray(mAgentSheets)) {
|
|
|
|
mAgentSheets->RemoveElement(aSheet);
|
|
|
|
PRInt32 index = mAgentSheets->IndexOf(aBeforeSheet);
|
|
|
|
mAgentSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
|
|
|
|
ClearAgentRuleProcessors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleSetImpl::RemoveAgentStyleSheet(nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
|
|
|
if (nsnull != mAgentSheets) {
|
|
|
|
mAgentSheets->RemoveElement(aSheet);
|
|
|
|
ClearAgentRuleProcessors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 StyleSetImpl::GetNumberOfAgentStyleSheets()
|
|
|
|
{
|
|
|
|
if (nsnull != mAgentSheets) {
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mAgentSheets->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return 0; // XXX error?
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
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:
|
2001-11-06 13:04:05 +03:00
|
|
|
// - run through all of the agent sheets and check for a CSSStyleSheet that
|
2000-06-03 01:45:06 +04:00
|
|
|
// has the URL we want
|
2001-11-06 13:04:05 +03:00
|
|
|
PRUint32 i, nSheets = GetNumberOfAgentStyleSheets();
|
2000-06-03 01:45:06 +04:00
|
|
|
for (i=0; i< nSheets; i++) {
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
2001-11-06 13:04:05 +03:00
|
|
|
sheet = getter_AddRefs(GetAgentStyleSheetAt(i));
|
2000-06-03 01:45:06 +04:00
|
|
|
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);
|
2001-06-07 03:34:17 +04:00
|
|
|
// only one quirk style sheet can exist, so stop looking
|
|
|
|
break;
|
2000-06-03 01:45:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-05-24 03:09:31 +04:00
|
|
|
NS_ASSERTION(mQuirkStyleSheet, "no quirk stylesheet");
|
2000-06-03 01:45:06 +04:00
|
|
|
if (mQuirkStyleSheet) {
|
2001-09-25 02:36:43 +04:00
|
|
|
#if defined(DEBUG_warren) || defined(DEBUG_attinasi)
|
2000-10-29 02:17:53 +04:00
|
|
|
printf( "%s Quirk StyleSheet\n", aEnable ? "Enabling" : "Disabling" );
|
2002-05-24 03:09:31 +04:00
|
|
|
#endif
|
2002-06-03 22:26:18 +04:00
|
|
|
#ifdef DEBUG_dbaron // XXX Make this |DEBUG| once it stops firing.
|
2002-05-24 03:09:31 +04:00
|
|
|
PRUint32 count = 0;
|
|
|
|
if (mAgentRuleProcessors)
|
|
|
|
mAgentRuleProcessors->Count(&count);
|
|
|
|
PRBool enabledNow;
|
|
|
|
mQuirkStyleSheet->GetEnabled(enabledNow);
|
|
|
|
NS_ASSERTION(count == 0 || aEnable == enabledNow,
|
|
|
|
"enabling/disabling quirk stylesheet too late");
|
|
|
|
if (count != 0 && aEnable == enabledNow)
|
|
|
|
printf("WARNING: We set the quirks mode too many times.\n"); // we do!
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif
|
2000-06-03 01:45:06 +04:00
|
|
|
mQuirkStyleSheet->SetEnabled(aEnable);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
nsIStyleSheet* StyleSetImpl::GetAgentStyleSheetAt(PRInt32 aIndex)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
nsIStyleSheet* sheet = nsnull;
|
2001-11-06 13:04:05 +03:00
|
|
|
if (nsnull != mAgentSheets) {
|
|
|
|
sheet = (nsIStyleSheet*)mAgentSheets->ElementAt(aIndex);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
2000-05-28 00:03:14 +04:00
|
|
|
void
|
2001-11-06 13:04:05 +03:00
|
|
|
StyleSetImpl::ReplaceAgentStyleSheets(nsISupportsArray* aNewAgentSheets)
|
|
|
|
{
|
|
|
|
ClearAgentRuleProcessors();
|
|
|
|
mAgentSheets = aNewAgentSheets;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::NotifyStyleSheetStateChanged(PRBool aDisabled)
|
2000-05-28 00:03:14 +04:00
|
|
|
{
|
2001-11-06 13:04:05 +03:00
|
|
|
ClearRuleProcessors();
|
|
|
|
GatherRuleProcessors();
|
|
|
|
return NS_OK;
|
2000-05-28 00:03:14 +04:00
|
|
|
}
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
struct RulesMatchingData : public ElementRuleProcessorData {
|
1999-06-15 10:15:51 +04:00
|
|
|
RulesMatchingData(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aContent,
|
2001-10-24 04:01:09 +04:00
|
|
|
nsRuleWalker* aRuleWalker)
|
2001-11-11 02:51:45 +03:00
|
|
|
: ElementRuleProcessorData(aPresContext, aContent, aRuleWalker),
|
|
|
|
mMedium(aMedium)
|
1999-06-15 10:15:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
nsIAtom* mMedium;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
processor->RulesMatching(data, data->mMedium);
|
1999-06-15 10:15:51 +04:00
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-03-08 02:48:26 +03:00
|
|
|
/**
|
|
|
|
* |GetContext| implements sharing of style contexts (not just the data
|
|
|
|
* on the rule nodes) between siblings and cousins of the same
|
|
|
|
* generation. (It works for cousins of the same generation since
|
|
|
|
* |aParentContext| could itself be a shared context.)
|
|
|
|
*/
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* StyleSetImpl::GetContext(nsIPresContext* aPresContext,
|
2001-06-01 02:19:43 +04:00
|
|
|
nsIStyleContext* aParentContext,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsIAtom* aPseudoTag)
|
1998-05-19 01:05:52 +04:00
|
|
|
{
|
1998-11-03 23:19:28 +03:00
|
|
|
nsIStyleContext* result = nsnull;
|
2001-10-24 04:01:09 +04:00
|
|
|
nsRuleNode* ruleNode = mRuleWalker->GetCurrentNode();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2002-03-31 20:59:00 +04:00
|
|
|
if (aParentContext)
|
2001-06-01 02:19:43 +04:00
|
|
|
aParentContext->FindChildWithRules(aPseudoTag, ruleNode, result);
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
#ifdef NOISY_DEBUG
|
2002-03-31 20:59:00 +04:00
|
|
|
if (result)
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "--- SharedSC %d ---\n", ++gSharedCount);
|
2002-03-31 20:59:00 +04:00
|
|
|
else
|
|
|
|
fprintf(stdout, "+++ NewSC %d +++\n", ++gNewCount);
|
2000-03-31 11:08:36 +04:00
|
|
|
#endif
|
|
|
|
|
2002-03-31 20:59:00 +04:00
|
|
|
if (!result)
|
|
|
|
NS_NewStyleContext(&result, aParentContext, aPseudoTag, ruleNode,
|
|
|
|
aPresContext);
|
|
|
|
|
1998-05-19 01:05:52 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
void
|
2001-11-06 13:04:05 +03:00
|
|
|
StyleSetImpl::AddImportantRules(nsRuleNode* aCurrLevelNode,
|
|
|
|
nsRuleNode* aLastPrevLevelNode)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2001-11-06 13:04:05 +03:00
|
|
|
if (!aCurrLevelNode || aCurrLevelNode == aLastPrevLevelNode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AddImportantRules(aCurrLevelNode->GetParent(), aLastPrevLevelNode);
|
2001-06-01 02:19:43 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIStyleRule> rule;;
|
2001-11-06 13:04:05 +03:00
|
|
|
aCurrLevelNode->GetRule(getter_AddRefs(rule));
|
2001-06-01 02:19:43 +04:00
|
|
|
nsCOMPtr<nsICSSStyleRule> cssRule(do_QueryInterface(rule));
|
|
|
|
if (cssRule) {
|
2002-10-09 05:59:43 +04:00
|
|
|
nsCOMPtr<nsIStyleRule> impRule = cssRule->GetImportantRule();
|
2001-06-01 02:19:43 +04:00
|
|
|
if (impRule)
|
|
|
|
mRuleWalker->Forward(impRule);
|
1998-09-11 06:05:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
// Enumerate the rules in a way that cares about the order of the rules.
|
2001-11-06 13:04:05 +03:00
|
|
|
void
|
|
|
|
StyleSetImpl::FileRules(nsISupportsArrayEnumFunc aCollectorFunc,
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorData* aData)
|
2001-11-06 13:04:05 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
// Cascading order:
|
|
|
|
// [least important]
|
|
|
|
// 1. UA normal rules = Agent normal
|
|
|
|
// 2. User normal rules = User normal
|
|
|
|
// 3. Author normal rules = Document normal
|
|
|
|
// 4. Override normal rules = Override normal
|
|
|
|
// 5. Author !important rules = Document !important
|
|
|
|
// 6. Override !important rules = Override !important
|
|
|
|
// 7. User !important rules = User !important
|
|
|
|
// 8. UA !important rules = Agent !important
|
|
|
|
// [most important]
|
|
|
|
|
|
|
|
nsRuleNode* lastAgentRN = nsnull;
|
|
|
|
if (mAgentRuleProcessors) {
|
|
|
|
mAgentRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
|
|
|
|
lastAgentRN = mRuleWalker->GetCurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRuleNode* lastUserRN = lastAgentRN;
|
|
|
|
if (mUserRuleProcessors) {
|
|
|
|
mUserRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
|
|
|
|
lastUserRN = mRuleWalker->GetCurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRuleNode* lastDocRN = lastUserRN;
|
|
|
|
PRBool useRuleProcessors = PR_TRUE;
|
|
|
|
if (mStyleRuleSupplier) {
|
|
|
|
// We can supply additional document-level sheets that should be walked.
|
2001-11-11 02:51:45 +03:00
|
|
|
mStyleRuleSupplier->WalkRules(this, aCollectorFunc, aData);
|
|
|
|
mStyleRuleSupplier->UseDocumentRules(aData->mContent, &useRuleProcessors);
|
2001-11-06 13:04:05 +03:00
|
|
|
}
|
2001-11-28 07:54:05 +03:00
|
|
|
if (mDocRuleProcessors && useRuleProcessors) {
|
2001-11-06 13:04:05 +03:00
|
|
|
mDocRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
|
|
|
|
}
|
|
|
|
lastDocRN = mRuleWalker->GetCurrentNode();
|
|
|
|
|
|
|
|
nsRuleNode* lastOvrRN = lastDocRN;
|
|
|
|
if (mOverrideRuleProcessors) {
|
|
|
|
mOverrideRuleProcessors->EnumerateForwards(aCollectorFunc, aData);
|
|
|
|
lastOvrRN = mRuleWalker->GetCurrentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
AddImportantRules(lastDocRN, lastUserRN); //doc
|
|
|
|
AddImportantRules(lastOvrRN, lastDocRN); //ovr
|
|
|
|
AddImportantRules(lastUserRN, lastAgentRN); //user
|
|
|
|
AddImportantRules(lastAgentRN, nsnull); //agent
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
// Enumerate all the rules in a way that doesn't care about the order
|
|
|
|
// of the rules and break out if the enumeration is halted.
|
|
|
|
void
|
|
|
|
StyleSetImpl::WalkRuleProcessors(nsISupportsArrayEnumFunc aFunc,
|
|
|
|
RuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
// Walk the agent rules first.
|
|
|
|
if (mAgentRuleProcessors)
|
|
|
|
if (!mAgentRuleProcessors->EnumerateForwards(aFunc, aData))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Walk the user rules next.
|
|
|
|
if (mUserRuleProcessors)
|
|
|
|
if (!mUserRuleProcessors->EnumerateForwards(aFunc, aData))
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRBool useRuleProcessors = PR_TRUE;
|
|
|
|
if (mStyleRuleSupplier) {
|
|
|
|
// We can supply additional document-level sheets that should be walked.
|
|
|
|
// XXX We ignore whether the enumerator wants to halt here!
|
|
|
|
mStyleRuleSupplier->WalkRules(this, aFunc, aData);
|
|
|
|
mStyleRuleSupplier->UseDocumentRules(aData->mContent, &useRuleProcessors);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now walk the doc rules.
|
|
|
|
if (mDocRuleProcessors && useRuleProcessors)
|
|
|
|
if (!mDocRuleProcessors->EnumerateForwards(aFunc, aData))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Walk the override rules last.
|
|
|
|
if (mOverrideRuleProcessors)
|
|
|
|
mOverrideRuleProcessors->EnumerateForwards(aFunc, aData);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
void StyleSetImpl::EnsureRuleWalker(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
if (mRuleWalker)
|
|
|
|
return;
|
|
|
|
|
2001-10-24 04:01:09 +04:00
|
|
|
nsRuleNode::CreateRootNode(aPresContext, &mRuleTree);
|
|
|
|
mRuleWalker = new nsRuleWalker(mRuleTree);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsIStyleContext* aParentContext)
|
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");
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_ASSERTION(aContent->IsContentOfType(nsIContent::eELEMENT),
|
|
|
|
"content must be element");
|
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();
|
2001-11-06 13:04:05 +03:00
|
|
|
if (mAgentRuleProcessors ||
|
|
|
|
mUserRuleProcessors ||
|
|
|
|
mDocRuleProcessors ||
|
|
|
|
mOverrideRuleProcessors) {
|
2001-06-01 02:19:43 +04:00
|
|
|
EnsureRuleWalker(aPresContext);
|
|
|
|
nsCOMPtr<nsIAtom> medium;
|
|
|
|
aPresContext->GetMedium(getter_AddRefs(medium));
|
2001-11-11 02:51:45 +03:00
|
|
|
RulesMatchingData data(aPresContext, medium, aContent, mRuleWalker);
|
|
|
|
FileRules(EnumRulesMatching, &data);
|
2002-03-31 20:59:00 +04:00
|
|
|
result = GetContext(aPresContext, aParentContext, nsnull);
|
2001-06-01 02:19:43 +04:00
|
|
|
|
|
|
|
// Now reset the walker back to the root of the tree.
|
|
|
|
mRuleWalker->Reset();
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-30 09:02:05 +03:00
|
|
|
nsIStyleContext* StyleSetImpl::ResolveStyleForNonElement(
|
|
|
|
nsIPresContext* aPresContext,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsIStyleContext* aParentContext)
|
2001-10-30 09:02:05 +03:00
|
|
|
{
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ResolveStyleForNonElement(), this=%p\n", this));
|
|
|
|
STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION);
|
|
|
|
|
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
|
|
|
NS_ASSERTION(aPresContext, "must have pres context");
|
|
|
|
|
|
|
|
if (aPresContext) {
|
|
|
|
GatherRuleProcessors();
|
2001-11-06 13:04:05 +03:00
|
|
|
if (mAgentRuleProcessors ||
|
|
|
|
mUserRuleProcessors ||
|
|
|
|
mDocRuleProcessors ||
|
2001-10-30 09:02:05 +03:00
|
|
|
mOverrideRuleProcessors) {
|
|
|
|
EnsureRuleWalker(aPresContext);
|
2002-03-27 05:38:13 +03:00
|
|
|
result = GetContext(aPresContext, aParentContext,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsHTMLAtoms::mozNonElementPseudo);
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_ASSERTION(mRuleWalker->AtRoot(), "rule walker must be at root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ResolveStyleForNonElement(), this=%p\n", this));
|
|
|
|
STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
struct PseudoRulesMatchingData : public PseudoRuleProcessorData {
|
1999-06-15 10:15:51 +04:00
|
|
|
PseudoRulesMatchingData(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
2001-02-16 00:24:47 +03:00
|
|
|
nsICSSPseudoComparator* aComparator,
|
2001-11-11 02:51:45 +03:00
|
|
|
nsRuleWalker* aRuleWalker)
|
|
|
|
: PseudoRuleProcessorData(aPresContext, aParentContent, aPseudoTag, aComparator,
|
|
|
|
aRuleWalker),
|
|
|
|
mMedium(aMedium)
|
1999-06-15 10:15:51 +04:00
|
|
|
{
|
|
|
|
}
|
2001-02-16 00:24:47 +03:00
|
|
|
nsIAtom* mMedium;
|
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
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
processor->RulesMatching(data, data->mMedium);
|
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
|
|
|
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");
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_ASSERTION(!aParentContent ||
|
|
|
|
aParentContent->IsContentOfType(nsIContent::eELEMENT),
|
|
|
|
"content (if non-null) must be element");
|
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();
|
2001-11-06 13:04:05 +03:00
|
|
|
if (mAgentRuleProcessors ||
|
|
|
|
mUserRuleProcessors ||
|
|
|
|
mDocRuleProcessors ||
|
|
|
|
mOverrideRuleProcessors) {
|
2001-06-01 02:19:43 +04:00
|
|
|
nsCOMPtr<nsIAtom> medium;
|
|
|
|
aPresContext->GetMedium(getter_AddRefs(medium));
|
|
|
|
EnsureRuleWalker(aPresContext);
|
|
|
|
PseudoRulesMatchingData data(aPresContext, medium, aParentContent,
|
2001-11-11 02:51:45 +03:00
|
|
|
aPseudoTag, aComparator, mRuleWalker);
|
|
|
|
FileRules(EnumPseudoRulesMatching, &data);
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2002-03-31 20:59:00 +04:00
|
|
|
result = GetContext(aPresContext, aParentContext, aPseudoTag);
|
2001-06-01 02:19:43 +04:00
|
|
|
|
|
|
|
// Now reset the walker back to the root of the tree.
|
|
|
|
mRuleWalker->Reset();
|
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,
|
2002-03-31 20:59:00 +04:00
|
|
|
nsIStyleContext* aParentContext)
|
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");
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_ASSERTION(!aParentContent ||
|
|
|
|
aParentContent->IsContentOfType(nsIContent::eELEMENT),
|
|
|
|
"content (if non-null) must be element");
|
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();
|
2001-11-06 13:04:05 +03:00
|
|
|
if (mAgentRuleProcessors ||
|
|
|
|
mUserRuleProcessors ||
|
|
|
|
mDocRuleProcessors ||
|
|
|
|
mOverrideRuleProcessors) {
|
2001-06-01 02:19:43 +04:00
|
|
|
nsCOMPtr<nsIAtom> medium;
|
|
|
|
aPresContext->GetMedium(getter_AddRefs(medium));
|
|
|
|
EnsureRuleWalker(aPresContext);
|
|
|
|
PseudoRulesMatchingData data(aPresContext, medium, aParentContent,
|
2001-11-11 02:51:45 +03:00
|
|
|
aPseudoTag, nsnull, mRuleWalker);
|
|
|
|
FileRules(EnumPseudoRulesMatching, &data);
|
2001-11-06 13:04:05 +03:00
|
|
|
|
2001-10-24 04:01:09 +04:00
|
|
|
if (!mRuleWalker->AtRoot())
|
2002-03-31 20:59:00 +04:00
|
|
|
result = GetContext(aPresContext, aParentContext, aPseudoTag);
|
2001-06-01 02:19:43 +04:00
|
|
|
|
|
|
|
// Now reset the walker back to the root of the tree.
|
|
|
|
mRuleWalker->Reset();
|
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;
|
|
|
|
}
|
|
|
|
|
2002-04-05 12:05:33 +04:00
|
|
|
PRBool PR_CALLBACK DeleteRuleNodeLists(nsHashKey* aKey, void* aData, void* aClosure)
|
|
|
|
{
|
|
|
|
nsRuleNodeList* ruleNodeList = (nsRuleNodeList*)aData;
|
|
|
|
ruleNodeList->Destroy();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::Shutdown()
|
|
|
|
{
|
2002-04-05 12:05:33 +04:00
|
|
|
mRuleMappings.Enumerate(DeleteRuleNodeLists);
|
|
|
|
mRuleMappings.Reset();
|
|
|
|
|
2001-10-24 04:01:09 +04:00
|
|
|
delete mRuleWalker;
|
2001-10-25 04:19:21 +04:00
|
|
|
if (mRuleTree)
|
|
|
|
{
|
|
|
|
mRuleTree->Destroy();
|
|
|
|
mRuleTree = nsnull;
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2001-10-24 04:01:09 +04:00
|
|
|
StyleSetImpl::GetRuleTree(nsRuleNode** aResult)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
|
|
|
*aResult = mRuleTree;
|
2001-10-24 04:01:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-05 12:05:33 +04:00
|
|
|
nsresult
|
|
|
|
StyleSetImpl::AddRuleNodeMapping(nsRuleNode* aRuleNode)
|
|
|
|
{
|
|
|
|
nsVoidKey key(aRuleNode->Rule());
|
|
|
|
nsRuleNodeList* ruleList =
|
|
|
|
new (aRuleNode->PresContext()) nsRuleNodeList(aRuleNode,
|
|
|
|
NS_STATIC_CAST(nsRuleNodeList*, mRuleMappings.Get(&key)));
|
|
|
|
mRuleMappings.Put(&key, ruleList);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
nsresult
|
|
|
|
StyleSetImpl::BeginRuleTreeReconstruct()
|
|
|
|
{
|
|
|
|
delete mRuleWalker;
|
|
|
|
mRuleWalker = nsnull;
|
|
|
|
mOldRuleTree = mRuleTree;
|
|
|
|
mRuleTree = nsnull;
|
2002-04-05 12:05:33 +04:00
|
|
|
mRuleMappings.Enumerate(DeleteRuleNodeLists);
|
|
|
|
mRuleMappings.Reset();
|
2001-12-18 01:51:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
StyleSetImpl::EndRuleTreeReconstruct()
|
|
|
|
{
|
|
|
|
if (mOldRuleTree) {
|
|
|
|
mOldRuleTree->Destroy();
|
|
|
|
mOldRuleTree = nsnull;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-24 04:01:09 +04:00
|
|
|
nsresult
|
|
|
|
StyleSetImpl::ClearCachedDataInRuleTree(nsIStyleRule* aInlineStyleRule)
|
|
|
|
{
|
|
|
|
if (mRuleTree)
|
|
|
|
mRuleTree->ClearCachedDataInSubtree(aInlineStyleRule);
|
2001-06-01 02:19:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-04 03:35:41 +04:00
|
|
|
|
2001-07-25 10:33:06 +04:00
|
|
|
nsresult
|
|
|
|
StyleSetImpl::ClearStyleData(nsIPresContext* aPresContext, nsIStyleRule* aRule, nsIStyleContext* aContext)
|
|
|
|
{
|
|
|
|
// XXXdwh. If we're willing to *really* optimize this
|
|
|
|
// invalidation, we could only invalidate the struct data
|
|
|
|
// that actually changed. For example, if someone changes
|
|
|
|
// style.left, we really only need to blow away cached
|
|
|
|
// data in the position struct.
|
|
|
|
if (aContext) {
|
2002-04-05 12:05:33 +04:00
|
|
|
// |aRule| should never be null, but we'll sanity check it just in case.
|
|
|
|
if (aRule) {
|
|
|
|
// Obtain our rule node list and clear out the cached data in all rule nodes
|
|
|
|
// that correspond to this rule. See bug 99344 for more details as to how
|
|
|
|
// inline style rules can end up with multiple rule nodes in a rule tree.
|
|
|
|
nsVoidKey key(aRule);
|
|
|
|
nsRuleNodeList* ruleList = NS_STATIC_CAST(nsRuleNodeList*, mRuleMappings.Get(&key));
|
|
|
|
for ( ; ruleList; ruleList = ruleList->mNext)
|
|
|
|
ruleList->mRuleNode->ClearCachedData(aRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXdwh I'm just being paranoid here. Also clear out the data starting at the style
|
|
|
|
// context's rule node. This really should always be done in the for loop above,
|
|
|
|
// but I'm going to leave this here just in case (for now).
|
2001-10-24 04:01:09 +04:00
|
|
|
nsRuleNode* ruleNode;
|
|
|
|
aContext->GetRuleNode(&ruleNode);
|
2001-07-25 10:33:06 +04:00
|
|
|
ruleNode->ClearCachedData(aRule);
|
|
|
|
|
2001-12-09 01:46:21 +03:00
|
|
|
// XXX We need to clear style data here in case there's a style context
|
|
|
|
// that inherits a struct from its parent where the parent uses data
|
|
|
|
// that's cached on the rule node. Otherwise we could crash while
|
|
|
|
// doing checks comparing old data to new data during reresolution.
|
|
|
|
// This could make some of those checks incorrect.
|
|
|
|
aContext->ClearStyleData(aPresContext, nsnull);
|
2001-07-25 10:33:06 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// XXXdwh This is not terribly fast, but fortunately this case is rare (and often a full tree
|
|
|
|
// invalidation anyway). Improving performance here would involve a footprint
|
|
|
|
// increase. Mappings from rule nodes to their associated style contexts as well as
|
|
|
|
// mappings from rules to their associated rule nodes would enable us to avoid the two
|
|
|
|
// tree walks that occur here.
|
|
|
|
|
|
|
|
// Crawl the entire rule tree and blow away all data for rule nodes (and their descendants)
|
|
|
|
// that have the given rule.
|
|
|
|
if (mRuleTree)
|
|
|
|
mRuleTree->ClearCachedDataInSubtree(aRule);
|
|
|
|
|
|
|
|
// We need to crawl the entire style context tree, and for each style context we need
|
|
|
|
// to see if the specified rule is matched. If so, that context and all its descendant
|
|
|
|
// contexts must have their data wiped.
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
nsIFrame* rootFrame;
|
|
|
|
shell->GetRootFrame(&rootFrame);
|
|
|
|
if (rootFrame) {
|
|
|
|
nsCOMPtr<nsIStyleContext> rootContext;
|
|
|
|
rootFrame->GetStyleContext(getter_AddRefs(rootContext));
|
|
|
|
if (rootContext)
|
|
|
|
rootContext->ClearStyleData(aPresContext, aRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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) {
|
2002-10-09 05:46:15 +04:00
|
|
|
nsCOMPtr<nsIStyleContext> oldParent = aStyleContext->GetParent();
|
1999-09-04 03:35:41 +04:00
|
|
|
|
|
|
|
if (oldParent == aNewParentContext) {
|
|
|
|
result = NS_OK;
|
|
|
|
NS_ADDREF(aStyleContext); // for return
|
|
|
|
*aNewStyleContext = aStyleContext;
|
|
|
|
}
|
|
|
|
else { // really a new parent
|
|
|
|
nsIStyleContext* newChild = nsnull;
|
2002-10-09 05:46:15 +04:00
|
|
|
nsCOMPtr<nsIAtom> pseudoTag;
|
|
|
|
aStyleContext->GetPseudoType(*getter_AddRefs(pseudoTag));
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2001-10-24 04:01:09 +04:00
|
|
|
nsRuleNode* ruleNode;
|
|
|
|
aStyleContext->GetRuleNode(&ruleNode);
|
1999-09-04 03:35:41 +04:00
|
|
|
if (aNewParentContext) {
|
2001-06-01 02:19:43 +04:00
|
|
|
result = aNewParentContext->FindChildWithRules(pseudoTag, ruleNode, newChild);
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
|
|
|
if (newChild) { // new parent already has one
|
|
|
|
*aNewStyleContext = newChild;
|
|
|
|
}
|
|
|
|
else { // need to make one in the new parent
|
|
|
|
result = NS_NewStyleContext(aNewStyleContext, aNewParentContext, pseudoTag,
|
2001-06-01 02:19:43 +04:00
|
|
|
ruleNode, aPresContext);
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
struct StatefulData : public StateRuleProcessorData {
|
2002-04-11 07:49:30 +04:00
|
|
|
StatefulData(nsIPresContext* aPresContext, nsIAtom* aMedium,
|
|
|
|
nsIContent* aContent, PRInt32 aStateMask)
|
|
|
|
: StateRuleProcessorData(aPresContext, aContent, aStateMask),
|
1999-10-08 07:09:31 +04:00
|
|
|
mMedium(aMedium),
|
1999-04-20 04:02:22 +04:00
|
|
|
mStateful(PR_FALSE)
|
|
|
|
{}
|
1999-10-08 07:09:31 +04:00
|
|
|
nsIAtom* mMedium;
|
1999-04-20 04:02:22 +04:00
|
|
|
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;
|
2002-04-16 02:28:54 +04:00
|
|
|
PRBool hasStateful;
|
|
|
|
processor->HasStateDependentStyle(data, data->mMedium, &hasStateful);
|
|
|
|
if (hasStateful) {
|
|
|
|
data->mStateful = PR_TRUE;
|
|
|
|
// Stop iteration. Note that StyleSetImpl::WalkRuleProcessors uses
|
|
|
|
// this to stop its own iteration in some cases, but not all (the
|
|
|
|
// style rule supplier case). Since this optimization is only for
|
|
|
|
// the case where we have a lot more work to do, it's not worth the
|
|
|
|
// code needed to make the stopping perfect.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-04-20 04:02:22 +04:00
|
|
|
return PR_TRUE; // continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::HasStateDependentStyle(nsIPresContext* aPresContext,
|
2002-04-11 07:49:30 +04:00
|
|
|
nsIContent* aContent,
|
|
|
|
PRInt32 aStateMask,
|
|
|
|
PRBool* aResult)
|
1999-04-20 04:02:22 +04:00
|
|
|
{
|
2000-08-12 10:28:02 +04:00
|
|
|
GatherRuleProcessors();
|
2001-10-30 09:02:05 +03:00
|
|
|
|
|
|
|
if (aContent->IsContentOfType(nsIContent::eELEMENT) &&
|
2001-11-06 13:04:05 +03:00
|
|
|
(mAgentRuleProcessors ||
|
|
|
|
mUserRuleProcessors ||
|
|
|
|
mDocRuleProcessors ||
|
2001-10-30 09:02:05 +03:00
|
|
|
mOverrideRuleProcessors)) {
|
1999-10-08 07:09:31 +04:00
|
|
|
nsIAtom* medium = nsnull;
|
|
|
|
aPresContext->GetMedium(&medium);
|
2002-04-11 07:49:30 +04:00
|
|
|
StatefulData data(aPresContext, medium, aContent, aStateMask);
|
2001-11-11 02:51:45 +03:00
|
|
|
WalkRuleProcessors(SheetHasStatefulStyle, &data);
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IF_RELEASE(medium);
|
2002-04-11 07:49:30 +04:00
|
|
|
*aResult = data.mStateful;
|
|
|
|
} else {
|
|
|
|
*aResult = PR_FALSE;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
2002-04-11 07:49:30 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
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,
|
2002-01-15 01:05:26 +03:00
|
|
|
aChild, aIndexInContainer,
|
|
|
|
nsnull, PR_FALSE);
|
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,
|
2002-01-15 01:05:26 +03:00
|
|
|
aChild, aIndexInContainer, PR_FALSE);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
|
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,
|
2002-03-07 06:34:29 +03:00
|
|
|
nsIContent* aContent2,
|
2002-04-11 07:49:30 +04:00
|
|
|
PRInt32 aStateMask)
|
1999-02-27 10:11:04 +03:00
|
|
|
{
|
2002-04-11 07:49:30 +04:00
|
|
|
return mFrameConstructor->ContentStatesChanged(aPresContext, aContent1,
|
|
|
|
aContent2, aStateMask);
|
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,
|
2001-08-25 06:01:08 +04:00
|
|
|
PRInt32 aModType,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint aHint)
|
1998-09-30 03:47:03 +04:00
|
|
|
{
|
|
|
|
return mFrameConstructor->AttributeChanged(aPresContext, aContent,
|
2001-08-25 06:01:08 +04:00
|
|
|
aNameSpaceID, aAttribute, aModType, 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,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint aHint)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-09-13 00:19:41 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StyleSetImpl::GetInsertionPoint(nsIPresShell* aPresShell,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIContent* aChildContent,
|
|
|
|
nsIFrame** aInsertionPoint)
|
|
|
|
{
|
|
|
|
return mFrameConstructor->GetInsertionPoint(aPresShell, aParentFrame,
|
|
|
|
aChildContent, aInsertionPoint);
|
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
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);
|
|
|
|
}
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
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);
|
2001-11-06 13:04:05 +03:00
|
|
|
// List(out, aIndent, mUserSheets);
|
|
|
|
// List(out, aIndent, mAgentSheets);
|
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
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
1998-05-19 01:05:52 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-10-20 00:59:33 +04:00
|
|
|
NS_EXPORT nsresult
|
1998-04-14 00:24:54 +04:00
|
|
|
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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 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;
|
2001-11-11 02:51:45 +03:00
|
|
|
nsresult res =
|
|
|
|
sheet->AttributeAffectsStyle(pair->attribute, pair->content, affects);
|
|
|
|
if (NS_FAILED(res) || affects)
|
2000-05-16 06:43:33 +04:00
|
|
|
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)) ||
|
2001-11-06 13:04:05 +03:00
|
|
|
(mUserSheets && !mUserSheets->EnumerateForwards(EnumAffectsStyle,
|
|
|
|
&pair)) ||
|
|
|
|
(mAgentSheets && !mAgentSheets->EnumerateForwards(EnumAffectsStyle,
|
2001-03-29 05:30:03 +04:00
|
|
|
&pair))) {
|
|
|
|
aAffects = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
aAffects = PR_FALSE;
|
|
|
|
}
|
2000-05-16 06:43:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
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):
|
2001-11-06 13:04:05 +03:00
|
|
|
* 1) Override Sheets, DocSheets, UserSheets, AgentSheets, RuleProcessors, Recycler
|
2000-03-31 11:08:36 +04:00
|
|
|
* 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);
|
|
|
|
}
|
2001-11-06 13:04:05 +03:00
|
|
|
if (mUserSheets && uniqueItems->AddItem(mUserSheets)){
|
|
|
|
aSize += sizeof(*mUserSheets);
|
2000-03-31 11:08:36 +04:00
|
|
|
}
|
2001-11-06 13:04:05 +03:00
|
|
|
if (mAgentSheets && uniqueItems->AddItem(mAgentSheets)){
|
|
|
|
aSize += sizeof(*mAgentSheets);
|
|
|
|
}
|
|
|
|
if (mAgentRuleProcessors && uniqueItems->AddItem(mAgentRuleProcessors)){
|
|
|
|
aSize += sizeof(*mAgentRuleProcessors);
|
|
|
|
}
|
|
|
|
if (mUserRuleProcessors && uniqueItems->AddItem(mUserRuleProcessors)){
|
|
|
|
aSize += sizeof(*mUserRuleProcessors);
|
2000-08-12 10:28:02 +04:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:04:05 +03:00
|
|
|
numSheets = GetNumberOfUserStyleSheets();
|
|
|
|
for(curSheet=0; curSheet < numSheets; curSheet++){
|
|
|
|
nsIStyleSheet* pSheet = GetUserStyleSheetAt(curSheet);
|
|
|
|
if(pSheet){
|
|
|
|
localSize=0;
|
|
|
|
pSheet->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
numSheets = GetNumberOfAgentStyleSheets();
|
2000-03-31 11:08:36 +04:00
|
|
|
for(curSheet=0; curSheet < numSheets; curSheet++){
|
2001-11-06 13:04:05 +03:00
|
|
|
nsIStyleSheet* pSheet = GetAgentStyleSheetAt(curSheet);
|
2000-03-31 11:08:36 +04:00
|
|
|
if(pSheet){
|
|
|
|
localSize=0;
|
|
|
|
pSheet->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pSheet);
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
// rule processors
|
|
|
|
PRUint32 numRuleProcessors,curRuleProcessor;
|
2001-11-06 13:04:05 +03:00
|
|
|
if(mAgentRuleProcessors){
|
|
|
|
mAgentRuleProcessors->Count(&numRuleProcessors);
|
|
|
|
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
|
|
|
|
nsIStyleRuleProcessor* processor =
|
|
|
|
(nsIStyleRuleProcessor* )mAgentRuleProcessors->ElementAt(curRuleProcessor);
|
|
|
|
if(processor){
|
|
|
|
localSize=0;
|
|
|
|
processor->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(processor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(mUserRuleProcessors){
|
|
|
|
mUserRuleProcessors->Count(&numRuleProcessors);
|
2000-08-12 10:28:02 +04:00
|
|
|
for(curRuleProcessor=0; curRuleProcessor < numRuleProcessors; curRuleProcessor++){
|
|
|
|
nsIStyleRuleProcessor* processor =
|
2001-11-06 13:04:05 +03:00
|
|
|
(nsIStyleRuleProcessor* )mUserRuleProcessors->ElementAt(curRuleProcessor);
|
2000-08-12 10:28:02 +04:00
|
|
|
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
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|