Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
|
pfeldman
2015/08/21 01:43:00
make sure lushnikov@ likes it.
sergeyv
2015/08/21 04:05:42
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @param {!WebInspector.StylesSidebarPane} ssp | |
| 8 */ | |
| 9 WebInspector.PropertyChangeHighlighter = function(ssp) | |
| 10 { | |
| 11 this._styleSidebarPane = ssp; | |
| 12 WebInspector.targetManager.addModelListener(WebInspector.CSSStyleModel, WebI nspector.CSSStyleModel.Events.LayoutEditorChange, this._onLayoutEditorChange, th is); | |
| 13 this._animationDuration = 1400; | |
| 14 this._requestAnimationFrame = ssp.element.window().requestAnimationFrame; | |
| 15 } | |
| 16 | |
| 17 WebInspector.PropertyChangeHighlighter.prototype = { | |
| 18 | |
|
lushnikov
2015/08/21 02:36:07
stray line
sergeyv
2015/08/21 04:05:42
Done.
| |
| 19 /** | |
| 20 * @param {!WebInspector.Event} event | |
| 21 */ | |
| 22 _onLayoutEditorChange: function(event) | |
| 23 { | |
| 24 this._styleSheetId = event.data.id; | |
| 25 this._changeRange = event.data.range; | |
| 26 delete this._animationStart; | |
| 27 if (!this._nextAnimation) | |
| 28 this._nextAnimation = this._requestAnimationFrame.call(null, this.up date.bind(this)); | |
| 29 }, | |
| 30 | |
| 31 /** | |
| 32 * @param {number} now | |
| 33 */ | |
| 34 update: function(now) | |
| 35 { | |
| 36 delete this._nextAnimation; | |
|
lushnikov
2015/08/21 02:36:07
you might want to check ssp's node's target here
sergeyv
2015/08/21 04:05:42
Done.
| |
| 37 if (!this._styleSheetId) | |
| 38 return; | |
| 39 | |
| 40 var sectionBlocks = this._styleSidebarPane.sectionBlocks(); | |
| 41 var foundSection = null; | |
| 42 for (var block of sectionBlocks) { | |
| 43 for (var section of block.sections) { | |
| 44 var declaration = section.styleRule.style(); | |
| 45 if (declaration.styleSheetId !== this._styleSheetId) | |
| 46 continue; | |
| 47 | |
| 48 if (this._checkRanges(declaration.range, this._changeRange)) { | |
|
lushnikov
2015/08/21 02:36:07
FYI: you compare outdated declaration range here.
sergeyv
2015/08/21 04:05:42
Done.
| |
| 49 foundSection = section; | |
| 50 break; | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 if (!foundSection) | |
| 56 return; | |
| 57 | |
| 58 var treeElement = foundSection.propertiesTreeOutline.firstChild(); | |
| 59 var foundTreeElement = null; | |
| 60 while (treeElement) { | |
| 61 if (treeElement.property.range && this._checkRanges(treeElement.pro perty.range, this._changeRange)) { | |
|
lushnikov
2015/08/21 02:36:07
FYI: this might occasionally fail as property rang
sergeyv
2015/08/21 04:05:42
Done.
| |
| 62 foundTreeElement = treeElement; | |
| 63 break; | |
| 64 } | |
| 65 treeElement = treeElement.traverseNextTreeElement(false, null, true) ; | |
| 66 } | |
| 67 | |
| 68 if (!foundTreeElement) | |
| 69 return; | |
| 70 | |
| 71 if (!this._animationStart) | |
| 72 this._animationStart = now; | |
| 73 | |
| 74 var animationProgress = (now - this._animationStart) / this._animationDu ration; | |
| 75 var valueElement = foundTreeElement.valueElement; | |
| 76 valueElement.classList.toggle("css-update-highlight", animationProgress < 1); | |
| 77 valueElement.classList.toggle("first-part", animationProgress < 0.2); | |
| 78 | |
| 79 if (animationProgress > 1) { | |
| 80 delete this._animationStart; | |
|
lushnikov
2015/08/21 02:36:07
let's delete background
sergeyv
2015/08/21 04:05:42
Done.
| |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 valueElement.style.backgroundColor = "rgba(158, 54, 153, " + (1 - animat ionProgress) + ")"; | |
| 85 this._nextAnimation = this._requestAnimationFrame.call(null, this.update .bind(this)); | |
| 86 }, | |
| 87 | |
| 88 /** | |
| 89 * | |
| 90 * @param {!CSSAgent.SourceRange} outterRange | |
| 91 * @param {!CSSAgent.SourceRange} innerRange | |
| 92 * @return {boolean} | |
| 93 */ | |
| 94 _checkRanges: function(outterRange, innerRange) | |
| 95 { | |
| 96 var startsBefore = outterRange.startLine < innerRange.startLine || (outt erRange.startLine === innerRange.startLine && outterRange.startColumn <= innerRa nge.startColumn); | |
| 97 var endsAfter = outterRange.endLine > innerRange.endLine || (outterRange .endLine === innerRange.endLine && outterRange.endColumn >= innerRange.endColumn ); | |
| 98 return startsBefore && endsAfter; | |
| 99 } | |
| 100 } | |
| OLD | NEW |