CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / layout / style / nsCSSRuleProcessor.h
blobde0f280d31f31ec9d4e559cb80045d6d742b898e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:tabstop=2:expandtab:shiftwidth=2:
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * L. David Baron <dbaron@dbaron.org>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
41 * style rule processor for CSS style sheets, responsible for selector
42 * matching and cascading
45 #ifndef nsCSSRuleProcessor_h_
46 #define nsCSSRuleProcessor_h_
48 #include "nsIStyleRuleProcessor.h"
49 #include "nsCSSStyleSheet.h"
50 #include "nsTArray.h"
51 #include "nsAutoPtr.h"
52 #include "nsCSSRules.h"
54 struct RuleCascadeData;
55 struct nsCSSSelectorList;
56 struct CascadeEnumData;
58 /**
59 * The CSS style rule processor provides a mechanism for sibling style
60 * sheets to combine their rule processing in order to allow proper
61 * cascading to happen.
63 * CSS style rule processors keep a live reference on all style sheets
64 * bound to them. The CSS style sheets keep a weak reference to all the
65 * processors that they are bound to (many to many). The CSS style sheet
66 * is told when the rule processor is going away (via DropRuleProcessor).
69 class nsCSSRuleProcessor: public nsIStyleRuleProcessor {
70 public:
71 typedef nsTArray<nsRefPtr<nsCSSStyleSheet> > sheet_array_type;
73 nsCSSRuleProcessor(const sheet_array_type& aSheets, PRUint8 aSheetType);
74 virtual ~nsCSSRuleProcessor();
76 NS_DECL_ISUPPORTS
78 public:
79 nsresult ClearRuleCascades();
81 static nsresult Startup();
82 static void Shutdown();
83 static void FreeSystemMetrics();
84 static PRBool HasSystemMetric(nsIAtom* aMetric);
87 * Returns true if the given RuleProcessorData matches one of the
88 * selectors in aSelectorList. Note that this method will assume
89 * the matching is not for styling purposes. aSelectorList must not
90 * include any pseudo-element selectors. aSelectorList is allowed
91 * to be null; in this case PR_FALSE will be returned.
93 static PRBool SelectorListMatches(RuleProcessorData& aData,
94 nsCSSSelectorList* aSelectorList);
96 // nsIStyleRuleProcessor
97 virtual void RulesMatching(ElementRuleProcessorData* aData);
99 virtual void RulesMatching(PseudoElementRuleProcessorData* aData);
101 virtual void RulesMatching(AnonBoxRuleProcessorData* aData);
103 #ifdef MOZ_XUL
104 virtual void RulesMatching(XULTreeRuleProcessorData* aData);
105 #endif
107 virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData);
109 virtual PRBool HasDocumentStateDependentStyle(StateRuleProcessorData* aData);
111 virtual nsRestyleHint
112 HasAttributeDependentStyle(AttributeRuleProcessorData* aData);
114 virtual PRBool MediumFeaturesChanged(nsPresContext* aPresContext);
116 // Append all the currently-active font face rules to aArray. Return
117 // true for success and false for failure.
118 PRBool AppendFontFaceRules(nsPresContext* aPresContext,
119 nsTArray<nsFontFaceRuleContainer>& aArray);
121 #ifdef DEBUG
122 void AssertQuirksChangeOK() {
123 NS_ASSERTION(!mRuleCascades, "can't toggle quirks style sheet without "
124 "clearing rule cascades");
126 #endif
128 #ifdef XP_WIN
129 // Cached theme identifier for the moz-windows-theme media query.
130 static PRUint8 GetWindowsThemeIdentifier();
131 static void SetWindowsThemeIdentifier(PRUint8 aId) {
132 sWinThemeId = aId;
134 #endif
136 private:
137 static PRBool CascadeSheet(nsCSSStyleSheet* aSheet, CascadeEnumData* aData);
139 RuleCascadeData* GetRuleCascade(nsPresContext* aPresContext);
140 void RefreshRuleCascade(nsPresContext* aPresContext);
142 // The sheet order here is the same as in nsStyleSet::mSheets
143 sheet_array_type mSheets;
145 // active first, then cached (most recent first)
146 RuleCascadeData* mRuleCascades;
148 // The last pres context for which GetRuleCascades was called.
149 nsPresContext *mLastPresContext;
151 // type of stylesheet using this processor
152 PRUint8 mSheetType; // == nsStyleSet::sheetType
154 #ifdef XP_WIN
155 static PRUint8 sWinThemeId;
156 #endif
159 #endif /* nsCSSRuleProcessor_h_ */