summaryrefslogtreecommitdiffstats
path: root/parser/htmlparser/nsElementTable.cpp
blob: b7742e56f3edb0e5f2217370c492f65b1888a51d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsElementTable.h"

struct HTMLElement
{
#ifdef DEBUG
  nsHTMLTag mTagID;
#endif
  bool mIsBlock;
  bool mIsContainer;
};

#ifdef DEBUG
#define ELEM(tag, block, container) { eHTMLTag_##tag, block, container },
#else
#define ELEM(tag, block, container) { block, container },
#endif

#define ____ false    // This makes the table easier to read.

// Note that the mIsBlock field disagrees with
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements for
// the following elements: center, details, dialog, dir, dt, figcaption,
// listing, menu, multicol, noscript, output, summary, tfoot, video.
//
// mrbkap thinks that the field values were pulled from the old HTML4 DTD and
// then got modified in mostly random ways to make the old parser's behavior
// compatible with the web. So it might make sense to change the mIsBlock
// values for the abovementioned tags at some point.
//

static const HTMLElement gHTMLElements[] = {
  ELEM(unknown,     ____, ____)
  ELEM(a,           ____, true)
  ELEM(abbr,        ____, true)
  ELEM(acronym,     ____, true)
  ELEM(address,     true, true)
  ELEM(applet,      ____, true)
  ELEM(area,        ____, ____)
  ELEM(article,     true, true)
  ELEM(aside,       true, true)
  ELEM(audio,       ____, true)
  ELEM(b,           ____, true)
  ELEM(base,        ____, ____)
  ELEM(basefont,    ____, ____)
  ELEM(bdo,         ____, true)
  ELEM(bgsound,     ____, ____)
  ELEM(big,         ____, true)
  ELEM(blockquote,  true, true)
  ELEM(body,        ____, true)
  ELEM(br,          ____, ____)
  ELEM(button,      ____, true)
  ELEM(canvas,      ____, true)
  ELEM(caption,     ____, true)
  ELEM(center,      true, true)
  ELEM(cite,        ____, true)
  ELEM(code,        ____, true)
  ELEM(col,         ____, ____)
  ELEM(colgroup,    ____, true)
  ELEM(content,     ____, true)
  ELEM(data,        ____, true)
  ELEM(datalist,    ____, true)
  ELEM(dd,          ____, true)
  ELEM(del,         ____, true)
  ELEM(details,     true, true)
  ELEM(dfn,         ____, true)
  ELEM(dialog,      true, true)
  ELEM(dir,         true, true)
  ELEM(div,         true, true)
  ELEM(dl,          true, true)
  ELEM(dt,          ____, true)
  ELEM(em,          ____, true)
  ELEM(embed,       ____, ____)
  ELEM(fieldset,    true, true)
  ELEM(figcaption,  ____, true)
  ELEM(figure,      true, true)
  ELEM(font,        ____, true)
  ELEM(footer,      true, true)
  ELEM(form,        true, true)
  ELEM(frame,       ____, ____)
  ELEM(frameset,    ____, true)
  ELEM(h1,          true, true)
  ELEM(h2,          true, true)
  ELEM(h3,          true, true)
  ELEM(h4,          true, true)
  ELEM(h5,          true, true)
  ELEM(h6,          true, true)
  ELEM(head,        ____, true)
  ELEM(header,      true, true)
  ELEM(hgroup,      true, true)
  ELEM(hr,          true, ____)
  ELEM(html,        ____, true)
  ELEM(i,           ____, true)
  ELEM(iframe,      ____, true)
  ELEM(image,       ____, ____)
  ELEM(img,         ____, ____)
  ELEM(input,       ____, ____)
  ELEM(ins,         ____, true)
  ELEM(kbd,         ____, true)
  ELEM(keygen,      ____, ____)
  ELEM(label,       ____, true)
  ELEM(legend,      ____, true)
  ELEM(li,          true, true)
  ELEM(link,        ____, ____)
  ELEM(listing,     true, true)
  ELEM(main,        true, true)
  ELEM(map,         ____, true)
  ELEM(mark,        ____, true)
  ELEM(marquee,     ____, true)
  ELEM(menu,        true, true)
  ELEM(menuitem,    ____, true)
  ELEM(meta,        ____, ____)
  ELEM(meter,       ____, true)
  ELEM(multicol,    true, true)
  ELEM(nav,         true, true)
  ELEM(nobr,        ____, true)
  ELEM(noembed,     ____, true)
  ELEM(noframes,    ____, true)
  ELEM(noscript,    ____, true)
  ELEM(object,      ____, true)
  ELEM(ol,          true, true)
  ELEM(optgroup,    ____, true)
  ELEM(option,      ____, true)
  ELEM(output,      ____, true)
  ELEM(p,           true, true)
  ELEM(param,       ____, ____)
  ELEM(picture,     ____, true)
  ELEM(plaintext,   ____, true)
  ELEM(pre,         true, true)
  ELEM(progress,    ____, true)
  ELEM(q,           ____, true)
  ELEM(rb,          ____, true)
  ELEM(rp,          ____, true)
  ELEM(rt,          ____, true)
  ELEM(rtc,         ____, true)
  ELEM(ruby,        ____, true)
  ELEM(s,           ____, true)
  ELEM(samp,        ____, true)
  ELEM(script,      ____, true)
  ELEM(section,     true, true)
  ELEM(select,      ____, true)
  ELEM(small,       ____, true)
  ELEM(source,      ____, ____)
  ELEM(span,        ____, true)
  ELEM(strike,      ____, true)
  ELEM(strong,      ____, true)
  ELEM(style,       ____, true)
  ELEM(sub,         ____, true)
  ELEM(summary,     true, true)
  ELEM(sup,         ____, true)
  ELEM(table,       true, true)
  ELEM(tbody,       ____, true)
  ELEM(td,          ____, true)
  ELEM(textarea,    ____, true)
  ELEM(tfoot,       ____, true)
  ELEM(th,          ____, true)
  ELEM(thead,       ____, true)
  ELEM(template,    ____, true)
  ELEM(time,        ____, true)
  ELEM(title,       ____, true)
  ELEM(tr,          ____, true)
  ELEM(track,       ____, ____)
  ELEM(tt,          ____, true)
  ELEM(u,           ____, true)
  ELEM(ul,          true, true)
  ELEM(var,         ____, true)
  ELEM(video,       ____, true)
  ELEM(wbr,         ____, ____)
  ELEM(xmp,         ____, true)
  ELEM(text,        ____, ____)
  ELEM(whitespace,  ____, ____)
  ELEM(newline,     ____, ____)
  ELEM(comment,     ____, true)
  ELEM(entity,      ____, true)
  ELEM(doctypeDecl, ____, true)
  ELEM(markupDecl,  ____, true)
  ELEM(instruction, ____, true)
  ELEM(userdefined, ____, true)
};

#undef ELEM
#undef ____

bool
nsHTMLElement::IsContainer(nsHTMLTag aId)
{
  return gHTMLElements[aId].mIsContainer;
}

bool
nsHTMLElement::IsBlock(nsHTMLTag aId)
{
  return gHTMLElements[aId].mIsBlock;
}

#ifdef DEBUG
void
CheckElementTable()
{
  for (nsHTMLTag t = eHTMLTag_unknown;
       t <= eHTMLTag_userdefined;
       t = nsHTMLTag(t + 1)) {
    MOZ_ASSERT(gHTMLElements[t].mTagID == t,
               "gHTMLElements entries does match tag list.");
  }
}
#endif