Commit 60f0dce4 authored by caseq@chromium.org's avatar 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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147105 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a86fc7bb
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.
......@@ -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";
......@@ -5060,6 +5060,7 @@
'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',
......
......@@ -77705,6 +77705,10 @@
RelativePath="..\inspector\front-end\NetworkUISourceCodeProvider.js"
>
</File>
<File
RelativePath="..\inspector\front-end\InspectElementModeController.js"
>
</File>
<File
RelativePath="..\inspector\front-end\Object.js"
>
......@@ -13503,6 +13503,7 @@
<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" />
......@@ -14875,6 +14875,9 @@
<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>
......
......@@ -184,6 +184,7 @@ modules = [
"FontView.js",
"ImageView.js",
"NativeBreakpointsSidebarPane.js",
"InspectElementModeController.js",
"ObjectPopoverHelper.js",
"ObjectPropertiesSection.js",
"SourceFrame.js",
......
/*
* 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;
}
}
......@@ -107,7 +107,8 @@ var InspectorFrontendAPI = {
enterInspectElementMode: function()
{
WebInspector.toggleSearchingForNode();
if (WebInspector.inspectElementModeController)
WebInspector.inspectElementModeController.toggleSearch();
},
fileSystemsLoaded: function(fileSystems)
......
......@@ -132,6 +132,7 @@
<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>
......
......@@ -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>
......
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment