Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / layout / style / nsIStyleRule.h
blob819f169f563f41849ae5aef52de9e5f76817c9bf
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * internal abstract interface for objects providing immutable style
40 * information
43 #ifndef nsIStyleRule_h___
44 #define nsIStyleRule_h___
46 #include <stdio.h>
48 #include "nsISupports.h"
50 class nsIStyleSheet;
51 class nsIContent;
52 struct nsRuleData;
54 // IID for the nsIStyleRule interface {f75f3f70-435d-43a6-a01b-65970489ca26}
55 #define NS_ISTYLE_RULE_IID \
56 { 0xf75f3f70, 0x435d, 0x43a6, \
57 { 0xa0, 0x1b, 0x65, 0x97, 0x04, 0x89, 0xca, 0x26 } }
59 /**
60 * An object implementing |nsIStyleRule| (henceforth, a rule) represents
61 * immutable stylistic information that either applies or does not apply
62 * to a given element. It belongs to an object or group of objects that
63 * implement |nsIStyleSheet| and |nsIStyleRuleProcessor| (henceforth, a
64 * sheet).
66 * A rule becomes relevant to the computation of style data when
67 * |nsIStyleRuleProcessor::RulesMatching| creates a rule node that
68 * points to the rule. (A rule node, |nsRuleNode|, is a node in the
69 * rule tree, which is a lexicographic tree indexed by rules. The path
70 * from the root of the rule tree to the |nsRuleNode| for a given
71 * |nsStyleContext| contains exactly the rules that match the element
72 * that the style context is for, in priority (weight, origin,
73 * specificity) order.)
75 * The computation of style data uses the rule tree, which calls
76 * |nsIStyleRule::MapRuleInfoInto| below.
78 * It is worth emphasizing that the data represented by a rule
79 * implementation are immutable. When the data need to be changed, a
80 * new rule object must be created. Failing to do this will lead to
81 * bugs in the handling of dynamic style changes, since the rule tree
82 * caches the results of |MapRuleInfoInto|.
84 * |nsIStyleRule| objects are owned by |nsRuleNode| objects (in addition
85 * to typically being owned by their sheet), which are in turn garbage
86 * collected (with the garbage collection roots being style contexts).
90 class nsIStyleRule : public nsISupports {
91 public:
92 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_IID)
94 /**
95 * |nsIStyleRule::MapRuleInfoInto| is a request to copy all stylistic
96 * data represented by the rule that:
97 * + are relevant for any structs in |aRuleData->mSIDs| (style
98 * struct ID bits)
99 * + are not already filled into the data struct
100 * into the appropriate data struct in |aRuleData|. It is important
101 * that only empty data are filled in, since the rule tree is walked
102 * from highest priority rule to least, so that the walk can stop if
103 * all needed data are found. Thus overwriting non-empty data will
104 * break CSS cascading rules.
106 virtual void MapRuleInfoInto(nsRuleData* aRuleData)=0;
108 virtual nsIStyleRule* GetImportantRule(void) { return nsnull; }
110 #ifdef DEBUG
111 virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
112 #endif
115 NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRule, NS_ISTYLE_RULE_IID)
117 #endif /* nsIStyleRule_h___ */