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
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.
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
44 #ifndef nsCSSProps_h___
45 #define nsCSSProps_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 */
62 static void AddRefTable(void);
63 static void ReleaseTable(void);
65 // Given a property string, return the enum value
66 static nsCSSProperty
LookupProperty(const nsAString
& aProperty
);
67 static nsCSSProperty
LookupProperty(const nsACString
& aProperty
);
69 static inline PRBool
IsShorthand(nsCSSProperty aProperty
) {
70 NS_ASSERTION(0 <= aProperty
&& aProperty
< eCSSProperty_COUNT
,
72 return (aProperty
>= eCSSProperty_COUNT_no_shorthands
);
75 // Same but for @font-face descriptors
76 static nsCSSFontDesc
LookupFontDesc(const nsAString
& aProperty
);
77 static nsCSSFontDesc
LookupFontDesc(const nsACString
& aProperty
);
79 // Given a property enum, get the string value
80 static const nsAFlatCString
& GetStringValue(nsCSSProperty aProperty
);
81 static const nsAFlatCString
& GetStringValue(nsCSSFontDesc aFontDesc
);
83 // Given a CSS Property and a Property Enum Value
84 // Return back a const nsString& representation of the
85 // value. Return back nullstr if no value is found
86 static const nsAFlatCString
& LookupPropertyValue(nsCSSProperty aProperty
, PRInt32 aValue
);
88 // Get a color name for a predefined color value like buttonhighlight or activeborder
89 // Sets the aStr param to the name of the propertyID
90 static PRBool
GetColorName(PRInt32 aPropID
, nsCString
&aStr
);
92 // Find |aKeyword| in |aTable|, if found set |aValue| to its corresponding value.
93 // If not found, return PR_FALSE and do not set |aValue|.
94 static PRBool
FindKeyword(nsCSSKeyword aKeyword
, const PRInt32 aTable
[], PRInt32
& aValue
);
95 // Return the first keyword in |aTable| that has the corresponding value |aValue|.
96 // Return |eCSSKeyword_UNKNOWN| if not found.
97 static nsCSSKeyword
ValueToKeywordEnum(PRInt32 aValue
, const PRInt32 aTable
[]);
98 // Ditto but as a string, return "" when not found.
99 static const nsAFlatCString
& ValueToKeyword(PRInt32 aValue
, const PRInt32 aTable
[]);
101 static const nsCSSType kTypeTable
[eCSSProperty_COUNT_no_shorthands
];
102 static const nsStyleStructID kSIDTable
[eCSSProperty_COUNT_no_shorthands
];
103 static const PRInt32
* const kKeywordTableTable
[eCSSProperty_COUNT_no_shorthands
];
105 static const PRUint32 kFlagsTable
[eCSSProperty_COUNT
];
107 // A table for shorthand properties. The appropriate index is the
108 // property ID minus eCSSProperty_COUNT_no_shorthands.
109 static const nsCSSProperty
*const
110 kSubpropertyTable
[eCSSProperty_COUNT
- eCSSProperty_COUNT_no_shorthands
];
114 const nsCSSProperty
*const SubpropertyEntryFor(nsCSSProperty aProperty
) {
115 NS_ASSERTION(eCSSProperty_COUNT_no_shorthands
<= aProperty
&&
116 aProperty
< eCSSProperty_COUNT
,
118 return nsCSSProps::kSubpropertyTable
[aProperty
-
119 eCSSProperty_COUNT_no_shorthands
];
122 static inline PRBool
PropHasFlags(nsCSSProperty aProperty
, PRUint32 aFlags
)
124 return (nsCSSProps::kFlagsTable
[aProperty
] & aFlags
) == aFlags
;
127 #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_) \
128 for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_); \
129 *iter_ != eCSSProperty_UNKNOWN; ++iter_)
131 // Keyword/Enum value tables
132 static const PRInt32 kAppearanceKTable
[];
133 static const PRInt32 kAzimuthKTable
[];
134 static const PRInt32 kBackgroundAttachmentKTable
[];
135 static const PRInt32 kBackgroundClipKTable
[];
136 static const PRInt32 kBackgroundInlinePolicyKTable
[];
137 static const PRInt32 kBackgroundOriginKTable
[];
138 static const PRInt32 kBackgroundPositionKTable
[];
139 static const PRInt32 kBackgroundRepeatKTable
[];
140 static const PRInt32 kBorderCollapseKTable
[];
141 static const PRInt32 kBorderColorKTable
[];
142 static const PRInt32 kBorderImageKTable
[];
143 static const PRInt32 kBorderStyleKTable
[];
144 static const PRInt32 kBorderWidthKTable
[];
145 static const PRInt32 kBoxAlignKTable
[];
146 static const PRInt32 kBoxDirectionKTable
[];
147 static const PRInt32 kBoxOrientKTable
[];
148 static const PRInt32 kBoxPackKTable
[];
150 static const PRInt32 kDominantBaselineKTable
[];
151 static const PRInt32 kFillRuleKTable
[];
152 static const PRInt32 kPointerEventsKTable
[];
153 static const PRInt32 kShapeRenderingKTable
[];
154 static const PRInt32 kStrokeLinecapKTable
[];
155 static const PRInt32 kStrokeLinejoinKTable
[];
156 static const PRInt32 kTextAnchorKTable
[];
157 static const PRInt32 kTextRenderingKTable
[];
158 static const PRInt32 kColorInterpolationKTable
[];
160 static const PRInt32 kBoxPropSourceKTable
[];
161 static const PRInt32 kBoxSizingKTable
[];
162 static const PRInt32 kCaptionSideKTable
[];
163 static const PRInt32 kClearKTable
[];
164 static const PRInt32 kColorKTable
[];
165 static const PRInt32 kContentKTable
[];
166 static const PRInt32 kCursorKTable
[];
167 static const PRInt32 kDirectionKTable
[];
168 static const PRInt32 kDisplayKTable
[];
169 static const PRInt32 kElevationKTable
[];
170 static const PRInt32 kEmptyCellsKTable
[];
171 static const PRInt32 kFloatKTable
[];
172 static const PRInt32 kFloatEdgeKTable
[];
173 static const PRInt32 kFontKTable
[];
174 static const PRInt32 kFontSizeKTable
[];
175 static const PRInt32 kFontStretchKTable
[];
176 static const PRInt32 kFontStyleKTable
[];
177 static const PRInt32 kFontVariantKTable
[];
178 static const PRInt32 kFontWeightKTable
[];
179 static const PRInt32 kKeyEquivalentKTable
[];
180 static const PRInt32 kIMEModeKTable
[];
181 static const PRInt32 kListStylePositionKTable
[];
182 static const PRInt32 kListStyleKTable
[];
183 static const PRInt32 kOutlineStyleKTable
[];
184 static const PRInt32 kOutlineColorKTable
[];
185 static const PRInt32 kOverflowKTable
[];
186 static const PRInt32 kOverflowSubKTable
[];
187 static const PRInt32 kPageBreakKTable
[];
188 static const PRInt32 kPageBreakInsideKTable
[];
189 static const PRInt32 kPageMarksKTable
[];
190 static const PRInt32 kPageSizeKTable
[];
191 static const PRInt32 kPitchKTable
[];
192 static const PRInt32 kPositionKTable
[];
193 static const PRInt32 kSpeakKTable
[];
194 static const PRInt32 kSpeakHeaderKTable
[];
195 static const PRInt32 kSpeakNumeralKTable
[];
196 static const PRInt32 kSpeakPunctuationKTable
[];
197 static const PRInt32 kSpeechRateKTable
[];
198 static const PRInt32 kStackSizingKTable
[];
199 static const PRInt32 kTableLayoutKTable
[];
200 static const PRInt32 kTextAlignKTable
[];
201 static const PRInt32 kTextDecorationKTable
[];
202 static const PRInt32 kTextTransformKTable
[];
203 static const PRInt32 kUnicodeBidiKTable
[];
204 static const PRInt32 kUserFocusKTable
[];
205 static const PRInt32 kUserInputKTable
[];
206 static const PRInt32 kUserModifyKTable
[];
207 static const PRInt32 kUserSelectKTable
[];
208 static const PRInt32 kVerticalAlignKTable
[];
209 static const PRInt32 kVisibilityKTable
[];
210 static const PRInt32 kVolumeKTable
[];
211 static const PRInt32 kWhitespaceKTable
[];
212 static const PRInt32 kWidthKTable
[]; // also min-width, max-width
213 static const PRInt32 kWindowShadowKTable
[];
214 static const PRInt32 kWordwrapKTable
[];
217 #endif /* nsCSSProps_h___ */