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 {SDK.SDKModelObserver<!SDK.DOMModel>} | 29 * @implements {SDK.SDKModelObserver<!SDK.OverlayModel>} |
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 this._mode = Protocol.DOM.InspectMode.None; | 35 this._mode = Protocol.Overlay.InspectMode.None; |
36 SDK.targetManager.addEventListener(SDK.TargetManager.Events.SuspendStateChan
ged, this._suspendStateChanged, this); | 36 SDK.targetManager.addEventListener(SDK.TargetManager.Events.SuspendStateChan
ged, this._suspendStateChanged, this); |
37 SDK.targetManager.observeModels(SDK.DOMModel, this); | 37 SDK.targetManager.observeModels(SDK.OverlayModel, this); |
38 } | 38 } |
39 | 39 |
40 /** | 40 /** |
41 * @override | 41 * @override |
42 * @param {!SDK.DOMModel} domModel | 42 * @param {!SDK.OverlayModel} overlayModel |
43 */ | 43 */ |
44 modelAdded(domModel) { | 44 modelAdded(overlayModel) { |
45 // When DevTools are opening in the inspect element mode, the first target c
omes in | 45 // When DevTools are opening in the inspect element mode, the first target c
omes in |
46 // much later than the InspectorFrontendAPI.enterInspectElementMode event. | 46 // much later than the InspectorFrontendAPI.enterInspectElementMode event. |
47 if (this._mode === Protocol.DOM.InspectMode.None) | 47 if (this._mode === Protocol.Overlay.InspectMode.None) |
48 return; | 48 return; |
49 domModel.setInspectMode(this._mode); | 49 overlayModel.setInspectMode(this._mode); |
50 } | 50 } |
51 | 51 |
52 /** | 52 /** |
53 * @override | 53 * @override |
54 * @param {!SDK.DOMModel} domModel | 54 * @param {!SDK.OverlayModel} overlayModel |
55 */ | 55 */ |
56 modelRemoved(domModel) { | 56 modelRemoved(overlayModel) { |
57 } | 57 } |
58 | 58 |
59 /** | 59 /** |
60 * @return {boolean} | 60 * @return {boolean} |
61 */ | 61 */ |
62 isInInspectElementMode() { | 62 isInInspectElementMode() { |
63 return this._mode === Protocol.DOM.InspectMode.SearchForNode || | 63 return this._mode === Protocol.Overlay.InspectMode.SearchForNode || |
64 this._mode === Protocol.DOM.InspectMode.SearchForUAShadowDOM; | 64 this._mode === Protocol.Overlay.InspectMode.SearchForUAShadowDOM; |
65 } | 65 } |
66 | 66 |
67 stopInspection() { | 67 stopInspection() { |
68 if (this._mode && this._mode !== Protocol.DOM.InspectMode.None) | 68 if (this._mode && this._mode !== Protocol.Overlay.InspectMode.None) |
69 this._toggleInspectMode(); | 69 this._toggleInspectMode(); |
70 } | 70 } |
71 | 71 |
72 _toggleInspectMode() { | 72 _toggleInspectMode() { |
73 if (SDK.targetManager.allTargetsSuspended()) | 73 if (SDK.targetManager.allTargetsSuspended()) |
74 return; | 74 return; |
75 | 75 |
76 var mode; | 76 var mode; |
77 if (this.isInInspectElementMode()) { | 77 if (this.isInInspectElementMode()) { |
78 mode = Protocol.DOM.InspectMode.None; | 78 mode = Protocol.Overlay.InspectMode.None; |
79 } else { | 79 } else { |
80 mode = Common.moduleSetting('showUAShadowDOM').get() ? Protocol.DOM.Inspec
tMode.SearchForUAShadowDOM : | 80 mode = Common.moduleSetting('showUAShadowDOM').get() ? Protocol.Overlay.In
spectMode.SearchForUAShadowDOM : |
81 Protocol.DOM.Inspec
tMode.SearchForNode; | 81 Protocol.Overlay.In
spectMode.SearchForNode; |
82 } | 82 } |
83 | 83 |
84 this._setMode(mode); | 84 this._setMode(mode); |
85 } | 85 } |
86 | 86 |
87 /** | 87 /** |
88 * @param {!Protocol.DOM.InspectMode} mode | 88 * @param {!Protocol.Overlay.InspectMode} mode |
89 */ | 89 */ |
90 _setMode(mode) { | 90 _setMode(mode) { |
91 this._mode = mode; | 91 this._mode = mode; |
92 for (var domModel of SDK.targetManager.models(SDK.DOMModel)) | 92 for (var overlayModel of SDK.targetManager.models(SDK.OverlayModel)) |
93 domModel.setInspectMode(mode); | 93 overlayModel.setInspectMode(mode); |
94 this._toggleSearchAction.setToggled(this.isInInspectElementMode()); | 94 this._toggleSearchAction.setToggled(this.isInInspectElementMode()); |
95 } | 95 } |
96 | 96 |
97 _suspendStateChanged() { | 97 _suspendStateChanged() { |
98 if (!SDK.targetManager.allTargetsSuspended()) | 98 if (!SDK.targetManager.allTargetsSuspended()) |
99 return; | 99 return; |
100 | 100 |
101 this._mode = Protocol.DOM.InspectMode.None; | 101 this._mode = Protocol.Overlay.InspectMode.None; |
102 this._toggleSearchAction.setToggled(false); | 102 this._toggleSearchAction.setToggled(false); |
103 } | 103 } |
104 }; | 104 }; |
105 | 105 |
106 /** | 106 /** |
107 * @implements {UI.ActionDelegate} | 107 * @implements {UI.ActionDelegate} |
108 * @unrestricted | 108 * @unrestricted |
109 */ | 109 */ |
110 Elements.InspectElementModeController.ToggleSearchActionDelegate = class { | 110 Elements.InspectElementModeController.ToggleSearchActionDelegate = class { |
111 /** | 111 /** |
112 * @override | 112 * @override |
113 * @param {!UI.Context} context | 113 * @param {!UI.Context} context |
114 * @param {string} actionId | 114 * @param {string} actionId |
115 * @return {boolean} | 115 * @return {boolean} |
116 */ | 116 */ |
117 handleAction(context, actionId) { | 117 handleAction(context, actionId) { |
118 if (!Elements.inspectElementModeController) | 118 if (!Elements.inspectElementModeController) |
119 return false; | 119 return false; |
120 Elements.inspectElementModeController._toggleInspectMode(); | 120 Elements.inspectElementModeController._toggleInspectMode(); |
121 return true; | 121 return true; |
122 } | 122 } |
123 }; | 123 }; |
124 | 124 |
125 /** @type {?Elements.InspectElementModeController} */ | 125 /** @type {?Elements.InspectElementModeController} */ |
126 Elements.inspectElementModeController = | 126 Elements.inspectElementModeController = |
127 Runtime.queryParam('isSharedWorker') ? null : new Elements.InspectElementMod
eController(); | 127 Runtime.queryParam('isSharedWorker') ? null : new Elements.InspectElementMod
eController(); |
OLD | NEW |