Changeset 80102 in webkit


Ignore:
Timestamp:
Mar 2, 2011 1:40:17 AM (13 years ago)
Author:
caseq@chromium.org
Message:

2011-02-25 Andrey Kosyakov <caseq@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: factor search logic out of inspector.js
https://bugs.webkit.org/show_bug.cgi?id=54965

  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • inspector/front-end/ElementsPanel.js: (WebInspector.ElementsPanel.prototype.searchCanceled): (WebInspector.ElementsPanel.prototype.switchToAndFocus): (WebInspector.ElementsPanel.prototype._updateMatchesCount):
  • inspector/front-end/Panel.js: (WebInspector.Panel.prototype.searchCanceled): (WebInspector.Panel.prototype.performSearch.updateMatchesCount):
  • inspector/front-end/ScriptsPanel.js: (WebInspector.ScriptsPanel.prototype.searchCanceled): (WebInspector.ScriptsPanel.prototype.performSearch.finishedCallback): (WebInspector.ScriptsPanel.prototype.performSearch):
  • inspector/front-end/SearchController.js: Added. (WebInspector.SearchController): (WebInspector.SearchController.prototype.updateSearchMatchesCount): (WebInspector.SearchController.prototype.updateSearchLabel): (WebInspector.SearchController.prototype.cancelSearch): (WebInspector.SearchController.prototype.handleShortcut): (WebInspector.SearchController.prototype.activePanelChanged.performPanelSearch): (WebInspector.SearchController.prototype.activePanelChanged): (WebInspector.SearchController.prototype._updateSearchMatchesCount): (WebInspector.SearchController.prototype._focusSearchField): (WebInspector.SearchController.prototype._onSearchFieldManualFocus): (WebInspector.SearchController.prototype._onKeyDown): (WebInspector.SearchController.prototype._onSearch): (WebInspector.SearchController.prototype._performSearch):
  • inspector/front-end/WebKit.qrc:
  • inspector/front-end/inspector.html:
  • inspector/front-end/inspector.js: (WebInspector.set currentPanel): (WebInspector.set attached): (WebInspector.doLoadedDone): (WebInspector.documentKeyDown):
