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

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

Issue 2421983002: [DevTools] Remove layout editor experiment. (Closed)
Patch Set: rebased Created 4 years 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
(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 * @unrestricted
6 */
7 Elements.PropertyChangeHighlighter = class {
8 /**
9 * @param {!Elements.StylesSidebarPane} ssp
10 * @param {!SDK.CSSModel} cssModel
11 * @param {!Protocol.CSS.StyleSheetId} styleSheetId
12 * @param {!Common.TextRange} range
13 */
14 constructor(ssp, cssModel, styleSheetId, range) {
15 this._styleSidebarPane = ssp;
16 this._target = cssModel.target();
17 this._styleSheetId = styleSheetId;
18 this._range = range;
19 }
20
21 /**
22 */
23 perform() {
24 var node = this._styleSidebarPane.node();
25 if (!node || this._target !== node.target())
26 return;
27
28 var foundSection = null;
29 for (var section of this._styleSidebarPane.allSections()) {
30 var declaration = section.style();
31 if (declaration.styleSheetId !== this._styleSheetId)
32 continue;
33
34 var parentRule = declaration.parentRule;
35 var isInlineSelector = this._range.isEmpty();
36 var isMatchingRule =
37 parentRule && parentRule.selectorRange() && this._range.compareTo(pare ntRule.selectorRange()) === 0;
38 if (isInlineSelector || isMatchingRule) {
39 section.element.animate(
40 [
41 {offset: 0, backgroundColor: 'rgba(255, 227, 199, 1)'},
42 {offset: 0.5, backgroundColor: 'rgba(255, 227, 199, 1)'},
43 {offset: 0.9, backgroundColor: 'rgba(255, 227, 199, 0)'}, {offset: 1, backgroundColor: 'white'}
44 ],
45 {duration: 400, easing: 'cubic-bezier(0, 0, 0.2, 1)'});
46 return;
47 }
48
49 if (this._checkRanges(declaration.range, this._range)) {
50 foundSection = section;
51 break;
52 }
53 }
54
55 if (!foundSection)
56 return;
57
58 var highlightElement;
59 var treeElement = foundSection.propertiesTreeOutline.firstChild();
60 var foundTreeElement = null;
61 while (!highlightElement && treeElement) {
62 if (treeElement.property.range && this._checkRanges(treeElement.property.r ange, this._range)) {
63 highlightElement = treeElement.valueElement;
64 break;
65 }
66 treeElement = treeElement.traverseNextTreeElement(false, null, true);
67 }
68
69 if (highlightElement) {
70 highlightElement.animate(
71 [
72 {offset: 0, backgroundColor: 'rgba(158, 54, 153, 1)', color: 'white' },
73 {offset: 0.5, backgroundColor: 'rgba(158, 54, 153, 1)', color: 'whit e'},
74 {offset: 0.9, backgroundColor: 'rgba(158, 54, 153, 0)', color: 'init ial'},
75 {offset: 1, backgroundColor: 'white', color: 'initial'}
76 ],
77 {duration: 400, easing: 'cubic-bezier(0, 0, 0.2, 1)'});
78 }
79 }
80
81 /**
82 *
83 * @param {!Common.TextRange} outterRange
84 * @param {!Common.TextRange} innerRange
85 * @return {boolean}
86 */
87 _checkRanges(outterRange, innerRange) {
88 var startsBefore = outterRange.startLine < innerRange.startLine ||
89 (outterRange.startLine === innerRange.startLine && outterRange.startColu mn <= innerRange.startColumn);
90 // SSP might be outdated, so inner range will a bit bigger than outter. E.g. ; "padding-left: 9px" -> "padding-left: 10px"
91 var eps = 5;
92 var endsAfter = outterRange.endLine > innerRange.endLine ||
93 (outterRange.endLine === innerRange.endLine && outterRange.endColumn + e ps >= innerRange.endColumn);
94 return startsBefore && endsAfter;
95 }
96 };
97
98 /**
99 * @unrestricted
100 */
101 Elements.PropertyRevealHighlighter = class {
102 /**
103 * @param {!Elements.StylesSidebarPane} ssp
104 * @param {!SDK.CSSProperty} cssProperty
105 */
106 constructor(ssp, cssProperty) {
107 this._styleSidebarPane = ssp;
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 }
144 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698