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

Side by Side Diff: sky/tests/resources/dom_serializer.dart

Issue 1025013003: Move dom-serializer.sky to dom_serializer.dart (and clean up some analyizer errors) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: foo Created 5 years, 9 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 | « sky/tests/resources/dom-serializer.sky ('k') | sky/tests/resources/dump-as-markup.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!--
2 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 3 // found in the LICENSE file.
5 -->
6 <script>
7 import "dart:sky"; 4 import "dart:sky";
8 5
9 final kEntityMap = new Map.fromIterable([ 6 final kEntityMap = new Map.fromIterable([
10 ['\u00a0', '&nbsp;'], 7 ['\u00a0', '&nbsp;'],
11 ['&', '&amp;'], 8 ['&', '&amp;'],
12 ['<', '&lt;'], 9 ['<', '&lt;'],
13 ['>', '&gt;'], 10 ['>', '&gt;'],
14 ['"', '&quot;'], 11 ['"', '&quot;'],
15 ], key: (item) => item[0], value: (item) => item[1]); 12 ], key: (item) => item[0], value: (item) => item[1]);
16 13
(...skipping 18 matching lines...) Expand all
35 buffer += ' '; 32 buffer += ' ';
36 buffer += attribute.name; 33 buffer += attribute.name;
37 buffer += '="'; 34 buffer += '="';
38 buffer += escapeText(attribute.value, kAttributeEscapePattern); 35 buffer += escapeText(attribute.value, kAttributeEscapePattern);
39 buffer += '"'; 36 buffer += '"';
40 } 37 }
41 38
42 return buffer; 39 return buffer;
43 } 40 }
44 41
45 Node getFirstChild(Node node) { 42 Node getFirstChild(ParentNode node) {
46 if (node is HTMLTemplateElement) 43 if (node is HTMLTemplateElement)
47 return node.content.firstChild; 44 return node.content.firstChild;
48 return node.firstChild; 45 return node.firstChild;
49 } 46 }
50 47
51 Node getLastChild(Node node) { 48 Node getLastChild(ParentNode node) {
52 if (node is HTMLTemplateElement) 49 if (node is HTMLTemplateElement)
53 return node.content.lastChild; 50 return node.content.lastChild;
54 return node.lastChild; 51 return node.lastChild;
55 } 52 }
56 53
57 String serializeChildren(Node node, int depth) { 54 String serializeChildren(ParentNode node, int depth) {
58 String buffer = ''; 55 String buffer = '';
59 Node firstChild = getFirstChild(node); 56 Node firstChild = getFirstChild(node);
60 Node lastChild = getLastChild(node); 57 Node lastChild = getLastChild(node);
61 if (firstChild is Element && depth != 0) 58 if (firstChild is Element && depth != 0)
62 buffer += '\n' + (kIndent * depth); 59 buffer += '\n' + (kIndent * depth);
63 for (Node child = firstChild; child != null; child = child.nextSibling) { 60 for (Node child = firstChild; child != null; child = child.nextSibling) {
64 buffer += serializeNode(child, depth); 61 buffer += serializeNode(child, depth);
65 if (child is Element && child.nextSibling is Element) 62 if (child is Element && child.nextSibling is Element)
66 buffer += '\n' + (kIndent * depth); 63 buffer += '\n' + (kIndent * depth);
67 } 64 }
68 if (lastChild is Element) { 65 if (lastChild is Element) {
69 buffer += '\n'; 66 buffer += '\n';
70 if (depth != 0) 67 if (depth != 0)
71 buffer += kIndent * (depth - 1); 68 buffer += kIndent * (depth - 1);
72 } 69 }
73 return buffer; 70 return buffer;
74 } 71 }
75 72
76 String serializeElement(Element element, int depth) { 73 String serializeElement(Element element, int depth) {
77 String buffer = '<' + element.tagName + serializeAttributes(element) + '>'; 74 String buffer = '<' + element.tagName + serializeAttributes(element) + '>';
78 buffer += serializeChildren(element, depth + 1); 75 buffer += serializeChildren(element, depth + 1);
79 buffer += '</' + element.tagName + '>'; 76 buffer += '</' + element.tagName + '>';
80 return buffer; 77 return buffer;
81 } 78 }
82 79
83 String serializeText(Node node) { 80 String serializeText(Text node) {
84 Node parent = node.parentNode; 81 Node parent = node.parentNode;
85 if (parent != null && (parent is HTMLScriptElement || parent is HTMLStyleEleme nt)) 82 if (parent != null && (parent is HTMLScriptElement || parent is HTMLStyleEleme nt))
86 return node.data; 83 return node.data;
87 return escapeText(node.data, kTextEscapePattern); 84 return escapeText(node.data, kTextEscapePattern);
88 } 85 }
89 86
90 String serializeNode(Node node, [int depth = 0]) { 87 String serializeNode(Node node, [int depth = 0]) {
91 if (node is Text) 88 if (node is Text)
92 return serializeText(node); 89 return serializeText(node);
93 if (node is Element) 90 if (node is Element)
94 return serializeElement(node, depth); 91 return serializeElement(node, depth);
95 if (node is Document || node is ShadowRoot) 92 if (node is Document || node is ShadowRoot)
96 return serializeChildren(node, depth); 93 return serializeChildren(node, depth);
97 throw new Error('Cannot serialize node'); 94 throw new Exception('Cannot serialize node');
98 } 95 }
99 </script>
OLDNEW
« no previous file with comments | « sky/tests/resources/dom-serializer.sky ('k') | sky/tests/resources/dump-as-markup.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698