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 objects providing immutable style 8 * information 9 */ 10 11 #ifndef nsIStyleRule_h___ 12 #define nsIStyleRule_h___ 13 14 #include <stdio.h> 15 16 #include "nsCSSPropertyID.h" 17 #include "nsISupports.h" 18 19 class nsCSSValue; 20 struct nsRuleData; 21 22 // IID for the nsIStyleRule interface {f75f3f70-435d-43a6-a01b-65970489ca26} 23 #define NS_ISTYLE_RULE_IID \ 24 { 0xf75f3f70, 0x435d, 0x43a6, \ 25 { 0xa0, 0x1b, 0x65, 0x97, 0x04, 0x89, 0xca, 0x26 } } 26 27 /** 28 * An object implementing |nsIStyleRule| (henceforth, a rule) represents 29 * immutable stylistic information that either applies or does not apply 30 * to a given element. It belongs to an object or group of objects that 31 * implement |nsIStyleSheet| and |nsIStyleRuleProcessor| (henceforth, a 32 * sheet). 33 * 34 * A rule becomes relevant to the computation of style data when 35 * |nsIStyleRuleProcessor::RulesMatching| creates a rule node that 36 * points to the rule. (A rule node, |nsRuleNode|, is a node in the 37 * rule tree, which is a lexicographic tree indexed by rules. The path 38 * from the root of the rule tree to the |nsRuleNode| for a given 39 * |nsStyleContext| contains exactly the rules that match the element 40 * that the style context is for, in priority (weight, origin, 41 * specificity) order.) 42 * 43 * The computation of style data uses the rule tree, which calls 44 * |nsIStyleRule::MapRuleInfoInto| below. 45 * 46 * It is worth emphasizing that the data represented by a rule 47 * implementation are immutable. When the data need to be changed, a 48 * new rule object must be created. Failing to do this will lead to 49 * bugs in the handling of dynamic style changes, since the rule tree 50 * caches the results of |MapRuleInfoInto|. 51 * 52 * |nsIStyleRule| objects are owned by |nsRuleNode| objects (in addition 53 * to typically being owned by their sheet), which are in turn garbage 54 * collected (with the garbage collection roots being style contexts). 55 */ 56 57 58 class nsIStyleRule : public nsISupports { 59 public: 60 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_IID) 61 62 /** 63 * |nsIStyleRule::MapRuleInfoInto| is a request to copy all stylistic 64 * data represented by the rule that: 65 * + are relevant for any structs in |aRuleData->mSIDs| (style 66 * struct ID bits) 67 * + are not already filled into the data struct 68 * into the appropriate data struct in |aRuleData|. It is important 69 * that only empty data are filled in, since the rule tree is walked 70 * from highest priority rule to least, so that the walk can stop if 71 * all needed data are found. Thus overwriting non-empty data will 72 * break CSS cascading rules. 73 */ 74 virtual void MapRuleInfoInto(nsRuleData* aRuleData)=0; 75 76 /** 77 * Returns whether this style rule has any style data for inherited 78 * properties. 79 */ 80 virtual bool MightMapInheritedStyleData() = 0; 81 82 /** 83 * Gets and sets given aProperty's value to aValue. 84 * Returns true, if aValue is filled in this rule. 85 */ 86 virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, 87 nsCSSValue* aValue) = 0; 88 89 #ifdef DEBUG 90 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; 91 #endif 92 }; 93 94 NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRule, NS_ISTYLE_RULE_IID) 95 96 #endif /* nsIStyleRule_h___ */ 97