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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 /** | 152 /** |
153 * @return {Element} | 153 * @return {Element} |
154 */ | 154 */ |
155 element: function() { } | 155 element: function() { } |
156 } | 156 } |
157 | 157 |
158 /** | 158 /** |
159 * @constructor | 159 * @constructor |
160 * @implements {WebInspector.FilterUI} | 160 * @implements {WebInspector.FilterUI} |
161 * @extends {WebInspector.Object} | 161 * @extends {WebInspector.Object} |
| 162 * @param {boolean=} supportRegex |
162 */ | 163 */ |
163 WebInspector.TextFilterUI = function() | 164 WebInspector.TextFilterUI = function(supportRegex) |
164 { | 165 { |
| 166 this._supportRegex = !!supportRegex; |
| 167 this._regex = null; |
| 168 |
165 this._filterElement = document.createElement("div"); | 169 this._filterElement = document.createElement("div"); |
166 this._filterElement.className = "filter-text-filter"; | 170 this._filterElement.className = "filter-text-filter"; |
167 | 171 |
168 this._filterInputElement = this._filterElement.createChild("input", "search-
replace toolbar-replace-control"); | 172 this._filterInputElement = this._filterElement.createChild("input", "search-
replace toolbar-replace-control"); |
169 this._filterInputElement.placeholder = WebInspector.UIString("Filter"); | 173 this._filterInputElement.placeholder = WebInspector.UIString("Filter"); |
170 this._filterInputElement.id = "filter-input-field"; | 174 this._filterInputElement.id = "filter-input-field"; |
171 this._filterInputElement.addEventListener("mousedown", this._onFilterFieldMa
nualFocus.bind(this), false); // when the search field is manually selected | 175 this._filterInputElement.addEventListener("mousedown", this._onFilterFieldMa
nualFocus.bind(this), false); // when the search field is manually selected |
172 this._filterInputElement.addEventListener("input", this._onInput.bind(this),
false); | 176 this._filterInputElement.addEventListener("input", this._onInput.bind(this),
false); |
173 this._filterInputElement.addEventListener("change", this._onInput.bind(this)
, false); | 177 this._filterInputElement.addEventListener("change", this._onInput.bind(this)
, false); |
| 178 |
| 179 if (this._supportRegex) { |
| 180 this._filterElement.classList.add("supports-regex"); |
| 181 this._regexCheckBox = this._filterElement.createChild("input"); |
| 182 this._regexCheckBox.type = "checkbox"; |
| 183 this._regexCheckBox.id = "text-filter-regex"; |
| 184 this._regexCheckBox.addEventListener("change", this._onInput.bind(this),
false); |
| 185 |
| 186 this._regexLabel = this._filterElement.createChild("label"); |
| 187 this._regexLabel.htmlFor = "text-filter-regex"; |
| 188 this._regexLabel.textContent = WebInspector.UIString("Regex"); |
| 189 } |
174 } | 190 } |
175 | 191 |
176 WebInspector.TextFilterUI.prototype = { | 192 WebInspector.TextFilterUI.prototype = { |
177 /** | 193 /** |
178 * @return {boolean} | 194 * @return {boolean} |
179 */ | 195 */ |
180 isActive: function() | 196 isActive: function() |
181 { | 197 { |
182 return !!this._filterInputElement.value; | 198 return !!this._filterInputElement.value; |
183 }, | 199 }, |
(...skipping 21 matching lines...) Expand all Loading... |
205 { | 221 { |
206 this._filterInputElement.value = value; | 222 this._filterInputElement.value = value; |
207 this._valueChanged(); | 223 this._valueChanged(); |
208 }, | 224 }, |
209 | 225 |
210 /** | 226 /** |
211 * @return {?RegExp} | 227 * @return {?RegExp} |
212 */ | 228 */ |
213 regex: function() | 229 regex: function() |
214 { | 230 { |
215 if (this._regex !== undefined) | |
216 return this._regex; | |
217 var filterQuery = this.value(); | |
218 this._regex = filterQuery ? createPlainTextSearchRegex(filterQuery, "i")
: null; | |
219 return this._regex; | 231 return this._regex; |
220 }, | 232 }, |
221 | 233 |
222 /** | 234 /** |
223 * @param {Event} event | 235 * @param {Event} event |
224 */ | 236 */ |
225 _onFilterFieldManualFocus: function(event) | 237 _onFilterFieldManualFocus: function(event) |
226 { | 238 { |
227 WebInspector.setCurrentFocusElement(event.target); | 239 WebInspector.setCurrentFocusElement(event.target); |
228 }, | 240 }, |
229 | 241 |
230 /** | 242 /** |
231 * @param {WebInspector.Event} event | 243 * @param {WebInspector.Event} event |
232 */ | 244 */ |
233 _onInput: function(event) | 245 _onInput: function(event) |
234 { | 246 { |
235 this._valueChanged(); | 247 this._valueChanged(); |
236 }, | 248 }, |
237 | 249 |
238 _valueChanged: function() { | 250 _valueChanged: function() { |
239 delete this._regex; | 251 var filterQuery = this.value(); |
| 252 |
| 253 this._regex = null; |
| 254 this._filterInputElement.classList.remove("filter-text-invalid"); |
| 255 if (filterQuery) { |
| 256 if (this._supportRegex && this._regexCheckBox.checked) { |
| 257 try { |
| 258 this._regex = new RegExp(filterQuery, "i"); |
| 259 } catch (e) { |
| 260 this._filterInputElement.classList.add("filter-text-invalid"
); |
| 261 } |
| 262 } else { |
| 263 this._regex = createPlainTextSearchRegex(filterQuery, "i"); |
| 264 } |
| 265 } |
| 266 |
240 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged
, null); | 267 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged
, null); |
241 }, | 268 }, |
242 | 269 |
243 __proto__: WebInspector.Object.prototype | 270 __proto__: WebInspector.Object.prototype |
244 } | 271 } |
245 | 272 |
246 /** | 273 /** |
247 * @constructor | 274 * @constructor |
248 * @implements {WebInspector.FilterUI} | 275 * @implements {WebInspector.FilterUI} |
249 * @extends {WebInspector.Object} | 276 * @extends {WebInspector.Object} |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 var label = this._filterElement.createChild("label"); | 544 var label = this._filterElement.createChild("label"); |
518 var checkBorder = label.createChild("div", "checkbox-filter-checkbox"); | 545 var checkBorder = label.createChild("div", "checkbox-filter-checkbox"); |
519 this._checkElement = checkBorder.createChild("div", "checkbox-filter-che
ckbox-check"); | 546 this._checkElement = checkBorder.createChild("div", "checkbox-filter-che
ckbox-check"); |
520 this._filterElement.addEventListener("click", this._onClick.bind(this),
false); | 547 this._filterElement.addEventListener("click", this._onClick.bind(this),
false); |
521 var typeElement = label.createChild("span", "type"); | 548 var typeElement = label.createChild("span", "type"); |
522 typeElement.textContent = title; | 549 typeElement.textContent = title; |
523 }, | 550 }, |
524 | 551 |
525 __proto__: WebInspector.Object.prototype | 552 __proto__: WebInspector.Object.prototype |
526 } | 553 } |
OLD | NEW |