OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 20 matching lines...) Expand all Loading... |
31 /** | 31 /** |
32 * @unrestricted | 32 * @unrestricted |
33 */ | 33 */ |
34 Sources.CSSSourceFrame = class extends SourceFrame.UISourceCodeFrame { | 34 Sources.CSSSourceFrame = class extends SourceFrame.UISourceCodeFrame { |
35 /** | 35 /** |
36 * @param {!Workspace.UISourceCode} uiSourceCode | 36 * @param {!Workspace.UISourceCode} uiSourceCode |
37 */ | 37 */ |
38 constructor(uiSourceCode) { | 38 constructor(uiSourceCode) { |
39 super(uiSourceCode); | 39 super(uiSourceCode); |
40 this._registerShortcuts(); | 40 this._registerShortcuts(); |
41 this._swatchPopoverHelper = new UI.SwatchPopoverHelper(); | 41 this._swatchPopoverHelper = new InlineEditor.SwatchPopoverHelper(); |
42 this._muteSwatchProcessing = false; | 42 this._muteSwatchProcessing = false; |
43 this.configureAutocomplete( | 43 this.configureAutocomplete( |
44 {suggestionsCallback: this._cssSuggestions.bind(this), isWordChar: this.
_isWordChar.bind(this)}); | 44 {suggestionsCallback: this._cssSuggestions.bind(this), isWordChar: this.
_isWordChar.bind(this)}); |
45 this.textEditor.addEventListener(SourceFrame.SourcesTextEditor.Events.Scroll
Changed, () => { | 45 this.textEditor.addEventListener(SourceFrame.SourcesTextEditor.Events.Scroll
Changed, () => { |
46 if (this._swatchPopoverHelper.isShowing()) | 46 if (this._swatchPopoverHelper.isShowing()) |
47 this._swatchPopoverHelper.hide(true); | 47 this._swatchPopoverHelper.hide(true); |
48 }); | 48 }); |
49 } | 49 } |
50 | 50 |
51 _registerShortcuts() { | 51 _registerShortcuts() { |
52 var shortcutKeys = Components.ShortcutsScreen.SourcesPanelShortcuts; | 52 var shortcutKeys = UI.ShortcutsScreen.SourcesPanelShortcuts; |
53 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByOne.length; ++i) | 53 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByOne.length; ++i) |
54 this.addShortcut(shortcutKeys.IncreaseCSSUnitByOne[i].key, this._handleUni
tModification.bind(this, 1)); | 54 this.addShortcut(shortcutKeys.IncreaseCSSUnitByOne[i].key, this._handleUni
tModification.bind(this, 1)); |
55 for (var i = 0; i < shortcutKeys.DecreaseCSSUnitByOne.length; ++i) | 55 for (var i = 0; i < shortcutKeys.DecreaseCSSUnitByOne.length; ++i) |
56 this.addShortcut(shortcutKeys.DecreaseCSSUnitByOne[i].key, this._handleUni
tModification.bind(this, -1)); | 56 this.addShortcut(shortcutKeys.DecreaseCSSUnitByOne[i].key, this._handleUni
tModification.bind(this, -1)); |
57 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByTen.length; ++i) | 57 for (var i = 0; i < shortcutKeys.IncreaseCSSUnitByTen.length; ++i) |
58 this.addShortcut(shortcutKeys.IncreaseCSSUnitByTen[i].key, this._handleUni
tModification.bind(this, 10)); | 58 this.addShortcut(shortcutKeys.IncreaseCSSUnitByTen[i].key, this._handleUni
tModification.bind(this, 10)); |
59 for (var i = 0; i < shortcutKeys.DecreaseCSSUnitByTen.length; ++i) | 59 for (var i = 0; i < shortcutKeys.DecreaseCSSUnitByTen.length; ++i) |
60 this.addShortcut(shortcutKeys.DecreaseCSSUnitByTen[i].key, this._handleUni
tModification.bind(this, -10)); | 60 this.addShortcut(shortcutKeys.DecreaseCSSUnitByTen[i].key, this._handleUni
tModification.bind(this, -10)); |
61 } | 61 } |
62 | 62 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 var swatchPosition = swatchPositions[i]; | 151 var swatchPosition = swatchPositions[i]; |
152 var bookmark = this.textEditor.addBookmark( | 152 var bookmark = this.textEditor.addBookmark( |
153 swatchPosition.startLine, swatchPosition.startColumn, swatch, Source
s.CSSSourceFrame.SwatchBookmark); | 153 swatchPosition.startLine, swatchPosition.startColumn, swatch, Source
s.CSSSourceFrame.SwatchBookmark); |
154 swatch[Sources.CSSSourceFrame.SwatchBookmark] = bookmark; | 154 swatch[Sources.CSSSourceFrame.SwatchBookmark] = bookmark; |
155 } | 155 } |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 /** | 159 /** |
160 * @param {string} text | 160 * @param {string} text |
161 * @return {?UI.ColorSwatch} | 161 * @return {?InlineEditor.ColorSwatch} |
162 */ | 162 */ |
163 _createColorSwatch(text) { | 163 _createColorSwatch(text) { |
164 var color = Common.Color.parse(text); | 164 var color = Common.Color.parse(text); |
165 if (!color) | 165 if (!color) |
166 return null; | 166 return null; |
167 var swatch = UI.ColorSwatch.create(); | 167 var swatch = InlineEditor.ColorSwatch.create(); |
168 swatch.setColor(color); | 168 swatch.setColor(color); |
169 swatch.iconElement().title = Common.UIString('Open color picker.'); | 169 swatch.iconElement().title = Common.UIString('Open color picker.'); |
170 swatch.iconElement().addEventListener('click', this._swatchIconClicked.bind(
this, swatch), false); | 170 swatch.iconElement().addEventListener('click', this._swatchIconClicked.bind(
this, swatch), false); |
171 swatch.hideText(true); | 171 swatch.hideText(true); |
172 return swatch; | 172 return swatch; |
173 } | 173 } |
174 | 174 |
175 /** | 175 /** |
176 * @param {string} text | 176 * @param {string} text |
177 * @return {?UI.BezierSwatch} | 177 * @return {?InlineEditor.BezierSwatch} |
178 */ | 178 */ |
179 _createBezierSwatch(text) { | 179 _createBezierSwatch(text) { |
180 if (!Common.Geometry.CubicBezier.parse(text)) | 180 if (!Common.Geometry.CubicBezier.parse(text)) |
181 return null; | 181 return null; |
182 var swatch = UI.BezierSwatch.create(); | 182 var swatch = InlineEditor.BezierSwatch.create(); |
183 swatch.setBezierText(text); | 183 swatch.setBezierText(text); |
184 swatch.iconElement().title = Common.UIString('Open cubic bezier editor.'); | 184 swatch.iconElement().title = Common.UIString('Open cubic bezier editor.'); |
185 swatch.iconElement().addEventListener('click', this._swatchIconClicked.bind(
this, swatch), false); | 185 swatch.iconElement().addEventListener('click', this._swatchIconClicked.bind(
this, swatch), false); |
186 swatch.hideText(true); | 186 swatch.hideText(true); |
187 return swatch; | 187 return swatch; |
188 } | 188 } |
189 | 189 |
190 /** | 190 /** |
191 * @param {!Element} swatch | 191 * @param {!Element} swatch |
192 * @param {!Event} event | 192 * @param {!Event} event |
193 */ | 193 */ |
194 _swatchIconClicked(swatch, event) { | 194 _swatchIconClicked(swatch, event) { |
195 event.consume(true); | 195 event.consume(true); |
196 this._hadSwatchChange = false; | 196 this._hadSwatchChange = false; |
197 this._muteSwatchProcessing = true; | 197 this._muteSwatchProcessing = true; |
198 var swatchPosition = swatch[Sources.CSSSourceFrame.SwatchBookmark].position(
); | 198 var swatchPosition = swatch[Sources.CSSSourceFrame.SwatchBookmark].position(
); |
199 this.textEditor.setSelection(swatchPosition); | 199 this.textEditor.setSelection(swatchPosition); |
200 this._editedSwatchTextRange = swatchPosition.clone(); | 200 this._editedSwatchTextRange = swatchPosition.clone(); |
201 this._editedSwatchTextRange.endColumn += swatch.textContent.length; | 201 this._editedSwatchTextRange.endColumn += swatch.textContent.length; |
202 this._currentSwatch = swatch; | 202 this._currentSwatch = swatch; |
203 | 203 |
204 if (swatch instanceof UI.ColorSwatch) | 204 if (swatch instanceof InlineEditor.ColorSwatch) |
205 this._showSpectrum(swatch); | 205 this._showSpectrum(swatch); |
206 else if (swatch instanceof UI.BezierSwatch) | 206 else if (swatch instanceof InlineEditor.BezierSwatch) |
207 this._showBezierEditor(swatch); | 207 this._showBezierEditor(swatch); |
208 } | 208 } |
209 | 209 |
210 /** | 210 /** |
211 * @param {!UI.ColorSwatch} swatch | 211 * @param {!InlineEditor.ColorSwatch} swatch |
212 */ | 212 */ |
213 _showSpectrum(swatch) { | 213 _showSpectrum(swatch) { |
214 if (!this._spectrum) { | 214 if (!this._spectrum) { |
215 this._spectrum = new Components.Spectrum(); | 215 this._spectrum = new ColorPicker.Spectrum(); |
216 this._spectrum.addEventListener(Components.Spectrum.Events.SizeChanged, th
is._spectrumResized, this); | 216 this._spectrum.addEventListener(ColorPicker.Spectrum.Events.SizeChanged, t
his._spectrumResized, this); |
217 this._spectrum.addEventListener(Components.Spectrum.Events.ColorChanged, t
his._spectrumChanged, this); | 217 this._spectrum.addEventListener(ColorPicker.Spectrum.Events.ColorChanged,
this._spectrumChanged, this); |
218 } | 218 } |
219 this._spectrum.setColor(swatch.color(), swatch.format()); | 219 this._spectrum.setColor(swatch.color(), swatch.format()); |
220 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), this._s
watchPopoverHidden.bind(this)); | 220 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), this._s
watchPopoverHidden.bind(this)); |
221 } | 221 } |
222 | 222 |
223 /** | 223 /** |
224 * @param {!Common.Event} event | 224 * @param {!Common.Event} event |
225 */ | 225 */ |
226 _spectrumResized(event) { | 226 _spectrumResized(event) { |
227 this._swatchPopoverHelper.reposition(); | 227 this._swatchPopoverHelper.reposition(); |
228 } | 228 } |
229 | 229 |
230 /** | 230 /** |
231 * @param {!Common.Event} event | 231 * @param {!Common.Event} event |
232 */ | 232 */ |
233 _spectrumChanged(event) { | 233 _spectrumChanged(event) { |
234 var colorString = /** @type {string} */ (event.data); | 234 var colorString = /** @type {string} */ (event.data); |
235 var color = Common.Color.parse(colorString); | 235 var color = Common.Color.parse(colorString); |
236 if (!color) | 236 if (!color) |
237 return; | 237 return; |
238 this._currentSwatch.setColor(color); | 238 this._currentSwatch.setColor(color); |
239 this._changeSwatchText(colorString); | 239 this._changeSwatchText(colorString); |
240 } | 240 } |
241 | 241 |
242 /** | 242 /** |
243 * @param {!UI.BezierSwatch} swatch | 243 * @param {!InlineEditor.BezierSwatch} swatch |
244 */ | 244 */ |
245 _showBezierEditor(swatch) { | 245 _showBezierEditor(swatch) { |
246 if (!this._bezierEditor) { | 246 if (!this._bezierEditor) { |
247 this._bezierEditor = new UI.BezierEditor(); | 247 this._bezierEditor = new InlineEditor.BezierEditor(); |
248 this._bezierEditor.addEventListener(UI.BezierEditor.Events.BezierChanged,
this._bezierChanged, this); | 248 this._bezierEditor.addEventListener(InlineEditor.BezierEditor.Events.Bezie
rChanged, this._bezierChanged, this); |
249 } | 249 } |
250 var cubicBezier = Common.Geometry.CubicBezier.parse(swatch.bezierText()); | 250 var cubicBezier = Common.Geometry.CubicBezier.parse(swatch.bezierText()); |
251 if (!cubicBezier) { | 251 if (!cubicBezier) { |
252 cubicBezier = | 252 cubicBezier = |
253 /** @type {!Common.Geometry.CubicBezier} */ (Common.Geometry.CubicBezi
er.parse('linear')); | 253 /** @type {!Common.Geometry.CubicBezier} */ (Common.Geometry.CubicBezi
er.parse('linear')); |
254 } | 254 } |
255 this._bezierEditor.setBezier(cubicBezier); | 255 this._bezierEditor.setBezier(cubicBezier); |
256 this._swatchPopoverHelper.show(this._bezierEditor, swatch.iconElement(), thi
s._swatchPopoverHidden.bind(this)); | 256 this._swatchPopoverHelper.show(this._bezierEditor, swatch.iconElement(), thi
s._swatchPopoverHidden.bind(this)); |
257 } | 257 } |
258 | 258 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 tokenPosition = token.startColumn - 1; | 360 tokenPosition = token.startColumn - 1; |
361 } | 361 } |
362 return null; | 362 return null; |
363 } | 363 } |
364 }; | 364 }; |
365 | 365 |
366 /** @type {number} */ | 366 /** @type {number} */ |
367 Sources.CSSSourceFrame.maxSwatchProcessingLength = 300; | 367 Sources.CSSSourceFrame.maxSwatchProcessingLength = 300; |
368 /** @type {symbol} */ | 368 /** @type {symbol} */ |
369 Sources.CSSSourceFrame.SwatchBookmark = Symbol('swatch'); | 369 Sources.CSSSourceFrame.SwatchBookmark = Symbol('swatch'); |
OLD | NEW |