Web Inspector: factor out node search controller from inspector.js
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Mar 2013 13:25:50 +0000 (13:25 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Mar 2013 13:25:50 +0000 (13:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112689

Reviewed by Pavel Feldman.

This just extracts the existing logic of toggling node search
from inspector.js into a class of its own, InspectElementModeController.
Drive-by: add CtrlOrMeta+Shift+C to help screen.
* English.lproj/localizedStrings.js:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* inspector/compile-front-end.py:
* inspector/front-end/InspectElementModeController.js: Added.
(WebInspector.InspectElementModeController):
(WebInspector.InspectElementModeController.createShortcut):
(WebInspector.InspectElementModeController.prototype.enabled):
(WebInspector.InspectElementModeController.prototype.disable):
(WebInspector.InspectElementModeController.prototype.toggleSearch.callback):
(WebInspector.InspectElementModeController.prototype.toggleSearch):
(WebInspector.InspectElementModeController.prototype.handleShortcut):
* inspector/front-end/InspectorFrontendAPI.js:
(InspectorFrontendAPI.enterInspectElementMode):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/inspector.html:
* inspector/front-end/inspector.js:
(WebInspector._createGlobalStatusBarItems):
(WebInspector._registerShortcuts):
(WebInspector.documentKeyDown):
(WebInspector._updateFocusedNode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@147105 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/English.lproj/localizedStrings.js
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/inspector/compile-front-end.py
Source/WebCore/inspector/front-end/InspectElementModeController.js [new file with mode: 0644]
Source/WebCore/inspector/front-end/InspectorFrontendAPI.js
Source/WebCore/inspector/front-end/WebKit.qrc
Source/WebCore/inspector/front-end/inspector.html
Source/WebCore/inspector/front-end/inspector.js

index 4291340..335e560 100644 (file)
@@ -1,3 +1,38 @@
+2013-03-22  Andrey Kosyakov  <caseq@chromium.org>
+
+        Web Inspector: factor out node search controller from inspector.js
+        https://bugs.webkit.org/show_bug.cgi?id=112689
+
+        Reviewed by Pavel Feldman.
+
+        This just extracts the existing logic of toggling node search
+        from inspector.js into a class of its own, InspectElementModeController.
+        Drive-by: add CtrlOrMeta+Shift+C to help screen.
+
+        * English.lproj/localizedStrings.js:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.vcxproj/WebCore.vcxproj.filters:
+        * inspector/compile-front-end.py:
+        * inspector/front-end/InspectElementModeController.js: Added.
+        (WebInspector.InspectElementModeController):
+        (WebInspector.InspectElementModeController.createShortcut):
+        (WebInspector.InspectElementModeController.prototype.enabled):
+        (WebInspector.InspectElementModeController.prototype.disable):
+        (WebInspector.InspectElementModeController.prototype.toggleSearch.callback):
+        (WebInspector.InspectElementModeController.prototype.toggleSearch):
+        (WebInspector.InspectElementModeController.prototype.handleShortcut):
+        * inspector/front-end/InspectorFrontendAPI.js:
+        (InspectorFrontendAPI.enterInspectElementMode):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/inspector.html:
+        * inspector/front-end/inspector.js:
+        (WebInspector._createGlobalStatusBarItems):
+        (WebInspector._registerShortcuts):
+        (WebInspector.documentKeyDown):
+        (WebInspector._updateFocusedNode):
+
 2013-03-28  Eugene Klyuchnikov  <eustas@chromium.org>
 
         Web Inspector: [Settings] "previouslyViewedFiles" exceeds local storage quota.
index 192146b..91ece21 100644 (file)
@@ -917,3 +917,4 @@ localizedStrings["This file was changed externally. Would you like to reload it?
 localizedStrings["It is recommended to restart inspector after making these changes. Would you like to restart it?"] = "It is recommended to restart inspector after making these changes. Would you like to restart it?";
 localizedStrings["Limit number of captured JS stack frames"] = "Limit number of captured JS stack frames";
 localizedStrings["Frames to capture"] = "Frames to capture";
+localizedStrings["Select node to inspect"] = "Select node to inspect";
index 14f39b1..0f5543b 100644 (file)
             'inspector/front-end/NetworkPanelDescriptor.js',
             'inspector/front-end/NetworkRequest.js',
             'inspector/front-end/NetworkUISourceCodeProvider.js',
+            'inspector/front-end/InspectElementModeController.js',
             'inspector/front-end/Object.js',
             'inspector/front-end/ObjectPopoverHelper.js',
             'inspector/front-end/ObjectPropertiesSection.js',
index 6f655fe..41716b7 100755 (executable)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\inspector\front-end\InspectElementModeController.js"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\inspector\front-end\Object.js"
                                        >
                                </File>
index 67bf17f..7d36e0b 100644 (file)
     <None Include="..\inspector\front-end\NetworkPanelDescriptor.js" />
     <None Include="..\inspector\front-end\NetworkRequest.js" />
     <None Include="..\inspector\front-end\NetworkUISourceCodeProvider.js" />
+    <None Include="..\inspector\front-end\InspectElementModeController.js" />
     <None Include="..\inspector\front-end\Object.js" />
     <None Include="..\inspector\front-end\ObjectPopoverHelper.js" />
     <None Include="..\inspector\front-end\ObjectPropertiesSection.js" />
index dea38d4..11b9618 100644 (file)
     <None Include="..\inspector\front-end\NetworkUISourceCodeProvider.js">
       <Filter>inspector\front-end</Filter>
     </None>
+    <None Include="..\inspector\front-end\InspectElementModeController.js">
+      <Filter>inspector\front-end</Filter>
+    </None>
     <None Include="..\inspector\front-end\Object.js">
       <Filter>inspector\front-end</Filter>
     </None>
index 7e10abc..fecaea4 100755 (executable)
@@ -184,6 +184,7 @@ modules = [
             "FontView.js",
             "ImageView.js",
             "NativeBreakpointsSidebarPane.js",
+            "InspectElementModeController.js",
             "ObjectPopoverHelper.js",
             "ObjectPropertiesSection.js",
             "SourceFrame.js",
diff --git a/Source/WebCore/inspector/front-end/InspectElementModeController.js b/Source/WebCore/inspector/front-end/InspectElementModeController.js
new file mode 100644 (file)
index 0000000..9fbf9b8
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
+ * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @constructor
+ */
+WebInspector.InspectElementModeController = function()
+{
+    this.toggleSearchButton = new WebInspector.StatusBarButton(WebInspector.UIString("Select an element in the page to inspect it."), "node-search-status-bar-item");
+    this.toggleSearchButton.addEventListener("click", this.toggleSearch, this);
+    this._shortcut = WebInspector.InspectElementModeController.createShortcut();
+}
+
+WebInspector.InspectElementModeController.createShortcut = function()
+{
+    return WebInspector.KeyboardShortcut.makeDescriptor("c", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift);
+}
+
+WebInspector.InspectElementModeController.prototype = {
+    enabled: function()
+    {
+        return this.toggleSearchButton.toggled;
+    },
+
+    disable: function()
+    {
+        if (this.enabled())
+            this.toggleSearch();
+    },
+
+    toggleSearch: function()
+    {
+        var enabled = !this.enabled();
+        /**
+         * @param {?Protocol.Error} error
+         */
+        function callback(error)
+        {
+            if (!error)
+                this.toggleSearchButton.toggled = enabled;
+        }
+        WebInspector.domAgent.setInspectModeEnabled(enabled, callback.bind(this));
+    },
+
+    /**
+     * @param {KeyboardEvent} event
+     * @return {boolean}
+     */
+    handleShortcut: function(event)
+    {
+        if (WebInspector.KeyboardShortcut.makeKeyFromEvent(event) !== this._shortcut.key)
+            return false;
+        this.toggleSearch();
+        event.consume(true);
+        return true;
+    }
+}
index db2c926..01df30a 100644 (file)
@@ -107,7 +107,8 @@ var InspectorFrontendAPI = {
 
     enterInspectElementMode: function()
     {
-        WebInspector.toggleSearchingForNode();
+        if (WebInspector.inspectElementModeController)
+            WebInspector.inspectElementModeController.toggleSearch();
     },
 
     fileSystemsLoaded: function(fileSystems)
index ed58c57..5b0c136 100644 (file)
     <file>NetworkPanelDescriptor.js</file>
     <file>NetworkRequest.js</file>
     <file>NetworkUISourceCodeProvider.js</file>
+    <file>InspectElementModeController.js</file>
     <file>Object.js</file>
     <file>ObjectPopoverHelper.js</file>
     <file>ObjectPropertiesSection.js</file>
index 6d2ae91..8cad6df 100644 (file)
@@ -168,6 +168,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     <script type="text/javascript" src="CookieParser.js"></script>
     <script type="text/javascript" src="Toolbar.js"></script>
     <script type="text/javascript" src="SearchController.js"></script>
+    <script type="text/javascript" src="InspectElementModeController.js"></script>
     <script type="text/javascript" src="WorkerManager.js"></script>
     <script type="text/javascript" src="UserMetrics.js"></script>
     <script type="text/javascript" src="RuntimeModel.js"></script>
index 8eb0daa..fd3f1f8 100644 (file)
@@ -93,11 +93,8 @@ var WebInspector = {
         this._toggleConsoleButton.addEventListener("click", this._toggleConsoleButtonClicked.bind(this), false);
         mainStatusBar.insertBefore(this._toggleConsoleButton.element, bottomStatusBarContainer);
 
-        if (!WebInspector.WorkerManager.isWorkerFrontend()) {
-            this._nodeSearchButton = new WebInspector.StatusBarButton(WebInspector.UIString("Select an element in the page to inspect it."), "node-search-status-bar-item");
-            this._nodeSearchButton.addEventListener("click", this.toggleSearchingForNode, this);
-            mainStatusBar.insertBefore(this._nodeSearchButton.element, bottomStatusBarContainer);
-        }
+        if (this.inspectElementModeController)
+            mainStatusBar.insertBefore(this.inspectElementModeController.toggleSearchButton.element, bottomStatusBarContainer);
 
         mainStatusBar.appendChild(this.settingsController.statusBarItem);
     },
@@ -273,20 +270,6 @@ var WebInspector = {
         InspectorFrontendHost.setZoomFactor(WebInspector.Zoom.Table[index]);
     },
 
-    toggleSearchingForNode: function()
-    {
-        var enabled = !this._nodeSearchButton.toggled;
-        /**
-         * @param {?Protocol.Error} error
-         */
-        function callback(error)
-        {
-            if (!error)
-                this._nodeSearchButton.toggled = enabled;
-        }
-        WebInspector.domAgent.setInspectModeEnabled(enabled, callback.bind(this));
-    },
-
     _debuggerPaused: function()
     {
         // Create scripts panel upon demand.
@@ -456,6 +439,9 @@ WebInspector._doLoadedDoneWithCapabilities = function()
 
     this.searchController = new WebInspector.SearchController();
     this.advancedSearchController = new WebInspector.AdvancedSearchController();
+    if (!WebInspector.WorkerManager.isWorkerFrontend())
+        this.inspectElementModeController = new WebInspector.InspectElementModeController();
+
     this.settingsController = new WebInspector.SettingsController();
 
     this.domBreakpointsSidebarPane = new WebInspector.DOMBreakpointsSidebarPane();
@@ -687,6 +673,9 @@ WebInspector._registerShortcuts = function()
     var advancedSearchShortcut = WebInspector.AdvancedSearchController.createShortcut();
     section.addKey(advancedSearchShortcut, WebInspector.UIString("Search across all sources"));
 
+    var inspectElementModeShortcut = WebInspector.InspectElementModeController.createShortcut();
+    section.addKey(inspectElementModeShortcut, WebInspector.UIString("Select node to inspect"));
+
     var openResourceShortcut = WebInspector.KeyboardShortcut.makeDescriptor("o", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta);
     section.addKey(openResourceShortcut, WebInspector.UIString("Go to source"));
 
@@ -742,6 +731,8 @@ WebInspector.documentKeyDown = function(event)
         return;
     if (WebInspector.advancedSearchController.handleShortcut(event))
         return;
+    if (WebInspector.inspectElementModeController && WebInspector.inspectElementModeController.handleShortcut(event))
+        return;
 
     switch (event.keyIdentifier) {
         case "U+004F": // O key
@@ -794,22 +785,6 @@ WebInspector.documentKeyDown = function(event)
             }
             break;
     }
-
-    // Cmd/Control + Shift + C should be a shortcut to clicking the Node Search Button.
-    // This shortcut matches Firebug.
-    if (event.keyIdentifier === "U+0043") { // C key
-        if (WebInspector.isMac())
-            var isNodeSearchKey = event.metaKey && !event.ctrlKey && !event.altKey && event.shiftKey;
-        else
-            var isNodeSearchKey = event.ctrlKey && !event.metaKey && !event.altKey && event.shiftKey;
-
-        if (isNodeSearchKey) {
-            this.toggleSearchingForNode();
-            event.consume(true);
-            return;
-        }
-        return;
-    }
 }
 
 WebInspector.postDocumentKeyDown = function(event)
@@ -991,9 +966,9 @@ WebInspector.targetCrashed = function()
 
 WebInspector._updateFocusedNode = function(nodeId)
 {
-    if (WebInspector._nodeSearchButton.toggled) {
+    if (WebInspector.inspectElementModeController && WebInspector.inspectElementModeController.enabled()) {
         InspectorFrontendHost.bringToFront();
-        WebInspector._nodeSearchButton.toggled = false;
+        WebInspector.inspectElementModeController.disable();
     }
     WebInspector.showPanel("elements").revealAndSelectNode(nodeId);
 }