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._regexCheckBox = this._filterElement.createChild("input"); | |
vsevik
2013/11/27 13:37:23
4 spaces indent in blink.
Dmitry Zvorygin
2013/11/27 17:52:24
Done.
| |
181 this._regexCheckBox.type = "checkbox"; | |
182 this._regexCheckBox.id = "text-filter-regex"; | |
183 this._regexCheckBox.addEventListener("change", this._onInput.bind(this), f alse); | |
184 | |
185 this._regexLabel = this._filterElement.createChild("label"); | |
186 this._regexLabel.htmlFor = "text-filter-regex"; | |
187 this._regexLabel.textContent = WebInspector.UIString("Regex"); | |
188 } | |
174 } | 189 } |
175 | 190 |
176 WebInspector.TextFilterUI.prototype = { | 191 WebInspector.TextFilterUI.prototype = { |
177 /** | 192 /** |
178 * @return {boolean} | 193 * @return {boolean} |
179 */ | 194 */ |
180 isActive: function() | 195 isActive: function() |
181 { | 196 { |
182 return !!this._filterInputElement.value; | 197 return !!this._filterInputElement.value; |
183 }, | 198 }, |
(...skipping 21 matching lines...) Expand all Loading... | |
205 { | 220 { |
206 this._filterInputElement.value = value; | 221 this._filterInputElement.value = value; |
207 this._valueChanged(); | 222 this._valueChanged(); |
208 }, | 223 }, |
209 | 224 |
210 /** | 225 /** |
211 * @return {?RegExp} | 226 * @return {?RegExp} |
212 */ | 227 */ |
213 regex: function() | 228 regex: function() |
214 { | 229 { |
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; | 230 return this._regex; |
220 }, | 231 }, |
221 | 232 |
222 /** | 233 /** |
223 * @param {Event} event | 234 * @param {Event} event |
224 */ | 235 */ |
225 _onFilterFieldManualFocus: function(event) | 236 _onFilterFieldManualFocus: function(event) |
226 { | 237 { |
227 WebInspector.setCurrentFocusElement(event.target); | 238 WebInspector.setCurrentFocusElement(event.target); |
228 }, | 239 }, |
229 | 240 |
230 /** | 241 /** |
231 * @param {WebInspector.Event} event | 242 * @param {WebInspector.Event} event |
232 */ | 243 */ |
233 _onInput: function(event) | 244 _onInput: function(event) |
234 { | 245 { |
235 this._valueChanged(); | 246 this._valueChanged(); |
236 }, | 247 }, |
237 | 248 |
238 _valueChanged: function() { | 249 _valueChanged: function() { |
239 delete this._regex; | 250 var filterQuery = this.value(); |
251 | |
252 this._regex = null | |
253 this._filterInputElement.classList.remove("filter-text-invalid"); | |
254 if (filterQuery) { | |
255 if (this._supportRegex && this._regexCheckBox.checked) { | |
256 try { | |
257 this._regex = new RegExp(filterQuery, "i"); | |
258 } catch (e) { | |
259 this._filterInputElement.classList.add("filter-text-invalid" ); | |
260 } | |
261 } else { | |
262 this._regex = createPlainTextSearchRegex(filterQuery, "i"); | |
263 } | |
264 } | |
265 | |
240 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null); | 266 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null); |
241 }, | 267 }, |
242 | 268 |
243 __proto__: WebInspector.Object.prototype | 269 __proto__: WebInspector.Object.prototype |
244 } | 270 } |
245 | 271 |
246 /** | 272 /** |
247 * @constructor | 273 * @constructor |
248 * @implements {WebInspector.FilterUI} | 274 * @implements {WebInspector.FilterUI} |
249 * @extends {WebInspector.Object} | 275 * @extends {WebInspector.Object} |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 { | 572 { |
547 this.setChecked(!this._checkElement.checked); | 573 this.setChecked(!this._checkElement.checked); |
548 } | 574 } |
549 | 575 |
550 var typeElement = label.createChild("span", "type"); | 576 var typeElement = label.createChild("span", "type"); |
551 typeElement.textContent = title; | 577 typeElement.textContent = title; |
552 }, | 578 }, |
553 | 579 |
554 __proto__: WebInspector.Object.prototype | 580 __proto__: WebInspector.Object.prototype |
555 } | 581 } |
OLD | NEW |