Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | // vim:cindent:tabstop=2:expandtab:shiftwidth=2: |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * style rule processor for CSS style sheets, responsible for selector |
michael@0 | 9 | * matching and cascading |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | #ifndef nsCSSRuleProcessor_h_ |
michael@0 | 13 | #define nsCSSRuleProcessor_h_ |
michael@0 | 14 | |
michael@0 | 15 | #include "mozilla/Attributes.h" |
michael@0 | 16 | #include "mozilla/EventStates.h" |
michael@0 | 17 | #include "mozilla/MemoryReporting.h" |
michael@0 | 18 | #include "nsIStyleRuleProcessor.h" |
michael@0 | 19 | #include "nsCSSStyleSheet.h" |
michael@0 | 20 | #include "nsTArray.h" |
michael@0 | 21 | #include "nsAutoPtr.h" |
michael@0 | 22 | #include "nsRuleWalker.h" |
michael@0 | 23 | |
michael@0 | 24 | struct CascadeEnumData; |
michael@0 | 25 | struct nsCSSSelector; |
michael@0 | 26 | struct nsCSSSelectorList; |
michael@0 | 27 | struct RuleCascadeData; |
michael@0 | 28 | struct TreeMatchContext; |
michael@0 | 29 | class nsCSSKeyframesRule; |
michael@0 | 30 | class nsCSSPageRule; |
michael@0 | 31 | class nsCSSFontFeatureValuesRule; |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * The CSS style rule processor provides a mechanism for sibling style |
michael@0 | 35 | * sheets to combine their rule processing in order to allow proper |
michael@0 | 36 | * cascading to happen. |
michael@0 | 37 | * |
michael@0 | 38 | * CSS style rule processors keep a live reference on all style sheets |
michael@0 | 39 | * bound to them. The CSS style sheets keep a weak reference to all the |
michael@0 | 40 | * processors that they are bound to (many to many). The CSS style sheet |
michael@0 | 41 | * is told when the rule processor is going away (via DropRuleProcessor). |
michael@0 | 42 | */ |
michael@0 | 43 | |
michael@0 | 44 | class nsCSSRuleProcessor: public nsIStyleRuleProcessor { |
michael@0 | 45 | public: |
michael@0 | 46 | typedef nsTArray<nsRefPtr<nsCSSStyleSheet> > sheet_array_type; |
michael@0 | 47 | |
michael@0 | 48 | // aScopeElement must be non-null iff aSheetType is |
michael@0 | 49 | // nsStyleSet::eScopedDocSheet. |
michael@0 | 50 | nsCSSRuleProcessor(const sheet_array_type& aSheets, |
michael@0 | 51 | uint8_t aSheetType, |
michael@0 | 52 | mozilla::dom::Element* aScopeElement); |
michael@0 | 53 | virtual ~nsCSSRuleProcessor(); |
michael@0 | 54 | |
michael@0 | 55 | NS_DECL_ISUPPORTS |
michael@0 | 56 | |
michael@0 | 57 | public: |
michael@0 | 58 | nsresult ClearRuleCascades(); |
michael@0 | 59 | |
michael@0 | 60 | static nsresult Startup(); |
michael@0 | 61 | static void Shutdown(); |
michael@0 | 62 | static void FreeSystemMetrics(); |
michael@0 | 63 | static bool HasSystemMetric(nsIAtom* aMetric); |
michael@0 | 64 | |
michael@0 | 65 | /* |
michael@0 | 66 | * Returns true if the given aElement matches one of the |
michael@0 | 67 | * selectors in aSelectorList. Note that this method will assume |
michael@0 | 68 | * the given aElement is not a relevant link. aSelectorList must not |
michael@0 | 69 | * include any pseudo-element selectors. aSelectorList is allowed |
michael@0 | 70 | * to be null; in this case false will be returned. |
michael@0 | 71 | */ |
michael@0 | 72 | static bool SelectorListMatches(mozilla::dom::Element* aElement, |
michael@0 | 73 | TreeMatchContext& aTreeMatchContext, |
michael@0 | 74 | nsCSSSelectorList* aSelectorList); |
michael@0 | 75 | |
michael@0 | 76 | /* |
michael@0 | 77 | * Helper to get the content state for a content node. This may be |
michael@0 | 78 | * slightly adjusted from IntrinsicState(). |
michael@0 | 79 | */ |
michael@0 | 80 | static mozilla::EventStates GetContentState( |
michael@0 | 81 | mozilla::dom::Element* aElement, |
michael@0 | 82 | const TreeMatchContext& aTreeMatchContext); |
michael@0 | 83 | |
michael@0 | 84 | /* |
michael@0 | 85 | * Helper to get the content state for :visited handling for an element |
michael@0 | 86 | */ |
michael@0 | 87 | static mozilla::EventStates GetContentStateForVisitedHandling( |
michael@0 | 88 | mozilla::dom::Element* aElement, |
michael@0 | 89 | const TreeMatchContext& aTreeMatchContext, |
michael@0 | 90 | nsRuleWalker::VisitedHandlingType aVisitedHandling, |
michael@0 | 91 | bool aIsRelevantLink); |
michael@0 | 92 | |
michael@0 | 93 | /* |
michael@0 | 94 | * Helper to test whether a node is a link |
michael@0 | 95 | */ |
michael@0 | 96 | static bool IsLink(mozilla::dom::Element* aElement); |
michael@0 | 97 | |
michael@0 | 98 | // nsIStyleRuleProcessor |
michael@0 | 99 | virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE; |
michael@0 | 100 | |
michael@0 | 101 | virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE; |
michael@0 | 102 | |
michael@0 | 103 | virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE; |
michael@0 | 104 | |
michael@0 | 105 | #ifdef MOZ_XUL |
michael@0 | 106 | virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE; |
michael@0 | 107 | #endif |
michael@0 | 108 | |
michael@0 | 109 | virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE; |
michael@0 | 110 | virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) MOZ_OVERRIDE; |
michael@0 | 111 | |
michael@0 | 112 | virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE; |
michael@0 | 113 | |
michael@0 | 114 | virtual nsRestyleHint |
michael@0 | 115 | HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE; |
michael@0 | 116 | |
michael@0 | 117 | virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE; |
michael@0 | 118 | |
michael@0 | 119 | virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) |
michael@0 | 120 | const MOZ_MUST_OVERRIDE MOZ_OVERRIDE; |
michael@0 | 121 | virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) |
michael@0 | 122 | const MOZ_MUST_OVERRIDE MOZ_OVERRIDE; |
michael@0 | 123 | |
michael@0 | 124 | // Append all the currently-active font face rules to aArray. Return |
michael@0 | 125 | // true for success and false for failure. |
michael@0 | 126 | bool AppendFontFaceRules(nsPresContext* aPresContext, |
michael@0 | 127 | nsTArray<nsFontFaceRuleContainer>& aArray); |
michael@0 | 128 | |
michael@0 | 129 | nsCSSKeyframesRule* KeyframesRuleForName(nsPresContext* aPresContext, |
michael@0 | 130 | const nsString& aName); |
michael@0 | 131 | |
michael@0 | 132 | bool AppendPageRules(nsPresContext* aPresContext, |
michael@0 | 133 | nsTArray<nsCSSPageRule*>& aArray); |
michael@0 | 134 | |
michael@0 | 135 | bool AppendFontFeatureValuesRules(nsPresContext* aPresContext, |
michael@0 | 136 | nsTArray<nsCSSFontFeatureValuesRule*>& aArray); |
michael@0 | 137 | |
michael@0 | 138 | /** |
michael@0 | 139 | * Returns the scope element for the scoped style sheets this rule |
michael@0 | 140 | * processor is for. If this is not a rule processor for scoped style |
michael@0 | 141 | * sheets, it returns null. |
michael@0 | 142 | */ |
michael@0 | 143 | mozilla::dom::Element* GetScopeElement() const { return mScopeElement; } |
michael@0 | 144 | |
michael@0 | 145 | #ifdef DEBUG |
michael@0 | 146 | void AssertQuirksChangeOK() { |
michael@0 | 147 | NS_ASSERTION(!mRuleCascades, "can't toggle quirks style sheet without " |
michael@0 | 148 | "clearing rule cascades"); |
michael@0 | 149 | } |
michael@0 | 150 | #endif |
michael@0 | 151 | |
michael@0 | 152 | #ifdef XP_WIN |
michael@0 | 153 | // Cached theme identifier for the moz-windows-theme media query. |
michael@0 | 154 | static uint8_t GetWindowsThemeIdentifier(); |
michael@0 | 155 | static void SetWindowsThemeIdentifier(uint8_t aId) { |
michael@0 | 156 | sWinThemeId = aId; |
michael@0 | 157 | } |
michael@0 | 158 | #endif |
michael@0 | 159 | |
michael@0 | 160 | struct StateSelector { |
michael@0 | 161 | StateSelector(mozilla::EventStates aStates, nsCSSSelector* aSelector) |
michael@0 | 162 | : mStates(aStates), |
michael@0 | 163 | mSelector(aSelector) |
michael@0 | 164 | {} |
michael@0 | 165 | |
michael@0 | 166 | mozilla::EventStates mStates; |
michael@0 | 167 | nsCSSSelector* mSelector; |
michael@0 | 168 | }; |
michael@0 | 169 | |
michael@0 | 170 | private: |
michael@0 | 171 | static bool CascadeSheet(nsCSSStyleSheet* aSheet, CascadeEnumData* aData); |
michael@0 | 172 | |
michael@0 | 173 | RuleCascadeData* GetRuleCascade(nsPresContext* aPresContext); |
michael@0 | 174 | void RefreshRuleCascade(nsPresContext* aPresContext); |
michael@0 | 175 | |
michael@0 | 176 | nsRestyleHint HasStateDependentStyle(ElementDependentRuleProcessorData* aData, |
michael@0 | 177 | mozilla::dom::Element* aStatefulElement, |
michael@0 | 178 | nsCSSPseudoElements::Type aPseudoType, |
michael@0 | 179 | mozilla::EventStates aStateMask); |
michael@0 | 180 | |
michael@0 | 181 | // The sheet order here is the same as in nsStyleSet::mSheets |
michael@0 | 182 | sheet_array_type mSheets; |
michael@0 | 183 | |
michael@0 | 184 | // active first, then cached (most recent first) |
michael@0 | 185 | RuleCascadeData* mRuleCascades; |
michael@0 | 186 | |
michael@0 | 187 | // The last pres context for which GetRuleCascades was called. |
michael@0 | 188 | nsPresContext *mLastPresContext; |
michael@0 | 189 | |
michael@0 | 190 | // The scope element for this rule processor's scoped style sheets. |
michael@0 | 191 | // Only used if mSheetType == nsStyleSet::eScopedDocSheet. |
michael@0 | 192 | nsRefPtr<mozilla::dom::Element> mScopeElement; |
michael@0 | 193 | |
michael@0 | 194 | // type of stylesheet using this processor |
michael@0 | 195 | uint8_t mSheetType; // == nsStyleSet::sheetType |
michael@0 | 196 | |
michael@0 | 197 | #ifdef XP_WIN |
michael@0 | 198 | static uint8_t sWinThemeId; |
michael@0 | 199 | #endif |
michael@0 | 200 | }; |
michael@0 | 201 | |
michael@0 | 202 | #endif /* nsCSSRuleProcessor_h_ */ |