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