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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 isActive: function() { }, | 157 isActive: function() { }, |
158 | 158 |
159 /** | 159 /** |
160 * @return {!Element} | 160 * @return {!Element} |
161 */ | 161 */ |
162 element: function() { } | 162 element: function() { } |
163 } | 163 } |
164 | 164 |
165 /** | 165 /** |
166 * @constructor | 166 * @constructor |
| 167 * @extends {WebInspector.Object} |
167 * @implements {WebInspector.FilterUI} | 168 * @implements {WebInspector.FilterUI} |
168 * @extends {WebInspector.Object} | 169 * @implements {WebInspector.SuggestBoxDelegate} |
169 * @param {boolean=} supportRegex | 170 * @param {boolean=} supportRegex |
170 */ | 171 */ |
171 WebInspector.TextFilterUI = function(supportRegex) | 172 WebInspector.TextFilterUI = function(supportRegex) |
172 { | 173 { |
173 this._supportRegex = !!supportRegex; | 174 this._supportRegex = !!supportRegex; |
174 this._regex = null; | 175 this._regex = null; |
175 | 176 |
176 this._filterElement = document.createElement("div"); | 177 this._filterElement = document.createElement("div"); |
177 this._filterElement.className = "filter-text-filter"; | 178 this._filterElement.className = "filter-text-filter"; |
178 | 179 |
179 this._filterInputElement = this._filterElement.createChild("input", "search-
replace toolbar-replace-control"); | 180 this._filterInputElement = this._filterElement.createChild("input", "search-
replace toolbar-replace-control"); |
180 this._filterInputElement.placeholder = WebInspector.UIString("Filter"); | 181 this._filterInputElement.placeholder = WebInspector.UIString("Filter"); |
181 this._filterInputElement.id = "filter-input-field"; | 182 this._filterInputElement.id = "filter-input-field"; |
182 this._filterInputElement.addEventListener("mousedown", this._onFilterFieldMa
nualFocus.bind(this), false); // when the search field is manually selected | 183 this._filterInputElement.addEventListener("mousedown", this._onFilterFieldMa
nualFocus.bind(this), false); // when the search field is manually selected |
183 this._filterInputElement.addEventListener("input", this._onInput.bind(this),
false); | 184 this._filterInputElement.addEventListener("input", this._onInput.bind(this),
false); |
184 this._filterInputElement.addEventListener("change", this._onInput.bind(this)
, false); | 185 this._filterInputElement.addEventListener("change", this._onInput.bind(this)
, false); |
| 186 this._filterInputElement.addEventListener("keydown", this._onInputKeyDown.bi
nd(this), true); |
| 187 this._filterInputElement.addEventListener("blur", this._onBlur.bind(this), t
rue); |
| 188 |
| 189 /** @type {?WebInspector.TextFilterUI.SuggestionBuilder} */ |
| 190 this._suggestionBuilder = null; |
| 191 |
| 192 this._suggestBox = new WebInspector.SuggestBox(this, this._filterElement); |
185 | 193 |
186 if (this._supportRegex) { | 194 if (this._supportRegex) { |
187 this._filterElement.classList.add("supports-regex"); | 195 this._filterElement.classList.add("supports-regex"); |
188 this._regexCheckBox = this._filterElement.createChild("input"); | 196 this._regexCheckBox = this._filterElement.createChild("input"); |
189 this._regexCheckBox.type = "checkbox"; | 197 this._regexCheckBox.type = "checkbox"; |
190 this._regexCheckBox.id = "text-filter-regex"; | 198 this._regexCheckBox.id = "text-filter-regex"; |
191 this._regexCheckBox.addEventListener("change", this._onInput.bind(this),
false); | 199 this._regexCheckBox.addEventListener("change", this._onInput.bind(this),
false); |
192 | 200 |
193 this._regexLabel = this._filterElement.createChild("label"); | 201 this._regexLabel = this._filterElement.createChild("label"); |
194 this._regexLabel.htmlFor = "text-filter-regex"; | 202 this._regexLabel.htmlFor = "text-filter-regex"; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 248 |
241 /** | 249 /** |
242 * @param {?Event} event | 250 * @param {?Event} event |
243 */ | 251 */ |
244 _onFilterFieldManualFocus: function(event) | 252 _onFilterFieldManualFocus: function(event) |
245 { | 253 { |
246 WebInspector.setCurrentFocusElement(event.target); | 254 WebInspector.setCurrentFocusElement(event.target); |
247 }, | 255 }, |
248 | 256 |
249 /** | 257 /** |
| 258 * @param {?Event} event |
| 259 */ |
| 260 _onBlur: function(event) |
| 261 { |
| 262 this._suggestBox.hide(); |
| 263 }, |
| 264 |
| 265 /** |
250 * @param {!WebInspector.Event} event | 266 * @param {!WebInspector.Event} event |
251 */ | 267 */ |
252 _onInput: function(event) | 268 _onInput: function(event) |
253 { | 269 { |
254 this._valueChanged(); | 270 this._valueChanged(); |
255 }, | 271 }, |
256 | 272 |
257 _valueChanged: function() { | 273 /** |
| 274 * @param {?WebInspector.TextFilterUI.SuggestionBuilder} suggestionBuilder |
| 275 */ |
| 276 setSuggestionBuilder: function(suggestionBuilder) |
| 277 { |
| 278 this._suggestionBuilder = suggestionBuilder; |
| 279 if (document.activeElement === this._filterInputElement) |
| 280 this._updateSuggestions(); |
| 281 }, |
| 282 |
| 283 _updateSuggestions: function() |
| 284 { |
| 285 if (!this._suggestionBuilder) { |
| 286 this._suggestBox.hide(); |
| 287 return; |
| 288 } |
| 289 var suggestions = this._suggestionBuilder.buildSuggestions(this._filterI
nputElement); |
| 290 if (suggestions && suggestions.length) |
| 291 this._suggestBox.updateSuggestions(null, suggestions, 0, true, ""); |
| 292 else |
| 293 this._suggestBox.hide(); |
| 294 }, |
| 295 |
| 296 _valueChanged: function() |
| 297 { |
| 298 this._updateSuggestions(); |
258 var filterQuery = this.value(); | 299 var filterQuery = this.value(); |
259 | 300 |
260 this._regex = null; | 301 this._regex = null; |
261 this._filterInputElement.classList.remove("filter-text-invalid"); | 302 this._filterInputElement.classList.remove("filter-text-invalid"); |
262 if (filterQuery) { | 303 if (filterQuery) { |
263 if (this._supportRegex && this._regexCheckBox.checked) { | 304 if (this._supportRegex && this._regexCheckBox.checked) { |
264 try { | 305 try { |
265 this._regex = new RegExp(filterQuery, "i"); | 306 this._regex = new RegExp(filterQuery, "i"); |
266 } catch (e) { | 307 } catch (e) { |
267 this._filterInputElement.classList.add("filter-text-invalid"
); | 308 this._filterInputElement.classList.add("filter-text-invalid"
); |
268 } | 309 } |
269 } else { | 310 } else { |
270 this._regex = createPlainTextSearchRegex(filterQuery, "i"); | 311 this._regex = createPlainTextSearchRegex(filterQuery, "i"); |
271 } | 312 } |
272 } | 313 } |
273 | 314 |
274 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged
, null); | 315 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged
, null); |
275 }, | 316 }, |
276 | 317 |
| 318 /** |
| 319 * @param {!KeyboardEvent} event |
| 320 * @return {boolean} |
| 321 */ |
| 322 _onInputKeyDown: function(event) |
| 323 { |
| 324 var handled = false; |
| 325 if (this._suggestBox.visible()) { |
| 326 if (event.keyIdentifier === "U+0009") // Tab |
| 327 handled = this._suggestBox.enterKeyPressed(); |
| 328 else |
| 329 handled = this._suggestBox.keyPressed(event); |
| 330 } |
| 331 if (handled) |
| 332 event.consume(true); |
| 333 return handled; |
| 334 }, |
| 335 |
| 336 /** |
| 337 * @override |
| 338 * @param {string} suggestion |
| 339 * @param {boolean=} isIntermediateSuggestion |
| 340 */ |
| 341 applySuggestion: function(suggestion, isIntermediateSuggestion) |
| 342 { |
| 343 if (!this._suggestionBuilder || isIntermediateSuggestion) |
| 344 return; |
| 345 this._suggestionBuilder.applySuggestion(this._filterInputElement, sugges
tion); |
| 346 }, |
| 347 |
| 348 /** @override */ |
| 349 acceptSuggestion: function() |
| 350 { |
| 351 this._filterInputElement.scrollLeft = this._filterInputElement.scrollWid
th; |
| 352 this._valueChanged(); |
| 353 }, |
| 354 |
277 __proto__: WebInspector.Object.prototype | 355 __proto__: WebInspector.Object.prototype |
278 } | 356 } |
279 | 357 |
280 /** | 358 /** |
| 359 * @interface |
| 360 */ |
| 361 WebInspector.TextFilterUI.SuggestionBuilder = function() |
| 362 { |
| 363 } |
| 364 |
| 365 WebInspector.TextFilterUI.SuggestionBuilder.prototype = { |
| 366 /** |
| 367 * @param {!HTMLInputElement} input |
| 368 * @return {?Array.<string>} |
| 369 */ |
| 370 buildSuggestions: function(input) { }, |
| 371 |
| 372 /** |
| 373 * @param {!HTMLInputElement} input |
| 374 * @param {string} suggestion |
| 375 */ |
| 376 applySuggestion: function(input, suggestion) { } |
| 377 } |
| 378 |
| 379 /** |
281 * @constructor | 380 * @constructor |
282 * @implements {WebInspector.FilterUI} | 381 * @implements {WebInspector.FilterUI} |
283 * @extends {WebInspector.Object} | 382 * @extends {WebInspector.Object} |
284 */ | 383 */ |
285 WebInspector.NamedBitSetFilterUI = function() | 384 WebInspector.NamedBitSetFilterUI = function() |
286 { | 385 { |
287 this._filtersElement = document.createElement("div"); | 386 this._filtersElement = document.createElement("div"); |
288 this._filtersElement.className = "filter-bitset-filter status-bar-item"; | 387 this._filtersElement.className = "filter-bitset-filter status-bar-item"; |
289 this._filtersElement.title = WebInspector.UIString("Use %s Click to select m
ultiple types.", WebInspector.KeyboardShortcut.shortcutToString("", WebInspector
.KeyboardShortcut.Modifiers.CtrlOrMeta)); | 388 this._filtersElement.title = WebInspector.UIString("Use %s Click to select m
ultiple types.", WebInspector.KeyboardShortcut.shortcutToString("", WebInspector
.KeyboardShortcut.Modifiers.CtrlOrMeta)); |
290 | 389 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 var label = this._filterElement.createChild("label"); | 675 var label = this._filterElement.createChild("label"); |
577 var checkBorder = label.createChild("div", "checkbox-filter-checkbox"); | 676 var checkBorder = label.createChild("div", "checkbox-filter-checkbox"); |
578 this._checkElement = checkBorder.createChild("div", "checkbox-filter-che
ckbox-check"); | 677 this._checkElement = checkBorder.createChild("div", "checkbox-filter-che
ckbox-check"); |
579 this._filterElement.addEventListener("click", this._onClick.bind(this),
false); | 678 this._filterElement.addEventListener("click", this._onClick.bind(this),
false); |
580 var typeElement = label.createChild("span", "type"); | 679 var typeElement = label.createChild("span", "type"); |
581 typeElement.textContent = title; | 680 typeElement.textContent = title; |
582 }, | 681 }, |
583 | 682 |
584 __proto__: WebInspector.Object.prototype | 683 __proto__: WebInspector.Object.prototype |
585 } | 684 } |
OLD | NEW |