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 #include "nsElementTable.h"
8 
9 struct HTMLElement {
10 #ifdef DEBUG
11   nsHTMLTag mTagID;
12 #endif
13   bool mIsBlock;
14   bool mIsContainer;
15 };
16 
17 #ifdef DEBUG
18 #  define ELEM(tag, block, container) {eHTMLTag_##tag, block, container},
19 #else
20 #  define ELEM(tag, block, container) {block, container},
21 #endif
22 
23 #define ____ false  // This makes the table easier to read.
24 
25 // Note that the mIsBlock field disagrees with
26 // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements for
27 // the following elements: center, details, dialog, dir, dt, figcaption,
28 // listing, menu, multicol, noscript, output, summary, tfoot, video.
29 //
30 // mrbkap thinks that the field values were pulled from the old HTML4 DTD and
31 // then got modified in mostly random ways to make the old parser's behavior
32 // compatible with the web. So it might make sense to change the mIsBlock
33 // values for the abovementioned tags at some point.
34 //
35 static const HTMLElement gHTMLElements[] = {
36     // clang-format off
37   ELEM(unknown,     ____, ____)
38   ELEM(a,           ____, true)
39   ELEM(abbr,        ____, true)
40   ELEM(acronym,     ____, true)
41   ELEM(address,     true, true)
42   ELEM(applet,      ____, true)
43   ELEM(area,        ____, ____)
44   ELEM(article,     true, true)
45   ELEM(aside,       true, true)
46   ELEM(audio,       ____, true)
47   ELEM(b,           ____, true)
48   ELEM(base,        ____, ____)
49   ELEM(basefont,    ____, ____)
50   ELEM(bdi,         ____, true)
51   ELEM(bdo,         ____, true)
52   ELEM(bgsound,     ____, ____)
53   ELEM(big,         ____, true)
54   ELEM(blockquote,  true, true)
55   ELEM(body,        ____, true)
56   ELEM(br,          ____, ____)
57   ELEM(button,      ____, true)
58   ELEM(canvas,      ____, true)
59   ELEM(caption,     ____, true)
60   ELEM(center,      true, true)
61   ELEM(cite,        ____, true)
62   ELEM(code,        ____, true)
63   ELEM(col,         ____, ____)
64   ELEM(colgroup,    ____, true)
65   ELEM(data,        ____, true)
66   ELEM(datalist,    ____, true)
67   ELEM(dd,          ____, true)
68   ELEM(del,         ____, true)
69   ELEM(details,     true, true)
70   ELEM(dfn,         ____, true)
71   ELEM(dialog,      true, true)
72   ELEM(dir,         true, true)
73   ELEM(div,         true, true)
74   ELEM(dl,          true, true)
75   ELEM(dt,          ____, true)
76   ELEM(em,          ____, true)
77   ELEM(embed,       ____, ____)
78   ELEM(fieldset,    true, true)
79   ELEM(figcaption,  ____, true)
80   ELEM(figure,      true, true)
81   ELEM(font,        ____, true)
82   ELEM(footer,      true, true)
83   ELEM(form,        true, true)
84   ELEM(frame,       ____, ____)
85   ELEM(frameset,    ____, true)
86   ELEM(h1,          true, true)
87   ELEM(h2,          true, true)
88   ELEM(h3,          true, true)
89   ELEM(h4,          true, true)
90   ELEM(h5,          true, true)
91   ELEM(h6,          true, true)
92   ELEM(head,        ____, true)
93   ELEM(header,      true, true)
94   ELEM(hgroup,      true, true)
95   ELEM(hr,          true, ____)
96   ELEM(html,        ____, true)
97   ELEM(i,           ____, true)
98   ELEM(iframe,      ____, true)
99   ELEM(image,       ____, ____)
100   ELEM(img,         ____, ____)
101   ELEM(input,       ____, ____)
102   ELEM(ins,         ____, true)
103   ELEM(kbd,         ____, true)
104   ELEM(keygen,      ____, ____)
105   ELEM(label,       ____, true)
106   ELEM(legend,      ____, true)
107   ELEM(li,          true, true)
108   ELEM(link,        ____, ____)
109   ELEM(listing,     true, true)
110   ELEM(main,        true, true)
111   ELEM(map,         ____, true)
112   ELEM(mark,        ____, true)
113   ELEM(marquee,     ____, true)
114   ELEM(menu,        true, true)
115   ELEM(menuitem,    ____, true)
116   ELEM(meta,        ____, ____)
117   ELEM(meter,       ____, true)
118   ELEM(multicol,    true, true)
119   ELEM(nav,         true, true)
120   ELEM(nobr,        ____, true)
121   ELEM(noembed,     ____, true)
122   ELEM(noframes,    ____, true)
123   ELEM(noscript,    ____, true)
124   ELEM(object,      ____, true)
125   ELEM(ol,          true, true)
126   ELEM(optgroup,    ____, true)
127   ELEM(option,      ____, true)
128   ELEM(output,      ____, true)
129   ELEM(p,           true, true)
130   ELEM(param,       ____, ____)
131   ELEM(picture,     ____, true)
132   ELEM(plaintext,   ____, true)
133   ELEM(pre,         true, true)
134   ELEM(progress,    ____, true)
135   ELEM(q,           ____, true)
136   ELEM(rb,          ____, true)
137   ELEM(rp,          ____, true)
138   ELEM(rt,          ____, true)
139   ELEM(rtc,         ____, true)
140   ELEM(ruby,        ____, true)
141   ELEM(s,           ____, true)
142   ELEM(samp,        ____, true)
143   ELEM(script,      ____, true)
144   ELEM(section,     true, true)
145   ELEM(select,      ____, true)
146   ELEM(small,       ____, true)
147   ELEM(slot,        ____, true)
148   ELEM(source,      ____, ____)
149   ELEM(span,        ____, true)
150   ELEM(strike,      ____, true)
151   ELEM(strong,      ____, true)
152   ELEM(style,       ____, true)
153   ELEM(sub,         ____, true)
154   ELEM(summary,     true, true)
155   ELEM(sup,         ____, true)
156   ELEM(table,       true, true)
157   ELEM(tbody,       ____, true)
158   ELEM(td,          ____, true)
159   ELEM(textarea,    ____, true)
160   ELEM(tfoot,       ____, true)
161   ELEM(th,          ____, true)
162   ELEM(thead,       ____, true)
163   ELEM(template,    ____, true)
164   ELEM(time,        ____, true)
165   ELEM(title,       ____, true)
166   ELEM(tr,          ____, true)
167   ELEM(track,       ____, ____)
168   ELEM(tt,          ____, true)
169   ELEM(u,           ____, true)
170   ELEM(ul,          true, true)
171   ELEM(var,         ____, true)
172   ELEM(video,       ____, true)
173   ELEM(wbr,         ____, ____)
174   ELEM(xmp,         ____, true)
175   ELEM(text,        ____, ____)
176   ELEM(whitespace,  ____, ____)
177   ELEM(newline,     ____, ____)
178   ELEM(comment,     ____, true)
179   ELEM(entity,      ____, true)
180   ELEM(doctypeDecl, ____, true)
181   ELEM(markupDecl,  ____, true)
182   ELEM(instruction, ____, true)
183   ELEM(userdefined, ____, true)
184     // clang-format on
185 };
186 
187 #undef ELEM
188 #undef ____
189 
IsContainer(nsHTMLTag aId)190 bool nsHTMLElement::IsContainer(nsHTMLTag aId) {
191   return gHTMLElements[aId].mIsContainer;
192 }
193 
IsBlock(nsHTMLTag aId)194 bool nsHTMLElement::IsBlock(nsHTMLTag aId) {
195   return gHTMLElements[aId].mIsBlock;
196 }
197 
198 #ifdef DEBUG
CheckElementTable()199 void CheckElementTable() {
200   for (nsHTMLTag t = eHTMLTag_unknown; t <= eHTMLTag_userdefined;
201        t = nsHTMLTag(t + 1)) {
202     MOZ_ASSERT(gHTMLElements[t].mTagID == t,
203                "gHTMLElements entries does match tag list.");
204   }
205 }
206 #endif
207