2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * @implements {WebInspector.TargetManager.Observer}
33 WebInspector.InspectElementModeController = function()
35 this._toggleSearchButton = new WebInspector.ToolbarButton(WebInspector.UIString("Select an element in the page to inspect it"), "node-search-toolbar-item");
36 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.EnterInspectElementMode, this._toggleSearch, this);
37 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this);
38 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Page);
42 * @return {!WebInspector.KeyboardShortcut.Descriptor}
44 WebInspector.InspectElementModeController.createShortcut = function()
46 return WebInspector.KeyboardShortcut.makeDescriptor("c", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift);
49 WebInspector.InspectElementModeController.prototype = {
52 * @param {!WebInspector.Target} target
54 targetAdded: function(target)
56 // When DevTools are opening in the inspect element mode, the first target comes in
57 // much later than the InspectorFrontendAPI.enterInspectElementMode event.
60 var domModel = WebInspector.DOMModel.fromTarget(target);
61 domModel.setInspectMode(WebInspector.moduleSetting("showUAShadowDOM").get() ? DOMAgent.InspectMode.SearchForUAShadowDOM : DOMAgent.InspectMode.SearchForNode);
66 * @param {!WebInspector.Target} target
68 targetRemoved: function(target)
77 return this._toggleSearchButton.toggled();
89 this._toggleSearchButton.setEnabled(false);
94 this._toggleSearchButton.setEnabled(true);
97 _toggleSearch: function()
99 if (!this._toggleSearchButton.enabled())
102 var shouldEnable = !this.started();
103 this._toggleSearchButton.setToggled(shouldEnable);
105 for (var domModel of WebInspector.DOMModel.instances()) {
108 mode = DOMAgent.InspectMode.None;
109 else if (WebInspector.moduleSetting("showUAShadowDOM").get())
110 mode = DOMAgent.InspectMode.SearchForUAShadowDOM;
112 mode = DOMAgent.InspectMode.SearchForNode;
114 domModel.setInspectMode(mode);
118 _suspendStateChanged: function()
120 if (WebInspector.targetManager.allTargetsSuspended())
121 this._toggleSearchButton.setToggled(false);
127 * @implements {WebInspector.ActionDelegate}
129 WebInspector.InspectElementModeController.ToggleSearchActionDelegate = function()
133 WebInspector.InspectElementModeController.ToggleSearchActionDelegate.prototype = {
136 * @param {!WebInspector.Context} context
137 * @param {string} actionId
139 handleAction: function(context, actionId)
141 if (!WebInspector.inspectElementModeController)
143 WebInspector.inspectElementModeController._toggleSearch();
149 * @implements {WebInspector.ToolbarItem.Provider}
151 WebInspector.InspectElementModeController.ToggleButtonProvider = function()
155 WebInspector.InspectElementModeController.ToggleButtonProvider.prototype = {
158 * @return {?WebInspector.ToolbarItem}
162 if (!WebInspector.inspectElementModeController)
165 return WebInspector.inspectElementModeController._toggleSearchButton;
169 /** @type {?WebInspector.InspectElementModeController} */
170 WebInspector.inspectElementModeController = null;