ScreencastApp.js 2.5 KB

1234567891011121314
  1. export default class ScreencastApp{constructor(){this._enabledSetting=Common.settings.createSetting('screencastEnabled',true);this._toggleButton=new UI.ToolbarToggle(Common.UIString('Toggle screencast'),'largeicon-phone');this._toggleButton.setToggled(this._enabledSetting.get());this._toggleButton.setEnabled(false);this._toggleButton.addEventListener(UI.ToolbarButton.Events.Click,this._toggleButtonClicked,this);SDK.targetManager.observeModels(SDK.ScreenCaptureModel,this);}
  2. static _instance(){if(!Screencast.ScreencastApp._appInstance){Screencast.ScreencastApp._appInstance=new Screencast.ScreencastApp();}
  3. return Screencast.ScreencastApp._appInstance;}
  4. presentUI(document){const rootView=new UI.RootView();this._rootSplitWidget=new UI.SplitWidget(false,true,'InspectorView.screencastSplitViewState',300,300);this._rootSplitWidget.setVertical(true);this._rootSplitWidget.setSecondIsSidebar(true);this._rootSplitWidget.show(rootView.element);this._rootSplitWidget.hideMain();this._rootSplitWidget.setSidebarWidget(UI.inspectorView);UI.inspectorView.setOwnerSplit(this._rootSplitWidget);rootView.attachToDocument(document);rootView.focus();}
  5. modelAdded(screenCaptureModel){if(this._screenCaptureModel){return;}
  6. this._screenCaptureModel=screenCaptureModel;this._toggleButton.setEnabled(true);this._screencastView=new Screencast.ScreencastView(screenCaptureModel);this._rootSplitWidget.setMainWidget(this._screencastView);this._screencastView.initialize();this._onScreencastEnabledChanged();}
  7. modelRemoved(screenCaptureModel){if(this._screenCaptureModel!==screenCaptureModel){return;}
  8. delete this._screenCaptureModel;this._toggleButton.setEnabled(false);this._screencastView.detach();delete this._screencastView;this._onScreencastEnabledChanged();}
  9. _toggleButtonClicked(){const enabled=!this._toggleButton.toggled();this._enabledSetting.set(enabled);this._onScreencastEnabledChanged();}
  10. _onScreencastEnabledChanged(){if(!this._rootSplitWidget){return;}
  11. const enabled=this._enabledSetting.get()&&this._screencastView;this._toggleButton.setToggled(enabled);if(enabled){this._rootSplitWidget.showBoth();}else{this._rootSplitWidget.hideMain();}}}
  12. export class ToolbarButtonProvider{item(){return Screencast.ScreencastApp._instance()._toggleButton;}}
  13. export class ScreencastAppProvider{createApp(){return Screencast.ScreencastApp._instance();}}
  14. self.Screencast=self.Screencast||{};Screencast=Screencast||{};Screencast.ScreencastApp=ScreencastApp;Screencast.ScreencastApp.ToolbarButtonProvider=ToolbarButtonProvider;Screencast.ScreencastApp._appInstance;Screencast.ScreencastAppProvider=ScreencastAppProvider;