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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/BezierEditor.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots 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 /** 4 /**
5 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 WebInspector.BezierEditor = class extends WebInspector.VBox { 7 UI.BezierEditor = class extends UI.VBox {
8 constructor() { 8 constructor() {
9 super(true); 9 super(true);
10 this.registerRequiredCSS('ui/bezierEditor.css'); 10 this.registerRequiredCSS('ui/bezierEditor.css');
11 this.contentElement.tabIndex = 0; 11 this.contentElement.tabIndex = 0;
12 12
13 // Preview UI 13 // Preview UI
14 this._previewElement = this.contentElement.createChild('div', 'bezier-previe w-container'); 14 this._previewElement = this.contentElement.createChild('div', 'bezier-previe w-container');
15 this._previewElement.createChild('div', 'bezier-preview-animation'); 15 this._previewElement.createChild('div', 'bezier-preview-animation');
16 this._previewElement.addEventListener('click', this._startPreviewAnimation.b ind(this)); 16 this._previewElement.addEventListener('click', this._startPreviewAnimation.b ind(this));
17 this._previewOnion = this.contentElement.createChild('div', 'bezier-preview- onion'); 17 this._previewOnion = this.contentElement.createChild('div', 'bezier-preview- onion');
18 this._previewOnion.addEventListener('click', this._startPreviewAnimation.bin d(this)); 18 this._previewOnion.addEventListener('click', this._startPreviewAnimation.bin d(this));
19 19
20 this._outerContainer = this.contentElement.createChild('div', 'bezier-contai ner'); 20 this._outerContainer = this.contentElement.createChild('div', 'bezier-contai ner');
21 21
22 // Presets UI 22 // Presets UI
23 this._presetsContainer = this._outerContainer.createChild('div', 'bezier-pre sets'); 23 this._presetsContainer = this._outerContainer.createChild('div', 'bezier-pre sets');
24 this._presetUI = new WebInspector.BezierUI(40, 40, 0, 2, false); 24 this._presetUI = new UI.BezierUI(40, 40, 0, 2, false);
25 this._presetCategories = []; 25 this._presetCategories = [];
26 for (var i = 0; i < WebInspector.BezierEditor.Presets.length; i++) { 26 for (var i = 0; i < UI.BezierEditor.Presets.length; i++) {
27 this._presetCategories[i] = this._createCategory(WebInspector.BezierEditor .Presets[i]); 27 this._presetCategories[i] = this._createCategory(UI.BezierEditor.Presets[i ]);
28 this._presetsContainer.appendChild(this._presetCategories[i].icon); 28 this._presetsContainer.appendChild(this._presetCategories[i].icon);
29 } 29 }
30 30
31 // Curve UI 31 // Curve UI
32 this._curveUI = new WebInspector.BezierUI(150, 250, 50, 7, true); 32 this._curveUI = new UI.BezierUI(150, 250, 50, 7, true);
33 this._curve = this._outerContainer.createSVGChild('svg', 'bezier-curve'); 33 this._curve = this._outerContainer.createSVGChild('svg', 'bezier-curve');
34 WebInspector.installDragHandle( 34 UI.installDragHandle(
35 this._curve, this._dragStart.bind(this), this._dragMove.bind(this), this ._dragEnd.bind(this), 'default'); 35 this._curve, this._dragStart.bind(this), this._dragMove.bind(this), this ._dragEnd.bind(this), 'default');
36 36
37 this._header = this.contentElement.createChild('div', 'bezier-header'); 37 this._header = this.contentElement.createChild('div', 'bezier-header');
38 var minus = this._createPresetModifyIcon(this._header, 'bezier-preset-minus' , 'M 12 6 L 8 10 L 12 14'); 38 var minus = this._createPresetModifyIcon(this._header, 'bezier-preset-minus' , 'M 12 6 L 8 10 L 12 14');
39 var plus = this._createPresetModifyIcon(this._header, 'bezier-preset-plus', 'M 8 6 L 12 10 L 8 14'); 39 var plus = this._createPresetModifyIcon(this._header, 'bezier-preset-plus', 'M 8 6 L 12 10 L 8 14');
40 minus.addEventListener('click', this._presetModifyClicked.bind(this, false)) ; 40 minus.addEventListener('click', this._presetModifyClicked.bind(this, false)) ;
41 plus.addEventListener('click', this._presetModifyClicked.bind(this, true)); 41 plus.addEventListener('click', this._presetModifyClicked.bind(this, true));
42 this._label = this._header.createChild('span', 'source-code bezier-display-v alue'); 42 this._label = this._header.createChild('span', 'source-code bezier-display-v alue');
43 } 43 }
44 44
45 /** 45 /**
46 * @param {?WebInspector.Geometry.CubicBezier} bezier 46 * @param {?Common.Geometry.CubicBezier} bezier
47 */ 47 */
48 setBezier(bezier) { 48 setBezier(bezier) {
49 if (!bezier) 49 if (!bezier)
50 return; 50 return;
51 this._bezier = bezier; 51 this._bezier = bezier;
52 this._updateUI(); 52 this._updateUI();
53 } 53 }
54 54
55 /** 55 /**
56 * @return {!WebInspector.Geometry.CubicBezier} 56 * @return {!Common.Geometry.CubicBezier}
57 */ 57 */
58 bezier() { 58 bezier() {
59 return this._bezier; 59 return this._bezier;
60 } 60 }
61 61
62 /** 62 /**
63 * @override 63 * @override
64 */ 64 */
65 wasShown() { 65 wasShown() {
66 this._unselectPresets(); 66 this._unselectPresets();
67 // Check if bezier matches a preset 67 // Check if bezier matches a preset
68 for (var category of this._presetCategories) { 68 for (var category of this._presetCategories) {
69 for (var i = 0; i < category.presets.length; i++) { 69 for (var i = 0; i < category.presets.length; i++) {
70 if (this._bezier.asCSSText() === category.presets[i].value) { 70 if (this._bezier.asCSSText() === category.presets[i].value) {
71 category.presetIndex = i; 71 category.presetIndex = i;
72 this._presetCategorySelected(category); 72 this._presetCategorySelected(category);
73 } 73 }
74 } 74 }
75 } 75 }
76 76
77 this._updateUI(); 77 this._updateUI();
78 this._startPreviewAnimation(); 78 this._startPreviewAnimation();
79 } 79 }
80 80
81 _onchange() { 81 _onchange() {
82 this._updateUI(); 82 this._updateUI();
83 this.dispatchEventToListeners(WebInspector.BezierEditor.Events.BezierChanged , this._bezier.asCSSText()); 83 this.dispatchEventToListeners(UI.BezierEditor.Events.BezierChanged, this._be zier.asCSSText());
84 } 84 }
85 85
86 _updateUI() { 86 _updateUI() {
87 var labelText = this._selectedCategory ? this._selectedCategory.presets[this ._selectedCategory.presetIndex].name : 87 var labelText = this._selectedCategory ? this._selectedCategory.presets[this ._selectedCategory.presetIndex].name :
88 this._bezier.asCSSText().replace(/\ s(-\d\.\d)/g, '$1'); 88 this._bezier.asCSSText().replace(/\ s(-\d\.\d)/g, '$1');
89 this._label.textContent = WebInspector.UIString(labelText); 89 this._label.textContent = Common.UIString(labelText);
90 this._curveUI.drawCurve(this._bezier, this._curve); 90 this._curveUI.drawCurve(this._bezier, this._curve);
91 this._previewOnion.removeChildren(); 91 this._previewOnion.removeChildren();
92 } 92 }
93 93
94 /** 94 /**
95 * @param {!Event} event 95 * @param {!Event} event
96 * @return {boolean} 96 * @return {boolean}
97 */ 97 */
98 _dragStart(event) { 98 _dragStart(event) {
99 this._mouseDownPosition = new WebInspector.Geometry.Point(event.x, event.y); 99 this._mouseDownPosition = new Common.Geometry.Point(event.x, event.y);
100 var ui = this._curveUI; 100 var ui = this._curveUI;
101 this._controlPosition = new WebInspector.Geometry.Point( 101 this._controlPosition = new Common.Geometry.Point(
102 Number.constrain((event.offsetX - ui.radius) / ui.curveWidth(), 0, 1), 102 Number.constrain((event.offsetX - ui.radius) / ui.curveWidth(), 0, 1),
103 (ui.curveHeight() + ui.marginTop + ui.radius - event.offsetY) / ui.curve Height()); 103 (ui.curveHeight() + ui.marginTop + ui.radius - event.offsetY) / ui.curve Height());
104 104
105 var firstControlPointIsCloser = this._controlPosition.distanceTo(this._bezie r.controlPoints[0]) < 105 var firstControlPointIsCloser = this._controlPosition.distanceTo(this._bezie r.controlPoints[0]) <
106 this._controlPosition.distanceTo(this._bezier.controlPoints[1]); 106 this._controlPosition.distanceTo(this._bezier.controlPoints[1]);
107 this._selectedPoint = firstControlPointIsCloser ? 0 : 1; 107 this._selectedPoint = firstControlPointIsCloser ? 0 : 1;
108 108
109 this._bezier.controlPoints[this._selectedPoint] = this._controlPosition; 109 this._bezier.controlPoints[this._selectedPoint] = this._controlPosition;
110 this._unselectPresets(); 110 this._unselectPresets();
111 this._onchange(); 111 this._onchange();
112 112
113 event.consume(true); 113 event.consume(true);
114 return true; 114 return true;
115 } 115 }
116 116
117 /** 117 /**
118 * @param {number} mouseX 118 * @param {number} mouseX
119 * @param {number} mouseY 119 * @param {number} mouseY
120 */ 120 */
121 _updateControlPosition(mouseX, mouseY) { 121 _updateControlPosition(mouseX, mouseY) {
122 var deltaX = (mouseX - this._mouseDownPosition.x) / this._curveUI.curveWidth (); 122 var deltaX = (mouseX - this._mouseDownPosition.x) / this._curveUI.curveWidth ();
123 var deltaY = (mouseY - this._mouseDownPosition.y) / this._curveUI.curveHeigh t(); 123 var deltaY = (mouseY - this._mouseDownPosition.y) / this._curveUI.curveHeigh t();
124 var newPosition = new WebInspector.Geometry.Point( 124 var newPosition = new Common.Geometry.Point(
125 Number.constrain(this._controlPosition.x + deltaX, 0, 1), this._controlP osition.y - deltaY); 125 Number.constrain(this._controlPosition.x + deltaX, 0, 1), this._controlP osition.y - deltaY);
126 this._bezier.controlPoints[this._selectedPoint] = newPosition; 126 this._bezier.controlPoints[this._selectedPoint] = newPosition;
127 } 127 }
128 128
129 /** 129 /**
130 * @param {!Event} event 130 * @param {!Event} event
131 */ 131 */
132 _dragMove(event) { 132 _dragMove(event) {
133 this._updateControlPosition(event.x, event.y); 133 this._updateControlPosition(event.x, event.y);
134 this._onchange(); 134 this._onchange();
135 } 135 }
136 136
137 /** 137 /**
138 * @param {!Event} event 138 * @param {!Event} event
139 */ 139 */
140 _dragEnd(event) { 140 _dragEnd(event) {
141 this._updateControlPosition(event.x, event.y); 141 this._updateControlPosition(event.x, event.y);
142 this._onchange(); 142 this._onchange();
143 this._startPreviewAnimation(); 143 this._startPreviewAnimation();
144 } 144 }
145 145
146 /** 146 /**
147 * @param {!Array<{name: string, value: string}>} presetGroup 147 * @param {!Array<{name: string, value: string}>} presetGroup
148 * @return {!WebInspector.BezierEditor.PresetCategory} 148 * @return {!UI.BezierEditor.PresetCategory}
149 */ 149 */
150 _createCategory(presetGroup) { 150 _createCategory(presetGroup) {
151 var presetElement = createElementWithClass('div', 'bezier-preset-category'); 151 var presetElement = createElementWithClass('div', 'bezier-preset-category');
152 var iconElement = presetElement.createSVGChild('svg', 'bezier-preset monospa ce'); 152 var iconElement = presetElement.createSVGChild('svg', 'bezier-preset monospa ce');
153 var category = {presets: presetGroup, presetIndex: 0, icon: presetElement}; 153 var category = {presets: presetGroup, presetIndex: 0, icon: presetElement};
154 this._presetUI.drawCurve(WebInspector.Geometry.CubicBezier.parse(category.pr esets[0].value), iconElement); 154 this._presetUI.drawCurve(Common.Geometry.CubicBezier.parse(category.presets[ 0].value), iconElement);
155 iconElement.addEventListener('click', this._presetCategorySelected.bind(this , category)); 155 iconElement.addEventListener('click', this._presetCategorySelected.bind(this , category));
156 return category; 156 return category;
157 } 157 }
158 158
159 /** 159 /**
160 * @param {!Element} parentElement 160 * @param {!Element} parentElement
161 * @param {string} className 161 * @param {string} className
162 * @param {string} drawPath 162 * @param {string} drawPath
163 * @return {!Element} 163 * @return {!Element}
164 */ 164 */
165 _createPresetModifyIcon(parentElement, className, drawPath) { 165 _createPresetModifyIcon(parentElement, className, drawPath) {
166 var icon = parentElement.createSVGChild('svg', 'bezier-preset-modify ' + cla ssName); 166 var icon = parentElement.createSVGChild('svg', 'bezier-preset-modify ' + cla ssName);
167 icon.setAttribute('width', 20); 167 icon.setAttribute('width', 20);
168 icon.setAttribute('height', 20); 168 icon.setAttribute('height', 20);
169 var path = icon.createSVGChild('path'); 169 var path = icon.createSVGChild('path');
170 path.setAttribute('d', drawPath); 170 path.setAttribute('d', drawPath);
171 return icon; 171 return icon;
172 } 172 }
173 173
174 _unselectPresets() { 174 _unselectPresets() {
175 for (var category of this._presetCategories) 175 for (var category of this._presetCategories)
176 category.icon.classList.remove('bezier-preset-selected'); 176 category.icon.classList.remove('bezier-preset-selected');
177 delete this._selectedCategory; 177 delete this._selectedCategory;
178 this._header.classList.remove('bezier-header-active'); 178 this._header.classList.remove('bezier-header-active');
179 } 179 }
180 180
181 /** 181 /**
182 * @param {!WebInspector.BezierEditor.PresetCategory} category 182 * @param {!UI.BezierEditor.PresetCategory} category
183 * @param {!Event=} event 183 * @param {!Event=} event
184 */ 184 */
185 _presetCategorySelected(category, event) { 185 _presetCategorySelected(category, event) {
186 if (this._selectedCategory === category) 186 if (this._selectedCategory === category)
187 return; 187 return;
188 this._unselectPresets(); 188 this._unselectPresets();
189 this._header.classList.add('bezier-header-active'); 189 this._header.classList.add('bezier-header-active');
190 this._selectedCategory = category; 190 this._selectedCategory = category;
191 this._selectedCategory.icon.classList.add('bezier-preset-selected'); 191 this._selectedCategory.icon.classList.add('bezier-preset-selected');
192 this.setBezier(WebInspector.Geometry.CubicBezier.parse(category.presets[cate gory.presetIndex].value)); 192 this.setBezier(Common.Geometry.CubicBezier.parse(category.presets[category.p resetIndex].value));
193 this._onchange(); 193 this._onchange();
194 this._startPreviewAnimation(); 194 this._startPreviewAnimation();
195 if (event) 195 if (event)
196 event.consume(true); 196 event.consume(true);
197 } 197 }
198 198
199 /** 199 /**
200 * @param {boolean} intensify 200 * @param {boolean} intensify
201 * @param {!Event} event 201 * @param {!Event} event
202 */ 202 */
203 _presetModifyClicked(intensify, event) { 203 _presetModifyClicked(intensify, event) {
204 if (!this._selectedCategory) 204 if (!this._selectedCategory)
205 return; 205 return;
206 206
207 var length = this._selectedCategory.presets.length; 207 var length = this._selectedCategory.presets.length;
208 this._selectedCategory.presetIndex = (this._selectedCategory.presetIndex + ( intensify ? 1 : -1) + length) % length; 208 this._selectedCategory.presetIndex = (this._selectedCategory.presetIndex + ( intensify ? 1 : -1) + length) % length;
209 this.setBezier(WebInspector.Geometry.CubicBezier.parse( 209 this.setBezier(Common.Geometry.CubicBezier.parse(
210 this._selectedCategory.presets[this._selectedCategory.presetIndex].value )); 210 this._selectedCategory.presets[this._selectedCategory.presetIndex].value ));
211 this._onchange(); 211 this._onchange();
212 this._startPreviewAnimation(); 212 this._startPreviewAnimation();
213 } 213 }
214 214
215 _startPreviewAnimation() { 215 _startPreviewAnimation() {
216 if (this._previewAnimation) 216 if (this._previewAnimation)
217 this._previewAnimation.cancel(); 217 this._previewAnimation.cancel();
218 218
219 const animationDuration = 1600; 219 const animationDuration = 1600;
(...skipping 11 matching lines...) Expand all
231 var player = slice.animate( 231 var player = slice.animate(
232 [{transform: 'translateX(0px)', easing: this._bezier.asCSSText()}, {tr ansform: 'translateX(218px)'}], 232 [{transform: 'translateX(0px)', easing: this._bezier.asCSSText()}, {tr ansform: 'translateX(218px)'}],
233 {duration: animationDuration, fill: 'forwards'}); 233 {duration: animationDuration, fill: 'forwards'});
234 player.pause(); 234 player.pause();
235 player.currentTime = animationDuration * i / numberOnionSlices; 235 player.currentTime = animationDuration * i / numberOnionSlices;
236 } 236 }
237 } 237 }
238 }; 238 };
239 239
240 /** @enum {symbol} */ 240 /** @enum {symbol} */
241 WebInspector.BezierEditor.Events = { 241 UI.BezierEditor.Events = {
242 BezierChanged: Symbol('BezierChanged') 242 BezierChanged: Symbol('BezierChanged')
243 }; 243 };
244 244
245 WebInspector.BezierEditor.Presets = [ 245 UI.BezierEditor.Presets = [
246 [ 246 [
247 {name: 'ease-in-out', value: 'ease-in-out'}, {name: 'In Out · Sine', value: 'cubic-bezier(0.45, 0.05, 0.55, 0.95)'}, 247 {name: 'ease-in-out', value: 'ease-in-out'}, {name: 'In Out · Sine', value: 'cubic-bezier(0.45, 0.05, 0.55, 0.95)'},
248 {name: 'In Out · Quadratic', value: 'cubic-bezier(0.46, 0.03, 0.52, 0.96)'}, 248 {name: 'In Out · Quadratic', value: 'cubic-bezier(0.46, 0.03, 0.52, 0.96)'},
249 {name: 'In Out · Cubic', value: 'cubic-bezier(0.65, 0.05, 0.36, 1)'}, 249 {name: 'In Out · Cubic', value: 'cubic-bezier(0.65, 0.05, 0.36, 1)'},
250 {name: 'Fast Out, Slow In', value: 'cubic-bezier(0.4, 0, 0.2, 1)'}, 250 {name: 'Fast Out, Slow In', value: 'cubic-bezier(0.4, 0, 0.2, 1)'},
251 {name: 'In Out · Back', value: 'cubic-bezier(0.68, -0.55, 0.27, 1.55)'} 251 {name: 'In Out · Back', value: 'cubic-bezier(0.68, -0.55, 0.27, 1.55)'}
252 ], 252 ],
253 [ 253 [
254 {name: 'Fast Out, Linear In', value: 'cubic-bezier(0.4, 0, 1, 1)'}, {name: ' ease-in', value: 'ease-in'}, 254 {name: 'Fast Out, Linear In', value: 'cubic-bezier(0.4, 0, 1, 1)'}, {name: ' ease-in', value: 'ease-in'},
255 {name: 'In · Sine', value: 'cubic-bezier(0.47, 0, 0.75, 0.72)'}, 255 {name: 'In · Sine', value: 'cubic-bezier(0.47, 0, 0.75, 0.72)'},
256 {name: 'In · Quadratic', value: 'cubic-bezier(0.55, 0.09, 0.68, 0.53)'}, 256 {name: 'In · Quadratic', value: 'cubic-bezier(0.55, 0.09, 0.68, 0.53)'},
257 {name: 'In · Cubic', value: 'cubic-bezier(0.55, 0.06, 0.68, 0.19)'}, 257 {name: 'In · Cubic', value: 'cubic-bezier(0.55, 0.06, 0.68, 0.19)'},
258 {name: 'In · Back', value: 'cubic-bezier(0.6, -0.28, 0.74, 0.05)'} 258 {name: 'In · Back', value: 'cubic-bezier(0.6, -0.28, 0.74, 0.05)'}
259 ], 259 ],
260 [ 260 [
261 {name: 'ease-out', value: 'ease-out'}, {name: 'Out · Sine', value: 'cubic-be zier(0.39, 0.58, 0.57, 1)'}, 261 {name: 'ease-out', value: 'ease-out'}, {name: 'Out · Sine', value: 'cubic-be zier(0.39, 0.58, 0.57, 1)'},
262 {name: 'Out · Quadratic', value: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)'}, 262 {name: 'Out · Quadratic', value: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)'},
263 {name: 'Out · Cubic', value: 'cubic-bezier(0.22, 0.61, 0.36, 1)'}, 263 {name: 'Out · Cubic', value: 'cubic-bezier(0.22, 0.61, 0.36, 1)'},
264 {name: 'Linear Out, Slow In', value: 'cubic-bezier(0, 0, 0.2, 1)'}, 264 {name: 'Linear Out, Slow In', value: 'cubic-bezier(0, 0, 0.2, 1)'},
265 {name: 'Out · Back', value: 'cubic-bezier(0.18, 0.89, 0.32, 1.28)'} 265 {name: 'Out · Back', value: 'cubic-bezier(0.18, 0.89, 0.32, 1.28)'}
266 ] 266 ]
267 ]; 267 ];
268 268
269 /** @typedef {{presets: !Array.<{name: string, value: string}>, icon: !Element, presetIndex: number}} */ 269 /** @typedef {{presets: !Array.<{name: string, value: string}>, icon: !Element, presetIndex: number}} */
270 WebInspector.BezierEditor.PresetCategory; 270 UI.BezierEditor.PresetCategory;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698