OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @constructor | |
7 * @param {!WebInspector.CSSShadowModel} model | |
8 * @extends {WebInspector.VBox} | |
9 */ | |
10 WebInspector.CSSShadowEditor = function(model) | |
11 { | |
12 WebInspector.VBox.call(this, true); | |
13 this.registerRequiredCSS("ui/cssShadowEditor.css"); | |
14 this.contentElement.tabIndex = 0; | |
15 | |
16 this._model = model; | |
17 | |
18 this._typeField = this.contentElement.createChild("div", "shadow-editor-fiel d"); | |
19 var label = this._typeField.createChild("label", "shadow-editor-label"); | |
20 label.textContent = WebInspector.UIString("Type"); | |
dgozman
2016/08/24 19:18:30
Inline |label| here.
flandy
2016/08/24 22:08:41
Done.
| |
21 this._outsetButton = this._typeField.createChild("button", "shadow-editor-bu tton left"); | |
dgozman
2016/08/24 19:18:30
"left" is too generic for css class. Let's do shad
flandy
2016/08/24 22:08:41
Done.
| |
22 this._outsetButton.createTextChild(WebInspector.UIString("Outset")); | |
23 this._outsetButton.addEventListener("click", this._onButtonClick.bind(this), true); | |
24 this._insetButton = this._typeField.createChild("button", "shadow-editor-but ton right"); | |
25 this._insetButton.createTextChild(WebInspector.UIString("Inset")); | |
dgozman
2016/08/24 19:18:30
Just textContent = ... ?
flandy
2016/08/24 22:08:41
Done.
| |
26 this._insetButton.addEventListener("click", this._onButtonClick.bind(this), true); | |
27 | |
28 var inputs; | |
29 inputs = this._createSliderField("X offset", true); | |
dgozman
2016/08/24 19:18:30
Always UIString the literal, do not pass it raw.
flandy
2016/08/24 22:08:41
I called UIString in the function, but I suppose I
| |
30 this._xInput = inputs.textInput; | |
31 this._xSlider = inputs.rangeInput; | |
32 inputs = this._createSliderField("Y offset", true); | |
33 this._yInput = inputs.textInput; | |
34 this._ySlider = inputs.rangeInput; | |
35 inputs = this._createSliderField("Blur", false); | |
36 this._blurInput = inputs.textInput; | |
37 this._blurSlider = inputs.rangeInput; | |
38 inputs = this._createSliderField("Spread", false); | |
39 this._spreadInput = inputs.textInput; | |
40 this._spreadSlider = inputs.rangeInput; | |
41 this._spreadField = inputs.field; | |
42 | |
43 this._updateUI(); | |
44 } | |
45 | |
46 /** @enum {symbol} */ | |
47 WebInspector.CSSShadowEditor.Events = { | |
48 ShadowChanged: Symbol("ShadowChanged") | |
49 } | |
50 | |
51 /** @type {number} */ | |
52 WebInspector.CSSShadowEditor.maxRange = 40; | |
53 /** @type {string} */ | |
54 WebInspector.CSSShadowEditor.defaultUnit = "px"; | |
55 | |
56 WebInspector.CSSShadowEditor.prototype = { | |
57 /** | |
58 * @param {string} propertyName | |
59 * @param {boolean} negativeAllowed | |
60 * @return {{textInput: !Element, rangeInput: !Element, field: !Element}} | |
61 */ | |
62 _createSliderField: function(propertyName, negativeAllowed) | |
63 { | |
64 var field = this.contentElement.createChild("div", "shadow-editor-field" ); | |
65 var label = field.createChild("label", "shadow-editor-label"); | |
66 label.textContent = WebInspector.UIString(propertyName); | |
67 label.htmlFor = propertyName; | |
dgozman
2016/08/24 19:18:30
Use setAttribute.
flandy
2016/08/24 22:08:41
Done.
| |
68 var textInput = field.createChild("input", "shadow-editor-text-input"); | |
69 textInput.type = "text"; | |
70 textInput.id = propertyName; | |
71 textInput.addEventListener("input", this._onTextInput.bind(this), true); | |
dgozman
2016/08/24 19:18:30
Why do we capture all events?
flandy
2016/08/24 22:08:41
We want any valid changes to be reflected immediat
dgozman
2016/08/24 23:26:58
I was talking about last parameter being |true|. S
flandy
2016/08/25 00:17:47
Oh I see, done!
| |
72 textInput.addEventListener("blur", this._onTextBlur.bind(this), true); | |
73 var halfRange = WebInspector.CSSShadowEditor.maxRange / 2; | |
74 var slider = negativeAllowed ? createSliderLabel(halfRange * -1, halfRan ge) : createSliderLabel(0, WebInspector.CSSShadowEditor.maxRange); | |
dgozman
2016/08/24 19:18:30
-halfRange
flandy
2016/08/24 22:08:41
Done.
| |
75 slider.addEventListener("input", this._onSliderInput.bind(this), true); | |
76 field.appendChild(slider); | |
77 return {field: field, textInput: textInput, rangeInput: slider}; | |
78 }, | |
79 | |
80 hideBoxShadowProperties: function() | |
dgozman
2016/08/24 19:18:30
Isn't this class reused? We should.
flandy
2016/08/24 22:08:41
Is CSSShadowEditor re-used for text-shadows? Yes.
dgozman
2016/08/24 23:26:58
What I meant is that creating an editor every time
flandy
2016/08/25 00:17:47
Thanks for clarifying. Done.
| |
81 { | |
82 this._typeField.hidden = true; | |
dgozman
2016/08/24 19:18:30
Figure that out from this._model.
flandy
2016/08/24 22:08:41
Done.
| |
83 this._spreadField.hidden = true; | |
84 }, | |
85 | |
86 _updateUI: function() | |
87 { | |
88 this._updateButtons(); | |
89 this._updateSliders(); | |
90 this._xInput.value = this._model.offsetX().asCSSText(); | |
91 this._yInput.value = this._model.offsetY().asCSSText(); | |
92 this._blurInput.value = this._model.blurRadius().asCSSText(); | |
93 this._spreadInput.value = this._model.spreadRadius().asCSSText(); | |
94 }, | |
95 | |
96 _updateButtons: function() | |
97 { | |
98 this._insetButton.classList.toggle("enabled", this._model.inset()); | |
99 this._outsetButton.classList.toggle("enabled", !this._model.inset()); | |
100 }, | |
101 | |
102 _updateSliders: function() | |
103 { | |
104 this._xSlider.value = this._model.offsetX().amount; | |
105 this._ySlider.value = this._model.offsetY().amount; | |
106 this._blurSlider.value = this._model.blurRadius().amount; | |
107 this._spreadSlider.value = this._model.spreadRadius().amount; | |
108 }, | |
109 | |
110 /** | |
111 * @param {!Event} event | |
112 */ | |
113 _onButtonClick: function(event) | |
114 { | |
115 var insetClicked = (event.currentTarget === this._insetButton); | |
116 if (insetClicked && this._model.inset() || !insetClicked && !this._model .inset()) | |
117 return; | |
118 this._model.setInset(insetClicked); | |
119 this._updateButtons(); | |
120 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | |
121 }, | |
122 | |
123 /** | |
124 * @param {!Event} event | |
125 */ | |
126 _onTextInput: function(event) | |
127 { | |
128 this._changedElement = event.currentTarget; | |
129 this._changedElement.classList.toggle("invalid", false); | |
130 var length = WebInspector.CSSLength.parse(event.currentTarget.value); | |
131 if (!length || event.currentTarget === this._blurInput && length.amount < 0) | |
132 return; | |
133 if (event.currentTarget === this._xInput) | |
134 this._model.setOffset(length, this._model.offsetY()); | |
dgozman
2016/08/24 19:18:30
Why don't we have separate setOffsetX and setOffse
flandy
2016/08/24 22:08:41
Done.
| |
135 else if (event.currentTarget === this._yInput) | |
136 this._model.setOffset(this._model.offsetX(), length); | |
137 else if (event.currentTarget === this._blurInput) | |
138 this._model.setBlurRadius(length); | |
139 else if (event.currentTarget === this._spreadInput) | |
140 this._model.setSpreadRadius(length); | |
141 this._updateSliders(); | |
dgozman
2016/08/24 19:18:30
Let's update them separately as we do for inputs.
flandy
2016/08/24 22:08:41
Done.
| |
142 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | |
143 }, | |
144 | |
145 _onTextBlur: function() | |
146 { | |
147 if (!this._changedElement) | |
148 return; | |
149 var length = this._changedElement.value === "" ? WebInspector.CSSLength. zero() : WebInspector.CSSLength.parse(this._changedElement.value); | |
dgozman
2016/08/24 19:18:30
x === "" should be !x
flandy
2016/08/24 22:08:41
Done.
| |
150 if (!length) | |
151 length = WebInspector.CSSLength.parse(this._changedElement.value + W ebInspector.CSSShadowEditor.defaultUnit); | |
152 if (!length) { | |
153 this._changedElement.classList.add("invalid"); | |
154 this._changedElement = null; | |
155 return; | |
156 } | |
157 if (this._changedElement === this._xInput) { | |
158 this._model.setOffset(length, this._model.offsetY()); | |
159 this._xInput.value = this._model.offsetX().asCSSText(); | |
160 } else if (this._changedElement === this._yInput) { | |
161 this._model.setOffset(this._model.offsetX(), length); | |
162 this._yInput.value = this._model.offsetY().asCSSText(); | |
163 } else if (this._changedElement === this._blurInput) { | |
164 if (length.amount < 0) | |
165 length = WebInspector.CSSLength.zero(); | |
166 this._model.setBlurRadius(length); | |
167 this._blurInput.value = this._model.blurRadius().asCSSText(); | |
168 } else if (this._changedElement === this._spreadInput) { | |
169 this._model.setSpreadRadius(length); | |
170 this._spreadInput.value = this._model.spreadRadius().asCSSText(); | |
171 } | |
172 this._changedElement = null; | |
173 this._updateSliders(); | |
174 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | |
175 }, | |
176 | |
177 /** | |
178 * @param {!Event} event | |
179 */ | |
180 _onSliderInput: function(event) | |
181 { | |
182 if (event.currentTarget === this._xSlider) { | |
183 this._model.setOffset(new WebInspector.CSSLength(this._xSlider.value , this._model.offsetX().unit || WebInspector.CSSShadowEditor.defaultUnit), this. _model.offsetY()); | |
184 this._xInput.value = this._model.offsetX().asCSSText(); | |
185 this._xInput.classList.toggle("invalid", false); | |
186 } else if (event.currentTarget === this._ySlider) { | |
187 this._model.setOffset(this._model.offsetX(), new WebInspector.CSSLen gth(this._ySlider.value, this._model.offsetY().unit || WebInspector.CSSShadowEdi tor.defaultUnit)); | |
188 this._yInput.value = this._model.offsetY().asCSSText(); | |
189 this._yInput.classList.toggle("invalid", false); | |
190 } else if (event.currentTarget === this._blurSlider) { | |
191 this._model.setBlurRadius(new WebInspector.CSSLength(this._blurSlide r.value, this._model.blurRadius().unit || WebInspector.CSSShadowEditor.defaultUn it)); | |
192 this._blurInput.value = this._model.blurRadius().asCSSText(); | |
193 this._blurInput.classList.toggle("invalid", false); | |
194 } else if (event.currentTarget === this._spreadSlider) { | |
195 this._model.setSpreadRadius(new WebInspector.CSSLength(this._spreadS lider.value, this._model.spreadRadius().unit || WebInspector.CSSShadowEditor.def aultUnit)); | |
196 this._spreadInput.value = this._model.spreadRadius().asCSSText(); | |
197 this._spreadInput.classList.toggle("invalid", false); | |
198 } | |
199 this.dispatchEventToListeners(WebInspector.CSSShadowEditor.Events.Shadow Changed, this._model); | |
200 }, | |
201 | |
202 __proto__: WebInspector.VBox.prototype | |
203 } | |
OLD | NEW |