1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsCSSRuleProcessor.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,202 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +// vim:cindent:tabstop=2:expandtab:shiftwidth=2: 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* 1.11 + * style rule processor for CSS style sheets, responsible for selector 1.12 + * matching and cascading 1.13 + */ 1.14 + 1.15 +#ifndef nsCSSRuleProcessor_h_ 1.16 +#define nsCSSRuleProcessor_h_ 1.17 + 1.18 +#include "mozilla/Attributes.h" 1.19 +#include "mozilla/EventStates.h" 1.20 +#include "mozilla/MemoryReporting.h" 1.21 +#include "nsIStyleRuleProcessor.h" 1.22 +#include "nsCSSStyleSheet.h" 1.23 +#include "nsTArray.h" 1.24 +#include "nsAutoPtr.h" 1.25 +#include "nsRuleWalker.h" 1.26 + 1.27 +struct CascadeEnumData; 1.28 +struct nsCSSSelector; 1.29 +struct nsCSSSelectorList; 1.30 +struct RuleCascadeData; 1.31 +struct TreeMatchContext; 1.32 +class nsCSSKeyframesRule; 1.33 +class nsCSSPageRule; 1.34 +class nsCSSFontFeatureValuesRule; 1.35 + 1.36 +/** 1.37 + * The CSS style rule processor provides a mechanism for sibling style 1.38 + * sheets to combine their rule processing in order to allow proper 1.39 + * cascading to happen. 1.40 + * 1.41 + * CSS style rule processors keep a live reference on all style sheets 1.42 + * bound to them. The CSS style sheets keep a weak reference to all the 1.43 + * processors that they are bound to (many to many). The CSS style sheet 1.44 + * is told when the rule processor is going away (via DropRuleProcessor). 1.45 + */ 1.46 + 1.47 +class nsCSSRuleProcessor: public nsIStyleRuleProcessor { 1.48 +public: 1.49 + typedef nsTArray<nsRefPtr<nsCSSStyleSheet> > sheet_array_type; 1.50 + 1.51 + // aScopeElement must be non-null iff aSheetType is 1.52 + // nsStyleSet::eScopedDocSheet. 1.53 + nsCSSRuleProcessor(const sheet_array_type& aSheets, 1.54 + uint8_t aSheetType, 1.55 + mozilla::dom::Element* aScopeElement); 1.56 + virtual ~nsCSSRuleProcessor(); 1.57 + 1.58 + NS_DECL_ISUPPORTS 1.59 + 1.60 +public: 1.61 + nsresult ClearRuleCascades(); 1.62 + 1.63 + static nsresult Startup(); 1.64 + static void Shutdown(); 1.65 + static void FreeSystemMetrics(); 1.66 + static bool HasSystemMetric(nsIAtom* aMetric); 1.67 + 1.68 + /* 1.69 + * Returns true if the given aElement matches one of the 1.70 + * selectors in aSelectorList. Note that this method will assume 1.71 + * the given aElement is not a relevant link. aSelectorList must not 1.72 + * include any pseudo-element selectors. aSelectorList is allowed 1.73 + * to be null; in this case false will be returned. 1.74 + */ 1.75 + static bool SelectorListMatches(mozilla::dom::Element* aElement, 1.76 + TreeMatchContext& aTreeMatchContext, 1.77 + nsCSSSelectorList* aSelectorList); 1.78 + 1.79 + /* 1.80 + * Helper to get the content state for a content node. This may be 1.81 + * slightly adjusted from IntrinsicState(). 1.82 + */ 1.83 + static mozilla::EventStates GetContentState( 1.84 + mozilla::dom::Element* aElement, 1.85 + const TreeMatchContext& aTreeMatchContext); 1.86 + 1.87 + /* 1.88 + * Helper to get the content state for :visited handling for an element 1.89 + */ 1.90 + static mozilla::EventStates GetContentStateForVisitedHandling( 1.91 + mozilla::dom::Element* aElement, 1.92 + const TreeMatchContext& aTreeMatchContext, 1.93 + nsRuleWalker::VisitedHandlingType aVisitedHandling, 1.94 + bool aIsRelevantLink); 1.95 + 1.96 + /* 1.97 + * Helper to test whether a node is a link 1.98 + */ 1.99 + static bool IsLink(mozilla::dom::Element* aElement); 1.100 + 1.101 + // nsIStyleRuleProcessor 1.102 + virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE; 1.103 + 1.104 + virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE; 1.105 + 1.106 + virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE; 1.107 + 1.108 +#ifdef MOZ_XUL 1.109 + virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE; 1.110 +#endif 1.111 + 1.112 + virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE; 1.113 + virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) MOZ_OVERRIDE; 1.114 + 1.115 + virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE; 1.116 + 1.117 + virtual nsRestyleHint 1.118 + HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE; 1.119 + 1.120 + virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE; 1.121 + 1.122 + virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) 1.123 + const MOZ_MUST_OVERRIDE MOZ_OVERRIDE; 1.124 + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) 1.125 + const MOZ_MUST_OVERRIDE MOZ_OVERRIDE; 1.126 + 1.127 + // Append all the currently-active font face rules to aArray. Return 1.128 + // true for success and false for failure. 1.129 + bool AppendFontFaceRules(nsPresContext* aPresContext, 1.130 + nsTArray<nsFontFaceRuleContainer>& aArray); 1.131 + 1.132 + nsCSSKeyframesRule* KeyframesRuleForName(nsPresContext* aPresContext, 1.133 + const nsString& aName); 1.134 + 1.135 + bool AppendPageRules(nsPresContext* aPresContext, 1.136 + nsTArray<nsCSSPageRule*>& aArray); 1.137 + 1.138 + bool AppendFontFeatureValuesRules(nsPresContext* aPresContext, 1.139 + nsTArray<nsCSSFontFeatureValuesRule*>& aArray); 1.140 + 1.141 + /** 1.142 + * Returns the scope element for the scoped style sheets this rule 1.143 + * processor is for. If this is not a rule processor for scoped style 1.144 + * sheets, it returns null. 1.145 + */ 1.146 + mozilla::dom::Element* GetScopeElement() const { return mScopeElement; } 1.147 + 1.148 +#ifdef DEBUG 1.149 + void AssertQuirksChangeOK() { 1.150 + NS_ASSERTION(!mRuleCascades, "can't toggle quirks style sheet without " 1.151 + "clearing rule cascades"); 1.152 + } 1.153 +#endif 1.154 + 1.155 +#ifdef XP_WIN 1.156 + // Cached theme identifier for the moz-windows-theme media query. 1.157 + static uint8_t GetWindowsThemeIdentifier(); 1.158 + static void SetWindowsThemeIdentifier(uint8_t aId) { 1.159 + sWinThemeId = aId; 1.160 + } 1.161 +#endif 1.162 + 1.163 + struct StateSelector { 1.164 + StateSelector(mozilla::EventStates aStates, nsCSSSelector* aSelector) 1.165 + : mStates(aStates), 1.166 + mSelector(aSelector) 1.167 + {} 1.168 + 1.169 + mozilla::EventStates mStates; 1.170 + nsCSSSelector* mSelector; 1.171 + }; 1.172 + 1.173 +private: 1.174 + static bool CascadeSheet(nsCSSStyleSheet* aSheet, CascadeEnumData* aData); 1.175 + 1.176 + RuleCascadeData* GetRuleCascade(nsPresContext* aPresContext); 1.177 + void RefreshRuleCascade(nsPresContext* aPresContext); 1.178 + 1.179 + nsRestyleHint HasStateDependentStyle(ElementDependentRuleProcessorData* aData, 1.180 + mozilla::dom::Element* aStatefulElement, 1.181 + nsCSSPseudoElements::Type aPseudoType, 1.182 + mozilla::EventStates aStateMask); 1.183 + 1.184 + // The sheet order here is the same as in nsStyleSet::mSheets 1.185 + sheet_array_type mSheets; 1.186 + 1.187 + // active first, then cached (most recent first) 1.188 + RuleCascadeData* mRuleCascades; 1.189 + 1.190 + // The last pres context for which GetRuleCascades was called. 1.191 + nsPresContext *mLastPresContext; 1.192 + 1.193 + // The scope element for this rule processor's scoped style sheets. 1.194 + // Only used if mSheetType == nsStyleSet::eScopedDocSheet. 1.195 + nsRefPtr<mozilla::dom::Element> mScopeElement; 1.196 + 1.197 + // type of stylesheet using this processor 1.198 + uint8_t mSheetType; // == nsStyleSet::sheetType 1.199 + 1.200 +#ifdef XP_WIN 1.201 + static uint8_t sWinThemeId; 1.202 +#endif 1.203 +}; 1.204 + 1.205 +#endif /* nsCSSRuleProcessor_h_ */