Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/style/nsCSSProps.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
/*
8
 * methods for dealing with CSS properties and tables of the keyword
9
 * values they accept
10
 */
11
12
#include "nsCSSProps.h"
13
14
#include "mozilla/ArrayUtils.h"
15
#include "mozilla/Casting.h"
16
17
#include "nsCSSKeywords.h"
18
#include "nsLayoutUtils.h"
19
#include "nsStyleConsts.h"
20
#include "nsIWidget.h"
21
#include "nsStyleConsts.h"  // For system widget appearance types
22
23
#include "mozilla/dom/Animation.h"
24
#include "mozilla/dom/AnimationEffectBinding.h" // for PlaybackDirection
25
#include "mozilla/LookAndFeel.h" // for system colors
26
27
#include "nsString.h"
28
#include "nsStaticNameTable.h"
29
30
#include "mozilla/Preferences.h"
31
#include "mozilla/StaticPrefs.h"
32
33
using namespace mozilla;
34
35
typedef nsCSSProps::KTableEntry KTableEntry;
36
37
using namespace mozilla;
38
39
static int32_t gPropertyTableRefCount;
40
static nsStaticCaseInsensitiveNameTable* gFontDescTable;
41
static nsStaticCaseInsensitiveNameTable* gCounterDescTable;
42
static nsDataHashtable<nsCStringHashKey,nsCSSPropertyID>* gPropertyIDLNameTable;
43
44
static const char* const kCSSRawFontDescs[] = {
45
#define CSS_FONT_DESC(name_, method_) #name_,
46
#include "nsCSSFontDescList.h"
47
#undef CSS_FONT_DESC
48
};
49
50
static const char* const kCSSRawCounterDescs[] = {
51
#define CSS_COUNTER_DESC(name_, method_) #name_,
52
#include "nsCSSCounterDescList.h"
53
#undef CSS_COUNTER_DESC
54
};
55
56
static nsStaticCaseInsensitiveNameTable*
57
CreateStaticTable(const char* const aRawTable[], int32_t aLength)
58
6
{
59
6
  auto table = new nsStaticCaseInsensitiveNameTable(aRawTable, aLength);
60
#ifdef DEBUG
61
  // Partially verify the entries.
62
  for (int32_t index = 0; index < aLength; ++index) {
63
    nsAutoCString temp(aRawTable[index]);
64
    MOZ_ASSERT(-1 == temp.FindChar('_'),
65
               "underscore char in case insensitive name table");
66
  }
67
#endif
68
  return table;
69
6
}
70
71
void
72
nsCSSProps::AddRefTable(void)
73
3
{
74
3
  if (0 == gPropertyTableRefCount++) {
75
3
    MOZ_ASSERT(!gFontDescTable, "pre existing array!");
76
3
    MOZ_ASSERT(!gCounterDescTable, "pre existing array!");
77
3
    MOZ_ASSERT(!gPropertyIDLNameTable, "pre existing array!");
78
3
79
3
    gFontDescTable = CreateStaticTable(kCSSRawFontDescs, eCSSFontDesc_COUNT);
80
3
    gCounterDescTable = CreateStaticTable(
81
3
        kCSSRawCounterDescs, eCSSCounterDesc_COUNT);
82
3
83
3
    gPropertyIDLNameTable = new nsDataHashtable<nsCStringHashKey,nsCSSPropertyID>;
84
3
    for (nsCSSPropertyID p = nsCSSPropertyID(0);
85
1.13k
         size_t(p) < ArrayLength(kIDLNameTable);
86
1.13k
         p = nsCSSPropertyID(p + 1)) {
87
1.13k
      if (kIDLNameTable[p]) {
88
1.08k
        gPropertyIDLNameTable->Put(nsDependentCString(kIDLNameTable[p]), p);
89
1.08k
      }
90
1.13k
    }
91
3
92
3
    static bool prefObserversInited = false;
93
3
    if (!prefObserversInited) {
94
3
      prefObserversInited = true;
95
3
      for (const PropertyPref* pref = kPropertyPrefTable;
96
405
           pref->mPropID != eCSSProperty_UNKNOWN; pref++) {
97
402
        nsCString prefName;
98
402
        prefName.AssignLiteral(pref->mPref, strlen(pref->mPref));
99
402
        bool* enabled = &gPropertyEnabled[pref->mPropID];
100
402
        Preferences::AddBoolVarCache(enabled, prefName);
101
402
      }
102
3
    }
103
3
  }
104
3
}
105
106
#undef  DEBUG_SHORTHANDS_CONTAINING
107
108
void
109
nsCSSProps::ReleaseTable(void)
110
0
{
111
0
  if (0 == --gPropertyTableRefCount) {
112
0
    delete gFontDescTable;
113
0
    gFontDescTable = nullptr;
114
0
115
0
    delete gCounterDescTable;
116
0
    gCounterDescTable = nullptr;
117
0
118
0
    delete gPropertyIDLNameTable;
119
0
    gPropertyIDLNameTable = nullptr;
120
0
  }
121
0
}
122
123
/* static */ bool
124
nsCSSProps::IsCustomPropertyName(const nsAString& aProperty)
125
0
{
126
0
  return aProperty.Length() >= CSS_CUSTOM_NAME_PREFIX_LENGTH &&
127
0
         StringBeginsWith(aProperty, NS_LITERAL_STRING("--"));
128
0
}
129
130
nsCSSPropertyID
131
nsCSSProps::LookupPropertyByIDLName(const nsACString& aPropertyIDLName,
132
                                    EnabledState aEnabled)
133
0
{
134
0
  nsCSSPropertyID res;
135
0
  if (!gPropertyIDLNameTable->Get(aPropertyIDLName, &res)) {
136
0
    return eCSSProperty_UNKNOWN;
137
0
  }
138
0
  MOZ_ASSERT(res < eCSSProperty_COUNT);
139
0
  if (!IsEnabled(res, aEnabled)) {
140
0
    return eCSSProperty_UNKNOWN;
141
0
  }
142
0
  return res;
143
0
}
144
145
nsCSSPropertyID
146
nsCSSProps::LookupPropertyByIDLName(const nsAString& aPropertyIDLName,
147
                                    EnabledState aEnabled)
