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

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

Issue 2278203003: DevTools: Allow shadow-editor value manipulation with arrow keys and mousewheel (Closed)
Patch Set: Add return annotations 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 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 */ 55 */
56 _createSliderField: function(propertyName, negativeAllowed) 56 _createSliderField: function(propertyName, negativeAllowed)
57 { 57 {
58 var field = this.contentElement.createChild("div", "shadow-editor-field" ); 58 var field = this.contentElement.createChild("div", "shadow-editor-field" );
59 var label = field.createChild("label", "shadow-editor-label"); 59 var label = field.createChild("label", "shadow-editor-label");
60 label.textContent = propertyName; 60 label.textContent = propertyName;
61 label.setAttribute("for", propertyName); 61 label.setAttribute("for", propertyName);
62 var textInput = field.createChild("input", "shadow-editor-text-input"); 62 var textInput = field.createChild("input", "shadow-editor-text-input");
63 textInput.type = "text"; 63 textInput.type = "text";
64 textInput.id = propertyName; 64 textInput.id = propertyName;
65 textInput.addEventListener("keydown", this._handleValueModification.bind (this), false);
66 textInput.addEventListener("mousewheel", this._handleValueModification.b ind(this), false);
65 textInput.addEventListener("input", this._onTextInput.bind(this), false) ; 67 textInput.addEventListener("input", this._onTextInput.bind(this), false) ;
66 textInput.addEventListener("blur", this._onTextBlur.bind(this), false); 68 textInput.addEventListener("blur", this._onTextBlur.bind(this), false);
67 var halfRange = WebInspector.CSSShadowEditor.maxRange / 2; 69 var halfRange = WebInspector.CSSShadowEditor.maxRange / 2;
68 var slider = negativeAllowed ? createSliderLabel(-halfRange, halfRange) : createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange); 70 var slider = negativeAllowed ? createSliderLabel(-halfRange, halfRange) : createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange);
69 slider.addEventListener("input", this._onSliderInput.bind(this), false); 71 slider.addEventListener("input", this._onSliderInput.bind(this), false);
70 field.appendChild(slider); 72 field.appendChild(slider);
71 return {field: field, textInput: textInput, rangeInput: slider}; 73 return {field: field, textInput: textInput, rangeInput: slider};
72 }, 74 },
73 75
74 /** 76 /**
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (insetClicked && this._model.inset() || !insetClicked && !this._model .inset()) 120 if (insetClicked && this._model.inset() || !insetClicked && !this._model .inset())
119 return; 121 return;
120 this._model.setInset(insetClicked); 122 this._model.setInset(insetClicked);
121 this._updateButtons(); 123 this._updateButtons();
122 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); 124 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model);
123 }, 125 },
124 126
125 /** 127 /**
126 * @param {!Event} event 128 * @param {!Event} event
127 */ 129 */
130 _handleValueModification: function(event)
131 {
132 var modifiedValue = WebInspector.createReplacementString(event.currentTa rget.value, event, customNumberHandler);
133 if (!modifiedValue)
134 return;
135 var length = WebInspector.CSSLength.parse(modifiedValue);
136 if (!length)
137 return;
138 if (event.currentTarget === this._blurInput && length.amount < 0)
139 length.amount = 0;
140 event.currentTarget.value = length.asCSSText();
141 event.currentTarget.selectionStart = 0;
142 event.currentTarget.selectionEnd = event.currentTarget.value.length;
143 this._onTextInput(event);
144 event.consume(true);
145
146 /**
147 * @param {string} prefix
148 * @param {number} number
149 * @param {string} suffix
150 * @return {string}
151 */
152 function customNumberHandler(prefix, number, suffix)
153 {
154 if (!suffix.length)
155 suffix = WebInspector.CSSShadowEditor.defaultUnit;
156 return prefix + number + suffix;
157 }
158 },
159
160 /**
161 * @param {!Event} event
162 */
128 _onTextInput: function(event) 163 _onTextInput: function(event)
129 { 164 {
130 this._changedElement = event.currentTarget; 165 this._changedElement = event.currentTarget;
131 this._changedElement.classList.toggle("invalid", false); 166 this._changedElement.classList.toggle("invalid", false);
132 var length = WebInspector.CSSLength.parse(event.currentTarget.value); 167 var length = WebInspector.CSSLength.parse(event.currentTarget.value);
133 if (!length || event.currentTarget === this._blurInput && length.amount < 0) 168 if (!length || event.currentTarget === this._blurInput && length.amount < 0)
134 return; 169 return;
135 if (event.currentTarget === this._xInput) { 170 if (event.currentTarget === this._xInput) {
136 this._model.setOffsetX(length); 171 this._model.setOffsetX(length);
137 this._xSlider.value = length.amount; 172 this._xSlider.value = length.amount;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } else if (event.currentTarget === this._spreadSlider) { 238 } else if (event.currentTarget === this._spreadSlider) {
204 this._model.setSpreadRadius(new WebInspector.CSSLength(this._spreadS lider.value, this._model.spreadRadius().unit || WebInspector.CSSShadowEditor.def aultUnit)); 239 this._model.setSpreadRadius(new WebInspector.CSSLength(this._spreadS lider.value, this._model.spreadRadius().unit || WebInspector.CSSShadowEditor.def aultUnit));
205 this._spreadInput.value = this._model.spreadRadius().asCSSText(); 240 this._spreadInput.value = this._model.spreadRadius().asCSSText();
206 this._spreadInput.classList.toggle("invalid", false); 241 this._spreadInput.classList.toggle("invalid", false);
207 } 242 }
208 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); 243 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model);
209 }, 244 },
210 245
211 __proto__: WebInspector.VBox.prototype 246 __proto__: WebInspector.VBox.prototype
212 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698