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, new DocumentFragment.html(html, | 1040 _insertAdjacentNode(where, createFragment(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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 } | 1321 } |
1322 treeSanitizer = _defaultSanitizer; | 1322 treeSanitizer = _defaultSanitizer; |
1323 } else if (validator != null) { | 1323 } else if (validator != null) { |
1324 throw new ArgumentError( | 1324 throw new ArgumentError( |
1325 'validator can only be passed if treeSanitizer is null'); | 1325 'validator can only be passed if treeSanitizer is null'); |
1326 } | 1326 } |
1327 | 1327 |
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 | |
1332 // Workaround for Chrome bug 229142- URIs are not resolved in new doc. | |
1333 var base = _parseDocument.createElement('base'); | |
1334 base.href = document.baseUri; | |
1335 _parseDocument.head.append(base); | |
1336 } | 1331 } |
1337 var contextElement; | 1332 var contextElement; |
1338 if (this is BodyElement) { | 1333 if (this is BodyElement) { |
1339 contextElement = _parseDocument.body; | 1334 contextElement = _parseDocument.body; |
1340 } else { | 1335 } else { |
1341 contextElement = _parseDocument.createElement(tagName); | 1336 contextElement = _parseDocument.createElement(tagName); |
1342 _parseDocument.body.append(contextElement); | 1337 _parseDocument.body.append(contextElement); |
1343 } | 1338 } |
1344 var fragment; | 1339 var fragment; |
1345 if (Range.supportsCreateContextualFragment) { | 1340 if (Range.supportsCreateContextualFragment && |
| 1341 _canBeUsedToCreateContextualFragment) { |
1346 _parseRange.selectNodeContents(contextElement); | 1342 _parseRange.selectNodeContents(contextElement); |
1347 fragment = _parseRange.createContextualFragment(html); | 1343 fragment = _parseRange.createContextualFragment(html); |
1348 } else { | 1344 } else { |
1349 contextElement._innerHtml = html; | 1345 contextElement._innerHtml = html; |
1350 | 1346 |
1351 fragment = _parseDocument.createDocumentFragment(); | 1347 fragment = _parseDocument.createDocumentFragment(); |
1352 while (contextElement.firstChild != null) { | 1348 while (contextElement.firstChild != null) { |
1353 fragment.append(contextElement.firstChild); | 1349 fragment.append(contextElement.firstChild); |
1354 } | 1350 } |
1355 } | 1351 } |
1356 if (contextElement != _parseDocument.body) { | 1352 if (contextElement != _parseDocument.body) { |
1357 contextElement.remove(); | 1353 contextElement.remove(); |
1358 } | 1354 } |
1359 | 1355 |
1360 treeSanitizer.sanitizeTree(fragment); | 1356 treeSanitizer.sanitizeTree(fragment); |
1361 // Copy the fragment over to the main document (fix for 14184) | 1357 // Copy the fragment over to the main document (fix for 14184) |
1362 document.adoptNode(fragment); | 1358 document.adoptNode(fragment); |
1363 | 1359 |
1364 return fragment; | 1360 return fragment; |
1365 } | 1361 } |
1366 | 1362 |
| 1363 /** Test if createContextualFragment is supported for this element type */ |
| 1364 bool get _canBeUsedToCreateContextualFragment => |
| 1365 !_cannotBeUsedToCreateContextualFragment; |
| 1366 |
| 1367 /** Test if createContextualFragment is NOT supported for this element type */ |
| 1368 bool get _cannotBeUsedToCreateContextualFragment => |
| 1369 _tagsForWhichCreateContextualFragmentIsNotSupported.contains(tagName); |
| 1370 |
| 1371 /** |
| 1372 * A hard-coded list of the tag names for which createContextualFragment |
| 1373 * isn't supported. |
| 1374 */ |
| 1375 static const _tagsForWhichCreateContextualFragmentIsNotSupported = |
| 1376 const ['HEAD', 'AREA', |
| 1377 'BASE', 'BASEFONT', 'BR', 'COL', 'COLGROUP', 'EMBED', 'FRAME', 'FRAMESET', |
| 1378 'HR', 'IMAGE', 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM', |
| 1379 'SOURCE', 'STYLE', 'TITLE', 'WBR']; |
| 1380 |
1367 /** | 1381 /** |
1368 * Parses the HTML fragment and sets it as the contents of this element. | 1382 * Parses the HTML fragment and sets it as the contents of this element. |
1369 * | 1383 * |
1370 * This uses the default sanitization behavior to sanitize the HTML fragment, | 1384 * This uses the default sanitization behavior to sanitize the HTML fragment, |
1371 * use [setInnerHtml] to override the default behavior. | 1385 * use [setInnerHtml] to override the default behavior. |
1372 */ | 1386 */ |
1373 void set innerHtml(String html) { | 1387 void set innerHtml(String html) { |
1374 this.setInnerHtml(html); | 1388 this.setInnerHtml(html); |
1375 } | 1389 } |
1376 | 1390 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 const ScrollAlignment._internal(this._value); | 1674 const ScrollAlignment._internal(this._value); |
1661 toString() => 'ScrollAlignment.$_value'; | 1675 toString() => 'ScrollAlignment.$_value'; |
1662 | 1676 |
1663 /// Attempt to align the element to the top of the scrollable area. | 1677 /// Attempt to align the element to the top of the scrollable area. |
1664 static const TOP = const ScrollAlignment._internal('TOP'); | 1678 static const TOP = const ScrollAlignment._internal('TOP'); |
1665 /// Attempt to center the element in the scrollable area. | 1679 /// Attempt to center the element in the scrollable area. |
1666 static const CENTER = const ScrollAlignment._internal('CENTER'); | 1680 static const CENTER = const ScrollAlignment._internal('CENTER'); |
1667 /// Attempt to align the element to the bottom of the scrollable area. | 1681 /// Attempt to align the element to the bottom of the scrollable area. |
1668 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); | 1682 static const BOTTOM = const ScrollAlignment._internal('BOTTOM'); |
1669 } | 1683 } |
OLD | NEW |