| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {!WebInspector.CSSStyleDeclaration} ownerStyle | 7 * @param {!WebInspector.CSSStyleDeclaration} ownerStyle |
| 8 * @param {number} index | 8 * @param {number} index |
| 9 * @param {string} name | 9 * @param {string} name |
| 10 * @param {string} value | 10 * @param {string} value |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 this.index = index; | 21 this.index = index; |
| 22 this.name = name; | 22 this.name = name; |
| 23 this.value = value; | 23 this.value = value; |
| 24 this.important = important; | 24 this.important = important; |
| 25 this.disabled = disabled; | 25 this.disabled = disabled; |
| 26 this.parsedOk = parsedOk; | 26 this.parsedOk = parsedOk; |
| 27 this.implicit = implicit; // A longhand, implicitly set by missing values of
shorthand. | 27 this.implicit = implicit; // A longhand, implicitly set by missing values of
shorthand. |
| 28 this.text = text; | 28 this.text = text; |
| 29 this.range = range ? WebInspector.TextRange.fromObject(range) : null; | 29 this.range = range ? WebInspector.TextRange.fromObject(range) : null; |
| 30 this._active = true; | 30 this._active = true; |
| 31 this._nameRange = null; |
| 32 this._valueRange = null; |
| 31 } | 33 } |
| 32 | 34 |
| 33 /** | 35 /** |
| 34 * @param {!WebInspector.CSSStyleDeclaration} ownerStyle | 36 * @param {!WebInspector.CSSStyleDeclaration} ownerStyle |
| 35 * @param {number} index | 37 * @param {number} index |
| 36 * @param {!CSSAgent.CSSProperty} payload | 38 * @param {!CSSAgent.CSSProperty} payload |
| 37 * @return {!WebInspector.CSSProperty} | 39 * @return {!WebInspector.CSSProperty} |
| 38 */ | 40 */ |
| 39 WebInspector.CSSProperty.parsePayload = function(ownerStyle, index, payload) | 41 WebInspector.CSSProperty.parsePayload = function(ownerStyle, index, payload) |
| 40 { | 42 { |
| 41 // The following default field values are used in the payload: | 43 // The following default field values are used in the payload: |
| 42 // important: false | 44 // important: false |
| 43 // parsedOk: true | 45 // parsedOk: true |
| 44 // implicit: false | 46 // implicit: false |
| 45 // disabled: false | 47 // disabled: false |
| 46 var result = new WebInspector.CSSProperty( | 48 var result = new WebInspector.CSSProperty( |
| 47 ownerStyle, index, payload.name, payload.value, payload.important || fal
se, payload.disabled || false, ("parsedOk" in payload) ? !!payload.parsedOk : tr
ue, !!payload.implicit, payload.text, payload.range); | 49 ownerStyle, index, payload.name, payload.value, payload.important || fal
se, payload.disabled || false, ("parsedOk" in payload) ? !!payload.parsedOk : tr
ue, !!payload.implicit, payload.text, payload.range); |
| 48 return result; | 50 return result; |
| 49 } | 51 } |
| 50 | 52 |
| 51 WebInspector.CSSProperty.prototype = { | 53 WebInspector.CSSProperty.prototype = { |
| 54 _ensureRanges: function() |
| 55 { |
| 56 if (this._nameRange && this._valueRange) |
| 57 return; |
| 58 var range = this.range; |
| 59 var text = this.text ? new WebInspector.Text(this.text) : null; |
| 60 if (!range || !text) |
| 61 return; |
| 62 |
| 63 var nameIndex = text.value().indexOf(this.name); |
| 64 var valueIndex = text.value().lastIndexOf(this.value); |
| 65 if (nameIndex === -1 || valueIndex === -1 || nameIndex > valueIndex) |
| 66 return; |
| 67 |
| 68 var nameSourceRange = new WebInspector.SourceRange(nameIndex, this.name.
length); |
| 69 var valueSourceRange = new WebInspector.SourceRange(valueIndex, this.val
ue.length); |
| 70 |
| 71 this._nameRange = rebase(text.toTextRange(nameSourceRange), range.startL
ine, range.startColumn); |
| 72 this._valueRange = rebase(text.toTextRange(valueSourceRange), range.star
tLine, range.startColumn); |
| 73 |
| 74 /** |
| 75 * @param {!WebInspector.TextRange} oneLineRange |
| 76 * @param {number} lineOffset |
| 77 * @param {number} columnOffset |
| 78 * @return {!WebInspector.TextRange} |
| 79 */ |
| 80 function rebase(oneLineRange, lineOffset, columnOffset) |
| 81 { |
| 82 if (oneLineRange.startLine === 0) { |
| 83 oneLineRange.startColumn += columnOffset; |
| 84 oneLineRange.endColumn += columnOffset; |
| 85 } |
| 86 oneLineRange.startLine += lineOffset; |
| 87 oneLineRange.endLine += lineOffset; |
| 88 return oneLineRange; |
| 89 } |
| 90 }, |
| 91 |
| 92 /** |
| 93 * @return {?WebInspector.TextRange} |
| 94 */ |
| 95 nameRange: function() |
| 96 { |
| 97 this._ensureRanges(); |
| 98 return this._nameRange; |
| 99 }, |
| 100 |
| 101 /** |
| 102 * @return {?WebInspector.TextRange} |
| 103 */ |
| 104 valueRange: function() |
| 105 { |
| 106 this._ensureRanges(); |
| 107 return this._valueRange; |
| 108 }, |
| 109 |
| 52 /** | 110 /** |
| 53 * @param {!WebInspector.CSSModel.Edit} edit | 111 * @param {!WebInspector.CSSModel.Edit} edit |
| 54 */ | 112 */ |
| 55 rebase: function(edit) | 113 rebase: function(edit) |
| 56 { | 114 { |
| 57 if (this.ownerStyle.styleSheetId !== edit.styleSheetId) | 115 if (this.ownerStyle.styleSheetId !== edit.styleSheetId) |
| 58 return; | 116 return; |
| 59 if (this.range) | 117 if (this.range) |
| 60 this.range = this.range.rebaseAfterTextEdit(edit.oldRange, edit.newR
ange); | 118 this.range = this.range.rebaseAfterTextEdit(edit.oldRange, edit.newR
ange); |
| 61 }, | 119 }, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 { | 291 { |
| 234 if (!this.ownerStyle) | 292 if (!this.ownerStyle) |
| 235 return Promise.resolve(false); | 293 return Promise.resolve(false); |
| 236 if (disabled === this.disabled) | 294 if (disabled === this.disabled) |
| 237 return Promise.resolve(true); | 295 return Promise.resolve(true); |
| 238 var propertyText = this.text.trim(); | 296 var propertyText = this.text.trim(); |
| 239 var text = disabled ? "/* " + propertyText + " */" : this.text.substring
(2, propertyText.length - 2).trim(); | 297 var text = disabled ? "/* " + propertyText + " */" : this.text.substring
(2, propertyText.length - 2).trim(); |
| 240 return this.setText(text, true, true); | 298 return this.setText(text, true, true); |
| 241 } | 299 } |
| 242 } | 300 } |
| OLD | NEW |