| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * | 10 * |
| 11 * 2. Redistributions in binary form must reproduce the above | 11 * 2. Redistributions in binary form must reproduce the above |
| 12 * copyright notice, this list of conditions and the following disclaimer | 12 * copyright notice, this list of conditions and the following disclaimer |
| 13 * in the documentation and/or other materials provided with the | 13 * in the documentation and/or other materials provided with the |
| 14 * distribution. | 14 * distribution. |
| 15 * | 15 * |
| 16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS | 16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS |
| 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. | 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. |
| 20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | |
| 29 /** | 28 /** |
| 30 * @constructor | |
| 31 * @implements {WebInspector.TargetManager.Observer} | 29 * @implements {WebInspector.TargetManager.Observer} |
| 30 * @unrestricted |
| 32 */ | 31 */ |
| 33 WebInspector.InspectElementModeController = function() | 32 WebInspector.InspectElementModeController = class { |
| 34 { | 33 constructor() { |
| 35 this._toggleSearchAction = WebInspector.actionRegistry.action("elements.togg
le-element-search"); | 34 this._toggleSearchAction = WebInspector.actionRegistry.action('elements.togg
le-element-search'); |
| 36 if (Runtime.experiments.isEnabled("layoutEditor")) { | 35 if (Runtime.experiments.isEnabled('layoutEditor')) { |
| 37 this._layoutEditorButton = new WebInspector.ToolbarToggle(WebInspector.U
IString("Toggle Layout Editor"), "layout-editor-toolbar-item"); | 36 this._layoutEditorButton = |
| 38 this._layoutEditorButton.addEventListener("click", this._toggleLayoutEdi
tor, this); | 37 new WebInspector.ToolbarToggle(WebInspector.UIString('Toggle Layout Ed
itor'), 'layout-editor-toolbar-item'); |
| 38 this._layoutEditorButton.addEventListener('click', this._toggleLayoutEdito
r, this); |
| 39 } | 39 } |
| 40 | 40 |
| 41 this._mode = DOMAgent.InspectMode.None; | 41 this._mode = DOMAgent.InspectMode.None; |
| 42 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event
s.SuspendStateChanged, this._suspendStateChanged, this); | 42 WebInspector.targetManager.addEventListener( |
| 43 WebInspector.TargetManager.Events.SuspendStateChanged, this._suspendStat
eChanged, this); |
| 43 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili
ty.DOM); | 44 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili
ty.DOM); |
| 44 }; | 45 } |
| 45 | 46 |
| 46 WebInspector.InspectElementModeController.prototype = { | 47 /** |
| 47 /** | 48 * @override |
| 48 * @override | 49 * @param {!WebInspector.Target} target |
| 49 * @param {!WebInspector.Target} target | 50 */ |
| 50 */ | 51 targetAdded(target) { |
| 51 targetAdded: function(target) | 52 // When DevTools are opening in the inspect element mode, the first target c
omes in |
| 52 { | 53 // much later than the InspectorFrontendAPI.enterInspectElementMode event. |
| 53 // When DevTools are opening in the inspect element mode, the first targ
et comes in | 54 if (this._mode === DOMAgent.InspectMode.None) |
| 54 // much later than the InspectorFrontendAPI.enterInspectElementMode even
t. | 55 return; |
| 55 if (this._mode === DOMAgent.InspectMode.None) | 56 var domModel = WebInspector.DOMModel.fromTarget(target); |
| 56 return; | 57 domModel.setInspectMode(this._mode); |
| 57 var domModel = WebInspector.DOMModel.fromTarget(target); | 58 } |
| 58 domModel.setInspectMode(this._mode); | |
| 59 }, | |
| 60 | 59 |
| 61 /** | 60 /** |
| 62 * @override | 61 * @override |
| 63 * @param {!WebInspector.Target} target | 62 * @param {!WebInspector.Target} target |
| 64 */ | 63 */ |
| 65 targetRemoved: function(target) | 64 targetRemoved(target) { |
| 66 { | 65 } |
| 67 }, | |
| 68 | 66 |
| 69 /** | 67 /** |
| 70 * @return {boolean} | 68 * @return {boolean} |
| 71 */ | 69 */ |
| 72 isInInspectElementMode: function() | 70 isInInspectElementMode() { |
| 73 { | 71 return this._mode === DOMAgent.InspectMode.SearchForNode || |
| 74 return this._mode === DOMAgent.InspectMode.SearchForNode || this._mode =
== DOMAgent.InspectMode.SearchForUAShadowDOM; | 72 this._mode === DOMAgent.InspectMode.SearchForUAShadowDOM; |
| 75 }, | 73 } |
| 76 | 74 |
| 77 /** | 75 /** |
| 78 * @return {boolean} | 76 * @return {boolean} |
| 79 */ | 77 */ |
| 80 isInLayoutEditorMode: function() | 78 isInLayoutEditorMode() { |
| 81 { | 79 return this._mode === DOMAgent.InspectMode.ShowLayoutEditor; |
| 82 return this._mode === DOMAgent.InspectMode.ShowLayoutEditor; | 80 } |
| 83 }, | |
| 84 | 81 |
| 85 stopInspection: function() | 82 stopInspection() { |
| 86 { | 83 if (this._mode && this._mode !== DOMAgent.InspectMode.None) |
| 87 if (this._mode && this._mode !== DOMAgent.InspectMode.None) | 84 this._toggleInspectMode(); |
| 88 this._toggleInspectMode(); | 85 } |
| 89 }, | |
| 90 | 86 |
| 91 _toggleLayoutEditor: function() | 87 _toggleLayoutEditor() { |
| 92 { | 88 var mode = this.isInLayoutEditorMode() ? DOMAgent.InspectMode.None : DOMAgen
t.InspectMode.ShowLayoutEditor; |
| 93 var mode = this.isInLayoutEditorMode() ? DOMAgent.InspectMode.None : DOM
Agent.InspectMode.ShowLayoutEditor; | 89 this._setMode(mode); |
| 94 this._setMode(mode); | 90 } |
| 95 }, | |
| 96 | 91 |
| 97 _toggleInspectMode: function() | 92 _toggleInspectMode() { |
| 98 { | 93 if (WebInspector.targetManager.allTargetsSuspended()) |
| 99 if (WebInspector.targetManager.allTargetsSuspended()) | 94 return; |
| 100 return; | |
| 101 | 95 |
| 102 var mode; | 96 var mode; |
| 103 if (this.isInInspectElementMode()) | 97 if (this.isInInspectElementMode()) |
| 104 mode = DOMAgent.InspectMode.None; | 98 mode = DOMAgent.InspectMode.None; |
| 105 else | 99 else |
| 106 mode = WebInspector.moduleSetting("showUAShadowDOM").get() ? DOMAgen
t.InspectMode.SearchForUAShadowDOM : DOMAgent.InspectMode.SearchForNode; | 100 mode = WebInspector.moduleSetting('showUAShadowDOM').get() ? DOMAgent.Insp
ectMode.SearchForUAShadowDOM : |
| 101 DOMAgent.Insp
ectMode.SearchForNode; |
| 107 | 102 |
| 108 this._setMode(mode); | 103 this._setMode(mode); |
| 109 }, | 104 } |
| 110 | 105 |
| 111 /** | 106 /** |
| 112 * @param {!DOMAgent.InspectMode} mode | 107 * @param {!DOMAgent.InspectMode} mode |
| 113 */ | 108 */ |
| 114 _setMode: function(mode) | 109 _setMode(mode) { |
| 115 { | 110 this._mode = mode; |
| 116 this._mode = mode; | 111 for (var domModel of WebInspector.DOMModel.instances()) |
| 117 for (var domModel of WebInspector.DOMModel.instances()) | 112 domModel.setInspectMode(mode); |
| 118 domModel.setInspectMode(mode); | |
| 119 | 113 |
| 120 if (this._layoutEditorButton) { | 114 if (this._layoutEditorButton) { |
| 121 this._layoutEditorButton.setEnabled(!this.isInInspectElementMode()); | 115 this._layoutEditorButton.setEnabled(!this.isInInspectElementMode()); |
| 122 this._layoutEditorButton.setToggled(this.isInLayoutEditorMode()); | 116 this._layoutEditorButton.setToggled(this.isInLayoutEditorMode()); |
| 123 } | 117 } |
| 124 | 118 |
| 125 this._toggleSearchAction.setEnabled(!this.isInLayoutEditorMode()); | 119 this._toggleSearchAction.setEnabled(!this.isInLayoutEditorMode()); |
| 126 this._toggleSearchAction.setToggled(this.isInInspectElementMode()); | 120 this._toggleSearchAction.setToggled(this.isInInspectElementMode()); |
| 127 }, | 121 } |
| 128 | 122 |
| 129 _suspendStateChanged: function() | 123 _suspendStateChanged() { |
| 130 { | 124 if (!WebInspector.targetManager.allTargetsSuspended()) |
| 131 if (!WebInspector.targetManager.allTargetsSuspended()) | 125 return; |
| 132 return; | |
| 133 | 126 |
| 134 this._mode = DOMAgent.InspectMode.None; | 127 this._mode = DOMAgent.InspectMode.None; |
| 135 this._toggleSearchAction.setToggled(false); | 128 this._toggleSearchAction.setToggled(false); |
| 136 if (this._layoutEditorButton) | 129 if (this._layoutEditorButton) |
| 137 this._layoutEditorButton.setToggled(false); | 130 this._layoutEditorButton.setToggled(false); |
| 138 } | 131 } |
| 139 }; | 132 }; |
| 140 | 133 |
| 141 /** | 134 /** |
| 142 * @constructor | |
| 143 * @implements {WebInspector.ActionDelegate} | 135 * @implements {WebInspector.ActionDelegate} |
| 136 * @unrestricted |
| 144 */ | 137 */ |
| 145 WebInspector.InspectElementModeController.ToggleSearchActionDelegate = function(
) | 138 WebInspector.InspectElementModeController.ToggleSearchActionDelegate = class { |
| 146 { | 139 /** |
| 147 }; | 140 * @override |
| 148 | 141 * @param {!WebInspector.Context} context |
| 149 WebInspector.InspectElementModeController.ToggleSearchActionDelegate.prototype =
{ | 142 * @param {string} actionId |
| 150 /** | 143 * @return {boolean} |
| 151 * @override | 144 */ |
| 152 * @param {!WebInspector.Context} context | 145 handleAction(context, actionId) { |
| 153 * @param {string} actionId | 146 if (!WebInspector.inspectElementModeController) |
| 154 * @return {boolean} | 147 return false; |
| 155 */ | 148 WebInspector.inspectElementModeController._toggleInspectMode(); |
| 156 handleAction: function(context, actionId) | 149 return true; |
| 157 { | 150 } |
| 158 if (!WebInspector.inspectElementModeController) | |
| 159 return false; | |
| 160 WebInspector.inspectElementModeController._toggleInspectMode(); | |
| 161 return true; | |
| 162 } | |
| 163 }; | 151 }; |
| 164 | 152 |
| 165 /** | 153 /** |
| 166 * @constructor | |
| 167 * @implements {WebInspector.ToolbarItem.Provider} | 154 * @implements {WebInspector.ToolbarItem.Provider} |
| 155 * @unrestricted |
| 168 */ | 156 */ |
| 169 WebInspector.InspectElementModeController.LayoutEditorButtonProvider = function(
) | 157 WebInspector.InspectElementModeController.LayoutEditorButtonProvider = class { |
| 170 { | 158 /** |
| 171 }; | 159 * @override |
| 160 * @return {?WebInspector.ToolbarItem} |
| 161 */ |
| 162 item() { |
| 163 if (!WebInspector.inspectElementModeController) |
| 164 return null; |
| 172 | 165 |
| 173 WebInspector.InspectElementModeController.LayoutEditorButtonProvider.prototype =
{ | 166 return WebInspector.inspectElementModeController._layoutEditorButton; |
| 174 /** | 167 } |
| 175 * @override | |
| 176 * @return {?WebInspector.ToolbarItem} | |
| 177 */ | |
| 178 item: function() | |
| 179 { | |
| 180 if (!WebInspector.inspectElementModeController) | |
| 181 return null; | |
| 182 | |
| 183 return WebInspector.inspectElementModeController._layoutEditorButton; | |
| 184 } | |
| 185 }; | 168 }; |
| 186 | 169 |
| 187 /** @type {?WebInspector.InspectElementModeController} */ | 170 /** @type {?WebInspector.InspectElementModeController} */ |
| 188 WebInspector.inspectElementModeController = Runtime.queryParam("isSharedWorker")
? null : new WebInspector.InspectElementModeController(); | 171 WebInspector.inspectElementModeController = |
| 172 Runtime.queryParam('isSharedWorker') ? null : new WebInspector.InspectElemen
tModeController(); |
| OLD | NEW |