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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/CSSShadowEditor.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.CSSShadowEditor = class extends WebInspector.VBox { 7 UI.CSSShadowEditor = class extends UI.VBox {
8 constructor() { 8 constructor() {
9 super(true); 9 super(true);
10 this.registerRequiredCSS('ui/cssShadowEditor.css'); 10 this.registerRequiredCSS('ui/cssShadowEditor.css');
11 this.contentElement.tabIndex = 0; 11 this.contentElement.tabIndex = 0;
12 12
13 this._typeField = this.contentElement.createChild('div', 'shadow-editor-fiel d'); 13 this._typeField = this.contentElement.createChild('div', 'shadow-editor-fiel d');
14 this._typeField.createChild('label', 'shadow-editor-label').textContent = We bInspector.UIString('Type'); 14 this._typeField.createChild('label', 'shadow-editor-label').textContent = Co mmon.UIString('Type');
15 this._outsetButton = this._typeField.createChild('button', 'shadow-editor-bu tton-left'); 15 this._outsetButton = this._typeField.createChild('button', 'shadow-editor-bu tton-left');
16 this._outsetButton.textContent = WebInspector.UIString('Outset'); 16 this._outsetButton.textContent = Common.UIString('Outset');
17 this._outsetButton.addEventListener('click', this._onButtonClick.bind(this), false); 17 this._outsetButton.addEventListener('click', this._onButtonClick.bind(this), false);
18 this._insetButton = this._typeField.createChild('button', 'shadow-editor-but ton-right'); 18 this._insetButton = this._typeField.createChild('button', 'shadow-editor-but ton-right');
19 this._insetButton.textContent = WebInspector.UIString('Inset'); 19 this._insetButton.textContent = Common.UIString('Inset');
20 this._insetButton.addEventListener('click', this._onButtonClick.bind(this), false); 20 this._insetButton.addEventListener('click', this._onButtonClick.bind(this), false);
21 21
22 var xField = this.contentElement.createChild('div', 'shadow-editor-field'); 22 var xField = this.contentElement.createChild('div', 'shadow-editor-field');
23 this._xInput = this._createTextInput(xField, WebInspector.UIString('X offset ')); 23 this._xInput = this._createTextInput(xField, Common.UIString('X offset'));
24 var yField = this.contentElement.createChild('div', 'shadow-editor-field'); 24 var yField = this.contentElement.createChild('div', 'shadow-editor-field');
25 this._yInput = this._createTextInput(yField, WebInspector.UIString('Y offset ')); 25 this._yInput = this._createTextInput(yField, Common.UIString('Y offset'));
26 this._xySlider = xField.createChild('canvas', 'shadow-editor-2D-slider'); 26 this._xySlider = xField.createChild('canvas', 'shadow-editor-2D-slider');
27 this._xySlider.width = WebInspector.CSSShadowEditor.canvasSize; 27 this._xySlider.width = UI.CSSShadowEditor.canvasSize;
28 this._xySlider.height = WebInspector.CSSShadowEditor.canvasSize; 28 this._xySlider.height = UI.CSSShadowEditor.canvasSize;
29 this._xySlider.tabIndex = -1; 29 this._xySlider.tabIndex = -1;
30 this._halfCanvasSize = WebInspector.CSSShadowEditor.canvasSize / 2; 30 this._halfCanvasSize = UI.CSSShadowEditor.canvasSize / 2;
31 this._innerCanvasSize = this._halfCanvasSize - WebInspector.CSSShadowEditor. sliderThumbRadius; 31 this._innerCanvasSize = this._halfCanvasSize - UI.CSSShadowEditor.sliderThum bRadius;
32 WebInspector.installDragHandle( 32 UI.installDragHandle(
33 this._xySlider, this._dragStart.bind(this), this._dragMove.bind(this), n ull, 'default'); 33 this._xySlider, this._dragStart.bind(this), this._dragMove.bind(this), n ull, 'default');
34 this._xySlider.addEventListener('keydown', this._onCanvasArrowKey.bind(this) , false); 34 this._xySlider.addEventListener('keydown', this._onCanvasArrowKey.bind(this) , false);
35 this._xySlider.addEventListener('blur', this._onCanvasBlur.bind(this), false ); 35 this._xySlider.addEventListener('blur', this._onCanvasBlur.bind(this), false );
36 36
37 var blurField = this.contentElement.createChild('div', 'shadow-editor-blur-f ield'); 37 var blurField = this.contentElement.createChild('div', 'shadow-editor-blur-f ield');
38 this._blurInput = this._createTextInput(blurField, WebInspector.UIString('Bl ur')); 38 this._blurInput = this._createTextInput(blurField, Common.UIString('Blur'));
39 this._blurSlider = this._createSlider(blurField); 39 this._blurSlider = this._createSlider(blurField);
40 40
41 this._spreadField = this.contentElement.createChild('div', 'shadow-editor-fi eld'); 41 this._spreadField = this.contentElement.createChild('div', 'shadow-editor-fi eld');
42 this._spreadInput = this._createTextInput(this._spreadField, WebInspector.UI String('Spread')); 42 this._spreadInput = this._createTextInput(this._spreadField, Common.UIString ('Spread'));
43 this._spreadSlider = this._createSlider(this._spreadField); 43 this._spreadSlider = this._createSlider(this._spreadField);
44 } 44 }
45 45
46 /** 46 /**
47 * @param {!Element} field 47 * @param {!Element} field
48 * @param {string} propertyName 48 * @param {string} propertyName
49 * @return {!Element} 49 * @return {!Element}
50 */ 50 */
51 _createTextInput(field, propertyName) { 51 _createTextInput(field, propertyName) {
52 var label = field.createChild('label', 'shadow-editor-label'); 52 var label = field.createChild('label', 'shadow-editor-label');
53 label.textContent = propertyName; 53 label.textContent = propertyName;
54 label.setAttribute('for', propertyName); 54 label.setAttribute('for', propertyName);
55 var textInput = field.createChild('input', 'shadow-editor-text-input'); 55 var textInput = field.createChild('input', 'shadow-editor-text-input');
56 textInput.type = 'text'; 56 textInput.type = 'text';
57 textInput.id = propertyName; 57 textInput.id = propertyName;
58 textInput.addEventListener('keydown', this._handleValueModification.bind(thi s), false); 58 textInput.addEventListener('keydown', this._handleValueModification.bind(thi s), false);
59 textInput.addEventListener('mousewheel', this._handleValueModification.bind( this), false); 59 textInput.addEventListener('mousewheel', this._handleValueModification.bind( this), false);
60 textInput.addEventListener('input', this._onTextInput.bind(this), false); 60 textInput.addEventListener('input', this._onTextInput.bind(this), false);
61 textInput.addEventListener('blur', this._onTextBlur.bind(this), false); 61 textInput.addEventListener('blur', this._onTextBlur.bind(this), false);
62 return textInput; 62 return textInput;
63 } 63 }
64 64
65 /** 65 /**
66 * @param {!Element} field 66 * @param {!Element} field
67 * @return {!Element} 67 * @return {!Element}
68 */ 68 */
69 _createSlider(field) { 69 _createSlider(field) {
70 var slider = createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange, -1) ; 70 var slider = createSliderLabel(0, UI.CSSShadowEditor.maxRange, -1);
71 slider.addEventListener('input', this._onSliderInput.bind(this), false); 71 slider.addEventListener('input', this._onSliderInput.bind(this), false);
72 field.appendChild(slider); 72 field.appendChild(slider);
73 return slider; 73 return slider;
74 } 74 }
75 75
76 /** 76 /**
77 * @override 77 * @override
78 */ 78 */
79 wasShown() { 79 wasShown() {
80 this._updateUI(); 80 this._updateUI();
81 } 81 }
82 82
83 /** 83 /**
84 * @param {!WebInspector.CSSShadowModel} model 84 * @param {!Common.CSSShadowModel} model
85 */ 85 */
86 setModel(model) { 86 setModel(model) {
87 this._model = model; 87 this._model = model;
88 this._typeField.hidden = !model.isBoxShadow(); 88 this._typeField.hidden = !model.isBoxShadow();
89 this._spreadField.hidden = !model.isBoxShadow(); 89 this._spreadField.hidden = !model.isBoxShadow();
90 this._updateUI(); 90 this._updateUI();
91 } 91 }
92 92
93 _updateUI() { 93 _updateUI() {
94 this._updateButtons(); 94 this._updateButtons();
(...skipping 17 matching lines...) Expand all
112 _updateCanvas(drawFocus) { 112 _updateCanvas(drawFocus) {
113 var context = this._xySlider.getContext('2d'); 113 var context = this._xySlider.getContext('2d');
114 context.clearRect(0, 0, this._xySlider.width, this._xySlider.height); 114 context.clearRect(0, 0, this._xySlider.width, this._xySlider.height);
115 115
116 // Draw dashed axes. 116 // Draw dashed axes.
117 context.save(); 117 context.save();
118 context.setLineDash([1, 1]); 118 context.setLineDash([1, 1]);
119 context.strokeStyle = 'rgba(210, 210, 210, 0.8)'; 119 context.strokeStyle = 'rgba(210, 210, 210, 0.8)';
120 context.beginPath(); 120 context.beginPath();
121 context.moveTo(this._halfCanvasSize, 0); 121 context.moveTo(this._halfCanvasSize, 0);
122 context.lineTo(this._halfCanvasSize, WebInspector.CSSShadowEditor.canvasSize ); 122 context.lineTo(this._halfCanvasSize, UI.CSSShadowEditor.canvasSize);
123 context.moveTo(0, this._halfCanvasSize); 123 context.moveTo(0, this._halfCanvasSize);
124 context.lineTo(WebInspector.CSSShadowEditor.canvasSize, this._halfCanvasSize ); 124 context.lineTo(UI.CSSShadowEditor.canvasSize, this._halfCanvasSize);
125 context.stroke(); 125 context.stroke();
126 context.restore(); 126 context.restore();
127 127
128 var thumbPoint = this._sliderThumbPosition(); 128 var thumbPoint = this._sliderThumbPosition();
129 // Draw 2D slider line. 129 // Draw 2D slider line.
130 context.save(); 130 context.save();
131 context.translate(this._halfCanvasSize, this._halfCanvasSize); 131 context.translate(this._halfCanvasSize, this._halfCanvasSize);
132 context.lineWidth = 2; 132 context.lineWidth = 2;
133 context.strokeStyle = 'rgba(130, 130, 130, 0.75)'; 133 context.strokeStyle = 'rgba(130, 130, 130, 0.75)';
134 context.beginPath(); 134 context.beginPath();
135 context.moveTo(0, 0); 135 context.moveTo(0, 0);
136 context.lineTo(thumbPoint.x, thumbPoint.y); 136 context.lineTo(thumbPoint.x, thumbPoint.y);
137 context.stroke(); 137 context.stroke();
138 // Draw 2D slider thumb. 138 // Draw 2D slider thumb.
139 if (drawFocus) { 139 if (drawFocus) {
140 context.beginPath(); 140 context.beginPath();
141 context.fillStyle = 'rgba(66, 133, 244, 0.4)'; 141 context.fillStyle = 'rgba(66, 133, 244, 0.4)';
142 context.arc(thumbPoint.x, thumbPoint.y, WebInspector.CSSShadowEditor.slide rThumbRadius + 2, 0, 2 * Math.PI); 142 context.arc(thumbPoint.x, thumbPoint.y, UI.CSSShadowEditor.sliderThumbRadi us + 2, 0, 2 * Math.PI);
143 context.fill(); 143 context.fill();
144 } 144 }
145 context.beginPath(); 145 context.beginPath();
146 context.fillStyle = '#4285F4'; 146 context.fillStyle = '#4285F4';
147 context.arc(thumbPoint.x, thumbPoint.y, WebInspector.CSSShadowEditor.sliderT humbRadius, 0, 2 * Math.PI); 147 context.arc(thumbPoint.x, thumbPoint.y, UI.CSSShadowEditor.sliderThumbRadius , 0, 2 * Math.PI);
148 context.fill(); 148 context.fill();
149 context.restore(); 149 context.restore();
150 } 150 }
151 151
152 /** 152 /**
153 * @param {!Event} event 153 * @param {!Event} event
154 */ 154 */
155 _onButtonClick(event) { 155 _onButtonClick(event) {
156 var insetClicked = (event.currentTarget === this._insetButton); 156 var insetClicked = (event.currentTarget === this._insetButton);
157 if (insetClicked && this._model.inset() || !insetClicked && !this._model.ins et()) 157 if (insetClicked && this._model.inset() || !insetClicked && !this._model.ins et())
158 return; 158 return;
159 this._model.setInset(insetClicked); 159 this._model.setInset(insetClicked);
160 this._updateButtons(); 160 this._updateButtons();
161 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.ShadowChan ged, this._model); 161 this.dispatchEventToListeners(UI.CSSShadowEditor.Events.ShadowChanged, this. _model);
162 } 162 }
163 163
164 /** 164 /**
165 * @param {!Event} event 165 * @param {!Event} event
166 */ 166 */
167 _handleValueModification(event) { 167 _handleValueModification(event) {
168 var modifiedValue = WebInspector.createReplacementString(event.currentTarget .value, event, customNumberHandler); 168 var modifiedValue = UI.createReplacementString(event.currentTarget.value, ev ent, customNumberHandler);
169 if (!modifiedValue) 169 if (!modifiedValue)
170 return; 170 return;
171 var length = WebInspector.CSSLength.parse(modifiedValue); 171 var length = Common.CSSLength.parse(modifiedValue);
172 if (!length) 172 if (!length)
173 return; 173 return;
174 if (event.currentTarget === this._blurInput && length.amount < 0) 174 if (event.currentTarget === this._blurInput && length.amount < 0)
175 length.amount = 0; 175 length.amount = 0;
176 event.currentTarget.value = length.asCSSText(); 176 event.currentTarget.value = length.asCSSText();
177 event.currentTarget.selectionStart = 0; 177 event.currentTarget.selectionStart = 0;
178 event.currentTarget.selectionEnd = event.currentTarget.value.length; 178 event.currentTarget.selectionEnd = event.currentTarget.value.length;
179 this._onTextInput(event); 179 this._onTextInput(event);
180 event.consume(true); 180 event.consume(true);
181 181
182 /** 182 /**
183 * @param {string} prefix 183 * @param {string} prefix
184 * @param {number} number 184 * @param {number} number
185 * @param {string} suffix 185 * @param {string} suffix
186 * @return {string} 186 * @return {string}
187 */ 187 */
188 function customNumberHandler(prefix, number, suffix) { 188 function customNumberHandler(prefix, number, suffix) {
189 if (!suffix.length) 189 if (!suffix.length)
190 suffix = WebInspector.CSSShadowEditor.defaultUnit; 190 suffix = UI.CSSShadowEditor.defaultUnit;
191 return prefix + number + suffix; 191 return prefix + number + suffix;
192 } 192 }
193 } 193 }
194 194
195 /** 195 /**
196 * @param {!Event} event 196 * @param {!Event} event
197 */ 197 */
198 _onTextInput(event) { 198 _onTextInput(event) {
199 this._changedElement = event.currentTarget; 199 this._changedElement = event.currentTarget;
200 this._changedElement.classList.remove('invalid'); 200 this._changedElement.classList.remove('invalid');
201 var length = WebInspector.CSSLength.parse(event.currentTarget.value); 201 var length = Common.CSSLength.parse(event.currentTarget.value);
202 if (!length || event.currentTarget === this._blurInput && length.amount < 0) 202 if (!length || event.currentTarget === this._blurInput && length.amount < 0)
203 return; 203 return;
204 if (event.currentTarget === this._xInput) { 204 if (event.currentTarget === this._xInput) {
205 this._model.setOffsetX(length); 205 this._model.setOffsetX(length);
206 this._updateCanvas(false); 206 this._updateCanvas(false);
207 } else if (event.currentTarget === this._yInput) { 207 } else if (event.currentTarget === this._yInput) {
208 this._model.setOffsetY(length); 208 this._model.setOffsetY(length);
209 this._updateCanvas(false); 209 this._updateCanvas(false);
210 } else if (event.currentTarget === this._blurInput) { 210 } else if (event.currentTarget === this._blurInput) {
211 this._model.setBlurRadius(length); 211 this._model.setBlurRadius(length);
212 this._blurSlider.value = length.amount; 212 this._blurSlider.value = length.amount;
213 } else if (event.currentTarget === this._spreadInput) { 213 } else if (event.currentTarget === this._spreadInput) {
214 this._model.setSpreadRadius(length); 214 this._model.setSpreadRadius(length);
215 this._spreadSlider.value = length.amount; 215 this._spreadSlider.value = length.amount;
216 } 216 }
217 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.ShadowChan ged, this._model); 217 this.dispatchEventToListeners(UI.CSSShadowEditor.Events.ShadowChanged, this. _model);
218 } 218 }
219 219
220 _onTextBlur() { 220 _onTextBlur() {
221 if (!this._changedElement) 221 if (!this._changedElement)
222 return; 222 return;
223 var length = !this._changedElement.value.trim() ? WebInspector.CSSLength.zer o() : 223 var length = !this._changedElement.value.trim() ? Common.CSSLength.zero() :
224 WebInspector.CSSLength.par se(this._changedElement.value); 224 Common.CSSLength.parse(thi s._changedElement.value);
225 if (!length) 225 if (!length)
226 length = WebInspector.CSSLength.parse(this._changedElement.value + WebInsp ector.CSSShadowEditor.defaultUnit); 226 length = Common.CSSLength.parse(this._changedElement.value + UI.CSSShadowE ditor.defaultUnit);
227 if (!length) { 227 if (!length) {
228 this._changedElement.classList.add('invalid'); 228 this._changedElement.classList.add('invalid');
229 this._changedElement = null; 229 this._changedElement = null;
230 return; 230 return;
231 } 231 }
232 if (this._changedElement === this._xInput) { 232 if (this._changedElement === this._xInput) {
233 this._model.setOffsetX(length); 233 this._model.setOffsetX(length);
234 this._xInput.value = length.asCSSText(); 234 this._xInput.value = length.asCSSText();
235 this._updateCanvas(false); 235 this._updateCanvas(false);
236 } else if (this._changedElement === this._yInput) { 236 } else if (this._changedElement === this._yInput) {
237 this._model.setOffsetY(length); 237 this._model.setOffsetY(length);
238 this._yInput.value = length.asCSSText(); 238 this._yInput.value = length.asCSSText();
239 this._updateCanvas(false); 239 this._updateCanvas(false);
240 } else if (this._changedElement === this._blurInput) { 240 } else if (this._changedElement === this._blurInput) {
241 if (length.amount < 0) 241 if (length.amount < 0)
242 length = WebInspector.CSSLength.zero(); 242 length = Common.CSSLength.zero();
243 this._model.setBlurRadius(length); 243 this._model.setBlurRadius(length);
244 this._blurInput.value = length.asCSSText(); 244 this._blurInput.value = length.asCSSText();
245 this._blurSlider.value = length.amount; 245 this._blurSlider.value = length.amount;
246 } else if (this._changedElement === this._spreadInput) { 246 } else if (this._changedElement === this._spreadInput) {
247 this._model.setSpreadRadius(length); 247 this._model.setSpreadRadius(length);
248 this._spreadInput.value = length.asCSSText(); 248 this._spreadInput.value = length.asCSSText();
249 this._spreadSlider.value = length.amount; 249 this._spreadSlider.value = length.amount;
250 } 250 }
251 this._changedElement = null; 251 this._changedElement = null;
252 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.ShadowChan ged, this._model); 252 this.dispatchEventToListeners(UI.CSSShadowEditor.Events.ShadowChanged, this. _model);
253 } 253 }
254 254
255 /** 255 /**
256 * @param {!Event} event 256 * @param {!Event} event
257 */ 257 */
258 _onSliderInput(event) { 258 _onSliderInput(event) {
259 if (event.currentTarget === this._blurSlider) { 259 if (event.currentTarget === this._blurSlider) {
260 this._model.setBlurRadius(new WebInspector.CSSLength( 260 this._model.setBlurRadius(new Common.CSSLength(
261 this._blurSlider.value, this._model.blurRadius().unit || WebInspector. CSSShadowEditor.defaultUnit)); 261 this._blurSlider.value, this._model.blurRadius().unit || UI.CSSShadowE ditor.defaultUnit));
262 this._blurInput.value = this._model.blurRadius().asCSSText(); 262 this._blurInput.value = this._model.blurRadius().asCSSText();
263 this._blurInput.classList.remove('invalid'); 263 this._blurInput.classList.remove('invalid');
264 } else if (event.currentTarget === this._spreadSlider) { 264 } else if (event.currentTarget === this._spreadSlider) {
265 this._model.setSpreadRadius(new WebInspector.CSSLength( 265 this._model.setSpreadRadius(new Common.CSSLength(
266 this._spreadSlider.value, this._model.spreadRadius().unit || WebInspec tor.CSSShadowEditor.defaultUnit)); 266 this._spreadSlider.value, this._model.spreadRadius().unit || UI.CSSSha dowEditor.defaultUnit));
267 this._spreadInput.value = this._model.spreadRadius().asCSSText(); 267 this._spreadInput.value = this._model.spreadRadius().asCSSText();
268 this._spreadInput.classList.remove('invalid'); 268 this._spreadInput.classList.remove('invalid');
269 } 269 }
270 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.ShadowChan ged, this._model); 270 this.dispatchEventToListeners(UI.CSSShadowEditor.Events.ShadowChanged, this. _model);
271 } 271 }
272 272
273 /** 273 /**
274 * @param {!MouseEvent} event 274 * @param {!MouseEvent} event
275 * @return {boolean} 275 * @return {boolean}
276 */ 276 */
277 _dragStart(event) { 277 _dragStart(event) {
278 this._xySlider.focus(); 278 this._xySlider.focus();
279 this._updateCanvas(true); 279 this._updateCanvas(true);
280 this._canvasOrigin = new WebInspector.Geometry.Point( 280 this._canvasOrigin = new Common.Geometry.Point(
281 this._xySlider.totalOffsetLeft() + this._halfCanvasSize, 281 this._xySlider.totalOffsetLeft() + this._halfCanvasSize,
282 this._xySlider.totalOffsetTop() + this._halfCanvasSize); 282 this._xySlider.totalOffsetTop() + this._halfCanvasSize);
283 var clickedPoint = new WebInspector.Geometry.Point(event.x - this._canvasOri gin.x, event.y - this._canvasOrigin.y); 283 var clickedPoint = new Common.Geometry.Point(event.x - this._canvasOrigin.x, event.y - this._canvasOrigin.y);
284 var thumbPoint = this._sliderThumbPosition(); 284 var thumbPoint = this._sliderThumbPosition();
285 if (clickedPoint.distanceTo(thumbPoint) >= WebInspector.CSSShadowEditor.slid erThumbRadius) 285 if (clickedPoint.distanceTo(thumbPoint) >= UI.CSSShadowEditor.sliderThumbRad ius)
286 this._dragMove(event); 286 this._dragMove(event);
287 return true; 287 return true;
288 } 288 }
289 289
290 /** 290 /**
291 * @param {!MouseEvent} event 291 * @param {!MouseEvent} event
292 */ 292 */
293 _dragMove(event) { 293 _dragMove(event) {
294 var point = new WebInspector.Geometry.Point(event.x - this._canvasOrigin.x, event.y - this._canvasOrigin.y); 294 var point = new Common.Geometry.Point(event.x - this._canvasOrigin.x, event. y - this._canvasOrigin.y);
295 if (event.shiftKey) 295 if (event.shiftKey)
296 point = this._snapToClosestDirection(point); 296 point = this._snapToClosestDirection(point);
297 var constrainedPoint = this._constrainPoint(point, this._innerCanvasSize); 297 var constrainedPoint = this._constrainPoint(point, this._innerCanvasSize);
298 var newX = Math.round((constrainedPoint.x / this._innerCanvasSize) * WebInsp ector.CSSShadowEditor.maxRange); 298 var newX = Math.round((constrainedPoint.x / this._innerCanvasSize) * UI.CSSS hadowEditor.maxRange);
299 var newY = Math.round((constrainedPoint.y / this._innerCanvasSize) * WebInsp ector.CSSShadowEditor.maxRange); 299 var newY = Math.round((constrainedPoint.y / this._innerCanvasSize) * UI.CSSS hadowEditor.maxRange);
300 300
301 if (event.shiftKey) { 301 if (event.shiftKey) {
302 this._model.setOffsetX( 302 this._model.setOffsetX(
303 new WebInspector.CSSLength(newX, this._model.offsetX().unit || WebInsp ector.CSSShadowEditor.defaultUnit)); 303 new Common.CSSLength(newX, this._model.offsetX().unit || UI.CSSShadowE ditor.defaultUnit));
304 this._model.setOffsetY( 304 this._model.setOffsetY(
305 new WebInspector.CSSLength(newY, this._model.offsetY().unit || WebInsp ector.CSSShadowEditor.defaultUnit)); 305 new Common.CSSLength(newY, this._model.offsetY().unit || UI.CSSShadowE ditor.defaultUnit));
306 } else { 306 } else {
307 if (!event.altKey) 307 if (!event.altKey)
308 this._model.setOffsetX( 308 this._model.setOffsetX(
309 new WebInspector.CSSLength(newX, this._model.offsetX().unit || WebIn spector.CSSShadowEditor.defaultUnit)); 309 new Common.CSSLength(newX, this._model.offsetX().unit || UI.CSSShado wEditor.defaultUnit));
310 if (!WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event)) 310 if (!UI.KeyboardShortcut.eventHasCtrlOrMeta(event))
311 this._model.setOffsetY( 311 this._model.setOffsetY(
312 new WebInspector.CSSLength(newY, this._model.offsetY().unit || WebIn spector.CSSShadowEditor.defaultUnit)); 312 new Common.CSSLength(newY, this._model.offsetY().unit || UI.CSSShado wEditor.defaultUnit));
313 } 313 }
314 this._xInput.value = this._model.offsetX().asCSSText(); 314 this._xInput.value = this._model.offsetX().asCSSText();
315 this._yInput.value = this._model.offsetY().asCSSText(); 315 this._yInput.value = this._model.offsetY().asCSSText();
316 this._xInput.classList.remove('invalid'); 316 this._xInput.classList.remove('invalid');
317 this._yInput.classList.remove('invalid'); 317 this._yInput.classList.remove('invalid');
318 this._updateCanvas(true); 318 this._updateCanvas(true);
319 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.ShadowChan ged, this._model); 319 this.dispatchEventToListeners(UI.CSSShadowEditor.Events.ShadowChanged, this. _model);
320 } 320 }
321 321
322 _onCanvasBlur() { 322 _onCanvasBlur() {
323 this._updateCanvas(false); 323 this._updateCanvas(false);
324 } 324 }
325 325
326 /** 326 /**
327 * @param {!Event} event 327 * @param {!Event} event
328 */ 328 */
329 _onCanvasArrowKey(event) { 329 _onCanvasArrowKey(event) {
330 var shiftX = 0; 330 var shiftX = 0;
331 var shiftY = 0; 331 var shiftY = 0;
332 if (event.key === 'ArrowRight') 332 if (event.key === 'ArrowRight')
333 shiftX = 1; 333 shiftX = 1;
334 else if (event.key === 'ArrowLeft') 334 else if (event.key === 'ArrowLeft')
335 shiftX = -1; 335 shiftX = -1;
336 else if (event.key === 'ArrowUp') 336 else if (event.key === 'ArrowUp')
337 shiftY = -1; 337 shiftY = -1;
338 else if (event.key === 'ArrowDown') 338 else if (event.key === 'ArrowDown')
339 shiftY = 1; 339 shiftY = 1;
340 340
341 if (!shiftX && !shiftY) 341 if (!shiftX && !shiftY)
342 return; 342 return;
343 event.consume(true); 343 event.consume(true);
344 344
345 if (shiftX) { 345 if (shiftX) {
346 var offsetX = this._model.offsetX(); 346 var offsetX = this._model.offsetX();
347 var newAmount = Number.constrain( 347 var newAmount = Number.constrain(
348 offsetX.amount + shiftX, -WebInspector.CSSShadowEditor.maxRange, WebIn spector.CSSShadowEditor.maxRange); 348 offsetX.amount + shiftX, -UI.CSSShadowEditor.maxRange, UI.CSSShadowEdi tor.maxRange);
349 if (newAmount === offsetX.amount) 349 if (newAmount === offsetX.amount)
350 return; 350 return;
351 this._model.setOffsetX( 351 this._model.setOffsetX(
352 new WebInspector.CSSLength(newAmount, offsetX.unit || WebInspector.CSS ShadowEditor.defaultUnit)); 352 new Common.CSSLength(newAmount, offsetX.unit || UI.CSSShadowEditor.def aultUnit));
353 this._xInput.value = this._model.offsetX().asCSSText(); 353 this._xInput.value = this._model.offsetX().asCSSText();
354 this._xInput.classList.remove('invalid'); 354 this._xInput.classList.remove('invalid');
355 } 355 }
356 if (shiftY) { 356 if (shiftY) {
357 var offsetY = this._model.offsetY(); 357 var offsetY = this._model.offsetY();
358 var newAmount = Number.constrain( 358 var newAmount = Number.constrain(
359 offsetY.amount + shiftY, -WebInspector.CSSShadowEditor.maxRange, WebIn spector.CSSShadowEditor.maxRange); 359 offsetY.amount + shiftY, -UI.CSSShadowEditor.maxRange, UI.CSSShadowEdi tor.maxRange);
360 if (newAmount === offsetY.amount) 360 if (newAmount === offsetY.amount)
361 return; 361 return;
362 this._model.setOffsetY( 362 this._model.setOffsetY(
363 new WebInspector.CSSLength(newAmount, offsetY.unit || WebInspector.CSS ShadowEditor.defaultUnit)); 363 new Common.CSSLength(newAmount, offsetY.unit || UI.CSSShadowEditor.def aultUnit));
364 this._yInput.value = this._model.offsetY().asCSSText(); 364 this._yInput.value = this._model.offsetY().asCSSText();
365 this._yInput.classList.remove('invalid'); 365 this._yInput.classList.remove('invalid');
366 } 366 }
367 this._updateCanvas(true); 367 this._updateCanvas(true);
368 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.ShadowChan ged, this._model); 368 this.dispatchEventToListeners(UI.CSSShadowEditor.Events.ShadowChanged, this. _model);
369 } 369 }
370 370
371 /** 371 /**
372 * @param {!WebInspector.Geometry.Point} point 372 * @param {!Common.Geometry.Point} point
373 * @param {number} max 373 * @param {number} max
374 * @return {!WebInspector.Geometry.Point} 374 * @return {!Common.Geometry.Point}
375 */ 375 */
376 _constrainPoint(point, max) { 376 _constrainPoint(point, max) {
377 if (Math.abs(point.x) <= max && Math.abs(point.y) <= max) 377 if (Math.abs(point.x) <= max && Math.abs(point.y) <= max)
378 return new WebInspector.Geometry.Point(point.x, point.y); 378 return new Common.Geometry.Point(point.x, point.y);
379 return point.scale(max / Math.max(Math.abs(point.x), Math.abs(point.y))); 379 return point.scale(max / Math.max(Math.abs(point.x), Math.abs(point.y)));
380 } 380 }
381 381
382 /** 382 /**
383 * @param {!WebInspector.Geometry.Point} point 383 * @param {!Common.Geometry.Point} point
384 * @return {!WebInspector.Geometry.Point} 384 * @return {!Common.Geometry.Point}
385 */ 385 */
386 _snapToClosestDirection(point) { 386 _snapToClosestDirection(point) {
387 var minDistance = Number.MAX_VALUE; 387 var minDistance = Number.MAX_VALUE;
388 var closestPoint = point; 388 var closestPoint = point;
389 389
390 var directions = [ 390 var directions = [
391 new WebInspector.Geometry.Point(0, -1), // North 391 new Common.Geometry.Point(0, -1), // North
392 new WebInspector.Geometry.Point(1, -1), // Northeast 392 new Common.Geometry.Point(1, -1), // Northeast
393 new WebInspector.Geometry.Point(1, 0), // East 393 new Common.Geometry.Point(1, 0), // East
394 new WebInspector.Geometry.Point(1, 1) // Southeast 394 new Common.Geometry.Point(1, 1) // Southeast
395 ]; 395 ];
396 396
397 for (var direction of directions) { 397 for (var direction of directions) {
398 var projection = point.projectOn(direction); 398 var projection = point.projectOn(direction);
399 var distance = point.distanceTo(projection); 399 var distance = point.distanceTo(projection);
400 if (distance < minDistance) { 400 if (distance < minDistance) {
401 minDistance = distance; 401 minDistance = distance;
402 closestPoint = projection; 402 closestPoint = projection;
403 } 403 }
404 } 404 }
405 405
406 return closestPoint; 406 return closestPoint;
407 } 407 }
408 408
409 /** 409 /**
410 * @return {!WebInspector.Geometry.Point} 410 * @return {!Common.Geometry.Point}
411 */ 411 */
412 _sliderThumbPosition() { 412 _sliderThumbPosition() {
413 var x = (this._model.offsetX().amount / WebInspector.CSSShadowEditor.maxRang e) * this._innerCanvasSize; 413 var x = (this._model.offsetX().amount / UI.CSSShadowEditor.maxRange) * this. _innerCanvasSize;
414 var y = (this._model.offsetY().amount / WebInspector.CSSShadowEditor.maxRang e) * this._innerCanvasSize; 414 var y = (this._model.offsetY().amount / UI.CSSShadowEditor.maxRange) * this. _innerCanvasSize;
415 return this._constrainPoint(new WebInspector.Geometry.Point(x, y), this._inn erCanvasSize); 415 return this._constrainPoint(new Common.Geometry.Point(x, y), this._innerCanv asSize);
416 } 416 }
417 }; 417 };
418 418
419 /** @enum {symbol} */ 419 /** @enum {symbol} */
420 WebInspector.CSSShadowEditor.Events = { 420 UI.CSSShadowEditor.Events = {
421 ShadowChanged: Symbol('ShadowChanged') 421 ShadowChanged: Symbol('ShadowChanged')
422 }; 422 };
423 423
424 /** @type {number} */ 424 /** @type {number} */
425 WebInspector.CSSShadowEditor.maxRange = 20; 425 UI.CSSShadowEditor.maxRange = 20;
426 /** @type {string} */ 426 /** @type {string} */
427 WebInspector.CSSShadowEditor.defaultUnit = 'px'; 427 UI.CSSShadowEditor.defaultUnit = 'px';
428 /** @type {number} */ 428 /** @type {number} */
429 WebInspector.CSSShadowEditor.sliderThumbRadius = 6; 429 UI.CSSShadowEditor.sliderThumbRadius = 6;
430 /** @type {number} */ 430 /** @type {number} */
431 WebInspector.CSSShadowEditor.canvasSize = 88; 431 UI.CSSShadowEditor.canvasSize = 88;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698