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 */
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)
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
,
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 static const PRUint32 kFlagsTable
[eCSSProperty_COUNT
];
111 // A table for shorthand properties. The appropriate index is the
112 // property ID minus eCSSProperty_COUNT_no_shorthands.
113 static const nsCSSProperty
*const
114 kSubpropertyTable
[eCSSProperty_COUNT
- eCSSProperty_COUNT_no_shorthands
];
118 const nsCSSProperty
*const SubpropertyEntryFor(nsCSSProperty aProperty
) {
119 NS_ASSERTION(eCSSProperty_COUNT_no_shorthands
<= aProperty
&&
120 aProperty
< eCSSProperty_COUNT
,
122 return nsCSSProps::kSubpropertyTable
[aProperty
-
123 eCSSProperty_COUNT_no_shorthands
];
126 static inline PRBool
PropHasFlags(nsCSSProperty aProperty
, PRUint32 aFlags
)
128 return (nsCSSProps::kFlagsTable
[aProperty
] & aFlags
) == aFlags
;
131 #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_) \
132 for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_); \
133 *iter_ != eCSSProperty_UNKNOWN; ++iter_)
135 // Keyword/Enum value tables
136 static const PRInt32 kAppearanceKTable
[];
137 static const PRInt32 kAzimuthKTable
[];
138 static const PRInt32 kBackgroundAttachmentKTable
[];
139 static const PRInt32 kBackgroundClipKTable
[];
140 static const PRInt32 kBackgroundInlinePolicyKTable
[];
141 static const PRInt32 kBackgroundOriginKTable
[];
142 static const PRInt32 kBackgroundPositionKTable
[];
143 static const PRInt32 kBackgroundRepeatKTable
[];
144 static const PRInt32 kBorderCollapseKTable
[];
145 static const PRInt32 kBorderColorKTable
[];
146 static const PRInt32 kBorderImageKTable
[];
147 static const PRInt32 kBorderStyleKTable
[];
148 static const PRInt32 kBorderWidthKTable
[];
149 static const PRInt32 kBoxAlignKTable
[];
150 static const PRInt32 kBoxDirectionKTable
[];
151 static const PRInt32 kBoxOrientKTable
[];
152 static const PRInt32 kBoxPackKTable
[];
154 static const PRInt32 kDominantBaselineKTable
[];
155 static const PRInt32 kFillRuleKTable
[];
156 static const PRInt32 kPointerEventsKTable
[];
157 static const PRInt32 kShapeRenderingKTable
[];
158 static const PRInt32 kStrokeLinecapKTable
[];
159 static const PRInt32 kStrokeLinejoinKTable
[];
160 static const PRInt32 kTextAnchorKTable
[];
161 static const PRInt32 kTextRenderingKTable
[];
162 static const PRInt32 kColorInterpolationKTable
[];
164 static const PRInt32 kBoxPropSourceKTable
[];
165 static const PRInt32 kBoxSizingKTable
[];
166 static const PRInt32 kCaptionSideKTable
[];
167 static const PRInt32 kClearKTable
[];
168 static const PRInt32 kColorKTable
[];
169 static const PRInt32 kContentKTable
[];
170 static const PRInt32 kCursorKTable
[];
171 static const PRInt32 kDirectionKTable
[];
172 static const PRInt32 kDisplayKTable
[];
173 static const PRInt32 kElevationKTable
[];
174 static const PRInt32 kEmptyCellsKTable
[];
175 static const PRInt32 kFloatKTable
[];
176 static const PRInt32 kFloatEdgeKTable
[];
177 static const PRInt32 kFontKTable
[];
178 static const PRInt32 kFontSizeKTable
[];
179 static const PRInt32 kFontStretchKTable
[];
180 static const PRInt32 kFontStyleKTable
[];
181 static const PRInt32 kFontVariantKTable
[];
182 static const PRInt32 kFontWeightKTable
[];
183 static const PRInt32 kKeyEquivalentKTable
[];
184 static const PRInt32 kIMEModeKTable
[];
185 static const PRInt32 kListStylePositionKTable
[];
186 static const PRInt32 kListStyleKTable
[];
187 static const PRInt32 kOutlineStyleKTable
[];
188 static const PRInt32 kOutlineColorKTable
[];
189 static const PRInt32 kOverflowKTable
[];
190 static const PRInt32 kOverflowSubKTable
[];
191 static const PRInt32 kPageBreakKTable
[];
192 static const PRInt32 kPageBreakInsideKTable
[];
193 static const PRInt32 kPageMarksKTable
[];
194 static const PRInt32 kPageSizeKTable
[];
195 static const PRInt32 kPitchKTable
[];
196 static const PRInt32 kPositionKTable
[];
197 static const PRInt32 kSpeakKTable
[];
198 static const PRInt32 kSpeakHeaderKTable
[];
199 static const PRInt32 kSpeakNumeralKTable
[];
200 static const PRInt32 kSpeakPunctuationKTable
[];
201 static const PRInt32 kSpeechRateKTable
[];
202 static const PRInt32 kStackSizingKTable
[];
203 static const PRInt32 kTableLayoutKTable
[];
204 static const PRInt32 kTextAlignKTable
[];
205 static const PRInt32 kTextDecorationKTable
[];
206 static const PRInt32 kTextTransformKTable
[];
207 static const PRInt32 kUnicodeBidiKTable
[];
208 static const PRInt32 kUserFocusKTable
[];
209 static const PRInt32 kUserInputKTable
[];
210 static const PRInt32 kUserModifyKTable
[];
211 static const PRInt32 kUserSelectKTable
[];
212 static const PRInt32 kVerticalAlignKTable
[];
213 static const PRInt32 kVisibilityKTable
[];
214 static const PRInt32 kVolumeKTable
[];
215 static const PRInt32 kWhitespaceKTable
[];
216 static const PRInt32 kWidthKTable
[]; // also min-width, max-width
217 static const PRInt32 kWindowShadowKTable
[];
218 static const PRInt32 kWordwrapKTable
[];
221 #endif /* nsCSSProps_h___ */