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. 4 5 /** 6 * @constructor 7 * @extends {WebInspector.App} 8 * @implements {WebInspector.TargetManager.Observer} 9 */ 10 WebInspector.ScreencastApp = function() 11 { 12 WebInspector.App.call(this); 13 14 var lastScreencastState = WebInspector.settings.createSetting("lastScreencastState", "left"); 15 this._currentScreencastState = WebInspector.settings.createSetting("currentScreencastState", "disabled"); 16 this._toggleScreencastButton = new WebInspector.StatusBarStatesSettingButton( 17 "screencast-status-bar-item", 18 ["disabled", "left", "top"], 19 [WebInspector.UIString("Disable screencast."), WebInspector.UIString("Switch to portrait screencast."), WebInspector.UIString("Switch to landscape screencast.")], 20 this._currentScreencastState.get(), 21 this._currentScreencastState, 22 lastScreencastState, 23 this._onStatusBarButtonStateChanged.bind(this)); 24 WebInspector.targetManager.observeTargets(this); 25 }; 26 27 WebInspector.ScreencastApp.prototype = { 28 presentUI: function() 29 { 30 var rootView = new WebInspector.RootView(); 31 32 this._rootSplitView = new WebInspector.SplitView(false, true, "InspectorView.screencastSplitViewState", 300, 300); 33 this._rootSplitView.show(rootView.element); 34 this._rootSplitView.hideMain(); 35 36 WebInspector.inspectorView.show(this._rootSplitView.sidebarElement()); 37 WebInspector.inspectorView.showInitialPanel(); 38 rootView.attachToBody(); 39 }, 40 41 /** 42 * @param {!WebInspector.Target} target 43 */ 44 targetAdded: function(target) 45 { 46 if (this._target) 47 return; 48 this._target = target; 49 if (target.hasCapability(WebInspector.Target.Capabilities.CanScreencast)) { 50 this._screencastView = new WebInspector.ScreencastView(target); 51 this._screencastView.show(this._rootSplitView.mainElement()); 52 this._screencastView.initialize(); 53 this._onStatusBarButtonStateChanged(this._currentScreencastState.get()); 54 } else { 55 this._onStatusBarButtonStateChanged("disabled"); 56 this._toggleScreencastButton.setEnabled(false); 57 } 58 }, 59 60 /** 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._onStatusBarButtonStateChanged("disabled"); 70 this._toggleScreencastButton.setEnabled(false); 71 this._screencastView.detach(); 72 delete this._screencastView; 73 } 74 }, 75 76 /** 77 * @param {string} state 78 */ 79 _onStatusBarButtonStateChanged: function(state) 80 { 81 if (!this._rootSplitView) 82 return; 83 if (state === "disabled") { 84 this._rootSplitView.toggleResizer(this._rootSplitView.resizerElement(), false); 85 this._rootSplitView.toggleResizer(WebInspector.inspectorView.topResizerElement(), false); 86 this._rootSplitView.hideMain(); 87 return; 88 } 89 90 this._rootSplitView.setVertical(state === "left"); 91 this._rootSplitView.setSecondIsSidebar(true); 92 this._rootSplitView.toggleResizer(this._rootSplitView.resizerElement(), true); 93 this._rootSplitView.toggleResizer(WebInspector.inspectorView.topResizerElement(), state === "top"); 94 this._rootSplitView.showBoth(); 95 }, 96 97 __proto__: WebInspector.App.prototype 98 }; 99 100 /** 101 * @constructor 102 * @implements {WebInspector.StatusBarItem.Provider} 103 */ 104 WebInspector.ScreencastApp.StatusBarButtonProvider = function() 105 { 106 } 107 108 WebInspector.ScreencastApp.StatusBarButtonProvider.prototype = { 109 /** 110 * @return {?WebInspector.StatusBarItem} 111 */ 112 item: function() 113 { 114 if (!(WebInspector.app instanceof WebInspector.ScreencastApp)) 115 return null; 116 return /** @type {!WebInspector.ScreencastApp} */ (WebInspector.app)._toggleScreencastButton; 117 } 118 }