Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / layout / style / nsStyleContext.h
blob1000c4822b8c296df4b8cd4f50286cfdfee55b5a
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):
23 * David Hyatt <hyatt@netscape.com>
24 * Pierre Phaneuf <pp@ludusdesign.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 /* the interface (to internal code) for retrieving computed style data */
42 #ifndef _nsStyleContext_h_
43 #define _nsStyleContext_h_
45 #include "nsRuleNode.h"
46 #include "nsIAtom.h"
48 class nsPresContext;
50 /**
51 * An nsStyleContext represents the computed style data for an element.
52 * The computed style data are stored in a set of structs (see
53 * nsStyleStruct.h) that are cached either on the style context or in
54 * the rule tree (see nsRuleNode.h for a description of this caching and
55 * how the cached structs are shared).
57 * Since the data in |nsIStyleRule|s and |nsRuleNode|s are immutable
58 * (with a few exceptions, like system color changes), the data in an
59 * nsStyleContext are also immutable (with the additional exception of
60 * GetUniqueStyleData). When style data change,
61 * nsFrameManager::ReResolveStyleContext creates a new style context.
63 * Style contexts are reference counted. References are generally held
64 * by:
65 * 1. the |nsIFrame|s that are using the style context and
66 * 2. any *child* style contexts (this might be the reverse of
67 * expectation, but it makes sense in this case)
68 * Style contexts participate in the mark phase of rule node garbage
69 * collection.
72 class nsStyleContext
74 public:
75 nsStyleContext(nsStyleContext* aParent, nsIAtom* aPseudoTag,
76 nsRuleNode* aRuleNode, nsPresContext* aPresContext) NS_HIDDEN;
77 ~nsStyleContext() NS_HIDDEN;
79 NS_HIDDEN_(void*) operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW;
80 NS_HIDDEN_(void) Destroy();
82 nsrefcnt AddRef() {
83 ++mRefCnt;
84 NS_LOG_ADDREF(this, mRefCnt, "nsStyleContext", sizeof(nsStyleContext));
85 return mRefCnt;
88 nsrefcnt Release() {
89 --mRefCnt;
90 NS_LOG_RELEASE(this, mRefCnt, "nsStyleContext");
91 if (mRefCnt == 0) {
92 Destroy();
93 return 0;
95 return mRefCnt;
98 nsPresContext* PresContext() const { return mRuleNode->GetPresContext(); }
100 nsStyleContext* GetParent() const { return mParent; }
102 nsStyleContext* GetFirstChild() const { return mChild; }
104 nsIAtom* GetPseudoType() const { return mPseudoTag; }
106 NS_HIDDEN_(already_AddRefed<nsStyleContext>)
107 FindChildWithRules(const nsIAtom* aPseudoTag, nsRuleNode* aRules);
109 NS_HIDDEN_(PRBool) Equals(const nsStyleContext* aOther) const;
110 PRBool HasTextDecorations() { return !!(mBits & NS_STYLE_HAS_TEXT_DECORATIONS); }
112 NS_HIDDEN_(void) SetStyle(nsStyleStructID aSID, void* aStruct);
114 nsRuleNode* GetRuleNode() { return mRuleNode; }
115 void AddStyleBit(const PRUint32& aBit) { mBits |= aBit; }
118 * Mark this style context's rule node (and its ancestors) to prevent
119 * it from being garbage collected.
121 NS_HIDDEN_(void) Mark();
124 * Get the style data for a style struct. This is the most important
125 * member function of nsIStyleContext. It fills in a const pointer
126 * to a style data struct that is appropriate for the style context's
127 * frame. This struct may be shared with other contexts (either in
128 * the rule tree or the style context tree), so it should not be
129 * modified.
131 * This function will NOT return null (even when out of memory) when
132 * given a valid style struct ID, so the result does not need to be
133 * null-checked.
135 * The typesafe functions below are preferred to the use of this
136 * function.
138 NS_HIDDEN_(const void*) NS_FASTCALL GetStyleData(nsStyleStructID aSID);
141 * Define typesafe getter functions for each style struct by
142 * preprocessing the list of style structs. These functions are the
143 * preferred way to get style data. The macro creates functions like:
144 * const nsStyleBorder* GetStyleBorder();
145 * const nsStyleColor* GetStyleColor();
148 #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_) \
149 NS_HIDDEN_(const nsStyle##name_ *) NS_FASTCALL GetStyle##name_();
150 #include "nsStyleStructList.h"
151 #undef STYLE_STRUCT
154 NS_HIDDEN_(const void*) PeekStyleData(nsStyleStructID aSID);
156 NS_HIDDEN_(void*) GetUniqueStyleData(const nsStyleStructID& aSID);
158 NS_HIDDEN_(nsChangeHint) CalcStyleDifference(nsStyleContext* aOther);
160 #ifdef DEBUG
161 NS_HIDDEN_(void) DumpRegressionData(nsPresContext* aPresContext, FILE* out,
162 PRInt32 aIndent);
164 NS_HIDDEN_(void) List(FILE* out, PRInt32 aIndent);
165 #endif
167 protected:
168 NS_HIDDEN_(void) AddChild(nsStyleContext* aChild);
169 NS_HIDDEN_(void) RemoveChild(nsStyleContext* aChild);
171 NS_HIDDEN_(void) ApplyStyleFixups(nsPresContext* aPresContext);
173 nsStyleContext* mParent;
175 // Children are kept in two circularly-linked lists. The list anchor
176 // is not part of the list (null for empty), and we point to the first
177 // child.
178 // mEmptyChild for children whose rule node is the root rule node, and
179 // mChild for other children. The order of children is not
180 // meaningful.
181 nsStyleContext* mChild;
182 nsStyleContext* mEmptyChild;
183 nsStyleContext* mPrevSibling;
184 nsStyleContext* mNextSibling;
186 // If this style context is for a pseudo-element, the pseudo-element
187 // atom. Otherwise, null.
188 nsCOMPtr<nsIAtom> mPseudoTag;
190 // The rule node is the node in the lexicographic tree of rule nodes
191 // (the "rule tree") that indicates which style rules are used to
192 // compute the style data, and in what cascading order. The least
193 // specific rule matched is the one whose rule node is a child of the
194 // root of the rule tree, and the most specific rule matched is the
195 // |mRule| member of |mRuleNode|.
196 nsRuleNode* const mRuleNode;
198 // |mCachedStyleData| points to both structs that are owned by this
199 // style context and structs that are owned by one of this style
200 // context's ancestors (which are indirectly owned since this style
201 // context owns a reference to its parent). If the bit in |mBits| is
202 // set for a struct, that means that the pointer for that struct is
203 // owned by an ancestor rather than by this style context.
204 nsCachedStyleData mCachedStyleData; // Our cached style data.
205 PRUint32 mBits; // Which structs are inherited from the
206 // parent context.
207 PRUint32 mRefCnt;
210 NS_HIDDEN_(already_AddRefed<nsStyleContext>)
211 NS_NewStyleContext(nsStyleContext* aParentContext,
212 nsIAtom* aPseudoTag,
213 nsRuleNode* aRuleNode,
214 nsPresContext* aPresContext);
215 #endif