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
3 // found in the LICENSE file.
7 * @implements {WebInspector.App}
8 * @implements {WebInspector.TargetManager.Observer}
10 WebInspector
.ScreencastApp = function()
12 this._enabledSetting
= WebInspector
.settings
.createSetting("screencastEnabled", true);
13 this._toggleButton
= new WebInspector
.ToolbarButton(WebInspector
.UIString("Toggle screencast"), "screencast-toolbar-item");
14 this._toggleButton
.setToggled(this._enabledSetting
.get());
15 this._toggleButton
.addEventListener("click", this._toggleButtonClicked
, this);
16 WebInspector
.targetManager
.observeTargets(this);
19 WebInspector
.ScreencastApp
.prototype = {
21 * @param {!Document} document
24 presentUI: function(document
)
26 var rootView
= new WebInspector
.RootView();
28 this._rootSplitWidget
= new WebInspector
.SplitWidget(false, true, "InspectorView.screencastSplitViewState", 300, 300);
29 this._rootSplitWidget
.setVertical(true);
30 this._rootSplitWidget
.setSecondIsSidebar(true);
31 this._rootSplitWidget
.show(rootView
.element
);
32 this._rootSplitWidget
.hideMain();
34 this._rootSplitWidget
.setSidebarWidget(WebInspector
.inspectorView
);
35 WebInspector
.inspectorView
.showInitialPanel();
36 rootView
.attachToDocument(document
);
41 * @param {!WebInspector.Target} target
43 targetAdded: function(target
)
47 this._target
= target
;
48 if (target
.hasCapability(WebInspector
.Target
.Capabilities
.CanScreencast
)) {
49 this._screencastView
= new WebInspector
.ScreencastView(target
);
50 this._rootSplitWidget
.setMainWidget(this._screencastView
);
51 this._screencastView
.initialize();
53 this._toggleButton
.setEnabled(false);
55 this._onScreencastEnabledChanged();
60 * @param {!WebInspector.Target} target
62 targetRemoved: function(target
)
64 if (this._target
=== target
) {
66 if (!this._screencastView
)
68 this._toggleButton
.setEnabled(false);
69 this._screencastView
.detach();
70 delete this._screencastView
;
71 this._onScreencastEnabledChanged();
75 _toggleButtonClicked: function()
77 var enabled
= !this._toggleButton
.toggled();
78 this._enabledSetting
.set(enabled
);
79 this._onScreencastEnabledChanged();
82 _onScreencastEnabledChanged: function()
84 if (!this._rootSplitWidget
)
86 var enabled
= this._enabledSetting
.get() && this._screencastView
;
87 this._toggleButton
.setToggled(enabled
);
89 this._rootSplitWidget
.showBoth();
91 this._rootSplitWidget
.hideMain();
96 /** @type {!WebInspector.ScreencastApp} */
97 WebInspector
.ScreencastApp
._appInstance
;
100 * @return {!WebInspector.ScreencastApp}
102 WebInspector
.ScreencastApp
._instance = function()
104 if (!WebInspector
.ScreencastApp
._appInstance
)
105 WebInspector
.ScreencastApp
._appInstance
= new WebInspector
.ScreencastApp();
106 return WebInspector
.ScreencastApp
._appInstance
;
111 * @implements {WebInspector.ToolbarItem.Provider}
113 WebInspector
.ScreencastApp
.ToolbarButtonProvider = function()
117 WebInspector
.ScreencastApp
.ToolbarButtonProvider
.prototype = {
120 * @return {?WebInspector.ToolbarItem}
124 return WebInspector
.ScreencastApp
._instance()._toggleButton
;
130 * @implements {WebInspector.AppProvider}
132 WebInspector
.ScreencastAppProvider = function()
136 WebInspector
.ScreencastAppProvider
.prototype = {
139 * @return {!WebInspector.App}
141 createApp: function()
143 return WebInspector
.ScreencastApp
._instance();