Bug 473680. Stop crashtest 458637-1.html early (returning success) if it's running...
[mozilla-central.git] / layout / style / nsCSSProps.h
blob7edb68684cd7d9407af89b3411e9c452f4e11878
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 * Mats Palmgren <mats.palmgren@bredband.net>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 * methods for dealing with CSS properties and tables of the keyword
41 * values they accept
44 #ifndef nsCSSProps_h___
45 #define nsCSSProps_h___
47 #include "nsString.h"
48 #include "nsChangeHint.h"
49 #include "nsCSSProperty.h"
50 #include "nsStyleStruct.h"
51 #include "nsCSSKeywords.h"
53 // Flags for the kFlagsTable bitfield (flags_ in nsCSSPropList.h)
55 // A property that is a *-ltr-source or *-rtl-source property for one of
56 // the directional pseudo-shorthand properties.
57 #define CSS_PROPERTY_DIRECTIONAL_SOURCE (1<<0)
58 #define CSS_PROPERTY_VALUE_LIST_USES_COMMAS (1<<1) /* otherwise spaces */
59 #define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER (1<<2)
60 #define CSS_PROPERTY_APPLIES_TO_FIRST_LINE (1<<3)
61 #define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE \
62 (CSS_PROPERTY_APPLIES_TO_FIRST_LETTER | CSS_PROPERTY_APPLIES_TO_FIRST_LINE)
64 class nsCSSProps {
65 public:
66 static void AddRefTable(void);
67 static void ReleaseTable(void);
69 // Given a property string, return the enum value
70 static nsCSSProperty LookupProperty(const nsAString& aProperty);
71 static nsCSSProperty LookupProperty(const nsACString& aProperty);
73 static inline PRBool IsShorthand(nsCSSProperty aProperty) {
74 NS_ASSERTION(0 <= aProperty && aProperty < eCSSProperty_COUNT,
75 "out of range");
76 return (aProperty >= eCSSProperty_COUNT_no_shorthands);
79 // Same but for @font-face descriptors
80 static nsCSSFontDesc LookupFontDesc(const nsAString& aProperty);
81 static nsCSSFontDesc LookupFontDesc(const nsACString& aProperty);
83 // Given a property enum, get the string value
84 static const nsAFlatCString& GetStringValue(nsCSSProperty aProperty);
85 static const nsAFlatCString& GetStringValue(nsCSSFontDesc aFontDesc);
87 // Given a CSS Property and a Property Enum Value
88 // Return back a const nsString& representation of the
89 // value. Return back nullstr if no value is found
90 static const nsAFlatCString& LookupPropertyValue(nsCSSProperty aProperty, PRInt32 aValue);
92 // Get a color name for a predefined color value like buttonhighlight or activeborder
93 // Sets the aStr param to the name of the propertyID
94 static PRBool GetColorName(PRInt32 aPropID, nsCString &aStr);
96 // Find |aKeyword| in |aTable|, if found set |aValue| to its corresponding value.
97 // If not found, return PR_FALSE and do not set |aValue|.
98 static PRBool FindKeyword(nsCSSKeyword aKeyword, const PRInt32 aTable[], PRInt32& aValue);
99 // Return the first keyword in |aTable| that has the corresponding value |aValue|.
100 // Return |eCSSKeyword_UNKNOWN| if not found.
101 static nsCSSKeyword ValueToKeywordEnum(PRInt32 aValue, const PRInt32 aTable[]);
102 // Ditto but as a string, return "" when not found.
103 static const nsAFlatCString& ValueToKeyword(PRInt32 aValue, const PRInt32 aTable[]);
105 static const nsCSSType kTypeTable[eCSSProperty_COUNT_no_shorthands];
106 static const nsStyleStructID kSIDTable[eCSSProperty_COUNT_no_shorthands];
107 static const PRInt32* const kKeywordTableTable[eCSSProperty_COUNT_no_shorthands];
109 private:
110 static const PRUint32 kFlagsTable[eCSSProperty_COUNT];
112 public:
113 static inline PRBool PropHasFlags(nsCSSProperty aProperty, PRUint32 aFlags)
115 NS_ASSERTION(0 <= aProperty && aProperty < eCSSProperty_COUNT,
116 "out of range");
117 return (nsCSSProps::kFlagsTable[aProperty] & aFlags) == aFlags;
120 private:
121 // A table for shorthand properties. The appropriate index is the
122 // property ID minus eCSSProperty_COUNT_no_shorthands.
123 static const nsCSSProperty *const
124 kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands];
126 public:
127 static inline
128 const nsCSSProperty * SubpropertyEntryFor(nsCSSProperty aProperty) {
129 NS_ASSERTION(eCSSProperty_COUNT_no_shorthands <= aProperty &&
130 aProperty < eCSSProperty_COUNT,
131 "out of range");
132 return nsCSSProps::kSubpropertyTable[aProperty -
133 eCSSProperty_COUNT_no_shorthands];
136 // Returns an eCSSProperty_UNKNOWN-terminated array of the shorthand
137 // properties containing |aProperty|, sorted from those that contain
138 // the most properties to those that contain the least.
139 static const nsCSSProperty * ShorthandsContaining(nsCSSProperty aProperty) {
140 NS_ASSERTION(gShorthandsContainingPool, "uninitialized");
141 NS_ASSERTION(0 <= aProperty && aProperty < eCSSProperty_COUNT_no_shorthands,
142 "out of range");
143 return gShorthandsContainingTable[aProperty];
145 private:
146 // gShorthandsContainingTable is an array of the return values for
147 // ShorthandsContaining (arrays of nsCSSProperty terminated by
148 // eCSSProperty_UNKNOWN) pointing into memory in
149 // gShorthandsContainingPool (which contains all of those arrays in a
150 // single allocation, and is the one pointer that should be |free|d).
151 static nsCSSProperty *gShorthandsContainingTable[eCSSProperty_COUNT_no_shorthands];
152 static nsCSSProperty* gShorthandsContainingPool;
153 static PRBool BuildShorthandsContainingTable();
155 public:
157 #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_) \
158 for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_); \
159 *iter_ != eCSSProperty_UNKNOWN; ++iter_)
161 // Keyword/Enum value tables
162 static const PRInt32 kAppearanceKTable[];
163 static const PRInt32 kAzimuthKTable[];
164 static const PRInt32 kBackgroundAttachmentKTable[];
165 static const PRInt32 kBackgroundClipKTable[];
166 static const PRInt32 kBackgroundInlinePolicyKTable[];
167 static const PRInt32 kBackgroundOriginKTable[];
168 static const PRInt32 kBackgroundPositionKTable[];
169 static const PRInt32 kBackgroundRepeatKTable[];
170 static const PRInt32 kBorderCollapseKTable[];
171 static const PRInt32 kBorderColorKTable[];
172 static const PRInt32 kBorderImageKTable[];
173 static const PRInt32 kBorderStyleKTable[];
174 static const PRInt32 kBorderWidthKTable[];
175 static const PRInt32 kBoxAlignKTable[];
176 static const PRInt32 kBoxDirectionKTable[];
177 static const PRInt32 kBoxOrientKTable[];
178 static const PRInt32 kBoxPackKTable[];
179 #ifdef MOZ_SVG
180 static const PRInt32 kDominantBaselineKTable[];
181 static const PRInt32 kFillRuleKTable[];
182 static const PRInt32 kPointerEventsKTable[];
183 static const PRInt32 kShapeRenderingKTable[];
184 static const PRInt32 kStrokeLinecapKTable[];
185 static const PRInt32 kStrokeLinejoinKTable[];
186 static const PRInt32 kTextAnchorKTable[];
187 static const PRInt32 kTextRenderingKTable[];
188 static const PRInt32 kColorInterpolationKTable[];
189 #endif
190 static const PRInt32 kBoxPropSourceKTable[];
191 static const PRInt32 kBoxSizingKTable[];
192 static const PRInt32 kCaptionSideKTable[];
193 static const PRInt32 kClearKTable[];
194 static const PRInt32 kColorKTable[];
195 static const PRInt32 kContentKTable[];
196 static const PRInt32 kCursorKTable[];
197 static const PRInt32 kDirectionKTable[];
198 static const PRInt32 kDisplayKTable[];
199 static const PRInt32 kElevationKTable[];
200 static const PRInt32 kEmptyCellsKTable[];
201 static const PRInt32 kFloatKTable[];
202 static const PRInt32 kFloatEdgeKTable[];
203 static const PRInt32 kFontKTable[];
204 static const PRInt32 kFontSizeKTable[];
205 static const PRInt32 kFontStretchKTable[];
206 static const PRInt32 kFontStyleKTable[];
207 static const PRInt32 kFontVariantKTable[];
208 static const PRInt32 kFontWeightKTable[];
209 static const PRInt32 kKeyEquivalentKTable[];
210 static const PRInt32 kIMEModeKTable[];
211 static const PRInt32 kListStylePositionKTable[];
212 static const PRInt32 kListStyleKTable[];
213 static const PRInt32 kOutlineStyleKTable[];
214 static const PRInt32 kOutlineColorKTable[];
215 static const PRInt32 kOverflowKTable[];
216 static const PRInt32 kOverflowSubKTable[];
217 static const PRInt32 kPageBreakKTable[];
218 static const PRInt32 kPageBreakInsideKTable[];
219 static const PRInt32 kPageMarksKTable[];
220 static const PRInt32 kPageSizeKTable[];
221 static const PRInt32 kPitchKTable[];
222 static const PRInt32 kPositionKTable[];
223 static const PRInt32 kSpeakKTable[];
224 static const PRInt32 kSpeakHeaderKTable[];
225 static const PRInt32 kSpeakNumeralKTable[];
226 static const PRInt32 kSpeakPunctuationKTable[];
227 static const PRInt32 kSpeechRateKTable[];
228 static const PRInt32 kStackSizingKTable[];
229 static const PRInt32 kTableLayoutKTable[];
230 static const PRInt32 kTextAlignKTable[];
231 static const PRInt32 kTextDecorationKTable[];
232 static const PRInt32 kTextTransformKTable[];
233 static const PRInt32 kUnicodeBidiKTable[];
234 static const PRInt32 kUserFocusKTable[];
235 static const PRInt32 kUserInputKTable[];
236 static const PRInt32 kUserModifyKTable[];
237 static const PRInt32 kUserSelectKTable[];
238 static const PRInt32 kVerticalAlignKTable[];
239 static const PRInt32 kVisibilityKTable[];
240 static const PRInt32 kVolumeKTable[];
241 static const PRInt32 kWhitespaceKTable[];
242 static const PRInt32 kWidthKTable[]; // also min-width, max-width
243 static const PRInt32 kWindowShadowKTable[];
244 static const PRInt32 kWordwrapKTable[];
247 #endif /* nsCSSProps_h___ */