1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 * internal abstract interface for containers (roughly origins within 8 * the CSS cascade) that provide style rules matching an element or 9 * pseudo-element 10 */ 11 12 #ifndef nsIStyleRuleProcessor_h___ 13 #define nsIStyleRuleProcessor_h___ 14 15 #include "mozilla/MemoryReporting.h" 16 #include "nsISupports.h" 17 #include "nsChangeHint.h" 18 19 struct RuleProcessorData; 20 struct ElementRuleProcessorData; 21 struct PseudoElementRuleProcessorData; 22 struct AnonBoxRuleProcessorData; 23 #ifdef MOZ_XUL 24 struct XULTreeRuleProcessorData; 25 #endif 26 struct StateRuleProcessorData; 27 struct PseudoElementStateRuleProcessorData; 28 struct AttributeRuleProcessorData; 29 class nsPresContext; 30 31 // IID for the nsIStyleRuleProcessor interface 32 // {c1d6001e-4fcb-4c40-bce1-5eba80bfd8f3} 33 #define NS_ISTYLE_RULE_PROCESSOR_IID \ 34 { 0xc1d6001e, 0x4fcb, 0x4c40, \ 35 {0xbc, 0xe1, 0x5e, 0xba, 0x80, 0xbf, 0xd8, 0xf3} } 36 37 38 /* The style rule processor interface is a mechanism to separate the matching 39 * of style rules from style sheet instances. 40 * Simple style sheets can and will act as their own processor. 41 * Sheets where rule ordering interlaces between multiple sheets, will need to 42 * share a single rule processor between them (CSS sheets do this for cascading order) 43 * 44 * @see nsIStyleRule (for significantly more detailed comments) 45 */ 46 class nsIStyleRuleProcessor : public nsISupports { 47 public: 48 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_PROCESSOR_IID) 49 50 // Shorthand for: 51 // nsCOMArray<nsIStyleRuleProcessor>::nsCOMArrayEnumFunc 52 typedef bool (* EnumFunc)(nsIStyleRuleProcessor*, void*); 53 54 /** 55 * Find the |nsIStyleRule|s matching the given content node and 56 * position the given |nsRuleWalker| at the |nsRuleNode| in the rule 57 * tree representing that ordered list of rules (with higher 58 * precedence being farther from the root of the lexicographic tree). 59 */ 60 virtual void RulesMatching(ElementRuleProcessorData* aData) = 0; 61 62 /** 63 * Just like the previous |RulesMatching|, except for a given content 64 * node <em>and pseudo-element</em>. 65 */ 66 virtual void RulesMatching(PseudoElementRuleProcessorData* aData) = 0; 67 68 /** 69 * Just like the previous |RulesMatching|, except for a given anonymous box. 70 */ 71 virtual void RulesMatching(AnonBoxRuleProcessorData* aData) = 0; 72 73 #ifdef MOZ_XUL 74 /** 75 * Just like the previous |RulesMatching|, except for a given content 76 * node <em>and tree pseudo</em>. 77 */ 78 virtual void RulesMatching(XULTreeRuleProcessorData* aData) = 0; 79 #endif 80 81 /** 82 * Return whether style can depend on a change of the given document state. 83 * 84 * Document states are defined in nsIDocument.h. 85 */ 86 virtual bool 87 HasDocumentStateDependentStyle(StateRuleProcessorData* aData) = 0; 88 89 /** 90 * Return how (as described by nsRestyleHint) style can depend on a 91 * change of the given content state on the given content node. This 92 * test is used for optimization only, and may err on the side of 93 * reporting more dependencies than really exist. 94 * 95 * Event states are defined in mozilla/EventStates.h. 96 */ 97 virtual nsRestyleHint 98 HasStateDependentStyle(StateRuleProcessorData* aData) = 0; 99 virtual nsRestyleHint 100 HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) = 0; 101 102 /** 103 * This method will be called twice for every attribute change. 104 * During the first call, aData->mAttrHasChanged will be false and 105 * the attribute change will not have happened yet. During the 106 * second call, aData->mAttrHasChanged will be true and the 107 * change will have already happened. The bitwise OR of the two 108 * return values must describe the style changes that are needed due 109 * to the attribute change. It's up to the rule processor 110 * implementation to decide how to split the bits up amongst the two 111 * return values. For example, it could return the bits needed by 112 * rules that might stop matching the node from the first call and 113 * the bits needed by rules that might have started matching the 114 * node from the second call. This test is used for optimization 115 * only, and may err on the side of reporting more dependencies than 116 * really exist. 117 */ 118 virtual nsRestyleHint HasAttributeDependentStyle( 119 AttributeRuleProcessorData* aData, 120 mozilla::RestyleHintData& aRestyleHintDataResult) = 0; 121 122 /** 123 * Do any processing that needs to happen as a result of a change in 124 * the characteristics of the medium, and return whether this rule 125 * processor's rules have changed (e.g., because of media queries). 126 */ 127 virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) = 0; 128 129 /** 130 * Report the size of this style rule processor to about:memory. A 131 * processor may return 0. 132 */ 133 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const = 0; 134 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const = 0; 135 }; 136 137 NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRuleProcessor, 138 NS_ISTYLE_RULE_PROCESSOR_IID) 139 140 #endif /* nsIStyleRuleProcessor_h___ */ 141