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

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

Issue 2292583002: DevTools: Create 2D slider for shadow-editor offset (Closed)
Patch Set: Address comments Created 4 years, 3 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 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 */ 8 */
9 WebInspector.CSSShadowEditor = function() 9 WebInspector.CSSShadowEditor = function()
10 { 10 {
11 WebInspector.VBox.call(this, true); 11 WebInspector.VBox.call(this, true);
12 this.registerRequiredCSS("ui/cssShadowEditor.css"); 12 this.registerRequiredCSS("ui/cssShadowEditor.css");
13 this.contentElement.tabIndex = 0; 13 this.contentElement.tabIndex = 0;
14 14
15 this._typeField = this.contentElement.createChild("div", "shadow-editor-fiel d"); 15 this._typeField = this.contentElement.createChild("div", "shadow-editor-fiel d");
16 this._typeField.createChild("label", "shadow-editor-label").textContent = We bInspector.UIString("Type"); 16 this._typeField.createChild("label", "shadow-editor-label").textContent = We bInspector.UIString("Type");
17 this._outsetButton = this._typeField.createChild("button", "shadow-editor-bu tton-left"); 17 this._outsetButton = this._typeField.createChild("button", "shadow-editor-bu tton-left");
18 this._outsetButton.textContent = WebInspector.UIString("Outset"); 18 this._outsetButton.textContent = WebInspector.UIString("Outset");
19 this._outsetButton.addEventListener("click", this._onButtonClick.bind(this), false); 19 this._outsetButton.addEventListener("click", this._onButtonClick.bind(this), false);
20 this._insetButton = this._typeField.createChild("button", "shadow-editor-but ton-right"); 20 this._insetButton = this._typeField.createChild("button", "shadow-editor-but ton-right");
21 this._insetButton.textContent = WebInspector.UIString("Inset"); 21 this._insetButton.textContent = WebInspector.UIString("Inset");
22 this._insetButton.addEventListener("click", this._onButtonClick.bind(this), false); 22 this._insetButton.addEventListener("click", this._onButtonClick.bind(this), false);
23 23
24 var inputs; 24 var xField = this.contentElement.createChild("div", "shadow-editor-field");
25 inputs = this._createSliderField(WebInspector.UIString("X offset"), true); 25 this._xInput = this._createTextInput(xField, WebInspector.UIString("X offset "));
26 this._xInput = inputs.textInput; 26 var yField = this.contentElement.createChild("div", "shadow-editor-field");
27 this._xSlider = inputs.rangeInput; 27 this._yInput = this._createTextInput(yField, WebInspector.UIString("Y offset "));
28 inputs = this._createSliderField(WebInspector.UIString("Y offset"), true); 28 this._xySlider = xField.createChild("canvas", "shadow-editor-2D-slider");
29 this._yInput = inputs.textInput; 29 this._xySlider.width = WebInspector.CSSShadowEditor.canvasSize;
30 this._ySlider = inputs.rangeInput; 30 this._xySlider.height = WebInspector.CSSShadowEditor.canvasSize;
31 inputs = this._createSliderField(WebInspector.UIString("Blur"), false); 31 this._xySlider.tabIndex = -1;
32 this._blurInput = inputs.textInput; 32 this._halfCanvasSize = WebInspector.CSSShadowEditor.canvasSize / 2;
33 this._blurSlider = inputs.rangeInput; 33 this._innerCanvasSize = this._halfCanvasSize - WebInspector.CSSShadowEditor. sliderThumbRadius;
34 inputs = this._createSliderField(WebInspector.UIString("Spread"), false); 34 WebInspector.installDragHandle(this._xySlider, this._dragStart.bind(this), t his._dragMove.bind(this), null, "default");
35 this._spreadInput = inputs.textInput; 35 this._xySlider.addEventListener("keydown", this._onCanvasArrowKey.bind(this) , false);
36 this._spreadSlider = inputs.rangeInput; 36 this._xySlider.addEventListener("blur", this._onCanvasBlur.bind(this), false );
37 this._spreadField = inputs.field; 37
38 var blurField = this.contentElement.createChild("div", "shadow-editor-blur-f ield");
39 this._blurInput = this._createTextInput(blurField, WebInspector.UIString("Bl ur"));
40 this._blurSlider = this._createSlider(blurField);
41
42 this._spreadField = this.contentElement.createChild("div", "shadow-editor-fi eld");
43 this._spreadInput = this._createTextInput(this._spreadField, WebInspector.UI String("Spread"));
44 this._spreadSlider = this._createSlider(this._spreadField);
38 } 45 }
39 46
40 /** @enum {symbol} */ 47 /** @enum {symbol} */
41 WebInspector.CSSShadowEditor.Events = { 48 WebInspector.CSSShadowEditor.Events = {
42 ShadowChanged: Symbol("ShadowChanged") 49 ShadowChanged: Symbol("ShadowChanged")
43 } 50 }
44 51
45 /** @type {number} */ 52 /** @type {number} */
46 WebInspector.CSSShadowEditor.maxRange = 40; 53 WebInspector.CSSShadowEditor.maxRange = 20;
47 /** @type {string} */ 54 /** @type {string} */
48 WebInspector.CSSShadowEditor.defaultUnit = "px"; 55 WebInspector.CSSShadowEditor.defaultUnit = "px";
56 /** @type {number} */
57 WebInspector.CSSShadowEditor.sliderThumbRadius = 6;
58 /** @type {number} */
59 WebInspector.CSSShadowEditor.canvasSize = 88;
49 60
50 WebInspector.CSSShadowEditor.prototype = { 61 WebInspector.CSSShadowEditor.prototype = {
51 /** 62 /**
63 * @param {!Element} field
52 * @param {string} propertyName 64 * @param {string} propertyName
53 * @param {boolean} negativeAllowed 65 * @return {!Element}
54 * @return {{textInput: !Element, rangeInput: !Element, field: !Element}}
55 */ 66 */
56 _createSliderField: function(propertyName, negativeAllowed) 67 _createTextInput: function(field, propertyName)
57 { 68 {
58 var field = this.contentElement.createChild("div", "shadow-editor-field" );
59 var label = field.createChild("label", "shadow-editor-label"); 69 var label = field.createChild("label", "shadow-editor-label");
60 label.textContent = propertyName; 70 label.textContent = propertyName;
61 label.setAttribute("for", propertyName); 71 label.setAttribute("for", propertyName);
62 var textInput = field.createChild("input", "shadow-editor-text-input"); 72 var textInput = field.createChild("input", "shadow-editor-text-input");
63 textInput.type = "text"; 73 textInput.type = "text";
64 textInput.id = propertyName; 74 textInput.id = propertyName;
65 textInput.addEventListener("keydown", this._handleValueModification.bind (this), false); 75 textInput.addEventListener("keydown", this._handleValueModification.bind (this), false);
66 textInput.addEventListener("mousewheel", this._handleValueModification.b ind(this), false); 76 textInput.addEventListener("mousewheel", this._handleValueModification.b ind(this), false);
67 textInput.addEventListener("input", this._onTextInput.bind(this), false) ; 77 textInput.addEventListener("input", this._onTextInput.bind(this), false) ;
68 textInput.addEventListener("blur", this._onTextBlur.bind(this), false); 78 textInput.addEventListener("blur", this._onTextBlur.bind(this), false);
69 var halfRange = WebInspector.CSSShadowEditor.maxRange / 2; 79 return textInput;
70 var slider = negativeAllowed ? createSliderLabel(-halfRange, halfRange) : createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange);
71 slider.addEventListener("input", this._onSliderInput.bind(this), false);
72 field.appendChild(slider);
73 return {field: field, textInput: textInput, rangeInput: slider};
74 }, 80 },
75 81
76 /** 82 /**
83 * @param {!Element} field
84 * @return {!Element}
85 */
86 _createSlider: function(field)
87 {
88 var slider = createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange, -1);
89 slider.addEventListener("input", this._onSliderInput.bind(this), false);
90 field.appendChild(slider);
91 return slider;
92 },
93
94 /**
77 * @override 95 * @override
78 */ 96 */
79 wasShown: function() 97 wasShown: function()
80 { 98 {
81 this._updateUI(); 99 this._updateUI();
82 }, 100 },
83 101
84 /** 102 /**
85 * @param {!WebInspector.CSSShadowModel} model 103 * @param {!WebInspector.CSSShadowModel} model
86 */ 104 */
87 setModel: function(model) 105 setModel: function(model)
88 { 106 {
89 this._model = model; 107 this._model = model;
90 this._typeField.hidden = !model.isBoxShadow(); 108 this._typeField.hidden = !model.isBoxShadow();
91 this._spreadField.hidden = !model.isBoxShadow(); 109 this._spreadField.hidden = !model.isBoxShadow();
92 this._updateUI(); 110 this._updateUI();
93 }, 111 },
94 112
95 _updateUI: function() 113 _updateUI: function()
96 { 114 {
97 this._updateButtons(); 115 this._updateButtons();
98 this._xInput.value = this._model.offsetX().asCSSText(); 116 this._xInput.value = this._model.offsetX().asCSSText();
99 this._yInput.value = this._model.offsetY().asCSSText(); 117 this._yInput.value = this._model.offsetY().asCSSText();
100 this._blurInput.value = this._model.blurRadius().asCSSText(); 118 this._blurInput.value = this._model.blurRadius().asCSSText();
101 this._spreadInput.value = this._model.spreadRadius().asCSSText(); 119 this._spreadInput.value = this._model.spreadRadius().asCSSText();
102 this._xSlider.value = this._model.offsetX().amount;
103 this._ySlider.value = this._model.offsetY().amount;
104 this._blurSlider.value = this._model.blurRadius().amount; 120 this._blurSlider.value = this._model.blurRadius().amount;
105 this._spreadSlider.value = this._model.spreadRadius().amount; 121 this._spreadSlider.value = this._model.spreadRadius().amount;
122 this._updateCanvas();
106 }, 123 },
107 124
108 _updateButtons: function() 125 _updateButtons: function()
109 { 126 {
110 this._insetButton.classList.toggle("enabled", this._model.inset()); 127 this._insetButton.classList.toggle("enabled", this._model.inset());
111 this._outsetButton.classList.toggle("enabled", !this._model.inset()); 128 this._outsetButton.classList.toggle("enabled", !this._model.inset());
112 }, 129 },
113 130
131 _updateCanvas: function()
132 {
133 var context = this._xySlider.getContext("2d");
134 context.clearRect(0, 0, this._xySlider.width, this._xySlider.height);
135
136 // Draw dashed axes.
137 context.save();
138 context.setLineDash([1, 1]);
139 context.strokeStyle = "rgba(0, 0, 0, 0.2)";
140 context.beginPath();
141 context.moveTo(this._halfCanvasSize, 0);
142 context.lineTo(this._halfCanvasSize, WebInspector.CSSShadowEditor.canvas Size);
143 context.moveTo(0, this._halfCanvasSize);
144 context.lineTo(WebInspector.CSSShadowEditor.canvasSize, this._halfCanvas Size);
145 context.stroke();
146 context.restore();
147
148 var thumbPoint = this._sliderThumbPosition();
149 // Draw 2D slider line.
150 context.save();
151 context.translate(this._halfCanvasSize, this._halfCanvasSize);
152 context.lineWidth = 2;
153 context.strokeStyle = "rgba(0, 0, 0, 0.3)";
154 context.beginPath();
155 context.moveTo(0, 0);
156 context.lineTo(thumbPoint.x, thumbPoint.y);
157 context.stroke();
158 // Draw 2D slider thumb.
159 context.beginPath();
160 if (this._xySlider.ownerDocument.deepActiveElement() === this._xySlider) {
lushnikov 2016/08/31 00:48:03 I actually like your "drawFocus" parameter even mo
flandy 2016/08/31 01:35:05 Done.
161 context.fillStyle = "rgba(66, 133, 244, 0.4)";
162 context.arc(thumbPoint.x, thumbPoint.y, WebInspector.CSSShadowEditor .sliderThumbRadius + 2, 0, 2 * Math.PI);
163 context.fill();
164 }
165 context.beginPath()
166 context.fillStyle = "#4285F4";
167 context.arc(thumbPoint.x, thumbPoint.y, WebInspector.CSSShadowEditor.sli derThumbRadius, 0, 2 * Math.PI);
168 context.fill();
169 context.restore();
170 },
171
114 /** 172 /**
115 * @param {!Event} event 173 * @param {!Event} event
116 */ 174 */
117 _onButtonClick: function(event) 175 _onButtonClick: function(event)
118 { 176 {
119 var insetClicked = (event.currentTarget === this._insetButton); 177 var insetClicked = (event.currentTarget === this._insetButton);
120 if (insetClicked && this._model.inset() || !insetClicked && !this._model .inset()) 178 if (insetClicked && this._model.inset() || !insetClicked && !this._model .inset())
121 return; 179 return;
122 this._model.setInset(insetClicked); 180 this._model.setInset(insetClicked);
123 this._updateButtons(); 181 this._updateButtons();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return prefix + number + suffix; 214 return prefix + number + suffix;
157 } 215 }
158 }, 216 },
159 217
160 /** 218 /**
161 * @param {!Event} event 219 * @param {!Event} event
162 */ 220 */
163 _onTextInput: function(event) 221 _onTextInput: function(event)
164 { 222 {
165 this._changedElement = event.currentTarget; 223 this._changedElement = event.currentTarget;
166 this._changedElement.classList.toggle("invalid", false); 224 this._changedElement.classList.remove("invalid");
167 var length = WebInspector.CSSLength.parse(event.currentTarget.value); 225 var length = WebInspector.CSSLength.parse(event.currentTarget.value);
168 if (!length || event.currentTarget === this._blurInput && length.amount < 0) 226 if (!length || event.currentTarget === this._blurInput && length.amount < 0)
169 return; 227 return;
170 if (event.currentTarget === this._xInput) { 228 if (event.currentTarget === this._xInput) {
171 this._model.setOffsetX(length); 229 this._model.setOffsetX(length);
172 this._xSlider.value = length.amount; 230 this._updateCanvas();
173 } else if (event.currentTarget === this._yInput) { 231 } else if (event.currentTarget === this._yInput) {
174 this._model.setOffsetY(length); 232 this._model.setOffsetY(length);
175 this._ySlider.value = length.amount; 233 this._updateCanvas();
176 } else if (event.currentTarget === this._blurInput) { 234 } else if (event.currentTarget === this._blurInput) {
177 this._model.setBlurRadius(length); 235 this._model.setBlurRadius(length);
178 this._blurSlider.value = length.amount; 236 this._blurSlider.value = length.amount;
179 } else if (event.currentTarget === this._spreadInput) { 237 } else if (event.currentTarget === this._spreadInput) {
180 this._model.setSpreadRadius(length); 238 this._model.setSpreadRadius(length);
181 this._spreadSlider.value = length.amount; 239 this._spreadSlider.value = length.amount;
182 } 240 }
183 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); 241 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model);
184 }, 242 },
185 243
186 _onTextBlur: function() 244 _onTextBlur: function()
187 { 245 {
188 if (!this._changedElement) 246 if (!this._changedElement)
189 return; 247 return;
190 var length = !this._changedElement.value ? WebInspector.CSSLength.zero() : WebInspector.CSSLength.parse(this._changedElement.value); 248 var length = !this._changedElement.value.trim() ? WebInspector.CSSLength .zero() : WebInspector.CSSLength.parse(this._changedElement.value);
191 if (!length) 249 if (!length)
192 length = WebInspector.CSSLength.parse(this._changedElement.value + W ebInspector.CSSShadowEditor.defaultUnit); 250 length = WebInspector.CSSLength.parse(this._changedElement.value + W ebInspector.CSSShadowEditor.defaultUnit);
193 if (!length) { 251 if (!length) {
194 this._changedElement.classList.add("invalid"); 252 this._changedElement.classList.add("invalid");
195 this._changedElement = null; 253 this._changedElement = null;
196 return; 254 return;
197 } 255 }
198 if (this._changedElement === this._xInput) { 256 if (this._changedElement === this._xInput) {
199 this._model.setOffsetX(length); 257 this._model.setOffsetX(length);
200 this._xInput.value = length.asCSSText(); 258 this._xInput.value = length.asCSSText();
201 this._xSlider.value = length.amount; 259 this._updateCanvas();
202 } else if (this._changedElement === this._yInput) { 260 } else if (this._changedElement === this._yInput) {
203 this._model.setOffsetY(length); 261 this._model.setOffsetY(length);
204 this._yInput.value = length.asCSSText(); 262 this._yInput.value = length.asCSSText();
205 this._ySlider.value = length.amount; 263 this._updateCanvas();
206 } else if (this._changedElement === this._blurInput) { 264 } else if (this._changedElement === this._blurInput) {
207 if (length.amount < 0) 265 if (length.amount < 0)
208 length = WebInspector.CSSLength.zero(); 266 length = WebInspector.CSSLength.zero();
209 this._model.setBlurRadius(length); 267 this._model.setBlurRadius(length);
210 this._blurInput.value = length.asCSSText(); 268 this._blurInput.value = length.asCSSText();
211 this._blurSlider.value = length.amount; 269 this._blurSlider.value = length.amount;
212 } else if (this._changedElement === this._spreadInput) { 270 } else if (this._changedElement === this._spreadInput) {
213 this._model.setSpreadRadius(length); 271 this._model.setSpreadRadius(length);
214 this._spreadInput.value = length.asCSSText(); 272 this._spreadInput.value = length.asCSSText();
215 this._spreadSlider.value = length.amount; 273 this._spreadSlider.value = length.amount;
216 } 274 }
217 this._changedElement = null; 275 this._changedElement = null;
218 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); 276 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model);
219 }, 277 },
220 278
221 /** 279 /**
222 * @param {!Event} event 280 * @param {!Event} event
223 */ 281 */
224 _onSliderInput: function(event) 282 _onSliderInput: function(event)
225 { 283 {
226 if (event.currentTarget === this._xSlider) { 284 if (event.currentTarget === this._blurSlider) {
227 this._model.setOffsetX(new WebInspector.CSSLength(this._xSlider.valu e, this._model.offsetX().unit || WebInspector.CSSShadowEditor.defaultUnit));
228 this._xInput.value = this._model.offsetX().asCSSText();
229 this._xInput.classList.toggle("invalid", false);
230 } else if (event.currentTarget === this._ySlider) {
231 this._model.setOffsetY(new WebInspector.CSSLength(this._ySlider.valu e, this._model.offsetY().unit || WebInspector.CSSShadowEditor.defaultUnit));
232 this._yInput.value = this._model.offsetY().asCSSText();
233 this._yInput.classList.toggle("invalid", false);
234 } else if (event.currentTarget === this._blurSlider) {
235 this._model.setBlurRadius(new WebInspector.CSSLength(this._blurSlide r.value, this._model.blurRadius().unit || WebInspector.CSSShadowEditor.defaultUn it)); 285 this._model.setBlurRadius(new WebInspector.CSSLength(this._blurSlide r.value, this._model.blurRadius().unit || WebInspector.CSSShadowEditor.defaultUn it));
236 this._blurInput.value = this._model.blurRadius().asCSSText(); 286 this._blurInput.value = this._model.blurRadius().asCSSText();
237 this._blurInput.classList.toggle("invalid", false); 287 this._blurInput.classList.remove("invalid");
238 } else if (event.currentTarget === this._spreadSlider) { 288 } else if (event.currentTarget === this._spreadSlider) {
239 this._model.setSpreadRadius(new WebInspector.CSSLength(this._spreadS lider.value, this._model.spreadRadius().unit || WebInspector.CSSShadowEditor.def aultUnit)); 289 this._model.setSpreadRadius(new WebInspector.CSSLength(this._spreadS lider.value, this._model.spreadRadius().unit || WebInspector.CSSShadowEditor.def aultUnit));
240 this._spreadInput.value = this._model.spreadRadius().asCSSText(); 290 this._spreadInput.value = this._model.spreadRadius().asCSSText();
241 this._spreadInput.classList.toggle("invalid", false); 291 this._spreadInput.classList.remove("invalid");
242 } 292 }
243 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); 293 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model);
244 }, 294 },
245 295
296 /**
297 * @param {!Event} event
298 * @return {boolean}
299 */
300 _dragStart: function(event)
301 {
302 this._xySlider.focus();
303 this._updateCanvas();
304 this._canvasOrigin = new WebInspector.Geometry.Point(this._xySlider.tota lOffsetLeft() + this._halfCanvasSize, this._xySlider.totalOffsetTop() + this._ha lfCanvasSize);
305 var clickedPoint = new WebInspector.Geometry.Point(event.x - this._canva sOrigin.x, event.y - this._canvasOrigin.y);
306 var thumbPoint = this._sliderThumbPosition();
307 if (clickedPoint.distanceTo(thumbPoint) >= WebInspector.CSSShadowEditor. sliderThumbRadius)
308 this._dragMove(event);
309 return true;
310 },
311
312 /**
313 * @param {!Event} event
314 */
315 _dragMove: function(event)
316 {
317 var point = new WebInspector.Geometry.Point(event.x - this._canvasOrigin .x, event.y - this._canvasOrigin.y);
318 var constrainedPoint = this._constrainPoint(point, this._innerCanvasSize );
319 var newX = Math.round((constrainedPoint.x / this._innerCanvasSize) * Web Inspector.CSSShadowEditor.maxRange);
320 var newY = Math.round((constrainedPoint.y / this._innerCanvasSize) * Web Inspector.CSSShadowEditor.maxRange);
321 this._model.setOffsetX(new WebInspector.CSSLength(newX, this._model.offs etX().unit || WebInspector.CSSShadowEditor.defaultUnit));
322 this._model.setOffsetY(new WebInspector.CSSLength(newY, this._model.offs etY().unit || WebInspector.CSSShadowEditor.defaultUnit));
323 this._xInput.value = this._model.offsetX().asCSSText();
324 this._yInput.value = this._model.offsetY().asCSSText();
325 this._xInput.classList.remove("invalid");
326 this._yInput.classList.remove("invalid");
327 this._updateCanvas();
328 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model);
329 },
330
331 _onCanvasBlur: function()
332 {
333 this._updateCanvas();
334 },
335
336 /**
337 * @param {!Event} event
338 */
339 _onCanvasArrowKey: function(event)
340 {
341 var shiftX = 0;
342 var shiftY = 0;
343 if (event.key === "ArrowRight")
344 shiftX = 1;
345 else if (event.key === "ArrowLeft")
346 shiftX = -1;
347 else if (event.key === "ArrowUp")
348 shiftY = -1;
349 else if (event.key === "ArrowDown")
350 shiftY = 1;
351 else
352 return;
lushnikov 2016/08/31 00:48:03 let's do a conventional bail-out if (!shiftX && !
flandy 2016/08/31 01:35:05 Done.
353 event.consume(true);
354
355 var newAmount;
lushnikov 2016/08/31 00:48:03 no need to forward-declare
flandy 2016/08/31 01:35:05 Done.
356 if (shiftX) {
357 var offsetX = this._model.offsetX();
358 newAmount = Number.constrain(offsetX.amount + shiftX, -WebInspector. CSSShadowEditor.maxRange, WebInspector.CSSShadowEditor.maxRange);
359 if (newAmount === offsetX.amount)
360 return;
361 this._model.setOffsetX(new WebInspector.CSSLength(newAmount, offsetX .unit || WebInspector.CSSShadowEditor.defaultUnit));
362 this._xInput.value = this._model.offsetX().asCSSText();
363 this._xInput.classList.remove("invalid");
364 }
365 if (shiftY) {
366 var offsetY = this._model.offsetY();
367 newAmount = Number.constrain(offsetY.amount + shiftY, -WebInspector. CSSShadowEditor.maxRange, WebInspector.CSSShadowEditor.maxRange);
368 if (newAmount === offsetY.amount)
369 return;
370 this._model.setOffsetY(new WebInspector.CSSLength(newAmount, offsetY .unit || WebInspector.CSSShadowEditor.defaultUnit));
371 this._yInput.value = this._model.offsetY().asCSSText();
372 this._yInput.classList.remove("invalid");
373 }
374 this._updateCanvas();
375 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model);
376 },
377
378 /**
379 * @param {!WebInspector.Geometry.Point} point
380 * @param {number} max
381 * @return {!WebInspector.Geometry.Point}
382 */
383 _constrainPoint: function(point, max)
384 {
385 var newPoint = new WebInspector.Geometry.Point(point.x, point.y);
386 if (Math.abs(point.x) <= max && Math.abs(point.y) <= max)
387 return newPoint;
388 newPoint.scale(max / Math.max(Math.abs(point.x), Math.abs(point.y)));
389 return newPoint;
390 },
391
392 /**
393 * @return {!WebInspector.Geometry.Point}
394 */
395 _sliderThumbPosition: function()
396 {
397 var x = (this._model.offsetX().amount / WebInspector.CSSShadowEditor.max Range) * this._innerCanvasSize;
398 var y = (this._model.offsetY().amount / WebInspector.CSSShadowEditor.max Range) * this._innerCanvasSize;
399 return this._constrainPoint(new WebInspector.Geometry.Point(x, y), this. _innerCanvasSize);
400 },
401
246 __proto__: WebInspector.VBox.prototype 402 __proto__: WebInspector.VBox.prototype
247 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698