Location:
trunk/Source/WebCore
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r80099 r80102  
     12011-02-25  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: factor search logic out of inspector.js
     6        https://bugs.webkit.org/show_bug.cgi?id=54965
     7
     8        * WebCore.gypi:
     9        * WebCore.vcproj/WebCore.vcproj:
     10        * inspector/front-end/ElementsPanel.js:
     11        (WebInspector.ElementsPanel.prototype.searchCanceled):
     12        (WebInspector.ElementsPanel.prototype.switchToAndFocus):
     13        (WebInspector.ElementsPanel.prototype._updateMatchesCount):
     14        * inspector/front-end/Panel.js:
     15        (WebInspector.Panel.prototype.searchCanceled):
     16        (WebInspector.Panel.prototype.performSearch.updateMatchesCount):
     17        * inspector/front-end/ScriptsPanel.js:
     18        (WebInspector.ScriptsPanel.prototype.searchCanceled):
     19        (WebInspector.ScriptsPanel.prototype.performSearch.finishedCallback):
     20        (WebInspector.ScriptsPanel.prototype.performSearch):
     21        * inspector/front-end/SearchController.js: Added.
     22        (WebInspector.SearchController):
     23        (WebInspector.SearchController.prototype.updateSearchMatchesCount):
     24        (WebInspector.SearchController.prototype.updateSearchLabel):
     25        (WebInspector.SearchController.prototype.cancelSearch):
     26        (WebInspector.SearchController.prototype.handleShortcut):
     27        (WebInspector.SearchController.prototype.activePanelChanged.performPanelSearch):
     28        (WebInspector.SearchController.prototype.activePanelChanged):
     29        (WebInspector.SearchController.prototype._updateSearchMatchesCount):
     30        (WebInspector.SearchController.prototype._focusSearchField):
     31        (WebInspector.SearchController.prototype._onSearchFieldManualFocus):
     32        (WebInspector.SearchController.prototype._onKeyDown):
     33        (WebInspector.SearchController.prototype._onSearch):
     34        (WebInspector.SearchController.prototype._performSearch):
     35        * inspector/front-end/WebKit.qrc:
     36        * inspector/front-end/inspector.html:
     37        * inspector/front-end/inspector.js:
     38        (WebInspector.set currentPanel):
     39        (WebInspector.set attached):
     40        (WebInspector.doLoadedDone):
     41        (WebInspector.documentKeyDown):
     42
    1432011-03-02  Renata Hodovan  <reni@webkit.org>
    244
  • trunk/Source/WebCore/WebCore.gypi

    r80096 r80102  
    47974797            'inspector/front-end/ScriptFormatterWorker.js',
    47984798            'inspector/front-end/ScriptsPanel.js',
     4799            'inspector/front-end/SearchController.js',
    47994800            'inspector/front-end/ShortcutsHelp.js',
    48004801            'inspector/front-end/ShowMoreDataGridNode.js',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r80041 r80102  
    6600266002                                </File>
    6600366003                                <File
     66004                                        RelativePath="..\inspector\front-end\SearchController.js"
     66005                                        >
     66006                                </File>
     66007                                <File
    6600466008                                        RelativePath="..\inspector\front-end\Section.js"
    6600566009                                        >
  • trunk/Source/WebCore/inspector/front-end/ElementsPanel.js

    r80003 r80102  
    223223        this._hideSearchHighlights();
    224224
    225         WebInspector.updateSearchMatchesCount(0, this);
     225        WebInspector.searchController.updateSearchMatchesCount(0, this);
    226226
    227227        delete this._currentSearchResultIndex;
     
    265265    {
    266266        // Reset search restore.
    267         WebInspector.cancelSearch();
     267        WebInspector.searchController.cancelSearch();
    268268        WebInspector.currentPanel = this;
    269269        this.focusedDOMNode = node;
     
    272272    _updateMatchesCount: function()
    273273    {
    274         WebInspector.updateSearchMatchesCount(this._searchResults.length, this);
     274        WebInspector.searchController.updateSearchMatchesCount(this._searchResults.length, this);
    275275        this._matchesCountUpdateTimeout = null;
    276276        this._updatedMatchCountOnce = true;
  • trunk/Source/WebCore/inspector/front-end/Panel.js

    r79306 r80102  
    111111        }
    112112
    113         WebInspector.updateSearchMatchesCount(0, this);
     113        WebInspector.searchController.updateSearchMatchesCount(0, this);
    114114
    115115        if (this._currentSearchChunkIntervalIdentifier) {
     
    140140        function updateMatchesCount()
    141141        {
    142             WebInspector.updateSearchMatchesCount(this._totalSearchMatches, this);
     142            WebInspector.searchController.updateSearchMatchesCount(this._totalSearchMatches, this);
    143143            matchesCountUpdateTimeout = null;
    144144        }
  • trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js

    r79873 r80102  
    985985    searchCanceled: function()
    986986    {
    987         WebInspector.updateSearchMatchesCount(0, this);
    988 
    989987        if (this._searchView)
    990988            this._searchView.searchCanceled();
     
    996994    performSearch: function(query)
    997995    {
     996        WebInspector.searchController.updateSearchMatchesCount(0, this);
     997
    998998        if (!this.visibleView)
    999999            return;
     
    10101010                return;
    10111011
    1012             WebInspector.updateSearchMatchesCount(searchMatches, this);
     1012            WebInspector.searchController.updateSearchMatchesCount(searchMatches, this);
    10131013            view.jumpToFirstSearchResult();
    10141014        }
  • trunk/Source/WebCore/inspector/front-end/WebKit.qrc

    r79311 r80102  
    8888    <file>ScriptFormatterWorker.js</file>
    8989    <file>ScriptsPanel.js</file>
     90    <file>SearchController.js</file>
    9091    <file>Section.js</file>
    9192    <file>Settings.js</file>
  • trunk/Source/WebCore/inspector/front-end/inspector.html

    r79311 r80102  
    158158    <script type="text/javascript" src="CookieParser.js"></script>
    159159    <script type="text/javascript" src="Toolbar.js"></script>
     160    <script type="text/javascript" src="SearchController.js"></script>
    160161</head>
    161162<body class="detached">
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r79853 r80102  
    154154        this._currentPanel = x;
    155155
    156         this.updateSearchLabel();
    157 
    158156        if (x) {
    159157            x.show();
    160 
    161             if (this.currentQuery) {
    162                 if (x.performSearch) {
    163                     function performPanelSearch()
    164                     {
    165                         this.updateSearchMatchesCount();
    166 
    167                         x.currentQuery = this.currentQuery;
    168                         x.performSearch(this.currentQuery);
    169                     }
    170 
    171                     // Perform the search on a timeout so the panel switches fast.
    172                     setTimeout(performPanelSearch.bind(this), 0);
    173                 } else {
    174                     // Update to show Not found for panels that can't be searched.
    175                     this.updateSearchMatchesCount();
    176                 }
    177             }
    178         }
    179 
     158            WebInspector.searchController.activePanelChanged();
     159        }
    180160        for (var panelName in WebInspector.panels) {
    181161            if (WebInspector.panels[panelName] === x) {
     
    249229        this._attached = x;
    250230
    251         this.updateSearchLabel();
    252 
    253231        var dockToggleButton = document.getElementById("dock-status-bar-item");
    254232        var body = document.body;
     
    263241            dockToggleButton.title = WebInspector.UIString("Dock to main window.");
    264242        }
    265         if (this.drawer)
    266             this.drawer.resize();
    267         if (this.toolbar)
    268             this.toolbar.resize();
     243
     244        // This may be called before onLoadedDone, hence the bulk of inspector objects may
     245        // not be created yet.
     246        if (WebInspector.searchController)
     247            WebInspector.searchController.updateSearchLabel();
    269248    },
    270249
     
    495474
    496475    this.breakpointManager = new WebInspector.BreakpointManager();
     476    this.searchController = new WebInspector.SearchController();
    497477
    498478    this.panels = {};
     
    534514    errorWarningCount.addEventListener("click", this.showConsole.bind(this), false);
    535515    this._updateErrorAndWarningCounts();
    536 
    537     var searchField = document.getElementById("search");
    538     searchField.addEventListener("search", this.performSearch.bind(this), false); // when the search is emptied
    539     searchField.addEventListener("mousedown", this._searchFieldManualFocus.bind(this), false); // when the search field is manually selected
    540     searchField.addEventListener("keydown", this._searchKeyDown.bind(this), true);
    541516
    542517    this.extensionServer.initExtensions();
     
    769744    }
    770745
     746    WebInspector.searchController.handleShortcut(event);
     747    if (event.handled) {
     748        event.preventDefault();
     749        return;
     750    }
     751
    771752    var isMac = WebInspector.isMac();
    772753    switch (event.keyIdentifier) {
     
    793774
    794775            this.drawer.visible = !this.drawer.visible;
    795             break;
    796 
    797         case "U+0046": // F key
    798             if (isMac)
    799                 var isFindKey = event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
    800             else
    801                 var isFindKey = event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey;
    802 
    803             if (isFindKey) {
    804                 WebInspector.focusSearchField();
    805                 event.preventDefault();
    806             }
    807             break;
    808 
    809         case "F3":
    810             if (!isMac) {
    811                 WebInspector.focusSearchField();
    812                 event.preventDefault();
    813             }
    814             break;
    815 
    816         case "U+0047": // G key
    817             if (isMac && event.metaKey && !event.ctrlKey && !event.altKey) {
    818                 if (event.shiftKey) {
    819                     if (this.currentPanel.jumpToPreviousSearchResult)
    820                         this.currentPanel.jumpToPreviousSearchResult();
    821                 } else if (this.currentPanel.jumpToNextSearchResult)
    822                     this.currentPanel.jumpToNextSearchResult();
    823                 event.preventDefault();
    824             }
    825776            break;
    826777
     
    989940        forceComplete: forceComplete
    990941    };
    991 }
    992 
    993 WebInspector.updateSearchLabel = function()
    994 {
    995     if (!this.currentPanel)
    996         return;
    997 
    998     var newLabel = WebInspector.UIString("Search %s", this.currentPanel.toolbarItemLabel);
    999     if (this.attached)
    1000         document.getElementById("search").setAttribute("placeholder", newLabel);
    1001     else {
    1002         document.getElementById("search").removeAttribute("placeholder");
    1003         document.getElementById("search-toolbar-label").textContent = newLabel;
    1004     }
    1005 }
    1006 
    1007 WebInspector.focusSearchField = function()
    1008 {
    1009     var searchField = document.getElementById("search");
    1010     searchField.focus();
    1011     searchField.select();
    1012942}
    1013943
     
    14691399}
    14701400
    1471 WebInspector._searchFieldManualFocus = function(event)
    1472 {
    1473     this.currentFocusElement = event.target;
    1474     this._previousFocusElement = event.target;
    1475 }
    1476 
    1477 WebInspector._searchKeyDown = function(event)
    1478 {
    1479     // Escape Key will clear the field and clear the search results
    1480     if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
    1481         // If focus belongs here and text is empty - nothing to do, return unhandled.
    1482         if (event.target.value === "" && this.currentFocusElement === this.previousFocusElement)
    1483             return;
    1484         event.preventDefault();
    1485         event.stopPropagation();
    1486         // When search was selected manually and is currently blank, we'd like Esc stay unhandled
    1487         // and hit console drawer handler.
    1488         event.target.value = "";
    1489 
    1490         this.performSearch(event);
    1491         this.currentFocusElement = this.previousFocusElement;
    1492         if (this.currentFocusElement === event.target)
    1493             this.currentFocusElement.select();
    1494         return false;
    1495     }
    1496 
    1497     if (!isEnterKey(event))
    1498         return false;
    1499 
    1500     // Select all of the text so the user can easily type an entirely new query.
    1501     event.target.select();
    1502 
    1503     // Only call performSearch if the Enter key was pressed. Otherwise the search
    1504     // performance is poor because of searching on every key. The search field has
    1505     // the incremental attribute set, so we still get incremental searches.
    1506     this.performSearch(event);
    1507 
    1508     // Call preventDefault since this was the Enter key. This prevents a "search" event
    1509     // from firing for key down. This stops performSearch from being called twice in a row.
    1510     event.preventDefault();
    1511 }
    1512 
    1513 WebInspector.performSearch = function(event)
    1514 {
    1515     var forceSearch = event.keyIdentifier === "Enter";
    1516     this.doPerformSearch(event.target.value, forceSearch, event.shiftKey, false);
    1517 }
    1518 
    1519 WebInspector.cancelSearch = function()
    1520 {
    1521     document.getElementById("search").value = "";
    1522     this.doPerformSearch("");
    1523 }
    1524 
    1525 WebInspector.doPerformSearch = function(query, forceSearch, isBackwardSearch, repeatSearch)
    1526 {
    1527     var isShortSearch = (query.length < 3);
    1528 
    1529     // Clear a leftover short search flag due to a non-conflicting forced search.
    1530     if (isShortSearch && this.shortSearchWasForcedByKeyEvent && this.currentQuery !== query)
    1531         delete this.shortSearchWasForcedByKeyEvent;
    1532 
    1533     // Indicate this was a forced search on a short query.
    1534     if (isShortSearch && forceSearch)
    1535         this.shortSearchWasForcedByKeyEvent = true;
    1536 
    1537     if (!query || !query.length || (!forceSearch && isShortSearch)) {
    1538         // Prevent clobbering a short search forced by the user.
    1539         if (this.shortSearchWasForcedByKeyEvent) {
    1540             delete this.shortSearchWasForcedByKeyEvent;
    1541             return;
    1542         }
    1543 
    1544         delete this.currentQuery;
    1545 
    1546         for (var panelName in this.panels) {
    1547             var panel = this.panels[panelName];
    1548             var hadCurrentQuery = !!panel.currentQuery;
    1549             delete panel.currentQuery;
    1550             if (hadCurrentQuery && panel.searchCanceled)
    1551                 panel.searchCanceled();
    1552         }
    1553 
    1554         this.updateSearchMatchesCount();
    1555 
    1556         return;
    1557     }
    1558 
    1559     if (!repeatSearch && query === this.currentPanel.currentQuery && this.currentPanel.currentQuery === this.currentQuery) {
    1560         // When this is the same query and a forced search, jump to the next
    1561         // search result for a good user experience.
    1562         if (forceSearch) {
    1563             if (!isBackwardSearch && this.currentPanel.jumpToNextSearchResult)
    1564                 this.currentPanel.jumpToNextSearchResult();
    1565             else if (isBackwardSearch && this.currentPanel.jumpToPreviousSearchResult)
    1566                 this.currentPanel.jumpToPreviousSearchResult();
    1567         }
    1568         return;
    1569     }
    1570 
    1571     this.currentQuery = query;
    1572 
    1573     this.updateSearchMatchesCount();
    1574 
    1575     if (!this.currentPanel.performSearch)
    1576         return;
    1577 
    1578     this.currentPanel.currentQuery = query;
    1579     this.currentPanel.performSearch(query);
    1580 }
    1581 
    15821401WebInspector.frontendReused = function()
    15831402{
     
    15891408{
    15901409    WebInspector.panels.elements.addNodesToSearchResult(nodeIds);
    1591 }
    1592 
    1593 WebInspector.updateSearchMatchesCount = function(matches, panel)
    1594 {
    1595     if (!panel)
    1596         panel = this.currentPanel;
    1597 
    1598     panel.currentSearchMatches = matches;
    1599 
    1600     if (panel !== this.currentPanel)
    1601         return;
    1602 
    1603     if (!this.currentPanel.currentQuery) {
    1604         document.getElementById("search-results-matches").addStyleClass("hidden");
    1605         return;
    1606     }
    1607 
    1608     if (matches) {
    1609         if (matches === 1)
    1610             var matchesString = WebInspector.UIString("1 match");
    1611         else
    1612             var matchesString = WebInspector.UIString("%d matches", matches);
    1613     } else
    1614         var matchesString = WebInspector.UIString("Not Found");
    1615 
    1616     var matchesToolbarElement = document.getElementById("search-results-matches");
    1617     matchesToolbarElement.removeStyleClass("hidden");
    1618     matchesToolbarElement.textContent = matchesString;
    16191410}
    16201411
Note: See TracChangeset for help on using the changeset viewer.