Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: packages/html/lib/parser.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/html/lib/dom.dart ('k') | packages/html/lib/src/css_class_set.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /// This library has a parser for HTML5 documents, that lets you parse HTML 1 /// This library has a parser for HTML5 documents, that lets you parse HTML
2 /// easily from a script or server side application: 2 /// easily from a script or server side application:
3 /// 3 ///
4 /// import 'package:html/parser.dart' show parse; 4 /// import 'package:html/parser.dart' show parse;
5 /// import 'package:html/dom.dart'; 5 /// import 'package:html/dom.dart';
6 /// main() { 6 /// main() {
7 /// var document = parse( 7 /// var document = parse(
8 /// '<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!'); 8 /// '<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!');
9 /// print(document.outerHtml); 9 /// print(document.outerHtml);
10 /// } 10 /// }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 return tree.getFragment(); 203 return tree.getFragment();
204 } 204 }
205 205
206 void _parse() { 206 void _parse() {
207 reset(); 207 reset();
208 208
209 while (true) { 209 while (true) {
210 try { 210 try {
211 mainLoop(); 211 mainLoop();
212 break; 212 break;
213 } on ReparseException catch (e) { 213 } on ReparseException catch (_) {
214 // Note: this happens if we start parsing but the character encoding 214 // Note: this happens if we start parsing but the character encoding
215 // changes. So we should only need to restart very early in the parse. 215 // changes. So we should only need to restart very early in the parse.
216 reset(); 216 reset();
217 } 217 }
218 } 218 }
219 } 219 }
220 220
221 void reset() { 221 void reset() {
222 tokenizer.reset(); 222 tokenizer.reset();
223 223
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 anythingElse(); 812 anythingElse();
813 return true; 813 return true;
814 } 814 }
815 } 815 }
816 816
817 class BeforeHtmlPhase extends Phase { 817 class BeforeHtmlPhase extends Phase {
818 BeforeHtmlPhase(parser) : super(parser); 818 BeforeHtmlPhase(parser) : super(parser);
819 819
820 // helper methods 820 // helper methods
821 void insertHtmlElement() { 821 void insertHtmlElement() {
822 tree.insertRoot(new StartTagToken("html", data: {})); 822 tree.insertRoot(new StartTagToken("html",
823 data: new LinkedHashMap<dynamic, String>()));
823 parser.phase = parser._beforeHeadPhase; 824 parser.phase = parser._beforeHeadPhase;
824 } 825 }
825 826
826 // other 827 // other
827 bool processEOF() { 828 bool processEOF() {
828 insertHtmlElement(); 829 insertHtmlElement();
829 return true; 830 return true;
830 } 831 }
831 832
832 Token processComment(CommentToken token) { 833 Token processComment(CommentToken token) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 } 869 }
869 870
870 class BeforeHeadPhase extends Phase { 871 class BeforeHeadPhase extends Phase {
871 BeforeHeadPhase(parser) : super(parser); 872 BeforeHeadPhase(parser) : super(parser);
872 873
873 processStartTag(StartTagToken token) { 874 processStartTag(StartTagToken token) {
874 switch (token.name) { 875 switch (token.name) {
875 case 'html': 876 case 'html':
876 return startTagHtml(token); 877 return startTagHtml(token);
877 case 'head': 878 case 'head':
878 return startTagHead(token); 879 startTagHead(token);
880 return null;
879 default: 881 default:
880 return startTagOther(token); 882 return startTagOther(token);
881 } 883 }
882 } 884 }
883 885
884 processEndTag(EndTagToken token) { 886 processEndTag(EndTagToken token) {
885 switch (token.name) { 887 switch (token.name) {
886 case "head": 888 case "head":
887 case "body": 889 case "body":
888 case "html": 890 case "html":
889 case "br": 891 case "br":
890 return endTagImplyHead(token); 892 return endTagImplyHead(token);
891 default: 893 default:
892 return endTagOther(token); 894 endTagOther(token);
895 return null;
893 } 896 }
894 } 897 }
895 898
896 bool processEOF() { 899 bool processEOF() {
897 startTagHead(new StartTagToken("head", data: {})); 900 startTagHead(new StartTagToken("head",
901 data: new LinkedHashMap<dynamic, String>()));
898 return true; 902 return true;
899 } 903 }
900 904
901 Token processSpaceCharacters(SpaceCharactersToken token) { 905 Token processSpaceCharacters(SpaceCharactersToken token) {
902 return null; 906 return null;
903 } 907 }
904 908
905 Token processCharacters(CharactersToken token) { 909 Token processCharacters(CharactersToken token) {
906 startTagHead(new StartTagToken("head", data: {})); 910 startTagHead(new StartTagToken("head",
911 data: new LinkedHashMap<dynamic, String>()));
907 return token; 912 return token;
908 } 913 }
909 914
910 Token startTagHtml(StartTagToken token) { 915 Token startTagHtml(StartTagToken token) {
911 return parser._inBodyPhase.processStartTag(token); 916 return parser._inBodyPhase.processStartTag(token);
912 } 917 }
913 918
914 void startTagHead(StartTagToken token) { 919 void startTagHead(StartTagToken token) {
915 tree.insertElement(token); 920 tree.insertElement(token);
916 tree.headPointer = tree.openElements.last; 921 tree.headPointer = tree.openElements.last;
917 parser.phase = parser._inHeadPhase; 922 parser.phase = parser._inHeadPhase;
918 } 923 }
919 924
920 Token startTagOther(StartTagToken token) { 925 Token startTagOther(StartTagToken token) {
921 startTagHead(new StartTagToken("head", data: {})); 926 startTagHead(new StartTagToken("head",
927 data: new LinkedHashMap<dynamic, String>()));
922 return token; 928 return token;
923 } 929 }
924 930
925 Token endTagImplyHead(EndTagToken token) { 931 Token endTagImplyHead(EndTagToken token) {
926 startTagHead(new StartTagToken("head", data: {})); 932 startTagHead(new StartTagToken("head",
933 data: new LinkedHashMap<dynamic, String>()));
927 return token; 934 return token;
928 } 935 }
929 936
930 void endTagOther(EndTagToken token) { 937 void endTagOther(EndTagToken token) {
931 parser.parseError( 938 parser.parseError(
932 token.span, "end-tag-after-implied-root", {"name": token.name}); 939 token.span, "end-tag-after-implied-root", {"name": token.name});
933 } 940 }
934 } 941 }
935 942
936 class InHeadPhase extends Phase { 943 class InHeadPhase extends Phase {
937 InHeadPhase(parser) : super(parser); 944 InHeadPhase(parser) : super(parser);
938 945
939 processStartTag(StartTagToken token) { 946 processStartTag(StartTagToken token) {
940 switch (token.name) { 947 switch (token.name) {
941 case "html": 948 case "html":
942 return startTagHtml(token); 949 return startTagHtml(token);
943 case "title": 950 case "title":
944 return startTagTitle(token); 951 startTagTitle(token);
952 return null;
945 case "noscript": 953 case "noscript":
946 case "noframes": 954 case "noframes":
947 case "style": 955 case "style":
948 return startTagNoScriptNoFramesStyle(token); 956 startTagNoScriptNoFramesStyle(token);
957 return null;
949 case "script": 958 case "script":
950 return startTagScript(token); 959 startTagScript(token);
960 return null;
951 case "base": 961 case "base":
952 case "basefont": 962 case "basefont":
953 case "bgsound": 963 case "bgsound":
954 case "command": 964 case "command":
955 case "link": 965 case "link":
956 return startTagBaseLinkCommand(token); 966 startTagBaseLinkCommand(token);
967 return null;
957 case "meta": 968 case "meta":
958 return startTagMeta(token); 969 startTagMeta(token);
970 return null;
959 case "head": 971 case "head":
960 return startTagHead(token); 972 startTagHead(token);
973 return null;
961 default: 974 default:
962 return startTagOther(token); 975 return startTagOther(token);
963 } 976 }
964 } 977 }
965 978
966 processEndTag(EndTagToken token) { 979 processEndTag(EndTagToken token) {
967 switch (token.name) { 980 switch (token.name) {
968 case "head": 981 case "head":
969 return endTagHead(token); 982 endTagHead(token);
983 return null;
970 case "br": 984 case "br":
971 case "html": 985 case "html":
972 case "body": 986 case "body":
973 return endTagHtmlBodyBr(token); 987 return endTagHtmlBodyBr(token);
974 default: 988 default:
975 return endTagOther(token); 989 endTagOther(token);
990 return null;
976 } 991 }
977 } 992 }
978 993
979 // the real thing 994 // the real thing
980 bool processEOF() { 995 bool processEOF() {
981 anythingElse(); 996 anythingElse();
982 return true; 997 return true;
983 } 998 }
984 999
985 Token processCharacters(CharactersToken token) { 1000 Token processCharacters(CharactersToken token) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 // class InHeadNoScriptPhase extends Phase { 1083 // class InHeadNoScriptPhase extends Phase {
1069 1084
1070 class AfterHeadPhase extends Phase { 1085 class AfterHeadPhase extends Phase {
1071 AfterHeadPhase(parser) : super(parser); 1086 AfterHeadPhase(parser) : super(parser);
1072 1087
1073 processStartTag(StartTagToken token) { 1088 processStartTag(StartTagToken token) {
1074 switch (token.name) { 1089 switch (token.name) {
1075 case "html": 1090 case "html":
1076 return startTagHtml(token); 1091 return startTagHtml(token);
1077 case "body": 1092 case "body":
1078 return startTagBody(token); 1093 startTagBody(token);
1094 return null;
1079 case "frameset": 1095 case "frameset":
1080 return startTagFrameset(token); 1096 startTagFrameset(token);
1097 return null;
1081 case "base": 1098 case "base":
1082 case "basefont": 1099 case "basefont":
1083 case "bgsound": 1100 case "bgsound":
1084 case "link": 1101 case "link":
1085 case "meta": 1102 case "meta":
1086 case "noframes": 1103 case "noframes":
1087 case "script": 1104 case "script":
1088 case "style": 1105 case "style":
1089 case "title": 1106 case "title":
1090 return startTagFromHead(token); 1107 startTagFromHead(token);
1108 return null;
1091 case "head": 1109 case "head":
1092 return startTagHead(token); 1110 startTagHead(token);
1111 return null;
1093 default: 1112 default:
1094 return startTagOther(token); 1113 return startTagOther(token);
1095 } 1114 }
1096 } 1115 }
1097 1116
1098 processEndTag(EndTagToken token) { 1117 processEndTag(EndTagToken token) {
1099 switch (token.name) { 1118 switch (token.name) {
1100 case "body": 1119 case "body":
1101 case "html": 1120 case "html":
1102 case "br": 1121 case "br":
1103 return endTagHtmlBodyBr(token); 1122 return endTagHtmlBodyBr(token);
1104 default: 1123 default:
1105 return endTagOther(token); 1124 endTagOther(token);
1125 return null;
1106 } 1126 }
1107 } 1127 }
1108 1128
1109 bool processEOF() { 1129 bool processEOF() {
1110 anythingElse(); 1130 anythingElse();
1111 return true; 1131 return true;
1112 } 1132 }
1113 1133
1114 Token processCharacters(CharactersToken token) { 1134 Token processCharacters(CharactersToken token) {
1115 anythingElse(); 1135 anythingElse();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 Token endTagHtmlBodyBr(EndTagToken token) { 1177 Token endTagHtmlBodyBr(EndTagToken token) {
1158 anythingElse(); 1178 anythingElse();
1159 return token; 1179 return token;
1160 } 1180 }
1161 1181
1162 void endTagOther(EndTagToken token) { 1182 void endTagOther(EndTagToken token) {
1163 parser.parseError(token.span, "unexpected-end-tag", {"name": token.name}); 1183 parser.parseError(token.span, "unexpected-end-tag", {"name": token.name});
1164 } 1184 }
1165 1185
1166 void anythingElse() { 1186 void anythingElse() {
1167 tree.insertElement(new StartTagToken("body", data: {})); 1187 tree.insertElement(new StartTagToken("body",
1188 data: new LinkedHashMap<dynamic, String>()));
1168 parser.phase = parser._inBodyPhase; 1189 parser.phase = parser._inBodyPhase;
1169 parser.framesetOK = true; 1190 parser.framesetOK = true;
1170 } 1191 }
1171 } 1192 }
1172 1193
1173 typedef Token TokenProccessor(Token token); 1194 typedef Token TokenProccessor(Token token);
1174 1195
1175 class InBodyPhase extends Phase { 1196 class InBodyPhase extends Phase {
1176 bool dropNewline = false; 1197 bool dropNewline = false;
1177 1198
(...skipping 10 matching lines...) Expand all
1188 case "bgsound": 1209 case "bgsound":
1189 case "command": 1210 case "command":
1190 case "link": 1211 case "link":
1191 case "meta": 1212 case "meta":
1192 case "noframes": 1213 case "noframes":
1193 case "script": 1214 case "script":
1194 case "style": 1215 case "style":
1195 case "title": 1216 case "title":
1196 return startTagProcessInHead(token); 1217 return startTagProcessInHead(token);
1197 case "body": 1218 case "body":
1198 return startTagBody(token); 1219 startTagBody(token);
1220 return null;
1199 case "frameset": 1221 case "frameset":
1200 return startTagFrameset(token); 1222 startTagFrameset(token);
1223 return null;
1201 case "address": 1224 case "address":
1202 case "article": 1225 case "article":
1203 case "aside": 1226 case "aside":
1204 case "blockquote": 1227 case "blockquote":
1205 case "center": 1228 case "center":
1206 case "details": 1229 case "details":
1207 case "details": 1230 case "details":
1208 case "dir": 1231 case "dir":
1209 case "div": 1232 case "div":
1210 case "dl": 1233 case "dl":
1211 case "fieldset": 1234 case "fieldset":
1212 case "figcaption": 1235 case "figcaption":
1213 case "figure": 1236 case "figure":
1214 case "footer": 1237 case "footer":
1215 case "header": 1238 case "header":
1216 case "hgroup": 1239 case "hgroup":
1217 case "menu": 1240 case "menu":
1218 case "nav": 1241 case "nav":
1219 case "ol": 1242 case "ol":
1220 case "p": 1243 case "p":
1221 case "section": 1244 case "section":
1222 case "summary": 1245 case "summary":
1223 case "ul": 1246 case "ul":
1224 return startTagCloseP(token); 1247 startTagCloseP(token);
1248 return null;
1225 // headingElements 1249 // headingElements
1226 case "h1": 1250 case "h1":
1227 case "h2": 1251 case "h2":
1228 case "h3": 1252 case "h3":
1229 case "h4": 1253 case "h4":
1230 case "h5": 1254 case "h5":
1231 case "h6": 1255 case "h6":
1232 return startTagHeading(token); 1256 startTagHeading(token);
1257 return null;
1233 case "pre": 1258 case "pre":
1234 case "listing": 1259 case "listing":
1235 return startTagPreListing(token); 1260 startTagPreListing(token);
1261 return null;
1236 case "form": 1262 case "form":
1237 return startTagForm(token); 1263 startTagForm(token);
1264 return null;
1238 case "li": 1265 case "li":
1239 case "dd": 1266 case "dd":
1240 case "dt": 1267 case "dt":
1241 return startTagListItem(token); 1268 startTagListItem(token);
1269 return null;
1242 case "plaintext": 1270 case "plaintext":
1243 return startTagPlaintext(token); 1271 startTagPlaintext(token);
1272 return null;
1244 case "a": 1273 case "a":
1245 return startTagA(token); 1274 startTagA(token);
1275 return null;
1246 case "b": 1276 case "b":
1247 case "big": 1277 case "big":
1248 case "code": 1278 case "code":
1249 case "em": 1279 case "em":
1250 case "font": 1280 case "font":
1251 case "i": 1281 case "i":
1252 case "s": 1282 case "s":
1253 case "small": 1283 case "small":
1254 case "strike": 1284 case "strike":
1255 case "strong": 1285 case "strong":
1256 case "tt": 1286 case "tt":
1257 case "u": 1287 case "u":
1258 return startTagFormatting(token); 1288 startTagFormatting(token);
1289 return null;
1259 case "nobr": 1290 case "nobr":
1260 return startTagNobr(token); 1291 startTagNobr(token);
1292 return null;
1261 case "button": 1293 case "button":
1262 return startTagButton(token); 1294 return startTagButton(token);
1263 case "applet": 1295 case "applet":
1264 case "marquee": 1296 case "marquee":
1265 case "object": 1297 case "object":
1266 return startTagAppletMarqueeObject(token); 1298 startTagAppletMarqueeObject(token);
1299 return null;
1267 case "xmp": 1300 case "xmp":
1268 return startTagXmp(token); 1301 startTagXmp(token);
1302 return null;
1269 case "table": 1303 case "table":
1270 return startTagTable(token); 1304 startTagTable(token);
1305 return null;
1271 case "area": 1306 case "area":
1272 case "br": 1307 case "br":
1273 case "embed": 1308 case "embed":
1274 case "img": 1309 case "img":
1275 case "keygen": 1310 case "keygen":
1276 case "wbr": 1311 case "wbr":
1277 return startTagVoidFormatting(token); 1312 startTagVoidFormatting(token);
1313 return null;
1278 case "param": 1314 case "param":
1279 case "source": 1315 case "source":
1280 case "track": 1316 case "track":
1281 return startTagParamSource(token); 1317 startTagParamSource(token);
1318 return null;
1282 case "input": 1319 case "input":
1283 return startTagInput(token); 1320 startTagInput(token);
1321 return null;
1284 case "hr": 1322 case "hr":
1285 return startTagHr(token); 1323 startTagHr(token);
1324 return null;
1286 case "image": 1325 case "image":
1287 return startTagImage(token); 1326 startTagImage(token);
1327 return null;
1288 case "isindex": 1328 case "isindex":
1289 return startTagIsIndex(token); 1329 startTagIsIndex(token);
1330 return null;
1290 case "textarea": 1331 case "textarea":
1291 return startTagTextarea(token); 1332 startTagTextarea(token);
1333 return null;
1292 case "iframe": 1334 case "iframe":
1293 return startTagIFrame(token); 1335 startTagIFrame(token);
1336 return null;
1294 case "noembed": 1337 case "noembed":
1295 case "noframes": 1338 case "noframes":
1296 case "noscript": 1339 case "noscript":
1297 return startTagRawtext(token); 1340 startTagRawtext(token);
1341 return null;
1298 case "select": 1342 case "select":
1299 return startTagSelect(token); 1343 startTagSelect(token);
1344 return null;
1300 case "rp": 1345 case "rp":
1301 case "rt": 1346 case "rt":
1302 return startTagRpRt(token); 1347 startTagRpRt(token);
1348 return null;
1303 case "option": 1349 case "option":
1304 case "optgroup": 1350 case "optgroup":
1305 return startTagOpt(token); 1351 startTagOpt(token);
1352 return null;
1306 case "math": 1353 case "math":
1307 return startTagMath(token); 1354 startTagMath(token);
1355 return null;
1308 case "svg": 1356 case "svg":
1309 return startTagSvg(token); 1357 startTagSvg(token);
1358 return null;
1310 case "caption": 1359 case "caption":
1311 case "col": 1360 case "col":
1312 case "colgroup": 1361 case "colgroup":
1313 case "frame": 1362 case "frame":
1314 case "head": 1363 case "head":
1315 case "tbody": 1364 case "tbody":
1316 case "td": 1365 case "td":
1317 case "tfoot": 1366 case "tfoot":
1318 case "th": 1367 case "th":
1319 case "thead": 1368 case "thead":
1320 case "tr": 1369 case "tr":
1321 return startTagMisplaced(token); 1370 startTagMisplaced(token);
1371 return null;
1322 default: 1372 default:
1323 return startTagOther(token); 1373 return startTagOther(token);
1324 } 1374 }
1325 } 1375 }
1326 1376
1327 processEndTag(EndTagToken token) { 1377 processEndTag(EndTagToken token) {
1328 switch (token.name) { 1378 switch (token.name) {
1329 case "body": 1379 case "body":
1330 return endTagBody(token); 1380 endTagBody(token);
1381 return null;
1331 case "html": 1382 case "html":
1332 return endTagHtml(token); 1383 return endTagHtml(token);
1333 case "address": 1384 case "address":
1334 case "article": 1385 case "article":
1335 case "aside": 1386 case "aside":
1336 case "blockquote": 1387 case "blockquote":
1337 case "center": 1388 case "center":
1338 case "details": 1389 case "details":
1339 case "dir": 1390 case "dir":
1340 case "div": 1391 case "div":
1341 case "dl": 1392 case "dl":
1342 case "fieldset": 1393 case "fieldset":
1343 case "figcaption": 1394 case "figcaption":
1344 case "figure": 1395 case "figure":
1345 case "footer": 1396 case "footer":
1346 case "header": 1397 case "header":
1347 case "hgroup": 1398 case "hgroup":
1348 case "listing": 1399 case "listing":
1349 case "menu": 1400 case "menu":
1350 case "nav": 1401 case "nav":
1351 case "ol": 1402 case "ol":
1352 case "pre": 1403 case "pre":
1353 case "section": 1404 case "section":
1354 case "summary": 1405 case "summary":
1355 case "ul": 1406 case "ul":
1356 return endTagBlock(token); 1407 endTagBlock(token);
1408 return null;
1357 case "form": 1409 case "form":
1358 return endTagForm(token); 1410 endTagForm(token);
1411 return null;
1359 case "p": 1412 case "p":
1360 return endTagP(token); 1413 endTagP(token);
1414 return null;
1361 case "dd": 1415 case "dd":
1362 case "dt": 1416 case "dt":
1363 case "li": 1417 case "li":
1364 return endTagListItem(token); 1418 endTagListItem(token);
1419 return null;
1365 // headingElements 1420 // headingElements
1366 case "h1": 1421 case "h1":
1367 case "h2": 1422 case "h2":
1368 case "h3": 1423 case "h3":
1369 case "h4": 1424 case "h4":
1370 case "h5": 1425 case "h5":
1371 case "h6": 1426 case "h6":
1372 return endTagHeading(token); 1427 endTagHeading(token);
1428 return null;
1373 case "a": 1429 case "a":
1374 case "b": 1430 case "b":
1375 case "big": 1431 case "big":
1376 case "code": 1432 case "code":
1377 case "em": 1433 case "em":
1378 case "font": 1434 case "font":
1379 case "i": 1435 case "i":
1380 case "nobr": 1436 case "nobr":
1381 case "s": 1437 case "s":
1382 case "small": 1438 case "small":
1383 case "strike": 1439 case "strike":
1384 case "strong": 1440 case "strong":
1385 case "tt": 1441 case "tt":
1386 case "u": 1442 case "u":
1387 return endTagFormatting(token); 1443 endTagFormatting(token);
1444 return null;
1388 case "applet": 1445 case "applet":
1389 case "marquee": 1446 case "marquee":
1390 case "object": 1447 case "object":
1391 return endTagAppletMarqueeObject(token); 1448 endTagAppletMarqueeObject(token);
1449 return null;
1392 case "br": 1450 case "br":
1393 return endTagBr(token); 1451 endTagBr(token);
1452 return null;
1394 default: 1453 default:
1395 return endTagOther(token); 1454 endTagOther(token);
1455 return null;
1396 } 1456 }
1397 } 1457 }
1398 1458
1399 bool isMatchingFormattingElement(Element node1, Element node2) { 1459 bool isMatchingFormattingElement(Element node1, Element node2) {
1400 if (node1.localName != node2.localName || 1460 if (node1.localName != node2.localName ||
1401 node1.namespaceUri != node2.namespaceUri) { 1461 node1.namespaceUri != node2.namespaceUri) {
1402 return false; 1462 return false;
1403 } else if (node1.attributes.length != node2.attributes.length) { 1463 } else if (node1.attributes.length != node2.attributes.length) {
1404 return false; 1464 return false;
1405 } else { 1465 } else {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 }); 1786 });
1727 processStartTag(new StartTagToken("img", 1787 processStartTag(new StartTagToken("img",
1728 data: token.data, selfClosing: token.selfClosing)); 1788 data: token.data, selfClosing: token.selfClosing));
1729 } 1789 }
1730 1790
1731 void startTagIsIndex(StartTagToken token) { 1791 void startTagIsIndex(StartTagToken token) {
1732 parser.parseError(token.span, "deprecated-tag", {"name": "isindex"}); 1792 parser.parseError(token.span, "deprecated-tag", {"name": "isindex"});
1733 if (tree.formPointer != null) { 1793 if (tree.formPointer != null) {
1734 return; 1794 return;
1735 } 1795 }
1736 var formAttrs = {}; 1796 var formAttrs = new LinkedHashMap<dynamic, String>();
1737 var dataAction = token.data["action"]; 1797 var dataAction = token.data["action"];
1738 if (dataAction != null) { 1798 if (dataAction != null) {
1739 formAttrs["action"] = dataAction; 1799 formAttrs["action"] = dataAction;
1740 } 1800 }
1741 processStartTag(new StartTagToken("form", data: formAttrs)); 1801 processStartTag(new StartTagToken("form", data: formAttrs));
1742 processStartTag(new StartTagToken("hr", data: {})); 1802 processStartTag(new StartTagToken("hr",
1743 processStartTag(new StartTagToken("label", data: {})); 1803 data: new LinkedHashMap<dynamic, String>()));
1804 processStartTag(new StartTagToken("label",
1805 data: new LinkedHashMap<dynamic, String>()));
1744 // XXX Localization ... 1806 // XXX Localization ...
1745 var prompt = token.data["prompt"]; 1807 var prompt = token.data["prompt"];
1746 if (prompt == null) { 1808 if (prompt == null) {
1747 prompt = "This is a searchable index. Enter search keywords: "; 1809 prompt = "This is a searchable index. Enter search keywords: ";
1748 } 1810 }
1749 processCharacters(new CharactersToken(prompt)); 1811 processCharacters(new CharactersToken(prompt));
1750 var attributes = new LinkedHashMap.from(token.data); 1812 var attributes = new LinkedHashMap<dynamic, String>.from(token.data);
1751 attributes.remove('action'); 1813 attributes.remove('action');
1752 attributes.remove('prompt'); 1814 attributes.remove('prompt');
1753 attributes["name"] = "isindex"; 1815 attributes["name"] = "isindex";
1754 processStartTag(new StartTagToken( 1816 processStartTag(new StartTagToken(
1755 "input", data: attributes, selfClosing: token.selfClosing)); 1817 "input", data: attributes, selfClosing: token.selfClosing));
1756 processEndTag(new EndTagToken("label")); 1818 processEndTag(new EndTagToken("label"));
1757 processStartTag(new StartTagToken("hr", data: {})); 1819 processStartTag(new StartTagToken("hr",
1820 data: new LinkedHashMap<dynamic, String>()));
1758 processEndTag(new EndTagToken("form")); 1821 processEndTag(new EndTagToken("form"));
1759 } 1822 }
1760 1823
1761 void startTagTextarea(StartTagToken token) { 1824 void startTagTextarea(StartTagToken token) {
1762 tree.insertElement(token); 1825 tree.insertElement(token);
1763 parser.tokenizer.state = parser.tokenizer.rcdataState; 1826 parser.tokenizer.state = parser.tokenizer.rcdataState;
1764 dropNewline = true; 1827 dropNewline = true;
1765 parser.framesetOK = false; 1828 parser.framesetOK = false;
1766 } 1829 }
1767 1830
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 } 1913 }
1851 1914
1852 Token startTagOther(StartTagToken token) { 1915 Token startTagOther(StartTagToken token) {
1853 tree.reconstructActiveFormattingElements(); 1916 tree.reconstructActiveFormattingElements();
1854 tree.insertElement(token); 1917 tree.insertElement(token);
1855 return null; 1918 return null;
1856 } 1919 }
1857 1920
1858 void endTagP(EndTagToken token) { 1921 void endTagP(EndTagToken token) {
1859 if (!tree.elementInScope("p", variant: "button")) { 1922 if (!tree.elementInScope("p", variant: "button")) {
1860 startTagCloseP(new StartTagToken("p", data: {})); 1923 startTagCloseP(new StartTagToken("p",
1924 data: new LinkedHashMap<dynamic, String>()));
1861 parser.parseError(token.span, "unexpected-end-tag", {"name": "p"}); 1925 parser.parseError(token.span, "unexpected-end-tag", {"name": "p"});
1862 endTagP(new EndTagToken("p")); 1926 endTagP(new EndTagToken("p"));
1863 } else { 1927 } else {
1864 tree.generateImpliedEndTags("p"); 1928 tree.generateImpliedEndTags("p");
1865 if (tree.openElements.last.localName != "p") { 1929 if (tree.openElements.last.localName != "p") {
1866 parser.parseError(token.span, "unexpected-end-tag", {"name": "p"}); 1930 parser.parseError(token.span, "unexpected-end-tag", {"name": "p"});
1867 } 1931 }
1868 popOpenElementsUntil(token); 1932 popOpenElementsUntil(token);
1869 } 1933 }
1870 } 1934 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 } 2051 }
1988 if (node != null) { 2052 if (node != null) {
1989 node.endSourceSpan = token.span; 2053 node.endSourceSpan = token.span;
1990 } 2054 }
1991 break; 2055 break;
1992 } 2056 }
1993 } 2057 }
1994 } 2058 }
1995 2059
1996 /// The much-feared adoption agency algorithm. 2060 /// The much-feared adoption agency algorithm.
1997 endTagFormatting(EndTagToken token) { 2061 void endTagFormatting(EndTagToken token) {
1998 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construc tion.html#adoptionAgency 2062 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construc tion.html#adoptionAgency
1999 // TODO(jmesserly): the comments here don't match the numbered steps in the 2063 // TODO(jmesserly): the comments here don't match the numbered steps in the
2000 // updated spec. This needs a pass over it to verify that it still matches. 2064 // updated spec. This needs a pass over it to verify that it still matches.
2001 // In particular the html5lib Python code skiped "step 4", I'm not sure why. 2065 // In particular the html5lib Python code skiped "step 4", I'm not sure why.
2002 // XXX Better parseError messages appreciated. 2066 // XXX Better parseError messages appreciated.
2003 int outerLoopCounter = 0; 2067 int outerLoopCounter = 0;
2004 while (outerLoopCounter < 8) { 2068 while (outerLoopCounter < 8) {
2005 outerLoopCounter += 1; 2069 outerLoopCounter += 1;
2006 2070
2007 // Step 1 paragraph 1 2071 // Step 1 paragraph 1
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2157 tree.clearActiveFormattingElements(); 2221 tree.clearActiveFormattingElements();
2158 } 2222 }
2159 } 2223 }
2160 2224
2161 void endTagBr(EndTagToken token) { 2225 void endTagBr(EndTagToken token) {
2162 parser.parseError(token.span, "unexpected-end-tag-treated-as", { 2226 parser.parseError(token.span, "unexpected-end-tag-treated-as", {
2163 "originalName": "br", 2227 "originalName": "br",
2164 "newName": "br element" 2228 "newName": "br element"
2165 }); 2229 });
2166 tree.reconstructActiveFormattingElements(); 2230 tree.reconstructActiveFormattingElements();
2167 tree.insertElement(new StartTagToken("br", data: {})); 2231 tree.insertElement(new StartTagToken("br",
2232 data: new LinkedHashMap<dynamic, String>()));
2168 tree.openElements.removeLast(); 2233 tree.openElements.removeLast();
2169 } 2234 }
2170 2235
2171 void endTagOther(EndTagToken token) { 2236 void endTagOther(EndTagToken token) {
2172 for (var node in tree.openElements.reversed) { 2237 for (var node in tree.openElements.reversed) {
2173 if (node.localName == token.name) { 2238 if (node.localName == token.name) {
2174 tree.generateImpliedEndTags(token.name); 2239 tree.generateImpliedEndTags(token.name);
2175 if (tree.openElements.last.localName != token.name) { 2240 if (tree.openElements.last.localName != token.name) {
2176 parser.parseError( 2241 parser.parseError(
2177 token.span, "unexpected-end-tag", {"name": token.name}); 2242 token.span, "unexpected-end-tag", {"name": token.name});
(...skipping 14 matching lines...) Expand all
2192 2257
2193 class TextPhase extends Phase { 2258 class TextPhase extends Phase {
2194 TextPhase(parser) : super(parser); 2259 TextPhase(parser) : super(parser);
2195 2260
2196 // "Tried to process start tag %s in RCDATA/RAWTEXT mode"%token.name 2261 // "Tried to process start tag %s in RCDATA/RAWTEXT mode"%token.name
2197 processStartTag(StartTagToken token) { 2262 processStartTag(StartTagToken token) {
2198 assert(false); 2263 assert(false);
2199 } 2264 }
2200 2265
2201 processEndTag(EndTagToken token) { 2266 processEndTag(EndTagToken token) {
2202 if (token.name == 'script') return endTagScript(token); 2267 if (token.name == 'script') {
2203 return endTagOther(token); 2268 endTagScript(token);
2269 return null;
2270 }
2271 endTagOther(token);
2204 } 2272 }
2205 2273
2206 Token processCharacters(CharactersToken token) { 2274 Token processCharacters(CharactersToken token) {
2207 tree.insertText(token.data, token.span); 2275 tree.insertText(token.data, token.span);
2208 return null; 2276 return null;
2209 } 2277 }
2210 2278
2211 bool processEOF() { 2279 bool processEOF() {
2212 var last = tree.openElements.last; 2280 var last = tree.openElements.last;
2213 parser.parseError(last.sourceSpan, "expected-named-closing-tag-but-got-eof", 2281 parser.parseError(last.sourceSpan, "expected-named-closing-tag-but-got-eof",
(...skipping 19 matching lines...) Expand all
2233 2301
2234 class InTablePhase extends Phase { 2302 class InTablePhase extends Phase {
2235 // http://www.whatwg.org/specs/web-apps/current-work///in-table 2303 // http://www.whatwg.org/specs/web-apps/current-work///in-table
2236 InTablePhase(parser) : super(parser); 2304 InTablePhase(parser) : super(parser);
2237 2305
2238 processStartTag(StartTagToken token) { 2306 processStartTag(StartTagToken token) {
2239 switch (token.name) { 2307 switch (token.name) {
2240 case "html": 2308 case "html":
2241 return startTagHtml(token); 2309 return startTagHtml(token);
2242 case "caption": 2310 case "caption":
2243 return startTagCaption(token); 2311 startTagCaption(token);
2312 return null;
2244 case "colgroup": 2313 case "colgroup":
2245 return startTagColgroup(token); 2314 startTagColgroup(token);
2315 return null;
2246 case "col": 2316 case "col":
2247 return startTagCol(token); 2317 return startTagCol(token);
2248 case "tbody": 2318 case "tbody":
2249 case "tfoot": 2319 case "tfoot":
2250 case "thead": 2320 case "thead":
2251 return startTagRowGroup(token); 2321 startTagRowGroup(token);
2322 return null;
2252 case "td": 2323 case "td":
2253 case "th": 2324 case "th":
2254 case "tr": 2325 case "tr":
2255 return startTagImplyTbody(token); 2326 return startTagImplyTbody(token);
2256 case "table": 2327 case "table":
2257 return startTagTable(token); 2328 return startTagTable(token);
2258 case "style": 2329 case "style":
2259 case "script": 2330 case "script":
2260 return startTagStyleScript(token); 2331 return startTagStyleScript(token);
2261 case "input": 2332 case "input":
2262 return startTagInput(token); 2333 startTagInput(token);
2334 return null;
2263 case "form": 2335 case "form":
2264 return startTagForm(token); 2336 startTagForm(token);
2337 return null;
2265 default: 2338 default:
2266 return startTagOther(token); 2339 startTagOther(token);
2340 return null;
2267 } 2341 }
2268 } 2342 }
2269 2343
2270 processEndTag(EndTagToken token) { 2344 processEndTag(EndTagToken token) {
2271 switch (token.name) { 2345 switch (token.name) {
2272 case "table": 2346 case "table":
2273 return endTagTable(token); 2347 endTagTable(token);
2348 return null;
2274 case "body": 2349 case "body":
2275 case "caption": 2350 case "caption":
2276 case "col": 2351 case "col":
2277 case "colgroup": 2352 case "colgroup":
2278 case "html": 2353 case "html":
2279 case "tbody": 2354 case "tbody":
2280 case "td": 2355 case "td":
2281 case "tfoot": 2356 case "tfoot":
2282 case "th": 2357 case "th":
2283 case "thead": 2358 case "thead":
2284 case "tr": 2359 case "tr":
2285 return endTagIgnore(token); 2360 endTagIgnore(token);
2361 return null;
2286 default: 2362 default:
2287 return endTagOther(token); 2363 endTagOther(token);
2364 return null;
2288 } 2365 }
2289 } 2366 }
2290 2367
2291 // helper methods 2368 // helper methods
2292 void clearStackToTableContext() { 2369 void clearStackToTableContext() {
2293 // "clear the stack back to a table context" 2370 // "clear the stack back to a table context"
2294 while (tree.openElements.last.localName != "table" && 2371 while (tree.openElements.last.localName != "table" &&
2295 tree.openElements.last.localName != "html") { 2372 tree.openElements.last.localName != "html") {
2296 //parser.parseError(token.span, "unexpected-implied-end-tag-in-table", 2373 //parser.parseError(token.span, "unexpected-implied-end-tag-in-table",
2297 // {"name": tree.openElements.last.name}) 2374 // {"name": tree.openElements.last.name})
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 parser.phase = parser._inCaptionPhase; 2420 parser.phase = parser._inCaptionPhase;
2344 } 2421 }
2345 2422
2346 void startTagColgroup(StartTagToken token) { 2423 void startTagColgroup(StartTagToken token) {
2347 clearStackToTableContext(); 2424 clearStackToTableContext();
2348 tree.insertElement(token); 2425 tree.insertElement(token);
2349 parser.phase = parser._inColumnGroupPhase; 2426 parser.phase = parser._inColumnGroupPhase;
2350 } 2427 }
2351 2428
2352 Token startTagCol(StartTagToken token) { 2429 Token startTagCol(StartTagToken token) {
2353 startTagColgroup(new StartTagToken("colgroup", data: {})); 2430 startTagColgroup(new StartTagToken("colgroup",
2431 data: new LinkedHashMap<dynamic, String>()));
2354 return token; 2432 return token;
2355 } 2433 }
2356 2434
2357 void startTagRowGroup(StartTagToken token) { 2435 void startTagRowGroup(StartTagToken token) {
2358 clearStackToTableContext(); 2436 clearStackToTableContext();
2359 tree.insertElement(token); 2437 tree.insertElement(token);
2360 parser.phase = parser._inTableBodyPhase; 2438 parser.phase = parser._inTableBodyPhase;
2361 } 2439 }
2362 2440
2363 Token startTagImplyTbody(StartTagToken token) { 2441 Token startTagImplyTbody(StartTagToken token) {
2364 startTagRowGroup(new StartTagToken("tbody", data: {})); 2442 startTagRowGroup(new StartTagToken("tbody",
2443 data: new LinkedHashMap<dynamic, String>()));
2365 return token; 2444 return token;
2366 } 2445 }
2367 2446
2368 Token startTagTable(StartTagToken token) { 2447 Token startTagTable(StartTagToken token) {
2369 parser.parseError(token.span, "unexpected-start-tag-implies-end-tag", { 2448 parser.parseError(token.span, "unexpected-start-tag-implies-end-tag", {
2370 "startName": "table", 2449 "startName": "table",
2371 "endName": "table" 2450 "endName": "table"
2372 }); 2451 });
2373 parser.phase.processEndTag(new EndTagToken("table")); 2452 parser.phase.processEndTag(new EndTagToken("table"));
2374 if (!parser.innerHTMLMode) { 2453 if (!parser.innerHTMLMode) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 case "tr": 2614 case "tr":
2536 return startTagTableElement(token); 2615 return startTagTableElement(token);
2537 default: 2616 default:
2538 return startTagOther(token); 2617 return startTagOther(token);
2539 } 2618 }
2540 } 2619 }
2541 2620
2542 processEndTag(EndTagToken token) { 2621 processEndTag(EndTagToken token) {
2543 switch (token.name) { 2622 switch (token.name) {
2544 case "caption": 2623 case "caption":
2545 return endTagCaption(token); 2624 endTagCaption(token);
2625 return null;
2546 case "table": 2626 case "table":
2547 return endTagTable(token); 2627 return endTagTable(token);
2548 case "body": 2628 case "body":
2549 case "col": 2629 case "col":
2550 case "colgroup": 2630 case "colgroup":
2551 case "html": 2631 case "html":
2552 case "tbody": 2632 case "tbody":
2553 case "td": 2633 case "td":
2554 case "tfoot": 2634 case "tfoot":
2555 case "th": 2635 case "th":
2556 case "thead": 2636 case "thead":
2557 case "tr": 2637 case "tr":
2558 return endTagIgnore(token); 2638 endTagIgnore(token);
2639 return null;
2559 default: 2640 default:
2560 return endTagOther(token); 2641 return endTagOther(token);
2561 } 2642 }
2562 } 2643 }
2563 2644
2564 bool ignoreEndTagCaption() { 2645 bool ignoreEndTagCaption() {
2565 return !tree.elementInScope("caption", variant: "table"); 2646 return !tree.elementInScope("caption", variant: "table");
2566 } 2647 }
2567 2648
2568 bool processEOF() { 2649 bool processEOF() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 2715
2635 class InColumnGroupPhase extends Phase { 2716 class InColumnGroupPhase extends Phase {
2636 // http://www.whatwg.org/specs/web-apps/current-work///in-column 2717 // http://www.whatwg.org/specs/web-apps/current-work///in-column
2637 InColumnGroupPhase(parser) : super(parser); 2718 InColumnGroupPhase(parser) : super(parser);
2638 2719
2639 processStartTag(StartTagToken token) { 2720 processStartTag(StartTagToken token) {
2640 switch (token.name) { 2721 switch (token.name) {
2641 case "html": 2722 case "html":
2642 return startTagHtml(token); 2723 return startTagHtml(token);
2643 case "col": 2724 case "col":
2644 return startTagCol(token); 2725 startTagCol(token);
2726 return null;
2645 default: 2727 default:
2646 return startTagOther(token); 2728 return startTagOther(token);
2647 } 2729 }
2648 } 2730 }
2649 2731
2650 processEndTag(EndTagToken token) { 2732 processEndTag(EndTagToken token) {
2651 switch (token.name) { 2733 switch (token.name) {
2652 case "colgroup": 2734 case "colgroup":
2653 return endTagColgroup(token); 2735 endTagColgroup(token);
2736 return null;
2654 case "col": 2737 case "col":
2655 return endTagCol(token); 2738 endTagCol(token);
2739 return null;
2656 default: 2740 default:
2657 return endTagOther(token); 2741 return endTagOther(token);
2658 } 2742 }
2659 } 2743 }
2660 2744
2661 bool ignoreEndTagColgroup() { 2745 bool ignoreEndTagColgroup() {
2662 return tree.openElements.last.localName == "html"; 2746 return tree.openElements.last.localName == "html";
2663 } 2747 }
2664 2748
2665 bool processEOF() { 2749 bool processEOF() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2715 2799
2716 class InTableBodyPhase extends Phase { 2800 class InTableBodyPhase extends Phase {
2717 // http://www.whatwg.org/specs/web-apps/current-work///in-table0 2801 // http://www.whatwg.org/specs/web-apps/current-work///in-table0
2718 InTableBodyPhase(parser) : super(parser); 2802 InTableBodyPhase(parser) : super(parser);
2719 2803
2720 processStartTag(StartTagToken token) { 2804 processStartTag(StartTagToken token) {
2721 switch (token.name) { 2805 switch (token.name) {
2722 case "html": 2806 case "html":
2723 return startTagHtml(token); 2807 return startTagHtml(token);
2724 case "tr": 2808 case "tr":
2725 return startTagTr(token); 2809 startTagTr(token);
2810 return null;
2726 case "td": 2811 case "td":
2727 case "th": 2812 case "th":
2728 return startTagTableCell(token); 2813 return startTagTableCell(token);
2729 case "caption": 2814 case "caption":
2730 case "col": 2815 case "col":
2731 case "colgroup": 2816 case "colgroup":
2732 case "tbody": 2817 case "tbody":
2733 case "tfoot": 2818 case "tfoot":
2734 case "thead": 2819 case "thead":
2735 return startTagTableOther(token); 2820 return startTagTableOther(token);
2736 default: 2821 default:
2737 return startTagOther(token); 2822 return startTagOther(token);
2738 } 2823 }
2739 } 2824 }
2740 2825
2741 processEndTag(EndTagToken token) { 2826 processEndTag(EndTagToken token) {
2742 switch (token.name) { 2827 switch (token.name) {
2743 case "tbody": 2828 case "tbody":
2744 case "tfoot": 2829 case "tfoot":
2745 case "thead": 2830 case "thead":
2746 return endTagTableRowGroup(token); 2831 endTagTableRowGroup(token);
2832 return null;
2747 case "table": 2833 case "table":
2748 return endTagTable(token); 2834 return endTagTable(token);
2749 case "body": 2835 case "body":
2750 case "caption": 2836 case "caption":
2751 case "col": 2837 case "col":
2752 case "colgroup": 2838 case "colgroup":
2753 case "html": 2839 case "html":
2754 case "td": 2840 case "td":
2755 case "th": 2841 case "th":
2756 case "tr": 2842 case "tr":
2757 return endTagIgnore(token); 2843 endTagIgnore(token);
2844 return null;
2758 default: 2845 default:
2759 return endTagOther(token); 2846 return endTagOther(token);
2760 } 2847 }
2761 } 2848 }
2762 2849
2763 // helper methods 2850 // helper methods
2764 void clearStackToTableBodyContext() { 2851 void clearStackToTableBodyContext() {
2765 var tableTags = const ["tbody", "tfoot", "thead", "html"]; 2852 var tableTags = const ["tbody", "tfoot", "thead", "html"];
2766 while (!tableTags.contains(tree.openElements.last.localName)) { 2853 while (!tableTags.contains(tree.openElements.last.localName)) {
2767 //XXX parser.parseError(token.span, "unexpected-implied-end-tag-in-table", 2854 //XXX parser.parseError(token.span, "unexpected-implied-end-tag-in-table",
(...skipping 21 matching lines...) Expand all
2789 2876
2790 void startTagTr(StartTagToken token) { 2877 void startTagTr(StartTagToken token) {
2791 clearStackToTableBodyContext(); 2878 clearStackToTableBodyContext();
2792 tree.insertElement(token); 2879 tree.insertElement(token);
2793 parser.phase = parser._inRowPhase; 2880 parser.phase = parser._inRowPhase;
2794 } 2881 }
2795 2882
2796 Token startTagTableCell(StartTagToken token) { 2883 Token startTagTableCell(StartTagToken token) {
2797 parser.parseError( 2884 parser.parseError(
2798 token.span, "unexpected-cell-in-table-body", {"name": token.name}); 2885 token.span, "unexpected-cell-in-table-body", {"name": token.name});
2799 startTagTr(new StartTagToken("tr", data: {})); 2886 startTagTr(new StartTagToken("tr",
2887 data: new LinkedHashMap<dynamic, String>()));
2800 return token; 2888 return token;
2801 } 2889 }
2802 2890
2803 Token startTagTableOther(token) => endTagTable(token); 2891 Token startTagTableOther(token) => endTagTable(token);
2804 2892
2805 Token startTagOther(StartTagToken token) { 2893 Token startTagOther(StartTagToken token) {
2806 return parser._inTablePhase.processStartTag(token); 2894 return parser._inTablePhase.processStartTag(token);
2807 } 2895 }
2808 2896
2809 void endTagTableRowGroup(EndTagToken token) { 2897 void endTagTableRowGroup(EndTagToken token) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 class InRowPhase extends Phase { 2935 class InRowPhase extends Phase {
2848 // http://www.whatwg.org/specs/web-apps/current-work///in-row 2936 // http://www.whatwg.org/specs/web-apps/current-work///in-row
2849 InRowPhase(parser) : super(parser); 2937 InRowPhase(parser) : super(parser);
2850 2938
2851 processStartTag(StartTagToken token) { 2939 processStartTag(StartTagToken token) {
2852 switch (token.name) { 2940 switch (token.name) {
2853 case "html": 2941 case "html":
2854 return startTagHtml(token); 2942 return startTagHtml(token);
2855 case "td": 2943 case "td":
2856 case "th": 2944 case "th":
2857 return startTagTableCell(token); 2945 startTagTableCell(token);
2946 return null;
2858 case "caption": 2947 case "caption":
2859 case "col": 2948 case "col":
2860 case "colgroup": 2949 case "colgroup":
2861 case "tbody": 2950 case "tbody":
2862 case "tfoot": 2951 case "tfoot":
2863 case "thead": 2952 case "thead":
2864 case "tr": 2953 case "tr":
2865 return startTagTableOther(token); 2954 return startTagTableOther(token);
2866 default: 2955 default:
2867 return startTagOther(token); 2956 return startTagOther(token);
2868 } 2957 }
2869 } 2958 }
2870 2959
2871 processEndTag(EndTagToken token) { 2960 processEndTag(EndTagToken token) {
2872 switch (token.name) { 2961 switch (token.name) {
2873 case "tr": 2962 case "tr":
2874 return endTagTr(token); 2963 endTagTr(token);
2964 return null;
2875 case "table": 2965 case "table":
2876 return endTagTable(token); 2966 return endTagTable(token);
2877 case "tbody": 2967 case "tbody":
2878 case "tfoot": 2968 case "tfoot":
2879 case "thead": 2969 case "thead":
2880 return endTagTableRowGroup(token); 2970 return endTagTableRowGroup(token);
2881 case "body": 2971 case "body":
2882 case "caption": 2972 case "caption":
2883 case "col": 2973 case "col":
2884 case "colgroup": 2974 case "colgroup":
2885 case "html": 2975 case "html":
2886 case "td": 2976 case "td":
2887 case "th": 2977 case "th":
2888 return endTagIgnore(token); 2978 endTagIgnore(token);
2979 return null;
2889 default: 2980 default:
2890 return endTagOther(token); 2981 return endTagOther(token);
2891 } 2982 }
2892 } 2983 }
2893 2984
2894 // helper methods (XXX unify this with other table helper methods) 2985 // helper methods (XXX unify this with other table helper methods)
2895 void clearStackToTableRowContext() { 2986 void clearStackToTableRowContext() {
2896 while (true) { 2987 while (true) {
2897 var last = tree.openElements.last; 2988 var last = tree.openElements.last;
2898 if (last.localName == "tr" || last.localName == "html") break; 2989 if (last.localName == "tr" || last.localName == "html") break;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3002 return startTagTableOther(token); 3093 return startTagTableOther(token);
3003 default: 3094 default:
3004 return startTagOther(token); 3095 return startTagOther(token);
3005 } 3096 }
3006 } 3097 }
3007 3098
3008 processEndTag(EndTagToken token) { 3099 processEndTag(EndTagToken token) {
3009 switch (token.name) { 3100 switch (token.name) {
3010 case "td": 3101 case "td":
3011 case "th": 3102 case "th":
3012 return endTagTableCell(token); 3103 endTagTableCell(token);
3104 return null;
3013 case "body": 3105 case "body":
3014 case "caption": 3106 case "caption":
3015 case "col": 3107 case "col":
3016 case "colgroup": 3108 case "colgroup":
3017 case "html": 3109 case "html":
3018 return endTagIgnore(token); 3110 endTagIgnore(token);
3111 return null;
3019 case "table": 3112 case "table":
3020 case "tbody": 3113 case "tbody":
3021 case "tfoot": 3114 case "tfoot":
3022 case "thead": 3115 case "thead":
3023 case "tr": 3116 case "tr":
3024 return endTagImply(token); 3117 return endTagImply(token);
3025 default: 3118 default:
3026 return endTagOther(token); 3119 return endTagOther(token);
3027 } 3120 }
3028 } 3121 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3102 } 3195 }
3103 3196
3104 class InSelectPhase extends Phase { 3197 class InSelectPhase extends Phase {
3105 InSelectPhase(parser) : super(parser); 3198 InSelectPhase(parser) : super(parser);
3106 3199
3107 processStartTag(StartTagToken token) { 3200 processStartTag(StartTagToken token) {
3108 switch (token.name) { 3201 switch (token.name) {
3109 case "html": 3202 case "html":
3110 return startTagHtml(token); 3203 return startTagHtml(token);
3111 case "option": 3204 case "option":
3112 return startTagOption(token); 3205 startTagOption(token);
3206 return null;
3113 case "optgroup": 3207 case "optgroup":
3114 return startTagOptgroup(token); 3208 startTagOptgroup(token);
3209 return null;
3115 case "select": 3210 case "select":
3116 return startTagSelect(token); 3211 startTagSelect(token);
3212 return null;
3117 case "input": 3213 case "input":
3118 case "keygen": 3214 case "keygen":
3119 case "textarea": 3215 case "textarea":
3120 return startTagInput(token); 3216 return startTagInput(token);
3121 case "script": 3217 case "script":
3122 return startTagScript(token); 3218 return startTagScript(token);
3123 default: 3219 default:
3124 return startTagOther(token); 3220 return startTagOther(token);
3125 } 3221 }
3126 } 3222 }
3127 3223
3128 processEndTag(EndTagToken token) { 3224 processEndTag(EndTagToken token) {
3129 switch (token.name) { 3225 switch (token.name) {
3130 case "option": 3226 case "option":
3131 return endTagOption(token); 3227 endTagOption(token);
3228 return null;
3132 case "optgroup": 3229 case "optgroup":
3133 return endTagOptgroup(token); 3230 endTagOptgroup(token);
3231 return null;
3134 case "select": 3232 case "select":
3135 return endTagSelect(token); 3233 endTagSelect(token);
3234 return null;
3136 default: 3235 default:
3137 return endTagOther(token); 3236 endTagOther(token);
3237 return null;
3138 } 3238 }
3139 } 3239 }
3140 3240
3141 // http://www.whatwg.org/specs/web-apps/current-work///in-select 3241 // http://www.whatwg.org/specs/web-apps/current-work///in-select
3142 bool processEOF() { 3242 bool processEOF() {
3143 var last = tree.openElements.last; 3243 var last = tree.openElements.last;
3144 if (last.localName != "html") { 3244 if (last.localName != "html") {
3145 parser.parseError(last.sourceSpan, "eof-in-select"); 3245 parser.parseError(last.sourceSpan, "eof-in-select");
3146 } else { 3246 } else {
3147 assert(parser.innerHTMLMode); 3247 assert(parser.innerHTMLMode);
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
3497 3597
3498 class AfterBodyPhase extends Phase { 3598 class AfterBodyPhase extends Phase {
3499 AfterBodyPhase(parser) : super(parser); 3599 AfterBodyPhase(parser) : super(parser);
3500 3600
3501 processStartTag(StartTagToken token) { 3601 processStartTag(StartTagToken token) {
3502 if (token.name == "html") return startTagHtml(token); 3602 if (token.name == "html") return startTagHtml(token);
3503 return startTagOther(token); 3603 return startTagOther(token);
3504 } 3604 }
3505 3605
3506 processEndTag(EndTagToken token) { 3606 processEndTag(EndTagToken token) {
3507 if (token.name == "html") return endTagHtml(token); 3607 if (token.name == "html") {
3608 endTagHtml(token);
3609 return null;
3610 }
3508 return endTagOther(token); 3611 return endTagOther(token);
3509 } 3612 }
3510 3613
3511 //Stop parsing 3614 //Stop parsing
3512 bool processEOF() => false; 3615 bool processEOF() => false;
3513 3616
3514 Token processComment(CommentToken token) { 3617 Token processComment(CommentToken token) {
3515 // This is needed because data is to be appended to the <html> element 3618 // This is needed because data is to be appended to the <html> element
3516 // here and not to whatever is currently open. 3619 // here and not to whatever is currently open.
3517 tree.insertComment(token, tree.openElements[0]); 3620 tree.insertComment(token, tree.openElements[0]);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3559 3662
3560 class InFramesetPhase extends Phase { 3663 class InFramesetPhase extends Phase {
3561 // http://www.whatwg.org/specs/web-apps/current-work///in-frameset 3664 // http://www.whatwg.org/specs/web-apps/current-work///in-frameset
3562 InFramesetPhase(parser) : super(parser); 3665 InFramesetPhase(parser) : super(parser);
3563 3666
3564 processStartTag(StartTagToken token) { 3667 processStartTag(StartTagToken token) {
3565 switch (token.name) { 3668 switch (token.name) {
3566 case "html": 3669 case "html":
3567 return startTagHtml(token); 3670 return startTagHtml(token);
3568 case "frameset": 3671 case "frameset":
3569 return startTagFrameset(token); 3672 startTagFrameset(token);
3673 return null;
3570 case "frame": 3674 case "frame":
3571 return startTagFrame(token); 3675 startTagFrame(token);
3676 return null;
3572 case "noframes": 3677 case "noframes":
3573 return startTagNoframes(token); 3678 return startTagNoframes(token);
3574 default: 3679 default:
3575 return startTagOther(token); 3680 return startTagOther(token);
3576 } 3681 }
3577 } 3682 }
3578 3683
3579 processEndTag(EndTagToken token) { 3684 processEndTag(EndTagToken token) {
3580 switch (token.name) { 3685 switch (token.name) {
3581 case "frameset": 3686 case "frameset":
3582 return endTagFrameset(token); 3687 endTagFrameset(token);
3688 return null;
3583 default: 3689 default:
3584 return endTagOther(token); 3690 endTagOther(token);
3691 return null;
3585 } 3692 }
3586 } 3693 }
3587 3694
3588 bool processEOF() { 3695 bool processEOF() {
3589 var last = tree.openElements.last; 3696 var last = tree.openElements.last;
3590 if (last.localName != "html") { 3697 if (last.localName != "html") {
3591 parser.parseError(last.sourceSpan, "eof-in-frameset"); 3698 parser.parseError(last.sourceSpan, "eof-in-frameset");
3592 } else { 3699 } else {
3593 assert(parser.innerHTMLMode); 3700 assert(parser.innerHTMLMode);
3594 } 3701 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3646 // http://www.whatwg.org/specs/web-apps/current-work///after3 3753 // http://www.whatwg.org/specs/web-apps/current-work///after3
3647 AfterFramesetPhase(parser) : super(parser); 3754 AfterFramesetPhase(parser) : super(parser);
3648 3755
3649 processStartTag(StartTagToken token) { 3756 processStartTag(StartTagToken token) {
3650 switch (token.name) { 3757 switch (token.name) {
3651 case "html": 3758 case "html":
3652 return startTagHtml(token); 3759 return startTagHtml(token);
3653 case "noframes": 3760 case "noframes":
3654 return startTagNoframes(token); 3761 return startTagNoframes(token);
3655 default: 3762 default:
3656 return startTagOther(token); 3763 startTagOther(token);
3764 return null;
3657 } 3765 }
3658 } 3766 }
3659 3767
3660 processEndTag(EndTagToken token) { 3768 processEndTag(EndTagToken token) {
3661 switch (token.name) { 3769 switch (token.name) {
3662 case "html": 3770 case "html":
3663 return endTagHtml(token); 3771 endTagHtml(token);
3772 return null;
3664 default: 3773 default:
3665 return endTagOther(token); 3774 endTagOther(token);
3775 return null;
3666 } 3776 }
3667 } 3777 }
3668 3778
3669 // Stop parsing 3779 // Stop parsing
3670 bool processEOF() => false; 3780 bool processEOF() => false;
3671 3781
3672 Token processCharacters(CharactersToken token) { 3782 Token processCharacters(CharactersToken token) {
3673 parser.parseError(token.span, "unexpected-char-after-frameset"); 3783 parser.parseError(token.span, "unexpected-char-after-frameset");
3674 return null; 3784 return null;
3675 } 3785 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3741 class AfterAfterFramesetPhase extends Phase { 3851 class AfterAfterFramesetPhase extends Phase {
3742 AfterAfterFramesetPhase(parser) : super(parser); 3852 AfterAfterFramesetPhase(parser) : super(parser);
3743 3853
3744 processStartTag(StartTagToken token) { 3854 processStartTag(StartTagToken token) {
3745 switch (token.name) { 3855 switch (token.name) {
3746 case "html": 3856 case "html":
3747 return startTagHtml(token); 3857 return startTagHtml(token);
3748 case "noframes": 3858 case "noframes":
3749 return startTagNoFrames(token); 3859 return startTagNoFrames(token);
3750 default: 3860 default:
3751 return startTagOther(token); 3861 startTagOther(token);
3862 return null;
3752 } 3863 }
3753 } 3864 }
3754 3865
3755 bool processEOF() => false; 3866 bool processEOF() => false;
3756 3867
3757 Token processComment(CommentToken token) { 3868 Token processComment(CommentToken token) {
3758 tree.insertComment(token, tree.document); 3869 tree.insertComment(token, tree.document);
3759 return null; 3870 return null;
3760 } 3871 }
3761 3872
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3813 return span.sourceUrl == null ? 'ParserError on $res' : 'On $res'; 3924 return span.sourceUrl == null ? 'ParserError on $res' : 'On $res';
3814 } 3925 }
3815 } 3926 }
3816 3927
3817 /// Convenience function to get the pair of namespace and localName. 3928 /// Convenience function to get the pair of namespace and localName.
3818 Pair<String, String> getElementNameTuple(Element e) { 3929 Pair<String, String> getElementNameTuple(Element e) {
3819 var ns = e.namespaceUri; 3930 var ns = e.namespaceUri;
3820 if (ns == null) ns = Namespaces.html; 3931 if (ns == null) ns = Namespaces.html;
3821 return new Pair(ns, e.localName); 3932 return new Pair(ns, e.localName);
3822 } 3933 }
OLDNEW
« no previous file with comments | « packages/html/lib/dom.dart ('k') | packages/html/lib/src/css_class_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698