| 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 /** | 4 /** |
| 5 * @implements {Common.App} | 5 * @implements {Common.App} |
| 6 * @implements {SDK.TargetManager.Observer} | 6 * @implements {SDK.SDKModelObserver<!SDK.ScreenCaptureModel>} |
| 7 * @unrestricted | 7 * @unrestricted |
| 8 */ | 8 */ |
| 9 Screencast.ScreencastApp = class { | 9 Screencast.ScreencastApp = class { |
| 10 constructor() { | 10 constructor() { |
| 11 this._enabledSetting = Common.settings.createSetting('screencastEnabled', tr
ue); | 11 this._enabledSetting = Common.settings.createSetting('screencastEnabled', tr
ue); |
| 12 this._toggleButton = new UI.ToolbarToggle(Common.UIString('Toggle screencast
'), 'largeicon-phone'); | 12 this._toggleButton = new UI.ToolbarToggle(Common.UIString('Toggle screencast
'), 'largeicon-phone'); |
| 13 this._toggleButton.setToggled(this._enabledSetting.get()); | 13 this._toggleButton.setToggled(this._enabledSetting.get()); |
| 14 this._toggleButton.setEnabled(false); |
| 14 this._toggleButton.addEventListener(UI.ToolbarButton.Events.Click, this._tog
gleButtonClicked, this); | 15 this._toggleButton.addEventListener(UI.ToolbarButton.Events.Click, this._tog
gleButtonClicked, this); |
| 15 SDK.targetManager.observeTargets(this); | 16 SDK.targetManager.observeModels(SDK.ScreenCaptureModel, this); |
| 16 } | 17 } |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * @return {!Screencast.ScreencastApp} | 20 * @return {!Screencast.ScreencastApp} |
| 20 */ | 21 */ |
| 21 static _instance() { | 22 static _instance() { |
| 22 if (!Screencast.ScreencastApp._appInstance) | 23 if (!Screencast.ScreencastApp._appInstance) |
| 23 Screencast.ScreencastApp._appInstance = new Screencast.ScreencastApp(); | 24 Screencast.ScreencastApp._appInstance = new Screencast.ScreencastApp(); |
| 24 return Screencast.ScreencastApp._appInstance; | 25 return Screencast.ScreencastApp._appInstance; |
| 25 } | 26 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 this._rootSplitWidget.show(rootView.element); | 38 this._rootSplitWidget.show(rootView.element); |
| 38 this._rootSplitWidget.hideMain(); | 39 this._rootSplitWidget.hideMain(); |
| 39 | 40 |
| 40 this._rootSplitWidget.setSidebarWidget(UI.inspectorView); | 41 this._rootSplitWidget.setSidebarWidget(UI.inspectorView); |
| 41 rootView.attachToDocument(document); | 42 rootView.attachToDocument(document); |
| 42 rootView.focus(); | 43 rootView.focus(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 /** | 46 /** |
| 46 * @override | 47 * @override |
| 47 * @param {!SDK.Target} target | 48 * @param {!SDK.ScreenCaptureModel} screenCaptureModel |
| 48 */ | 49 */ |
| 49 targetAdded(target) { | 50 modelAdded(screenCaptureModel) { |
| 50 if (this._target) | 51 if (this._screenCaptureModel) |
| 51 return; | 52 return; |
| 52 this._target = target; | 53 this._screenCaptureModel = screenCaptureModel; |
| 53 | 54 this._toggleButton.setEnabled(true); |
| 54 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target); | 55 this._screencastView = new Screencast.ScreencastView(screenCaptureModel); |
| 55 if (resourceTreeModel) { | 56 this._rootSplitWidget.setMainWidget(this._screencastView); |
| 56 this._screencastView = new Screencast.ScreencastView(target, resourceTreeM
odel); | 57 this._screencastView.initialize(); |
| 57 this._rootSplitWidget.setMainWidget(this._screencastView); | |
| 58 this._screencastView.initialize(); | |
| 59 } else { | |
| 60 this._toggleButton.setEnabled(false); | |
| 61 } | |
| 62 this._onScreencastEnabledChanged(); | 58 this._onScreencastEnabledChanged(); |
| 63 } | 59 } |
| 64 | 60 |
| 65 /** | 61 /** |
| 66 * @override | 62 * @override |
| 67 * @param {!SDK.Target} target | 63 * @param {!SDK.ScreenCaptureModel} screenCaptureModel |
| 68 */ | 64 */ |
| 69 targetRemoved(target) { | 65 modelRemoved(screenCaptureModel) { |
| 70 if (this._target === target) { | 66 if (this._screenCaptureModel !== screenCaptureModel) |
| 71 delete this._target; | 67 return; |
| 72 if (!this._screencastView) | 68 delete this._screenCaptureModel; |
| 73 return; | 69 this._toggleButton.setEnabled(false); |
| 74 this._toggleButton.setEnabled(false); | 70 this._screencastView.detach(); |
| 75 this._screencastView.detach(); | 71 delete this._screencastView; |
| 76 delete this._screencastView; | 72 this._onScreencastEnabledChanged(); |
| 77 this._onScreencastEnabledChanged(); | |
| 78 } | |
| 79 } | 73 } |
| 80 | 74 |
| 81 _toggleButtonClicked() { | 75 _toggleButtonClicked() { |
| 82 var enabled = !this._toggleButton.toggled(); | 76 var enabled = !this._toggleButton.toggled(); |
| 83 this._enabledSetting.set(enabled); | 77 this._enabledSetting.set(enabled); |
| 84 this._onScreencastEnabledChanged(); | 78 this._onScreencastEnabledChanged(); |
| 85 } | 79 } |
| 86 | 80 |
| 87 _onScreencastEnabledChanged() { | 81 _onScreencastEnabledChanged() { |
| 88 if (!this._rootSplitWidget) | 82 if (!this._rootSplitWidget) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 */ | 114 */ |
| 121 Screencast.ScreencastAppProvider = class { | 115 Screencast.ScreencastAppProvider = class { |
| 122 /** | 116 /** |
| 123 * @override | 117 * @override |
| 124 * @return {!Common.App} | 118 * @return {!Common.App} |
| 125 */ | 119 */ |
| 126 createApp() { | 120 createApp() { |
| 127 return Screencast.ScreencastApp._instance(); | 121 return Screencast.ScreencastApp._instance(); |
| 128 } | 122 } |
| 129 }; | 123 }; |
| OLD | NEW |