Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1274 value = value.replace(closingPunctuationRegex, '$&\u200B'); | 1274 value = value.replace(closingPunctuationRegex, '$&\u200B'); |
| 1275 if (value.startsWith('data:')) | 1275 if (value.startsWith('data:')) |
| 1276 value = value.trimMiddle(60); | 1276 value = value.trimMiddle(60); |
| 1277 var link = node.nodeName().toLowerCase() === 'a' ? | 1277 var link = node.nodeName().toLowerCase() === 'a' ? |
| 1278 UI.createExternalLink(rewrittenHref, value, '', true) : | 1278 UI.createExternalLink(rewrittenHref, value, '', true) : |
| 1279 Components.Linkifier.linkifyURL(rewrittenHref, value, '', undefined, u ndefined, true); | 1279 Components.Linkifier.linkifyURL(rewrittenHref, value, '', undefined, u ndefined, true); |
| 1280 link[Elements.ElementsTreeElement.HrefSymbol] = rewrittenHref; | 1280 link[Elements.ElementsTreeElement.HrefSymbol] = rewrittenHref; |
| 1281 return link; | 1281 return link; |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 if (node && (name === 'src' || name === 'href')) { | 1284 var nodeName = node ? node.nodeName().toLowerCase() : ''; |
| 1285 if (node && (name === 'src' || name === 'href')) | |
|
dgozman
2017/05/08 23:37:40
Use nodeName here.
luoe
2017/05/09 02:53:18
Done.
| |
| 1285 attrValueElement.appendChild(linkifyValue.call(this, value)); | 1286 attrValueElement.appendChild(linkifyValue.call(this, value)); |
| 1286 } else if ( | 1287 else if ((nodeName === 'img' || nodeName === 'source') && name === 'srcset') |
| 1287 node && (node.nodeName().toLowerCase() === 'img' || node.nodeName().toLo werCase() === 'source') && | 1288 attrValueElement.appendChild(linkifySrcset.call(this, value)); |
| 1288 name === 'srcset') { | 1289 else |
| 1289 var sources = value.split(','); | |
| 1290 for (var i = 0; i < sources.length; ++i) { | |
| 1291 if (i > 0) | |
| 1292 attrValueElement.createTextChild(', '); | |
| 1293 var source = sources[i].trim(); | |
| 1294 var indexOfSpace = source.indexOf(' '); | |
| 1295 var url, tail; | |
| 1296 | |
| 1297 if (indexOfSpace === -1) { | |
| 1298 url = source; | |
| 1299 } else { | |
| 1300 url = source.substring(0, indexOfSpace); | |
| 1301 tail = source.substring(indexOfSpace); | |
| 1302 } | |
| 1303 | |
| 1304 attrValueElement.appendChild(linkifyValue.call(this, url)); | |
| 1305 | |
| 1306 if (tail) | |
| 1307 attrValueElement.createTextChild(tail); | |
| 1308 } | |
| 1309 } else { | |
| 1310 setValueWithEntities.call(this, attrValueElement, value); | 1290 setValueWithEntities.call(this, attrValueElement, value); |
| 1311 } | |
| 1312 | 1291 |
| 1313 if (hasText) | 1292 if (hasText) |
| 1314 attrSpanElement.createTextChild('"'); | 1293 attrSpanElement.createTextChild('"'); |
| 1294 | |
| 1295 /** | |
| 1296 * @param {string} value | |
| 1297 * @return {!DocumentFragment} | |
| 1298 * @this {!Elements.ElementsTreeElement} | |
| 1299 */ | |
| 1300 function linkifySrcset(value) { | |
| 1301 // Splitting normally on commas or spaces will break on valid srcsets "foo 1x,bar 2x" and "data:,foo 1x". | |
| 1302 // 1) Let the index of the next space be `i`. | |
| 1303 // 2a) If the character at `i-1` is a comma, collect the preceding charact ers up to `i-1` as a URL and repeat 1). | |
| 1304 // 2b) Else, collect the preceding characters as a URL. | |
| 1305 // 3) Collect the characters from `i` up to the next comma as the size des criptor. | |
| 1306 // https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-sr cset-attribute | |
| 1307 var fragment = createDocumentFragment(); | |
| 1308 var i = 0; | |
| 1309 while (value.length) { | |
| 1310 if (i++ > 0) | |
| 1311 fragment.createTextChild(' '); | |
| 1312 value = value.trim(); | |
| 1313 var url = ''; | |
| 1314 var descriptor = ''; | |
| 1315 var indexOfSpace = value.search(/\s/); | |
|
dgozman
2017/05/08 23:37:40
Comment above calls this 'i'. Let's align
luoe
2017/05/09 02:53:18
Done.
| |
| 1316 if (indexOfSpace === -1) { | |
| 1317 url = value; | |
| 1318 } else if (indexOfSpace > 0 && value[indexOfSpace - 1] === ',') { | |
| 1319 url = value.substring(0, indexOfSpace); | |
| 1320 } else { | |
| 1321 url = value.substring(0, indexOfSpace); | |
| 1322 var indexOfComma = value.indexOf(',', indexOfSpace); | |
| 1323 if (indexOfComma !== -1) | |
| 1324 descriptor = value.substring(indexOfSpace, indexOfComma + 1); | |
|
dgozman
2017/05/08 23:37:40
Should this be indexOfComma-1 ?
luoe
2017/05/09 02:53:18
No, I actually want to include the comma in the `d
| |
| 1325 else | |
| 1326 descriptor = value.substring(indexOfSpace); | |
| 1327 } | |
| 1328 | |
| 1329 if (url) | |
| 1330 fragment.appendChild(linkifyValue.call(this, url)); | |
| 1331 if (descriptor) | |
| 1332 fragment.createTextChild(descriptor); | |
| 1333 value = value.substring(url.length + descriptor.length); | |
| 1334 } | |
| 1335 return fragment; | |
| 1336 } | |
| 1315 } | 1337 } |
| 1316 | 1338 |
| 1317 /** | 1339 /** |
| 1318 * @param {!Node} parentElement | 1340 * @param {!Node} parentElement |
| 1319 * @param {string} pseudoElementName | 1341 * @param {string} pseudoElementName |
| 1320 */ | 1342 */ |
| 1321 _buildPseudoElementDOM(parentElement, pseudoElementName) { | 1343 _buildPseudoElementDOM(parentElement, pseudoElementName) { |
| 1322 var pseudoElement = parentElement.createChild('span', 'webkit-html-pseudo-el ement'); | 1344 var pseudoElement = parentElement.createChild('span', 'webkit-html-pseudo-el ement'); |
| 1323 pseudoElement.textContent = '::' + pseudoElementName; | 1345 pseudoElement.textContent = '::' + pseudoElementName; |
| 1324 parentElement.createTextChild('\u200B'); | 1346 parentElement.createTextChild('\u200B'); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1630 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ | 1652 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ |
| 1631 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed', 'frame', 'hr', | 1653 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed', 'frame', 'hr', |
| 1632 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr' | 1654 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr' |
| 1633 ]); | 1655 ]); |
| 1634 | 1656 |
| 1635 // These tags we do not allow editing their tag name. | 1657 // These tags we do not allow editing their tag name. |
| 1636 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body'] ); | 1658 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body'] ); |
| 1637 | 1659 |
| 1638 /** @typedef {{cancel: function(), commit: function(), resize: function(), edito r:!UI.TextEditor}} */ | 1660 /** @typedef {{cancel: function(), commit: function(), resize: function(), edito r:!UI.TextEditor}} */ |
| 1639 Elements.MultilineEditorController; | 1661 Elements.MultilineEditorController; |
| OLD | NEW |