1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @implements {Common.App}
* @implements {SDK.TargetManager.Observer}
* @unrestricted
*/
Screencast.ScreencastApp = class {
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.addEventListener(UI.ToolbarButton.Events.Click, this._toggleButtonClicked, this);
SDK.targetManager.observeTargets(this);
}
/**
* @return {!Screencast.ScreencastApp}
*/
static _instance() {
if (!Screencast.ScreencastApp._appInstance)
Screencast.ScreencastApp._appInstance = new Screencast.ScreencastApp();
return Screencast.ScreencastApp._appInstance;
}
/**
* @override
* @param {!Document} document
*/
presentUI(document) {
var 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);
rootView.attachToDocument(document);
rootView.focus();
}
/**
* @override
* @param {!SDK.Target} target
*/
targetAdded(target) {
if (this._target)
return;
this._target = target;
var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target);
if (resourceTreeModel) {
this._screencastView = new Screencast.ScreencastView(target, resourceTreeModel);
this._rootSplitWidget.setMainWidget(this._screencastView);
this._screencastView.initialize();
} else {
this._toggleButton.setEnabled(false);
}
this._onScreencastEnabledChanged();
}
/**
* @override
* @param {!SDK.Target} target
*/
targetRemoved(target) {
if (this._target === target) {
delete this._target;
if (!this._screencastView)
return;
this._toggleButton.setEnabled(false);
this._screencastView.detach();
delete this._screencastView;
this._onScreencastEnabledChanged();
}
}
_toggleButtonClicked() {
var enabled = !this._toggleButton.toggled();
this._enabledSetting.set(enabled);
this._onScreencastEnabledChanged();
}
_onScreencastEnabledChanged() {
if (!this._rootSplitWidget)
return;
var enabled = this._enabledSetting.get() && this._screencastView;
this._toggleButton.setToggled(enabled);
if (enabled)
this._rootSplitWidget.showBoth();
else
this._rootSplitWidget.hideMain();
}
};
/** @type {!Screencast.ScreencastApp} */
Screencast.ScreencastApp._appInstance;
/**
* @implements {UI.ToolbarItem.Provider}
* @unrestricted
*/
Screencast.ScreencastApp.ToolbarButtonProvider = class {
/**
* @override
* @return {?UI.ToolbarItem}
*/
item() {
return Screencast.ScreencastApp._instance()._toggleButton;
}
};
/**
* @implements {Common.AppProvider}
* @unrestricted
*/
Screencast.ScreencastAppProvider = class {
/**
* @override
* @return {!Common.App}
*/
createApp() {
return Screencast.ScreencastApp._instance();
}
};
|