Changeset 96580 in webkit


Ignore:
Timestamp:
Oct 4, 2011 3:05:46 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: move abstract panel search logic into the only view that is using it.
https://bugs.webkit.org/show_bug.cgi?id=69328

Reviewed by Yury Semikhatsky.

  • inspector/front-end/Panel.js:

(WebInspector.Panel.prototype.searchCanceled):
(WebInspector.Panel.prototype.performSearch):
(WebInspector.Panel.prototype.jumpToNextSearchResult):
(WebInspector.Panel.prototype.jumpToPreviousSearchResult):

  • inspector/front-end/ProfilesPanel.js:

(WebInspector.ProfilesPanel.prototype.performSearch.updateMatchesCount):
(WebInspector.ProfilesPanel.prototype.performSearch.updateMatchesCountSoon):
(WebInspector.ProfilesPanel.prototype.performSearch.finishedCallback):
(WebInspector.ProfilesPanel.prototype.performSearch.processChunk):
(WebInspector.ProfilesPanel.prototype.performSearch):
(WebInspector.ProfilesPanel.prototype.jumpToNextSearchResult):
(WebInspector.ProfilesPanel.prototype.jumpToPreviousSearchResult):
(WebInspector.ProfilesPanel.prototype._searchableViews):
(WebInspector.ProfilesPanel.prototype.searchCanceled):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r96579 r96580  
     12011-10-04  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: move abstract panel search logic into the only view that is using it.
     4        https://bugs.webkit.org/show_bug.cgi?id=69328
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * inspector/front-end/Panel.js:
     9        (WebInspector.Panel.prototype.searchCanceled):
     10        (WebInspector.Panel.prototype.performSearch):
     11        (WebInspector.Panel.prototype.jumpToNextSearchResult):
     12        (WebInspector.Panel.prototype.jumpToPreviousSearchResult):
     13        * inspector/front-end/ProfilesPanel.js:
     14        (WebInspector.ProfilesPanel.prototype.performSearch.updateMatchesCount):
     15        (WebInspector.ProfilesPanel.prototype.performSearch.updateMatchesCountSoon):
     16        (WebInspector.ProfilesPanel.prototype.performSearch.finishedCallback):
     17        (WebInspector.ProfilesPanel.prototype.performSearch.processChunk):
     18        (WebInspector.ProfilesPanel.prototype.performSearch):
     19        (WebInspector.ProfilesPanel.prototype.jumpToNextSearchResult):
     20        (WebInspector.ProfilesPanel.prototype.jumpToPreviousSearchResult):
     21        (WebInspector.ProfilesPanel.prototype._searchableViews):
     22        (WebInspector.ProfilesPanel.prototype.searchCanceled):
     23
    1242011-10-04  Pavel Feldman  <pfeldman@google.com>
    225
  • trunk/Source/WebCore/inspector/front-end/Panel.js

    r96577 r96580  
    109109    searchCanceled: function()
    110110    {
    111         if (this._searchResults) {
    112             for (var i = 0; i < this._searchResults.length; ++i) {
    113                 var view = this._searchResults[i];
    114                 if (view.searchCanceled)
    115                     view.searchCanceled();
    116                 delete view.currentQuery;
    117             }
    118         }
    119 
    120111        WebInspector.searchController.updateSearchMatchesCount(0, this);
    121 
    122         if (this._currentSearchChunkIntervalIdentifier) {
    123             clearInterval(this._currentSearchChunkIntervalIdentifier);
    124             delete this._currentSearchChunkIntervalIdentifier;
    125         }
    126 
    127         this._totalSearchMatches = 0;
    128         this._currentSearchResultIndex = 0;
    129         this._searchResults = [];
    130112    },
    131113
     
    133115    {
    134116        // Call searchCanceled since it will reset everything we need before doing a new search.
    135         this.searchCanceled(true);
    136 
    137         var searchableViews = this.searchableViews;
    138         if (!searchableViews || !searchableViews.length)
    139             return;
    140 
    141         var parentElement = this.viewsContainerElement;
    142         var visibleView = this.visibleView;
    143         var sortFuction = this.searchResultsSortFunction;
    144 
    145         var matchesCountUpdateTimeout = null;
    146 
    147         function updateMatchesCount()
    148         {
    149             WebInspector.searchController.updateSearchMatchesCount(this._totalSearchMatches, this);
    150             matchesCountUpdateTimeout = null;
    151         }
    152 
    153         function updateMatchesCountSoon()
    154         {
    155             if (matchesCountUpdateTimeout)
    156                 return;
    157             // Update the matches count every half-second so it doesn't feel twitchy.
    158             matchesCountUpdateTimeout = setTimeout(updateMatchesCount.bind(this), 500);
    159         }
    160 
    161         function finishedCallback(view, searchMatches)
    162         {
    163             if (!searchMatches)
    164                 return;
    165 
    166             this._totalSearchMatches += searchMatches;
    167             this._searchResults.push(view);
    168 
    169             if (sortFuction)
    170                 this._searchResults.sort(sortFuction);
    171 
    172             if (this.searchMatchFound)
    173                 this.searchMatchFound(view, searchMatches);
    174 
    175             updateMatchesCountSoon.call(this);
    176 
    177             if (view === visibleView)
    178                 view.jumpToFirstSearchResult();
    179         }
    180 
    181         var i = 0;
    182         var panel = this;
    183         var boundFinishedCallback = finishedCallback.bind(this);
    184         var chunkIntervalIdentifier = null;
    185 
    186         // Split up the work into chunks so we don't block the
    187         // UI thread while processing.
    188 
    189         function processChunk()
    190         {
    191             var view = searchableViews[i];
    192 
    193             if (++i >= searchableViews.length) {
    194                 if (panel._currentSearchChunkIntervalIdentifier === chunkIntervalIdentifier)
    195                     delete panel._currentSearchChunkIntervalIdentifier;
    196                 clearInterval(chunkIntervalIdentifier);
    197             }
    198 
    199             if (!view)
    200                 return;
    201 
    202             view.currentQuery = query;
    203             view.performSearch(query, boundFinishedCallback);
    204         }
    205 
    206         processChunk();
    207 
    208         chunkIntervalIdentifier = setInterval(processChunk, 25);
    209         this._currentSearchChunkIntervalIdentifier = chunkIntervalIdentifier;
     117        this.searchCanceled();
    210118    },
    211119
    212120    jumpToNextSearchResult: function()
    213121    {
    214         if (!this.showView || !this._searchResults || !this._searchResults.length)
    215             return;
    216 
    217         var showFirstResult = false;
    218 
    219         this._currentSearchResultIndex = this._searchResults.indexOf(this.visibleView);
    220         if (this._currentSearchResultIndex === -1) {
    221             this._currentSearchResultIndex = 0;
    222             showFirstResult = true;
    223         }
    224 
    225         var currentView = this._searchResults[this._currentSearchResultIndex];
    226 
    227         if (currentView.showingLastSearchResult()) {
    228             if (++this._currentSearchResultIndex >= this._searchResults.length)
    229                 this._currentSearchResultIndex = 0;
    230             currentView = this._searchResults[this._currentSearchResultIndex];
    231             showFirstResult = true;
    232         }
    233 
    234         if (currentView !== this.visibleView) {
    235             this.showView(currentView);
    236             WebInspector.searchController.focusSearchField();
    237         }
    238 
    239         if (showFirstResult)
    240             currentView.jumpToFirstSearchResult();
    241         else
    242             currentView.jumpToNextSearchResult();
    243122    },
    244123
    245124    jumpToPreviousSearchResult: function()
    246125    {
    247         if (!this.showView || !this._searchResults || !this._searchResults.length)
    248             return;
    249 
    250         var showLastResult = false;
    251 
    252         this._currentSearchResultIndex = this._searchResults.indexOf(this.visibleView);
    253         if (this._currentSearchResultIndex === -1) {
    254             this._currentSearchResultIndex = 0;
    255             showLastResult = true;
    256         }
    257 
    258         var currentView = this._searchResults[this._currentSearchResultIndex];
    259 
    260         if (currentView.showingFirstSearchResult()) {
    261             if (--this._currentSearchResultIndex < 0)
    262                 this._currentSearchResultIndex = (this._searchResults.length - 1);
    263             currentView = this._searchResults[this._currentSearchResultIndex];
    264             showLastResult = true;
    265         }
    266 
    267         if (currentView !== this.visibleView) {
    268             this.showView(currentView);
    269             WebInspector.searchController.focusSearchField();
    270         }
    271 
    272         if (showLastResult)
    273             currentView.jumpToLastSearchResult();
    274         else
    275             currentView.jumpToPreviousSearchResult();
    276126    },
    277127
  • trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js

    r94754 r96580  
    539539    },
    540540
    541     get searchableViews()
     541    performSearch: function(query)
     542    {
     543        this.searchCanceled();
     544
     545        var searchableViews = this._searchableViews();
     546        if (!searchableViews || !searchableViews.length)
     547            return;
     548
     549        var parentElement = this.viewsContainerElement;
     550        var visibleView = this.visibleView;
     551        var sortFuction = this.searchResultsSortFunction;
     552
     553        var matchesCountUpdateTimeout = null;
     554
     555        function updateMatchesCount()
     556        {
     557            WebInspector.searchController.updateSearchMatchesCount(this._totalSearchMatches, this);
     558            matchesCountUpdateTimeout = null;
     559        }
     560
     561        function updateMatchesCountSoon()
     562        {
     563            if (matchesCountUpdateTimeout)
     564                return;
     565            // Update the matches count every half-second so it doesn't feel twitchy.
     566            matchesCountUpdateTimeout = setTimeout(updateMatchesCount.bind(this), 500);
     567        }
     568
     569        function finishedCallback(view, searchMatches)
     570        {
     571            if (!searchMatches)
     572                return;
     573
     574            this._totalSearchMatches += searchMatches;
     575            this._searchResults.push(view);
     576
     577            if (sortFuction)
     578                this._searchResults.sort(sortFuction);
     579
     580            if (this.searchMatchFound)
     581                this.searchMatchFound(view, searchMatches);
     582
     583            updateMatchesCountSoon.call(this);
     584
     585            if (view === visibleView)
     586                view.jumpToFirstSearchResult();
     587        }
     588
     589        var i = 0;
     590        var panel = this;
     591        var boundFinishedCallback = finishedCallback.bind(this);
     592        var chunkIntervalIdentifier = null;
     593
     594        // Split up the work into chunks so we don't block the
     595        // UI thread while processing.
     596
     597        function processChunk()
     598        {
     599            var view = searchableViews[i];
     600
     601            if (++i >= searchableViews.length) {
     602                if (panel._currentSearchChunkIntervalIdentifier === chunkIntervalIdentifier)
     603                    delete panel._currentSearchChunkIntervalIdentifier;
     604                clearInterval(chunkIntervalIdentifier);
     605            }
     606
     607            if (!view)
     608                return;
     609
     610            view.currentQuery = query;
     611            view.performSearch(query, boundFinishedCallback);
     612        }
     613
     614        processChunk();
     615
     616        chunkIntervalIdentifier = setInterval(processChunk, 25);
     617        this._currentSearchChunkIntervalIdentifier = chunkIntervalIdentifier;
     618    },
     619
     620    jumpToNextSearchResult: function()
     621    {
     622        if (!this.showView || !this._searchResults || !this._searchResults.length)
     623            return;
     624
     625        var showFirstResult = false;
     626
     627        this._currentSearchResultIndex = this._searchResults.indexOf(this.visibleView);
     628        if (this._currentSearchResultIndex === -1) {
     629            this._currentSearchResultIndex = 0;
     630            showFirstResult = true;
     631        }
     632
     633        var currentView = this._searchResults[this._currentSearchResultIndex];
     634
     635        if (currentView.showingLastSearchResult()) {
     636            if (++this._currentSearchResultIndex >= this._searchResults.length)
     637                this._currentSearchResultIndex = 0;
     638            currentView = this._searchResults[this._currentSearchResultIndex];
     639            showFirstResult = true;
     640        }
     641
     642        if (currentView !== this.visibleView) {
     643            this.showView(currentView);
     644            WebInspector.searchController.focusSearchField();
     645        }
     646
     647        if (showFirstResult)
     648            currentView.jumpToFirstSearchResult();
     649        else
     650            currentView.jumpToNextSearchResult();
     651    },
     652
     653    jumpToPreviousSearchResult: function()
     654    {
     655        if (!this.showView || !this._searchResults || !this._searchResults.length)
     656            return;
     657
     658        var showLastResult = false;
     659
     660        this._currentSearchResultIndex = this._searchResults.indexOf(this.visibleView);
     661        if (this._currentSearchResultIndex === -1) {
     662            this._currentSearchResultIndex = 0;
     663            showLastResult = true;
     664        }
     665
     666        var currentView = this._searchResults[this._currentSearchResultIndex];
     667
     668        if (currentView.showingFirstSearchResult()) {
     669            if (--this._currentSearchResultIndex < 0)
     670                this._currentSearchResultIndex = (this._searchResults.length - 1);
     671            currentView = this._searchResults[this._currentSearchResultIndex];
     672            showLastResult = true;
     673        }
     674
     675        if (currentView !== this.visibleView) {
     676            this.showView(currentView);
     677            WebInspector.searchController.focusSearchField();
     678        }
     679
     680        if (showLastResult)
     681            currentView.jumpToLastSearchResult();
     682        else
     683            currentView.jumpToPreviousSearchResult();
     684    },
     685
     686    _searchableViews: function()
    542687    {
    543688        var views = [];
     
    564709    },
    565710
    566     searchCanceled: function(startingNewSearch)
    567     {
    568         WebInspector.Panel.prototype.searchCanceled.call(this, startingNewSearch);
     711    searchCanceled: function()
     712    {
     713        if (this._searchResults) {
     714            for (var i = 0; i < this._searchResults.length; ++i) {
     715                var view = this._searchResults[i];
     716                if (view.searchCanceled)
     717                    view.searchCanceled();
     718                delete view.currentQuery;
     719            }
     720        }
     721
     722        WebInspector.Panel.prototype.searchCanceled.call(this);
     723
     724        if (this._currentSearchChunkIntervalIdentifier) {
     725            clearInterval(this._currentSearchChunkIntervalIdentifier);
     726            delete this._currentSearchChunkIntervalIdentifier;
     727        }
     728
     729        this._totalSearchMatches = 0;
     730        this._currentSearchResultIndex = 0;
     731        this._searchResults = [];
    569732
    570733        if (!this._profiles)
Note: See TracChangeset for help on using the changeset viewer.