148
0
{
149
0
  MOZ_ASSERT(gPropertyIDLNameTable, "no lookup table, needs addref");
150
0
  return LookupPropertyByIDLName(NS_ConvertUTF16toUTF8(aPropertyIDLName),
151
0
                                 aEnabled);
152
0
}
153
154
nsCSSFontDesc
155
nsCSSProps::LookupFontDesc(const nsAString& aFontDesc)
156
0
{
157
0
  MOZ_ASSERT(gFontDescTable, "no lookup table, needs addref");
158
0
  nsCSSFontDesc which = nsCSSFontDesc(gFontDescTable->Lookup(aFontDesc));
159
0
160
0
  if (which == eCSSFontDesc_Display &&
161
0
      !StaticPrefs::layout_css_font_display_enabled()) {
162
0
    which = eCSSFontDesc_UNKNOWN;
163
0
  }
164
0
  return which;
165
0
}
166
167
const nsCString&
168
nsCSSProps::GetStringValue(nsCSSFontDesc aFontDescID)
169
0
{
170
0
  MOZ_ASSERT(gFontDescTable, "no lookup table, needs addref");
171
0
  if (gFontDescTable) {
172
0
    return gFontDescTable->GetStringValue(int32_t(aFontDescID));
173
0
  } else {
174
0
    static nsDependentCString sNullStr("");
175
0
    return sNullStr;
176
0
  }
177
0
}
178
179
const nsCString&
180
nsCSSProps::GetStringValue(nsCSSCounterDesc aCounterDesc)
181
0
{
182
0
  MOZ_ASSERT(gCounterDescTable, "no lookup table, needs addref");
183
0
  if (gCounterDescTable) {
184
0
    return gCounterDescTable->GetStringValue(int32_t(aCounterDesc));
185
0
  } else {
186
0
    static nsDependentCString sNullStr("");
187
0
    return sNullStr;
188
0
  }
189
0
}
190
191
/***************************************************************************/
192
193
const KTableEntry nsCSSProps::kTransformStyleKTable[] = {
194
  { eCSSKeyword_flat, NS_STYLE_TRANSFORM_STYLE_FLAT },
195
  { eCSSKeyword_preserve_3d, NS_STYLE_TRANSFORM_STYLE_PRESERVE_3D },
196
  { eCSSKeyword_UNKNOWN, -1 }
197
};
198
199
const KTableEntry nsCSSProps::kImageLayerRepeatKTable[] = {
200
  { eCSSKeyword_no_repeat,  StyleImageLayerRepeat::NoRepeat },
201
  { eCSSKeyword_repeat,     StyleImageLayerRepeat::Repeat },
202
  { eCSSKeyword_repeat_x,   StyleImageLayerRepeat::RepeatX },
203
  { eCSSKeyword_repeat_y,   StyleImageLayerRepeat::RepeatY },
204
  { eCSSKeyword_round,      StyleImageLayerRepeat::Round},
205
  { eCSSKeyword_space,      StyleImageLayerRepeat::Space},
206
  { eCSSKeyword_UNKNOWN, -1 }
207
};
208
209
const KTableEntry nsCSSProps::kBorderImageRepeatKTable[] = {
210
  { eCSSKeyword_stretch, StyleBorderImageRepeat::Stretch },
211
  { eCSSKeyword_repeat, StyleBorderImageRepeat::Repeat },
212
  { eCSSKeyword_round, StyleBorderImageRepeat::Round },
213
  { eCSSKeyword_space, StyleBorderImageRepeat::Space },
214
  { eCSSKeyword_UNKNOWN, -1 }
215
};
216
217
const KTableEntry nsCSSProps::kBorderStyleKTable[] = {
218
  { eCSSKeyword_none,   NS_STYLE_BORDER_STYLE_NONE },
219
  { eCSSKeyword_hidden, NS_STYLE_BORDER_STYLE_HIDDEN },
220
  { eCSSKeyword_dotted, NS_STYLE_BORDER_STYLE_DOTTED },
221
  { eCSSKeyword_dashed, NS_STYLE_BORDER_STYLE_DASHED },
222
  { eCSSKeyword_solid,  NS_STYLE_BORDER_STYLE_SOLID },
223
  { eCSSKeyword_double, NS_STYLE_BORDER_STYLE_DOUBLE },
224
  { eCSSKeyword_groove, NS_STYLE_BORDER_STYLE_GROOVE },
225
  { eCSSKeyword_ridge,  NS_STYLE_BORDER_STYLE_RIDGE },
226
  { eCSSKeyword_inset,  NS_STYLE_BORDER_STYLE_INSET },
227
  { eCSSKeyword_outset, NS_STYLE_BORDER_STYLE_OUTSET },
228
  { eCSSKeyword_UNKNOWN, -1 }
229
};
230
231
const KTableEntry nsCSSProps::kBoxShadowTypeKTable[] = {
232
  { eCSSKeyword_inset, uint8_t(StyleBoxShadowType::Inset) },
233
  { eCSSKeyword_UNKNOWN, -1 }
234
};
235
236
const KTableEntry nsCSSProps::kCursorKTable[] = {
237
  // CSS 2.0
238
  { eCSSKeyword_auto, NS_STYLE_CURSOR_AUTO },
239
  { eCSSKeyword_crosshair, NS_STYLE_CURSOR_CROSSHAIR },
240
  { eCSSKeyword_default, NS_STYLE_CURSOR_DEFAULT },
241
  { eCSSKeyword_pointer, NS_STYLE_CURSOR_POINTER },
242
  { eCSSKeyword_move, NS_STYLE_CURSOR_MOVE },
243
  { eCSSKeyword_e_resize, NS_STYLE_CURSOR_E_RESIZE },
244
  { eCSSKeyword_ne_resize, NS_STYLE_CURSOR_NE_RESIZE },
245
  { eCSSKeyword_nw_resize, NS_STYLE_CURSOR_NW_RESIZE },
246
  { eCSSKeyword_n_resize, NS_STYLE_CURSOR_N_RESIZE },
247
  { eCSSKeyword_se_resize, NS_STYLE_CURSOR_SE_RESIZE },
248
  { eCSSKeyword_sw_resize, NS_STYLE_CURSOR_SW_RESIZE },
249
  { eCSSKeyword_s_resize, NS_STYLE_CURSOR_S_RESIZE },
250
  { eCSSKeyword_w_resize, NS_STYLE_CURSOR_W_RESIZE },
251
  { eCSSKeyword_text, NS_STYLE_CURSOR_TEXT },
252
  { eCSSKeyword_wait, NS_STYLE_CURSOR_WAIT },
253
  { eCSSKeyword_help, NS_STYLE_CURSOR_HELP },
254
  // CSS 2.1
255
  { eCSSKeyword_progress, NS_STYLE_CURSOR_SPINNING },
256
  // CSS3 basic user interface module
257
  { eCSSKeyword_copy, NS_STYLE_CURSOR_COPY },
258
  { eCSSKeyword_alias, NS_STYLE_CURSOR_ALIAS },
259
  { eCSSKeyword_context_menu, NS_STYLE_CURSOR_CONTEXT_MENU },
260
  { eCSSKeyword_cell, NS_STYLE_CURSOR_CELL },
261
  { eCSSKeyword_not_allowed, NS_STYLE_CURSOR_NOT_ALLOWED },
262
  { eCSSKeyword_col_resize, NS_STYLE_CURSOR_COL_RESIZE },
263
  { eCSSKeyword_row_resize, NS_STYLE_CURSOR_ROW_RESIZE },
264
  { eCSSKeyword_no_drop, NS_STYLE_CURSOR_NO_DROP },
265
  { eCSSKeyword_vertical_text, NS_STYLE_CURSOR_VERTICAL_TEXT },
266
  { eCSSKeyword_all_scroll, NS_STYLE_CURSOR_ALL_SCROLL },
267
  { eCSSKeyword_nesw_resize, NS_STYLE_CURSOR_NESW_RESIZE },
268
  { eCSSKeyword_nwse_resize, NS_STYLE_CURSOR_NWSE_RESIZE },
269
  { eCSSKeyword_ns_resize, NS_STYLE_CURSOR_NS_RESIZE },
270
  { eCSSKeyword_ew_resize, NS_STYLE_CURSOR_EW_RESIZE },
271
  { eCSSKeyword_none, NS_STYLE_CURSOR_NONE },
272
  { eCSSKeyword_grab, NS_STYLE_CURSOR_GRAB },
273
  { eCSSKeyword_grabbing, NS_STYLE_CURSOR_GRABBING },
274
  { eCSSKeyword_zoom_in, NS_STYLE_CURSOR_ZOOM_IN },
275
  { eCSSKeyword_zoom_out, NS_STYLE_CURSOR_ZOOM_OUT },
276
  // -moz- prefixed vendor specific
277
  { eCSSKeyword__moz_grab, NS_STYLE_CURSOR_GRAB },
278
  { eCSSKeyword__moz_grabbing, NS_STYLE_CURSOR_GRABBING },
279
  { eCSSKeyword__moz_zoom_in, NS_STYLE_CURSOR_ZOOM_IN },
280
  { eCSSKeyword__moz_zoom_out, NS_STYLE_CURSOR_ZOOM_OUT },
281
  { eCSSKeyword_UNKNOWN, -1 }
282
};
283
284
KTableEntry nsCSSProps::kDisplayKTable[] = {
285
  { eCSSKeyword_none,                StyleDisplay::None },
286
  { eCSSKeyword_inline,              StyleDisplay::Inline },
287
  { eCSSKeyword_block,               StyleDisplay::Block },
288
  { eCSSKeyword_inline_block,        StyleDisplay::InlineBlock },
289
  { eCSSKeyword_list_item,           StyleDisplay::ListItem },
290
  { eCSSKeyword_table,               StyleDisplay::Table },
291
  { eCSSKeyword_inline_table,        StyleDisplay::InlineTable },
292
  { eCSSKeyword_table_row_group,     StyleDisplay::TableRowGroup },
293
  { eCSSKeyword_table_header_group,  StyleDisplay::TableHeaderGroup },
294
  { eCSSKeyword_table_footer_group,  StyleDisplay::TableFooterGroup },
295
  { eCSSKeyword_table_row,           StyleDisplay::TableRow },
296
  { eCSSKeyword_table_column_group,  StyleDisplay::TableColumnGroup },
297
  { eCSSKeyword_table_column,        StyleDisplay::TableColumn },
298
  { eCSSKeyword_table_cell,          StyleDisplay::TableCell },
299
  { eCSSKeyword_table_caption,       StyleDisplay::TableCaption },
300
  // Make sure this is kept in sync with the code in
301
  // nsCSSFrameConstructor::ConstructXULFrame
302
  { eCSSKeyword__moz_box,            StyleDisplay::MozBox },
303
  { eCSSKeyword__moz_inline_box,     StyleDisplay::MozInlineBox },
304
#ifdef MOZ_XUL
305
  { eCSSKeyword__moz_grid,           StyleDisplay::MozGrid },
306
  { eCSSKeyword__moz_inline_grid,    StyleDisplay::MozInlineGrid },
307
  { eCSSKeyword__moz_grid_group,     StyleDisplay::MozGridGroup },
308
  { eCSSKeyword__moz_grid_line,      StyleDisplay::MozGridLine },
309
  { eCSSKeyword__moz_stack,          StyleDisplay::MozStack },
310
  { eCSSKeyword__moz_inline_stack,   StyleDisplay::MozInlineStack },
311
  { eCSSKeyword__moz_deck,           StyleDisplay::MozDeck },
312
  { eCSSKeyword__moz_popup,          StyleDisplay::MozPopup },
313
  { eCSSKeyword__moz_groupbox,       StyleDisplay::MozGroupbox },
314
#endif
315
  { eCSSKeyword_flex,                StyleDisplay::Flex },
316
  { eCSSKeyword_inline_flex,         StyleDisplay::InlineFlex },
317
  { eCSSKeyword_ruby,                StyleDisplay::Ruby },
318
  { eCSSKeyword_ruby_base,           StyleDisplay::RubyBase },
319
  { eCSSKeyword_ruby_base_container, StyleDisplay::RubyBaseContainer },
320
  { eCSSKeyword_ruby_text,           StyleDisplay::RubyText },
321
  { eCSSKeyword_ruby_text_container, StyleDisplay::RubyTextContainer },
322
  { eCSSKeyword_grid,                StyleDisplay::Grid },
323
  { eCSSKeyword_inline_grid,         StyleDisplay::InlineGrid },
324
  // The next 4 entries are controlled by the layout.css.prefixes.webkit pref.
325
  { eCSSKeyword__webkit_box,         StyleDisplay::WebkitBox },
326
  { eCSSKeyword__webkit_inline_box,  StyleDisplay::WebkitInlineBox },
327
  { eCSSKeyword__webkit_flex,        StyleDisplay::Flex },
328
  { eCSSKeyword__webkit_inline_flex, StyleDisplay::InlineFlex },
329
  { eCSSKeyword_contents,            StyleDisplay::Contents },
330
  { eCSSKeyword_flow_root,           StyleDisplay::FlowRoot },
331
  { eCSSKeyword_UNKNOWN,             -1 }
332
};
333
334
const KTableEntry nsCSSProps::kAlignAllKeywords[] = {
335
  { eCSSKeyword_auto,          NS_STYLE_ALIGN_AUTO },
336
  { eCSSKeyword_normal,        NS_STYLE_ALIGN_NORMAL },
337
  { eCSSKeyword_start,         NS_STYLE_ALIGN_START },
338
  { eCSSKeyword_end,           NS_STYLE_ALIGN_END },
339
  { eCSSKeyword_flex_start,    NS_STYLE_ALIGN_FLEX_START },
340
  { eCSSKeyword_flex_end,      NS_STYLE_ALIGN_FLEX_END },
341
  { eCSSKeyword_center,        NS_STYLE_ALIGN_CENTER },
342
  { eCSSKeyword_left,          NS_STYLE_ALIGN_LEFT },
343
  { eCSSKeyword_right,         NS_STYLE_ALIGN_RIGHT },
344
  { eCSSKeyword_baseline,      NS_STYLE_ALIGN_BASELINE },
345
  // Also "first/last baseline"; see nsCSSValue::AppendAlignJustifyValueToString
346
  { eCSSKeyword_stretch,       NS_STYLE_ALIGN_STRETCH },
347
  { eCSSKeyword_self_start,    NS_STYLE_ALIGN_SELF_START },
348
  { eCSSKeyword_self_end,      NS_STYLE_ALIGN_SELF_END },
349
  { eCSSKeyword_space_between, NS_STYLE_ALIGN_SPACE_BETWEEN },
350
  { eCSSKeyword_space_around,  NS_STYLE_ALIGN_SPACE_AROUND },
351
  { eCSSKeyword_space_evenly,  NS_STYLE_ALIGN_SPACE_EVENLY },
352
  { eCSSKeyword_legacy,        NS_STYLE_ALIGN_LEGACY },
353
  { eCSSKeyword_safe,          NS_STYLE_ALIGN_SAFE },
354
  { eCSSKeyword_unsafe,        NS_STYLE_ALIGN_UNSAFE },
355
  { eCSSKeyword_UNKNOWN,       -1 }
356
};
357
358
const KTableEntry nsCSSProps::kAlignOverflowPosition[] = {
359
  { eCSSKeyword_unsafe,        NS_STYLE_ALIGN_UNSAFE },
360
  { eCSSKeyword_safe,          NS_STYLE_ALIGN_SAFE },
361
  { eCSSKeyword_UNKNOWN,       -1 }
362
};
363
364
const KTableEntry nsCSSProps::kAlignSelfPosition[] = {
365
  { eCSSKeyword_start,         NS_STYLE_ALIGN_START },
366
  { eCSSKeyword_end,           NS_STYLE_ALIGN_END },
367
  { eCSSKeyword_flex_start,    NS_STYLE_ALIGN_FLEX_START },
368
  { eCSSKeyword_flex_end,      NS_STYLE_ALIGN_FLEX_END },
369
  { eCSSKeyword_center,        NS_STYLE_ALIGN_CENTER },
370
  { eCSSKeyword_left,          NS_STYLE_ALIGN_LEFT },
371
  { eCSSKeyword_right,         NS_STYLE_ALIGN_RIGHT },
372
  { eCSSKeyword_self_start,    NS_STYLE_ALIGN_SELF_START },
373
  { eCSSKeyword_self_end,      NS_STYLE_ALIGN_SELF_END },
374
  { eCSSKeyword_UNKNOWN,       -1 }
375
};
376
377
const KTableEntry nsCSSProps::kAlignLegacy[] = {
378
  { eCSSKeyword_legacy,        NS_STYLE_ALIGN_LEGACY },
379
  { eCSSKeyword_UNKNOWN,       -1 }
380
};
381
382
const KTableEntry nsCSSProps::kAlignLegacyPosition[] = {
383
  { eCSSKeyword_center,        NS_STYLE_ALIGN_CENTER },
384
  { eCSSKeyword_left,          NS_STYLE_ALIGN_LEFT },
385
  { eCSSKeyword_right,         NS_STYLE_ALIGN_RIGHT },
386
  { eCSSKeyword_UNKNOWN,       -1 }
387
};
388
389
const KTableEntry nsCSSProps::kAlignAutoNormalStretchBaseline[] = {
390
  { eCSSKeyword_auto,          NS_STYLE_ALIGN_AUTO },
391
  { eCSSKeyword_normal,        NS_STYLE_ALIGN_NORMAL },
392
  { eCSSKeyword_stretch,       NS_STYLE_ALIGN_STRETCH },
393
  { eCSSKeyword_baseline,      NS_STYLE_ALIGN_BASELINE },
394
  // Also "first baseline" & "last baseline"; see CSSParserImpl::ParseAlignEnum
395
  { eCSSKeyword_UNKNOWN,       -1 }
396
};
397
398
const KTableEntry nsCSSProps::kAlignNormalStretchBaseline[] = {
399
  { eCSSKeyword_normal,        NS_STYLE_ALIGN_NORMAL },
400
  { eCSSKeyword_stretch,       NS_STYLE_ALIGN_STRETCH },
401
  { eCSSKeyword_baseline,      NS_STYLE_ALIGN_BASELINE },
402
  // Also "first baseline" & "last baseline"; see CSSParserImpl::ParseAlignEnum
403
  { eCSSKeyword_UNKNOWN,       -1 }
404
};
405
406
const KTableEntry nsCSSProps::kAlignNormalBaseline[] = {
407
  { eCSSKeyword_normal,        NS_STYLE_ALIGN_NORMAL },
408
  { eCSSKeyword_baseline,      NS_STYLE_ALIGN_BASELINE },
409
  // Also "first baseline" & "last baseline"; see CSSParserImpl::ParseAlignEnum
410
  { eCSSKeyword_UNKNOWN,       -1 }
411
};
412
413
const KTableEntry nsCSSProps::kAlignContentDistribution[] = {
414
  { eCSSKeyword_stretch,       NS_STYLE_ALIGN_STRETCH },
415
  { eCSSKeyword_space_between, NS_STYLE_ALIGN_SPACE_BETWEEN },
416
  { eCSSKeyword_space_around,  NS_STYLE_ALIGN_SPACE_AROUND },
417
  { eCSSKeyword_space_evenly,  NS_STYLE_ALIGN_SPACE_EVENLY },
418
  { eCSSKeyword_UNKNOWN,       -1 }
419
};
420
421
const KTableEntry nsCSSProps::kAlignContentPosition[] = {
422
  { eCSSKeyword_start,         NS_STYLE_ALIGN_START },
423
  { eCSSKeyword_end,           NS_STYLE_ALIGN_END },
424
  { eCSSKeyword_flex_start,    NS_STYLE_ALIGN_FLEX_START },
425
  { eCSSKeyword_flex_end,      NS_STYLE_ALIGN_FLEX_END },
426
  { eCSSKeyword_center,        NS_STYLE_ALIGN_CENTER },
427
  { eCSSKeyword_left,          NS_STYLE_ALIGN_LEFT },
428
  { eCSSKeyword_right,         NS_STYLE_ALIGN_RIGHT },
429
  { eCSSKeyword_UNKNOWN,       -1 }
430
};
431
432
// <NOTE> these are only used for auto-completion, not parsing:
433
const KTableEntry nsCSSProps::kAutoCompletionAlignJustifySelf[] = {
434
  { eCSSKeyword_auto,          NS_STYLE_ALIGN_AUTO },
435
  { eCSSKeyword_normal,        NS_STYLE_ALIGN_NORMAL },
436
  { eCSSKeyword_stretch,       NS_STYLE_ALIGN_STRETCH },
437
  { eCSSKeyword_baseline,      NS_STYLE_ALIGN_BASELINE },
438
  { eCSSKeyword_last_baseline, NS_STYLE_ALIGN_LAST_BASELINE },
439
  { eCSSKeyword_start,         NS_STYLE_ALIGN_START },
440
  { eCSSKeyword_end,           NS_STYLE_ALIGN_END },
441
  { eCSSKeyword_flex_start,    NS_STYLE_ALIGN_FLEX_START },
442
  { eCSSKeyword_flex_end,      NS_STYLE_ALIGN_FLEX_END },
443
  { eCSSKeyword_center,        NS_STYLE_ALIGN_CENTER },
444
  { eCSSKeyword_left,          NS_STYLE_ALIGN_LEFT },
445
  { eCSSKeyword_right,         NS_STYLE_ALIGN_RIGHT },
446
  { eCSSKeyword_self_start,    NS_STYLE_ALIGN_SELF_START },
447
  { eCSSKeyword_self_end,      NS_STYLE_ALIGN_SELF_END },
448
  { eCSSKeyword_UNKNOWN,       -1 }
449
};
450
451
const KTableEntry nsCSSProps::kAutoCompletionAlignItems[] = {
452
  // Intentionally no 'auto' here.
453
  { eCSSKeyword_normal,        NS_STYLE_ALIGN_NORMAL },
454
  { eCSSKeyword_stretch,       NS_STYLE_ALIGN_STRETCH },
455
  { eCSSKeyword_baseline,      NS_STYLE_ALIGN_BASELINE },
456
  { eCSSKeyword_last_baseline, NS_STYLE_ALIGN_LAST_BASELINE },
457
  { eCSSKeyword_start,         NS_STYLE_ALIGN_START },
458
  { eCSSKeyword_end,           NS_STYLE_ALIGN_END },
459
  { eCSSKeyword_flex_start,    NS_STYLE_ALIGN_FLEX_START },
460
  { eCSSKeyword_flex_end,      NS_STYLE_ALIGN_FLEX_END },
461
  { eCSSKeyword_center,        NS_STYLE_ALIGN_CENTER },
462
  { eCSSKeyword_left,          NS_STYLE_ALIGN_LEFT },
463
  { eCSSKeyword_right,         NS_STYLE_ALIGN_RIGHT },
464
  { eCSSKeyword_self_start,    NS_STYLE_ALIGN_SELF_START },
465
  { eCSSKeyword_self_end,      NS_STYLE_ALIGN_SELF_END },
466
  { eCSSKeyword_UNKNOWN,       -1 }
467
};
468
469
const KTableEntry nsCSSProps::kAutoCompletionAlignJustifyContent[] = {
470
  // Intentionally no 'auto' here.
471
  { eCSSKeyword_normal,        NS_STYLE_ALIGN_NORMAL },
472
  { eCSSKeyword_baseline,      NS_STYLE_ALIGN_BASELINE },
473
  { eCSSKeyword_last_baseline, NS_STYLE_ALIGN_LAST_BASELINE },
474
  { eCSSKeyword_stretch,       NS_STYLE_ALIGN_STRETCH },
475
  { eCSSKeyword_space_between, NS_STYLE_ALIGN_SPACE_BETWEEN },
476
  { eCSSKeyword_space_around,  NS_STYLE_ALIGN_SPACE_AROUND },
477
  { eCSSKeyword_space_evenly,  NS_STYLE_ALIGN_SPACE_EVENLY },
478
  { eCSSKeyword_start,         NS_STYLE_ALIGN_START },
479
  { eCSSKeyword_end,           NS_STYLE_ALIGN_END },
480
  { eCSSKeyword_flex_start,    NS_STYLE_ALIGN_FLEX_START },
481
  { eCSSKeyword_flex_end,      NS_STYLE_ALIGN_FLEX_END },
482
  { eCSSKeyword_center,        NS_STYLE_ALIGN_CENTER },
483
  { eCSSKeyword_left,          NS_STYLE_ALIGN_LEFT },
484
  { eCSSKeyword_right,         NS_STYLE_ALIGN_RIGHT },
485
  { eCSSKeyword_UNKNOWN,       -1 }
486
};
487
// </NOTE>
488
489
const KTableEntry nsCSSProps::kFontSmoothingKTable[] = {
490
  { eCSSKeyword_auto, NS_FONT_SMOOTHING_AUTO },
491
  { eCSSKeyword_grayscale, NS_FONT_SMOOTHING_GRAYSCALE },
492
  { eCSSKeyword_UNKNOWN, -1 }
493
};
494
495
const KTableEntry nsCSSProps::kGridAutoFlowKTable[] = {
496
  { eCSSKeyword_row, NS_STYLE_GRID_AUTO_FLOW_ROW },
497
  { eCSSKeyword_column, NS_STYLE_GRID_AUTO_FLOW_COLUMN },
498
  { eCSSKeyword_dense, NS_STYLE_GRID_AUTO_FLOW_DENSE },
499
  { eCSSKeyword_UNKNOWN, -1 }
500
};
501
502
const KTableEntry nsCSSProps::kGridTrackBreadthKTable[] = {
503
  { eCSSKeyword_min_content, StyleGridTrackBreadth::MinContent },
504
  { eCSSKeyword_max_content, StyleGridTrackBreadth::MaxContent },
505
  { eCSSKeyword_UNKNOWN, -1 }
506
};
507
508
const KTableEntry nsCSSProps::kLineHeightKTable[] = {
509
  // -moz- prefixed, intended for internal use for single-line controls
510
  { eCSSKeyword__moz_block_height, NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT },
511
  { eCSSKeyword_UNKNOWN, -1 }
512
};
513
514
const KTableEntry nsCSSProps::kContainKTable[] = {
515
  { eCSSKeyword_none,    NS_STYLE_CONTAIN_NONE },
516
  { eCSSKeyword_strict,  NS_STYLE_CONTAIN_STRICT },
517
  { eCSSKeyword_content, NS_STYLE_CONTAIN_CONTENT },
518
  { eCSSKeyword_layout,  NS_STYLE_CONTAIN_LAYOUT },
519
  { eCSSKeyword_style,   NS_STYLE_CONTAIN_STYLE },
520
  { eCSSKeyword_paint,   NS_STYLE_CONTAIN_PAINT },
521
  { eCSSKeyword_size,    NS_STYLE_CONTAIN_SIZE },
522
  { eCSSKeyword_UNKNOWN, -1 }
523
};
524
525
// Same as kBorderStyleKTable except 'hidden'.
526
const KTableEntry nsCSSProps::kOutlineStyleKTable[] = {
527
  { eCSSKeyword_none,   NS_STYLE_BORDER_STYLE_NONE },
528
  { eCSSKeyword_auto,   NS_STYLE_BORDER_STYLE_AUTO },
529
  { eCSSKeyword_dotted, NS_STYLE_BORDER_STYLE_DOTTED },
530
  { eCSSKeyword_dashed, NS_STYLE_BORDER_STYLE_DASHED },
531
  { eCSSKeyword_solid,  NS_STYLE_BORDER_STYLE_SOLID },
532
  { eCSSKeyword_double, NS_STYLE_BORDER_STYLE_DOUBLE },
533
  { eCSSKeyword_groove, NS_STYLE_BORDER_STYLE_GROOVE },
534
  { eCSSKeyword_ridge,  NS_STYLE_BORDER_STYLE_RIDGE },
535
  { eCSSKeyword_inset,  NS_STYLE_BORDER_STYLE_INSET },
536
  { eCSSKeyword_outset, NS_STYLE_BORDER_STYLE_OUTSET },
537
  { eCSSKeyword_UNKNOWN, -1 }
538
};
539
540
const KTableEntry nsCSSProps::kOverflowKTable[] = {
541
  { eCSSKeyword_auto, NS_STYLE_OVERFLOW_AUTO },
542
  { eCSSKeyword_visible, NS_STYLE_OVERFLOW_VISIBLE },
543
  { eCSSKeyword_hidden, NS_STYLE_OVERFLOW_HIDDEN },
544
  { eCSSKeyword_scroll, NS_STYLE_OVERFLOW_SCROLL },
545
  // Deprecated:
546
  { eCSSKeyword__moz_scrollbars_none, NS_STYLE_OVERFLOW_HIDDEN },
547
  { eCSSKeyword__moz_scrollbars_horizontal, NS_STYLE_OVERFLOW_SCROLLBARS_HORIZONTAL },
548
  { eCSSKeyword__moz_scrollbars_vertical, NS_STYLE_OVERFLOW_SCROLLBARS_VERTICAL },
549
  { eCSSKeyword__moz_hidden_unscrollable, NS_STYLE_OVERFLOW_CLIP },
550
  { eCSSKeyword_UNKNOWN, -1 }
551
};
552
553
const KTableEntry nsCSSProps::kOverflowClipBoxKTable[] = {
554
  { eCSSKeyword_padding_box, NS_STYLE_OVERFLOW_CLIP_BOX_PADDING_BOX },
555
  { eCSSKeyword_content_box, NS_STYLE_OVERFLOW_CLIP_BOX_CONTENT_BOX },
556
  { eCSSKeyword_UNKNOWN, -1 }
557
};
558
559
const KTableEntry nsCSSProps::kOverflowSubKTable[] = {
560
  { eCSSKeyword_auto, NS_STYLE_OVERFLOW_AUTO },
561
  { eCSSKeyword_visible, NS_STYLE_OVERFLOW_VISIBLE },
562
  { eCSSKeyword_hidden, NS_STYLE_OVERFLOW_HIDDEN },
563
  { eCSSKeyword_scroll, NS_STYLE_OVERFLOW_SCROLL },
564
  // Deprecated:
565
  { eCSSKeyword__moz_hidden_unscrollable, NS_STYLE_OVERFLOW_CLIP },
566
  { eCSSKeyword_UNKNOWN, -1 }
567
};
568
569
const KTableEntry nsCSSProps::kRadialGradientSizeKTable[] = {
570
  { eCSSKeyword_closest_side,    NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE },
571
  { eCSSKeyword_closest_corner,  NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER },
572
  { eCSSKeyword_farthest_side,   NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE },
573
  { eCSSKeyword_farthest_corner, NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER },
574
  { eCSSKeyword_UNKNOWN,         -1 }
575
};
576
577
const KTableEntry nsCSSProps::kOverscrollBehaviorKTable[] = {
578
  { eCSSKeyword_auto,       StyleOverscrollBehavior::Auto },
579
  { eCSSKeyword_contain,    StyleOverscrollBehavior::Contain },
580
  { eCSSKeyword_none,       StyleOverscrollBehavior::None },
581
  { eCSSKeyword_UNKNOWN,    -1 }
582
};
583
584
const KTableEntry nsCSSProps::kScrollSnapTypeKTable[] = {
585
  { eCSSKeyword_none,      NS_STYLE_SCROLL_SNAP_TYPE_NONE },
586
  { eCSSKeyword_mandatory, NS_STYLE_SCROLL_SNAP_TYPE_MANDATORY },
587
  { eCSSKeyword_proximity, NS_STYLE_SCROLL_SNAP_TYPE_PROXIMITY },
588
  { eCSSKeyword_UNKNOWN,   -1 }
589
};
590
591
KTableEntry nsCSSProps::kTextAlignKTable[] = {
592
  { eCSSKeyword_left, NS_STYLE_TEXT_ALIGN_LEFT },
593
  { eCSSKeyword_right, NS_STYLE_TEXT_ALIGN_RIGHT },
594
  { eCSSKeyword_center, NS_STYLE_TEXT_ALIGN_CENTER },
595
  { eCSSKeyword_justify, NS_STYLE_TEXT_ALIGN_JUSTIFY },
596
  { eCSSKeyword__moz_center, NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
597
  { eCSSKeyword__moz_right, NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
598
  { eCSSKeyword__moz_left, NS_STYLE_TEXT_ALIGN_MOZ_LEFT },
599
  { eCSSKeyword_start, NS_STYLE_TEXT_ALIGN_START },
600
  { eCSSKeyword_end, NS_STYLE_TEXT_ALIGN_END },
601
  { eCSSKeyword_unsafe, NS_STYLE_TEXT_ALIGN_UNSAFE },
602
  { eCSSKeyword_match_parent, NS_STYLE_TEXT_ALIGN_MATCH_PARENT },
603
  { eCSSKeyword_UNKNOWN, -1 }
604
};
605
606
const KTableEntry nsCSSProps::kTextDecorationLineKTable[] = {
607
  { eCSSKeyword_none, NS_STYLE_TEXT_DECORATION_LINE_NONE },
608
  { eCSSKeyword_underline, NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE },
609
  { eCSSKeyword_overline, NS_STYLE_TEXT_DECORATION_LINE_OVERLINE },
610
  { eCSSKeyword_line_through, NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH },
611
  { eCSSKeyword_blink, NS_STYLE_TEXT_DECORATION_LINE_BLINK },
612
  { eCSSKeyword_UNKNOWN, -1 }
613
};
614
615
const KTableEntry nsCSSProps::kTextDecorationStyleKTable[] = {
616
  { eCSSKeyword__moz_none, NS_STYLE_TEXT_DECORATION_STYLE_NONE },
617
  { eCSSKeyword_solid, NS_STYLE_TEXT_DECORATION_STYLE_SOLID },
618
  { eCSSKeyword_double, NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE },
619
  { eCSSKeyword_dotted, NS_STYLE_TEXT_DECORATION_STYLE_DOTTED },
620
  { eCSSKeyword_dashed, NS_STYLE_TEXT_DECORATION_STYLE_DASHED },
621
  { eCSSKeyword_wavy, NS_STYLE_TEXT_DECORATION_STYLE_WAVY },
622
  { eCSSKeyword_UNKNOWN, -1 }
623
};
624
625
const KTableEntry nsCSSProps::kTextEmphasisStyleShapeKTable[] = {
626
  { eCSSKeyword_dot, NS_STYLE_TEXT_EMPHASIS_STYLE_DOT },
627
  { eCSSKeyword_circle, NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE },
628
  { eCSSKeyword_double_circle, NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE },
629
  { eCSSKeyword_triangle, NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE },
630
  { eCSSKeyword_sesame, NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME} ,
631
  { eCSSKeyword_UNKNOWN, -1 }
632
};
633
634
const KTableEntry nsCSSProps::kTextOverflowKTable[] = {
635
  { eCSSKeyword_clip, NS_STYLE_TEXT_OVERFLOW_CLIP },
636
  { eCSSKeyword_ellipsis, NS_STYLE_TEXT_OVERFLOW_ELLIPSIS },
637
  { eCSSKeyword_UNKNOWN, -1 }
638
};
639
640
const KTableEntry nsCSSProps::kTouchActionKTable[] = {
641
  { eCSSKeyword_none,         NS_STYLE_TOUCH_ACTION_NONE },
642
  { eCSSKeyword_auto,         NS_STYLE_TOUCH_ACTION_AUTO },
643
  { eCSSKeyword_pan_x,        NS_STYLE_TOUCH_ACTION_PAN_X },
644
  { eCSSKeyword_pan_y,        NS_STYLE_TOUCH_ACTION_PAN_Y },
645
  { eCSSKeyword_manipulation, NS_STYLE_TOUCH_ACTION_MANIPULATION },
646
  { eCSSKeyword_UNKNOWN,      -1 }
647
};
648
649
const KTableEntry nsCSSProps::kTransitionTimingFunctionKTable[] = {
650
  { eCSSKeyword_ease, NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE },
651
  { eCSSKeyword_linear, NS_STYLE_TRANSITION_TIMING_FUNCTION_LINEAR },
652
  { eCSSKeyword_ease_in, NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE_IN },
653
  { eCSSKeyword_ease_out, NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE_OUT },
654
  { eCSSKeyword_ease_in_out, NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE_IN_OUT },
655
  { eCSSKeyword_step_start, NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_START },
656
  { eCSSKeyword_step_end, NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_END },
657
  { eCSSKeyword_UNKNOWN, -1 }
658
};
659
660
const KTableEntry nsCSSProps::kVerticalAlignKTable[] = {
661
  { eCSSKeyword_baseline, NS_STYLE_VERTICAL_ALIGN_BASELINE },
662
  { eCSSKeyword_sub, NS_STYLE_VERTICAL_ALIGN_SUB },
663
  { eCSSKeyword_super, NS_STYLE_VERTICAL_ALIGN_SUPER },
664
  { eCSSKeyword_top, NS_STYLE_VERTICAL_ALIGN_TOP },
665
  { eCSSKeyword_text_top, NS_STYLE_VERTICAL_ALIGN_TEXT_TOP },
666
  { eCSSKeyword_middle, NS_STYLE_VERTICAL_ALIGN_MIDDLE },
667
  { eCSSKeyword__moz_middle_with_baseline, NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE },
668
  { eCSSKeyword_bottom, NS_STYLE_VERTICAL_ALIGN_BOTTOM },
669
  { eCSSKeyword_text_bottom, NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM },
670
  { eCSSKeyword_UNKNOWN, -1 }
671
};
672
673
const KTableEntry nsCSSProps::kWidthKTable[] = {
674
  { eCSSKeyword__moz_max_content, NS_STYLE_WIDTH_MAX_CONTENT },
675
  { eCSSKeyword__moz_min_content, NS_STYLE_WIDTH_MIN_CONTENT },
676
  { eCSSKeyword__moz_fit_content, NS_STYLE_WIDTH_FIT_CONTENT },
677
  { eCSSKeyword__moz_available, NS_STYLE_WIDTH_AVAILABLE },
678
  { eCSSKeyword_UNKNOWN, -1 }
679
};
680
681
// This must be the same as kWidthKTable, but just with 'content' added:
682
const KTableEntry nsCSSProps::kFlexBasisKTable[] = {
683
  { eCSSKeyword__moz_max_content, NS_STYLE_WIDTH_MAX_CONTENT },
684
  { eCSSKeyword__moz_min_content, NS_STYLE_WIDTH_MIN_CONTENT },
685
  { eCSSKeyword__moz_fit_content, NS_STYLE_WIDTH_FIT_CONTENT },
686
  { eCSSKeyword__moz_available,   NS_STYLE_WIDTH_AVAILABLE },
687
  { eCSSKeyword_content,          NS_STYLE_FLEX_BASIS_CONTENT },
688
  { eCSSKeyword_UNKNOWN, -1 }
689
};
690
static_assert(ArrayLength(nsCSSProps::kFlexBasisKTable) ==
691
              ArrayLength(nsCSSProps::kWidthKTable) + 1,
692
              "kFlexBasisKTable should have the same entries as "
693
              "kWidthKTable, plus one more for 'content'");
694
695
// Specific keyword tables for XUL.properties
696
697
// keyword tables for SVG properties
698
699
const KTableEntry nsCSSProps::kShapeRadiusKTable[] = {
700
  { eCSSKeyword_closest_side, StyleShapeRadius::ClosestSide },
701
  { eCSSKeyword_farthest_side, StyleShapeRadius::FarthestSide },
702
  { eCSSKeyword_UNKNOWN, -1 }
703
};
704
705
const KTableEntry nsCSSProps::kFilterFunctionKTable[] = {
706
  { eCSSKeyword_blur, NS_STYLE_FILTER_BLUR },
707
  { eCSSKeyword_brightness, NS_STYLE_FILTER_BRIGHTNESS },
708
  { eCSSKeyword_contrast, NS_STYLE_FILTER_CONTRAST },
709
  { eCSSKeyword_grayscale, NS_STYLE_FILTER_GRAYSCALE },
710
  { eCSSKeyword_invert, NS_STYLE_FILTER_INVERT },
711
  { eCSSKeyword_opacity, NS_STYLE_FILTER_OPACITY },
712
  { eCSSKeyword_saturate, NS_STYLE_FILTER_SATURATE },
713
  { eCSSKeyword_sepia, NS_STYLE_FILTER_SEPIA },
714
  { eCSSKeyword_hue_rotate, NS_STYLE_FILTER_HUE_ROTATE },
715
  { eCSSKeyword_drop_shadow, NS_STYLE_FILTER_DROP_SHADOW },
716
  { eCSSKeyword_UNKNOWN, -1 }
717
};
718
719
int32_t
720
nsCSSProps::FindIndexOfKeyword(nsCSSKeyword aKeyword,
721
                               const KTableEntry aTable[])
722
0
{
723
0
  if (eCSSKeyword_UNKNOWN == aKeyword) {
724
0
    // NOTE: we can have keyword tables where eCSSKeyword_UNKNOWN is used
725
0
    // not only for the sentinel, but also in the middle of the table to
726
0
    // knock out values that have been disabled by prefs, e.g. kDisplayKTable.
727
0
    // So we deal with eCSSKeyword_UNKNOWN up front to avoid returning a valid
728
0
    // index in the loop below.
729
0
    return -1;
730
0
  }
731
0
  for (int32_t i = 0; ; ++i) {
732
0
    const KTableEntry& entry = aTable[i];
733
0
    if (entry.IsSentinel()) {
734
0
      break;
735
0
    }
736
0
    if (aKeyword == entry.mKeyword) {
737
0
      return i;
738
0
    }
739
0
  }
740
0
  return -1;
741
0
}
742
743
bool
744
nsCSSProps::FindKeyword(nsCSSKeyword aKeyword, const KTableEntry aTable[],
745
                        int32_t& aResult)
746
0
{
747
0
  int32_t index = FindIndexOfKeyword(aKeyword, aTable);
748
0
  if (index >= 0) {
749
0
    aResult = aTable[index].mValue;
750
0
    return true;
751
0
  }
752
0
  return false;
753
0
}
754
755
nsCSSKeyword
756
nsCSSProps::ValueToKeywordEnum(int32_t aValue, const KTableEntry aTable[])
757
0
{
758
#ifdef DEBUG
759
  typedef decltype(aTable[0].mValue) table_value_type;
760
  NS_ASSERTION(table_value_type(aValue) == aValue, "Value out of range");
761
#endif
762
0
  for (int32_t i = 0; ; ++i) {
763
0
    const KTableEntry& entry = aTable[i];
764
0
    if (entry.IsSentinel()) {
765
0
      break;
766
0
    }
767
0
    if (aValue == entry.mValue) {
768
0
      return entry.mKeyword;
769
0
    }
770
0
  }
771
0
  return eCSSKeyword_UNKNOWN;
772
0
}
773
774
const nsCString&
775
nsCSSProps::ValueToKeyword(int32_t aValue, const KTableEntry aTable[])
776
0
{
777
0
  nsCSSKeyword keyword = ValueToKeywordEnum(aValue, aTable);
778
0
  if (keyword == eCSSKeyword_UNKNOWN) {
779
0
    static nsDependentCString sNullStr("");
780
0
    return sNullStr;
781
0
  } else {
782
0
    return nsCSSKeywords::GetStringValue(keyword);
783
0
  }
784
0
}
785
786
const CSSPropFlags nsCSSProps::kFlagsTable[eCSSProperty_COUNT] = {
787
#define CSS_PROP_LONGHAND(name_, id_, method_, flags_, ...) flags_,
788
#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, ...) flags_,
789
#include "mozilla/ServoCSSPropList.h"
790
#undef CSS_PROP_SHORTHAND
791
#undef CSS_PROP_LONGHAND
792
};
793
794
/* static */ bool
795
nsCSSProps::gPropertyEnabled[eCSSProperty_COUNT_with_aliases] = {
796
  // If the property has any "ENABLED_IN" flag set, it is disabled by
797
  // default. Note that, if a property has pref, whatever its default
798
  // value is, it will later be changed in nsCSSProps::AddRefTable().
799
  // If the property has "ENABLED_IN" flags but doesn't have a pref,
800
  // it is an internal property which is disabled elsewhere.
801
  #define IS_ENABLED_BY_DEFAULT(flags_) \
802
    (!((flags_) & (CSSPropFlags::EnabledMask | CSSPropFlags::Inaccessible)))
803
804
  #define CSS_PROP_LONGHAND(name_, id_, method_, flags_, ...) \
805
    IS_ENABLED_BY_DEFAULT(flags_),
806
  #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, ...) \
807
    IS_ENABLED_BY_DEFAULT(flags_),
808
  #define CSS_PROP_ALIAS(...) true,
809
  #include "mozilla/ServoCSSPropList.h"
810
  #undef CSS_PROP_ALIAS
811
  #undef CSS_PROP_SHORTHAND
812
  #undef CSS_PROP_LONGHAND
813
814
  #undef IS_ENABLED_BY_DEFAULT
815
};
816
817
#include "../../dom/base/PropertyUseCounterMap.inc"
818
819
/* static */ const UseCounter
820
nsCSSProps::gPropertyUseCounter[eCSSProperty_COUNT_no_shorthands] = {
821
  #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) privatename_
822
  // Need an extra level of macro nesting to force expansion of method_
823
  // params before they get pasted.
824
  #define CSS_PROP_USE_COUNTER(method_) \
825
    static_cast<UseCounter>(USE_COUNTER_FOR_CSS_PROPERTY_##method_),
826
  #define CSS_PROP_LONGHAND(name_, id_, method_, ...) \
827
    CSS_PROP_USE_COUNTER(method_)
828
  #include "mozilla/ServoCSSPropList.h"
829
  #undef CSS_PROP_LONGHAND
830
  #undef CSS_PROP_USE_COUNTER
831
  #undef CSS_PROP_PUBLIC_OR_PRIVATE
832
};
833
834
#include "nsCSSPropsGenerated.inc"