2004-01-08 01:30:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2004-01-08 01:30:53 +03:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
2004-01-08 01:30:53 +03:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2004-01-08 01:30:53 +03:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
|
|
|
* Brian Ryner <bryner@brianryner.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of 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"),
|
2004-01-08 01:30:53 +03:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2004-01-08 01:30:53 +03:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2004-01-08 01:30:53 +03:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/*
|
|
|
|
* the container for the style sheets that apply to a presentation, and
|
|
|
|
* the internal API that the style system exposes for creating (and
|
|
|
|
* potentially re-creating) style contexts
|
|
|
|
*/
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
#ifndef nsStyleSet_h_
|
|
|
|
#define nsStyleSet_h_
|
|
|
|
|
|
|
|
#include "nsIStyleRuleProcessor.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsIStyleRuleSupplier.h"
|
|
|
|
#include "nsRuleNode.h"
|
|
|
|
|
|
|
|
class nsIURI;
|
|
|
|
|
2004-01-08 22:23:12 +03:00
|
|
|
// The style set object is created by the document viewer and ownership is
|
|
|
|
// then handed off to the PresShell. Only the PresShell should delete a
|
|
|
|
// style set.
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
class nsStyleSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsStyleSet();
|
|
|
|
|
|
|
|
// Initialize the object. You must check the return code and not use
|
|
|
|
// the nsStyleSet if Init() fails.
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult Init(nsPresContext *aPresContext);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// For getting the cached default data in case we hit out-of-memory.
|
|
|
|
// To be used only by nsRuleNode.
|
|
|
|
nsCachedStyleData* DefaultStyleData() { return &mDefaultStyleData; }
|
|
|
|
|
|
|
|
// clear out all of the computed style data
|
2004-08-01 03:15:21 +04:00
|
|
|
void ClearStyleData(nsPresContext *aPresContext);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// enable / disable the Quirk style sheet
|
|
|
|
void EnableQuirkStyleSheet(PRBool aEnable);
|
|
|
|
|
|
|
|
// get a style context for a non-pseudo frame.
|
|
|
|
already_AddRefed<nsStyleContext>
|
2004-01-28 03:18:22 +03:00
|
|
|
ResolveStyleFor(nsIContent* aContent, nsStyleContext* aParentContext);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
2005-09-12 03:17:28 +04:00
|
|
|
// Get a style context for a non-element (which no rules will match),
|
|
|
|
// such as text nodes, placeholder frames, and the nsFirstLetterFrame
|
|
|
|
// for everything after the first letter.
|
|
|
|
//
|
|
|
|
// Perhaps this should go away and we shouldn't even create style
|
2004-01-08 01:30:53 +03:00
|
|
|
// contexts for such content nodes. However, not doing any rule
|
|
|
|
// matching for them is a first step.
|
|
|
|
already_AddRefed<nsStyleContext>
|
2004-01-28 03:18:22 +03:00
|
|
|
ResolveStyleForNonElement(nsStyleContext* aParentContext);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// get a style context for a pseudo-element (i.e.,
|
2005-09-12 03:17:28 +04:00
|
|
|
// |aPseudoTag == nsCOMPtr<nsIAtom>(do_GetAtom(":first-line"))|, in
|
|
|
|
// which case aParentContent must be non-null, or an anonymous box, in
|
|
|
|
// which case it may be null or non-null.
|
2004-01-08 01:30:53 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2004-01-28 03:18:22 +03:00
|
|
|
ResolvePseudoStyleFor(nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
nsICSSPseudoComparator* aComparator = nsnull);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
2005-09-12 08:28:16 +04:00
|
|
|
// This functions just like ResolvePseudoStyleFor except that it will
|
2004-01-08 01:30:53 +03:00
|
|
|
// return nsnull if there are no explicit style rules for that
|
2005-09-12 03:17:28 +04:00
|
|
|
// pseudo element. It should be used only for pseudo-elements.
|
2004-01-08 01:30:53 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2004-01-28 03:18:22 +03:00
|
|
|
ProbePseudoStyleFor(nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsStyleContext* aParentContext);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// Begin ignoring style context destruction, to avoid lots of unnecessary
|
|
|
|
// work on document teardown.
|
2004-08-01 03:15:21 +04:00
|
|
|
void BeginShutdown(nsPresContext* aPresContext);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// Free all of the data associated with this style set.
|
2004-08-01 03:15:21 +04:00
|
|
|
void Shutdown(nsPresContext* aPresContext);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// Notification that a style context is being destroyed.
|
2004-08-01 03:15:21 +04:00
|
|
|
void NotifyStyleContextDestroyed(nsPresContext* aPresContext,
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleContext* aStyleContext);
|
|
|
|
|
|
|
|
// Get a new style context that lives in a different parent
|
|
|
|
// The new context will be the same as the old if the new parent is the
|
|
|
|
// same as the old parent.
|
|
|
|
already_AddRefed<nsStyleContext>
|
2004-08-01 03:15:21 +04:00
|
|
|
ReParentStyleContext(nsPresContext* aPresContext,
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
nsStyleContext* aNewParentContext);
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
2004-08-01 03:15:21 +04:00
|
|
|
nsReStyleHint HasStateDependentStyle(nsPresContext* aPresContext,
|
2004-01-14 04:36:35 +03:00
|
|
|
nsIContent* aContent,
|
|
|
|
PRInt32 aStateMask);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// Test if style is dependent on the presence of an attribute.
|
2004-08-01 03:15:21 +04:00
|
|
|
nsReStyleHint HasAttributeDependentStyle(nsPresContext* aPresContext,
|
2004-01-14 04:36:35 +03:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// APIs for registering objects that can supply additional
|
|
|
|
// rules during processing.
|
|
|
|
void SetStyleRuleSupplier(nsIStyleRuleSupplier* aSupplier)
|
|
|
|
{
|
|
|
|
mStyleRuleSupplier = aSupplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleRuleSupplier* GetStyleRuleSupplier() const
|
|
|
|
{
|
|
|
|
return mStyleRuleSupplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free global data at module shutdown
|
|
|
|
static void FreeGlobals() { NS_IF_RELEASE(gQuirkURI); }
|
|
|
|
|
2005-08-20 05:24:00 +04:00
|
|
|
// The "origins" of the CSS cascade, from lowest precedence to
|
|
|
|
// highest (for non-!important rules).
|
2004-01-08 01:30:53 +03:00
|
|
|
enum sheetType {
|
2004-07-28 11:08:41 +04:00
|
|
|
eAgentSheet, // CSS
|
2004-05-05 04:30:57 +04:00
|
|
|
ePresHintSheet,
|
2004-07-28 11:08:41 +04:00
|
|
|
eUserSheet, // CSS
|
2004-07-16 00:30:30 +04:00
|
|
|
eHTMLPresHintSheet,
|
2004-07-28 11:08:41 +04:00
|
|
|
eDocSheet, // CSS
|
|
|
|
eStyleAttrSheet,
|
|
|
|
eOverrideSheet, // CSS
|
2004-01-08 01:30:53 +03:00
|
|
|
eSheetTypeCount
|
2004-07-28 11:08:41 +04:00
|
|
|
// be sure to keep the number of bits in |mDirty| below updated when
|
|
|
|
// changing the number of sheet types
|
2004-01-08 01:30:53 +03:00
|
|
|
};
|
|
|
|
|
2005-08-20 05:24:00 +04:00
|
|
|
// APIs to manipulate the style sheet lists. The sheets in each
|
|
|
|
// list are stored with the most significant sheet last.
|
2004-01-08 01:30:53 +03:00
|
|
|
nsresult AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
|
|
|
|
nsresult PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
|
|
|
|
nsresult RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
|
|
|
|
nsresult ReplaceSheets(sheetType aType,
|
|
|
|
const nsCOMArray<nsIStyleSheet> &aNewSheets);
|
|
|
|
|
2004-08-05 15:38:42 +04:00
|
|
|
//Enable/Disable entire author style level (Doc & PresHint levels)
|
|
|
|
PRBool GetAuthorStyleDisabled();
|
|
|
|
nsresult SetAuthorStyleDisabled(PRBool aStyleDisabled);
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
PRInt32 SheetCount(sheetType aType) const {
|
|
|
|
return mSheets[aType].Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleSheet* StyleSheetAt(sheetType aType, PRInt32 aIndex) const {
|
|
|
|
return mSheets[aType].ObjectAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument);
|
|
|
|
|
|
|
|
void BeginUpdate();
|
|
|
|
nsresult EndUpdate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Not to be implemented
|
|
|
|
nsStyleSet(const nsStyleSet& aCopy);
|
|
|
|
nsStyleSet& operator=(const nsStyleSet& aCopy);
|
|
|
|
|
|
|
|
// Returns false on out-of-memory.
|
2004-08-01 03:15:21 +04:00
|
|
|
PRBool BuildDefaultStyleData(nsPresContext* aPresContext);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// Update the rule processor list after a change to the style sheet list.
|
2004-07-28 11:08:41 +04:00
|
|
|
nsresult GatherRuleProcessors(sheetType aType);
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
void AddImportantRules(nsRuleNode* aCurrLevelNode,
|
|
|
|
nsRuleNode* aLastPrevLevelNode);
|
|
|
|
|
2004-07-16 00:30:30 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Just like AddImportantRules except it doesn't actually add anything; it
|
|
|
|
// just asserts that there are no important rules between aCurrLevelNode and
|
|
|
|
// aLastPrevLevelNode.
|
|
|
|
void AssertNoImportantRules(nsRuleNode* aCurrLevelNode,
|
|
|
|
nsRuleNode* aLastPrevLevelNode);
|
|
|
|
|
|
|
|
// Just like AddImportantRules except it doesn't actually add anything; it
|
|
|
|
// just asserts that there are no CSS rules between aCurrLevelNode and
|
|
|
|
// aLastPrevLevelNode. Mostly useful for the preshint levels.
|
|
|
|
void AssertNoCSSRules(nsRuleNode* aCurrLevelNode,
|
|
|
|
nsRuleNode* aLastPrevLevelNode);
|
|
|
|
#endif
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
// Enumerate the rules in a way that cares about the order of the
|
|
|
|
// rules.
|
|
|
|
void FileRules(nsIStyleRuleProcessor::EnumFunc 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(nsIStyleRuleProcessor::EnumFunc aFunc,
|
|
|
|
RuleProcessorData* aData);
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
already_AddRefed<nsStyleContext> GetContext(nsPresContext* aPresContext,
|
2004-01-08 01:30:53 +03:00
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag);
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* PresContext() { return mRuleTree->GetPresContext(); }
|
2004-01-28 03:18:22 +03:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
static nsIURI *gQuirkURI;
|
|
|
|
|
|
|
|
nsCOMArray<nsIStyleSheet> mSheets[eSheetTypeCount];
|
|
|
|
|
2004-07-28 11:08:41 +04:00
|
|
|
nsCOMPtr<nsIStyleRuleProcessor> mRuleProcessors[eSheetTypeCount];
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
// cached instance for enabling/disabling
|
|
|
|
nsCOMPtr<nsIStyleSheet> mQuirkStyleSheet;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStyleRuleSupplier> mStyleRuleSupplier;
|
|
|
|
|
|
|
|
// To be used only in case of emergency, such as being out of memory
|
|
|
|
// or operating on a deleted rule node. The latter should never
|
|
|
|
// happen, of course.
|
|
|
|
nsCachedStyleData mDefaultStyleData;
|
|
|
|
|
|
|
|
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.
|
|
|
|
nsRuleWalker* mRuleWalker; // This is an instance of a rule walker that can
|
|
|
|
// be used to navigate through our tree.
|
|
|
|
|
|
|
|
PRInt32 mDestroyedCount; // used to batch style context GC
|
|
|
|
nsVoidArray mRoots; // style contexts with no parent
|
|
|
|
|
2004-01-08 22:23:12 +03:00
|
|
|
PRUint16 mBatching;
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
unsigned mInShutdown : 1;
|
2004-08-05 15:38:42 +04:00
|
|
|
unsigned mAuthorStyleDisabled: 1;
|
2004-01-08 22:23:12 +03:00
|
|
|
unsigned mDirty : 7; // one dirty bit is used per sheet type
|
2004-01-08 01:30:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|