OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). | 3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). |
4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
5 * Copyright (C) 2011 Google Inc. All rights reserved. | 5 * Copyright (C) 2011 Google Inc. All rights reserved. |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * | 10 * |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 this._searchControlElement = searchControlElementColumn.createChild("span",
"toolbar-search-control"); | 47 this._searchControlElement = searchControlElementColumn.createChild("span",
"toolbar-search-control"); |
48 this._searchInputElement = this._searchControlElement.createChild("input", "
search-replace"); | 48 this._searchInputElement = this._searchControlElement.createChild("input", "
search-replace"); |
49 this._searchInputElement.id = "search-input-field"; | 49 this._searchInputElement.id = "search-input-field"; |
50 | 50 |
51 this._suggestBox = new WebInspector.SuggestBox(this, searchControlElementCol
umn); | 51 this._suggestBox = new WebInspector.SuggestBox(this, searchControlElementCol
umn); |
52 | 52 |
53 this._matchesElement = this._searchControlElement.createChild("label", "sear
ch-results-matches"); | 53 this._matchesElement = this._searchControlElement.createChild("label", "sear
ch-results-matches"); |
54 this._matchesElement.setAttribute("for", "search-input-field"); | 54 this._matchesElement.setAttribute("for", "search-input-field"); |
55 | 55 |
56 this._searchNavigationElement = this._searchControlElement.createChild("div"
, "toolbar-search-navigation-controls"); | 56 this._searchNavigationElement = this._searchControlElement.createChild("div"
, "toolbar-search-navigation-controls"); |
57 this._toggleFilterUI(false); | |
58 | 57 |
59 this._searchNavigationPrevElement = this._searchNavigationElement.createChil
d("div", "toolbar-search-navigation toolbar-search-navigation-prev"); | 58 this._searchNavigationPrevElement = this._searchNavigationElement.createChil
d("div", "toolbar-search-navigation toolbar-search-navigation-prev"); |
60 this._searchNavigationPrevElement.addEventListener("click", this._onPrevButt
onSearch.bind(this), false); | 59 this._searchNavigationPrevElement.addEventListener("click", this._onPrevButt
onSearch.bind(this), false); |
61 this._searchNavigationPrevElement.title = WebInspector.UIString("Search Prev
ious"); | 60 this._searchNavigationPrevElement.title = WebInspector.UIString("Search Prev
ious"); |
62 | 61 |
63 this._searchNavigationNextElement = this._searchNavigationElement.createChil
d("div", "toolbar-search-navigation toolbar-search-navigation-next"); | 62 this._searchNavigationNextElement = this._searchNavigationElement.createChil
d("div", "toolbar-search-navigation toolbar-search-navigation-next"); |
64 this._searchNavigationNextElement.addEventListener("click", this._onNextButt
onSearch.bind(this), false); | 63 this._searchNavigationNextElement.addEventListener("click", this._onNextButt
onSearch.bind(this), false); |
65 this._searchNavigationNextElement.title = WebInspector.UIString("Search Next
"); | 64 this._searchNavigationNextElement.title = WebInspector.UIString("Search Next
"); |
66 | 65 |
67 this._searchInputElement.addEventListener("mousedown", this._onSearchFieldMa
nualFocus.bind(this), false); // when the search field is manually selected | 66 this._searchInputElement.addEventListener("mousedown", this._onSearchFieldMa
nualFocus.bind(this), false); // when the search field is manually selected |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 99 |
101 this._replaceCheckboxElement = this._replaceElement.createChild("input"); | 100 this._replaceCheckboxElement = this._replaceElement.createChild("input"); |
102 this._replaceCheckboxElement.type = "checkbox"; | 101 this._replaceCheckboxElement.type = "checkbox"; |
103 this._replaceCheckboxElement.id = "search-replace-trigger"; | 102 this._replaceCheckboxElement.id = "search-replace-trigger"; |
104 this._replaceCheckboxElement.addEventListener("click", this._updateSecondRow
Visibility.bind(this), false); | 103 this._replaceCheckboxElement.addEventListener("click", this._updateSecondRow
Visibility.bind(this), false); |
105 | 104 |
106 this._replaceLabelElement = this._replaceElement.createChild("label"); | 105 this._replaceLabelElement = this._replaceElement.createChild("label"); |
107 this._replaceLabelElement.textContent = WebInspector.UIString("Replace"); | 106 this._replaceLabelElement.textContent = WebInspector.UIString("Replace"); |
108 this._replaceLabelElement.setAttribute("for", "search-replace-trigger"); | 107 this._replaceLabelElement.setAttribute("for", "search-replace-trigger"); |
109 | 108 |
110 // Column 5 | |
111 this._filterCheckboxContainer = this._firstRowElement.createChild("td").crea
teChild("label"); | |
112 this._filterCheckboxContainer.setAttribute("for", "filter-trigger"); | |
113 | |
114 this._filterCheckboxElement = this._filterCheckboxContainer.createChild("inp
ut"); | |
115 this._filterCheckboxElement.type = "checkbox"; | |
116 this._filterCheckboxElement.id = "filter-trigger"; | |
117 this._filterCheckboxElement.addEventListener("click", this._filterCheckboxCl
ick.bind(this), false); | |
118 | |
119 this._filterCheckboxContainer.createTextChild(WebInspector.UIString("Filter"
)); | |
120 | |
121 // Column 6 | 109 // Column 6 |
122 var cancelButtonElement = this._firstRowElement.createChild("td").createChil
d("button"); | 110 var cancelButtonElement = this._firstRowElement.createChild("td").createChil
d("button"); |
123 cancelButtonElement.textContent = WebInspector.UIString("Cancel"); | 111 cancelButtonElement.textContent = WebInspector.UIString("Cancel"); |
124 cancelButtonElement.tabIndex = -1; | 112 cancelButtonElement.tabIndex = -1; |
125 cancelButtonElement.addEventListener("click", this.closeSearch.bind(this), f
alse); | 113 cancelButtonElement.addEventListener("click", this.closeSearch.bind(this), f
alse); |
126 } | 114 } |
127 | 115 |
128 WebInspector.SearchController.prototype = { | 116 WebInspector.SearchController.prototype = { |
129 /** | 117 /** |
130 * @param {number} matches | 118 * @param {number} matches |
(...skipping 25 matching lines...) Expand all Loading... |
156 closeSearch: function() | 144 closeSearch: function() |
157 { | 145 { |
158 this.cancelSearch(); | 146 this.cancelSearch(); |
159 WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement())
; | 147 WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement())
; |
160 }, | 148 }, |
161 | 149 |
162 cancelSearch: function() | 150 cancelSearch: function() |
163 { | 151 { |
164 if (!this._searchIsVisible) | 152 if (!this._searchIsVisible) |
165 return; | 153 return; |
166 if (this._filterCheckboxElement.checked) { | 154 this.resetSearch(); |
167 this._filterCheckboxElement.checked = false; | |
168 this._toggleFilterUI(false); | |
169 this.resetFilter(); | |
170 } else | |
171 this.resetSearch(); | |
172 delete this._searchIsVisible; | 155 delete this._searchIsVisible; |
173 this._searchHost.setFooterElement(null); | 156 this._searchHost.setFooterElement(null); |
174 this.resetSearch(); | 157 this.resetSearch(); |
175 delete this._searchHost; | 158 delete this._searchHost; |
176 delete this._searchProvider; | 159 delete this._searchProvider; |
177 }, | 160 }, |
178 | 161 |
179 resetSearch: function() | 162 resetSearch: function() |
180 { | 163 { |
181 this._suggestBox.hide(); | 164 this._suggestBox.hide(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 // FIXME: fix this mess. | 252 // FIXME: fix this mess. |
270 if (WebInspector.inspectorView.drawer().element.isAncestor(document.acti
veElement) && WebInspector.inspectorView.drawer().getSearchProvider()) | 253 if (WebInspector.inspectorView.drawer().element.isAncestor(document.acti
veElement) && WebInspector.inspectorView.drawer().getSearchProvider()) |
271 this._searchHost = WebInspector.inspectorView.drawer(); | 254 this._searchHost = WebInspector.inspectorView.drawer(); |
272 else | 255 else |
273 this._searchHost = WebInspector.inspectorView; | 256 this._searchHost = WebInspector.inspectorView; |
274 | 257 |
275 this._searchProvider = this._searchHost.getSearchProvider(); | 258 this._searchProvider = this._searchHost.getSearchProvider(); |
276 this._searchHost.setFooterElement(this._element); | 259 this._searchHost.setFooterElement(this._element); |
277 | 260 |
278 this._updateReplaceVisibility(); | 261 this._updateReplaceVisibility(); |
279 this._updateFilterVisibility(); | |
280 if (WebInspector.currentFocusElement() !== this._searchInputElement) { | 262 if (WebInspector.currentFocusElement() !== this._searchInputElement) { |
281 var selection = window.getSelection(); | 263 var selection = window.getSelection(); |
282 if (selection.rangeCount) { | 264 if (selection.rangeCount) { |
283 var queryCandidate = selection.toString().replace(/\r?\n.*/, "")
; | 265 var queryCandidate = selection.toString().replace(/\r?\n.*/, "")
; |
284 if (queryCandidate) | 266 if (queryCandidate) |
285 this._searchInputElement.value = queryCandidate; | 267 this._searchInputElement.value = queryCandidate; |
286 } | 268 } |
287 } | 269 } |
288 this._performSearch(false, false); | 270 this._performSearch(false, false); |
289 this._searchInputElement.focus(); | 271 this._searchInputElement.focus(); |
290 this._searchInputElement.select(); | 272 this._searchInputElement.select(); |
291 this._searchIsVisible = true; | 273 this._searchIsVisible = true; |
292 }, | 274 }, |
293 | 275 |
294 /** | |
295 * @param {boolean} filter | |
296 */ | |
297 _toggleFilterUI: function(filter) | |
298 { | |
299 this._matchesElement.enableStyleClass("hidden", filter); | |
300 this._searchNavigationElement.enableStyleClass("hidden", filter); | |
301 this._searchInputElement.placeholder = filter ? WebInspector.UIString("F
ilter") : WebInspector.UIString("Find"); | |
302 }, | |
303 | |
304 _updateFilterVisibility: function() | |
305 { | |
306 if (this._searchProvider.canFilter()) | |
307 this._filterCheckboxContainer.removeStyleClass("hidden"); | |
308 else | |
309 this._filterCheckboxContainer.addStyleClass("hidden"); | |
310 }, | |
311 | |
312 _updateReplaceVisibility: function() | 276 _updateReplaceVisibility: function() |
313 { | 277 { |
314 if (!this._searchProvider) | 278 if (!this._searchProvider) |
315 return; | 279 return; |
316 | 280 |
317 if (this._searchProvider.canSearchAndReplace()) | 281 if (this._searchProvider.canSearchAndReplace()) |
318 this._replaceElement.removeStyleClass("hidden"); | 282 this._replaceElement.removeStyleClass("hidden"); |
319 else { | 283 else { |
320 this._replaceElement.addStyleClass("hidden"); | 284 this._replaceElement.addStyleClass("hidden"); |
321 this._replaceCheckboxElement.checked = false; | 285 this._replaceCheckboxElement.checked = false; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 this._searchProvider.replaceSelectionWith(this._replaceInputElement.valu
e); | 413 this._searchProvider.replaceSelectionWith(this._replaceInputElement.valu
e); |
450 delete this._currentQuery; | 414 delete this._currentQuery; |
451 this._performSearch(true, true); | 415 this._performSearch(true, true); |
452 }, | 416 }, |
453 | 417 |
454 _replaceAll: function() | 418 _replaceAll: function() |
455 { | 419 { |
456 this._searchProvider.replaceAllWith(this._searchInputElement.value, this
._replaceInputElement.value); | 420 this._searchProvider.replaceAllWith(this._searchInputElement.value, this
._replaceInputElement.value); |
457 }, | 421 }, |
458 | 422 |
459 _filterCheckboxClick: function() | |
460 { | |
461 this._searchInputElement.focus(); | |
462 this._searchInputElement.select(); | |
463 | |
464 if (this._filterCheckboxElement.checked) { | |
465 this._toggleFilterUI(true); | |
466 this.resetSearch(); | |
467 this._performFilter(this._searchInputElement.value); | |
468 } else { | |
469 this._toggleFilterUI(false); | |
470 this.resetFilter(); | |
471 this._performSearch(false, false); | |
472 } | |
473 }, | |
474 | |
475 /** | |
476 * @param {string} query | |
477 */ | |
478 _performFilter: function(query) | |
479 { | |
480 this._searchProvider.performFilter(query); | |
481 }, | |
482 | 423 |
483 _onInput: function(event) | 424 _onInput: function(event) |
484 { | 425 { |
485 this._onValueChanged(); | 426 this._onValueChanged(); |
486 }, | 427 }, |
487 | 428 |
488 _onValueChanged: function() | 429 _onValueChanged: function() |
489 { | 430 { |
490 var suggestions = this._searchProvider.buildSuggestions(this._searchInpu
tElement); | 431 var suggestions = this._searchProvider.buildSuggestions(this._searchInpu
tElement); |
491 if (suggestions && suggestions.length) | 432 if (suggestions && suggestions.length) |
492 this._suggestBox.updateSuggestions(null, suggestions, 0, true, ""); | 433 this._suggestBox.updateSuggestions(null, suggestions, 0, true, ""); |
493 else | 434 else |
494 this._suggestBox.hide(); | 435 this._suggestBox.hide(); |
495 | 436 this._performSearch(false, true); |
496 if (this._filterCheckboxElement.checked) | |
497 this._performFilter(this._searchInputElement.value); | |
498 else | |
499 this._performSearch(false, true); | |
500 }, | 437 }, |
501 | 438 |
502 /** | 439 /** |
503 * @override | 440 * @override |
504 * @param {string} suggestion | 441 * @param {string} suggestion |
505 * @param {boolean=} isIntermediateSuggestion | 442 * @param {boolean=} isIntermediateSuggestion |
506 */ | 443 */ |
507 applySuggestion: function(suggestion, isIntermediateSuggestion) | 444 applySuggestion: function(suggestion, isIntermediateSuggestion) |
508 { | 445 { |
509 if (isIntermediateSuggestion) | 446 if (isIntermediateSuggestion) |
510 return; | 447 return; |
511 | 448 |
512 var text = this._searchInputElement.value; | 449 var text = this._searchInputElement.value; |
513 text = text.substring(0, text.lastIndexOf(" ") + 1) + suggestion; | 450 text = text.substring(0, text.lastIndexOf(" ") + 1) + suggestion; |
514 this._searchInputElement.value = text; | 451 this._searchInputElement.value = text; |
515 }, | 452 }, |
516 | 453 |
517 /** @override */ | 454 /** @override */ |
518 acceptSuggestion: function() | 455 acceptSuggestion: function() |
519 { | 456 { |
520 this._searchInputElement.scrollLeft = this._searchInputElement.scrollWid
th; | 457 this._searchInputElement.scrollLeft = this._searchInputElement.scrollWid
th; |
521 this._onValueChanged(); | 458 this._onValueChanged(); |
522 }, | |
523 | |
524 resetFilter: function() | |
525 { | |
526 this._performFilter(""); | |
527 } | 459 } |
528 } | 460 } |
529 | 461 |
530 /** | 462 /** |
531 * @type {?WebInspector.SearchController} | 463 * @type {?WebInspector.SearchController} |
532 */ | 464 */ |
533 WebInspector.searchController = null; | 465 WebInspector.searchController = null; |
534 | 466 |
535 /** | 467 /** |
536 * @interface | 468 * @interface |
537 */ | 469 */ |
538 WebInspector.Searchable = function() | 470 WebInspector.Searchable = function() |
539 { | 471 { |
540 } | 472 } |
541 | 473 |
542 WebInspector.Searchable.prototype = { | 474 WebInspector.Searchable.prototype = { |
543 /** | 475 /** |
544 * @return {boolean} | 476 * @return {boolean} |
545 */ | 477 */ |
546 canSearchAndReplace: function() { }, | 478 canSearchAndReplace: function() { }, |
547 | 479 |
548 /** | |
549 * @return {boolean} | |
550 */ | |
551 canFilter: function() { }, | |
552 | |
553 searchCanceled: function() { }, | 480 searchCanceled: function() { }, |
554 | 481 |
555 /** | 482 /** |
556 * @param {string} query | 483 * @param {string} query |
557 * @param {boolean} shouldJump | 484 * @param {boolean} shouldJump |
558 * @param {WebInspector.Searchable=} self | 485 * @param {WebInspector.Searchable=} self |
559 */ | 486 */ |
560 performSearch: function(query, shouldJump, self) { }, | 487 performSearch: function(query, shouldJump, self) { }, |
561 | 488 |
562 /** | 489 /** |
(...skipping 10 matching lines...) Expand all Loading... |
573 * @param {WebInspector.Searchable=} self | 500 * @param {WebInspector.Searchable=} self |
574 */ | 501 */ |
575 jumpToPreviousSearchResult: function(self) { }, | 502 jumpToPreviousSearchResult: function(self) { }, |
576 | 503 |
577 /** | 504 /** |
578 * @param {HTMLInputElement} input | 505 * @param {HTMLInputElement} input |
579 * @return {?Array.<string>} | 506 * @return {?Array.<string>} |
580 */ | 507 */ |
581 buildSuggestions: function(input) { } | 508 buildSuggestions: function(input) { } |
582 } | 509 } |
OLD | NEW |