| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.DOMSyntaxHighlighter = class { | 34 UI.DOMSyntaxHighlighter = class { |
| 35 /** | 35 /** |
| 36 * @param {string} mimeType | 36 * @param {string} mimeType |
| 37 * @param {boolean} stripExtraWhitespace | 37 * @param {boolean} stripExtraWhitespace |
| 38 */ | 38 */ |
| 39 constructor(mimeType, stripExtraWhitespace) { | 39 constructor(mimeType, stripExtraWhitespace) { |
| 40 this._mimeType = mimeType; | 40 this._mimeType = mimeType; |
| 41 this._stripExtraWhitespace = stripExtraWhitespace; | 41 this._stripExtraWhitespace = stripExtraWhitespace; |
| 42 } | 42 } |
| 43 | 43 |
| 44 /** | 44 /** |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * @param {!Element} node | 59 * @param {!Element} node |
| 60 * @return {!Promise.<undefined>} | 60 * @return {!Promise.<undefined>} |
| 61 */ | 61 */ |
| 62 syntaxHighlightNode(node) { | 62 syntaxHighlightNode(node) { |
| 63 var lines = node.textContent.split('\n'); | 63 var lines = node.textContent.split('\n'); |
| 64 var plainTextStart; | 64 var plainTextStart; |
| 65 var line; | 65 var line; |
| 66 | 66 |
| 67 return self.runtime.extension(WebInspector.TokenizerFactory).instance().then
(processTokens.bind(this)); | 67 return self.runtime.extension(Common.TokenizerFactory).instance().then(proce
ssTokens.bind(this)); |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * @param {!WebInspector.TokenizerFactory} tokenizerFactory | 70 * @param {!Common.TokenizerFactory} tokenizerFactory |
| 71 * @this {WebInspector.DOMSyntaxHighlighter} | 71 * @this {UI.DOMSyntaxHighlighter} |
| 72 */ | 72 */ |
| 73 function processTokens(tokenizerFactory) { | 73 function processTokens(tokenizerFactory) { |
| 74 node.removeChildren(); | 74 node.removeChildren(); |
| 75 var tokenize = tokenizerFactory.createTokenizer(this._mimeType); | 75 var tokenize = tokenizerFactory.createTokenizer(this._mimeType); |
| 76 for (var i = 0; i < lines.length; ++i) { | 76 for (var i = 0; i < lines.length; ++i) { |
| 77 line = lines[i]; | 77 line = lines[i]; |
| 78 plainTextStart = 0; | 78 plainTextStart = 0; |
| 79 tokenize(line, processToken.bind(this)); | 79 tokenize(line, processToken.bind(this)); |
| 80 if (plainTextStart < line.length) { | 80 if (plainTextStart < line.length) { |
| 81 var plainText = line.substring(plainTextStart, line.length); | 81 var plainText = line.substring(plainTextStart, line.length); |
| 82 node.createTextChild(plainText); | 82 node.createTextChild(plainText); |
| 83 } | 83 } |
| 84 if (i < lines.length - 1) | 84 if (i < lines.length - 1) |
| 85 node.createTextChild('\n'); | 85 node.createTextChild('\n'); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * @param {string} token | 90 * @param {string} token |
| 91 * @param {?string} tokenType | 91 * @param {?string} tokenType |
| 92 * @param {number} column | 92 * @param {number} column |
| 93 * @param {number} newColumn | 93 * @param {number} newColumn |
| 94 * @this {WebInspector.DOMSyntaxHighlighter} | 94 * @this {UI.DOMSyntaxHighlighter} |
| 95 */ | 95 */ |
| 96 function processToken(token, tokenType, column, newColumn) { | 96 function processToken(token, tokenType, column, newColumn) { |
| 97 if (!tokenType) | 97 if (!tokenType) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 if (column > plainTextStart) { | 100 if (column > plainTextStart) { |
| 101 var plainText = line.substring(plainTextStart, column); | 101 var plainText = line.substring(plainTextStart, column); |
| 102 node.createTextChild(plainText); | 102 node.createTextChild(plainText); |
| 103 } | 103 } |
| 104 node.appendChild(this.createSpan(token, tokenType)); | 104 node.appendChild(this.createSpan(token, tokenType)); |
| 105 plainTextStart = newColumn; | 105 plainTextStart = newColumn; |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 }; | 108 }; |
| OLD | NEW |