| 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 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.CSSSourceFrame = class extends WebInspector.UISourceCodeFrame { | 34 Sources.CSSSourceFrame = class extends Sources.UISourceCodeFrame { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.UISourceCode} uiSourceCode | 36 * @param {!Workspace.UISourceCode} uiSourceCode |
| 37 */ | 37 */ |
| 38 constructor(uiSourceCode) { | 38 constructor(uiSourceCode) { |
| 39 super(uiSourceCode); | 39 super(uiSourceCode); |
| 40 this._registerShortcuts(); | 40 this._registerShortcuts(); |
| 41 this._swatchPopoverHelper = new WebInspector.SwatchPopoverHelper(); | 41 this._swatchPopoverHelper = new UI.SwatchPopoverHelper(); |
| 42 this._muteSwatchProcessing = false; | 42 this._muteSwatchProcessing = false; |
| 43 this.configureAutocomplete( | 43 this.configureAutocomplete( |
| 44 {suggestionsCallback: this._cssSuggestions.bind(this), isWordChar: this.
_isWordChar.bind(this)}); | 44 {suggestionsCallback: this._cssSuggestions.bind(this), isWordChar: this.
_isWordChar.bind(this)}); |
| 45 this.textEditor.addEventListener(WebInspector.SourcesTextEditor.Events.Scrol
lChanged, () => { | 45 this.textEditor.addEventListener(SourceFrame.SourcesTextEditor.Events.Scroll
Changed, () => { |
| 46 if (this._swatchPopoverHelper.isShowing()) | 46 if (this._swatchPopoverHelper.isShowing()) |
| 47 this._swatchPopoverHelper.hide(true); | 47 this._swatchPopoverHelper.hide(true); |
| 48 }); | 48 }); |
| 49 } | 49 } |
| 50 | 50 |
| 51 _registerShortcuts() { | 51 _registerShortcuts() { |
| 52 var shortcutKeys = WebInspector.ShortcutsScreen.SourcesPanelShortcuts; | 52 var shortcutKeys = Components.ShortcutsScreen.SourcesPanelShortcuts; |
| 53 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByOne.length; ++i) | 53 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByOne.length; ++i) |
| 54 this.addShortcut(shortcutKeys.IncreaseCSSUnitByOne[i].key, this._handleUni
tModification.bind(this, 1)); | 54 this.addShortcut(shortcutKeys.IncreaseCSSUnitByOne[i].key, this._handleUni
tModification.bind(this, 1)); |
| 55 for (var i = 0; i < shortcutKeys.DecreaseCSSUnitByOne.length; ++i) | 55 for (var i = 0; i < shortcutKeys.DecreaseCSSUnitByOne.length; ++i) |
| 56 this.addShortcut(shortcutKeys.DecreaseCSSUnitByOne[i].key, this._handleUni
tModification.bind(this, -1)); | 56 this.addShortcut(shortcutKeys.DecreaseCSSUnitByOne[i].key, this._handleUni
tModification.bind(this, -1)); |
| 57 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByTen.length; ++i) | 57 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByTen.length; ++i) |
| 58 this.addShortcut(shortcutKeys.IncreaseCSSUnitByTen[i].key, this._handleUni
tModification.bind(this, 10)); | 58 this.addShortcut(shortcutKeys.IncreaseCSSUnitByTen[i].key, this._handleUni
tModification.bind(this, 10)); |
| 59 for (var i = 0; i < shortcutKeys.DecreaseCSSUnitByTen.length; ++i) | 59 for (var i = 0; i < shortcutKeys.DecreaseCSSUnitByTen.length; ++i) |
| 60 this.addShortcut(shortcutKeys.DecreaseCSSUnitByTen[i].key, this._handleUni
tModification.bind(this, -10)); | 60 this.addShortcut(shortcutKeys.DecreaseCSSUnitByTen[i].key, this._handleUni
tModification.bind(this, -10)); |
| 61 } | 61 } |
| 62 | 62 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 83 if (!token) { | 83 if (!token) { |
| 84 if (selection.startColumn > 0) | 84 if (selection.startColumn > 0) |
| 85 token = this.textEditor.tokenAtTextPosition(selection.startLine, selecti
on.startColumn - 1); | 85 token = this.textEditor.tokenAtTextPosition(selection.startLine, selecti
on.startColumn - 1); |
| 86 if (!token) | 86 if (!token) |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 89 if (token.type !== 'css-number') | 89 if (token.type !== 'css-number') |
| 90 return false; | 90 return false; |
| 91 | 91 |
| 92 var cssUnitRange = | 92 var cssUnitRange = |
| 93 new WebInspector.TextRange(selection.startLine, token.startColumn, selec
tion.startLine, token.endColumn); | 93 new Common.TextRange(selection.startLine, token.startColumn, selection.s
tartLine, token.endColumn); |
| 94 var cssUnitText = this.textEditor.text(cssUnitRange); | 94 var cssUnitText = this.textEditor.text(cssUnitRange); |
| 95 var newUnitText = this._modifyUnit(cssUnitText, change); | 95 var newUnitText = this._modifyUnit(cssUnitText, change); |
| 96 if (!newUnitText) | 96 if (!newUnitText) |
| 97 return false; | 97 return false; |
| 98 this.textEditor.editRange(cssUnitRange, newUnitText); | 98 this.textEditor.editRange(cssUnitRange, newUnitText); |
| 99 selection.startColumn = token.startColumn; | 99 selection.startColumn = token.startColumn; |
| 100 selection.endColumn = selection.startColumn + newUnitText.length; | 100 selection.endColumn = selection.startColumn + newUnitText.length; |
| 101 this.textEditor.setSelection(selection); | 101 this.textEditor.setSelection(selection); |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * @param {number} startLine | 106 * @param {number} startLine |
| 107 * @param {number} endLine | 107 * @param {number} endLine |
| 108 */ | 108 */ |
| 109 _updateSwatches(startLine, endLine) { | 109 _updateSwatches(startLine, endLine) { |
| 110 var swatches = []; | 110 var swatches = []; |
| 111 var swatchPositions = []; | 111 var swatchPositions = []; |
| 112 | 112 |
| 113 var regexes = [ | 113 var regexes = [ |
| 114 WebInspector.CSSMetadata.VariableRegex, WebInspector.CSSMetadata.URLRegex, | 114 SDK.CSSMetadata.VariableRegex, SDK.CSSMetadata.URLRegex, |
| 115 WebInspector.Geometry.CubicBezier.Regex, WebInspector.Color.Regex | 115 Common.Geometry.CubicBezier.Regex, Common.Color.Regex |
| 116 ]; | 116 ]; |
| 117 var handlers = new Map(); | 117 var handlers = new Map(); |
| 118 handlers.set(WebInspector.Color.Regex, this._createColorSwatch.bind(this)); | 118 handlers.set(Common.Color.Regex, this._createColorSwatch.bind(this)); |
| 119 handlers.set(WebInspector.Geometry.CubicBezier.Regex, this._createBezierSwat
ch.bind(this)); | 119 handlers.set(Common.Geometry.CubicBezier.Regex, this._createBezierSwatch.bin
d(this)); |
| 120 | 120 |
| 121 for (var lineNumber = startLine; lineNumber <= endLine; lineNumber++) { | 121 for (var lineNumber = startLine; lineNumber <= endLine; lineNumber++) { |
| 122 var line = this.textEditor.line(lineNumber).substring(0, WebInspector.CSSS
ourceFrame.maxSwatchProcessingLength); | 122 var line = this.textEditor.line(lineNumber).substring(0, Sources.CSSSource
Frame.maxSwatchProcessingLength); |
| 123 var results = WebInspector.TextUtils.splitStringByRegexes(line, regexes); | 123 var results = Common.TextUtils.splitStringByRegexes(line, regexes); |
| 124 for (var i = 0; i < results.length; i++) { | 124 for (var i = 0; i < results.length; i++) { |
| 125 var result = results[i]; | 125 var result = results[i]; |
| 126 if (result.regexIndex === -1 || !handlers.has(regexes[result.regexIndex]
)) | 126 if (result.regexIndex === -1 || !handlers.has(regexes[result.regexIndex]
)) |
| 127 continue; | 127 continue; |
| 128 var delimiters = /[\s:;,(){}]/; | 128 var delimiters = /[\s:;,(){}]/; |
| 129 var positionBefore = result.position - 1; | 129 var positionBefore = result.position - 1; |
| 130 var positionAfter = result.position + result.value.length; | 130 var positionAfter = result.position + result.value.length; |
| 131 if (positionBefore >= 0 && !delimiters.test(line.charAt(positionBefore))
|| | 131 if (positionBefore >= 0 && !delimiters.test(line.charAt(positionBefore))
|| |
| 132 positionAfter < line.length && !delimiters.test(line.charAt(position
After))) | 132 positionAfter < line.length && !delimiters.test(line.charAt(position
After))) |
| 133 continue; | 133 continue; |
| 134 var swatch = handlers.get(regexes[result.regexIndex])(result.value); | 134 var swatch = handlers.get(regexes[result.regexIndex])(result.value); |
| 135 if (!swatch) | 135 if (!swatch) |
| 136 continue; | 136 continue; |
| 137 swatches.push(swatch); | 137 swatches.push(swatch); |
| 138 swatchPositions.push(WebInspector.TextRange.createFromLocation(lineNumbe
r, result.position)); | 138 swatchPositions.push(Common.TextRange.createFromLocation(lineNumber, res
ult.position)); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 this.textEditor.operation(putSwatchesInline.bind(this)); | 141 this.textEditor.operation(putSwatchesInline.bind(this)); |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * @this {WebInspector.CSSSourceFrame} | 144 * @this {Sources.CSSSourceFrame} |
| 145 */ | 145 */ |
| 146 function putSwatchesInline() { | 146 function putSwatchesInline() { |
| 147 var clearRange = new WebInspector.TextRange(startLine, 0, endLine, this.te
xtEditor.line(endLine).length); | 147 var clearRange = new Common.TextRange(startLine, 0, endLine, this.textEdit
or.line(endLine).length); |
| 148 this.textEditor.bookmarks(clearRange, WebInspector.CSSSourceFrame.SwatchBo
okmark) | 148 this.textEditor.bookmarks(clearRange, Sources.CSSSourceFrame.SwatchBookmar
k) |
| 149 .forEach(marker => marker.clear()); | 149 .forEach(marker => marker.clear()); |
| 150 | 150 |
| 151 for (var i = 0; i < swatches.length; i++) { | 151 for (var i = 0; i < swatches.length; i++) { |
| 152 var swatch = swatches[i]; | 152 var swatch = swatches[i]; |
| 153 var swatchPosition = swatchPositions[i]; | 153 var swatchPosition = swatchPositions[i]; |
| 154 var bookmark = this.textEditor.addBookmark( | 154 var bookmark = this.textEditor.addBookmark( |
| 155 swatchPosition.startLine, swatchPosition.startColumn, swatch, WebIns
pector.CSSSourceFrame.SwatchBookmark); | 155 swatchPosition.startLine, swatchPosition.startColumn, swatch, Source
s.CSSSourceFrame.SwatchBookmark); |
| 156 swatch[WebInspector.CSSSourceFrame.SwatchBookmark] = bookmark; | 156 swatch[Sources.CSSSourceFrame.SwatchBookmark] = bookmark; |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 /** | 161 /** |
| 162 * @param {string} text | 162 * @param {string} text |
| 163 * @return {?WebInspector.ColorSwatch} | 163 * @return {?UI.ColorSwatch} |
| 164 */ | 164 */ |
| 165 _createColorSwatch(text) { | 165 _createColorSwatch(text) { |
| 166 var color = WebInspector.Color.parse(text); | 166 var color = Common.Color.parse(text); |
| 167 if (!color) | 167 if (!color) |
| 168 return null; | 168 return null; |
| 169 var swatch = WebInspector.ColorSwatch.create(); | 169 var swatch = UI.ColorSwatch.create(); |
| 170 swatch.setColor(color); | 170 swatch.setColor(color); |
| 171 swatch.iconElement().title = WebInspector.UIString('Open color picker.'); | 171 swatch.iconElement().title = Common.UIString('Open color picker.'); |
| 172 swatch.iconElement().addEventListener('click', this._swatchIconClicked.bind(
this, swatch), false); | 172 swatch.iconElement().addEventListener('click', this._swatchIconClicked.bind(
this, swatch), false); |
| 173 swatch.hideText(true); | 173 swatch.hideText(true); |
| 174 return swatch; | 174 return swatch; |
| 175 } | 175 } |
| 176 | 176 |
| 177 /** | 177 /** |
| 178 * @param {string} text | 178 * @param {string} text |
| 179 * @return {?WebInspector.BezierSwatch} | 179 * @return {?UI.BezierSwatch} |
| 180 */ | 180 */ |
| 181 _createBezierSwatch(text) { | 181 _createBezierSwatch(text) { |
| 182 if (!WebInspector.Geometry.CubicBezier.parse(text)) | 182 if (!Common.Geometry.CubicBezier.parse(text)) |
| 183 return null; | 183 return null; |
| 184 var swatch = WebInspector.BezierSwatch.create(); | 184 var swatch = UI.BezierSwatch.create(); |
| 185 swatch.setBezierText(text); | 185 swatch.setBezierText(text); |
| 186 swatch.iconElement().title = WebInspector.UIString('Open cubic bezier editor
.'); | 186 swatch.iconElement().title = Common.UIString('Open cubic bezier editor.'); |
| 187 swatch.iconElement().addEventListener('click', this._swatchIconClicked.bind(
this, swatch), false); | 187 swatch.iconElement().addEventListener('click', this._swatchIconClicked.bind(
this, swatch), false); |
| 188 swatch.hideText(true); | 188 swatch.hideText(true); |
| 189 return swatch; | 189 return swatch; |
| 190 } | 190 } |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * @param {!Element} swatch | 193 * @param {!Element} swatch |
| 194 * @param {!Event} event | 194 * @param {!Event} event |
| 195 */ | 195 */ |
| 196 _swatchIconClicked(swatch, event) { | 196 _swatchIconClicked(swatch, event) { |
| 197 event.consume(true); | 197 event.consume(true); |
| 198 this._hadSwatchChange = false; | 198 this._hadSwatchChange = false; |
| 199 this._muteSwatchProcessing = true; | 199 this._muteSwatchProcessing = true; |
| 200 var swatchPosition = swatch[WebInspector.CSSSourceFrame.SwatchBookmark].posi
tion(); | 200 var swatchPosition = swatch[Sources.CSSSourceFrame.SwatchBookmark].position(
); |
| 201 this.textEditor.setSelection(swatchPosition); | 201 this.textEditor.setSelection(swatchPosition); |
| 202 this._editedSwatchTextRange = swatchPosition.clone(); | 202 this._editedSwatchTextRange = swatchPosition.clone(); |
| 203 this._editedSwatchTextRange.endColumn += swatch.textContent.length; | 203 this._editedSwatchTextRange.endColumn += swatch.textContent.length; |
| 204 this._currentSwatch = swatch; | 204 this._currentSwatch = swatch; |
| 205 | 205 |
| 206 if (swatch instanceof WebInspector.ColorSwatch) | 206 if (swatch instanceof UI.ColorSwatch) |
| 207 this._showSpectrum(swatch); | 207 this._showSpectrum(swatch); |
| 208 else if (swatch instanceof WebInspector.BezierSwatch) | 208 else if (swatch instanceof UI.BezierSwatch) |
| 209 this._showBezierEditor(swatch); | 209 this._showBezierEditor(swatch); |
| 210 } | 210 } |
| 211 | 211 |
| 212 /** | 212 /** |
| 213 * @param {!WebInspector.ColorSwatch} swatch | 213 * @param {!UI.ColorSwatch} swatch |
| 214 */ | 214 */ |
| 215 _showSpectrum(swatch) { | 215 _showSpectrum(swatch) { |
| 216 if (!this._spectrum) { | 216 if (!this._spectrum) { |
| 217 this._spectrum = new WebInspector.Spectrum(); | 217 this._spectrum = new Components.Spectrum(); |
| 218 this._spectrum.addEventListener(WebInspector.Spectrum.Events.SizeChanged,
this._spectrumResized, this); | 218 this._spectrum.addEventListener(Components.Spectrum.Events.SizeChanged, th
is._spectrumResized, this); |
| 219 this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChanged,
this._spectrumChanged, this); | 219 this._spectrum.addEventListener(Components.Spectrum.Events.ColorChanged, t
his._spectrumChanged, this); |
| 220 } | 220 } |
| 221 this._spectrum.setColor(swatch.color(), swatch.format()); | 221 this._spectrum.setColor(swatch.color(), swatch.format()); |
| 222 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), this._s
watchPopoverHidden.bind(this)); | 222 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), this._s
watchPopoverHidden.bind(this)); |
| 223 } | 223 } |
| 224 | 224 |
| 225 /** | 225 /** |
| 226 * @param {!WebInspector.Event} event | 226 * @param {!Common.Event} event |
| 227 */ | 227 */ |
| 228 _spectrumResized(event) { | 228 _spectrumResized(event) { |
| 229 this._swatchPopoverHelper.reposition(); | 229 this._swatchPopoverHelper.reposition(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 /** | 232 /** |
| 233 * @param {!WebInspector.Event} event | 233 * @param {!Common.Event} event |
| 234 */ | 234 */ |
| 235 _spectrumChanged(event) { | 235 _spectrumChanged(event) { |
| 236 var colorString = /** @type {string} */ (event.data); | 236 var colorString = /** @type {string} */ (event.data); |
| 237 var color = WebInspector.Color.parse(colorString); | 237 var color = Common.Color.parse(colorString); |
| 238 if (!color) | 238 if (!color) |
| 239 return; | 239 return; |
| 240 this._currentSwatch.setColor(color); | 240 this._currentSwatch.setColor(color); |
| 241 this._changeSwatchText(colorString); | 241 this._changeSwatchText(colorString); |
| 242 } | 242 } |
| 243 | 243 |
| 244 /** | 244 /** |
| 245 * @param {!WebInspector.BezierSwatch} swatch | 245 * @param {!UI.BezierSwatch} swatch |
| 246 */ | 246 */ |
| 247 _showBezierEditor(swatch) { | 247 _showBezierEditor(swatch) { |
| 248 if (!this._bezierEditor) { | 248 if (!this._bezierEditor) { |
| 249 this._bezierEditor = new WebInspector.BezierEditor(); | 249 this._bezierEditor = new UI.BezierEditor(); |
| 250 this._bezierEditor.addEventListener(WebInspector.BezierEditor.Events.Bezie
rChanged, this._bezierChanged, this); | 250 this._bezierEditor.addEventListener(UI.BezierEditor.Events.BezierChanged,
this._bezierChanged, this); |
| 251 } | 251 } |
| 252 var cubicBezier = WebInspector.Geometry.CubicBezier.parse(swatch.bezierText(
)); | 252 var cubicBezier = Common.Geometry.CubicBezier.parse(swatch.bezierText()); |
| 253 if (!cubicBezier) | 253 if (!cubicBezier) |
| 254 cubicBezier = | 254 cubicBezier = |
| 255 /** @type {!WebInspector.Geometry.CubicBezier} */ (WebInspector.Geomet
ry.CubicBezier.parse('linear')); | 255 /** @type {!Common.Geometry.CubicBezier} */ (Common.Geometry.CubicBezi
er.parse('linear')); |
| 256 this._bezierEditor.setBezier(cubicBezier); | 256 this._bezierEditor.setBezier(cubicBezier); |
| 257 this._swatchPopoverHelper.show(this._bezierEditor, swatch.iconElement(), thi
s._swatchPopoverHidden.bind(this)); | 257 this._swatchPopoverHelper.show(this._bezierEditor, swatch.iconElement(), thi
s._swatchPopoverHidden.bind(this)); |
| 258 } | 258 } |
| 259 | 259 |
| 260 /** | 260 /** |
| 261 * @param {!WebInspector.Event} event | 261 * @param {!Common.Event} event |
| 262 */ | 262 */ |
| 263 _bezierChanged(event) { | 263 _bezierChanged(event) { |
| 264 var bezierString = /** @type {string} */ (event.data); | 264 var bezierString = /** @type {string} */ (event.data); |
| 265 this._currentSwatch.setBezierText(bezierString); | 265 this._currentSwatch.setBezierText(bezierString); |
| 266 this._changeSwatchText(bezierString); | 266 this._changeSwatchText(bezierString); |
| 267 } | 267 } |
| 268 | 268 |
| 269 /** | 269 /** |
| 270 * @param {string} text | 270 * @param {string} text |
| 271 */ | 271 */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 288 * @override | 288 * @override |
| 289 */ | 289 */ |
| 290 onTextEditorContentSet() { | 290 onTextEditorContentSet() { |
| 291 super.onTextEditorContentSet(); | 291 super.onTextEditorContentSet(); |
| 292 if (!this._muteSwatchProcessing) | 292 if (!this._muteSwatchProcessing) |
| 293 this._updateSwatches(0, this.textEditor.linesCount - 1); | 293 this._updateSwatches(0, this.textEditor.linesCount - 1); |
| 294 } | 294 } |
| 295 | 295 |
| 296 /** | 296 /** |
| 297 * @override | 297 * @override |
| 298 * @param {!WebInspector.TextRange} oldRange | 298 * @param {!Common.TextRange} oldRange |
| 299 * @param {!WebInspector.TextRange} newRange | 299 * @param {!Common.TextRange} newRange |
| 300 */ | 300 */ |
| 301 onTextChanged(oldRange, newRange) { | 301 onTextChanged(oldRange, newRange) { |
| 302 super.onTextChanged(oldRange, newRange); | 302 super.onTextChanged(oldRange, newRange); |
| 303 if (!this._muteSwatchProcessing) | 303 if (!this._muteSwatchProcessing) |
| 304 this._updateSwatches(newRange.startLine, newRange.endLine); | 304 this._updateSwatches(newRange.startLine, newRange.endLine); |
| 305 } | 305 } |
| 306 | 306 |
| 307 /** | 307 /** |
| 308 * @param {string} char | 308 * @param {string} char |
| 309 * @return {boolean} | 309 * @return {boolean} |
| 310 */ | 310 */ |
| 311 _isWordChar(char) { | 311 _isWordChar(char) { |
| 312 return WebInspector.TextUtils.isWordChar(char) || char === '.' || char === '
-' || char === '$'; | 312 return Common.TextUtils.isWordChar(char) || char === '.' || char === '-' ||
char === '$'; |
| 313 } | 313 } |
| 314 | 314 |
| 315 /** | 315 /** |
| 316 * @param {!WebInspector.TextRange} prefixRange | 316 * @param {!Common.TextRange} prefixRange |
| 317 * @param {!WebInspector.TextRange} substituteRange | 317 * @param {!Common.TextRange} substituteRange |
| 318 * @return {?Promise.<!WebInspector.SuggestBox.Suggestions>} | 318 * @return {?Promise.<!UI.SuggestBox.Suggestions>} |
| 319 */ | 319 */ |
| 320 _cssSuggestions(prefixRange, substituteRange) { | 320 _cssSuggestions(prefixRange, substituteRange) { |
| 321 var prefix = this._textEditor.text(prefixRange); | 321 var prefix = this._textEditor.text(prefixRange); |
| 322 if (prefix.startsWith('$')) | 322 if (prefix.startsWith('$')) |
| 323 return null; | 323 return null; |
| 324 | 324 |
| 325 var propertyToken = this._backtrackPropertyToken(prefixRange.startLine, pref
ixRange.startColumn - 1); | 325 var propertyToken = this._backtrackPropertyToken(prefixRange.startLine, pref
ixRange.startColumn - 1); |
| 326 if (!propertyToken) | 326 if (!propertyToken) |
| 327 return null; | 327 return null; |
| 328 | 328 |
| 329 var line = this._textEditor.line(prefixRange.startLine); | 329 var line = this._textEditor.line(prefixRange.startLine); |
| 330 var tokenContent = line.substring(propertyToken.startColumn, propertyToken.e
ndColumn); | 330 var tokenContent = line.substring(propertyToken.startColumn, propertyToken.e
ndColumn); |
| 331 var propertyValues = WebInspector.cssMetadata().propertyValues(tokenContent)
; | 331 var propertyValues = SDK.cssMetadata().propertyValues(tokenContent); |
| 332 return Promise.resolve(propertyValues.filter(value => value.startsWith(prefi
x)).map(value => ({title: value}))); | 332 return Promise.resolve(propertyValues.filter(value => value.startsWith(prefi
x)).map(value => ({title: value}))); |
| 333 } | 333 } |
| 334 | 334 |
| 335 /** | 335 /** |
| 336 * @param {number} lineNumber | 336 * @param {number} lineNumber |
| 337 * @param {number} columnNumber | 337 * @param {number} columnNumber |
| 338 * @return {?{startColumn: number, endColumn: number, type: string}} | 338 * @return {?{startColumn: number, endColumn: number, type: string}} |
| 339 */ | 339 */ |
| 340 _backtrackPropertyToken(lineNumber, columnNumber) { | 340 _backtrackPropertyToken(lineNumber, columnNumber) { |
| 341 var backtrackDepth = 10; | 341 var backtrackDepth = 10; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 358 else | 358 else |
| 359 return null; | 359 return null; |
| 360 } | 360 } |
| 361 tokenPosition = token.startColumn - 1; | 361 tokenPosition = token.startColumn - 1; |
| 362 } | 362 } |
| 363 return null; | 363 return null; |
| 364 } | 364 } |
| 365 }; | 365 }; |
| 366 | 366 |
| 367 /** @type {number} */ | 367 /** @type {number} */ |
| 368 WebInspector.CSSSourceFrame.maxSwatchProcessingLength = 300; | 368 Sources.CSSSourceFrame.maxSwatchProcessingLength = 300; |
| 369 /** @type {symbol} */ | 369 /** @type {symbol} */ |
| 370 WebInspector.CSSSourceFrame.SwatchBookmark = Symbol('swatch'); | 370 Sources.CSSSourceFrame.SwatchBookmark = Symbol('swatch'); |
| OLD | NEW |