| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * @unrestricted | 31 * @unrestricted |
| 32 */ | 32 */ |
| 33 WebInspector.StylesSidebarPane = class extends WebInspector.ElementsSidebarPane
{ | 33 Elements.StylesSidebarPane = class extends Elements.ElementsSidebarPane { |
| 34 constructor() { | 34 constructor() { |
| 35 super(); | 35 super(); |
| 36 this.setMinimumSize(96, 26); | 36 this.setMinimumSize(96, 26); |
| 37 | 37 |
| 38 WebInspector.moduleSetting('colorFormat').addChangeListener(this.update.bind
(this)); | 38 Common.moduleSetting('colorFormat').addChangeListener(this.update.bind(this)
); |
| 39 WebInspector.moduleSetting('textEditorIndent').addChangeListener(this.update
.bind(this)); | 39 Common.moduleSetting('textEditorIndent').addChangeListener(this.update.bind(
this)); |
| 40 | 40 |
| 41 this._sectionsContainer = this.element.createChild('div'); | 41 this._sectionsContainer = this.element.createChild('div'); |
| 42 this._swatchPopoverHelper = new WebInspector.SwatchPopoverHelper(); | 42 this._swatchPopoverHelper = new UI.SwatchPopoverHelper(); |
| 43 this._linkifier = new WebInspector.Linkifier(WebInspector.StylesSidebarPane.
_maxLinkLength, /* useLinkDecorator */ true); | 43 this._linkifier = new Components.Linkifier(Elements.StylesSidebarPane._maxLi
nkLength, /* useLinkDecorator */ true); |
| 44 | 44 |
| 45 this.element.classList.add('styles-pane'); | 45 this.element.classList.add('styles-pane'); |
| 46 | 46 |
| 47 /** @type {!Array<!WebInspector.SectionBlock>} */ | 47 /** @type {!Array<!Elements.SectionBlock>} */ |
| 48 this._sectionBlocks = []; | 48 this._sectionBlocks = []; |
| 49 WebInspector.StylesSidebarPane._instance = this; | 49 Elements.StylesSidebarPane._instance = this; |
| 50 | 50 |
| 51 WebInspector.targetManager.addModelListener( | 51 SDK.targetManager.addModelListener( |
| 52 WebInspector.CSSModel, WebInspector.CSSModel.Events.LayoutEditorChange,
this._onLayoutEditorChange, this); | 52 SDK.CSSModel, SDK.CSSModel.Events.LayoutEditorChange, this._onLayoutEdit
orChange, this); |
| 53 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this.forc
eUpdate, this); | 53 UI.context.addFlavorChangeListener(SDK.DOMNode, this.forceUpdate, this); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @param {!WebInspector.CSSProperty} property | 57 * @param {!SDK.CSSProperty} property |
| 58 * @return {!Element} | 58 * @return {!Element} |
| 59 */ | 59 */ |
| 60 static createExclamationMark(property) { | 60 static createExclamationMark(property) { |
| 61 var exclamationElement = createElement('label', 'dt-icon-label'); | 61 var exclamationElement = createElement('label', 'dt-icon-label'); |
| 62 exclamationElement.className = 'exclamation-mark'; | 62 exclamationElement.className = 'exclamation-mark'; |
| 63 if (!WebInspector.StylesSidebarPane.ignoreErrorsForProperty(property)) | 63 if (!Elements.StylesSidebarPane.ignoreErrorsForProperty(property)) |
| 64 exclamationElement.type = 'smallicon-warning'; | 64 exclamationElement.type = 'smallicon-warning'; |
| 65 exclamationElement.title = WebInspector.cssMetadata().isCSSPropertyName(prop
erty.name) ? | 65 exclamationElement.title = SDK.cssMetadata().isCSSPropertyName(property.name
) ? |
| 66 WebInspector.UIString('Invalid property value') : | 66 Common.UIString('Invalid property value') : |
| 67 WebInspector.UIString('Unknown property name'); | 67 Common.UIString('Unknown property name'); |
| 68 return exclamationElement; | 68 return exclamationElement; |
| 69 } | 69 } |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * @param {!WebInspector.CSSProperty} property | 72 * @param {!SDK.CSSProperty} property |
| 73 * @return {boolean} | 73 * @return {boolean} |
| 74 */ | 74 */ |
| 75 static ignoreErrorsForProperty(property) { | 75 static ignoreErrorsForProperty(property) { |
| 76 /** | 76 /** |
| 77 * @param {string} string | 77 * @param {string} string |
| 78 */ | 78 */ |
| 79 function hasUnknownVendorPrefix(string) { | 79 function hasUnknownVendorPrefix(string) { |
| 80 return !string.startsWith('-webkit-') && /^[-_][\w\d]+-\w/.test(string); | 80 return !string.startsWith('-webkit-') && /^[-_][\w\d]+-\w/.test(string); |
| 81 } | 81 } |
| 82 | 82 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 function setFilterValue(value) { | 144 function setFilterValue(value) { |
| 145 input.value = value; | 145 input.value = value; |
| 146 input.focus(); | 146 input.focus(); |
| 147 searchHandler(); | 147 searchHandler(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 return input; | 150 return input; |
| 151 } | 151 } |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @param {!WebInspector.Event} event | 154 * @param {!Common.Event} event |
| 155 */ | 155 */ |
| 156 _onLayoutEditorChange(event) { | 156 _onLayoutEditorChange(event) { |
| 157 var cssModel = /** @type {!WebInspector.CSSModel} */ (event.target); | 157 var cssModel = /** @type {!SDK.CSSModel} */ (event.target); |
| 158 var styleSheetId = event.data['id']; | 158 var styleSheetId = event.data['id']; |
| 159 var sourceRange = /** @type {!Protocol.CSS.SourceRange} */ (event.data['rang
e']); | 159 var sourceRange = /** @type {!Protocol.CSS.SourceRange} */ (event.data['rang
e']); |
| 160 var range = WebInspector.TextRange.fromObject(sourceRange); | 160 var range = Common.TextRange.fromObject(sourceRange); |
| 161 this._decorator = new WebInspector.PropertyChangeHighlighter(this, cssModel,
styleSheetId, range); | 161 this._decorator = new Elements.PropertyChangeHighlighter(this, cssModel, sty
leSheetId, range); |
| 162 this.update(); | 162 this.update(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 /** | 165 /** |
| 166 * @param {!WebInspector.CSSProperty} cssProperty | 166 * @param {!SDK.CSSProperty} cssProperty |
| 167 */ | 167 */ |
| 168 revealProperty(cssProperty) { | 168 revealProperty(cssProperty) { |
| 169 this._decorator = new WebInspector.PropertyRevealHighlighter(this, cssProper
ty); | 169 this._decorator = new Elements.PropertyRevealHighlighter(this, cssProperty); |
| 170 this._decorator.perform(); | 170 this._decorator.perform(); |
| 171 this.update(); | 171 this.update(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 forceUpdate() { | 174 forceUpdate() { |
| 175 this._swatchPopoverHelper.hide(); | 175 this._swatchPopoverHelper.hide(); |
| 176 this._resetCache(); | 176 this._resetCache(); |
| 177 this.update(); | 177 this.update(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 /** | 180 /** |
| 181 * @param {!Event} event | 181 * @param {!Event} event |
| 182 */ | 182 */ |
| 183 _onAddButtonLongClick(event) { | 183 _onAddButtonLongClick(event) { |
| 184 var cssModel = this.cssModel(); | 184 var cssModel = this.cssModel(); |
| 185 if (!cssModel) | 185 if (!cssModel) |
| 186 return; | 186 return; |
| 187 var headers = cssModel.styleSheetHeaders().filter(styleSheetResourceHeader); | 187 var headers = cssModel.styleSheetHeaders().filter(styleSheetResourceHeader); |
| 188 | 188 |
| 189 /** @type {!Array.<{text: string, handler: function()}>} */ | 189 /** @type {!Array.<{text: string, handler: function()}>} */ |
| 190 var contextMenuDescriptors = []; | 190 var contextMenuDescriptors = []; |
| 191 for (var i = 0; i < headers.length; ++i) { | 191 for (var i = 0; i < headers.length; ++i) { |
| 192 var header = headers[i]; | 192 var header = headers[i]; |
| 193 var handler = this._createNewRuleInStyleSheet.bind(this, header); | 193 var handler = this._createNewRuleInStyleSheet.bind(this, header); |
| 194 contextMenuDescriptors.push({text: WebInspector.displayNameForURL(header.r
esourceURL()), handler: handler}); | 194 contextMenuDescriptors.push({text: Bindings.displayNameForURL(header.resou
rceURL()), handler: handler}); |
| 195 } | 195 } |
| 196 | 196 |
| 197 contextMenuDescriptors.sort(compareDescriptors); | 197 contextMenuDescriptors.sort(compareDescriptors); |
| 198 | 198 |
| 199 var contextMenu = new WebInspector.ContextMenu(event); | 199 var contextMenu = new UI.ContextMenu(event); |
| 200 for (var i = 0; i < contextMenuDescriptors.length; ++i) { | 200 for (var i = 0; i < contextMenuDescriptors.length; ++i) { |
| 201 var descriptor = contextMenuDescriptors[i]; | 201 var descriptor = contextMenuDescriptors[i]; |
| 202 contextMenu.appendItem(descriptor.text, descriptor.handler); | 202 contextMenu.appendItem(descriptor.text, descriptor.handler); |
| 203 } | 203 } |
| 204 if (!contextMenu.isEmpty()) | 204 if (!contextMenu.isEmpty()) |
| 205 contextMenu.appendSeparator(); | 205 contextMenu.appendSeparator(); |
| 206 contextMenu.appendItem('inspector-stylesheet', this._createNewRuleInViaInspe
ctorStyleSheet.bind(this)); | 206 contextMenu.appendItem('inspector-stylesheet', this._createNewRuleInViaInspe
ctorStyleSheet.bind(this)); |
| 207 contextMenu.show(); | 207 contextMenu.show(); |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * @param {!{text: string, handler: function()}} descriptor1 | 210 * @param {!{text: string, handler: function()}} descriptor1 |
| 211 * @param {!{text: string, handler: function()}} descriptor2 | 211 * @param {!{text: string, handler: function()}} descriptor2 |
| 212 * @return {number} | 212 * @return {number} |
| 213 */ | 213 */ |
| 214 function compareDescriptors(descriptor1, descriptor2) { | 214 function compareDescriptors(descriptor1, descriptor2) { |
| 215 return String.naturalOrderComparator(descriptor1.text, descriptor2.text); | 215 return String.naturalOrderComparator(descriptor1.text, descriptor2.text); |
| 216 } | 216 } |
| 217 | 217 |
| 218 /** | 218 /** |
| 219 * @param {!WebInspector.CSSStyleSheetHeader} header | 219 * @param {!SDK.CSSStyleSheetHeader} header |
| 220 * @return {boolean} | 220 * @return {boolean} |
| 221 */ | 221 */ |
| 222 function styleSheetResourceHeader(header) { | 222 function styleSheetResourceHeader(header) { |
| 223 return !header.isViaInspector() && !header.isInline && !!header.resourceUR
L(); | 223 return !header.isViaInspector() && !header.isInline && !!header.resourceUR
L(); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 /** | 227 /** |
| 228 * @param {?RegExp} regex | 228 * @param {?RegExp} regex |
| 229 */ | 229 */ |
| 230 onFilterChanged(regex) { | 230 onFilterChanged(regex) { |
| 231 this._filterRegex = regex; | 231 this._filterRegex = regex; |
| 232 this._updateFilter(); | 232 this._updateFilter(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * @param {!WebInspector.StylePropertiesSection=} editedSection | 236 * @param {!Elements.StylePropertiesSection=} editedSection |
| 237 */ | 237 */ |
| 238 _refreshUpdate(editedSection) { | 238 _refreshUpdate(editedSection) { |
| 239 var node = this.node(); | 239 var node = this.node(); |
| 240 if (!node) | 240 if (!node) |
| 241 return; | 241 return; |
| 242 | 242 |
| 243 var fullRefresh = Runtime.experiments.isEnabled('liveSASS'); | 243 var fullRefresh = Runtime.experiments.isEnabled('liveSASS'); |
| 244 for (var section of this.allSections()) { | 244 for (var section of this.allSections()) { |
| 245 if (section.isBlank) | 245 if (section.isBlank) |
| 246 continue; | 246 continue; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 259 doUpdate() { | 259 doUpdate() { |
| 260 return this._fetchMatchedCascade().then(this._innerRebuildUpdate.bind(this))
; | 260 return this._fetchMatchedCascade().then(this._innerRebuildUpdate.bind(this))
; |
| 261 } | 261 } |
| 262 | 262 |
| 263 _resetCache() { | 263 _resetCache() { |
| 264 if (this.cssModel()) | 264 if (this.cssModel()) |
| 265 this.cssModel().discardCachedMatchedCascade(); | 265 this.cssModel().discardCachedMatchedCascade(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 /** | 268 /** |
| 269 * @return {!Promise.<?WebInspector.CSSMatchedStyles>} | 269 * @return {!Promise.<?SDK.CSSMatchedStyles>} |
| 270 */ | 270 */ |
| 271 _fetchMatchedCascade() { | 271 _fetchMatchedCascade() { |
| 272 var node = this.node(); | 272 var node = this.node(); |
| 273 if (!node || !this.cssModel()) | 273 if (!node || !this.cssModel()) |
| 274 return Promise.resolve(/** @type {?WebInspector.CSSMatchedStyles} */ (null
)); | 274 return Promise.resolve(/** @type {?SDK.CSSMatchedStyles} */ (null)); |
| 275 | 275 |
| 276 return this.cssModel().cachedMatchedCascadeForNode(node).then(validateStyles
.bind(this)); | 276 return this.cssModel().cachedMatchedCascadeForNode(node).then(validateStyles
.bind(this)); |
| 277 | 277 |
| 278 /** | 278 /** |
| 279 * @param {?WebInspector.CSSMatchedStyles} matchedStyles | 279 * @param {?SDK.CSSMatchedStyles} matchedStyles |
| 280 * @return {?WebInspector.CSSMatchedStyles} | 280 * @return {?SDK.CSSMatchedStyles} |
| 281 * @this {WebInspector.StylesSidebarPane} | 281 * @this {Elements.StylesSidebarPane} |
| 282 */ | 282 */ |
| 283 function validateStyles(matchedStyles) { | 283 function validateStyles(matchedStyles) { |
| 284 return matchedStyles && matchedStyles.node() === this.node() ? matchedStyl
es : null; | 284 return matchedStyles && matchedStyles.node() === this.node() ? matchedStyl
es : null; |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * @param {boolean} editing | 289 * @param {boolean} editing |
| 290 */ | 290 */ |
| 291 setEditingStyle(editing) { | 291 setEditingStyle(editing) { |
| 292 if (this._isEditingStyle === editing) | 292 if (this._isEditingStyle === editing) |
| 293 return; | 293 return; |
| 294 this.element.classList.toggle('is-editing-style', editing); | 294 this.element.classList.toggle('is-editing-style', editing); |
| 295 this._isEditingStyle = editing; | 295 this._isEditingStyle = editing; |
| 296 } | 296 } |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * @override | 299 * @override |
| 300 * @param {!WebInspector.Event=} event | 300 * @param {!Common.Event=} event |
| 301 */ | 301 */ |
| 302 onCSSModelChanged(event) { | 302 onCSSModelChanged(event) { |
| 303 var edit = event && event.data ? /** @type {?WebInspector.CSSModel.Edit} */
(event.data.edit) : null; | 303 var edit = event && event.data ? /** @type {?SDK.CSSModel.Edit} */ (event.da
ta.edit) : null; |
| 304 if (edit) { | 304 if (edit) { |
| 305 for (var section of this.allSections()) | 305 for (var section of this.allSections()) |
| 306 section._styleSheetEdited(edit); | 306 section._styleSheetEdited(edit); |
| 307 return; | 307 return; |
| 308 } | 308 } |
| 309 | 309 |
| 310 if (this._userOperation || this._isEditingStyle) | 310 if (this._userOperation || this._isEditingStyle) |
| 311 return; | 311 return; |
| 312 | 312 |
| 313 this._resetCache(); | 313 this._resetCache(); |
| 314 this.update(); | 314 this.update(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 /** | 317 /** |
| 318 * @param {?WebInspector.CSSMatchedStyles} matchedStyles | 318 * @param {?SDK.CSSMatchedStyles} matchedStyles |
| 319 */ | 319 */ |
| 320 _innerRebuildUpdate(matchedStyles) { | 320 _innerRebuildUpdate(matchedStyles) { |
| 321 this._linkifier.reset(); | 321 this._linkifier.reset(); |
| 322 this._sectionsContainer.removeChildren(); | 322 this._sectionsContainer.removeChildren(); |
| 323 this._sectionBlocks = []; | 323 this._sectionBlocks = []; |
| 324 | 324 |
| 325 var node = this.node(); | 325 var node = this.node(); |
| 326 if (!matchedStyles || !node) | 326 if (!matchedStyles || !node) |
| 327 return; | 327 return; |
| 328 | 328 |
| 329 this._sectionBlocks = this._rebuildSectionsForMatchedStyleRules(matchedStyle
s); | 329 this._sectionBlocks = this._rebuildSectionsForMatchedStyleRules(matchedStyle
s); |
| 330 var pseudoTypes = []; | 330 var pseudoTypes = []; |
| 331 var keys = new Set(matchedStyles.pseudoStyles().keys()); | 331 var keys = new Set(matchedStyles.pseudoStyles().keys()); |
| 332 if (keys.delete(Protocol.DOM.PseudoType.Before)) | 332 if (keys.delete(Protocol.DOM.PseudoType.Before)) |
| 333 pseudoTypes.push(Protocol.DOM.PseudoType.Before); | 333 pseudoTypes.push(Protocol.DOM.PseudoType.Before); |
| 334 pseudoTypes = pseudoTypes.concat(keys.valuesArray().sort()); | 334 pseudoTypes = pseudoTypes.concat(keys.valuesArray().sort()); |
| 335 for (var pseudoType of pseudoTypes) { | 335 for (var pseudoType of pseudoTypes) { |
| 336 var block = WebInspector.SectionBlock.createPseudoTypeBlock(pseudoType); | 336 var block = Elements.SectionBlock.createPseudoTypeBlock(pseudoType); |
| 337 var styles = | 337 var styles = |
| 338 /** @type {!Array<!WebInspector.CSSStyleDeclaration>} */ (matchedStyle
s.pseudoStyles().get(pseudoType)); | 338 /** @type {!Array<!SDK.CSSStyleDeclaration>} */ (matchedStyles.pseudoS
tyles().get(pseudoType)); |
| 339 for (var style of styles) { | 339 for (var style of styles) { |
| 340 var section = new WebInspector.StylePropertiesSection(this, matchedStyle
s, style); | 340 var section = new Elements.StylePropertiesSection(this, matchedStyles, s
tyle); |
| 341 block.sections.push(section); | 341 block.sections.push(section); |
| 342 } | 342 } |
| 343 this._sectionBlocks.push(block); | 343 this._sectionBlocks.push(block); |
| 344 } | 344 } |
| 345 | 345 |
| 346 for (var keyframesRule of matchedStyles.keyframes()) { | 346 for (var keyframesRule of matchedStyles.keyframes()) { |
| 347 var block = WebInspector.SectionBlock.createKeyframesBlock(keyframesRule.n
ame().text); | 347 var block = Elements.SectionBlock.createKeyframesBlock(keyframesRule.name(
).text); |
| 348 for (var keyframe of keyframesRule.keyframes()) | 348 for (var keyframe of keyframesRule.keyframes()) |
| 349 block.sections.push(new WebInspector.KeyframePropertiesSection(this, mat
chedStyles, keyframe.style)); | 349 block.sections.push(new Elements.KeyframePropertiesSection(this, matched
Styles, keyframe.style)); |
| 350 this._sectionBlocks.push(block); | 350 this._sectionBlocks.push(block); |
| 351 } | 351 } |
| 352 | 352 |
| 353 for (var block of this._sectionBlocks) { | 353 for (var block of this._sectionBlocks) { |
| 354 var titleElement = block.titleElement(); | 354 var titleElement = block.titleElement(); |
| 355 if (titleElement) | 355 if (titleElement) |
| 356 this._sectionsContainer.appendChild(titleElement); | 356 this._sectionsContainer.appendChild(titleElement); |
| 357 for (var section of block.sections) | 357 for (var section of block.sections) |
| 358 this._sectionsContainer.appendChild(section.element); | 358 this._sectionsContainer.appendChild(section.element); |
| 359 } | 359 } |
| 360 | 360 |
| 361 if (this._filterRegex) | 361 if (this._filterRegex) |
| 362 this._updateFilter(); | 362 this._updateFilter(); |
| 363 | 363 |
| 364 this._nodeStylesUpdatedForTest(node, true); | 364 this._nodeStylesUpdatedForTest(node, true); |
| 365 if (this._decorator) { | 365 if (this._decorator) { |
| 366 this._decorator.perform(); | 366 this._decorator.perform(); |
| 367 delete this._decorator; | 367 delete this._decorator; |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 | 370 |
| 371 /** | 371 /** |
| 372 * @param {!WebInspector.DOMNode} node | 372 * @param {!SDK.DOMNode} node |
| 373 * @param {boolean} rebuild | 373 * @param {boolean} rebuild |
| 374 */ | 374 */ |
| 375 _nodeStylesUpdatedForTest(node, rebuild) { | 375 _nodeStylesUpdatedForTest(node, rebuild) { |
| 376 // For sniffing in tests. | 376 // For sniffing in tests. |
| 377 } | 377 } |
| 378 | 378 |
| 379 /** | 379 /** |
| 380 * @param {!WebInspector.CSSMatchedStyles} matchedStyles | 380 * @param {!SDK.CSSMatchedStyles} matchedStyles |
| 381 * @return {!Array.<!WebInspector.SectionBlock>} | 381 * @return {!Array.<!Elements.SectionBlock>} |
| 382 */ | 382 */ |
| 383 _rebuildSectionsForMatchedStyleRules(matchedStyles) { | 383 _rebuildSectionsForMatchedStyleRules(matchedStyles) { |
| 384 var blocks = [new WebInspector.SectionBlock(null)]; | 384 var blocks = [new Elements.SectionBlock(null)]; |
| 385 var lastParentNode = null; | 385 var lastParentNode = null; |
| 386 for (var style of matchedStyles.nodeStyles()) { | 386 for (var style of matchedStyles.nodeStyles()) { |
| 387 var parentNode = matchedStyles.isInherited(style) ? matchedStyles.nodeForS
tyle(style) : null; | 387 var parentNode = matchedStyles.isInherited(style) ? matchedStyles.nodeForS
tyle(style) : null; |
| 388 if (parentNode && parentNode !== lastParentNode) { | 388 if (parentNode && parentNode !== lastParentNode) { |
| 389 lastParentNode = parentNode; | 389 lastParentNode = parentNode; |
| 390 var block = WebInspector.SectionBlock.createInheritedNodeBlock(lastParen
tNode); | 390 var block = Elements.SectionBlock.createInheritedNodeBlock(lastParentNod
e); |
| 391 blocks.push(block); | 391 blocks.push(block); |
| 392 } | 392 } |
| 393 | 393 |
| 394 var section = new WebInspector.StylePropertiesSection(this, matchedStyles,
style); | 394 var section = new Elements.StylePropertiesSection(this, matchedStyles, sty
le); |
| 395 blocks.peekLast().sections.push(section); | 395 blocks.peekLast().sections.push(section); |
| 396 } | 396 } |
| 397 return blocks; | 397 return blocks; |
| 398 } | 398 } |
| 399 | 399 |
| 400 _createNewRuleInViaInspectorStyleSheet() { | 400 _createNewRuleInViaInspectorStyleSheet() { |
| 401 var cssModel = this.cssModel(); | 401 var cssModel = this.cssModel(); |
| 402 var node = this.node(); | 402 var node = this.node(); |
| 403 if (!cssModel || !node) | 403 if (!cssModel || !node) |
| 404 return; | 404 return; |
| 405 this._userOperation = true; | 405 this._userOperation = true; |
| 406 cssModel.requestViaInspectorStylesheet(node, onViaInspectorStyleSheet.bind(t
his)); | 406 cssModel.requestViaInspectorStylesheet(node, onViaInspectorStyleSheet.bind(t
his)); |
| 407 | 407 |
| 408 /** | 408 /** |
| 409 * @param {?WebInspector.CSSStyleSheetHeader} styleSheetHeader | 409 * @param {?SDK.CSSStyleSheetHeader} styleSheetHeader |
| 410 * @this {WebInspector.StylesSidebarPane} | 410 * @this {Elements.StylesSidebarPane} |
| 411 */ | 411 */ |
| 412 function onViaInspectorStyleSheet(styleSheetHeader) { | 412 function onViaInspectorStyleSheet(styleSheetHeader) { |
| 413 delete this._userOperation; | 413 delete this._userOperation; |
| 414 this._createNewRuleInStyleSheet(styleSheetHeader); | 414 this._createNewRuleInStyleSheet(styleSheetHeader); |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 | 417 |
| 418 /** | 418 /** |
| 419 * @param {?WebInspector.CSSStyleSheetHeader} styleSheetHeader | 419 * @param {?SDK.CSSStyleSheetHeader} styleSheetHeader |
| 420 */ | 420 */ |
| 421 _createNewRuleInStyleSheet(styleSheetHeader) { | 421 _createNewRuleInStyleSheet(styleSheetHeader) { |
| 422 if (!styleSheetHeader) | 422 if (!styleSheetHeader) |
| 423 return; | 423 return; |
| 424 styleSheetHeader.requestContent().then(onStyleSheetContent.bind(this, styleS
heetHeader.id)); | 424 styleSheetHeader.requestContent().then(onStyleSheetContent.bind(this, styleS
heetHeader.id)); |
| 425 | 425 |
| 426 /** | 426 /** |
| 427 * @param {string} styleSheetId | 427 * @param {string} styleSheetId |
| 428 * @param {?string} text | 428 * @param {?string} text |
| 429 * @this {WebInspector.StylesSidebarPane} | 429 * @this {Elements.StylesSidebarPane} |
| 430 */ | 430 */ |
| 431 function onStyleSheetContent(styleSheetId, text) { | 431 function onStyleSheetContent(styleSheetId, text) { |
| 432 text = text || ''; | 432 text = text || ''; |
| 433 var lines = text.split('\n'); | 433 var lines = text.split('\n'); |
| 434 var range = WebInspector.TextRange.createFromLocation(lines.length - 1, li
nes[lines.length - 1].length); | 434 var range = Common.TextRange.createFromLocation(lines.length - 1, lines[li
nes.length - 1].length); |
| 435 this._addBlankSection(this._sectionBlocks[0].sections[0], styleSheetId, ra
nge); | 435 this._addBlankSection(this._sectionBlocks[0].sections[0], styleSheetId, ra
nge); |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 | 438 |
| 439 /** | 439 /** |
| 440 * @param {!WebInspector.StylePropertiesSection} insertAfterSection | 440 * @param {!Elements.StylePropertiesSection} insertAfterSection |
| 441 * @param {string} styleSheetId | 441 * @param {string} styleSheetId |
| 442 * @param {!WebInspector.TextRange} ruleLocation | 442 * @param {!Common.TextRange} ruleLocation |
| 443 */ | 443 */ |
| 444 _addBlankSection(insertAfterSection, styleSheetId, ruleLocation) { | 444 _addBlankSection(insertAfterSection, styleSheetId, ruleLocation) { |
| 445 var node = this.node(); | 445 var node = this.node(); |
| 446 var blankSection = new WebInspector.BlankStylePropertiesSection( | 446 var blankSection = new Elements.BlankStylePropertiesSection( |
| 447 this, insertAfterSection._matchedStyles, node ? WebInspector.DOMPresenta
tionUtils.simpleSelector(node) : '', | 447 this, insertAfterSection._matchedStyles, node ? Components.DOMPresentati
onUtils.simpleSelector(node) : '', |
| 448 styleSheetId, ruleLocation, insertAfterSection._style); | 448 styleSheetId, ruleLocation, insertAfterSection._style); |
| 449 | 449 |
| 450 this._sectionsContainer.insertBefore(blankSection.element, insertAfterSectio
n.element.nextSibling); | 450 this._sectionsContainer.insertBefore(blankSection.element, insertAfterSectio
n.element.nextSibling); |
| 451 | 451 |
| 452 for (var block of this._sectionBlocks) { | 452 for (var block of this._sectionBlocks) { |
| 453 var index = block.sections.indexOf(insertAfterSection); | 453 var index = block.sections.indexOf(insertAfterSection); |
| 454 if (index === -1) | 454 if (index === -1) |
| 455 continue; | 455 continue; |
| 456 block.sections.splice(index + 1, 0, blankSection); | 456 block.sections.splice(index + 1, 0, blankSection); |
| 457 blankSection.startEditingSelector(); | 457 blankSection.startEditingSelector(); |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 | 460 |
| 461 /** | 461 /** |
| 462 * @param {!WebInspector.StylePropertiesSection} section | 462 * @param {!Elements.StylePropertiesSection} section |
| 463 */ | 463 */ |
| 464 removeSection(section) { | 464 removeSection(section) { |
| 465 for (var block of this._sectionBlocks) { | 465 for (var block of this._sectionBlocks) { |
| 466 var index = block.sections.indexOf(section); | 466 var index = block.sections.indexOf(section); |
| 467 if (index === -1) | 467 if (index === -1) |
| 468 continue; | 468 continue; |
| 469 block.sections.splice(index, 1); | 469 block.sections.splice(index, 1); |
| 470 section.element.remove(); | 470 section.element.remove(); |
| 471 } | 471 } |
| 472 } | 472 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 485 | 485 |
| 486 /** | 486 /** |
| 487 * @override | 487 * @override |
| 488 */ | 488 */ |
| 489 willHide() { | 489 willHide() { |
| 490 this._swatchPopoverHelper.hide(); | 490 this._swatchPopoverHelper.hide(); |
| 491 super.willHide(); | 491 super.willHide(); |
| 492 } | 492 } |
| 493 | 493 |
| 494 /** | 494 /** |
| 495 * @return {!Array<!WebInspector.StylePropertiesSection>} | 495 * @return {!Array<!Elements.StylePropertiesSection>} |
| 496 */ | 496 */ |
| 497 allSections() { | 497 allSections() { |
| 498 var sections = []; | 498 var sections = []; |
| 499 for (var block of this._sectionBlocks) | 499 for (var block of this._sectionBlocks) |
| 500 sections = sections.concat(block.sections); | 500 sections = sections.concat(block.sections); |
| 501 return sections; | 501 return sections; |
| 502 } | 502 } |
| 503 }; | 503 }; |
| 504 | 504 |
| 505 WebInspector.StylesSidebarPane._maxLinkLength = 30; | 505 Elements.StylesSidebarPane._maxLinkLength = 30; |
| 506 | 506 |
| 507 /** | 507 /** |
| 508 * @unrestricted | 508 * @unrestricted |
| 509 */ | 509 */ |
| 510 WebInspector.SectionBlock = class { | 510 Elements.SectionBlock = class { |
| 511 /** | 511 /** |
| 512 * @param {?Element} titleElement | 512 * @param {?Element} titleElement |
| 513 */ | 513 */ |
| 514 constructor(titleElement) { | 514 constructor(titleElement) { |
| 515 this._titleElement = titleElement; | 515 this._titleElement = titleElement; |
| 516 this.sections = []; | 516 this.sections = []; |
| 517 } | 517 } |
| 518 | 518 |
| 519 /** | 519 /** |
| 520 * @param {!Protocol.DOM.PseudoType} pseudoType | 520 * @param {!Protocol.DOM.PseudoType} pseudoType |
| 521 * @return {!WebInspector.SectionBlock} | 521 * @return {!Elements.SectionBlock} |
| 522 */ | 522 */ |
| 523 static createPseudoTypeBlock(pseudoType) { | 523 static createPseudoTypeBlock(pseudoType) { |
| 524 var separatorElement = createElement('div'); | 524 var separatorElement = createElement('div'); |
| 525 separatorElement.className = 'sidebar-separator'; | 525 separatorElement.className = 'sidebar-separator'; |
| 526 separatorElement.textContent = WebInspector.UIString('Pseudo ::%s element',
pseudoType); | 526 separatorElement.textContent = Common.UIString('Pseudo ::%s element', pseudo
Type); |
| 527 return new WebInspector.SectionBlock(separatorElement); | 527 return new Elements.SectionBlock(separatorElement); |
| 528 } | 528 } |
| 529 | 529 |
| 530 /** | 530 /** |
| 531 * @param {string} keyframesName | 531 * @param {string} keyframesName |
| 532 * @return {!WebInspector.SectionBlock} | 532 * @return {!Elements.SectionBlock} |
| 533 */ | 533 */ |
| 534 static createKeyframesBlock(keyframesName) { | 534 static createKeyframesBlock(keyframesName) { |
| 535 var separatorElement = createElement('div'); | 535 var separatorElement = createElement('div'); |
| 536 separatorElement.className = 'sidebar-separator'; | 536 separatorElement.className = 'sidebar-separator'; |
| 537 separatorElement.textContent = WebInspector.UIString('@keyframes ' + keyfram
esName); | 537 separatorElement.textContent = Common.UIString('@keyframes ' + keyframesName
); |
| 538 return new WebInspector.SectionBlock(separatorElement); | 538 return new Elements.SectionBlock(separatorElement); |
| 539 } | 539 } |
| 540 | 540 |
| 541 /** | 541 /** |
| 542 * @param {!WebInspector.DOMNode} node | 542 * @param {!SDK.DOMNode} node |
| 543 * @return {!WebInspector.SectionBlock} | 543 * @return {!Elements.SectionBlock} |
| 544 */ | 544 */ |
| 545 static createInheritedNodeBlock(node) { | 545 static createInheritedNodeBlock(node) { |
| 546 var separatorElement = createElement('div'); | 546 var separatorElement = createElement('div'); |
| 547 separatorElement.className = 'sidebar-separator'; | 547 separatorElement.className = 'sidebar-separator'; |
| 548 var link = WebInspector.DOMPresentationUtils.linkifyNodeReference(node); | 548 var link = Components.DOMPresentationUtils.linkifyNodeReference(node); |
| 549 separatorElement.createTextChild(WebInspector.UIString('Inherited from') + '
'); | 549 separatorElement.createTextChild(Common.UIString('Inherited from') + ' '); |
| 550 separatorElement.appendChild(link); | 550 separatorElement.appendChild(link); |
| 551 return new WebInspector.SectionBlock(separatorElement); | 551 return new Elements.SectionBlock(separatorElement); |
| 552 } | 552 } |
| 553 | 553 |
| 554 updateFilter() { | 554 updateFilter() { |
| 555 var hasAnyVisibleSection = false; | 555 var hasAnyVisibleSection = false; |
| 556 for (var section of this.sections) | 556 for (var section of this.sections) |
| 557 hasAnyVisibleSection |= section._updateFilter(); | 557 hasAnyVisibleSection |= section._updateFilter(); |
| 558 if (this._titleElement) | 558 if (this._titleElement) |
| 559 this._titleElement.classList.toggle('hidden', !hasAnyVisibleSection); | 559 this._titleElement.classList.toggle('hidden', !hasAnyVisibleSection); |
| 560 } | 560 } |
| 561 | 561 |
| 562 /** | 562 /** |
| 563 * @return {?Element} | 563 * @return {?Element} |
| 564 */ | 564 */ |
| 565 titleElement() { | 565 titleElement() { |
| 566 return this._titleElement; | 566 return this._titleElement; |
| 567 } | 567 } |
| 568 }; | 568 }; |
| 569 | 569 |
| 570 | 570 |
| 571 /** | 571 /** |
| 572 * @unrestricted | 572 * @unrestricted |
| 573 */ | 573 */ |
| 574 WebInspector.StylePropertiesSection = class { | 574 Elements.StylePropertiesSection = class { |
| 575 /** | 575 /** |
| 576 * @param {!WebInspector.StylesSidebarPane} parentPane | 576 * @param {!Elements.StylesSidebarPane} parentPane |
| 577 * @param {!WebInspector.CSSMatchedStyles} matchedStyles | 577 * @param {!SDK.CSSMatchedStyles} matchedStyles |
| 578 * @param {!WebInspector.CSSStyleDeclaration} style | 578 * @param {!SDK.CSSStyleDeclaration} style |
| 579 */ | 579 */ |
| 580 constructor(parentPane, matchedStyles, style) { | 580 constructor(parentPane, matchedStyles, style) { |
| 581 this._parentPane = parentPane; | 581 this._parentPane = parentPane; |
| 582 this._style = style; | 582 this._style = style; |
| 583 this._matchedStyles = matchedStyles; | 583 this._matchedStyles = matchedStyles; |
| 584 this.editable = !!(style.styleSheetId && style.range); | 584 this.editable = !!(style.styleSheetId && style.range); |
| 585 | 585 |
| 586 var rule = style.parentRule; | 586 var rule = style.parentRule; |
| 587 this.element = createElementWithClass('div', 'styles-section matched-styles
monospace'); | 587 this.element = createElementWithClass('div', 'styles-section matched-styles
monospace'); |
| 588 this.element._section = this; | 588 this.element._section = this; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 617 this.element.addEventListener('mousedown', this._handleEmptySpaceMouseDown.b
ind(this), false); | 617 this.element.addEventListener('mousedown', this._handleEmptySpaceMouseDown.b
ind(this), false); |
| 618 this.element.addEventListener('click', this._handleEmptySpaceClick.bind(this
), false); | 618 this.element.addEventListener('click', this._handleEmptySpaceClick.bind(this
), false); |
| 619 this.element.addEventListener('mousemove', this._onMouseMove.bind(this), fal
se); | 619 this.element.addEventListener('mousemove', this._onMouseMove.bind(this), fal
se); |
| 620 this.element.addEventListener('mouseleave', this._setSectionHovered.bind(thi
s, false), false); | 620 this.element.addEventListener('mouseleave', this._setSectionHovered.bind(thi
s, false), false); |
| 621 | 621 |
| 622 if (rule) { | 622 if (rule) { |
| 623 // Prevent editing the user agent and user rules. | 623 // Prevent editing the user agent and user rules. |
| 624 if (rule.isUserAgent() || rule.isInjected()) { | 624 if (rule.isUserAgent() || rule.isInjected()) { |
| 625 this.editable = false; | 625 this.editable = false; |
| 626 } else { | 626 } else { |
| 627 // Check this is a real CSSRule, not a bogus object coming from WebInspe
ctor.BlankStylePropertiesSection. | 627 // Check this is a real CSSRule, not a bogus object coming from Elements
.BlankStylePropertiesSection. |
| 628 if (rule.styleSheetId) | 628 if (rule.styleSheetId) |
| 629 this.navigable = !!rule.resourceURL(); | 629 this.navigable = !!rule.resourceURL(); |
| 630 } | 630 } |
| 631 } | 631 } |
| 632 | 632 |
| 633 this._mediaListElement = this._titleElement.createChild('div', 'media-list m
edia-matches'); | 633 this._mediaListElement = this._titleElement.createChild('div', 'media-list m
edia-matches'); |
| 634 this._selectorRefElement = this._titleElement.createChild('div', 'styles-sec
tion-subtitle'); | 634 this._selectorRefElement = this._titleElement.createChild('div', 'styles-sec
tion-subtitle'); |
| 635 this._updateMediaList(); | 635 this._updateMediaList(); |
| 636 this._updateRuleOrigin(); | 636 this._updateRuleOrigin(); |
| 637 this._titleElement.appendChild(selectorContainer); | 637 this._titleElement.appendChild(selectorContainer); |
| 638 this._selectorContainer = selectorContainer; | 638 this._selectorContainer = selectorContainer; |
| 639 | 639 |
| 640 if (this.navigable) | 640 if (this.navigable) |
| 641 this.element.classList.add('navigable'); | 641 this.element.classList.add('navigable'); |
| 642 | 642 |
| 643 if (!this.editable) { | 643 if (!this.editable) { |
| 644 this.element.classList.add('read-only'); | 644 this.element.classList.add('read-only'); |
| 645 this.propertiesTreeOutline.element.classList.add('read-only'); | 645 this.propertiesTreeOutline.element.classList.add('read-only'); |
| 646 } | 646 } |
| 647 | 647 |
| 648 this._hoverableSelectorsMode = false; | 648 this._hoverableSelectorsMode = false; |
| 649 this._markSelectorMatches(); | 649 this._markSelectorMatches(); |
| 650 this.onpopulate(); | 650 this.onpopulate(); |
| 651 } | 651 } |
| 652 | 652 |
| 653 /** | 653 /** |
| 654 * @param {!WebInspector.CSSMatchedStyles} matchedStyles | 654 * @param {!SDK.CSSMatchedStyles} matchedStyles |
| 655 * @param {!WebInspector.Linkifier} linkifier | 655 * @param {!Components.Linkifier} linkifier |
| 656 * @param {?WebInspector.CSSRule} rule | 656 * @param {?SDK.CSSRule} rule |
| 657 * @return {!Node} | 657 * @return {!Node} |
| 658 */ | 658 */ |
| 659 static createRuleOriginNode(matchedStyles, linkifier, rule) { | 659 static createRuleOriginNode(matchedStyles, linkifier, rule) { |
| 660 if (!rule) | 660 if (!rule) |
| 661 return createTextNode(''); | 661 return createTextNode(''); |
| 662 | 662 |
| 663 var ruleLocation; | 663 var ruleLocation; |
| 664 if (rule instanceof WebInspector.CSSStyleRule) { | 664 if (rule instanceof SDK.CSSStyleRule) { |
| 665 var matchingSelectors = matchedStyles.matchingSelectors(rule); | 665 var matchingSelectors = matchedStyles.matchingSelectors(rule); |
| 666 var firstMatchingIndex = matchingSelectors.length ? matchingSelectors[0] :
0; | 666 var firstMatchingIndex = matchingSelectors.length ? matchingSelectors[0] :
0; |
| 667 ruleLocation = rule.selectors[firstMatchingIndex].range; | 667 ruleLocation = rule.selectors[firstMatchingIndex].range; |
| 668 } else if (rule instanceof WebInspector.CSSKeyframeRule) { | 668 } else if (rule instanceof SDK.CSSKeyframeRule) { |
| 669 ruleLocation = rule.key().range; | 669 ruleLocation = rule.key().range; |
| 670 } | 670 } |
| 671 | 671 |
| 672 var header = rule.styleSheetId ? matchedStyles.cssModel().styleSheetHeaderFo
rId(rule.styleSheetId) : null; | 672 var header = rule.styleSheetId ? matchedStyles.cssModel().styleSheetHeaderFo
rId(rule.styleSheetId) : null; |
| 673 if (ruleLocation && rule.styleSheetId && header && header.resourceURL()) | 673 if (ruleLocation && rule.styleSheetId && header && header.resourceURL()) |
| 674 return WebInspector.StylePropertiesSection._linkifyRuleLocation( | 674 return Elements.StylePropertiesSection._linkifyRuleLocation( |
| 675 matchedStyles.cssModel(), linkifier, rule.styleSheetId, ruleLocation); | 675 matchedStyles.cssModel(), linkifier, rule.styleSheetId, ruleLocation); |
| 676 | 676 |
| 677 if (rule.isUserAgent()) | 677 if (rule.isUserAgent()) |
| 678 return createTextNode(WebInspector.UIString('user agent stylesheet')); | 678 return createTextNode(Common.UIString('user agent stylesheet')); |
| 679 if (rule.isInjected()) | 679 if (rule.isInjected()) |
| 680 return createTextNode(WebInspector.UIString('injected stylesheet')); | 680 return createTextNode(Common.UIString('injected stylesheet')); |
| 681 if (rule.isViaInspector()) | 681 if (rule.isViaInspector()) |
| 682 return createTextNode(WebInspector.UIString('via inspector')); | 682 return createTextNode(Common.UIString('via inspector')); |
| 683 | 683 |
| 684 if (header && header.ownerNode) { | 684 if (header && header.ownerNode) { |
| 685 var link = WebInspector.DOMPresentationUtils.linkifyDeferredNodeReference(
header.ownerNode); | 685 var link = Components.DOMPresentationUtils.linkifyDeferredNodeReference(he
ader.ownerNode); |
| 686 link.textContent = '<style>…</style>'; | 686 link.textContent = '<style>…</style>'; |
| 687 return link; | 687 return link; |
| 688 } | 688 } |
| 689 | 689 |
| 690 return createTextNode(''); | 690 return createTextNode(''); |
| 691 } | 691 } |
| 692 | 692 |
| 693 /** | 693 /** |
| 694 * @param {!WebInspector.CSSModel} cssModel | 694 * @param {!SDK.CSSModel} cssModel |
| 695 * @param {!WebInspector.Linkifier} linkifier | 695 * @param {!Components.Linkifier} linkifier |
| 696 * @param {string} styleSheetId | 696 * @param {string} styleSheetId |
| 697 * @param {!WebInspector.TextRange} ruleLocation | 697 * @param {!Common.TextRange} ruleLocation |
| 698 * @return {!Node} | 698 * @return {!Node} |
| 699 */ | 699 */ |
| 700 static _linkifyRuleLocation(cssModel, linkifier, styleSheetId, ruleLocation) { | 700 static _linkifyRuleLocation(cssModel, linkifier, styleSheetId, ruleLocation) { |
| 701 var styleSheetHeader = cssModel.styleSheetHeaderForId(styleSheetId); | 701 var styleSheetHeader = cssModel.styleSheetHeaderForId(styleSheetId); |
| 702 var lineNumber = styleSheetHeader.lineNumberInSource(ruleLocation.startLine)
; | 702 var lineNumber = styleSheetHeader.lineNumberInSource(ruleLocation.startLine)
; |
| 703 var columnNumber = styleSheetHeader.columnNumberInSource(ruleLocation.startL
ine, ruleLocation.startColumn); | 703 var columnNumber = styleSheetHeader.columnNumberInSource(ruleLocation.startL
ine, ruleLocation.startColumn); |
| 704 var matchingSelectorLocation = new WebInspector.CSSLocation(styleSheetHeader
, lineNumber, columnNumber); | 704 var matchingSelectorLocation = new SDK.CSSLocation(styleSheetHeader, lineNum
ber, columnNumber); |
| 705 return linkifier.linkifyCSSLocation(matchingSelectorLocation); | 705 return linkifier.linkifyCSSLocation(matchingSelectorLocation); |
| 706 } | 706 } |
| 707 | 707 |
| 708 /** | 708 /** |
| 709 * @param {boolean} isHovered | 709 * @param {boolean} isHovered |
| 710 */ | 710 */ |
| 711 _setSectionHovered(isHovered) { | 711 _setSectionHovered(isHovered) { |
| 712 this.element.classList.toggle('styles-panel-hovered', isHovered); | 712 this.element.classList.toggle('styles-panel-hovered', isHovered); |
| 713 this.propertiesTreeOutline.element.classList.toggle('styles-panel-hovered',
isHovered); | 713 this.propertiesTreeOutline.element.classList.toggle('styles-panel-hovered',
isHovered); |
| 714 if (this._hoverableSelectorsMode !== isHovered) { | 714 if (this._hoverableSelectorsMode !== isHovered) { |
| 715 this._hoverableSelectorsMode = isHovered; | 715 this._hoverableSelectorsMode = isHovered; |
| 716 this._markSelectorMatches(); | 716 this._markSelectorMatches(); |
| 717 } | 717 } |
| 718 } | 718 } |
| 719 | 719 |
| 720 /** | 720 /** |
| 721 * @param {!Event} event | 721 * @param {!Event} event |
| 722 */ | 722 */ |
| 723 _onMouseMove(event) { | 723 _onMouseMove(event) { |
| 724 var hasCtrlOrMeta = WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @ty
pe {!MouseEvent} */ (event)); | 724 var hasCtrlOrMeta = UI.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!Mouse
Event} */ (event)); |
| 725 this._setSectionHovered(hasCtrlOrMeta); | 725 this._setSectionHovered(hasCtrlOrMeta); |
| 726 } | 726 } |
| 727 | 727 |
| 728 /** | 728 /** |
| 729 * @param {!Element} container | 729 * @param {!Element} container |
| 730 */ | 730 */ |
| 731 _createHoverMenuToolbar(container) { | 731 _createHoverMenuToolbar(container) { |
| 732 if (!this.editable) | 732 if (!this.editable) |
| 733 return; | 733 return; |
| 734 var items = []; | 734 var items = []; |
| 735 | 735 |
| 736 var textShadowButton = | 736 var textShadowButton = |
| 737 new WebInspector.ToolbarButton(WebInspector.UIString('Add text-shadow'),
'largeicon-text-shadow'); | 737 new UI.ToolbarButton(Common.UIString('Add text-shadow'), 'largeicon-text
-shadow'); |
| 738 textShadowButton.addEventListener('click', this._onInsertShadowPropertyClick
.bind(this, 'text-shadow')); | 738 textShadowButton.addEventListener('click', this._onInsertShadowPropertyClick
.bind(this, 'text-shadow')); |
| 739 items.push(textShadowButton); | 739 items.push(textShadowButton); |
| 740 | 740 |
| 741 var boxShadowButton = | 741 var boxShadowButton = |
| 742 new WebInspector.ToolbarButton(WebInspector.UIString('Add box-shadow'),
'largeicon-box-shadow'); | 742 new UI.ToolbarButton(Common.UIString('Add box-shadow'), 'largeicon-box-s
hadow'); |
| 743 boxShadowButton.addEventListener('click', this._onInsertShadowPropertyClick.
bind(this, 'box-shadow')); | 743 boxShadowButton.addEventListener('click', this._onInsertShadowPropertyClick.
bind(this, 'box-shadow')); |
| 744 items.push(boxShadowButton); | 744 items.push(boxShadowButton); |
| 745 | 745 |
| 746 var colorButton = | 746 var colorButton = |
| 747 new WebInspector.ToolbarButton(WebInspector.UIString('Add color'), 'larg
eicon-foreground-color'); | 747 new UI.ToolbarButton(Common.UIString('Add color'), 'largeicon-foreground
-color'); |
| 748 colorButton.addEventListener('click', this._onInsertColorPropertyClick.bind(
this)); | 748 colorButton.addEventListener('click', this._onInsertColorPropertyClick.bind(
this)); |
| 749 items.push(colorButton); | 749 items.push(colorButton); |
| 750 | 750 |
| 751 var backgroundButton = | 751 var backgroundButton = |
| 752 new WebInspector.ToolbarButton(WebInspector.UIString('Add background-col
or'), 'largeicon-background-color'); | 752 new UI.ToolbarButton(Common.UIString('Add background-color'), 'largeicon
-background-color'); |
| 753 backgroundButton.addEventListener('click', this._onInsertBackgroundColorProp
ertyClick.bind(this)); | 753 backgroundButton.addEventListener('click', this._onInsertBackgroundColorProp
ertyClick.bind(this)); |
| 754 items.push(backgroundButton); | 754 items.push(backgroundButton); |
| 755 | 755 |
| 756 var newRuleButton = null; | 756 var newRuleButton = null; |
| 757 if (this._style.parentRule) { | 757 if (this._style.parentRule) { |
| 758 newRuleButton = | 758 newRuleButton = |
| 759 new WebInspector.ToolbarButton(WebInspector.UIString('Insert Style Rul
e Below'), 'largeicon-add'); | 759 new UI.ToolbarButton(Common.UIString('Insert Style Rule Below'), 'larg
eicon-add'); |
| 760 newRuleButton.addEventListener('click', this._onNewRuleClick.bind(this)); | 760 newRuleButton.addEventListener('click', this._onNewRuleClick.bind(this)); |
| 761 items.push(newRuleButton); | 761 items.push(newRuleButton); |
| 762 } | 762 } |
| 763 | 763 |
| 764 var sectionToolbar = new WebInspector.Toolbar('sidebar-pane-section-toolbar'
, container); | 764 var sectionToolbar = new UI.Toolbar('sidebar-pane-section-toolbar', containe
r); |
| 765 for (var i = 0; i < items.length; ++i) | 765 for (var i = 0; i < items.length; ++i) |
| 766 sectionToolbar.appendToolbarItem(items[i]); | 766 sectionToolbar.appendToolbarItem(items[i]); |
| 767 | 767 |
| 768 var menuButton = new WebInspector.ToolbarButton(WebInspector.UIString('More
tools\u2026'), 'largeicon-menu'); | 768 var menuButton = new UI.ToolbarButton(Common.UIString('More tools\u2026'), '
largeicon-menu'); |
| 769 sectionToolbar.appendToolbarItem(menuButton); | 769 sectionToolbar.appendToolbarItem(menuButton); |
| 770 setItemsVisibility.call(this, items, false); | 770 setItemsVisibility.call(this, items, false); |
| 771 sectionToolbar.element.addEventListener('mouseenter', setItemsVisibility.bin
d(this, items, true)); | 771 sectionToolbar.element.addEventListener('mouseenter', setItemsVisibility.bin
d(this, items, true)); |
| 772 sectionToolbar.element.addEventListener('mouseleave', setItemsVisibility.bin
d(this, items, false)); | 772 sectionToolbar.element.addEventListener('mouseleave', setItemsVisibility.bin
d(this, items, false)); |
| 773 | 773 |
| 774 /** | 774 /** |
| 775 * @param {!Array<!WebInspector.ToolbarButton>} items | 775 * @param {!Array<!UI.ToolbarButton>} items |
| 776 * @param {boolean} value | 776 * @param {boolean} value |
| 777 * @this {WebInspector.StylePropertiesSection} | 777 * @this {Elements.StylePropertiesSection} |
| 778 */ | 778 */ |
| 779 function setItemsVisibility(items, value) { | 779 function setItemsVisibility(items, value) { |
| 780 for (var i = 0; i < items.length; ++i) | 780 for (var i = 0; i < items.length; ++i) |
| 781 items[i].setVisible(value); | 781 items[i].setVisible(value); |
| 782 menuButton.setVisible(!value); | 782 menuButton.setVisible(!value); |
| 783 if (this._isSASSStyle()) | 783 if (this._isSASSStyle()) |
| 784 newRuleButton.setVisible(false); | 784 newRuleButton.setVisible(false); |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 | 787 |
| 788 /** | 788 /** |
| 789 * @return {boolean} | 789 * @return {boolean} |
| 790 */ | 790 */ |
| 791 _isSASSStyle() { | 791 _isSASSStyle() { |
| 792 var header = | 792 var header = |
| 793 this._style.styleSheetId ? this._style.cssModel().styleSheetHeaderForId(
this._style.styleSheetId) : null; | 793 this._style.styleSheetId ? this._style.cssModel().styleSheetHeaderForId(
this._style.styleSheetId) : null; |
| 794 if (!header) | 794 if (!header) |
| 795 return false; | 795 return false; |
| 796 var sourceMap = header.cssModel().sourceMapForHeader(header); | 796 var sourceMap = header.cssModel().sourceMapForHeader(header); |
| 797 return sourceMap ? sourceMap.editable() : false; | 797 return sourceMap ? sourceMap.editable() : false; |
| 798 } | 798 } |
| 799 | 799 |
| 800 /** | 800 /** |
| 801 * @return {!WebInspector.CSSStyleDeclaration} | 801 * @return {!SDK.CSSStyleDeclaration} |
| 802 */ | 802 */ |
| 803 style() { | 803 style() { |
| 804 return this._style; | 804 return this._style; |
| 805 } | 805 } |
| 806 | 806 |
| 807 /** | 807 /** |
| 808 * @return {string} | 808 * @return {string} |
| 809 */ | 809 */ |
| 810 _headerText() { | 810 _headerText() { |
| 811 var node = this._matchedStyles.nodeForStyle(this._style); | 811 var node = this._matchedStyles.nodeForStyle(this._style); |
| 812 if (this._style.type === WebInspector.CSSStyleDeclaration.Type.Inline) | 812 if (this._style.type === SDK.CSSStyleDeclaration.Type.Inline) |
| 813 return this._matchedStyles.isInherited(this._style) ? WebInspector.UIStrin
g('Style Attribute') : 'element.style'; | 813 return this._matchedStyles.isInherited(this._style) ? Common.UIString('Sty
le Attribute') : 'element.style'; |
| 814 if (this._style.type === WebInspector.CSSStyleDeclaration.Type.Attributes) | 814 if (this._style.type === SDK.CSSStyleDeclaration.Type.Attributes) |
| 815 return node.nodeNameInCorrectCase() + '[' + WebInspector.UIString('Attribu
tes Style') + ']'; | 815 return node.nodeNameInCorrectCase() + '[' + Common.UIString('Attributes St
yle') + ']'; |
| 816 return this._style.parentRule.selectorText(); | 816 return this._style.parentRule.selectorText(); |
| 817 } | 817 } |
| 818 | 818 |
| 819 _onMouseOutSelector() { | 819 _onMouseOutSelector() { |
| 820 if (this._hoverTimer) | 820 if (this._hoverTimer) |
| 821 clearTimeout(this._hoverTimer); | 821 clearTimeout(this._hoverTimer); |
| 822 WebInspector.DOMModel.hideDOMNodeHighlight(); | 822 SDK.DOMModel.hideDOMNodeHighlight(); |
| 823 } | 823 } |
| 824 | 824 |
| 825 _onMouseEnterSelector() { | 825 _onMouseEnterSelector() { |
| 826 if (this._hoverTimer) | 826 if (this._hoverTimer) |
| 827 clearTimeout(this._hoverTimer); | 827 clearTimeout(this._hoverTimer); |
| 828 this._hoverTimer = setTimeout(this._highlight.bind(this), 300); | 828 this._hoverTimer = setTimeout(this._highlight.bind(this), 300); |
| 829 } | 829 } |
| 830 | 830 |
| 831 _highlight() { | 831 _highlight() { |
| 832 WebInspector.DOMModel.hideDOMNodeHighlight(); | 832 SDK.DOMModel.hideDOMNodeHighlight(); |
| 833 var node = this._parentPane.node(); | 833 var node = this._parentPane.node(); |
| 834 var domModel = node.domModel(); | 834 var domModel = node.domModel(); |
| 835 var selectors = this._style.parentRule ? this._style.parentRule.selectorText
() : undefined; | 835 var selectors = this._style.parentRule ? this._style.parentRule.selectorText
() : undefined; |
| 836 domModel.highlightDOMNodeWithConfig(node.id, {mode: 'all', showInfo: undefin
ed, selectors: selectors}); | 836 domModel.highlightDOMNodeWithConfig(node.id, {mode: 'all', showInfo: undefin
ed, selectors: selectors}); |
| 837 } | 837 } |
| 838 | 838 |
| 839 /** | 839 /** |
| 840 * @return {?WebInspector.StylePropertiesSection} | 840 * @return {?Elements.StylePropertiesSection} |
| 841 */ | 841 */ |
| 842 firstSibling() { | 842 firstSibling() { |
| 843 var parent = this.element.parentElement; | 843 var parent = this.element.parentElement; |
| 844 if (!parent) | 844 if (!parent) |
| 845 return null; | 845 return null; |
| 846 | 846 |
| 847 var childElement = parent.firstChild; | 847 var childElement = parent.firstChild; |
| 848 while (childElement) { | 848 while (childElement) { |
| 849 if (childElement._section) | 849 if (childElement._section) |
| 850 return childElement._section; | 850 return childElement._section; |
| 851 childElement = childElement.nextSibling; | 851 childElement = childElement.nextSibling; |
| 852 } | 852 } |
| 853 | 853 |
| 854 return null; | 854 return null; |
| 855 } | 855 } |
| 856 | 856 |
| 857 /** | 857 /** |
| 858 * @return {?WebInspector.StylePropertiesSection} | 858 * @return {?Elements.StylePropertiesSection} |
| 859 */ | 859 */ |
| 860 lastSibling() { | 860 lastSibling() { |
| 861 var parent = this.element.parentElement; | 861 var parent = this.element.parentElement; |
| 862 if (!parent) | 862 if (!parent) |
| 863 return null; | 863 return null; |
| 864 | 864 |
| 865 var childElement = parent.lastChild; | 865 var childElement = parent.lastChild; |
| 866 while (childElement) { | 866 while (childElement) { |
| 867 if (childElement._section) | 867 if (childElement._section) |
| 868 return childElement._section; | 868 return childElement._section; |
| 869 childElement = childElement.previousSibling; | 869 childElement = childElement.previousSibling; |
| 870 } | 870 } |
| 871 | 871 |
| 872 return null; | 872 return null; |
| 873 } | 873 } |
| 874 | 874 |
| 875 /** | 875 /** |
| 876 * @return {?WebInspector.StylePropertiesSection} | 876 * @return {?Elements.StylePropertiesSection} |
| 877 */ | 877 */ |
| 878 nextSibling() { | 878 nextSibling() { |
| 879 var curElement = this.element; | 879 var curElement = this.element; |
| 880 do { | 880 do { |
| 881 curElement = curElement.nextSibling; | 881 curElement = curElement.nextSibling; |
| 882 } while (curElement && !curElement._section); | 882 } while (curElement && !curElement._section); |
| 883 | 883 |
| 884 return curElement ? curElement._section : null; | 884 return curElement ? curElement._section : null; |
| 885 } | 885 } |
| 886 | 886 |
| 887 /** | 887 /** |
| 888 * @return {?WebInspector.StylePropertiesSection} | 888 * @return {?Elements.StylePropertiesSection} |
| 889 */ | 889 */ |
| 890 previousSibling() { | 890 previousSibling() { |
| 891 var curElement = this.element; | 891 var curElement = this.element; |
| 892 do { | 892 do { |
| 893 curElement = curElement.previousSibling; | 893 curElement = curElement.previousSibling; |
| 894 } while (curElement && !curElement._section); | 894 } while (curElement && !curElement._section); |
| 895 | 895 |
| 896 return curElement ? curElement._section : null; | 896 return curElement ? curElement._section : null; |
| 897 } | 897 } |
| 898 | 898 |
| 899 /** | 899 /** |
| 900 * @param {!WebInspector.Event} event | 900 * @param {!Common.Event} event |
| 901 */ | 901 */ |
| 902 _onNewRuleClick(event) { | 902 _onNewRuleClick(event) { |
| 903 event.consume(); | 903 event.consume(); |
| 904 var rule = this._style.parentRule; | 904 var rule = this._style.parentRule; |
| 905 var range = WebInspector.TextRange.createFromLocation(rule.style.range.endLi
ne, rule.style.range.endColumn + 1); | 905 var range = Common.TextRange.createFromLocation(rule.style.range.endLine, ru
le.style.range.endColumn + 1); |
| 906 this._parentPane._addBlankSection(this, /** @type {string} */ (rule.styleShe
etId), range); | 906 this._parentPane._addBlankSection(this, /** @type {string} */ (rule.styleShe
etId), range); |
| 907 } | 907 } |
| 908 | 908 |
| 909 /** | 909 /** |
| 910 * @param {string} propertyName | 910 * @param {string} propertyName |
| 911 * @param {!WebInspector.Event} event | 911 * @param {!Common.Event} event |
| 912 */ | 912 */ |
| 913 _onInsertShadowPropertyClick(propertyName, event) { | 913 _onInsertShadowPropertyClick(propertyName, event) { |
| 914 event.consume(true); | 914 event.consume(true); |
| 915 var treeElement = this.addNewBlankProperty(); | 915 var treeElement = this.addNewBlankProperty(); |
| 916 treeElement.property.name = propertyName; | 916 treeElement.property.name = propertyName; |
| 917 treeElement.property.value = '0 0 black'; | 917 treeElement.property.value = '0 0 black'; |
| 918 treeElement.updateTitle(); | 918 treeElement.updateTitle(); |
| 919 var shadowSwatchPopoverHelper = WebInspector.ShadowSwatchPopoverHelper.forTr
eeElement(treeElement); | 919 var shadowSwatchPopoverHelper = Elements.ShadowSwatchPopoverHelper.forTreeEl
ement(treeElement); |
| 920 if (shadowSwatchPopoverHelper) | 920 if (shadowSwatchPopoverHelper) |
| 921 shadowSwatchPopoverHelper.showPopover(); | 921 shadowSwatchPopoverHelper.showPopover(); |
| 922 } | 922 } |
| 923 | 923 |
| 924 /** | 924 /** |
| 925 * @param {!WebInspector.Event} event | 925 * @param {!Common.Event} event |
| 926 */ | 926 */ |
| 927 _onInsertColorPropertyClick(event) { | 927 _onInsertColorPropertyClick(event) { |
| 928 event.consume(true); | 928 event.consume(true); |
| 929 var treeElement = this.addNewBlankProperty(); | 929 var treeElement = this.addNewBlankProperty(); |
| 930 treeElement.property.name = 'color'; | 930 treeElement.property.name = 'color'; |
| 931 treeElement.property.value = 'black'; | 931 treeElement.property.value = 'black'; |
| 932 treeElement.updateTitle(); | 932 treeElement.updateTitle(); |
| 933 var colorSwatch = WebInspector.ColorSwatchPopoverIcon.forTreeElement(treeEle
ment); | 933 var colorSwatch = Elements.ColorSwatchPopoverIcon.forTreeElement(treeElement
); |
| 934 if (colorSwatch) | 934 if (colorSwatch) |
| 935 colorSwatch.showPopover(); | 935 colorSwatch.showPopover(); |
| 936 } | 936 } |
| 937 | 937 |
| 938 /** | 938 /** |
| 939 * @param {!WebInspector.Event} event | 939 * @param {!Common.Event} event |
| 940 */ | 940 */ |
| 941 _onInsertBackgroundColorPropertyClick(event) { | 941 _onInsertBackgroundColorPropertyClick(event) { |
| 942 event.consume(true); | 942 event.consume(true); |
| 943 var treeElement = this.addNewBlankProperty(); | 943 var treeElement = this.addNewBlankProperty(); |
| 944 treeElement.property.name = 'background-color'; | 944 treeElement.property.name = 'background-color'; |
| 945 treeElement.property.value = 'white'; | 945 treeElement.property.value = 'white'; |
| 946 treeElement.updateTitle(); | 946 treeElement.updateTitle(); |
| 947 var colorSwatch = WebInspector.ColorSwatchPopoverIcon.forTreeElement(treeEle
ment); | 947 var colorSwatch = Elements.ColorSwatchPopoverIcon.forTreeElement(treeElement
); |
| 948 if (colorSwatch) | 948 if (colorSwatch) |
| 949 colorSwatch.showPopover(); | 949 colorSwatch.showPopover(); |
| 950 } | 950 } |
| 951 | 951 |
| 952 /** | 952 /** |
| 953 * @param {!WebInspector.CSSModel.Edit} edit | 953 * @param {!SDK.CSSModel.Edit} edit |
| 954 */ | 954 */ |
| 955 _styleSheetEdited(edit) { | 955 _styleSheetEdited(edit) { |
| 956 var rule = this._style.parentRule; | 956 var rule = this._style.parentRule; |
| 957 if (rule) | 957 if (rule) |
| 958 rule.rebase(edit); | 958 rule.rebase(edit); |
| 959 else | 959 else |
| 960 this._style.rebase(edit); | 960 this._style.rebase(edit); |
| 961 | 961 |
| 962 this._updateMediaList(); | 962 this._updateMediaList(); |
| 963 this._updateRuleOrigin(); | 963 this._updateRuleOrigin(); |
| 964 } | 964 } |
| 965 | 965 |
| 966 /** | 966 /** |
| 967 * @param {!Array.<!WebInspector.CSSMedia>} mediaRules | 967 * @param {!Array.<!SDK.CSSMedia>} mediaRules |
| 968 */ | 968 */ |
| 969 _createMediaList(mediaRules) { | 969 _createMediaList(mediaRules) { |
| 970 for (var i = mediaRules.length - 1; i >= 0; --i) { | 970 for (var i = mediaRules.length - 1; i >= 0; --i) { |
| 971 var media = mediaRules[i]; | 971 var media = mediaRules[i]; |
| 972 // Don't display trivial non-print media types. | 972 // Don't display trivial non-print media types. |
| 973 if (!media.text.includes('(') && media.text !== 'print') | 973 if (!media.text.includes('(') && media.text !== 'print') |
| 974 continue; | 974 continue; |
| 975 var mediaDataElement = this._mediaListElement.createChild('div', 'media'); | 975 var mediaDataElement = this._mediaListElement.createChild('div', 'media'); |
| 976 var mediaContainerElement = mediaDataElement.createChild('span'); | 976 var mediaContainerElement = mediaDataElement.createChild('span'); |
| 977 var mediaTextElement = mediaContainerElement.createChild('span', 'media-te
xt'); | 977 var mediaTextElement = mediaContainerElement.createChild('span', 'media-te
xt'); |
| 978 switch (media.source) { | 978 switch (media.source) { |
| 979 case WebInspector.CSSMedia.Source.LINKED_SHEET: | 979 case SDK.CSSMedia.Source.LINKED_SHEET: |
| 980 case WebInspector.CSSMedia.Source.INLINE_SHEET: | 980 case SDK.CSSMedia.Source.INLINE_SHEET: |
| 981 mediaTextElement.textContent = 'media="' + media.text + '"'; | 981 mediaTextElement.textContent = 'media="' + media.text + '"'; |
| 982 break; | 982 break; |
| 983 case WebInspector.CSSMedia.Source.MEDIA_RULE: | 983 case SDK.CSSMedia.Source.MEDIA_RULE: |
| 984 var decoration = mediaContainerElement.createChild('span'); | 984 var decoration = mediaContainerElement.createChild('span'); |
| 985 mediaContainerElement.insertBefore(decoration, mediaTextElement); | 985 mediaContainerElement.insertBefore(decoration, mediaTextElement); |
| 986 decoration.textContent = '@media '; | 986 decoration.textContent = '@media '; |
| 987 mediaTextElement.textContent = media.text; | 987 mediaTextElement.textContent = media.text; |
| 988 if (media.styleSheetId) { | 988 if (media.styleSheetId) { |
| 989 mediaDataElement.classList.add('editable-media'); | 989 mediaDataElement.classList.add('editable-media'); |
| 990 mediaTextElement.addEventListener( | 990 mediaTextElement.addEventListener( |
| 991 'click', this._handleMediaRuleClick.bind(this, media, mediaTextE
lement), false); | 991 'click', this._handleMediaRuleClick.bind(this, media, mediaTextE
lement), false); |
| 992 } | 992 } |
| 993 break; | 993 break; |
| 994 case WebInspector.CSSMedia.Source.IMPORT_RULE: | 994 case SDK.CSSMedia.Source.IMPORT_RULE: |
| 995 mediaTextElement.textContent = '@import ' + media.text; | 995 mediaTextElement.textContent = '@import ' + media.text; |
| 996 break; | 996 break; |
| 997 } | 997 } |
| 998 } | 998 } |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 _updateMediaList() { | 1001 _updateMediaList() { |
| 1002 this._mediaListElement.removeChildren(); | 1002 this._mediaListElement.removeChildren(); |
| 1003 if (this._style.parentRule && this._style.parentRule instanceof WebInspector
.CSSStyleRule) | 1003 if (this._style.parentRule && this._style.parentRule instanceof SDK.CSSStyle
Rule) |
| 1004 this._createMediaList(this._style.parentRule.media); | 1004 this._createMediaList(this._style.parentRule.media); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 /** | 1007 /** |
| 1008 * @param {string} propertyName | 1008 * @param {string} propertyName |
| 1009 * @return {boolean} | 1009 * @return {boolean} |
| 1010 */ | 1010 */ |
| 1011 isPropertyInherited(propertyName) { | 1011 isPropertyInherited(propertyName) { |
| 1012 if (this._matchedStyles.isInherited(this._style)) { | 1012 if (this._matchedStyles.isInherited(this._style)) { |
| 1013 // While rendering inherited stylesheet, reverse meaning of this property. | 1013 // While rendering inherited stylesheet, reverse meaning of this property. |
| 1014 // Render truly inherited properties with black, i.e. return them as non-i
nherited. | 1014 // Render truly inherited properties with black, i.e. return them as non-i
nherited. |
| 1015 return !WebInspector.cssMetadata().isPropertyInherited(propertyName); | 1015 return !SDK.cssMetadata().isPropertyInherited(propertyName); |
| 1016 } | 1016 } |
| 1017 return false; | 1017 return false; |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 /** | 1020 /** |
| 1021 * @return {?WebInspector.StylePropertiesSection} | 1021 * @return {?Elements.StylePropertiesSection} |
| 1022 */ | 1022 */ |
| 1023 nextEditableSibling() { | 1023 nextEditableSibling() { |
| 1024 var curSection = this; | 1024 var curSection = this; |
| 1025 do { | 1025 do { |
| 1026 curSection = curSection.nextSibling(); | 1026 curSection = curSection.nextSibling(); |
| 1027 } while (curSection && !curSection.editable); | 1027 } while (curSection && !curSection.editable); |
| 1028 | 1028 |
| 1029 if (!curSection) { | 1029 if (!curSection) { |
| 1030 curSection = this.firstSibling(); | 1030 curSection = this.firstSibling(); |
| 1031 while (curSection && !curSection.editable) | 1031 while (curSection && !curSection.editable) |
| 1032 curSection = curSection.nextSibling(); | 1032 curSection = curSection.nextSibling(); |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 return (curSection && curSection.editable) ? curSection : null; | 1035 return (curSection && curSection.editable) ? curSection : null; |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 /** | 1038 /** |
| 1039 * @return {?WebInspector.StylePropertiesSection} | 1039 * @return {?Elements.StylePropertiesSection} |
| 1040 */ | 1040 */ |
| 1041 previousEditableSibling() { | 1041 previousEditableSibling() { |
| 1042 var curSection = this; | 1042 var curSection = this; |
| 1043 do { | 1043 do { |
| 1044 curSection = curSection.previousSibling(); | 1044 curSection = curSection.previousSibling(); |
| 1045 } while (curSection && !curSection.editable); | 1045 } while (curSection && !curSection.editable); |
| 1046 | 1046 |
| 1047 if (!curSection) { | 1047 if (!curSection) { |
| 1048 curSection = this.lastSibling(); | 1048 curSection = this.lastSibling(); |
| 1049 while (curSection && !curSection.editable) | 1049 while (curSection && !curSection.editable) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 | 1082 |
| 1083 _afterUpdateFinishedForTest() { | 1083 _afterUpdateFinishedForTest() { |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 onpopulate() { | 1086 onpopulate() { |
| 1087 var style = this._style; | 1087 var style = this._style; |
| 1088 for (var property of style.leadingProperties()) { | 1088 for (var property of style.leadingProperties()) { |
| 1089 var isShorthand = !!style.longhandProperties(property.name).length; | 1089 var isShorthand = !!style.longhandProperties(property.name).length; |
| 1090 var inherited = this.isPropertyInherited(property.name); | 1090 var inherited = this.isPropertyInherited(property.name); |
| 1091 var overloaded = this._isPropertyOverloaded(property); | 1091 var overloaded = this._isPropertyOverloaded(property); |
| 1092 var item = new WebInspector.StylePropertyTreeElement( | 1092 var item = new Elements.StylePropertyTreeElement( |
| 1093 this._parentPane, this._matchedStyles, property, isShorthand, inherite
d, overloaded); | 1093 this._parentPane, this._matchedStyles, property, isShorthand, inherite
d, overloaded); |
| 1094 this.propertiesTreeOutline.appendChild(item); | 1094 this.propertiesTreeOutline.appendChild(item); |
| 1095 } | 1095 } |
| 1096 } | 1096 } |
| 1097 | 1097 |
| 1098 /** | 1098 /** |
| 1099 * @param {!WebInspector.CSSProperty} property | 1099 * @param {!SDK.CSSProperty} property |
| 1100 * @return {boolean} | 1100 * @return {boolean} |
| 1101 */ | 1101 */ |
| 1102 _isPropertyOverloaded(property) { | 1102 _isPropertyOverloaded(property) { |
| 1103 return this._matchedStyles.propertyState(property) === WebInspector.CSSMatch
edStyles.PropertyState.Overloaded; | 1103 return this._matchedStyles.propertyState(property) === SDK.CSSMatchedStyles.
PropertyState.Overloaded; |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 /** | 1106 /** |
| 1107 * @return {boolean} | 1107 * @return {boolean} |
| 1108 */ | 1108 */ |
| 1109 _updateFilter() { | 1109 _updateFilter() { |
| 1110 var hasMatchingChild = false; | 1110 var hasMatchingChild = false; |
| 1111 for (var child of this.propertiesTreeOutline.rootElement().children()) | 1111 for (var child of this.propertiesTreeOutline.rootElement().children()) |
| 1112 hasMatchingChild |= child._updateFilter(); | 1112 hasMatchingChild |= child._updateFilter(); |
| 1113 | 1113 |
| 1114 var regex = this._parentPane.filterRegex(); | 1114 var regex = this._parentPane.filterRegex(); |
| 1115 var hideRule = !hasMatchingChild && !!regex && !regex.test(this.element.deep
TextContent()); | 1115 var hideRule = !hasMatchingChild && !!regex && !regex.test(this.element.deep
TextContent()); |
| 1116 this.element.classList.toggle('hidden', hideRule); | 1116 this.element.classList.toggle('hidden', hideRule); |
| 1117 if (!hideRule && this._style.parentRule) | 1117 if (!hideRule && this._style.parentRule) |
| 1118 this._markSelectorHighlights(); | 1118 this._markSelectorHighlights(); |
| 1119 return !hideRule; | 1119 return !hideRule; |
| 1120 } | 1120 } |
| 1121 | 1121 |
| 1122 _markSelectorMatches() { | 1122 _markSelectorMatches() { |
| 1123 var rule = this._style.parentRule; | 1123 var rule = this._style.parentRule; |
| 1124 if (!rule) | 1124 if (!rule) |
| 1125 return; | 1125 return; |
| 1126 | 1126 |
| 1127 this._mediaListElement.classList.toggle('media-matches', this._matchedStyles
.mediaMatches(this._style)); | 1127 this._mediaListElement.classList.toggle('media-matches', this._matchedStyles
.mediaMatches(this._style)); |
| 1128 | 1128 |
| 1129 var selectorTexts = rule.selectors.map(selector => selector.text); | 1129 var selectorTexts = rule.selectors.map(selector => selector.text); |
| 1130 var matchingSelectorIndexes = | 1130 var matchingSelectorIndexes = |
| 1131 this._matchedStyles.matchingSelectors(/** @type {!WebInspector.CSSStyleR
ule} */ (rule)); | 1131 this._matchedStyles.matchingSelectors(/** @type {!SDK.CSSStyleRule} */ (
rule)); |
| 1132 var matchingSelectors = new Array(selectorTexts.length).fill(false); | 1132 var matchingSelectors = new Array(selectorTexts.length).fill(false); |
| 1133 for (var matchingIndex of matchingSelectorIndexes) | 1133 for (var matchingIndex of matchingSelectorIndexes) |
| 1134 matchingSelectors[matchingIndex] = true; | 1134 matchingSelectors[matchingIndex] = true; |
| 1135 | 1135 |
| 1136 var fragment = this._hoverableSelectorsMode ? this._renderHoverableSelectors
(selectorTexts, matchingSelectors) : | 1136 var fragment = this._hoverableSelectorsMode ? this._renderHoverableSelectors
(selectorTexts, matchingSelectors) : |
| 1137 this._renderSimplifiedSelector
s(selectorTexts, matchingSelectors); | 1137 this._renderSimplifiedSelector
s(selectorTexts, matchingSelectors); |
| 1138 this._selectorElement.removeChildren(); | 1138 this._selectorElement.removeChildren(); |
| 1139 this._selectorElement.appendChild(fragment); | 1139 this._selectorElement.appendChild(fragment); |
| 1140 this._markSelectorHighlights(); | 1140 this._markSelectorHighlights(); |
| 1141 } | 1141 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 if (this._checkWillCancelEditing() || !this.editable) | 1217 if (this._checkWillCancelEditing() || !this.editable) |
| 1218 return; | 1218 return; |
| 1219 if (event.target === this._selectorContainer) { | 1219 if (event.target === this._selectorContainer) { |
| 1220 this.addNewBlankProperty(0).startEditing(); | 1220 this.addNewBlankProperty(0).startEditing(); |
| 1221 event.consume(true); | 1221 event.consume(true); |
| 1222 } | 1222 } |
| 1223 } | 1223 } |
| 1224 | 1224 |
| 1225 /** | 1225 /** |
| 1226 * @param {number=} index | 1226 * @param {number=} index |
| 1227 * @return {!WebInspector.StylePropertyTreeElement} | 1227 * @return {!Elements.StylePropertyTreeElement} |
| 1228 */ | 1228 */ |
| 1229 addNewBlankProperty(index) { | 1229 addNewBlankProperty(index) { |
| 1230 var property = this._style.newBlankProperty(index); | 1230 var property = this._style.newBlankProperty(index); |
| 1231 var item = | 1231 var item = |
| 1232 new WebInspector.StylePropertyTreeElement(this._parentPane, this._matche
dStyles, property, false, false, false); | 1232 new Elements.StylePropertyTreeElement(this._parentPane, this._matchedSty
les, property, false, false, false); |
| 1233 index = property.index; | 1233 index = property.index; |
| 1234 this.propertiesTreeOutline.insertChild(item, index); | 1234 this.propertiesTreeOutline.insertChild(item, index); |
| 1235 item.listItemElement.textContent = ''; | 1235 item.listItemElement.textContent = ''; |
| 1236 item._newProperty = true; | 1236 item._newProperty = true; |
| 1237 item.updateTitle(); | 1237 item.updateTitle(); |
| 1238 return item; | 1238 return item; |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 _handleEmptySpaceMouseDown() { | 1241 _handleEmptySpaceMouseDown() { |
| 1242 this._willCauseCancelEditing = this._parentPane._isEditingStyle; | 1242 this._willCauseCancelEditing = this._parentPane._isEditingStyle; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1265 if (event.target.classList.contains('header') || this.element.classList.cont
ains('read-only') || | 1265 if (event.target.classList.contains('header') || this.element.classList.cont
ains('read-only') || |
| 1266 event.target.enclosingNodeOrSelfWithClass('media')) { | 1266 event.target.enclosingNodeOrSelfWithClass('media')) { |
| 1267 event.consume(); | 1267 event.consume(); |
| 1268 return; | 1268 return; |
| 1269 } | 1269 } |
| 1270 this.addNewBlankProperty().startEditing(); | 1270 this.addNewBlankProperty().startEditing(); |
| 1271 event.consume(true); | 1271 event.consume(true); |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 /** | 1274 /** |
| 1275 * @param {!WebInspector.CSSMedia} media | 1275 * @param {!SDK.CSSMedia} media |
| 1276 * @param {!Element} element | 1276 * @param {!Element} element |
| 1277 * @param {!Event} event | 1277 * @param {!Event} event |
| 1278 */ | 1278 */ |
| 1279 _handleMediaRuleClick(media, element, event) { | 1279 _handleMediaRuleClick(media, element, event) { |
| 1280 if (WebInspector.isBeingEdited(element)) | 1280 if (UI.isBeingEdited(element)) |
| 1281 return; | 1281 return; |
| 1282 | 1282 |
| 1283 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEvent}
*/ (event)) && this.navigable) { | 1283 if (UI.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEvent} */ (event
)) && this.navigable) { |
| 1284 var location = media.rawLocation(); | 1284 var location = media.rawLocation(); |
| 1285 if (!location) { | 1285 if (!location) { |
| 1286 event.consume(true); | 1286 event.consume(true); |
| 1287 return; | 1287 return; |
| 1288 } | 1288 } |
| 1289 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILocation(
location); | 1289 var uiLocation = Bindings.cssWorkspaceBinding.rawLocationToUILocation(loca
tion); |
| 1290 if (uiLocation) | 1290 if (uiLocation) |
| 1291 WebInspector.Revealer.reveal(uiLocation); | 1291 Common.Revealer.reveal(uiLocation); |
| 1292 event.consume(true); | 1292 event.consume(true); |
| 1293 return; | 1293 return; |
| 1294 } | 1294 } |
| 1295 | 1295 |
| 1296 if (!this.editable || this._isSASSStyle()) | 1296 if (!this.editable || this._isSASSStyle()) |
| 1297 return; | 1297 return; |
| 1298 | 1298 |
| 1299 var config = new WebInspector.InplaceEditor.Config( | 1299 var config = new UI.InplaceEditor.Config( |
| 1300 this._editingMediaCommitted.bind(this, media), this._editingMediaCancell
ed.bind(this, element), undefined, | 1300 this._editingMediaCommitted.bind(this, media), this._editingMediaCancell
ed.bind(this, element), undefined, |
| 1301 this._editingMediaBlurHandler.bind(this)); | 1301 this._editingMediaBlurHandler.bind(this)); |
| 1302 WebInspector.InplaceEditor.startEditing(element, config); | 1302 UI.InplaceEditor.startEditing(element, config); |
| 1303 | 1303 |
| 1304 element.getComponentSelection().setBaseAndExtent(element, 0, element, 1); | 1304 element.getComponentSelection().setBaseAndExtent(element, 0, element, 1); |
| 1305 this._parentPane.setEditingStyle(true); | 1305 this._parentPane.setEditingStyle(true); |
| 1306 var parentMediaElement = element.enclosingNodeOrSelfWithClass('media'); | 1306 var parentMediaElement = element.enclosingNodeOrSelfWithClass('media'); |
| 1307 parentMediaElement.classList.add('editing-media'); | 1307 parentMediaElement.classList.add('editing-media'); |
| 1308 | 1308 |
| 1309 event.consume(true); | 1309 event.consume(true); |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 /** | 1312 /** |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1332 /** | 1332 /** |
| 1333 * @param {!Element} editor | 1333 * @param {!Element} editor |
| 1334 * @param {!Event} blurEvent | 1334 * @param {!Event} blurEvent |
| 1335 * @return {boolean} | 1335 * @return {boolean} |
| 1336 */ | 1336 */ |
| 1337 _editingMediaBlurHandler(editor, blurEvent) { | 1337 _editingMediaBlurHandler(editor, blurEvent) { |
| 1338 return true; | 1338 return true; |
| 1339 } | 1339 } |
| 1340 | 1340 |
| 1341 /** | 1341 /** |
| 1342 * @param {!WebInspector.CSSMedia} media | 1342 * @param {!SDK.CSSMedia} media |
| 1343 * @param {!Element} element | 1343 * @param {!Element} element |
| 1344 * @param {string} newContent | 1344 * @param {string} newContent |
| 1345 * @param {string} oldContent | 1345 * @param {string} oldContent |
| 1346 * @param {(!WebInspector.StylePropertyTreeElement.Context|undefined)} context | 1346 * @param {(!Elements.StylePropertyTreeElement.Context|undefined)} context |
| 1347 * @param {string} moveDirection | 1347 * @param {string} moveDirection |
| 1348 */ | 1348 */ |
| 1349 _editingMediaCommitted(media, element, newContent, oldContent, context, moveDi
rection) { | 1349 _editingMediaCommitted(media, element, newContent, oldContent, context, moveDi
rection) { |
| 1350 this._parentPane.setEditingStyle(false); | 1350 this._parentPane.setEditingStyle(false); |
| 1351 this._editingMediaFinished(element); | 1351 this._editingMediaFinished(element); |
| 1352 | 1352 |
| 1353 if (newContent) | 1353 if (newContent) |
| 1354 newContent = newContent.trim(); | 1354 newContent = newContent.trim(); |
| 1355 | 1355 |
| 1356 /** | 1356 /** |
| 1357 * @param {boolean} success | 1357 * @param {boolean} success |
| 1358 * @this {WebInspector.StylePropertiesSection} | 1358 * @this {Elements.StylePropertiesSection} |
| 1359 */ | 1359 */ |
| 1360 function userCallback(success) { | 1360 function userCallback(success) { |
| 1361 if (success) { | 1361 if (success) { |
| 1362 this._matchedStyles.resetActiveProperties(); | 1362 this._matchedStyles.resetActiveProperties(); |
| 1363 this._parentPane._refreshUpdate(this); | 1363 this._parentPane._refreshUpdate(this); |
| 1364 } | 1364 } |
| 1365 delete this._parentPane._userOperation; | 1365 delete this._parentPane._userOperation; |
| 1366 this._editingMediaTextCommittedForTest(); | 1366 this._editingMediaTextCommittedForTest(); |
| 1367 } | 1367 } |
| 1368 | 1368 |
| 1369 // This gets deleted in finishOperation(), which is called both on success a
nd failure. | 1369 // This gets deleted in finishOperation(), which is called both on success a
nd failure. |
| 1370 this._parentPane._userOperation = true; | 1370 this._parentPane._userOperation = true; |
| 1371 this._parentPane.cssModel().setMediaText(media.styleSheetId, media.range, ne
wContent).then(userCallback.bind(this)); | 1371 this._parentPane.cssModel().setMediaText(media.styleSheetId, media.range, ne
wContent).then(userCallback.bind(this)); |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 _editingMediaTextCommittedForTest() { | 1374 _editingMediaTextCommittedForTest() { |
| 1375 } | 1375 } |
| 1376 | 1376 |
| 1377 /** | 1377 /** |
| 1378 * @param {!Event} event | 1378 * @param {!Event} event |
| 1379 */ | 1379 */ |
| 1380 _handleSelectorClick(event) { | 1380 _handleSelectorClick(event) { |
| 1381 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEvent}
*/ (event)) && this.navigable && | 1381 if (UI.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEvent} */ (event
)) && this.navigable && |
| 1382 event.target.classList.contains('simple-selector')) { | 1382 event.target.classList.contains('simple-selector')) { |
| 1383 this._navigateToSelectorSource(event.target._selectorIndex, true); | 1383 this._navigateToSelectorSource(event.target._selectorIndex, true); |
| 1384 event.consume(true); | 1384 event.consume(true); |
| 1385 return; | 1385 return; |
| 1386 } | 1386 } |
| 1387 this._startEditingOnMouseEvent(); | 1387 this._startEditingOnMouseEvent(); |
| 1388 event.consume(true); | 1388 event.consume(true); |
| 1389 } | 1389 } |
| 1390 | 1390 |
| 1391 /** | 1391 /** |
| 1392 * @param {number} index | 1392 * @param {number} index |
| 1393 * @param {boolean} focus | 1393 * @param {boolean} focus |
| 1394 */ | 1394 */ |
| 1395 _navigateToSelectorSource(index, focus) { | 1395 _navigateToSelectorSource(index, focus) { |
| 1396 var cssModel = this._parentPane.cssModel(); | 1396 var cssModel = this._parentPane.cssModel(); |
| 1397 var rule = this._style.parentRule; | 1397 var rule = this._style.parentRule; |
| 1398 var header = cssModel.styleSheetHeaderForId(/** @type {string} */ (rule.styl
eSheetId)); | 1398 var header = cssModel.styleSheetHeaderForId(/** @type {string} */ (rule.styl
eSheetId)); |
| 1399 if (!header) | 1399 if (!header) |
| 1400 return; | 1400 return; |
| 1401 var rawLocation = | 1401 var rawLocation = |
| 1402 new WebInspector.CSSLocation(header, rule.lineNumberInSource(index), rul
e.columnNumberInSource(index)); | 1402 new SDK.CSSLocation(header, rule.lineNumberInSource(index), rule.columnN
umberInSource(index)); |
| 1403 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILocation(ra
wLocation); | 1403 var uiLocation = Bindings.cssWorkspaceBinding.rawLocationToUILocation(rawLoc
ation); |
| 1404 if (uiLocation) | 1404 if (uiLocation) |
| 1405 WebInspector.Revealer.reveal(uiLocation, !focus); | 1405 Common.Revealer.reveal(uiLocation, !focus); |
| 1406 } | 1406 } |
| 1407 | 1407 |
| 1408 _startEditingOnMouseEvent() { | 1408 _startEditingOnMouseEvent() { |
| 1409 if (!this.editable || this._isSASSStyle()) | 1409 if (!this.editable || this._isSASSStyle()) |
| 1410 return; | 1410 return; |
| 1411 | 1411 |
| 1412 var rule = this._style.parentRule; | 1412 var rule = this._style.parentRule; |
| 1413 if (!rule && !this.propertiesTreeOutline.rootElement().childCount()) { | 1413 if (!rule && !this.propertiesTreeOutline.rootElement().childCount()) { |
| 1414 this.addNewBlankProperty().startEditing(); | 1414 this.addNewBlankProperty().startEditing(); |
| 1415 return; | 1415 return; |
| 1416 } | 1416 } |
| 1417 | 1417 |
| 1418 if (!rule) | 1418 if (!rule) |
| 1419 return; | 1419 return; |
| 1420 | 1420 |
| 1421 this.startEditingSelector(); | 1421 this.startEditingSelector(); |
| 1422 } | 1422 } |
| 1423 | 1423 |
| 1424 startEditingSelector() { | 1424 startEditingSelector() { |
| 1425 var element = this._selectorElement; | 1425 var element = this._selectorElement; |
| 1426 if (WebInspector.isBeingEdited(element)) | 1426 if (UI.isBeingEdited(element)) |
| 1427 return; | 1427 return; |
| 1428 | 1428 |
| 1429 element.scrollIntoViewIfNeeded(false); | 1429 element.scrollIntoViewIfNeeded(false); |
| 1430 element.textContent = element.textContent; // Reset selector marks in group
. | 1430 element.textContent = element.textContent; // Reset selector marks in group
. |
| 1431 | 1431 |
| 1432 var config = new WebInspector.InplaceEditor.Config( | 1432 var config = new UI.InplaceEditor.Config( |
| 1433 this.editingSelectorCommitted.bind(this), this.editingSelectorCancelled.
bind(this)); | 1433 this.editingSelectorCommitted.bind(this), this.editingSelectorCancelled.
bind(this)); |
| 1434 WebInspector.InplaceEditor.startEditing(this._selectorElement, config); | 1434 UI.InplaceEditor.startEditing(this._selectorElement, config); |
| 1435 | 1435 |
| 1436 element.getComponentSelection().setBaseAndExtent(element, 0, element, 1); | 1436 element.getComponentSelection().setBaseAndExtent(element, 0, element, 1); |
| 1437 this._parentPane.setEditingStyle(true); | 1437 this._parentPane.setEditingStyle(true); |
| 1438 if (element.classList.contains('simple-selector')) | 1438 if (element.classList.contains('simple-selector')) |
| 1439 this._navigateToSelectorSource(0, false); | 1439 this._navigateToSelectorSource(0, false); |
| 1440 } | 1440 } |
| 1441 | 1441 |
| 1442 /** | 1442 /** |
| 1443 * @param {string} moveDirection | 1443 * @param {string} moveDirection |
| 1444 */ | 1444 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1462 return; | 1462 return; |
| 1463 | 1463 |
| 1464 previousSection.addNewBlankProperty().startEditing(); | 1464 previousSection.addNewBlankProperty().startEditing(); |
| 1465 } | 1465 } |
| 1466 } | 1466 } |
| 1467 | 1467 |
| 1468 /** | 1468 /** |
| 1469 * @param {!Element} element | 1469 * @param {!Element} element |
| 1470 * @param {string} newContent | 1470 * @param {string} newContent |
| 1471 * @param {string} oldContent | 1471 * @param {string} oldContent |
| 1472 * @param {(!WebInspector.StylePropertyTreeElement.Context|undefined)} context | 1472 * @param {(!Elements.StylePropertyTreeElement.Context|undefined)} context |
| 1473 * @param {string} moveDirection | 1473 * @param {string} moveDirection |
| 1474 */ | 1474 */ |
| 1475 editingSelectorCommitted(element, newContent, oldContent, context, moveDirecti
on) { | 1475 editingSelectorCommitted(element, newContent, oldContent, context, moveDirecti
on) { |
| 1476 this._editingSelectorEnded(); | 1476 this._editingSelectorEnded(); |
| 1477 if (newContent) | 1477 if (newContent) |
| 1478 newContent = newContent.trim(); | 1478 newContent = newContent.trim(); |
| 1479 if (newContent === oldContent) { | 1479 if (newContent === oldContent) { |
| 1480 // Revert to a trimmed version of the selector if need be. | 1480 // Revert to a trimmed version of the selector if need be. |
| 1481 this._selectorElement.textContent = newContent; | 1481 this._selectorElement.textContent = newContent; |
| 1482 this._moveEditorFromSelector(moveDirection); | 1482 this._moveEditorFromSelector(moveDirection); |
| 1483 return; | 1483 return; |
| 1484 } | 1484 } |
| 1485 var rule = this._style.parentRule; | 1485 var rule = this._style.parentRule; |
| 1486 if (!rule) | 1486 if (!rule) |
| 1487 return; | 1487 return; |
| 1488 | 1488 |
| 1489 /** | 1489 /** |
| 1490 * @this {WebInspector.StylePropertiesSection} | 1490 * @this {Elements.StylePropertiesSection} |
| 1491 */ | 1491 */ |
| 1492 function headerTextCommitted() { | 1492 function headerTextCommitted() { |
| 1493 delete this._parentPane._userOperation; | 1493 delete this._parentPane._userOperation; |
| 1494 this._moveEditorFromSelector(moveDirection); | 1494 this._moveEditorFromSelector(moveDirection); |
| 1495 this._editingSelectorCommittedForTest(); | 1495 this._editingSelectorCommittedForTest(); |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 // This gets deleted in finishOperationAndMoveEditor(), which is called both
on success and failure. | 1498 // This gets deleted in finishOperationAndMoveEditor(), which is called both
on success and failure. |
| 1499 this._parentPane._userOperation = true; | 1499 this._parentPane._userOperation = true; |
| 1500 this._setHeaderText(rule, newContent).then(headerTextCommitted.bind(this)); | 1500 this._setHeaderText(rule, newContent).then(headerTextCommitted.bind(this)); |
| 1501 } | 1501 } |
| 1502 | 1502 |
| 1503 /** | 1503 /** |
| 1504 * @param {!WebInspector.CSSRule} rule | 1504 * @param {!SDK.CSSRule} rule |
| 1505 * @param {string} newContent | 1505 * @param {string} newContent |
| 1506 * @return {!Promise} | 1506 * @return {!Promise} |
| 1507 */ | 1507 */ |
| 1508 _setHeaderText(rule, newContent) { | 1508 _setHeaderText(rule, newContent) { |
| 1509 /** | 1509 /** |
| 1510 * @param {!WebInspector.CSSStyleRule} rule | 1510 * @param {!SDK.CSSStyleRule} rule |
| 1511 * @param {boolean} success | 1511 * @param {boolean} success |
| 1512 * @return {!Promise} | 1512 * @return {!Promise} |
| 1513 * @this {WebInspector.StylePropertiesSection} | 1513 * @this {Elements.StylePropertiesSection} |
| 1514 */ | 1514 */ |
| 1515 function onSelectorsUpdated(rule, success) { | 1515 function onSelectorsUpdated(rule, success) { |
| 1516 if (!success) | 1516 if (!success) |
| 1517 return Promise.resolve(); | 1517 return Promise.resolve(); |
| 1518 return this._matchedStyles.recomputeMatchingSelectors(rule).then(updateSou
rceRanges.bind(this, rule)); | 1518 return this._matchedStyles.recomputeMatchingSelectors(rule).then(updateSou
rceRanges.bind(this, rule)); |
| 1519 } | 1519 } |
| 1520 | 1520 |
| 1521 /** | 1521 /** |
| 1522 * @param {!WebInspector.CSSStyleRule} rule | 1522 * @param {!SDK.CSSStyleRule} rule |
| 1523 * @this {WebInspector.StylePropertiesSection} | 1523 * @this {Elements.StylePropertiesSection} |
| 1524 */ | 1524 */ |
| 1525 function updateSourceRanges(rule) { | 1525 function updateSourceRanges(rule) { |
| 1526 var doesAffectSelectedNode = this._matchedStyles.matchingSelectors(rule).l
ength > 0; | 1526 var doesAffectSelectedNode = this._matchedStyles.matchingSelectors(rule).l
ength > 0; |
| 1527 this.propertiesTreeOutline.element.classList.toggle('no-affect', !doesAffe
ctSelectedNode); | 1527 this.propertiesTreeOutline.element.classList.toggle('no-affect', !doesAffe
ctSelectedNode); |
| 1528 this._matchedStyles.resetActiveProperties(); | 1528 this._matchedStyles.resetActiveProperties(); |
| 1529 this._parentPane._refreshUpdate(this); | 1529 this._parentPane._refreshUpdate(this); |
| 1530 } | 1530 } |
| 1531 | 1531 |
| 1532 console.assert(rule instanceof WebInspector.CSSStyleRule); | 1532 console.assert(rule instanceof SDK.CSSStyleRule); |
| 1533 var oldSelectorRange = rule.selectorRange(); | 1533 var oldSelectorRange = rule.selectorRange(); |
| 1534 if (!oldSelectorRange) | 1534 if (!oldSelectorRange) |
| 1535 return Promise.resolve(); | 1535 return Promise.resolve(); |
| 1536 var selectedNode = this._parentPane.node(); | 1536 var selectedNode = this._parentPane.node(); |
| 1537 return rule.setSelectorText(newContent) | 1537 return rule.setSelectorText(newContent) |
| 1538 .then(onSelectorsUpdated.bind(this, /** @type {!WebInspector.CSSStyleRul
e} */ (rule), oldSelectorRange)); | 1538 .then(onSelectorsUpdated.bind(this, /** @type {!SDK.CSSStyleRule} */ (ru
le), oldSelectorRange)); |
| 1539 } | 1539 } |
| 1540 | 1540 |
| 1541 _editingSelectorCommittedForTest() { | 1541 _editingSelectorCommittedForTest() { |
| 1542 } | 1542 } |
| 1543 | 1543 |
| 1544 _updateRuleOrigin() { | 1544 _updateRuleOrigin() { |
| 1545 this._selectorRefElement.removeChildren(); | 1545 this._selectorRefElement.removeChildren(); |
| 1546 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection.cre
ateRuleOriginNode( | 1546 this._selectorRefElement.appendChild(Elements.StylePropertiesSection.createR
uleOriginNode( |
| 1547 this._matchedStyles, this._parentPane._linkifier, this._style.parentRule
)); | 1547 this._matchedStyles, this._parentPane._linkifier, this._style.parentRule
)); |
| 1548 } | 1548 } |
| 1549 | 1549 |
| 1550 _editingSelectorEnded() { | 1550 _editingSelectorEnded() { |
| 1551 this._parentPane.setEditingStyle(false); | 1551 this._parentPane.setEditingStyle(false); |
| 1552 } | 1552 } |
| 1553 | 1553 |
| 1554 editingSelectorCancelled() { | 1554 editingSelectorCancelled() { |
| 1555 this._editingSelectorEnded(); | 1555 this._editingSelectorEnded(); |
| 1556 | 1556 |
| 1557 // Mark the selectors in group if necessary. | 1557 // Mark the selectors in group if necessary. |
| 1558 // This is overridden by BlankStylePropertiesSection. | 1558 // This is overridden by BlankStylePropertiesSection. |
| 1559 this._markSelectorMatches(); | 1559 this._markSelectorMatches(); |
| 1560 } | 1560 } |
| 1561 }; | 1561 }; |
| 1562 | 1562 |
| 1563 | 1563 |
| 1564 /** | 1564 /** |
| 1565 * @unrestricted | 1565 * @unrestricted |
| 1566 */ | 1566 */ |
| 1567 WebInspector.BlankStylePropertiesSection = class extends WebInspector.StylePrope
rtiesSection { | 1567 Elements.BlankStylePropertiesSection = class extends Elements.StylePropertiesSec
tion { |
| 1568 /** | 1568 /** |
| 1569 * @param {!WebInspector.StylesSidebarPane} stylesPane | 1569 * @param {!Elements.StylesSidebarPane} stylesPane |
| 1570 * @param {!WebInspector.CSSMatchedStyles} matchedStyles | 1570 * @param {!SDK.CSSMatchedStyles} matchedStyles |
| 1571 * @param {string} defaultSelectorText | 1571 * @param {string} defaultSelectorText |
| 1572 * @param {string} styleSheetId | 1572 * @param {string} styleSheetId |
| 1573 * @param {!WebInspector.TextRange} ruleLocation | 1573 * @param {!Common.TextRange} ruleLocation |
| 1574 * @param {!WebInspector.CSSStyleDeclaration} insertAfterStyle | 1574 * @param {!SDK.CSSStyleDeclaration} insertAfterStyle |
| 1575 */ | 1575 */ |
| 1576 constructor(stylesPane, matchedStyles, defaultSelectorText, styleSheetId, rule
Location, insertAfterStyle) { | 1576 constructor(stylesPane, matchedStyles, defaultSelectorText, styleSheetId, rule
Location, insertAfterStyle) { |
| 1577 var cssModel = /** @type {!WebInspector.CSSModel} */ (stylesPane.cssModel())
; | 1577 var cssModel = /** @type {!SDK.CSSModel} */ (stylesPane.cssModel()); |
| 1578 var rule = WebInspector.CSSStyleRule.createDummyRule(cssModel, defaultSelect
orText); | 1578 var rule = SDK.CSSStyleRule.createDummyRule(cssModel, defaultSelectorText); |
| 1579 super(stylesPane, matchedStyles, rule.style); | 1579 super(stylesPane, matchedStyles, rule.style); |
| 1580 this._ruleLocation = ruleLocation; | 1580 this._ruleLocation = ruleLocation; |
| 1581 this._styleSheetId = styleSheetId; | 1581 this._styleSheetId = styleSheetId; |
| 1582 this._selectorRefElement.removeChildren(); | 1582 this._selectorRefElement.removeChildren(); |
| 1583 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection._li
nkifyRuleLocation( | 1583 this._selectorRefElement.appendChild(Elements.StylePropertiesSection._linkif
yRuleLocation( |
| 1584 cssModel, this._parentPane._linkifier, styleSheetId, this._actualRuleLoc
ation())); | 1584 cssModel, this._parentPane._linkifier, styleSheetId, this._actualRuleLoc
ation())); |
| 1585 if (insertAfterStyle && insertAfterStyle.parentRule) | 1585 if (insertAfterStyle && insertAfterStyle.parentRule) |
| 1586 this._createMediaList(insertAfterStyle.parentRule.media); | 1586 this._createMediaList(insertAfterStyle.parentRule.media); |
| 1587 this.element.classList.add('blank-section'); | 1587 this.element.classList.add('blank-section'); |
| 1588 } | 1588 } |
| 1589 | 1589 |
| 1590 /** | 1590 /** |
| 1591 * @return {!WebInspector.TextRange} | 1591 * @return {!Common.TextRange} |
| 1592 */ | 1592 */ |
| 1593 _actualRuleLocation() { | 1593 _actualRuleLocation() { |
| 1594 var prefix = this._rulePrefix(); | 1594 var prefix = this._rulePrefix(); |
| 1595 var lines = prefix.split('\n'); | 1595 var lines = prefix.split('\n'); |
| 1596 var editRange = new WebInspector.TextRange(0, 0, lines.length - 1, lines.pee
kLast().length); | 1596 var editRange = new Common.TextRange(0, 0, lines.length - 1, lines.peekLast(
).length); |
| 1597 return this._ruleLocation.rebaseAfterTextEdit(WebInspector.TextRange.createF
romLocation(0, 0), editRange); | 1597 return this._ruleLocation.rebaseAfterTextEdit(Common.TextRange.createFromLoc
ation(0, 0), editRange); |
| 1598 } | 1598 } |
| 1599 | 1599 |
| 1600 /** | 1600 /** |
| 1601 * @return {string} | 1601 * @return {string} |
| 1602 */ | 1602 */ |
| 1603 _rulePrefix() { | 1603 _rulePrefix() { |
| 1604 return this._ruleLocation.startLine === 0 && this._ruleLocation.startColumn
=== 0 ? '' : '\n\n'; | 1604 return this._ruleLocation.startLine === 0 && this._ruleLocation.startColumn
=== 0 ? '' : '\n\n'; |
| 1605 } | 1605 } |
| 1606 | 1606 |
| 1607 /** | 1607 /** |
| 1608 * @return {boolean} | 1608 * @return {boolean} |
| 1609 */ | 1609 */ |
| 1610 get isBlank() { | 1610 get isBlank() { |
| 1611 return !this._normal; | 1611 return !this._normal; |
| 1612 } | 1612 } |
| 1613 | 1613 |
| 1614 /** | 1614 /** |
| 1615 * @override | 1615 * @override |
| 1616 * @param {!Element} element | 1616 * @param {!Element} element |
| 1617 * @param {string} newContent | 1617 * @param {string} newContent |
| 1618 * @param {string} oldContent | 1618 * @param {string} oldContent |
| 1619 * @param {!WebInspector.StylePropertyTreeElement.Context|undefined} context | 1619 * @param {!Elements.StylePropertyTreeElement.Context|undefined} context |
| 1620 * @param {string} moveDirection | 1620 * @param {string} moveDirection |
| 1621 */ | 1621 */ |
| 1622 editingSelectorCommitted(element, newContent, oldContent, context, moveDirecti
on) { | 1622 editingSelectorCommitted(element, newContent, oldContent, context, moveDirecti
on) { |
| 1623 if (!this.isBlank) { | 1623 if (!this.isBlank) { |
| 1624 super.editingSelectorCommitted(element, newContent, oldContent, context, m
oveDirection); | 1624 super.editingSelectorCommitted(element, newContent, oldContent, context, m
oveDirection); |
| 1625 return; | 1625 return; |
| 1626 } | 1626 } |
| 1627 | 1627 |
| 1628 /** | 1628 /** |
| 1629 * @param {?WebInspector.CSSStyleRule} newRule | 1629 * @param {?SDK.CSSStyleRule} newRule |
| 1630 * @return {!Promise} | 1630 * @return {!Promise} |
| 1631 * @this {WebInspector.StylePropertiesSection} | 1631 * @this {Elements.StylePropertiesSection} |
| 1632 */ | 1632 */ |
| 1633 function onRuleAdded(newRule) { | 1633 function onRuleAdded(newRule) { |
| 1634 if (!newRule) { | 1634 if (!newRule) { |
| 1635 this.editingSelectorCancelled(); | 1635 this.editingSelectorCancelled(); |
| 1636 this._editingSelectorCommittedForTest(); | 1636 this._editingSelectorCommittedForTest(); |
| 1637 return Promise.resolve(); | 1637 return Promise.resolve(); |
| 1638 } | 1638 } |
| 1639 return this._matchedStyles.addNewRule(newRule, this._matchedStyles.node()) | 1639 return this._matchedStyles.addNewRule(newRule, this._matchedStyles.node()) |
| 1640 .then(onAddedToCascade.bind(this, newRule)); | 1640 .then(onAddedToCascade.bind(this, newRule)); |
| 1641 } | 1641 } |
| 1642 | 1642 |
| 1643 /** | 1643 /** |
| 1644 * @param {!WebInspector.CSSStyleRule} newRule | 1644 * @param {!SDK.CSSStyleRule} newRule |
| 1645 * @this {WebInspector.StylePropertiesSection} | 1645 * @this {Elements.StylePropertiesSection} |
| 1646 */ | 1646 */ |
| 1647 function onAddedToCascade(newRule) { | 1647 function onAddedToCascade(newRule) { |
| 1648 var doesSelectorAffectSelectedNode = this._matchedStyles.matchingSelectors
(newRule).length > 0; | 1648 var doesSelectorAffectSelectedNode = this._matchedStyles.matchingSelectors
(newRule).length > 0; |
| 1649 this._makeNormal(newRule); | 1649 this._makeNormal(newRule); |
| 1650 | 1650 |
| 1651 if (!doesSelectorAffectSelectedNode) | 1651 if (!doesSelectorAffectSelectedNode) |
| 1652 this.propertiesTreeOutline.element.classList.add('no-affect'); | 1652 this.propertiesTreeOutline.element.classList.add('no-affect'); |
| 1653 | 1653 |
| 1654 this._updateRuleOrigin(); | 1654 this._updateRuleOrigin(); |
| 1655 if (this.element.parentElement) // Might have been detached already. | 1655 if (this.element.parentElement) // Might have been detached already. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1679 if (!this.isBlank) { | 1679 if (!this.isBlank) { |
| 1680 super.editingSelectorCancelled(); | 1680 super.editingSelectorCancelled(); |
| 1681 return; | 1681 return; |
| 1682 } | 1682 } |
| 1683 | 1683 |
| 1684 this._editingSelectorEnded(); | 1684 this._editingSelectorEnded(); |
| 1685 this._parentPane.removeSection(this); | 1685 this._parentPane.removeSection(this); |
| 1686 } | 1686 } |
| 1687 | 1687 |
| 1688 /** | 1688 /** |
| 1689 * @param {!WebInspector.CSSRule} newRule | 1689 * @param {!SDK.CSSRule} newRule |
| 1690 */ | 1690 */ |
| 1691 _makeNormal(newRule) { | 1691 _makeNormal(newRule) { |
| 1692 this.element.classList.remove('blank-section'); | 1692 this.element.classList.remove('blank-section'); |
| 1693 this._style = newRule.style; | 1693 this._style = newRule.style; |
| 1694 // FIXME: replace this instance by a normal WebInspector.StylePropertiesSect
ion. | 1694 // FIXME: replace this instance by a normal Elements.StylePropertiesSection. |
| 1695 this._normal = true; | 1695 this._normal = true; |
| 1696 } | 1696 } |
| 1697 }; | 1697 }; |
| 1698 | 1698 |
| 1699 /** | 1699 /** |
| 1700 * @unrestricted | 1700 * @unrestricted |
| 1701 */ | 1701 */ |
| 1702 WebInspector.KeyframePropertiesSection = class extends WebInspector.StylePropert
iesSection { | 1702 Elements.KeyframePropertiesSection = class extends Elements.StylePropertiesSecti
on { |
| 1703 /** | 1703 /** |
| 1704 * @param {!WebInspector.StylesSidebarPane} stylesPane | 1704 * @param {!Elements.StylesSidebarPane} stylesPane |
| 1705 * @param {!WebInspector.CSSMatchedStyles} matchedStyles | 1705 * @param {!SDK.CSSMatchedStyles} matchedStyles |
| 1706 * @param {!WebInspector.CSSStyleDeclaration} style | 1706 * @param {!SDK.CSSStyleDeclaration} style |
| 1707 */ | 1707 */ |
| 1708 constructor(stylesPane, matchedStyles, style) { | 1708 constructor(stylesPane, matchedStyles, style) { |
| 1709 super(stylesPane, matchedStyles, style); | 1709 super(stylesPane, matchedStyles, style); |
| 1710 this._selectorElement.className = 'keyframe-key'; | 1710 this._selectorElement.className = 'keyframe-key'; |
| 1711 } | 1711 } |
| 1712 | 1712 |
| 1713 /** | 1713 /** |
| 1714 * @override | 1714 * @override |
| 1715 * @return {string} | 1715 * @return {string} |
| 1716 */ | 1716 */ |
| 1717 _headerText() { | 1717 _headerText() { |
| 1718 return this._style.parentRule.key().text; | 1718 return this._style.parentRule.key().text; |
| 1719 } | 1719 } |
| 1720 | 1720 |
| 1721 /** | 1721 /** |
| 1722 * @override | 1722 * @override |
| 1723 * @param {!WebInspector.CSSRule} rule | 1723 * @param {!SDK.CSSRule} rule |
| 1724 * @param {string} newContent | 1724 * @param {string} newContent |
| 1725 * @return {!Promise} | 1725 * @return {!Promise} |
| 1726 */ | 1726 */ |
| 1727 _setHeaderText(rule, newContent) { | 1727 _setHeaderText(rule, newContent) { |
| 1728 /** | 1728 /** |
| 1729 * @param {boolean} success | 1729 * @param {boolean} success |
| 1730 * @this {WebInspector.KeyframePropertiesSection} | 1730 * @this {Elements.KeyframePropertiesSection} |
| 1731 */ | 1731 */ |
| 1732 function updateSourceRanges(success) { | 1732 function updateSourceRanges(success) { |
| 1733 if (!success) | 1733 if (!success) |
| 1734 return; | 1734 return; |
| 1735 this._parentPane._refreshUpdate(this); | 1735 this._parentPane._refreshUpdate(this); |
| 1736 } | 1736 } |
| 1737 | 1737 |
| 1738 console.assert(rule instanceof WebInspector.CSSKeyframeRule); | 1738 console.assert(rule instanceof SDK.CSSKeyframeRule); |
| 1739 var oldRange = rule.key().range; | 1739 var oldRange = rule.key().range; |
| 1740 if (!oldRange) | 1740 if (!oldRange) |
| 1741 return Promise.resolve(); | 1741 return Promise.resolve(); |
| 1742 var selectedNode = this._parentPane.node(); | 1742 var selectedNode = this._parentPane.node(); |
| 1743 return rule.setKeyText(newContent).then(updateSourceRanges.bind(this)); | 1743 return rule.setKeyText(newContent).then(updateSourceRanges.bind(this)); |
| 1744 } | 1744 } |
| 1745 | 1745 |
| 1746 /** | 1746 /** |
| 1747 * @override | 1747 * @override |
| 1748 * @param {string} propertyName | 1748 * @param {string} propertyName |
| 1749 * @return {boolean} | 1749 * @return {boolean} |
| 1750 */ | 1750 */ |
| 1751 isPropertyInherited(propertyName) { | 1751 isPropertyInherited(propertyName) { |
| 1752 return false; | 1752 return false; |
| 1753 } | 1753 } |
| 1754 | 1754 |
| 1755 /** | 1755 /** |
| 1756 * @override | 1756 * @override |
| 1757 * @param {!WebInspector.CSSProperty} property | 1757 * @param {!SDK.CSSProperty} property |
| 1758 * @return {boolean} | 1758 * @return {boolean} |
| 1759 */ | 1759 */ |
| 1760 _isPropertyOverloaded(property) { | 1760 _isPropertyOverloaded(property) { |
| 1761 return false; | 1761 return false; |
| 1762 } | 1762 } |
| 1763 | 1763 |
| 1764 /** | 1764 /** |
| 1765 * @override | 1765 * @override |
| 1766 */ | 1766 */ |
| 1767 _markSelectorHighlights() { | 1767 _markSelectorHighlights() { |
| 1768 } | 1768 } |
| 1769 | 1769 |
| 1770 /** | 1770 /** |
| 1771 * @override | 1771 * @override |
| 1772 */ | 1772 */ |
| 1773 _markSelectorMatches() { | 1773 _markSelectorMatches() { |
| 1774 this._selectorElement.textContent = this._style.parentRule.key().text; | 1774 this._selectorElement.textContent = this._style.parentRule.key().text; |
| 1775 } | 1775 } |
| 1776 | 1776 |
| 1777 /** | 1777 /** |
| 1778 * @override | 1778 * @override |
| 1779 */ | 1779 */ |
| 1780 _highlight() { | 1780 _highlight() { |
| 1781 } | 1781 } |
| 1782 }; | 1782 }; |
| 1783 | 1783 |
| 1784 /** | 1784 /** |
| 1785 * @unrestricted | 1785 * @unrestricted |
| 1786 */ | 1786 */ |
| 1787 WebInspector.StylePropertyTreeElement = class extends TreeElement { | 1787 Elements.StylePropertyTreeElement = class extends TreeElement { |
| 1788 /** | 1788 /** |
| 1789 * @param {!WebInspector.StylesSidebarPane} stylesPane | 1789 * @param {!Elements.StylesSidebarPane} stylesPane |
| 1790 * @param {!WebInspector.CSSMatchedStyles} matchedStyles | 1790 * @param {!SDK.CSSMatchedStyles} matchedStyles |
| 1791 * @param {!WebInspector.CSSProperty} property | 1791 * @param {!SDK.CSSProperty} property |
| 1792 * @param {boolean} isShorthand | 1792 * @param {boolean} isShorthand |
| 1793 * @param {boolean} inherited | 1793 * @param {boolean} inherited |
| 1794 * @param {boolean} overloaded | 1794 * @param {boolean} overloaded |
| 1795 */ | 1795 */ |
| 1796 constructor(stylesPane, matchedStyles, property, isShorthand, inherited, overl
oaded) { | 1796 constructor(stylesPane, matchedStyles, property, isShorthand, inherited, overl
oaded) { |
| 1797 // Pass an empty title, the title gets made later in onattach. | 1797 // Pass an empty title, the title gets made later in onattach. |
| 1798 super('', isShorthand); | 1798 super('', isShorthand); |
| 1799 this._style = property.ownerStyle; | 1799 this._style = property.ownerStyle; |
| 1800 this._matchedStyles = matchedStyles; | 1800 this._matchedStyles = matchedStyles; |
| 1801 this.property = property; | 1801 this.property = property; |
| 1802 this._inherited = inherited; | 1802 this._inherited = inherited; |
| 1803 this._overloaded = overloaded; | 1803 this._overloaded = overloaded; |
| 1804 this.selectable = false; | 1804 this.selectable = false; |
| 1805 this._parentPane = stylesPane; | 1805 this._parentPane = stylesPane; |
| 1806 this.isShorthand = isShorthand; | 1806 this.isShorthand = isShorthand; |
| 1807 this._applyStyleThrottler = new WebInspector.Throttler(0); | 1807 this._applyStyleThrottler = new Common.Throttler(0); |
| 1808 } | 1808 } |
| 1809 | 1809 |
| 1810 /** | 1810 /** |
| 1811 * @return {boolean} | 1811 * @return {boolean} |
| 1812 */ | 1812 */ |
| 1813 _editable() { | 1813 _editable() { |
| 1814 return this._style.styleSheetId && this._style.range; | 1814 return this._style.styleSheetId && this._style.range; |
| 1815 } | 1815 } |
| 1816 | 1816 |
| 1817 /** | 1817 /** |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1872 } | 1872 } |
| 1873 return matches; | 1873 return matches; |
| 1874 } | 1874 } |
| 1875 | 1875 |
| 1876 /** | 1876 /** |
| 1877 * @param {string} text | 1877 * @param {string} text |
| 1878 * @return {!Node} | 1878 * @return {!Node} |
| 1879 */ | 1879 */ |
| 1880 _processColor(text) { | 1880 _processColor(text) { |
| 1881 // We can be called with valid non-color values of |text| (like 'none' from
border style) | 1881 // We can be called with valid non-color values of |text| (like 'none' from
border style) |
| 1882 var color = WebInspector.Color.parse(text); | 1882 var color = Common.Color.parse(text); |
| 1883 if (!color) | 1883 if (!color) |
| 1884 return createTextNode(text); | 1884 return createTextNode(text); |
| 1885 | 1885 |
| 1886 if (!this._editable()) { | 1886 if (!this._editable()) { |
| 1887 var swatch = WebInspector.ColorSwatch.create(); | 1887 var swatch = UI.ColorSwatch.create(); |
| 1888 swatch.setColor(color); | 1888 swatch.setColor(color); |
| 1889 return swatch; | 1889 return swatch; |
| 1890 } | 1890 } |
| 1891 | 1891 |
| 1892 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; | 1892 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; |
| 1893 var swatch = WebInspector.ColorSwatch.create(); | 1893 var swatch = UI.ColorSwatch.create(); |
| 1894 swatch.setColor(color); | 1894 swatch.setColor(color); |
| 1895 swatch.setFormat(WebInspector.Color.detectColorFormat(swatch.color())); | 1895 swatch.setFormat(Common.Color.detectColorFormat(swatch.color())); |
| 1896 var swatchIcon = new WebInspector.ColorSwatchPopoverIcon(this, swatchPopover
Helper, swatch); | 1896 var swatchIcon = new Elements.ColorSwatchPopoverIcon(this, swatchPopoverHelp
er, swatch); |
| 1897 | 1897 |
| 1898 /** | 1898 /** |
| 1899 * @param {?Array<string>} backgroundColors | 1899 * @param {?Array<string>} backgroundColors |
| 1900 */ | 1900 */ |
| 1901 function computedCallback(backgroundColors) { | 1901 function computedCallback(backgroundColors) { |
| 1902 // TODO(aboxhall): distinguish between !backgroundColors (no text) and | 1902 // TODO(aboxhall): distinguish between !backgroundColors (no text) and |
| 1903 // !backgroundColors.length (no computed bg color) | 1903 // !backgroundColors.length (no computed bg color) |
| 1904 if (!backgroundColors || !backgroundColors.length) | 1904 if (!backgroundColors || !backgroundColors.length) |
| 1905 return; | 1905 return; |
| 1906 // TODO(samli): figure out what to do in the case of multiple background c
olors (i.e. gradients) | 1906 // TODO(samli): figure out what to do in the case of multiple background c
olors (i.e. gradients) |
| 1907 var bgColorText = backgroundColors[0]; | 1907 var bgColorText = backgroundColors[0]; |
| 1908 var bgColor = WebInspector.Color.parse(bgColorText); | 1908 var bgColor = Common.Color.parse(bgColorText); |
| 1909 if (!bgColor) | 1909 if (!bgColor) |
| 1910 return; | 1910 return; |
| 1911 | 1911 |
| 1912 // If we have a semi-transparent background color over an unknown | 1912 // If we have a semi-transparent background color over an unknown |
| 1913 // background, draw the line for the "worst case" scenario: where | 1913 // background, draw the line for the "worst case" scenario: where |
| 1914 // the unknown background is the same color as the text. | 1914 // the unknown background is the same color as the text. |
| 1915 if (bgColor.hasAlpha) { | 1915 if (bgColor.hasAlpha) { |
| 1916 var blendedRGBA = []; | 1916 var blendedRGBA = []; |
| 1917 WebInspector.Color.blendColors(bgColor.rgba(), color.rgba(), blendedRGBA
); | 1917 Common.Color.blendColors(bgColor.rgba(), color.rgba(), blendedRGBA); |
| 1918 bgColor = new WebInspector.Color(blendedRGBA, WebInspector.Color.Format.
RGBA); | 1918 bgColor = new Common.Color(blendedRGBA, Common.Color.Format.RGBA); |
| 1919 } | 1919 } |
| 1920 | 1920 |
| 1921 swatchIcon.setContrastColor(bgColor); | 1921 swatchIcon.setContrastColor(bgColor); |
| 1922 } | 1922 } |
| 1923 | 1923 |
| 1924 if (Runtime.experiments.isEnabled('colorContrastRatio') && this.property.nam
e === 'color' && | 1924 if (Runtime.experiments.isEnabled('colorContrastRatio') && this.property.nam
e === 'color' && |
| 1925 this._parentPane.cssModel() && this.node()) { | 1925 this._parentPane.cssModel() && this.node()) { |
| 1926 var cssModel = this._parentPane.cssModel(); | 1926 var cssModel = this._parentPane.cssModel(); |
| 1927 cssModel.backgroundColorsPromise(this.node().id).then(computedCallback); | 1927 cssModel.backgroundColorsPromise(this.node().id).then(computedCallback); |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 return swatch; | 1930 return swatch; |
| 1931 } | 1931 } |
| 1932 | 1932 |
| 1933 /** | 1933 /** |
| 1934 * @return {string} | 1934 * @return {string} |
| 1935 */ | 1935 */ |
| 1936 renderedPropertyText() { | 1936 renderedPropertyText() { |
| 1937 return this.nameElement.textContent + ': ' + this.valueElement.textContent; | 1937 return this.nameElement.textContent + ': ' + this.valueElement.textContent; |
| 1938 } | 1938 } |
| 1939 | 1939 |
| 1940 /** | 1940 /** |
| 1941 * @param {string} text | 1941 * @param {string} text |
| 1942 * @return {!Node} | 1942 * @return {!Node} |
| 1943 */ | 1943 */ |
| 1944 _processBezier(text) { | 1944 _processBezier(text) { |
| 1945 if (!this._editable() || !WebInspector.Geometry.CubicBezier.parse(text)) | 1945 if (!this._editable() || !Common.Geometry.CubicBezier.parse(text)) |
| 1946 return createTextNode(text); | 1946 return createTextNode(text); |
| 1947 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; | 1947 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; |
| 1948 var swatch = WebInspector.BezierSwatch.create(); | 1948 var swatch = UI.BezierSwatch.create(); |
| 1949 swatch.setBezierText(text); | 1949 swatch.setBezierText(text); |
| 1950 new WebInspector.BezierPopoverIcon(this, swatchPopoverHelper, swatch); | 1950 new Elements.BezierPopoverIcon(this, swatchPopoverHelper, swatch); |
| 1951 return swatch; | 1951 return swatch; |
| 1952 } | 1952 } |
| 1953 | 1953 |
| 1954 /** | 1954 /** |
| 1955 * @param {string} propertyValue | 1955 * @param {string} propertyValue |
| 1956 * @param {string} propertyName | 1956 * @param {string} propertyName |
| 1957 * @return {!Node} | 1957 * @return {!Node} |
| 1958 */ | 1958 */ |
| 1959 _processShadow(propertyValue, propertyName) { | 1959 _processShadow(propertyValue, propertyName) { |
| 1960 if (!this._editable()) | 1960 if (!this._editable()) |
| 1961 return createTextNode(propertyValue); | 1961 return createTextNode(propertyValue); |
| 1962 var shadows; | 1962 var shadows; |
| 1963 if (propertyName === 'text-shadow') | 1963 if (propertyName === 'text-shadow') |
| 1964 shadows = WebInspector.CSSShadowModel.parseTextShadow(propertyValue); | 1964 shadows = Common.CSSShadowModel.parseTextShadow(propertyValue); |
| 1965 else | 1965 else |
| 1966 shadows = WebInspector.CSSShadowModel.parseBoxShadow(propertyValue); | 1966 shadows = Common.CSSShadowModel.parseBoxShadow(propertyValue); |
| 1967 if (!shadows.length) | 1967 if (!shadows.length) |
| 1968 return createTextNode(propertyValue); | 1968 return createTextNode(propertyValue); |
| 1969 var container = createDocumentFragment(); | 1969 var container = createDocumentFragment(); |
| 1970 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; | 1970 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; |
| 1971 for (var i = 0; i < shadows.length; i++) { | 1971 for (var i = 0; i < shadows.length; i++) { |
| 1972 if (i !== 0) | 1972 if (i !== 0) |
| 1973 container.appendChild(createTextNode(', ')); // Add back commas and spa
ces between each shadow. | 1973 container.appendChild(createTextNode(', ')); // Add back commas and spa
ces between each shadow. |
| 1974 // TODO(flandy): editing the property value should use the original value
with all spaces. | 1974 // TODO(flandy): editing the property value should use the original value
with all spaces. |
| 1975 var cssShadowSwatch = WebInspector.CSSShadowSwatch.create(); | 1975 var cssShadowSwatch = UI.CSSShadowSwatch.create(); |
| 1976 cssShadowSwatch.setCSSShadow(shadows[i]); | 1976 cssShadowSwatch.setCSSShadow(shadows[i]); |
| 1977 new WebInspector.ShadowSwatchPopoverHelper(this, swatchPopoverHelper, cssS
hadowSwatch); | 1977 new Elements.ShadowSwatchPopoverHelper(this, swatchPopoverHelper, cssShado
wSwatch); |
| 1978 var colorSwatch = cssShadowSwatch.colorSwatch(); | 1978 var colorSwatch = cssShadowSwatch.colorSwatch(); |
| 1979 if (colorSwatch) | 1979 if (colorSwatch) |
| 1980 new WebInspector.ColorSwatchPopoverIcon(this, swatchPopoverHelper, color
Swatch); | 1980 new Elements.ColorSwatchPopoverIcon(this, swatchPopoverHelper, colorSwat
ch); |
| 1981 container.appendChild(cssShadowSwatch); | 1981 container.appendChild(cssShadowSwatch); |
| 1982 } | 1982 } |
| 1983 return container; | 1983 return container; |
| 1984 } | 1984 } |
| 1985 | 1985 |
| 1986 _updateState() { | 1986 _updateState() { |
| 1987 if (!this.listItemElement) | 1987 if (!this.listItemElement) |
| 1988 return; | 1988 return; |
| 1989 | 1989 |
| 1990 if (this._style.isPropertyImplicit(this.name)) | 1990 if (this._style.isPropertyImplicit(this.name)) |
| 1991 this.listItemElement.classList.add('implicit'); | 1991 this.listItemElement.classList.add('implicit'); |
| 1992 else | 1992 else |
| 1993 this.listItemElement.classList.remove('implicit'); | 1993 this.listItemElement.classList.remove('implicit'); |
| 1994 | 1994 |
| 1995 var hasIgnorableError = | 1995 var hasIgnorableError = |
| 1996 !this.property.parsedOk && WebInspector.StylesSidebarPane.ignoreErrorsFo
rProperty(this.property); | 1996 !this.property.parsedOk && Elements.StylesSidebarPane.ignoreErrorsForPro
perty(this.property); |
| 1997 if (hasIgnorableError) | 1997 if (hasIgnorableError) |
| 1998 this.listItemElement.classList.add('has-ignorable-error'); | 1998 this.listItemElement.classList.add('has-ignorable-error'); |
| 1999 else | 1999 else |
| 2000 this.listItemElement.classList.remove('has-ignorable-error'); | 2000 this.listItemElement.classList.remove('has-ignorable-error'); |
| 2001 | 2001 |
| 2002 if (this.inherited()) | 2002 if (this.inherited()) |
| 2003 this.listItemElement.classList.add('inherited'); | 2003 this.listItemElement.classList.add('inherited'); |
| 2004 else | 2004 else |
| 2005 this.listItemElement.classList.remove('inherited'); | 2005 this.listItemElement.classList.remove('inherited'); |
| 2006 | 2006 |
| 2007 if (this.overloaded()) | 2007 if (this.overloaded()) |
| 2008 this.listItemElement.classList.add('overloaded'); | 2008 this.listItemElement.classList.add('overloaded'); |
| 2009 else | 2009 else |
| 2010 this.listItemElement.classList.remove('overloaded'); | 2010 this.listItemElement.classList.remove('overloaded'); |
| 2011 | 2011 |
| 2012 if (this.property.disabled) | 2012 if (this.property.disabled) |
| 2013 this.listItemElement.classList.add('disabled'); | 2013 this.listItemElement.classList.add('disabled'); |
| 2014 else | 2014 else |
| 2015 this.listItemElement.classList.remove('disabled'); | 2015 this.listItemElement.classList.remove('disabled'); |
| 2016 } | 2016 } |
| 2017 | 2017 |
| 2018 /** | 2018 /** |
| 2019 * @return {?WebInspector.DOMNode} | 2019 * @return {?SDK.DOMNode} |
| 2020 */ | 2020 */ |
| 2021 node() { | 2021 node() { |
| 2022 return this._parentPane.node(); | 2022 return this._parentPane.node(); |
| 2023 } | 2023 } |
| 2024 | 2024 |
| 2025 /** | 2025 /** |
| 2026 * @return {!WebInspector.StylesSidebarPane} | 2026 * @return {!Elements.StylesSidebarPane} |
| 2027 */ | 2027 */ |
| 2028 parentPane() { | 2028 parentPane() { |
| 2029 return this._parentPane; | 2029 return this._parentPane; |
| 2030 } | 2030 } |
| 2031 | 2031 |
| 2032 /** | 2032 /** |
| 2033 * @return {?WebInspector.StylePropertiesSection} | 2033 * @return {?Elements.StylePropertiesSection} |
| 2034 */ | 2034 */ |
| 2035 section() { | 2035 section() { |
| 2036 return this.treeOutline && this.treeOutline.section; | 2036 return this.treeOutline && this.treeOutline.section; |
| 2037 } | 2037 } |
| 2038 | 2038 |
| 2039 _updatePane() { | 2039 _updatePane() { |
| 2040 var section = this.section(); | 2040 var section = this.section(); |
| 2041 if (section && section._parentPane) | 2041 if (section && section._parentPane) |
| 2042 section._parentPane._refreshUpdate(section); | 2042 section._parentPane._refreshUpdate(section); |
| 2043 } | 2043 } |
| 2044 | 2044 |
| 2045 /** | 2045 /** |
| 2046 * @param {!Event} event | 2046 * @param {!Event} event |
| 2047 */ | 2047 */ |
| 2048 _toggleEnabled(event) { | 2048 _toggleEnabled(event) { |
| 2049 var disabled = !event.target.checked; | 2049 var disabled = !event.target.checked; |
| 2050 var oldStyleRange = this._style.range; | 2050 var oldStyleRange = this._style.range; |
| 2051 if (!oldStyleRange) | 2051 if (!oldStyleRange) |
| 2052 return; | 2052 return; |
| 2053 | 2053 |
| 2054 /** | 2054 /** |
| 2055 * @param {boolean} success | 2055 * @param {boolean} success |
| 2056 * @this {WebInspector.StylePropertyTreeElement} | 2056 * @this {Elements.StylePropertyTreeElement} |
| 2057 */ | 2057 */ |
| 2058 function callback(success) { | 2058 function callback(success) { |
| 2059 delete this._parentPane._userOperation; | 2059 delete this._parentPane._userOperation; |
| 2060 | 2060 |
| 2061 if (!success) | 2061 if (!success) |
| 2062 return; | 2062 return; |
| 2063 this._matchedStyles.resetActiveProperties(); | 2063 this._matchedStyles.resetActiveProperties(); |
| 2064 this._updatePane(); | 2064 this._updatePane(); |
| 2065 this.styleTextAppliedForTest(); | 2065 this.styleTextAppliedForTest(); |
| 2066 } | 2066 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2081 var longhandProperties = this._style.longhandProperties(this.name); | 2081 var longhandProperties = this._style.longhandProperties(this.name); |
| 2082 for (var i = 0; i < longhandProperties.length; ++i) { | 2082 for (var i = 0; i < longhandProperties.length; ++i) { |
| 2083 var name = longhandProperties[i].name; | 2083 var name = longhandProperties[i].name; |
| 2084 var inherited = false; | 2084 var inherited = false; |
| 2085 var overloaded = false; | 2085 var overloaded = false; |
| 2086 | 2086 |
| 2087 var section = this.section(); | 2087 var section = this.section(); |
| 2088 if (section) { | 2088 if (section) { |
| 2089 inherited = section.isPropertyInherited(name); | 2089 inherited = section.isPropertyInherited(name); |
| 2090 overloaded = this._matchedStyles.propertyState(longhandProperties[i]) ==
= | 2090 overloaded = this._matchedStyles.propertyState(longhandProperties[i]) ==
= |
| 2091 WebInspector.CSSMatchedStyles.PropertyState.Overloaded; | 2091 SDK.CSSMatchedStyles.PropertyState.Overloaded; |
| 2092 } | 2092 } |
| 2093 | 2093 |
| 2094 var item = new WebInspector.StylePropertyTreeElement( | 2094 var item = new Elements.StylePropertyTreeElement( |
| 2095 this._parentPane, this._matchedStyles, longhandProperties[i], false, i
nherited, overloaded); | 2095 this._parentPane, this._matchedStyles, longhandProperties[i], false, i
nherited, overloaded); |
| 2096 this.appendChild(item); | 2096 this.appendChild(item); |
| 2097 } | 2097 } |
| 2098 } | 2098 } |
| 2099 | 2099 |
| 2100 /** | 2100 /** |
| 2101 * @override | 2101 * @override |
| 2102 */ | 2102 */ |
| 2103 onattach() { | 2103 onattach() { |
| 2104 this.updateTitle(); | 2104 this.updateTitle(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2128 delete this._parentPane._mouseDownTreeElementIsValue; | 2128 delete this._parentPane._mouseDownTreeElementIsValue; |
| 2129 } | 2129 } |
| 2130 } | 2130 } |
| 2131 | 2131 |
| 2132 updateTitle() { | 2132 updateTitle() { |
| 2133 this._updateState(); | 2133 this._updateState(); |
| 2134 this._expandElement = createElement('span'); | 2134 this._expandElement = createElement('span'); |
| 2135 this._expandElement.className = 'expand-element'; | 2135 this._expandElement.className = 'expand-element'; |
| 2136 | 2136 |
| 2137 var propertyRenderer = | 2137 var propertyRenderer = |
| 2138 new WebInspector.StylesSidebarPropertyRenderer(this._style.parentRule, t
his.node(), this.name, this.value); | 2138 new Elements.StylesSidebarPropertyRenderer(this._style.parentRule, this.
node(), this.name, this.value); |
| 2139 if (this.property.parsedOk) { | 2139 if (this.property.parsedOk) { |
| 2140 propertyRenderer.setColorHandler(this._processColor.bind(this)); | 2140 propertyRenderer.setColorHandler(this._processColor.bind(this)); |
| 2141 propertyRenderer.setBezierHandler(this._processBezier.bind(this)); | 2141 propertyRenderer.setBezierHandler(this._processBezier.bind(this)); |
| 2142 propertyRenderer.setShadowHandler(this._processShadow.bind(this)); | 2142 propertyRenderer.setShadowHandler(this._processShadow.bind(this)); |
| 2143 } | 2143 } |
| 2144 | 2144 |
| 2145 this.listItemElement.removeChildren(); | 2145 this.listItemElement.removeChildren(); |
| 2146 this.nameElement = propertyRenderer.renderName(); | 2146 this.nameElement = propertyRenderer.renderName(); |
| 2147 this.valueElement = propertyRenderer.renderValue(); | 2147 this.valueElement = propertyRenderer.renderValue(); |
| 2148 if (!this.treeOutline) | 2148 if (!this.treeOutline) |
| 2149 return; | 2149 return; |
| 2150 | 2150 |
| 2151 var indent = WebInspector.moduleSetting('textEditorIndent').get(); | 2151 var indent = Common.moduleSetting('textEditorIndent').get(); |
| 2152 this.listItemElement.createChild('span', 'styles-clipboard-only') | 2152 this.listItemElement.createChild('span', 'styles-clipboard-only') |
| 2153 .createTextChild(indent + (this.property.disabled ? '/* ' : '')); | 2153 .createTextChild(indent + (this.property.disabled ? '/* ' : '')); |
| 2154 this.listItemElement.appendChild(this.nameElement); | 2154 this.listItemElement.appendChild(this.nameElement); |
| 2155 this.listItemElement.createTextChild(': '); | 2155 this.listItemElement.createTextChild(': '); |
| 2156 this.listItemElement.appendChild(this._expandElement); | 2156 this.listItemElement.appendChild(this._expandElement); |
| 2157 this.listItemElement.appendChild(this.valueElement); | 2157 this.listItemElement.appendChild(this.valueElement); |
| 2158 this.listItemElement.createTextChild(';'); | 2158 this.listItemElement.createTextChild(';'); |
| 2159 if (this.property.disabled) | 2159 if (this.property.disabled) |
| 2160 this.listItemElement.createChild('span', 'styles-clipboard-only').createTe
xtChild(' */'); | 2160 this.listItemElement.createChild('span', 'styles-clipboard-only').createTe
xtChild(' */'); |
| 2161 | 2161 |
| 2162 if (!this.property.parsedOk) { | 2162 if (!this.property.parsedOk) { |
| 2163 // Avoid having longhands under an invalid shorthand. | 2163 // Avoid having longhands under an invalid shorthand. |
| 2164 this.listItemElement.classList.add('not-parsed-ok'); | 2164 this.listItemElement.classList.add('not-parsed-ok'); |
| 2165 | 2165 |
| 2166 // Add a separate exclamation mark IMG element with a tooltip. | 2166 // Add a separate exclamation mark IMG element with a tooltip. |
| 2167 this.listItemElement.insertBefore( | 2167 this.listItemElement.insertBefore( |
| 2168 WebInspector.StylesSidebarPane.createExclamationMark(this.property), t
his.listItemElement.firstChild); | 2168 Elements.StylesSidebarPane.createExclamationMark(this.property), this.
listItemElement.firstChild); |
| 2169 } | 2169 } |
| 2170 if (!this.property.activeInStyle()) | 2170 if (!this.property.activeInStyle()) |
| 2171 this.listItemElement.classList.add('inactive'); | 2171 this.listItemElement.classList.add('inactive'); |
| 2172 this._updateFilter(); | 2172 this._updateFilter(); |
| 2173 | 2173 |
| 2174 if (this.property.parsedOk && this.section() && this.parent.root) { | 2174 if (this.property.parsedOk && this.section() && this.parent.root) { |
| 2175 var enabledCheckboxElement = createElement('input'); | 2175 var enabledCheckboxElement = createElement('input'); |
| 2176 enabledCheckboxElement.className = 'enabled-button'; | 2176 enabledCheckboxElement.className = 'enabled-button'; |
| 2177 enabledCheckboxElement.type = 'checkbox'; | 2177 enabledCheckboxElement.type = 'checkbox'; |
| 2178 enabledCheckboxElement.checked = !this.property.disabled; | 2178 enabledCheckboxElement.checked = !this.property.disabled; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2194 var section = this.section(); | 2194 var section = this.section(); |
| 2195 if (!section || !section.editable) | 2195 if (!section || !section.editable) |
| 2196 return; | 2196 return; |
| 2197 | 2197 |
| 2198 if (section._checkWillCancelEditing()) | 2198 if (section._checkWillCancelEditing()) |
| 2199 return; | 2199 return; |
| 2200 section.addNewBlankProperty(this.property.index + 1).startEditing(); | 2200 section.addNewBlankProperty(this.property.index + 1).startEditing(); |
| 2201 return; | 2201 return; |
| 2202 } | 2202 } |
| 2203 | 2203 |
| 2204 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEvent}
*/ (event)) && | 2204 if (UI.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEvent} */ (event
)) && |
| 2205 this.section().navigable) { | 2205 this.section().navigable) { |
| 2206 this._navigateToSource(/** @type {!Element} */ (event.target)); | 2206 this._navigateToSource(/** @type {!Element} */ (event.target)); |
| 2207 return; | 2207 return; |
| 2208 } | 2208 } |
| 2209 | 2209 |
| 2210 this.startEditing(/** @type {!Element} */ (event.target)); | 2210 this.startEditing(/** @type {!Element} */ (event.target)); |
| 2211 } | 2211 } |
| 2212 | 2212 |
| 2213 /** | 2213 /** |
| 2214 * @param {!Element} element | 2214 * @param {!Element} element |
| 2215 * @param {boolean=} omitFocus | 2215 * @param {boolean=} omitFocus |
| 2216 */ | 2216 */ |
| 2217 _navigateToSource(element, omitFocus) { | 2217 _navigateToSource(element, omitFocus) { |
| 2218 if (!this.section().navigable) | 2218 if (!this.section().navigable) |
| 2219 return; | 2219 return; |
| 2220 var propertyNameClicked = element === this.nameElement; | 2220 var propertyNameClicked = element === this.nameElement; |
| 2221 var uiLocation = WebInspector.cssWorkspaceBinding.propertyUILocation(this.pr
operty, propertyNameClicked); | 2221 var uiLocation = Bindings.cssWorkspaceBinding.propertyUILocation(this.proper
ty, propertyNameClicked); |
| 2222 if (uiLocation) | 2222 if (uiLocation) |
| 2223 WebInspector.Revealer.reveal(uiLocation, omitFocus); | 2223 Common.Revealer.reveal(uiLocation, omitFocus); |
| 2224 } | 2224 } |
| 2225 | 2225 |
| 2226 /** | 2226 /** |
| 2227 * @param {?Element=} selectElement | 2227 * @param {?Element=} selectElement |
| 2228 */ | 2228 */ |
| 2229 startEditing(selectElement) { | 2229 startEditing(selectElement) { |
| 2230 // FIXME: we don't allow editing of longhand properties under a shorthand ri
ght now. | 2230 // FIXME: we don't allow editing of longhand properties under a shorthand ri
ght now. |
| 2231 if (this.parent.isShorthand) | 2231 if (this.parent.isShorthand) |
| 2232 return; | 2232 return; |
| 2233 | 2233 |
| 2234 if (selectElement === this._expandElement) | 2234 if (selectElement === this._expandElement) |
| 2235 return; | 2235 return; |
| 2236 | 2236 |
| 2237 var section = this.section(); | 2237 var section = this.section(); |
| 2238 if (section && !section.editable) | 2238 if (section && !section.editable) |
| 2239 return; | 2239 return; |
| 2240 | 2240 |
| 2241 if (selectElement) | 2241 if (selectElement) |
| 2242 selectElement = selectElement.enclosingNodeOrSelfWithClass('webkit-css-pro
perty') || | 2242 selectElement = selectElement.enclosingNodeOrSelfWithClass('webkit-css-pro
perty') || |
| 2243 selectElement.enclosingNodeOrSelfWithClass('value'); | 2243 selectElement.enclosingNodeOrSelfWithClass('value'); |
| 2244 if (!selectElement) | 2244 if (!selectElement) |
| 2245 selectElement = this.nameElement; | 2245 selectElement = this.nameElement; |
| 2246 | 2246 |
| 2247 if (WebInspector.isBeingEdited(selectElement)) | 2247 if (UI.isBeingEdited(selectElement)) |
| 2248 return; | 2248 return; |
| 2249 | 2249 |
| 2250 var isEditingName = selectElement === this.nameElement; | 2250 var isEditingName = selectElement === this.nameElement; |
| 2251 if (!isEditingName) | 2251 if (!isEditingName) |
| 2252 this.valueElement.textContent = restoreURLs(this.valueElement.textContent,
this.value); | 2252 this.valueElement.textContent = restoreURLs(this.valueElement.textContent,
this.value); |
| 2253 | 2253 |
| 2254 /** | 2254 /** |
| 2255 * @param {string} fieldValue | 2255 * @param {string} fieldValue |
| 2256 * @param {string} modelValue | 2256 * @param {string} modelValue |
| 2257 * @return {string} | 2257 * @return {string} |
| 2258 */ | 2258 */ |
| 2259 function restoreURLs(fieldValue, modelValue) { | 2259 function restoreURLs(fieldValue, modelValue) { |
| 2260 const urlRegex = /\b(url\([^)]*\))/g; | 2260 const urlRegex = /\b(url\([^)]*\))/g; |
| 2261 var splitFieldValue = fieldValue.split(urlRegex); | 2261 var splitFieldValue = fieldValue.split(urlRegex); |
| 2262 if (splitFieldValue.length === 1) | 2262 if (splitFieldValue.length === 1) |
| 2263 return fieldValue; | 2263 return fieldValue; |
| 2264 var modelUrlRegex = new RegExp(urlRegex); | 2264 var modelUrlRegex = new RegExp(urlRegex); |
| 2265 for (var i = 1; i < splitFieldValue.length; i += 2) { | 2265 for (var i = 1; i < splitFieldValue.length; i += 2) { |
| 2266 var match = modelUrlRegex.exec(modelValue); | 2266 var match = modelUrlRegex.exec(modelValue); |
| 2267 if (match) | 2267 if (match) |
| 2268 splitFieldValue[i] = match[0]; | 2268 splitFieldValue[i] = match[0]; |
| 2269 } | 2269 } |
| 2270 return splitFieldValue.join(''); | 2270 return splitFieldValue.join(''); |
| 2271 } | 2271 } |
| 2272 | 2272 |
| 2273 /** @type {!WebInspector.StylePropertyTreeElement.Context} */ | 2273 /** @type {!Elements.StylePropertyTreeElement.Context} */ |
| 2274 var context = { | 2274 var context = { |
| 2275 expanded: this.expanded, | 2275 expanded: this.expanded, |
| 2276 hasChildren: this.isExpandable(), | 2276 hasChildren: this.isExpandable(), |
| 2277 isEditingName: isEditingName, | 2277 isEditingName: isEditingName, |
| 2278 previousContent: selectElement.textContent | 2278 previousContent: selectElement.textContent |
| 2279 }; | 2279 }; |
| 2280 | 2280 |
| 2281 // Lie about our children to prevent expanding on double click and to collap
se shorthands. | 2281 // Lie about our children to prevent expanding on double click and to collap
se shorthands. |
| 2282 this.setExpandable(false); | 2282 this.setExpandable(false); |
| 2283 | 2283 |
| 2284 if (selectElement.parentElement) | 2284 if (selectElement.parentElement) |
| 2285 selectElement.parentElement.classList.add('child-editing'); | 2285 selectElement.parentElement.classList.add('child-editing'); |
| 2286 selectElement.textContent = selectElement.textContent; // remove color swat
ch and the like | 2286 selectElement.textContent = selectElement.textContent; // remove color swat
ch and the like |
| 2287 | 2287 |
| 2288 /** | 2288 /** |
| 2289 * @param {!WebInspector.StylePropertyTreeElement.Context} context | 2289 * @param {!Elements.StylePropertyTreeElement.Context} context |
| 2290 * @param {!Event} event | 2290 * @param {!Event} event |
| 2291 * @this {WebInspector.StylePropertyTreeElement} | 2291 * @this {Elements.StylePropertyTreeElement} |
| 2292 */ | 2292 */ |
| 2293 function pasteHandler(context, event) { | 2293 function pasteHandler(context, event) { |
| 2294 var data = event.clipboardData.getData('Text'); | 2294 var data = event.clipboardData.getData('Text'); |
| 2295 if (!data) | 2295 if (!data) |
| 2296 return; | 2296 return; |
| 2297 var colonIdx = data.indexOf(':'); | 2297 var colonIdx = data.indexOf(':'); |
| 2298 if (colonIdx < 0) | 2298 if (colonIdx < 0) |
| 2299 return; | 2299 return; |
| 2300 var name = data.substring(0, colonIdx).trim(); | 2300 var name = data.substring(0, colonIdx).trim(); |
| 2301 var value = data.substring(colonIdx + 1).trim(); | 2301 var value = data.substring(colonIdx + 1).trim(); |
| 2302 | 2302 |
| 2303 event.preventDefault(); | 2303 event.preventDefault(); |
| 2304 | 2304 |
| 2305 if (!('originalName' in context)) { | 2305 if (!('originalName' in context)) { |
| 2306 context.originalName = this.nameElement.textContent; | 2306 context.originalName = this.nameElement.textContent; |
| 2307 context.originalValue = this.valueElement.textContent; | 2307 context.originalValue = this.valueElement.textContent; |
| 2308 } | 2308 } |
| 2309 this.property.name = name; | 2309 this.property.name = name; |
| 2310 this.property.value = value; | 2310 this.property.value = value; |
| 2311 this.nameElement.textContent = name; | 2311 this.nameElement.textContent = name; |
| 2312 this.valueElement.textContent = value; | 2312 this.valueElement.textContent = value; |
| 2313 this.nameElement.normalize(); | 2313 this.nameElement.normalize(); |
| 2314 this.valueElement.normalize(); | 2314 this.valueElement.normalize(); |
| 2315 | 2315 |
| 2316 this._editingCommitted(event.target.textContent, context, 'forward'); | 2316 this._editingCommitted(event.target.textContent, context, 'forward'); |
| 2317 } | 2317 } |
| 2318 | 2318 |
| 2319 /** | 2319 /** |
| 2320 * @param {!WebInspector.StylePropertyTreeElement.Context} context | 2320 * @param {!Elements.StylePropertyTreeElement.Context} context |
| 2321 * @param {!Event} event | 2321 * @param {!Event} event |
| 2322 * @this {WebInspector.StylePropertyTreeElement} | 2322 * @this {Elements.StylePropertyTreeElement} |
| 2323 */ | 2323 */ |
| 2324 function blurListener(context, event) { | 2324 function blurListener(context, event) { |
| 2325 var treeElement = this._parentPane._mouseDownTreeElement; | 2325 var treeElement = this._parentPane._mouseDownTreeElement; |
| 2326 var moveDirection = ''; | 2326 var moveDirection = ''; |
| 2327 if (treeElement === this) { | 2327 if (treeElement === this) { |
| 2328 if (isEditingName && this._parentPane._mouseDownTreeElementIsValue) | 2328 if (isEditingName && this._parentPane._mouseDownTreeElementIsValue) |
| 2329 moveDirection = 'forward'; | 2329 moveDirection = 'forward'; |
| 2330 if (!isEditingName && this._parentPane._mouseDownTreeElementIsName) | 2330 if (!isEditingName && this._parentPane._mouseDownTreeElementIsName) |
| 2331 moveDirection = 'backward'; | 2331 moveDirection = 'backward'; |
| 2332 } | 2332 } |
| 2333 var text = event.target.textContent; | 2333 var text = event.target.textContent; |
| 2334 if (!context.isEditingName) | 2334 if (!context.isEditingName) |
| 2335 text = this.value || text; | 2335 text = this.value || text; |
| 2336 this._editingCommitted(text, context, moveDirection); | 2336 this._editingCommitted(text, context, moveDirection); |
| 2337 } | 2337 } |
| 2338 | 2338 |
| 2339 this._originalPropertyText = this.property.propertyText; | 2339 this._originalPropertyText = this.property.propertyText; |
| 2340 | 2340 |
| 2341 this._parentPane.setEditingStyle(true); | 2341 this._parentPane.setEditingStyle(true); |
| 2342 if (selectElement.parentElement) | 2342 if (selectElement.parentElement) |
| 2343 selectElement.parentElement.scrollIntoViewIfNeeded(false); | 2343 selectElement.parentElement.scrollIntoViewIfNeeded(false); |
| 2344 | 2344 |
| 2345 var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdit.bi
nd(this) : undefined; | 2345 var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdit.bi
nd(this) : undefined; |
| 2346 var cssCompletions = isEditingName ? WebInspector.cssMetadata().allPropertie
s() : | 2346 var cssCompletions = isEditingName ? SDK.cssMetadata().allProperties() : |
| 2347 WebInspector.cssMetadata().propertyValu
es(this.nameElement.textContent); | 2347 SDK.cssMetadata().propertyValues(this.n
ameElement.textContent); |
| 2348 this._prompt = new WebInspector.StylesSidebarPane.CSSPropertyPrompt(cssCompl
etions, this, isEditingName); | 2348 this._prompt = new Elements.StylesSidebarPane.CSSPropertyPrompt(cssCompletio
ns, this, isEditingName); |
| 2349 this._prompt.setAutocompletionTimeout(0); | 2349 this._prompt.setAutocompletionTimeout(0); |
| 2350 if (applyItemCallback) { | 2350 if (applyItemCallback) { |
| 2351 this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemApplied,
applyItemCallback, this); | 2351 this._prompt.addEventListener(UI.TextPrompt.Events.ItemApplied, applyItemC
allback, this); |
| 2352 this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemAccepted,
applyItemCallback, this); | 2352 this._prompt.addEventListener(UI.TextPrompt.Events.ItemAccepted, applyItem
Callback, this); |
| 2353 } | 2353 } |
| 2354 var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurLis
tener.bind(this, context)); | 2354 var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurLis
tener.bind(this, context)); |
| 2355 this._navigateToSource(selectElement, true); | 2355 this._navigateToSource(selectElement, true); |
| 2356 | 2356 |
| 2357 proxyElement.addEventListener('keydown', this._editingNameValueKeyDown.bind(
this, context), false); | 2357 proxyElement.addEventListener('keydown', this._editingNameValueKeyDown.bind(
this, context), false); |
| 2358 proxyElement.addEventListener('keypress', this._editingNameValueKeyPress.bin
d(this, context), false); | 2358 proxyElement.addEventListener('keypress', this._editingNameValueKeyPress.bin
d(this, context), false); |
| 2359 proxyElement.addEventListener('input', this._editingNameValueInput.bind(this
, context), false); | 2359 proxyElement.addEventListener('input', this._editingNameValueInput.bind(this
, context), false); |
| 2360 if (isEditingName) | 2360 if (isEditingName) |
| 2361 proxyElement.addEventListener('paste', pasteHandler.bind(this, context), f
alse); | 2361 proxyElement.addEventListener('paste', pasteHandler.bind(this, context), f
alse); |
| 2362 | 2362 |
| 2363 selectElement.getComponentSelection().setBaseAndExtent(selectElement, 0, sel
ectElement, 1); | 2363 selectElement.getComponentSelection().setBaseAndExtent(selectElement, 0, sel
ectElement, 1); |
| 2364 } | 2364 } |
| 2365 | 2365 |
| 2366 /** | 2366 /** |
| 2367 * @param {!WebInspector.StylePropertyTreeElement.Context} context | 2367 * @param {!Elements.StylePropertyTreeElement.Context} context |
| 2368 * @param {!Event} event | 2368 * @param {!Event} event |
| 2369 */ | 2369 */ |
| 2370 _editingNameValueKeyDown(context, event) { | 2370 _editingNameValueKeyDown(context, event) { |
| 2371 if (event.handled) | 2371 if (event.handled) |
| 2372 return; | 2372 return; |
| 2373 | 2373 |
| 2374 var result; | 2374 var result; |
| 2375 | 2375 |
| 2376 if (isEnterKey(event)) { | 2376 if (isEnterKey(event)) { |
| 2377 event.preventDefault(); | 2377 event.preventDefault(); |
| 2378 result = 'forward'; | 2378 result = 'forward'; |
| 2379 } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code ||
event.key === 'Escape') | 2379 } else if (event.keyCode === UI.KeyboardShortcut.Keys.Esc.code || event.key
=== 'Escape') |
| 2380 result = 'cancel'; | 2380 result = 'cancel'; |
| 2381 else if ( | 2381 else if ( |
| 2382 !context.isEditingName && this._newProperty && | 2382 !context.isEditingName && this._newProperty && |
| 2383 event.keyCode === WebInspector.KeyboardShortcut.Keys.Backspace.code) { | 2383 event.keyCode === UI.KeyboardShortcut.Keys.Backspace.code) { |
| 2384 // For a new property, when Backspace is pressed at the beginning of new p
roperty value, move back to the property name. | 2384 // For a new property, when Backspace is pressed at the beginning of new p
roperty value, move back to the property name. |
| 2385 var selection = event.target.getComponentSelection(); | 2385 var selection = event.target.getComponentSelection(); |
| 2386 if (selection.isCollapsed && !selection.focusOffset) { | 2386 if (selection.isCollapsed && !selection.focusOffset) { |
| 2387 event.preventDefault(); | 2387 event.preventDefault(); |
| 2388 result = 'backward'; | 2388 result = 'backward'; |
| 2389 } | 2389 } |
| 2390 } else if (event.key === 'Tab') { | 2390 } else if (event.key === 'Tab') { |
| 2391 result = event.shiftKey ? 'backward' : 'forward'; | 2391 result = event.shiftKey ? 'backward' : 'forward'; |
| 2392 event.preventDefault(); | 2392 event.preventDefault(); |
| 2393 } | 2393 } |
| 2394 | 2394 |
| 2395 if (result) { | 2395 if (result) { |
| 2396 switch (result) { | 2396 switch (result) { |
| 2397 case 'cancel': | 2397 case 'cancel': |
| 2398 this.editingCancelled(null, context); | 2398 this.editingCancelled(null, context); |
| 2399 break; | 2399 break; |
| 2400 case 'forward': | 2400 case 'forward': |
| 2401 case 'backward': | 2401 case 'backward': |
| 2402 this._editingCommitted(event.target.textContent, context, result); | 2402 this._editingCommitted(event.target.textContent, context, result); |
| 2403 break; | 2403 break; |
| 2404 } | 2404 } |
| 2405 | 2405 |
| 2406 event.consume(); | 2406 event.consume(); |
| 2407 return; | 2407 return; |
| 2408 } | 2408 } |
| 2409 } | 2409 } |
| 2410 | 2410 |
| 2411 /** | 2411 /** |
| 2412 * @param {!WebInspector.StylePropertyTreeElement.Context} context | 2412 * @param {!Elements.StylePropertyTreeElement.Context} context |
| 2413 * @param {!Event} event | 2413 * @param {!Event} event |
| 2414 */ | 2414 */ |
| 2415 _editingNameValueKeyPress(context, event) { | 2415 _editingNameValueKeyPress(context, event) { |
| 2416 /** | 2416 /** |
| 2417 * @param {string} text | 2417 * @param {string} text |
| 2418 * @param {number} cursorPosition | 2418 * @param {number} cursorPosition |
| 2419 * @return {boolean} | 2419 * @return {boolean} |
| 2420 */ | 2420 */ |
| 2421 function shouldCommitValueSemicolon(text, cursorPosition) { | 2421 function shouldCommitValueSemicolon(text, cursorPosition) { |
| 2422 // FIXME: should this account for semicolons inside comments? | 2422 // FIXME: should this account for semicolons inside comments? |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2440 shouldCommitValueSemicolon(event.target.textContent, event.targ
et.selectionLeftOffset())); | 2440 shouldCommitValueSemicolon(event.target.textContent, event.targ
et.selectionLeftOffset())); |
| 2441 if (isFieldInputTerminated) { | 2441 if (isFieldInputTerminated) { |
| 2442 // Enter or colon (for name)/semicolon outside of string (for value). | 2442 // Enter or colon (for name)/semicolon outside of string (for value). |
| 2443 event.consume(true); | 2443 event.consume(true); |
| 2444 this._editingCommitted(event.target.textContent, context, 'forward'); | 2444 this._editingCommitted(event.target.textContent, context, 'forward'); |
| 2445 return; | 2445 return; |
| 2446 } | 2446 } |
| 2447 } | 2447 } |
| 2448 | 2448 |
| 2449 /** | 2449 /** |
| 2450 * @param {!WebInspector.StylePropertyTreeElement.Context} context | 2450 * @param {!Elements.StylePropertyTreeElement.Context} context |
| 2451 * @param {!Event} event | 2451 * @param {!Event} event |
| 2452 */ | 2452 */ |
| 2453 _editingNameValueInput(context, event) { | 2453 _editingNameValueInput(context, event) { |
| 2454 // Do not live-edit "content" property of pseudo elements. crbug.com/433889 | 2454 // Do not live-edit "content" property of pseudo elements. crbug.com/433889 |
| 2455 if (!context.isEditingName && (!this._parentPane.node().pseudoType() || this
.name !== 'content')) | 2455 if (!context.isEditingName && (!this._parentPane.node().pseudoType() || this
.name !== 'content')) |
| 2456 this._applyFreeFlowStyleTextEdit(); | 2456 this._applyFreeFlowStyleTextEdit(); |
| 2457 } | 2457 } |
| 2458 | 2458 |
| 2459 _applyFreeFlowStyleTextEdit() { | 2459 _applyFreeFlowStyleTextEdit() { |
| 2460 var valueText = this._prompt.textWithCurrentSuggestion(); | 2460 var valueText = this._prompt.textWithCurrentSuggestion(); |
| 2461 if (valueText.indexOf(';') === -1) | 2461 if (valueText.indexOf(';') === -1) |
| 2462 this.applyStyleText(this.nameElement.textContent + ': ' + valueText, false
); | 2462 this.applyStyleText(this.nameElement.textContent + ': ' + valueText, false
); |
| 2463 } | 2463 } |
| 2464 | 2464 |
| 2465 kickFreeFlowStyleEditForTest() { | 2465 kickFreeFlowStyleEditForTest() { |
| 2466 this._applyFreeFlowStyleTextEdit(); | 2466 this._applyFreeFlowStyleTextEdit(); |
| 2467 } | 2467 } |
| 2468 | 2468 |
| 2469 /** | 2469 /** |
| 2470 * @param {!WebInspector.StylePropertyTreeElement.Context} context | 2470 * @param {!Elements.StylePropertyTreeElement.Context} context |
| 2471 */ | 2471 */ |
| 2472 editingEnded(context) { | 2472 editingEnded(context) { |
| 2473 this._resetMouseDownElement(); | 2473 this._resetMouseDownElement(); |
| 2474 | 2474 |
| 2475 this.setExpandable(context.hasChildren); | 2475 this.setExpandable(context.hasChildren); |
| 2476 if (context.expanded) | 2476 if (context.expanded) |
| 2477 this.expand(); | 2477 this.expand(); |
| 2478 var editedElement = context.isEditingName ? this.nameElement : this.valueEle
ment; | 2478 var editedElement = context.isEditingName ? this.nameElement : this.valueEle
ment; |
| 2479 // The proxyElement has been deleted, no need to remove listener. | 2479 // The proxyElement has been deleted, no need to remove listener. |
| 2480 if (editedElement.parentElement) | 2480 if (editedElement.parentElement) |
| 2481 editedElement.parentElement.classList.remove('child-editing'); | 2481 editedElement.parentElement.classList.remove('child-editing'); |
| 2482 | 2482 |
| 2483 this._parentPane.setEditingStyle(false); | 2483 this._parentPane.setEditingStyle(false); |
| 2484 } | 2484 } |
| 2485 | 2485 |
| 2486 /** | 2486 /** |
| 2487 * @param {?Element} element | 2487 * @param {?Element} element |
| 2488 * @param {!WebInspector.StylePropertyTreeElement.Context} context | 2488 * @param {!Elements.StylePropertyTreeElement.Context} context |
| 2489 */ | 2489 */ |
| 2490 editingCancelled(element, context) { | 2490 editingCancelled(element, context) { |
| 2491 this._removePrompt(); | 2491 this._removePrompt(); |
| 2492 this._revertStyleUponEditingCanceled(); | 2492 this._revertStyleUponEditingCanceled(); |
| 2493 // This should happen last, as it clears the info necessary to restore the p
roperty value after [Page]Up/Down changes. | 2493 // This should happen last, as it clears the info necessary to restore the p
roperty value after [Page]Up/Down changes. |
| 2494 this.editingEnded(context); | 2494 this.editingEnded(context); |
| 2495 } | 2495 } |
| 2496 | 2496 |
| 2497 _revertStyleUponEditingCanceled() { | 2497 _revertStyleUponEditingCanceled() { |
| 2498 if (this._propertyHasBeenEditedIncrementally) { | 2498 if (this._propertyHasBeenEditedIncrementally) { |
| 2499 this.applyStyleText(this._originalPropertyText, false); | 2499 this.applyStyleText(this._originalPropertyText, false); |
| 2500 delete this._originalPropertyText; | 2500 delete this._originalPropertyText; |
| 2501 } else if (this._newProperty) { | 2501 } else if (this._newProperty) { |
| 2502 this.treeOutline.removeChild(this); | 2502 this.treeOutline.removeChild(this); |
| 2503 } else { | 2503 } else { |
| 2504 this.updateTitle(); | 2504 this.updateTitle(); |
| 2505 } | 2505 } |
| 2506 } | 2506 } |
| 2507 | 2507 |
| 2508 /** | 2508 /** |
| 2509 * @param {string} moveDirection | 2509 * @param {string} moveDirection |
| 2510 * @return {?WebInspector.StylePropertyTreeElement} | 2510 * @return {?Elements.StylePropertyTreeElement} |
| 2511 */ | 2511 */ |
| 2512 _findSibling(moveDirection) { | 2512 _findSibling(moveDirection) { |
| 2513 var target = this; | 2513 var target = this; |
| 2514 do { | 2514 do { |
| 2515 target = (moveDirection === 'forward' ? target.nextSibling : target.previo
usSibling); | 2515 target = (moveDirection === 'forward' ? target.nextSibling : target.previo
usSibling); |
| 2516 } while (target && target.inherited()); | 2516 } while (target && target.inherited()); |
| 2517 | 2517 |
| 2518 return target; | 2518 return target; |
| 2519 } | 2519 } |
| 2520 | 2520 |
| 2521 /** | 2521 /** |
| 2522 * @param {string} userInput | 2522 * @param {string} userInput |
| 2523 * @param {!WebInspector.StylePropertyTreeElement.Context} context | 2523 * @param {!Elements.StylePropertyTreeElement.Context} context |
| 2524 * @param {string} moveDirection | 2524 * @param {string} moveDirection |
| 2525 */ | 2525 */ |
| 2526 _editingCommitted(userInput, context, moveDirection) { | 2526 _editingCommitted(userInput, context, moveDirection) { |
| 2527 this._removePrompt(); | 2527 this._removePrompt(); |
| 2528 this.editingEnded(context); | 2528 this.editingEnded(context); |
| 2529 var isEditingName = context.isEditingName; | 2529 var isEditingName = context.isEditingName; |
| 2530 | 2530 |
| 2531 // Determine where to move to before making changes | 2531 // Determine where to move to before making changes |
| 2532 var createNewProperty, moveToPropertyName, moveToSelector; | 2532 var createNewProperty, moveToPropertyName, moveToSelector; |
| 2533 var isDataPasted = 'originalName' in context; | 2533 var isDataPasted = 'originalName' in context; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2546 createNewProperty = true; | 2546 createNewProperty = true; |
| 2547 else if (moveDirection === 'backward') | 2547 else if (moveDirection === 'backward') |
| 2548 moveToSelector = true; | 2548 moveToSelector = true; |
| 2549 } | 2549 } |
| 2550 | 2550 |
| 2551 // Make the Changes and trigger the moveToNextCallback after updating. | 2551 // Make the Changes and trigger the moveToNextCallback after updating. |
| 2552 var moveToIndex = moveTo && this.treeOutline ? this.treeOutline.rootElement(
).indexOfChild(moveTo) : -1; | 2552 var moveToIndex = moveTo && this.treeOutline ? this.treeOutline.rootElement(
).indexOfChild(moveTo) : -1; |
| 2553 var blankInput = userInput.isWhitespace(); | 2553 var blankInput = userInput.isWhitespace(); |
| 2554 var shouldCommitNewProperty = this._newProperty && | 2554 var shouldCommitNewProperty = this._newProperty && |
| 2555 (isPropertySplitPaste || moveToOther || (!moveDirection && !isEditingNam
e) || (isEditingName && blankInput)); | 2555 (isPropertySplitPaste || moveToOther || (!moveDirection && !isEditingNam
e) || (isEditingName && blankInput)); |
| 2556 var section = /** @type {!WebInspector.StylePropertiesSection} */ (this.sect
ion()); | 2556 var section = /** @type {!Elements.StylePropertiesSection} */ (this.section(
)); |
| 2557 if (((userInput !== context.previousContent || isDirtyViaPaste) && !this._ne
wProperty) || shouldCommitNewProperty) { | 2557 if (((userInput !== context.previousContent || isDirtyViaPaste) && !this._ne
wProperty) || shouldCommitNewProperty) { |
| 2558 section._afterUpdate = moveToNextCallback.bind(this, this._newProperty, !b
lankInput, section); | 2558 section._afterUpdate = moveToNextCallback.bind(this, this._newProperty, !b
lankInput, section); |
| 2559 var propertyText; | 2559 var propertyText; |
| 2560 if (blankInput || (this._newProperty && this.valueElement.textContent.isWh
itespace())) | 2560 if (blankInput || (this._newProperty && this.valueElement.textContent.isWh
itespace())) |
| 2561 propertyText = ''; | 2561 propertyText = ''; |
| 2562 else { | 2562 else { |
| 2563 if (isEditingName) | 2563 if (isEditingName) |
| 2564 propertyText = userInput + ': ' + this.property.value; | 2564 propertyText = userInput + ': ' + this.property.value; |
| 2565 else | 2565 else |
| 2566 propertyText = this.property.name + ': ' + userInput; | 2566 propertyText = this.property.name + ': ' + userInput; |
| 2567 } | 2567 } |
| 2568 this.applyStyleText(propertyText, true); | 2568 this.applyStyleText(propertyText, true); |
| 2569 } else { | 2569 } else { |
| 2570 if (isEditingName) | 2570 if (isEditingName) |
| 2571 this.property.name = userInput; | 2571 this.property.name = userInput; |
| 2572 else | 2572 else |
| 2573 this.property.value = userInput; | 2573 this.property.value = userInput; |
| 2574 if (!isDataPasted && !this._newProperty) | 2574 if (!isDataPasted && !this._newProperty) |
| 2575 this.updateTitle(); | 2575 this.updateTitle(); |
| 2576 moveToNextCallback.call(this, this._newProperty, false, section); | 2576 moveToNextCallback.call(this, this._newProperty, false, section); |
| 2577 } | 2577 } |
| 2578 | 2578 |
| 2579 /** | 2579 /** |
| 2580 * The Callback to start editing the next/previous property/selector. | 2580 * The Callback to start editing the next/previous property/selector. |
| 2581 * @param {boolean} alreadyNew | 2581 * @param {boolean} alreadyNew |
| 2582 * @param {boolean} valueChanged | 2582 * @param {boolean} valueChanged |
| 2583 * @param {!WebInspector.StylePropertiesSection} section | 2583 * @param {!Elements.StylePropertiesSection} section |
| 2584 * @this {WebInspector.StylePropertyTreeElement} | 2584 * @this {Elements.StylePropertyTreeElement} |
| 2585 */ | 2585 */ |
| 2586 function moveToNextCallback(alreadyNew, valueChanged, section) { | 2586 function moveToNextCallback(alreadyNew, valueChanged, section) { |
| 2587 if (!moveDirection) | 2587 if (!moveDirection) |
| 2588 return; | 2588 return; |
| 2589 | 2589 |
| 2590 // User just tabbed through without changes. | 2590 // User just tabbed through without changes. |
| 2591 if (moveTo && moveTo.parent) { | 2591 if (moveTo && moveTo.parent) { |
| 2592 moveTo.startEditing(!isEditingName ? moveTo.nameElement : moveTo.valueEl
ement); | 2592 moveTo.startEditing(!isEditingName ? moveTo.nameElement : moveTo.valueEl
ement); |
| 2593 return; | 2593 return; |
| 2594 } | 2594 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2684 this.parent.removeChild(this); | 2684 this.parent.removeChild(this); |
| 2685 section.afterUpdate(); | 2685 section.afterUpdate(); |
| 2686 return Promise.resolve(); | 2686 return Promise.resolve(); |
| 2687 } | 2687 } |
| 2688 | 2688 |
| 2689 var currentNode = this._parentPane.node(); | 2689 var currentNode = this._parentPane.node(); |
| 2690 this._parentPane._userOperation = true; | 2690 this._parentPane._userOperation = true; |
| 2691 | 2691 |
| 2692 /** | 2692 /** |
| 2693 * @param {boolean} success | 2693 * @param {boolean} success |
| 2694 * @this {WebInspector.StylePropertyTreeElement} | 2694 * @this {Elements.StylePropertyTreeElement} |
| 2695 */ | 2695 */ |
| 2696 function callback(success) { | 2696 function callback(success) { |
| 2697 delete this._parentPane._userOperation; | 2697 delete this._parentPane._userOperation; |
| 2698 | 2698 |
| 2699 if (!success) { | 2699 if (!success) { |
| 2700 if (majorChange) { | 2700 if (majorChange) { |
| 2701 // It did not apply, cancel editing. | 2701 // It did not apply, cancel editing. |
| 2702 this._revertStyleUponEditingCanceled(); | 2702 this._revertStyleUponEditingCanceled(); |
| 2703 } | 2703 } |
| 2704 this.styleTextAppliedForTest(); | 2704 this.styleTextAppliedForTest(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2736 * @override | 2736 * @override |
| 2737 * @param {!Event} event | 2737 * @param {!Event} event |
| 2738 * @return {boolean} | 2738 * @return {boolean} |
| 2739 */ | 2739 */ |
| 2740 isEventWithinDisclosureTriangle(event) { | 2740 isEventWithinDisclosureTriangle(event) { |
| 2741 return event.target === this._expandElement; | 2741 return event.target === this._expandElement; |
| 2742 } | 2742 } |
| 2743 }; | 2743 }; |
| 2744 | 2744 |
| 2745 /** @typedef {{expanded: boolean, hasChildren: boolean, isEditingName: boolean,
previousContent: string}} */ | 2745 /** @typedef {{expanded: boolean, hasChildren: boolean, isEditingName: boolean,
previousContent: string}} */ |
| 2746 WebInspector.StylePropertyTreeElement.Context; | 2746 Elements.StylePropertyTreeElement.Context; |
| 2747 | 2747 |
| 2748 /** | 2748 /** |
| 2749 * @unrestricted | 2749 * @unrestricted |
| 2750 */ | 2750 */ |
| 2751 WebInspector.StylesSidebarPane.CSSPropertyPrompt = class extends WebInspector.Te
xtPrompt { | 2751 Elements.StylesSidebarPane.CSSPropertyPrompt = class extends UI.TextPrompt { |
| 2752 /** | 2752 /** |
| 2753 * @param {!Array<string>} cssCompletions | 2753 * @param {!Array<string>} cssCompletions |
| 2754 * @param {!WebInspector.StylePropertyTreeElement} treeElement | 2754 * @param {!Elements.StylePropertyTreeElement} treeElement |
| 2755 * @param {boolean} isEditingName | 2755 * @param {boolean} isEditingName |
| 2756 */ | 2756 */ |
| 2757 constructor(cssCompletions, treeElement, isEditingName) { | 2757 constructor(cssCompletions, treeElement, isEditingName) { |
| 2758 // Use the same callback both for applyItemCallback and acceptItemCallback. | 2758 // Use the same callback both for applyItemCallback and acceptItemCallback. |
| 2759 super(); | 2759 super(); |
| 2760 this.initialize(this._buildPropertyCompletions.bind(this), WebInspector.Styl
eValueDelimiters); | 2760 this.initialize(this._buildPropertyCompletions.bind(this), UI.StyleValueDeli
miters); |
| 2761 this.setSuggestBoxEnabled(true); | 2761 this.setSuggestBoxEnabled(true); |
| 2762 this._cssCompletions = cssCompletions; | 2762 this._cssCompletions = cssCompletions; |
| 2763 this._treeElement = treeElement; | 2763 this._treeElement = treeElement; |
| 2764 this._isEditingName = isEditingName; | 2764 this._isEditingName = isEditingName; |
| 2765 | 2765 |
| 2766 if (!isEditingName) { | 2766 if (!isEditingName) { |
| 2767 this.disableDefaultSuggestionForEmptyInput(); | 2767 this.disableDefaultSuggestionForEmptyInput(); |
| 2768 | 2768 |
| 2769 // If a CSS value is being edited that has a numeric or hex substring, hin
t that precision modifier shortcuts are available. | 2769 // If a CSS value is being edited that has a numeric or hex substring, hin
t that precision modifier shortcuts are available. |
| 2770 if (treeElement && treeElement.valueElement) { | 2770 if (treeElement && treeElement.valueElement) { |
| 2771 var cssValueText = treeElement.valueElement.textContent; | 2771 var cssValueText = treeElement.valueElement.textContent; |
| 2772 if (cssValueText.match(/#[\da-f]{3,6}$/i)) | 2772 if (cssValueText.match(/#[\da-f]{3,6}$/i)) |
| 2773 this.setTitle(WebInspector.UIString( | 2773 this.setTitle(Common.UIString( |
| 2774 'Increment/decrement with mousewheel or up/down keys. %s: R ±1, Sh
ift: G ±1, Alt: B ±1', | 2774 'Increment/decrement with mousewheel or up/down keys. %s: R ±1, Sh
ift: G ±1, Alt: B ±1', |
| 2775 WebInspector.isMac() ? 'Cmd' : 'Ctrl')); | 2775 Host.isMac() ? 'Cmd' : 'Ctrl')); |
| 2776 else if (cssValueText.match(/\d+/)) | 2776 else if (cssValueText.match(/\d+/)) |
| 2777 this.setTitle(WebInspector.UIString( | 2777 this.setTitle(Common.UIString( |
| 2778 'Increment/decrement with mousewheel or up/down keys. %s: ±100, Sh
ift: ±10, Alt: ±0.1', | 2778 'Increment/decrement with mousewheel or up/down keys. %s: ±100, Sh
ift: ±10, Alt: ±0.1', |
| 2779 WebInspector.isMac() ? 'Cmd' : 'Ctrl')); | 2779 Host.isMac() ? 'Cmd' : 'Ctrl')); |
| 2780 } | 2780 } |
| 2781 } | 2781 } |
| 2782 } | 2782 } |
| 2783 | 2783 |
| 2784 /** | 2784 /** |
| 2785 * @override | 2785 * @override |
| 2786 * @param {!Event} event | 2786 * @param {!Event} event |
| 2787 */ | 2787 */ |
| 2788 onKeyDown(event) { | 2788 onKeyDown(event) { |
| 2789 switch (event.key) { | 2789 switch (event.key) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2832 } | 2832 } |
| 2833 | 2833 |
| 2834 /** | 2834 /** |
| 2835 * @param {!Event} event | 2835 * @param {!Event} event |
| 2836 * @return {boolean} | 2836 * @return {boolean} |
| 2837 */ | 2837 */ |
| 2838 _handleNameOrValueUpDown(event) { | 2838 _handleNameOrValueUpDown(event) { |
| 2839 /** | 2839 /** |
| 2840 * @param {string} originalValue | 2840 * @param {string} originalValue |
| 2841 * @param {string} replacementString | 2841 * @param {string} replacementString |
| 2842 * @this {WebInspector.StylesSidebarPane.CSSPropertyPrompt} | 2842 * @this {Elements.StylesSidebarPane.CSSPropertyPrompt} |
| 2843 */ | 2843 */ |
| 2844 function finishHandler(originalValue, replacementString) { | 2844 function finishHandler(originalValue, replacementString) { |
| 2845 // Synthesize property text disregarding any comments, custom whitespace e
tc. | 2845 // Synthesize property text disregarding any comments, custom whitespace e
tc. |
| 2846 this._treeElement.applyStyleText( | 2846 this._treeElement.applyStyleText( |
| 2847 this._treeElement.nameElement.textContent + ': ' + this._treeElement.v
alueElement.textContent, false); | 2847 this._treeElement.nameElement.textContent + ': ' + this._treeElement.v
alueElement.textContent, false); |
| 2848 } | 2848 } |
| 2849 | 2849 |
| 2850 /** | 2850 /** |
| 2851 * @param {string} prefix | 2851 * @param {string} prefix |
| 2852 * @param {number} number | 2852 * @param {number} number |
| 2853 * @param {string} suffix | 2853 * @param {string} suffix |
| 2854 * @return {string} | 2854 * @return {string} |
| 2855 * @this {WebInspector.StylesSidebarPane.CSSPropertyPrompt} | 2855 * @this {Elements.StylesSidebarPane.CSSPropertyPrompt} |
| 2856 */ | 2856 */ |
| 2857 function customNumberHandler(prefix, number, suffix) { | 2857 function customNumberHandler(prefix, number, suffix) { |
| 2858 if (number !== 0 && !suffix.length && | 2858 if (number !== 0 && !suffix.length && |
| 2859 WebInspector.cssMetadata().isLengthProperty(this._treeElement.property
.name)) | 2859 SDK.cssMetadata().isLengthProperty(this._treeElement.property.name)) |
| 2860 suffix = 'px'; | 2860 suffix = 'px'; |
| 2861 return prefix + number + suffix; | 2861 return prefix + number + suffix; |
| 2862 } | 2862 } |
| 2863 | 2863 |
| 2864 // Handle numeric value increment/decrement only at this point. | 2864 // Handle numeric value increment/decrement only at this point. |
| 2865 if (!this._isEditingName && | 2865 if (!this._isEditingName && |
| 2866 WebInspector.handleElementValueModifications( | 2866 UI.handleElementValueModifications( |
| 2867 event, this._treeElement.valueElement, finishHandler.bind(this), thi
s._isValueSuggestion.bind(this), | 2867 event, this._treeElement.valueElement, finishHandler.bind(this), thi
s._isValueSuggestion.bind(this), |
| 2868 customNumberHandler.bind(this))) | 2868 customNumberHandler.bind(this))) |
| 2869 return true; | 2869 return true; |
| 2870 | 2870 |
| 2871 return false; | 2871 return false; |
| 2872 } | 2872 } |
| 2873 | 2873 |
| 2874 /** | 2874 /** |
| 2875 * @param {string} word | 2875 * @param {string} word |
| 2876 * @return {boolean} | 2876 * @return {boolean} |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2900 this._cssCompletions.forEach(filterCompletions); | 2900 this._cssCompletions.forEach(filterCompletions); |
| 2901 var results = prefixResults.concat(anywhereResults); | 2901 var results = prefixResults.concat(anywhereResults); |
| 2902 | 2902 |
| 2903 if (!this._isEditingName && !results.length && query.length > 1 && '!importa
nt'.startsWith(query)) | 2903 if (!this._isEditingName && !results.length && query.length > 1 && '!importa
nt'.startsWith(query)) |
| 2904 results.push('!important'); | 2904 results.push('!important'); |
| 2905 var userEnteredText = wordRange.toString().replace('-', ''); | 2905 var userEnteredText = wordRange.toString().replace('-', ''); |
| 2906 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase()))
{ | 2906 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase()))
{ |
| 2907 for (var i = 0; i < results.length; ++i) | 2907 for (var i = 0; i < results.length; ++i) |
| 2908 results[i] = results[i].toUpperCase(); | 2908 results[i] = results[i].toUpperCase(); |
| 2909 } | 2909 } |
| 2910 var selectedIndex = this._isEditingName ? WebInspector.cssMetadata().mostUse
dProperty(prefixResults) : 0; | 2910 var selectedIndex = this._isEditingName ? SDK.cssMetadata().mostUsedProperty
(prefixResults) : 0; |
| 2911 completionsReadyCallback(results, selectedIndex); | 2911 completionsReadyCallback(results, selectedIndex); |
| 2912 | 2912 |
| 2913 /** | 2913 /** |
| 2914 * @param {string} completion | 2914 * @param {string} completion |
| 2915 */ | 2915 */ |
| 2916 function filterCompletions(completion) { | 2916 function filterCompletions(completion) { |
| 2917 var index = completion.indexOf(query); | 2917 var index = completion.indexOf(query); |
| 2918 if (index === 0) | 2918 if (index === 0) |
| 2919 prefixResults.push(completion); | 2919 prefixResults.push(completion); |
| 2920 else if (index > -1) | 2920 else if (index > -1) |
| 2921 anywhereResults.push(completion); | 2921 anywhereResults.push(completion); |
| 2922 } | 2922 } |
| 2923 } | 2923 } |
| 2924 }; | 2924 }; |
| 2925 | 2925 |
| 2926 /** | 2926 /** |
| 2927 * @unrestricted | 2927 * @unrestricted |
| 2928 */ | 2928 */ |
| 2929 WebInspector.StylesSidebarPropertyRenderer = class { | 2929 Elements.StylesSidebarPropertyRenderer = class { |
| 2930 /** | 2930 /** |
| 2931 * @param {?WebInspector.CSSRule} rule | 2931 * @param {?SDK.CSSRule} rule |
| 2932 * @param {?WebInspector.DOMNode} node | 2932 * @param {?SDK.DOMNode} node |
| 2933 * @param {string} name | 2933 * @param {string} name |
| 2934 * @param {string} value | 2934 * @param {string} value |
| 2935 */ | 2935 */ |
| 2936 constructor(rule, node, name, value) { | 2936 constructor(rule, node, name, value) { |
| 2937 this._rule = rule; | 2937 this._rule = rule; |
| 2938 this._node = node; | 2938 this._node = node; |
| 2939 this._propertyName = name; | 2939 this._propertyName = name; |
| 2940 this._propertyValue = value; | 2940 this._propertyValue = value; |
| 2941 } | 2941 } |
| 2942 | 2942 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2976 * @return {!Element} | 2976 * @return {!Element} |
| 2977 */ | 2977 */ |
| 2978 renderValue() { | 2978 renderValue() { |
| 2979 var valueElement = createElement('span'); | 2979 var valueElement = createElement('span'); |
| 2980 valueElement.className = 'value'; | 2980 valueElement.className = 'value'; |
| 2981 if (!this._propertyValue) | 2981 if (!this._propertyValue) |
| 2982 return valueElement; | 2982 return valueElement; |
| 2983 | 2983 |
| 2984 if (this._shadowHandler && (this._propertyName === 'box-shadow' || this._pro
pertyName === 'text-shadow' || | 2984 if (this._shadowHandler && (this._propertyName === 'box-shadow' || this._pro
pertyName === 'text-shadow' || |
| 2985 this._propertyName === '-webkit-box-shadow') && | 2985 this._propertyName === '-webkit-box-shadow') && |
| 2986 !WebInspector.CSSMetadata.VariableRegex.test(this._propertyValue)) { | 2986 !SDK.CSSMetadata.VariableRegex.test(this._propertyValue)) { |
| 2987 valueElement.appendChild(this._shadowHandler(this._propertyValue, this._pr
opertyName)); | 2987 valueElement.appendChild(this._shadowHandler(this._propertyValue, this._pr
opertyName)); |
| 2988 valueElement.normalize(); | 2988 valueElement.normalize(); |
| 2989 return valueElement; | 2989 return valueElement; |
| 2990 } | 2990 } |
| 2991 | 2991 |
| 2992 var regexes = [WebInspector.CSSMetadata.VariableRegex, WebInspector.CSSMetad
ata.URLRegex]; | 2992 var regexes = [SDK.CSSMetadata.VariableRegex, SDK.CSSMetadata.URLRegex]; |
| 2993 var processors = [createTextNode, this._processURL.bind(this)]; | 2993 var processors = [createTextNode, this._processURL.bind(this)]; |
| 2994 if (this._bezierHandler && WebInspector.cssMetadata().isBezierAwareProperty(
this._propertyName)) { | 2994 if (this._bezierHandler && SDK.cssMetadata().isBezierAwareProperty(this._pro
pertyName)) { |
| 2995 regexes.push(WebInspector.Geometry.CubicBezier.Regex); | 2995 regexes.push(Common.Geometry.CubicBezier.Regex); |
| 2996 processors.push(this._bezierHandler); | 2996 processors.push(this._bezierHandler); |
| 2997 } | 2997 } |
| 2998 if (this._colorHandler && WebInspector.cssMetadata().isColorAwareProperty(th
is._propertyName)) { | 2998 if (this._colorHandler && SDK.cssMetadata().isColorAwareProperty(this._prope
rtyName)) { |
| 2999 regexes.push(WebInspector.Color.Regex); | 2999 regexes.push(Common.Color.Regex); |
| 3000 processors.push(this._colorHandler); | 3000 processors.push(this._colorHandler); |
| 3001 } | 3001 } |
| 3002 var results = WebInspector.TextUtils.splitStringByRegexes(this._propertyValu
e, regexes); | 3002 var results = Common.TextUtils.splitStringByRegexes(this._propertyValue, reg
exes); |
| 3003 for (var i = 0; i < results.length; i++) { | 3003 for (var i = 0; i < results.length; i++) { |
| 3004 var result = results[i]; | 3004 var result = results[i]; |
| 3005 var processor = result.regexIndex === -1 ? createTextNode : processors[res
ult.regexIndex]; | 3005 var processor = result.regexIndex === -1 ? createTextNode : processors[res
ult.regexIndex]; |
| 3006 valueElement.appendChild(processor(result.value)); | 3006 valueElement.appendChild(processor(result.value)); |
| 3007 } | 3007 } |
| 3008 valueElement.normalize(); | 3008 valueElement.normalize(); |
| 3009 return valueElement; | 3009 return valueElement; |
| 3010 } | 3010 } |
| 3011 | 3011 |
| 3012 /** | 3012 /** |
| 3013 * @param {string} text | 3013 * @param {string} text |
| 3014 * @return {!Node} | 3014 * @return {!Node} |
| 3015 */ | 3015 */ |
| 3016 _processURL(text) { | 3016 _processURL(text) { |
| 3017 // Strip "url(" and ")" along with whitespace. | 3017 // Strip "url(" and ")" along with whitespace. |
| 3018 var url = text.substring(4, text.length - 1).trim(); | 3018 var url = text.substring(4, text.length - 1).trim(); |
| 3019 var isQuoted = /^'.*'$/.test(url) || /^".*"$/.test(url); | 3019 var isQuoted = /^'.*'$/.test(url) || /^".*"$/.test(url); |
| 3020 if (isQuoted) | 3020 if (isQuoted) |
| 3021 url = url.substring(1, url.length - 1); | 3021 url = url.substring(1, url.length - 1); |
| 3022 var container = createDocumentFragment(); | 3022 var container = createDocumentFragment(); |
| 3023 container.createTextChild('url('); | 3023 container.createTextChild('url('); |
| 3024 var hrefUrl = null; | 3024 var hrefUrl = null; |
| 3025 if (this._rule && this._rule.resourceURL()) | 3025 if (this._rule && this._rule.resourceURL()) |
| 3026 hrefUrl = WebInspector.ParsedURL.completeURL(this._rule.resourceURL(), url
); | 3026 hrefUrl = Common.ParsedURL.completeURL(this._rule.resourceURL(), url); |
| 3027 else if (this._node) | 3027 else if (this._node) |
| 3028 hrefUrl = this._node.resolveURL(url); | 3028 hrefUrl = this._node.resolveURL(url); |
| 3029 var hasResource = hrefUrl && !!WebInspector.resourceForURL(hrefUrl); | 3029 var hasResource = hrefUrl && !!Bindings.resourceForURL(hrefUrl); |
| 3030 // FIXME: WebInspector.linkifyURLAsNode() should really use baseURI. | 3030 // FIXME: UI.linkifyURLAsNode() should really use baseURI. |
| 3031 container.appendChild(WebInspector.linkifyURLAsNode(hrefUrl || url, url, und
efined, !hasResource)); | 3031 container.appendChild(UI.linkifyURLAsNode(hrefUrl || url, url, undefined, !h
asResource)); |
| 3032 container.createTextChild(')'); | 3032 container.createTextChild(')'); |
| 3033 return container; | 3033 return container; |
| 3034 } | 3034 } |
| 3035 }; | 3035 }; |
| 3036 | 3036 |
| 3037 /** | 3037 /** |
| 3038 * @implements {WebInspector.ToolbarItem.Provider} | 3038 * @implements {UI.ToolbarItem.Provider} |
| 3039 * @unrestricted | 3039 * @unrestricted |
| 3040 */ | 3040 */ |
| 3041 WebInspector.StylesSidebarPane.ButtonProvider = class { | 3041 Elements.StylesSidebarPane.ButtonProvider = class { |
| 3042 constructor() { | 3042 constructor() { |
| 3043 this._button = new WebInspector.ToolbarButton(WebInspector.UIString('New Sty
le Rule'), 'largeicon-add'); | 3043 this._button = new UI.ToolbarButton(Common.UIString('New Style Rule'), 'larg
eicon-add'); |
| 3044 this._button.addEventListener('click', this._clicked, this); | 3044 this._button.addEventListener('click', this._clicked, this); |
| 3045 var longclickTriangle = WebInspector.Icon.create('largeicon-longclick-triang
le', 'long-click-glyph'); | 3045 var longclickTriangle = UI.Icon.create('largeicon-longclick-triangle', 'long
-click-glyph'); |
| 3046 this._button.element.appendChild(longclickTriangle); | 3046 this._button.element.appendChild(longclickTriangle); |
| 3047 | 3047 |
| 3048 new WebInspector.LongClickController(this._button.element, this._longClicked
.bind(this)); | 3048 new UI.LongClickController(this._button.element, this._longClicked.bind(this
)); |
| 3049 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha
nged.bind(this)); | 3049 UI.context.addFlavorChangeListener(SDK.DOMNode, onNodeChanged.bind(this)); |
| 3050 onNodeChanged.call(this); | 3050 onNodeChanged.call(this); |
| 3051 | 3051 |
| 3052 /** | 3052 /** |
| 3053 * @this {WebInspector.StylesSidebarPane.ButtonProvider} | 3053 * @this {Elements.StylesSidebarPane.ButtonProvider} |
| 3054 */ | 3054 */ |
| 3055 function onNodeChanged() { | 3055 function onNodeChanged() { |
| 3056 var node = WebInspector.context.flavor(WebInspector.DOMNode); | 3056 var node = UI.context.flavor(SDK.DOMNode); |
| 3057 node = node ? node.enclosingElementOrSelf() : null; | 3057 node = node ? node.enclosingElementOrSelf() : null; |
| 3058 this._button.setEnabled(!!node); | 3058 this._button.setEnabled(!!node); |
| 3059 } | 3059 } |
| 3060 } | 3060 } |
| 3061 | 3061 |
| 3062 _clicked() { | 3062 _clicked() { |
| 3063 WebInspector.StylesSidebarPane._instance._createNewRuleInViaInspectorStyleSh
eet(); | 3063 Elements.StylesSidebarPane._instance._createNewRuleInViaInspectorStyleSheet(
); |
| 3064 } | 3064 } |
| 3065 | 3065 |
| 3066 /** | 3066 /** |
| 3067 * @param {!Event} e | 3067 * @param {!Event} e |
| 3068 */ | 3068 */ |
| 3069 _longClicked(e) { | 3069 _longClicked(e) { |
| 3070 WebInspector.StylesSidebarPane._instance._onAddButtonLongClick(e); | 3070 Elements.StylesSidebarPane._instance._onAddButtonLongClick(e); |
| 3071 } | 3071 } |
| 3072 | 3072 |
| 3073 /** | 3073 /** |
| 3074 * @override | 3074 * @override |
| 3075 * @return {!WebInspector.ToolbarItem} | 3075 * @return {!UI.ToolbarItem} |
| 3076 */ | 3076 */ |
| 3077 item() { | 3077 item() { |
| 3078 return this._button; | 3078 return this._button; |
| 3079 } | 3079 } |
| 3080 }; | 3080 }; |
| OLD | NEW |