Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: Source/devtools/front_end/elements/PropertyChangeHighlighter.js

Issue 1310433002: Devtools: [LayoutEditor] highlight changed value in the SSP (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/elements/StylesSidebarPane.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
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 /**
19 * @param {!WebInspector.Event} event
20 */
21 _onLayoutEditorChange: function(event)
22 {
23 this._target = event.target.target();
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;
37 if (!this._styleSheetId)
38 return;
39 var node = this._styleSidebarPane.node();
40 if (!node || this._target !== node.target()) {
41 this._clear();
42 return;
43 }
44
45 var sectionBlocks = this._styleSidebarPane.sectionBlocks();
46 var foundSection = null;
47 for (var block of sectionBlocks) {
48 for (var section of block.sections) {
49 var declaration = section.styleRule.style();
50 if (declaration.styleSheetId !== this._styleSheetId)
51 continue;
52
53 if (this._checkRanges(declaration.range, this._changeRange)) {
54 foundSection = section;
55 break;
56 }
57 }
58 if (foundSection)
59 break;
60 }
61
62 if (!foundSection) {
63 this._clear();
64 return;
65 }
66
67 var treeElement = foundSection.propertiesTreeOutline.firstChild();
68 var foundTreeElement = null;
69 while (treeElement) {
70 if (treeElement.property.range && this._checkRanges(treeElement.pro perty.range, this._changeRange)) {
71 foundTreeElement = treeElement;
72 break;
73 }
74 treeElement = treeElement.traverseNextTreeElement(false, null, true) ;
75 }
76
77 if (!foundTreeElement) {
78 this._clear();
79 return;
80 }
81
82 if (!this._animationStart)
83 this._animationStart = now;
84
85 var animationProgress = (now - this._animationStart) / this._animationDu ration;
86 var valueElement = foundTreeElement.valueElement;
87 valueElement.classList.toggle("css-update-highlight", animationProgress < 1);
88 valueElement.classList.toggle("first-part", animationProgress < 0.2);
89
90 if (animationProgress > 1) {
91 this._clear();
92 delete valueElement.style.backgroundColor;
93 return;
94 }
95
96 valueElement.style.backgroundColor = "rgba(158, 54, 153, " + (1 - animat ionProgress) + ")";
97 this._nextAnimation = this._requestAnimationFrame.call(null, this.update .bind(this));
98 },
99
100 _clear: function()
101 {
102 delete this._styleSheetId;
103 delete this._changeRange;
104 delete this._target;
105 delete this._animationStart;
106 },
107
108 /**
109 *
110 * @param {!CSSAgent.SourceRange} outterRange
111 * @param {!CSSAgent.SourceRange} innerRange
112 * @return {boolean}
113 */
114 _checkRanges: function(outterRange, innerRange)
115 {
116 var startsBefore = outterRange.startLine < innerRange.startLine || (outt erRange.startLine === innerRange.startLine && outterRange.startColumn <= innerRa nge.startColumn);
117 // SSP might be outdated, so inner range will a bit bigger than outter. E.g.; "padding-left: 9px" -> "padding-left: 10px"
118 var eps = 5;
119 var endsAfter = outterRange.endLine > innerRange.endLine || (outterRange .endLine === innerRange.endLine && outterRange.endColumn + eps >= innerRange.end Column);
120 return startsBefore && endsAfter;
121 }
122 }
OLDNEW
« no previous file with comments | « Source/devtools/devtools.gypi ('k') | Source/devtools/front_end/elements/StylesSidebarPane.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698