OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
6 | 6 |
7 class _ChildrenElementList extends ListBase<Element> | 7 class _ChildrenElementList extends ListBase<Element> |
8 implements NodeListWrapper { | 8 implements NodeListWrapper { |
9 // Raw Element. | 9 // Raw Element. |
10 final Element _element; | 10 final Element _element; |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 * See also: | 1030 * See also: |
1031 * | 1031 * |
1032 * * [insertAdjacentText] | 1032 * * [insertAdjacentText] |
1033 * * [insertAdjacentElement] | 1033 * * [insertAdjacentElement] |
1034 */ | 1034 */ |
1035 void insertAdjacentHtml(String where, String html, {NodeValidator validator, | 1035 void insertAdjacentHtml(String where, String html, {NodeValidator validator, |
1036 NodeTreeSanitizer treeSanitizer}) { | 1036 NodeTreeSanitizer treeSanitizer}) { |
1037 if (treeSanitizer is _TrustedHtmlTreeSanitizer) { | 1037 if (treeSanitizer is _TrustedHtmlTreeSanitizer) { |
1038 _insertAdjacentHtml(where, html); | 1038 _insertAdjacentHtml(where, html); |
1039 } else { | 1039 } else { |
1040 _insertAdjacentNode(where, createFragment(html, | 1040 _insertAdjacentNode(where, new DocumentFragment.html(html, |
1041 validator: validator, treeSanitizer: treeSanitizer)); | 1041 validator: validator, treeSanitizer: treeSanitizer)); |
1042 } | 1042 } |
1043 } | 1043 } |
1044 | 1044 |
1045 $if DART2JS | 1045 $if DART2JS |
1046 | 1046 |
1047 @JSName('insertAdjacentHTML') | 1047 @JSName('insertAdjacentHTML') |
1048 void _insertAdjacentHtml(String where, String text) native; | 1048 void _insertAdjacentHtml(String where, String text) native; |
1049 | 1049 |
1050 /** | 1050 /** |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 if (_parseDocument == null) { | 1328 if (_parseDocument == null) { |
1329 _parseDocument = document.implementation.createHtmlDocument(''); | 1329 _parseDocument = document.implementation.createHtmlDocument(''); |
1330 _parseRange = _parseDocument.createRange(); | 1330 _parseRange = _parseDocument.createRange(); |
1331 | 1331 |
1332 // Workaround for Chrome bug 229142- URIs are not resolved in new doc. | 1332 // Workaround for Chrome bug 229142- URIs are not resolved in new doc. |
1333 var base = _parseDocument.createElement('base'); | 1333 var base = _parseDocument.createElement('base'); |
1334 base.href = document.baseUri; | 1334 base.href = document.baseUri; |
1335 _parseDocument.head.append(base); | 1335 _parseDocument.head.append(base); |
1336 } | 1336 } |
1337 var contextElement; | 1337 var contextElement; |
1338 // Head and Area elements can't be used to create document fragments. | 1338 if (this is BodyElement) { |
1339 // Use the body instead. | |
1340 if (this is BodyElement || _cannotBeUsedToCreateContextualFragment) { | |
1341 contextElement = _parseDocument.body; | 1339 contextElement = _parseDocument.body; |
1342 } else { | 1340 } else { |
1343 contextElement = _parseDocument.createElement(tagName); | 1341 contextElement = _parseDocument.createElement(tagName); |
1344 _parseDocument.body.append(contextElement); | 1342 _parseDocument.body.append(contextElement); |
1345 } | 1343 } |
1346 var fragment; | 1344 var fragment; |
1347 if (Range.supportsCreateContextualFragment) { | 1345 if (Range.supportsCreateContextualFragment) { |
1348 _parseRange.selectNodeContents(contextElement); | 1346 _parseRange.selectNodeContents(contextElement); |
1349 fragment = _parseRange.createContextualFragment(html); | 1347 fragment = _parseRange.createContextualFragment(html); |
1350 } else { | 1348 } else { |
1351 contextElement._innerHtml = html; | 1349 contextElement._innerHtml = html; |
1352 | 1350 |
1353 fragment = _parseDocument.createDocumentFragment(); | 1351 fragment = _parseDocument.createDocumentFragment(); |
1354 while (contextElement.firstChild != null) { | 1352 while (contextElement.firstChild != null) { |
1355 fragment.append(contextElement.firstChild); | 1353 fragment.append(contextElement.firstChild); |
1356 } | 1354 } |
1357 } | 1355 } |
1358 if (contextElement != _parseDocument.body) { | 1356 if (contextElement != _parseDocument.body) { |
1359 contextElement.remove(); | 1357 contextElement.remove(); |
1360 } | 1358 } |
1361 | 1359 |
1362 treeSanitizer.sanitizeTree(fragment); | 1360 treeSanitizer.sanitizeTree(fragment); |
1363 // Copy the fragment over to the main document (fix for 14184) | 1361 // Copy the fragment over to the main document (fix for 14184) |
1364 document.adoptNode(fragment); | 1362 document.adoptNode(fragment); |
1365 | 1363 |
1366 return fragment; | 1364 return fragment; |
1367 } | 1365 } |
1368 | 1366 |
1369 /** Test if createContextualFragment is supported for this element types */ | |
1370 bool get _cannotBeUsedToCreateContextualFragment => | |
1371 _tagsForWhichCreateContextualFragmentIsNotSupported.contains(tagName); | |
1372 | |
1373 /** | |
1374 * A hard-coded list of the tag names for which createContextualFragment | |
1375 * isn't supported. | |
1376 */ | |
1377 static const _tagsForWhichCreateContextualFragmentIsNotSupported = | |
1378 const ['HEAD', 'AREA', | |
1379 'BASE', 'BASEFONT', 'BR', 'COL', 'COLGROUP', 'EMBED', 'FRAME', 'FRAMESET', | |
1380 'HR', 'IMAGE', 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM', | |
1381 'SOURCE', 'STYLE', 'TITLE', 'WBR']; | |
1382 | |
1383 /** | 1367 /** |
1384 * Parses the HTML fragment and sets it as the contents of this element. | 1368 * Parses the HTML fragment and sets it as the contents of this element. |
1385 * | 1369 * |
1386 * This uses the default sanitization behavior to sanitize the HTML fragment, | 1370 * This uses the default sanitization behavior to sanitize the HTML fragment, |
1387 * use [setInnerHtml] to override the default behavior. | 1371 * use [setInnerHtml] to override the default behavior. |
1388 */ | 1372 */ |
1389 void set innerHtml(String html) { | 1373 void set innerHtml(String html) { |
1390 this.setInnerHtml(html); | 1374 this.setInnerHtml(html); |
1391 } | 1375 } |
1392 | 1376 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 const ScrollAlignment._internal(this._value); | 1660 const ScrollAlignment._internal(this._value); |
1677 toString() => 'ScrollAlignment.$_value'; | 1661 toString() => 'ScrollAlignment.$_value'; |
1678 | 1662 |
1679 /// Attempt to align the element to the top of the scrollable area. | 1663 /// Attempt to align the element to the top of the scrollable area. |
1680 static const TOP = const ScrollAlignment._internal('TOP'); | 1664 static const TOP = const ScrollAlignment._internal('TOP'); |
1681 /// Attempt to center the element in the scrollable area. | 1665 /// Attempt to center the element in the scrollable area. |
1682 static const CENTER = const ScrollAlignment._internal('CENTER'); | 1666 static const CENTER = const ScrollAlignment._internal('CENTER'); |
1683 /// Attempt to align the element to the bottom of the scrollable area. | 1667 /// Attempt to align the element to the bottom of the scrollable area. |
1684 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); | 1668 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); |
1685 } | 1669 } |
OLD | NEW |