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

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: Don't let blur go below 0 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 arrowKeyOrMouseWheelEvent = (event.key === "ArrowUp" || event.key == = "ArrowDown" || event.type === "mousewheel");
133 var pageKeyPressed = (event.key === "PageUp" || event.key === "PageDown" );
134 if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed)
dgozman 2016/08/26 19:10:58 Doesn't createReplacementString check this for you
flandy 2016/08/26 19:25:59 No, it's checked one level higher in WI.handleElem
dgozman 2016/08/26 20:49:35 If it doesn't, we should make it. But I think it d
flandy 2016/08/26 22:19:42 Yes, that can be used if we also return null from
135 return;
136 var modifiedValue = WebInspector.createReplacementString(event.currentTa rget.value, event, customNumberHandler);
137 if (!modifiedValue)
138 return;
139 var length = WebInspector.CSSLength.parse(modifiedValue);
140 if (!length)
141 return;
142 if (event.currentTarget === this._blurInput && length.amount < 0)
143 length.amount = 0;
144 event.currentTarget.value = length.asCSSText();
145 this._onTextInput(event);
146 event.consume(true);
147
148 /**
149 * @param {string} prefix
150 * @param {number} number
151 * @param {string} suffix
152 * @return {string}
153 */
154 function customNumberHandler(prefix, number, suffix)
155 {
156 if (!suffix.length)
157 suffix = WebInspector.CSSShadowEditor.defaultUnit;
158 return prefix + number + suffix;
159 }
160 },
161
162 /**
163 * @param {!Event} event
164 */
128 _onTextInput: function(event) 165 _onTextInput: function(event)
129 { 166 {
130 this._changedElement = event.currentTarget; 167 this._changedElement = event.currentTarget;
131 this._changedElement.classList.toggle("invalid", false); 168 this._changedElement.classList.toggle("invalid", false);
132 var length = WebInspector.CSSLength.parse(event.currentTarget.value); 169 var length = WebInspector.CSSLength.parse(event.currentTarget.value);
133 if (!length || event.currentTarget === this._blurInput && length.amount < 0) 170 if (!length || event.currentTarget === this._blurInput && length.amount < 0)
134 return; 171 return;
135 if (event.currentTarget === this._xInput) { 172 if (event.currentTarget === this._xInput) {
136 this._model.setOffsetX(length); 173 this._model.setOffsetX(length);
137 this._xSlider.value = length.amount; 174 this._xSlider.value = length.amount;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } else if (event.currentTarget === this._spreadSlider) { 240 } 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)); 241 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(); 242 this._spreadInput.value = this._model.spreadRadius().asCSSText();
206 this._spreadInput.classList.toggle("invalid", false); 243 this._spreadInput.classList.toggle("invalid", false);
207 } 244 }
208 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); 245 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model);
209 }, 246 },
210 247
211 __proto__: WebInspector.VBox.prototype 248 __proto__: WebInspector.VBox.prototype
212 } 249 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698