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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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
5 /** 4 /**
6 * @constructor 5 * @unrestricted
7 * @param {!WebInspector.StylesSidebarPane} ssp
8 * @param {!WebInspector.CSSModel} cssModel
9 * @param {!CSSAgent.StyleSheetId} styleSheetId
10 * @param {!WebInspector.TextRange} range
11 */ 6 */
12 WebInspector.PropertyChangeHighlighter = function(ssp, cssModel, styleSheetId, r ange) 7 WebInspector.PropertyChangeHighlighter = class {
13 { 8 /**
9 * @param {!WebInspector.StylesSidebarPane} ssp
10 * @param {!WebInspector.CSSModel} cssModel
11 * @param {!CSSAgent.StyleSheetId} styleSheetId
12 * @param {!WebInspector.TextRange} range
13 */
14 constructor(ssp, cssModel, styleSheetId, range) {
14 this._styleSidebarPane = ssp; 15 this._styleSidebarPane = ssp;
15 this._target = cssModel.target(); 16 this._target = cssModel.target();
16 this._styleSheetId = styleSheetId; 17 this._styleSheetId = styleSheetId;
17 this._range = range; 18 this._range = range;
18 }; 19 }
19 20
20 WebInspector.PropertyChangeHighlighter.prototype = { 21 /**
21 /** 22 */
22 */ 23 perform() {
23 perform: function() 24 var node = this._styleSidebarPane.node();
24 { 25 if (!node || this._target !== node.target())
25 var node = this._styleSidebarPane.node(); 26 return;
26 if (!node || this._target !== node.target())
27 return;
28 27
29 var foundSection = null; 28 var foundSection = null;
30 for (var section of this._styleSidebarPane.allSections()) { 29 for (var section of this._styleSidebarPane.allSections()) {
31 var declaration = section.style(); 30 var declaration = section.style();
32 if (declaration.styleSheetId !== this._styleSheetId) 31 if (declaration.styleSheetId !== this._styleSheetId)
33 continue; 32 continue;
34 33
35 var parentRule = declaration.parentRule; 34 var parentRule = declaration.parentRule;
36 var isInlineSelector = this._range.isEmpty(); 35 var isInlineSelector = this._range.isEmpty();
37 var isMatchingRule = parentRule && parentRule.selectorRange() && thi s._range.compareTo(parentRule.selectorRange()) === 0; 36 var isMatchingRule =
38 if (isInlineSelector || isMatchingRule) { 37 parentRule && parentRule.selectorRange() && this._range.compareTo(pare ntRule.selectorRange()) === 0;
39 section.element.animate([ 38 if (isInlineSelector || isMatchingRule) {
40 { offset: 0, backgroundColor: "rgba(255, 227, 199, 1)" }, 39 section.element.animate(
41 { offset: 0.5, backgroundColor: "rgba(255, 227, 199, 1)" }, 40 [
42 { offset: 0.9, backgroundColor: "rgba(255, 227, 199, 0)" }, 41 {offset: 0, backgroundColor: 'rgba(255, 227, 199, 1)'},
43 { offset: 1, backgroundColor: "white" } 42 {offset: 0.5, backgroundColor: 'rgba(255, 227, 199, 1)'},
44 ], { duration : 400, easing: "cubic-bezier(0, 0, 0.2, 1)" }); 43 {offset: 0.9, backgroundColor: 'rgba(255, 227, 199, 0)'}, {offset: 1, backgroundColor: 'white'}
45 return; 44 ],
46 } 45 {duration: 400, easing: 'cubic-bezier(0, 0, 0.2, 1)'});
46 return;
47 }
47 48
48 if (this._checkRanges(declaration.range, this._range)) { 49 if (this._checkRanges(declaration.range, this._range)) {
49 foundSection = section; 50 foundSection = section;
50 break; 51 break;
51 } 52 }
52 } 53 }
53 54
54 if (!foundSection) 55 if (!foundSection)
55 return; 56 return;
56 57
57 var highlightElement; 58 var highlightElement;
58 var treeElement = foundSection.propertiesTreeOutline.firstChild(); 59 var treeElement = foundSection.propertiesTreeOutline.firstChild();
59 var foundTreeElement = null; 60 var foundTreeElement = null;
60 while (!highlightElement && treeElement) { 61 while (!highlightElement && treeElement) {
61 if (treeElement.property.range && this._checkRanges(treeElement.pro perty.range, this._range)) { 62 if (treeElement.property.range && this._checkRanges(treeElement.property.r ange, this._range)) {
62 highlightElement = treeElement.valueElement; 63 highlightElement = treeElement.valueElement;
63 break; 64 break;
64 } 65 }
65 treeElement = treeElement.traverseNextTreeElement(false, null, true) ; 66 treeElement = treeElement.traverseNextTreeElement(false, null, true);
66 } 67 }
67 68
68 if (highlightElement) { 69 if (highlightElement) {
69 highlightElement.animate([ 70 highlightElement.animate(
70 { offset: 0, backgroundColor: "rgba(158, 54, 153, 1)", color : "white" }, 71 [
71 { offset: 0.5, backgroundColor: "rgba(158, 54, 153, 1)", col or: "white" }, 72 {offset: 0, backgroundColor: 'rgba(158, 54, 153, 1)', color: 'white' },
72 { offset: 0.9, backgroundColor: "rgba(158, 54, 153, 0)", col or: "initial" }, 73 {offset: 0.5, backgroundColor: 'rgba(158, 54, 153, 1)', color: 'whit e'},
73 { offset: 1, backgroundColor: "white", color: "initial" } 74 {offset: 0.9, backgroundColor: 'rgba(158, 54, 153, 0)', color: 'init ial'},
74 ], { duration : 400, easing: "cubic-bezier(0, 0, 0.2, 1)" }); 75 {offset: 1, backgroundColor: 'white', color: 'initial'}
75 } 76 ],
76 }, 77 {duration: 400, easing: 'cubic-bezier(0, 0, 0.2, 1)'});
78 }
79 }
77 80
78 /** 81 /**
79 * 82 *
80 * @param {!WebInspector.TextRange} outterRange 83 * @param {!WebInspector.TextRange} outterRange
81 * @param {!WebInspector.TextRange} innerRange 84 * @param {!WebInspector.TextRange} innerRange
82 * @return {boolean} 85 * @return {boolean}
83 */ 86 */
84 _checkRanges: function(outterRange, innerRange) 87 _checkRanges(outterRange, innerRange) {
85 { 88 var startsBefore = outterRange.startLine < innerRange.startLine ||
86 var startsBefore = outterRange.startLine < innerRange.startLine || (outt erRange.startLine === innerRange.startLine && outterRange.startColumn <= innerRa nge.startColumn); 89 (outterRange.startLine === innerRange.startLine && outterRange.startColu mn <= innerRange.startColumn);
87 // SSP might be outdated, so inner range will a bit bigger than outter. E.g.; "padding-left: 9px" -> "padding-left: 10px" 90 // SSP might be outdated, so inner range will a bit bigger than outter. E.g. ; "padding-left: 9px" -> "padding-left: 10px"
88 var eps = 5; 91 var eps = 5;
89 var endsAfter = outterRange.endLine > innerRange.endLine || (outterRange .endLine === innerRange.endLine && outterRange.endColumn + eps >= innerRange.end Column); 92 var endsAfter = outterRange.endLine > innerRange.endLine ||
90 return startsBefore && endsAfter; 93 (outterRange.endLine === innerRange.endLine && outterRange.endColumn + e ps >= innerRange.endColumn);
91 } 94 return startsBefore && endsAfter;
95 }
92 }; 96 };
93 97
94 /** 98 /**
95 * @constructor 99 * @unrestricted
96 * @param {!WebInspector.StylesSidebarPane} ssp
97 * @param {!WebInspector.CSSProperty} cssProperty
98 */ 100 */
99 WebInspector.PropertyRevealHighlighter = function(ssp, cssProperty) 101 WebInspector.PropertyRevealHighlighter = class {
100 { 102 /**
103 * @param {!WebInspector.StylesSidebarPane} ssp
104 * @param {!WebInspector.CSSProperty} cssProperty
105 */
106 constructor(ssp, cssProperty) {
101 this._styleSidebarPane = ssp; 107 this._styleSidebarPane = ssp;
102 this._cssProperty = cssProperty; 108 this._cssProperty = cssProperty;
109 }
110
111 perform() {
112 // Expand all shorthands.
113 for (var section of this._styleSidebarPane.allSections()) {
114 for (var treeElement = section.propertiesTreeOutline.firstChild(); treeEle ment;
115 treeElement = treeElement.nextSibling)
116 treeElement.onpopulate();
117 }
118 var highlightTreeElement = null;
119 for (var section of this._styleSidebarPane.allSections()) {
120 var treeElement = section.propertiesTreeOutline.firstChild();
121 while (treeElement && !highlightTreeElement) {
122 if (treeElement.property === this._cssProperty) {
123 highlightTreeElement = treeElement;
124 break;
125 }
126 treeElement = treeElement.traverseNextTreeElement(false, null, true);
127 }
128 if (highlightTreeElement)
129 break;
130 }
131
132 if (!highlightTreeElement)
133 return;
134
135 highlightTreeElement.parent.expand();
136 highlightTreeElement.listItemElement.scrollIntoViewIfNeeded();
137 highlightTreeElement.listItemElement.animate(
138 [
139 {offset: 0, backgroundColor: 'rgba(255, 255, 0, 0.2)'},
140 {offset: 0.1, backgroundColor: 'rgba(255, 255, 0, 0.7)'}, {offset: 1, backgroundColor: 'transparent'}
141 ],
142 {duration: 2000, easing: 'cubic-bezier(0, 0, 0.2, 1)'});
143 }
103 }; 144 };
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)
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