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

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

Issue 1530353003: DevTools: jump from computed style to styles sidebar pane. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: kill revealer. rebaseline. Created 4 years, 11 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @param {!WebInspector.StylesSidebarPane} ssp 7 * @param {!WebInspector.StylesSidebarPane} ssp
8 * @param {!WebInspector.CSSStyleModel} cssModel
9 * @param {!CSSAgent.StyleSheetId} styleSheetId
10 * @param {!WebInspector.TextRange} range
8 */ 11 */
9 WebInspector.PropertyChangeHighlighter = function(ssp) 12 WebInspector.PropertyChangeHighlighter = function(ssp, cssModel, styleSheetId, r ange)
10 { 13 {
11 this._styleSidebarPane = ssp; 14 this._styleSidebarPane = ssp;
12 WebInspector.targetManager.addModelListener(WebInspector.CSSStyleModel, WebI nspector.CSSStyleModel.Events.LayoutEditorChange, this._onLayoutEditorChange, th is); 15 this._target = cssModel.target();
16 this._styleSheetId = styleSheetId;
17 this._range = range;
13 } 18 }
14 19
15 WebInspector.PropertyChangeHighlighter.prototype = { 20 WebInspector.PropertyChangeHighlighter.prototype = {
16 /** 21 /**
17 * @param {!WebInspector.Event} event
18 */ 22 */
19 _onLayoutEditorChange: function(event) 23 perform: function()
20 { 24 {
21 this._styleSidebarPane.runDecoratorAfterUpdate(this._updateHighlight.bin d(this, event));
22 this._styleSidebarPane.update();
23 },
24
25 /**
26 * @param {!WebInspector.Event} event
27 */
28 _updateHighlight: function(event)
29 {
30 var cssModel = /** @type {!WebInspector.CSSStyleModel} */(event.target);
31 var styleSheetId = event.data["id"];
32 var changeRange = /** @type {!CSSAgent.SourceRange} */(event.data["range "]);
33 var changeRangeObject = WebInspector.TextRange.fromObject(changeRange);
34
35 var node = this._styleSidebarPane.node(); 25 var node = this._styleSidebarPane.node();
36 if (!node || cssModel.target() !== node.target()) 26 if (!node || this._target !== node.target())
37 return; 27 return;
38 28
39 var sectionBlocks = this._styleSidebarPane.sectionBlocks();
40 var foundSection = null; 29 var foundSection = null;
41 for (var block of sectionBlocks) { 30 for (var section of this._styleSidebarPane.allSections()) {
42 for (var section of block.sections) { 31 var declaration = section.style();
43 var declaration = section.style(); 32 if (declaration.styleSheetId !== this._styleSheetId)
44 if (declaration.styleSheetId !== styleSheetId) 33 continue;
45 continue;
46 34
47 var parentRule = declaration.parentRule; 35 var parentRule = declaration.parentRule;
48 var isInlineSelector = changeRangeObject.isEmpty(); 36 var isInlineSelector = this._range.isEmpty();
49 var isMatchingRule = parentRule && parentRule.selectorRange() && changeRangeObject.compareTo(parentRule.selectorRange()) === 0; 37 var isMatchingRule = parentRule && parentRule.selectorRange() && thi s._range.compareTo(parentRule.selectorRange()) === 0;
50 if (isInlineSelector || isMatchingRule) { 38 if (isInlineSelector || isMatchingRule) {
51 section.element.animate([ 39 section.element.animate([
52 { offset: 0, backgroundColor: "rgba(255, 227, 199, 1)" } , 40 { offset: 0, backgroundColor: "rgba(255, 227, 199, 1)" },
53 { offset: 0.5, backgroundColor: "rgba(255, 227, 199, 1)" }, 41 { offset: 0.5, backgroundColor: "rgba(255, 227, 199, 1)" },
54 { offset: 0.9, backgroundColor: "rgba(255, 227, 199, 0)" }, 42 { offset: 0.9, backgroundColor: "rgba(255, 227, 199, 0)" },
55 { offset: 1, backgroundColor: "white" } 43 { offset: 1, backgroundColor: "white" }
56 ], { duration : 400, easing: "cubic-bezier(0, 0, 0.2, 1)" }) ; 44 ], { duration : 400, easing: "cubic-bezier(0, 0, 0.2, 1)" });
57 return; 45 return;
58 } 46 }
59 47
60 if (this._checkRanges(declaration.range, changeRange)) { 48 if (this._checkRanges(declaration.range, this._range)) {
61 foundSection = section; 49 foundSection = section;
62 break; 50 break;
63 }
64 } 51 }
65 if (foundSection)
66 break;
67 } 52 }
68 53
69 if (!foundSection) 54 if (!foundSection)
70 return; 55 return;
71 56
72 var highlightElement; 57 var highlightElement;
73 var treeElement = foundSection.propertiesTreeOutline.firstChild(); 58 var treeElement = foundSection.propertiesTreeOutline.firstChild();
74 var foundTreeElement = null; 59 var foundTreeElement = null;
75 while (!highlightElement && treeElement) { 60 while (!highlightElement && treeElement) {
76 if (treeElement.property.range && this._checkRanges(treeElement.pro perty.range, changeRange)) { 61 if (treeElement.property.range && this._checkRanges(treeElement.pro perty.range, this._range)) {
77 highlightElement = treeElement.valueElement; 62 highlightElement = treeElement.valueElement;
78 break; 63 break;
79 } 64 }
80 treeElement = treeElement.traverseNextTreeElement(false, null, true) ; 65 treeElement = treeElement.traverseNextTreeElement(false, null, true) ;
81 } 66 }
82 67
83 if (highlightElement) { 68 if (highlightElement) {
84 highlightElement.animate([ 69 highlightElement.animate([
85 { offset: 0, backgroundColor: "rgba(158, 54, 153, 1)", color : "white" }, 70 { offset: 0, backgroundColor: "rgba(158, 54, 153, 1)", color : "white" },
86 { offset: 0.5, backgroundColor: "rgba(158, 54, 153, 1)", col or: "white" }, 71 { offset: 0.5, backgroundColor: "rgba(158, 54, 153, 1)", col or: "white" },
87 { offset: 0.9, backgroundColor: "rgba(158, 54, 153, 0)", col or: "initial" }, 72 { offset: 0.9, backgroundColor: "rgba(158, 54, 153, 0)", col or: "initial" },
88 { offset: 1, backgroundColor: "white", color: "initial" } 73 { offset: 1, backgroundColor: "white", color: "initial" }
89 ], { duration : 400, easing: "cubic-bezier(0, 0, 0.2, 1)" }); 74 ], { duration : 400, easing: "cubic-bezier(0, 0, 0.2, 1)" });
90 } 75 }
91 }, 76 },
92 77
93 /** 78 /**
94 * 79 *
95 * @param {!CSSAgent.SourceRange} outterRange 80 * @param {!WebInspector.TextRange} outterRange
96 * @param {!CSSAgent.SourceRange} innerRange 81 * @param {!WebInspector.TextRange} innerRange
97 * @return {boolean} 82 * @return {boolean}
98 */ 83 */
99 _checkRanges: function(outterRange, innerRange) 84 _checkRanges: function(outterRange, innerRange)
100 { 85 {
101 var startsBefore = outterRange.startLine < innerRange.startLine || (outt erRange.startLine === innerRange.startLine && outterRange.startColumn <= innerRa nge.startColumn); 86 var startsBefore = outterRange.startLine < innerRange.startLine || (outt erRange.startLine === innerRange.startLine && outterRange.startColumn <= innerRa nge.startColumn);
102 // SSP might be outdated, so inner range will a bit bigger than outter. E.g.; "padding-left: 9px" -> "padding-left: 10px" 87 // SSP might be outdated, so inner range will a bit bigger than outter. E.g.; "padding-left: 9px" -> "padding-left: 10px"
103 var eps = 5; 88 var eps = 5;
104 var endsAfter = outterRange.endLine > innerRange.endLine || (outterRange .endLine === innerRange.endLine && outterRange.endColumn + eps >= innerRange.end Column); 89 var endsAfter = outterRange.endLine > innerRange.endLine || (outterRange .endLine === innerRange.endLine && outterRange.endColumn + eps >= innerRange.end Column);
105 return startsBefore && endsAfter; 90 return startsBefore && endsAfter;
106 } 91 }
107 } 92 }
93
94 /**
95 * @constructor
96 * @param {!WebInspector.StylesSidebarPane} ssp
97 * @param {!WebInspector.CSSProperty} cssProperty
98 */
99 WebInspector.PropertyRevealHighlighter = function(ssp, cssProperty)
100 {
101 this._styleSidebarPane = ssp;
102 this._cssProperty = cssProperty;
103 }
104
105 WebInspector.PropertyRevealHighlighter.prototype = {
106 perform: function()
107 {
108 // Expand all shorthands.
109 for (var section of this._styleSidebarPane.allSections()) {
110 for (var treeElement = section.propertiesTreeOutline.firstChild(); t reeElement; treeElement = treeElement.nextSibling)
pfeldman 2016/01/16 01:00:47 how much do we want this class to know about the s
lushnikov 2016/01/16 01:38:55 The patch doesn't change the approach from this po
111 treeElement.onpopulate();
112 }
113 var highlightTreeElement = null;
114 for (var section of this._styleSidebarPane.allSections()) {
115 var treeElement = section.propertiesTreeOutline.firstChild();
116 while (treeElement && !highlightTreeElement) {
117 if (treeElement.property === this._cssProperty) {
118 highlightTreeElement = treeElement;
119 break;
120 }
121 treeElement = treeElement.traverseNextTreeElement(false, null, t rue);
122 }
123 if (highlightTreeElement)
124 break;
125 }
126
127 if (!highlightTreeElement)
128 return;
129
130 highlightTreeElement.parent.expand();
131 highlightTreeElement.listItemElement.scrollIntoViewIfNeeded();
132 highlightTreeElement.listItemElement.animate([
133 { offset: 0, backgroundColor: "rgba(255, 255, 0, 0.2)"},
134 { offset: 0.1, backgroundColor: "rgba(255, 255, 0, 0.7)"},
135 { offset: 1, backgroundColor: "transparent"}
136 ], { duration : 2000, easing: "cubic-bezier(0, 0, 0.2, 1)" });
137 },
138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698