| 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 /** | 28 /** |
| 29 * @implements {WebInspector.TargetManager.Observer} | 29 * @implements {SDK.TargetManager.Observer} |
| 30 * @unrestricted | 30 * @unrestricted |
| 31 */ | 31 */ |
| 32 WebInspector.InspectElementModeController = class { | 32 Elements.InspectElementModeController = class { |
| 33 constructor() { | 33 constructor() { |
| 34 this._toggleSearchAction = WebInspector.actionRegistry.action('elements.togg
le-element-search'); | 34 this._toggleSearchAction = UI.actionRegistry.action('elements.toggle-element
-search'); |
| 35 if (Runtime.experiments.isEnabled('layoutEditor')) { | 35 if (Runtime.experiments.isEnabled('layoutEditor')) { |
| 36 this._layoutEditorButton = | 36 this._layoutEditorButton = |
| 37 new WebInspector.ToolbarToggle(WebInspector.UIString('Toggle Layout Ed
itor'), 'largeicon-layout-editor'); | 37 new UI.ToolbarToggle(Common.UIString('Toggle Layout Editor'), 'largeic
on-layout-editor'); |
| 38 this._layoutEditorButton.addEventListener('click', this._toggleLayoutEdito
r, this); | 38 this._layoutEditorButton.addEventListener('click', this._toggleLayoutEdito
r, this); |
| 39 } | 39 } |
| 40 | 40 |
| 41 this._mode = Protocol.DOM.InspectMode.None; | 41 this._mode = Protocol.DOM.InspectMode.None; |
| 42 WebInspector.targetManager.addEventListener( | 42 SDK.targetManager.addEventListener( |
| 43 WebInspector.TargetManager.Events.SuspendStateChanged, this._suspendStat
eChanged, this); | 43 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged,
this); |
| 44 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili
ty.DOM); | 44 SDK.targetManager.observeTargets(this, SDK.Target.Capability.DOM); |
| 45 } | 45 } |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * @override | 48 * @override |
| 49 * @param {!WebInspector.Target} target | 49 * @param {!SDK.Target} target |
| 50 */ | 50 */ |
| 51 targetAdded(target) { | 51 targetAdded(target) { |
| 52 // When DevTools are opening in the inspect element mode, the first target c
omes in | 52 // When DevTools are opening in the inspect element mode, the first target c
omes in |
| 53 // much later than the InspectorFrontendAPI.enterInspectElementMode event. | 53 // much later than the InspectorFrontendAPI.enterInspectElementMode event. |
| 54 if (this._mode === Protocol.DOM.InspectMode.None) | 54 if (this._mode === Protocol.DOM.InspectMode.None) |
| 55 return; | 55 return; |
| 56 var domModel = WebInspector.DOMModel.fromTarget(target); | 56 var domModel = SDK.DOMModel.fromTarget(target); |
| 57 domModel.setInspectMode(this._mode); | 57 domModel.setInspectMode(this._mode); |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * @override | 61 * @override |
| 62 * @param {!WebInspector.Target} target | 62 * @param {!SDK.Target} target |
| 63 */ | 63 */ |
| 64 targetRemoved(target) { | 64 targetRemoved(target) { |
| 65 } | 65 } |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * @return {boolean} | 68 * @return {boolean} |
| 69 */ | 69 */ |
| 70 isInInspectElementMode() { | 70 isInInspectElementMode() { |
| 71 return this._mode === Protocol.DOM.InspectMode.SearchForNode || | 71 return this._mode === Protocol.DOM.InspectMode.SearchForNode || |
| 72 this._mode === Protocol.DOM.InspectMode.SearchForUAShadowDOM; | 72 this._mode === Protocol.DOM.InspectMode.SearchForUAShadowDOM; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 83 if (this._mode && this._mode !== Protocol.DOM.InspectMode.None) | 83 if (this._mode && this._mode !== Protocol.DOM.InspectMode.None) |
| 84 this._toggleInspectMode(); | 84 this._toggleInspectMode(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 _toggleLayoutEditor() { | 87 _toggleLayoutEditor() { |
| 88 var mode = this.isInLayoutEditorMode() ? Protocol.DOM.InspectMode.None : Pro
tocol.DOM.InspectMode.ShowLayoutEditor; | 88 var mode = this.isInLayoutEditorMode() ? Protocol.DOM.InspectMode.None : Pro
tocol.DOM.InspectMode.ShowLayoutEditor; |
| 89 this._setMode(mode); | 89 this._setMode(mode); |
| 90 } | 90 } |
| 91 | 91 |
| 92 _toggleInspectMode() { | 92 _toggleInspectMode() { |
| 93 if (WebInspector.targetManager.allTargetsSuspended()) | 93 if (SDK.targetManager.allTargetsSuspended()) |
| 94 return; | 94 return; |
| 95 | 95 |
| 96 var mode; | 96 var mode; |
| 97 if (this.isInInspectElementMode()) | 97 if (this.isInInspectElementMode()) |
| 98 mode = Protocol.DOM.InspectMode.None; | 98 mode = Protocol.DOM.InspectMode.None; |
| 99 else | 99 else |
| 100 mode = WebInspector.moduleSetting('showUAShadowDOM').get() ? Protocol.DOM.
InspectMode.SearchForUAShadowDOM : | 100 mode = Common.moduleSetting('showUAShadowDOM').get() ? Protocol.DOM.Inspec
tMode.SearchForUAShadowDOM : |
| 101 Protocol.DOM.
InspectMode.SearchForNode; | 101 Protocol.DOM.
InspectMode.SearchForNode; |
| 102 | 102 |
| 103 this._setMode(mode); | 103 this._setMode(mode); |
| 104 } | 104 } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * @param {!Protocol.DOM.InspectMode} mode | 107 * @param {!Protocol.DOM.InspectMode} mode |
| 108 */ | 108 */ |
| 109 _setMode(mode) { | 109 _setMode(mode) { |
| 110 this._mode = mode; | 110 this._mode = mode; |
| 111 for (var domModel of WebInspector.DOMModel.instances()) | 111 for (var domModel of SDK.DOMModel.instances()) |
| 112 domModel.setInspectMode(mode); | 112 domModel.setInspectMode(mode); |
| 113 | 113 |
| 114 if (this._layoutEditorButton) { | 114 if (this._layoutEditorButton) { |
| 115 this._layoutEditorButton.setEnabled(!this.isInInspectElementMode()); | 115 this._layoutEditorButton.setEnabled(!this.isInInspectElementMode()); |
| 116 this._layoutEditorButton.setToggled(this.isInLayoutEditorMode()); | 116 this._layoutEditorButton.setToggled(this.isInLayoutEditorMode()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 this._toggleSearchAction.setEnabled(!this.isInLayoutEditorMode()); | 119 this._toggleSearchAction.setEnabled(!this.isInLayoutEditorMode()); |
| 120 this._toggleSearchAction.setToggled(this.isInInspectElementMode()); | 120 this._toggleSearchAction.setToggled(this.isInInspectElementMode()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 _suspendStateChanged() { | 123 _suspendStateChanged() { |
| 124 if (!WebInspector.targetManager.allTargetsSuspended()) | 124 if (!SDK.targetManager.allTargetsSuspended()) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 this._mode = Protocol.DOM.InspectMode.None; | 127 this._mode = Protocol.DOM.InspectMode.None; |
| 128 this._toggleSearchAction.setToggled(false); | 128 this._toggleSearchAction.setToggled(false); |
| 129 if (this._layoutEditorButton) | 129 if (this._layoutEditorButton) |
| 130 this._layoutEditorButton.setToggled(false); | 130 this._layoutEditorButton.setToggled(false); |
| 131 } | 131 } |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * @implements {WebInspector.ActionDelegate} | 135 * @implements {UI.ActionDelegate} |
| 136 * @unrestricted | 136 * @unrestricted |
| 137 */ | 137 */ |
| 138 WebInspector.InspectElementModeController.ToggleSearchActionDelegate = class { | 138 Elements.InspectElementModeController.ToggleSearchActionDelegate = class { |
| 139 /** | 139 /** |
| 140 * @override | 140 * @override |
| 141 * @param {!WebInspector.Context} context | 141 * @param {!UI.Context} context |
| 142 * @param {string} actionId | 142 * @param {string} actionId |
| 143 * @return {boolean} | 143 * @return {boolean} |
| 144 */ | 144 */ |
| 145 handleAction(context, actionId) { | 145 handleAction(context, actionId) { |
| 146 if (!WebInspector.inspectElementModeController) | 146 if (!Elements.inspectElementModeController) |
| 147 return false; | 147 return false; |
| 148 WebInspector.inspectElementModeController._toggleInspectMode(); | 148 Elements.inspectElementModeController._toggleInspectMode(); |
| 149 return true; | 149 return true; |
| 150 } | 150 } |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @implements {WebInspector.ToolbarItem.Provider} | 154 * @implements {UI.ToolbarItem.Provider} |
| 155 * @unrestricted | 155 * @unrestricted |
| 156 */ | 156 */ |
| 157 WebInspector.InspectElementModeController.LayoutEditorButtonProvider = class { | 157 Elements.InspectElementModeController.LayoutEditorButtonProvider = class { |
| 158 /** | 158 /** |
| 159 * @override | 159 * @override |
| 160 * @return {?WebInspector.ToolbarItem} | 160 * @return {?UI.ToolbarItem} |
| 161 */ | 161 */ |
| 162 item() { | 162 item() { |
| 163 if (!WebInspector.inspectElementModeController) | 163 if (!Elements.inspectElementModeController) |
| 164 return null; | 164 return null; |
| 165 | 165 |
| 166 return WebInspector.inspectElementModeController._layoutEditorButton; | 166 return Elements.inspectElementModeController._layoutEditorButton; |
| 167 } | 167 } |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 /** @type {?WebInspector.InspectElementModeController} */ | 170 /** @type {?Elements.InspectElementModeController} */ |
| 171 WebInspector.inspectElementModeController = | 171 Elements.inspectElementModeController = |
| 172 Runtime.queryParam('isSharedWorker') ? null : new WebInspector.InspectElemen
tModeController(); | 172 Runtime.queryParam('isSharedWorker') ? null : new Elements.InspectElementMod
eController(); |
| OLD | NEW |