| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 this._lastLine = -1; | 52 this._lastLine = -1; |
| 53 this._state = {}; | 53 this._state = {}; |
| 54 var tokenize = WebInspector.createTokenizer("text/css"); | 54 var tokenize = WebInspector.createTokenizer("text/css"); |
| 55 tokenize(text.substring(this._fromOffset, this._toOffset), this._tokenCa
llback.bind(this)); | 55 tokenize(text.substring(this._fromOffset, this._toOffset), this._tokenCa
llback.bind(this)); |
| 56 }, | 56 }, |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * @param {string} token | 59 * @param {string} token |
| 60 * @param {?string} type | 60 * @param {?string} type |
| 61 * @param {number} startPosition | 61 * @param {number} startPosition |
| 62 * @param {number} endPosition | |
| 63 */ | 62 */ |
| 64 _tokenCallback: function(token, type, startPosition, endPosition) | 63 _tokenCallback: function(token, type, startPosition) |
| 65 { | 64 { |
| 66 startPosition += this._fromOffset; | 65 startPosition += this._fromOffset; |
| 67 endPosition += this._fromOffset; | |
| 68 var startLine = this._lineEndings.lowerBound(startPosition); | 66 var startLine = this._lineEndings.lowerBound(startPosition); |
| 69 var endLine = this._lineEndings.lowerBound(endPosition); | |
| 70 if (startLine !== this._lastLine) | 67 if (startLine !== this._lastLine) |
| 71 this._state.eatWhitespace = true; | 68 this._state.eatWhitespace = true; |
| 72 if (/^property/.test(type) && !this._state.inPropertyValue) | 69 if (/^property/.test(type) && !this._state.inPropertyValue) |
| 73 this._state.seenProperty = true; | 70 this._state.seenProperty = true; |
| 74 this._lastLine = startLine; | 71 this._lastLine = startLine; |
| 75 var isWhitespace = /^\s+$/.test(token); | 72 var isWhitespace = /^\s+$/.test(token); |
| 76 if (isWhitespace) { | 73 if (isWhitespace) { |
| 77 if (!this._state.eatWhitespace) | 74 if (!this._state.eatWhitespace) |
| 78 this._builder.addSoftSpace(); | 75 this._builder.addSoftSpace(); |
| 79 return; | 76 return; |
| 80 } | 77 } |
| 81 this._state.eatWhitespace = false; | 78 this._state.eatWhitespace = false; |
| 82 if (token === "\n") | 79 if (token === "\n") |
| 83 return; | 80 return; |
| 84 | 81 |
| 85 if (token !== "}") { | 82 if (token !== "}") { |
| 86 if (this._state.afterClosingBrace) | 83 if (this._state.afterClosingBrace) |
| 87 this._builder.addNewLine(true); | 84 this._builder.addNewLine(true); |
| 88 this._state.afterClosingBrace = false; | 85 this._state.afterClosingBrace = false; |
| 89 } | 86 } |
| 90 if (token === "}") { | 87 if (token === "}") { |
| 91 if (this._state.inPropertyValue) | 88 if (this._state.inPropertyValue) |
| 92 this._builder.addNewLine(); | 89 this._builder.addNewLine(); |
| 93 this._builder.decreaseNestingLevel(); | 90 this._builder.decreaseNestingLevel(); |
| 94 this._state.afterClosingBrace = true; | 91 this._state.afterClosingBrace = true; |
| 95 this._state.inPropertyValue = false; | 92 this._state.inPropertyValue = false; |
| 96 } else if (token === ":" && !this._state.inPropertyValue && this._state.
seenProperty) { | 93 } else if (token === ":" && !this._state.inPropertyValue && this._state.
seenProperty) { |
| 97 this._builder.addToken(token, startPosition, startLine, endLine); | 94 this._builder.addToken(token, startPosition); |
| 98 this._builder.addSoftSpace(); | 95 this._builder.addSoftSpace(); |
| 99 this._state.eatWhitespace = true; | 96 this._state.eatWhitespace = true; |
| 100 this._state.inPropertyValue = true; | 97 this._state.inPropertyValue = true; |
| 101 this._state.seenProperty = false; | 98 this._state.seenProperty = false; |
| 102 return; | 99 return; |
| 103 } else if (token === "{") { | 100 } else if (token === "{") { |
| 104 this._builder.addSoftSpace(); | 101 this._builder.addSoftSpace(); |
| 105 this._builder.addToken(token, startPosition, startLine, endLine); | 102 this._builder.addToken(token, startPosition); |
| 106 this._builder.addNewLine(); | 103 this._builder.addNewLine(); |
| 107 this._builder.increaseNestingLevel(); | 104 this._builder.increaseNestingLevel(); |
| 108 return; | 105 return; |
| 109 } | 106 } |
| 110 | 107 |
| 111 this._builder.addToken(token, startPosition, startLine, endLine); | 108 this._builder.addToken(token, startPosition); |
| 112 | 109 |
| 113 if (type === "comment" && !this._state.inPropertyValue && !this._state.s
eenProperty) | 110 if (type === "comment" && !this._state.inPropertyValue && !this._state.s
eenProperty) |
| 114 this._builder.addNewLine(); | 111 this._builder.addNewLine(); |
| 115 if (token === ";" && this._state.inPropertyValue) { | 112 if (token === ";" && this._state.inPropertyValue) { |
| 116 this._state.inPropertyValue = false; | 113 this._state.inPropertyValue = false; |
| 117 this._builder.addNewLine(); | 114 this._builder.addNewLine(); |
| 118 } else if (token === "}") { | 115 } else if (token === "}") { |
| 119 this._builder.addNewLine(); | 116 this._builder.addNewLine(); |
| 120 } | 117 } |
| 121 } | 118 } |
| 122 } | 119 } |
| OLD | NEW |