| 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 15 matching lines...) Expand all Loading... |
| 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 /** | 29 /** |
| 30 * @constructor | 30 * @constructor |
| 31 * @implements {WebInspector.TargetManager.Observer} | 31 * @implements {WebInspector.TargetManager.Observer} |
| 32 */ | 32 */ |
| 33 WebInspector.InspectElementModeController = function() | 33 WebInspector.InspectElementModeController = function() |
| 34 { | 34 { |
| 35 this._toggleSearchButton = new WebInspector.ToolbarButton(WebInspector.UIStr
ing("Select an element in the page to inspect it"), "node-search-toolbar-item"); | 35 this._toggleSearchButton = new WebInspector.ToolbarButton(WebInspector.UIStr
ing("Select an element in the page to inspect it"), "node-search-toolbar-item"); |
| 36 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.EnterInspectElementMode, this._toggleSearch, this); | 36 if (Runtime.experiments.isEnabled("layoutEditor")) { |
| 37 this._layoutEditorButton = new WebInspector.ToolbarButton(WebInspector.U
IString("Toggle Layout Editor"), "layout-editor-toolbar-item"); |
| 38 this._layoutEditorButton.addEventListener("click", this._toggleLayoutEdi
tor, this); |
| 39 } |
| 40 |
| 41 this._mode = DOMAgent.InspectMode.None; |
| 42 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.EnterInspectElementMode, this._toggleInspectMode, this); |
| 37 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event
s.SuspendStateChanged, this._suspendStateChanged, this); | 43 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event
s.SuspendStateChanged, this._suspendStateChanged, this); |
| 38 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Pag
e); | 44 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Pag
e); |
| 39 } | 45 } |
| 40 | 46 |
| 41 /** | 47 /** |
| 42 * @return {!WebInspector.KeyboardShortcut.Descriptor} | 48 * @return {!WebInspector.KeyboardShortcut.Descriptor} |
| 43 */ | 49 */ |
| 44 WebInspector.InspectElementModeController.createShortcut = function() | 50 WebInspector.InspectElementModeController.createShortcut = function() |
| 45 { | 51 { |
| 46 return WebInspector.KeyboardShortcut.makeDescriptor("c", WebInspector.Keyboa
rdShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift)
; | 52 return WebInspector.KeyboardShortcut.makeDescriptor("c", WebInspector.Keyboa
rdShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift)
; |
| 47 } | 53 } |
| 48 | 54 |
| 49 WebInspector.InspectElementModeController.prototype = { | 55 WebInspector.InspectElementModeController.prototype = { |
| 50 /** | 56 /** |
| 51 * @override | 57 * @override |
| 52 * @param {!WebInspector.Target} target | 58 * @param {!WebInspector.Target} target |
| 53 */ | 59 */ |
| 54 targetAdded: function(target) | 60 targetAdded: function(target) |
| 55 { | 61 { |
| 56 // When DevTools are opening in the inspect element mode, the first targ
et comes in | 62 // When DevTools are opening in the inspect element mode, the first targ
et comes in |
| 57 // much later than the InspectorFrontendAPI.enterInspectElementMode even
t. | 63 // much later than the InspectorFrontendAPI.enterInspectElementMode even
t. |
| 58 if (!this.started()) | 64 if (this._mode === DOMAgent.InspectMode.None) |
| 59 return; | 65 return; |
| 60 var domModel = WebInspector.DOMModel.fromTarget(target); | 66 var domModel = WebInspector.DOMModel.fromTarget(target); |
| 61 domModel.setInspectMode(WebInspector.moduleSetting("showUAShadowDOM").ge
t() ? DOMAgent.InspectMode.SearchForUAShadowDOM : DOMAgent.InspectMode.SearchFor
Node); | 67 domModel.setInspectMode(this._mode); |
| 62 }, | 68 }, |
| 63 | 69 |
| 64 /** | 70 /** |
| 65 * @override | 71 * @override |
| 66 * @param {!WebInspector.Target} target | 72 * @param {!WebInspector.Target} target |
| 67 */ | 73 */ |
| 68 targetRemoved: function(target) | 74 targetRemoved: function(target) |
| 69 { | 75 { |
| 70 }, | 76 }, |
| 71 | 77 |
| 72 /** | 78 /** |
| 73 * @return {boolean} | 79 * @return {boolean} |
| 74 */ | 80 */ |
| 75 started: function() | 81 isInInspectElementMode: function() |
| 76 { | 82 { |
| 77 return this._toggleSearchButton.toggled(); | 83 return this._mode === DOMAgent.InspectMode.SearchForNode || this._mode =
== DOMAgent.InspectMode.SearchForUAShadowDOM; |
| 78 }, | 84 }, |
| 79 | 85 |
| 80 stop: function() | 86 /** |
| 87 * @return {boolean} |
| 88 */ |
| 89 isInLayoutEditorMode: function() |
| 81 { | 90 { |
| 82 if (this.started()) | 91 return this._mode === DOMAgent.InspectMode.ShowLayoutEditor; |
| 83 this._toggleSearch(); | |
| 84 }, | 92 }, |
| 85 | 93 |
| 86 disable: function() | 94 stopInspection: function() |
| 87 { | 95 { |
| 88 this.stop(); | 96 if (this._mode && this._mode !== DOMAgent.InspectMode.None) |
| 89 this._toggleSearchButton.setEnabled(false); | 97 this._toggleInspectMode(); |
| 90 }, | 98 }, |
| 91 | 99 |
| 92 enable: function() | 100 _toggleLayoutEditor: function() |
| 93 { | 101 { |
| 94 this._toggleSearchButton.setEnabled(true); | 102 var mode = this.isInLayoutEditorMode() ? DOMAgent.InspectMode.None : DOM
Agent.InspectMode.ShowLayoutEditor; |
| 103 this._setMode(mode); |
| 95 }, | 104 }, |
| 96 | 105 |
| 97 _toggleSearch: function() | 106 _toggleInspectMode: function() |
| 98 { | 107 { |
| 99 if (!this._toggleSearchButton.enabled()) | 108 if (WebInspector.targetManager.allTargetsSuspended()) |
| 100 return; | 109 return; |
| 101 | 110 |
| 102 var shouldEnable = !this.started(); | 111 var mode; |
| 103 this._toggleSearchButton.setToggled(shouldEnable); | 112 if (this.isInInspectElementMode()) |
| 113 mode = DOMAgent.InspectMode.None; |
| 114 else |
| 115 mode = WebInspector.moduleSetting("showUAShadowDOM").get() ? DOMAgen
t.InspectMode.SearchForUAShadowDOM : DOMAgent.InspectMode.SearchForNode; |
| 104 | 116 |
| 105 for (var domModel of WebInspector.DOMModel.instances()) { | 117 this._setMode(mode); |
| 106 var mode; | 118 }, |
| 107 if (!shouldEnable) | |
| 108 mode = DOMAgent.InspectMode.None; | |
| 109 else if (WebInspector.moduleSetting("showUAShadowDOM").get()) | |
| 110 mode = DOMAgent.InspectMode.SearchForUAShadowDOM; | |
| 111 else | |
| 112 mode = DOMAgent.InspectMode.SearchForNode; | |
| 113 | 119 |
| 120 /** |
| 121 * @param {!DOMAgent.InspectMode} mode |
| 122 */ |
| 123 _setMode: function(mode) |
| 124 { |
| 125 this._mode = mode; |
| 126 for (var domModel of WebInspector.DOMModel.instances()) |
| 114 domModel.setInspectMode(mode); | 127 domModel.setInspectMode(mode); |
| 128 |
| 129 if (this._layoutEditorButton) { |
| 130 this._layoutEditorButton.setEnabled(!this.isInInspectElementMode()); |
| 131 this._layoutEditorButton.setToggled(this.isInLayoutEditorMode()); |
| 115 } | 132 } |
| 133 |
| 134 this._toggleSearchButton.setEnabled(!this.isInLayoutEditorMode()); |
| 135 this._toggleSearchButton.setToggled(this.isInInspectElementMode()); |
| 116 }, | 136 }, |
| 117 | 137 |
| 118 _suspendStateChanged: function() | 138 _suspendStateChanged: function() |
| 119 { | 139 { |
| 120 if (WebInspector.targetManager.allTargetsSuspended()) | 140 if (!WebInspector.targetManager.allTargetsSuspended()) |
| 121 this._toggleSearchButton.setToggled(false); | 141 return; |
| 142 |
| 143 this._mode = DOMAgent.InspectMode.None; |
| 144 this._toggleSearchButton.setToggled(false); |
| 145 if (this._layoutEditorButton) |
| 146 this._layoutEditorButton.setToggled(false); |
| 122 } | 147 } |
| 123 } | 148 } |
| 124 | 149 |
| 125 /** | 150 /** |
| 126 * @constructor | 151 * @constructor |
| 127 * @implements {WebInspector.ActionDelegate} | 152 * @implements {WebInspector.ActionDelegate} |
| 128 */ | 153 */ |
| 129 WebInspector.InspectElementModeController.ToggleSearchActionDelegate = function(
) | 154 WebInspector.InspectElementModeController.ToggleSearchActionDelegate = function(
) |
| 130 { | 155 { |
| 131 } | 156 } |
| 132 | 157 |
| 133 WebInspector.InspectElementModeController.ToggleSearchActionDelegate.prototype =
{ | 158 WebInspector.InspectElementModeController.ToggleSearchActionDelegate.prototype =
{ |
| 134 /** | 159 /** |
| 135 * @override | 160 * @override |
| 136 * @param {!WebInspector.Context} context | 161 * @param {!WebInspector.Context} context |
| 137 * @param {string} actionId | 162 * @param {string} actionId |
| 138 */ | 163 */ |
| 139 handleAction: function(context, actionId) | 164 handleAction: function(context, actionId) |
| 140 { | 165 { |
| 141 if (!WebInspector.inspectElementModeController) | 166 if (!WebInspector.inspectElementModeController) |
| 142 return; | 167 return; |
| 143 WebInspector.inspectElementModeController._toggleSearch(); | 168 WebInspector.inspectElementModeController._toggleInspectMode(); |
| 144 } | 169 } |
| 145 } | 170 } |
| 146 | 171 |
| 147 /** | 172 /** |
| 148 * @constructor | 173 * @constructor |
| 149 * @implements {WebInspector.ToolbarItem.Provider} | 174 * @implements {WebInspector.ToolbarItem.Provider} |
| 150 */ | 175 */ |
| 151 WebInspector.InspectElementModeController.ToggleButtonProvider = function() | 176 WebInspector.InspectElementModeController.ToggleButtonProvider = function() |
| 152 { | 177 { |
| 153 } | 178 } |
| 154 | 179 |
| 155 WebInspector.InspectElementModeController.ToggleButtonProvider.prototype = { | 180 WebInspector.InspectElementModeController.ToggleButtonProvider.prototype = { |
| 156 /** | 181 /** |
| 157 * @override | 182 * @override |
| 158 * @return {?WebInspector.ToolbarItem} | 183 * @return {?WebInspector.ToolbarItem} |
| 159 */ | 184 */ |
| 160 item: function() | 185 item: function() |
| 161 { | 186 { |
| 162 if (!WebInspector.inspectElementModeController) | 187 if (!WebInspector.inspectElementModeController) |
| 163 return null; | 188 return null; |
| 164 | 189 |
| 165 return WebInspector.inspectElementModeController._toggleSearchButton; | 190 return WebInspector.inspectElementModeController._toggleSearchButton; |
| 166 } | 191 } |
| 167 } | 192 } |
| 168 | 193 |
| 194 /** |
| 195 * @constructor |
| 196 * @implements {WebInspector.ToolbarItem.Provider} |
| 197 */ |
| 198 WebInspector.InspectElementModeController.LayoutEditorButtonProvider = function(
) |
| 199 { |
| 200 } |
| 201 |
| 202 WebInspector.InspectElementModeController.LayoutEditorButtonProvider.prototype =
{ |
| 203 /** |
| 204 * @override |
| 205 * @return {?WebInspector.ToolbarItem} |
| 206 */ |
| 207 item: function() |
| 208 { |
| 209 if (!WebInspector.inspectElementModeController) |
| 210 return null; |
| 211 |
| 212 return WebInspector.inspectElementModeController._layoutEditorButton; |
| 213 } |
| 214 } |
| 215 |
| 169 /** @type {?WebInspector.InspectElementModeController} */ | 216 /** @type {?WebInspector.InspectElementModeController} */ |
| 170 WebInspector.inspectElementModeController = null; | 217 WebInspector.inspectElementModeController = null; |
| OLD | NEW |