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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. | 467 this._hideSearchHighlights(); |
| 468 this.searchCanceled(); | |
| 469 | 468 |
| 470 const whitespaceTrimmedQuery = query.trim(); | 469 const whitespaceTrimmedQuery = query.trim(); |
| 471 if (!whitespaceTrimmedQuery.length) | 470 if (!whitespaceTrimmedQuery.length) |
| 472 return; | 471 return; |
| 473 | 472 |
| 474 this._searchQuery = query; | 473 this._searchQuery = query; |
| 475 | 474 |
| 476 var promises = []; | 475 var promises = []; |
| 477 var domModels = SDK.DOMModel.instances(); | 476 var domModels = SDK.DOMModel.instances(); |
| 478 for (var domModel of domModels) { | 477 for (var domModel of domModels) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 491 */ | 490 */ |
| 492 this._searchResults = []; | 491 this._searchResults = []; |
| 493 for (var i = 0; i < resultCounts.length; ++i) { | 492 for (var i = 0; i < resultCounts.length; ++i) { |
| 494 var resultCount = resultCounts[i]; | 493 var resultCount = resultCounts[i]; |
| 495 for (var j = 0; j < resultCount; ++j) | 494 for (var j = 0; j < resultCount; ++j) |
| 496 this._searchResults.push({domModel: domModels[i], index: j, node: unde fined}); | 495 this._searchResults.push({domModel: domModels[i], index: j, node: unde fined}); |
| 497 } | 496 } |
| 498 this._searchableView.updateSearchMatchesCount(this._searchResults.length); | 497 this._searchableView.updateSearchMatchesCount(this._searchResults.length); |
| 499 if (!this._searchResults.length) | 498 if (!this._searchResults.length) |
| 500 return; | 499 return; |
| 501 this._currentSearchResultIndex = -1; | 500 if (this._currentSearchResultIndex === undefined) |
| 501 this._currentSearchResultIndex = -1; | |
| 502 | 502 |
| 503 if (shouldJump) | 503 var index = this._currentSearchResultIndex; |
| 504 this._jumpToSearchResult(jumpBackwards ? -1 : 0); | 504 |
| 505 if (shouldJump) { | |
| 506 if (index === -1) | |
| 507 index = jumpBackwards ? -1 : 0; | |
| 508 else | |
| 509 index = jumpBackwards ? index - 1 : index + 1; | |
| 510 this._jumpToSearchResult(index); | |
| 511 } | |
| 505 } | 512 } |
| 506 } | 513 } |
| 507 | 514 |
| 508 _domWordWrapSettingChanged(event) { | 515 _domWordWrapSettingChanged(event) { |
| 509 // FIXME: crbug.com/425984 | 516 // FIXME: crbug.com/425984 |
| 510 this._contentElement.classList.toggle('elements-wrap', event.data); | 517 this._contentElement.classList.toggle('elements-wrap', event.data); |
| 511 for (var i = 0; i < this._treeOutlines.length; ++i) | 518 for (var i = 0; i < this._treeOutlines.length; ++i) |
| 512 this._treeOutlines[i].setWordWrap(/** @type {boolean} */ (event.data)); | 519 this._treeOutlines[i].setWordWrap(/** @type {boolean} */ (event.data)); |
| 513 } | 520 } |
| 514 | 521 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 function showPopover(contents) { | 554 function showPopover(contents) { |
| 548 if (!contents) | 555 if (!contents) |
| 549 return; | 556 return; |
| 550 popover.setCanShrink(false); | 557 popover.setCanShrink(false); |
| 551 popover.showForAnchor(contents, link); | 558 popover.showForAnchor(contents, link); |
| 552 } | 559 } |
| 553 } | 560 } |
| 554 | 561 |
| 555 _jumpToSearchResult(index) { | 562 _jumpToSearchResult(index) { |
| 556 this._hideSearchHighlights(); | 563 this._hideSearchHighlights(); |
| 557 this._currentSearchResultIndex = (index + this._searchResults.length) % this ._searchResults.length; | 564 if (index > this._searchResults.length) |
|
pfeldman
2017/02/07 23:19:36
This should never happen. Whenever we update searc
| |
| 565 this._currentSearchResultIndex = 0; | |
| 566 else | |
| 567 this._currentSearchResultIndex = (index + this._searchResults.length) % th is._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._jumpToSearchResult(this._currentSearchResultIndex + 1); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 if (treeElement) { | 633 if (treeElement) { |
| 624 treeElement.highlightSearchResults(this._searchQuery); | 634 treeElement.highlightSearchResults(this._searchQuery); |
| 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 || |
| 644 this._currentSearchResultIndex > this._searchResults.length - 1) | |
|
pfeldman
2017/02/07 23:19:36
ditto
| |
| 634 return; | 645 return; |
| 635 var searchResult = this._searchResults[this._currentSearchResultIndex]; | 646 var searchResult = this._searchResults[this._currentSearchResultIndex]; |
| 636 if (!searchResult.node) | 647 if (!searchResult.node) |
| 637 return; | 648 return; |
| 638 var treeOutline = Elements.ElementsTreeOutline.forDOMModel(searchResult.node .domModel()); | 649 var treeOutline = Elements.ElementsTreeOutline.forDOMModel(searchResult.node .domModel()); |
| 639 var treeElement = treeOutline.findTreeElement(searchResult.node); | 650 var treeElement = treeOutline.findTreeElement(searchResult.node); |
| 640 if (treeElement) | 651 if (treeElement) |
| 641 treeElement.hideSearchHighlights(); | 652 treeElement.hideSearchHighlights(); |
| 642 } | 653 } |
| 643 | 654 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 * @param {!SDK.DOMNode} node | 1070 * @param {!SDK.DOMNode} node |
| 1060 * @return {?{title: string, color: string}} | 1071 * @return {?{title: string, color: string}} |
| 1061 */ | 1072 */ |
| 1062 decorate(node) { | 1073 decorate(node) { |
| 1063 return { | 1074 return { |
| 1064 color: 'orange', | 1075 color: 'orange', |
| 1065 title: Common.UIString('Element state: %s', ':' + SDK.CSSModel.fromNode(no de).pseudoState(node).join(', :')) | 1076 title: Common.UIString('Element state: %s', ':' + SDK.CSSModel.fromNode(no de).pseudoState(node).join(', :')) |
| 1066 }; | 1077 }; |
| 1067 } | 1078 } |
| 1068 }; | 1079 }; |
| OLD | NEW |