| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | |
| 5 /** | 4 /** |
| 6 * @constructor | |
| 7 * @implements {WebInspector.App} | 5 * @implements {WebInspector.App} |
| 8 * @implements {WebInspector.TargetManager.Observer} | 6 * @implements {WebInspector.TargetManager.Observer} |
| 7 * @unrestricted |
| 9 */ | 8 */ |
| 10 WebInspector.ScreencastApp = function() | 9 WebInspector.ScreencastApp = class { |
| 11 { | 10 constructor() { |
| 12 this._enabledSetting = WebInspector.settings.createSetting("screencastEnable
d", true); | 11 this._enabledSetting = WebInspector.settings.createSetting('screencastEnable
d', true); |
| 13 this._toggleButton = new WebInspector.ToolbarToggle(WebInspector.UIString("T
oggle screencast"), "phone-toolbar-item"); | 12 this._toggleButton = |
| 13 new WebInspector.ToolbarToggle(WebInspector.UIString('Toggle screencast'
), 'phone-toolbar-item'); |
| 14 this._toggleButton.setToggled(this._enabledSetting.get()); | 14 this._toggleButton.setToggled(this._enabledSetting.get()); |
| 15 this._toggleButton.addEventListener("click", this._toggleButtonClicked, this
); | 15 this._toggleButton.addEventListener('click', this._toggleButtonClicked, this
); |
| 16 WebInspector.targetManager.observeTargets(this); | 16 WebInspector.targetManager.observeTargets(this); |
| 17 } |
| 18 |
| 19 /** |
| 20 * @return {!WebInspector.ScreencastApp} |
| 21 */ |
| 22 static _instance() { |
| 23 if (!WebInspector.ScreencastApp._appInstance) |
| 24 WebInspector.ScreencastApp._appInstance = new WebInspector.ScreencastApp()
; |
| 25 return WebInspector.ScreencastApp._appInstance; |
| 26 } |
| 27 |
| 28 /** |
| 29 * @override |
| 30 * @param {!Document} document |
| 31 */ |
| 32 presentUI(document) { |
| 33 var rootView = new WebInspector.RootView(); |
| 34 |
| 35 this._rootSplitWidget = |
| 36 new WebInspector.SplitWidget(false, true, 'InspectorView.screencastSplit
ViewState', 300, 300); |
| 37 this._rootSplitWidget.setVertical(true); |
| 38 this._rootSplitWidget.setSecondIsSidebar(true); |
| 39 this._rootSplitWidget.show(rootView.element); |
| 40 this._rootSplitWidget.hideMain(); |
| 41 |
| 42 this._rootSplitWidget.setSidebarWidget(WebInspector.inspectorView); |
| 43 rootView.attachToDocument(document); |
| 44 } |
| 45 |
| 46 /** |
| 47 * @override |
| 48 * @param {!WebInspector.Target} target |
| 49 */ |
| 50 targetAdded(target) { |
| 51 if (this._target) |
| 52 return; |
| 53 this._target = target; |
| 54 |
| 55 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target); |
| 56 if (resourceTreeModel) { |
| 57 this._screencastView = new WebInspector.ScreencastView(target, resourceTre
eModel); |
| 58 this._rootSplitWidget.setMainWidget(this._screencastView); |
| 59 this._screencastView.initialize(); |
| 60 } else { |
| 61 this._toggleButton.setEnabled(false); |
| 62 } |
| 63 this._onScreencastEnabledChanged(); |
| 64 } |
| 65 |
| 66 /** |
| 67 * @override |
| 68 * @param {!WebInspector.Target} target |
| 69 */ |
| 70 targetRemoved(target) { |
| 71 if (this._target === target) { |
| 72 delete this._target; |
| 73 if (!this._screencastView) |
| 74 return; |
| 75 this._toggleButton.setEnabled(false); |
| 76 this._screencastView.detach(); |
| 77 delete this._screencastView; |
| 78 this._onScreencastEnabledChanged(); |
| 79 } |
| 80 } |
| 81 |
| 82 _toggleButtonClicked() { |
| 83 var enabled = !this._toggleButton.toggled(); |
| 84 this._enabledSetting.set(enabled); |
| 85 this._onScreencastEnabledChanged(); |
| 86 } |
| 87 |
| 88 _onScreencastEnabledChanged() { |
| 89 if (!this._rootSplitWidget) |
| 90 return; |
| 91 var enabled = this._enabledSetting.get() && this._screencastView; |
| 92 this._toggleButton.setToggled(enabled); |
| 93 if (enabled) |
| 94 this._rootSplitWidget.showBoth(); |
| 95 else |
| 96 this._rootSplitWidget.hideMain(); |
| 97 } |
| 17 }; | 98 }; |
| 18 | 99 |
| 19 WebInspector.ScreencastApp.prototype = { | |
| 20 /** | |
| 21 * @override | |
| 22 * @param {!Document} document | |
| 23 */ | |
| 24 presentUI: function(document) | |
| 25 { | |
| 26 var rootView = new WebInspector.RootView(); | |
| 27 | |
| 28 this._rootSplitWidget = new WebInspector.SplitWidget(false, true, "Inspe
ctorView.screencastSplitViewState", 300, 300); | |
| 29 this._rootSplitWidget.setVertical(true); | |
| 30 this._rootSplitWidget.setSecondIsSidebar(true); | |
| 31 this._rootSplitWidget.show(rootView.element); | |
| 32 this._rootSplitWidget.hideMain(); | |
| 33 | |
| 34 this._rootSplitWidget.setSidebarWidget(WebInspector.inspectorView); | |
| 35 rootView.attachToDocument(document); | |
| 36 }, | |
| 37 | |
| 38 /** | |
| 39 * @override | |
| 40 * @param {!WebInspector.Target} target | |
| 41 */ | |
| 42 targetAdded: function(target) | |
| 43 { | |
| 44 if (this._target) | |
| 45 return; | |
| 46 this._target = target; | |
| 47 | |
| 48 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target
); | |
| 49 if (resourceTreeModel) { | |
| 50 this._screencastView = new WebInspector.ScreencastView(target, resou
rceTreeModel); | |
| 51 this._rootSplitWidget.setMainWidget(this._screencastView); | |
| 52 this._screencastView.initialize(); | |
| 53 } else { | |
| 54 this._toggleButton.setEnabled(false); | |
| 55 } | |
| 56 this._onScreencastEnabledChanged(); | |
| 57 }, | |
| 58 | |
| 59 /** | |
| 60 * @override | |
| 61 * @param {!WebInspector.Target} target | |
| 62 */ | |
| 63 targetRemoved: function(target) | |
| 64 { | |
| 65 if (this._target === target) { | |
| 66 delete this._target; | |
| 67 if (!this._screencastView) | |
| 68 return; | |
| 69 this._toggleButton.setEnabled(false); | |
| 70 this._screencastView.detach(); | |
| 71 delete this._screencastView; | |
| 72 this._onScreencastEnabledChanged(); | |
| 73 } | |
| 74 }, | |
| 75 | |
| 76 _toggleButtonClicked: function() | |
| 77 { | |
| 78 var enabled = !this._toggleButton.toggled(); | |
| 79 this._enabledSetting.set(enabled); | |
| 80 this._onScreencastEnabledChanged(); | |
| 81 }, | |
| 82 | |
| 83 _onScreencastEnabledChanged: function() | |
| 84 { | |
| 85 if (!this._rootSplitWidget) | |
| 86 return; | |
| 87 var enabled = this._enabledSetting.get() && this._screencastView; | |
| 88 this._toggleButton.setToggled(enabled); | |
| 89 if (enabled) | |
| 90 this._rootSplitWidget.showBoth(); | |
| 91 else | |
| 92 this._rootSplitWidget.hideMain(); | |
| 93 } | |
| 94 }; | |
| 95 | |
| 96 | |
| 97 /** @type {!WebInspector.ScreencastApp} */ | 100 /** @type {!WebInspector.ScreencastApp} */ |
| 98 WebInspector.ScreencastApp._appInstance; | 101 WebInspector.ScreencastApp._appInstance; |
| 99 | 102 |
| 103 |
| 100 /** | 104 /** |
| 101 * @return {!WebInspector.ScreencastApp} | 105 * @implements {WebInspector.ToolbarItem.Provider} |
| 106 * @unrestricted |
| 102 */ | 107 */ |
| 103 WebInspector.ScreencastApp._instance = function() | 108 WebInspector.ScreencastApp.ToolbarButtonProvider = class { |
| 104 { | 109 /** |
| 105 if (!WebInspector.ScreencastApp._appInstance) | 110 * @override |
| 106 WebInspector.ScreencastApp._appInstance = new WebInspector.ScreencastApp
(); | 111 * @return {?WebInspector.ToolbarItem} |
| 107 return WebInspector.ScreencastApp._appInstance; | 112 */ |
| 113 item() { |
| 114 return WebInspector.ScreencastApp._instance()._toggleButton; |
| 115 } |
| 108 }; | 116 }; |
| 109 | 117 |
| 110 /** | 118 /** |
| 111 * @constructor | 119 * @implements {WebInspector.AppProvider} |
| 112 * @implements {WebInspector.ToolbarItem.Provider} | 120 * @unrestricted |
| 113 */ | 121 */ |
| 114 WebInspector.ScreencastApp.ToolbarButtonProvider = function() | 122 WebInspector.ScreencastAppProvider = class { |
| 115 { | 123 /** |
| 124 * @override |
| 125 * @return {!WebInspector.App} |
| 126 */ |
| 127 createApp() { |
| 128 return WebInspector.ScreencastApp._instance(); |
| 129 } |
| 116 }; | 130 }; |
| 117 | |
| 118 WebInspector.ScreencastApp.ToolbarButtonProvider.prototype = { | |
| 119 /** | |
| 120 * @override | |
| 121 * @return {?WebInspector.ToolbarItem} | |
| 122 */ | |
| 123 item: function() | |
| 124 { | |
| 125 return WebInspector.ScreencastApp._instance()._toggleButton; | |
| 126 } | |
| 127 }; | |
| 128 | |
| 129 /** | |
| 130 * @constructor | |
| 131 * @implements {WebInspector.AppProvider} | |
| 132 */ | |
| 133 WebInspector.ScreencastAppProvider = function() | |
| 134 { | |
| 135 }; | |
| 136 | |
| 137 WebInspector.ScreencastAppProvider.prototype = { | |
| 138 /** | |
| 139 * @override | |
| 140 * @return {!WebInspector.App} | |
| 141 */ | |
| 142 createApp: function() | |
| 143 { | |
| 144 return WebInspector.ScreencastApp._instance(); | |
| 145 } | |
| 146 }; | |
| OLD | NEW |