Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 return; | 438 return; |
| 439 this.selectDOMNode(node); | 439 this.selectDOMNode(node); |
| 440 if (treeOutline.selectedTreeElement) | 440 if (treeOutline.selectedTreeElement) |
| 441 treeOutline.selectedTreeElement.expand(); | 441 treeOutline.selectedTreeElement.expand(); |
| 442 } | 442 } |
| 443 | 443 |
| 444 /** | 444 /** |
| 445 * @override | 445 * @override |
| 446 */ | 446 */ |
| 447 searchCanceled() { | 447 searchCanceled() { |
| 448 delete this._searchQuery; | 448 delete this._searchConfig; |
| 449 this._hideSearchHighlights(); | 449 this._hideSearchHighlights(); |
| 450 | 450 |
| 451 this._searchableView.updateSearchMatchesCount(0); | 451 this._searchableView.updateSearchMatchesCount(0); |
| 452 | 452 |
| 453 delete this._currentSearchResultIndex; | 453 delete this._currentSearchResultIndex; |
| 454 delete this._searchResults; | 454 delete this._searchResults; |
| 455 | 455 |
| 456 SDK.DOMModel.cancelSearch(); | 456 SDK.DOMModel.cancelSearch(); |
| 457 } | 457 } |
| 458 | 458 |
| 459 /** | 459 /** |
| 460 * @override | 460 * @override |
| 461 * @param {!UI.SearchableView.SearchConfig} searchConfig | 461 * @param {!UI.SearchableView.SearchConfig} searchConfig |
| 462 * @param {boolean} shouldJump | 462 * @param {boolean} shouldJump |
| 463 * @param {boolean=} jumpBackwards | 463 * @param {boolean=} jumpBackwards |
| 464 */ | 464 */ |
| 465 performSearch(searchConfig, shouldJump, jumpBackwards) { | 465 performSearch(searchConfig, shouldJump, jumpBackwards) { |
| 466 var query = searchConfig.query; | 466 var query = searchConfig.query; |
| 467 // Call searchCanceled since it will reset everything we need before doing a new search. | |
| 468 this.searchCanceled(); | |
| 469 | 467 |
| 470 const whitespaceTrimmedQuery = query.trim(); | 468 const whitespaceTrimmedQuery = query.trim(); |
| 471 if (!whitespaceTrimmedQuery.length) | 469 if (!whitespaceTrimmedQuery.length) |
| 472 return; | 470 return; |
| 473 | 471 |
| 474 this._searchQuery = query; | 472 if (!this._searchConfig || this._searchConfig.query !== query) |
| 473 this.searchCanceled(); | |
| 474 else | |
| 475 this._hideSearchHighlights(); | |
| 476 | |
| 477 this._searchConfig = searchConfig; | |
| 475 | 478 |
| 476 var promises = []; | 479 var promises = []; |
| 477 var domModels = SDK.DOMModel.instances(); | 480 var domModels = SDK.DOMModel.instances(); |
| 478 for (var domModel of domModels) { | 481 for (var domModel of domModels) { |
| 479 promises.push( | 482 promises.push( |
| 480 domModel.performSearchPromise(whitespaceTrimmedQuery, Common.moduleSet ting('showUAShadowDOM').get())); | 483 domModel.performSearchPromise(whitespaceTrimmedQuery, Common.moduleSet ting('showUAShadowDOM').get())); |
| 481 } | 484 } |
| 482 Promise.all(promises).then(resultCountCallback.bind(this)); | 485 Promise.all(promises).then(resultCountCallback.bind(this)); |
| 483 | 486 |
| 484 /** | 487 /** |
| 485 * @param {!Array.<number>} resultCounts | 488 * @param {!Array.<number>} resultCounts |
| 486 * @this {Elements.ElementsPanel} | 489 * @this {Elements.ElementsPanel} |
| 487 */ | 490 */ |
| 488 function resultCountCallback(resultCounts) { | 491 function resultCountCallback(resultCounts) { |
| 489 /** | 492 /** |
| 490 * @type {!Array.<{domModel: !SDK.DOMModel, index: number, node: (?SDK.DOM Node|undefined)}>} | 493 * @type {!Array.<{domModel: !SDK.DOMModel, index: number, node: (?SDK.DOM Node|undefined)}>} |
| 491 */ | 494 */ |
| 492 this._searchResults = []; | 495 this._searchResults = []; |
| 493 for (var i = 0; i < resultCounts.length; ++i) { | 496 for (var i = 0; i < resultCounts.length; ++i) { |
| 494 var resultCount = resultCounts[i]; | 497 var resultCount = resultCounts[i]; |
| 495 for (var j = 0; j < resultCount; ++j) | 498 for (var j = 0; j < resultCount; ++j) |
| 496 this._searchResults.push({domModel: domModels[i], index: j, node: unde fined}); | 499 this._searchResults.push({domModel: domModels[i], index: j, node: unde fined}); |
| 497 } | 500 } |
| 498 this._searchableView.updateSearchMatchesCount(this._searchResults.length); | 501 this._searchableView.updateSearchMatchesCount(this._searchResults.length); |
| 499 if (!this._searchResults.length) | 502 if (!this._searchResults.length) |
| 500 return; | 503 return; |
| 501 this._currentSearchResultIndex = -1; | 504 if (this._currentSearchResultIndex === undefined || this._currentSearchRes ultIndex >= this._searchResults.length) |
| 505 this._currentSearchResultIndex = -1; | |
| 502 | 506 |
| 503 if (shouldJump) | 507 var index = this._currentSearchResultIndex; |
| 504 this._jumpToSearchResult(jumpBackwards ? -1 : 0); | 508 |
| 509 if (shouldJump) { | |
| 510 if (index === -1) | |
|
pfeldman
2017/02/13 18:16:24
Let's replace this with this._currentSearchResultI
| |
| 511 index = jumpBackwards ? -1 : 0; | |
| 512 else | |
| 513 index = jumpBackwards ? index - 1 : index + 1; | |
| 514 this._jumpToSearchResult(index); | |
| 515 } | |
| 505 } | 516 } |
| 506 } | 517 } |
| 507 | 518 |
| 508 _domWordWrapSettingChanged(event) { | 519 _domWordWrapSettingChanged(event) { |
| 509 // FIXME: crbug.com/425984 | 520 // FIXME: crbug.com/425984 |
| 510 this._contentElement.classList.toggle('elements-wrap', event.data); | 521 this._contentElement.classList.toggle('elements-wrap', event.data); |
| 511 for (var i = 0; i < this._treeOutlines.length; ++i) | 522 for (var i = 0; i < this._treeOutlines.length; ++i) |
| 512 this._treeOutlines[i].setWordWrap(/** @type {boolean} */ (event.data)); | 523 this._treeOutlines[i].setWordWrap(/** @type {boolean} */ (event.data)); |
| 513 } | 524 } |
| 514 | 525 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 */ | 557 */ |
| 547 function showPopover(contents) { | 558 function showPopover(contents) { |
| 548 if (!contents) | 559 if (!contents) |
| 549 return; | 560 return; |
| 550 popover.setCanShrink(false); | 561 popover.setCanShrink(false); |
| 551 popover.showForAnchor(contents, link); | 562 popover.showForAnchor(contents, link); |
| 552 } | 563 } |
| 553 } | 564 } |
| 554 | 565 |
| 555 _jumpToSearchResult(index) { | 566 _jumpToSearchResult(index) { |
| 556 this._hideSearchHighlights(); | |
| 557 this._currentSearchResultIndex = (index + this._searchResults.length) % this ._searchResults.length; | 567 this._currentSearchResultIndex = (index + this._searchResults.length) % this ._searchResults.length; |
| 558 this._highlightCurrentSearchResult(); | 568 this._highlightCurrentSearchResult(); |
| 559 } | 569 } |
| 560 | 570 |
| 561 /** | 571 /** |
| 562 * @override | 572 * @override |
| 563 */ | 573 */ |
| 564 jumpToNextSearchResult() { | 574 jumpToNextSearchResult() { |
| 565 if (!this._searchResults) | 575 if (!this._searchResults) |
| 566 return; | 576 return; |
| 567 this._jumpToSearchResult(this._currentSearchResultIndex + 1); | 577 this.performSearch(this._searchConfig, true); |
| 568 } | 578 } |
| 569 | 579 |
| 570 /** | 580 /** |
| 571 * @override | 581 * @override |
| 572 */ | 582 */ |
| 573 jumpToPreviousSearchResult() { | 583 jumpToPreviousSearchResult() { |
| 574 if (!this._searchResults) | 584 if (!this._searchResults) |
| 575 return; | 585 return; |
| 576 this._jumpToSearchResult(this._currentSearchResultIndex - 1); | 586 this.performSearch(this._searchConfig, true, true); |
| 577 } | 587 } |
| 578 | 588 |
| 579 /** | 589 /** |
| 580 * @override | 590 * @override |
| 581 * @return {boolean} | 591 * @return {boolean} |
| 582 */ | 592 */ |
| 583 supportsCaseSensitiveSearch() { | 593 supportsCaseSensitiveSearch() { |
| 584 return false; | 594 return false; |
| 585 } | 595 } |
| 586 | 596 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 614 if (typeof searchResult.node === 'undefined') { | 624 if (typeof searchResult.node === 'undefined') { |
| 615 // No data for slot, request it. | 625 // No data for slot, request it. |
| 616 searchResult.domModel.searchResult(searchResult.index, searchCallback.bind (this)); | 626 searchResult.domModel.searchResult(searchResult.index, searchCallback.bind (this)); |
| 617 return; | 627 return; |
| 618 } | 628 } |
| 619 | 629 |
| 620 this._searchableView.updateCurrentMatchIndex(index); | 630 this._searchableView.updateCurrentMatchIndex(index); |
| 621 | 631 |
| 622 var treeElement = this._treeElementForNode(searchResult.node); | 632 var treeElement = this._treeElementForNode(searchResult.node); |
| 623 if (treeElement) { | 633 if (treeElement) { |
| 624 treeElement.highlightSearchResults(this._searchQuery); | 634 treeElement.highlightSearchResults(this._searchConfig.query); |
| 625 treeElement.reveal(); | 635 treeElement.reveal(); |
| 626 var matches = treeElement.listItemElement.getElementsByClassName(UI.highli ghtedSearchResultClassName); | 636 var matches = treeElement.listItemElement.getElementsByClassName(UI.highli ghtedSearchResultClassName); |
| 627 if (matches.length) | 637 if (matches.length) |
| 628 matches[0].scrollIntoViewIfNeeded(false); | 638 matches[0].scrollIntoViewIfNeeded(false); |
| 629 } | 639 } |
| 630 } | 640 } |
| 631 | 641 |
| 632 _hideSearchHighlights() { | 642 _hideSearchHighlights() { |
| 633 if (!this._searchResults || !this._searchResults.length || this._currentSear chResultIndex < 0) | 643 if (!this._searchResults || !this._searchResults.length || this._currentSear chResultIndex < 0) |
| 634 return; | 644 return; |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 * @param {!SDK.DOMNode} node | 1069 * @param {!SDK.DOMNode} node |
| 1060 * @return {?{title: string, color: string}} | 1070 * @return {?{title: string, color: string}} |
| 1061 */ | 1071 */ |
| 1062 decorate(node) { | 1072 decorate(node) { |
| 1063 return { | 1073 return { |
| 1064 color: 'orange', | 1074 color: 'orange', |
| 1065 title: Common.UIString('Element state: %s', ':' + SDK.CSSModel.fromNode(no de).pseudoState(node).join(', :')) | 1075 title: Common.UIString('Element state: %s', ':' + SDK.CSSModel.fromNode(no de).pseudoState(node).join(', :')) |
| 1066 }; | 1076 }; |
| 1067 } | 1077 } |
| 1068 }; | 1078 }; |
| OLD | NEW |