Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / main / ScreencastApp.js
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  */
9 WebInspector.ScreencastApp = function()
10 {
11     WebInspector.App.call(this);
12
13     var lastScreencastState = WebInspector.settings.createSetting("lastScreencastState", "left");
14     this._currentScreencastState = WebInspector.settings.createSetting("currentScreencastState", "disabled");
15     this._toggleScreencastButton = new WebInspector.StatusBarStatesSettingButton(
16         "screencast-status-bar-item",
17         ["disabled", "left", "top"],
18         [WebInspector.UIString("Disable screencast."), WebInspector.UIString("Switch to portrait screencast."), WebInspector.UIString("Switch to landscape screencast.")],
19         this._currentScreencastState.get(),
20         this._currentScreencastState,
21         lastScreencastState,
22         this._onStatusBarButtonStateChanged.bind(this));
23 };
24
25 WebInspector.ScreencastApp.prototype = {
26     createRootView: function()
27     {
28         var rootView = new WebInspector.RootView();
29
30         this._rootSplitView = new WebInspector.SplitView(false, true, "InspectorView.screencastSplitViewState", 300, 300);
31         this._rootSplitView.show(rootView.element);
32         this._rootSplitView.hideMain();
33
34         WebInspector.inspectorView.show(this._rootSplitView.sidebarElement());
35         rootView.attachToBody();
36     },
37
38     /**
39      * @param {!WebInspector.Target} mainTarget
40      */
41     presentUI: function(mainTarget)
42     {
43         if (mainTarget.hasCapability(WebInspector.Target.Capabilities.CanScreencast)) {
44             this._screencastView = new WebInspector.ScreencastView(mainTarget);
45             this._screencastView.show(this._rootSplitView.mainElement());
46             this._screencastView.initialize();
47             this._onStatusBarButtonStateChanged(this._currentScreencastState.get());
48         } else {
49             this._onStatusBarButtonStateChanged("disabled");
50             this._toggleScreencastButton.setEnabled(false);
51         }
52         WebInspector.App.prototype.presentUI.call(this, mainTarget);
53     },
54
55     /**
56      * @param {string} state
57      */
58     _onStatusBarButtonStateChanged: function(state)
59     {
60         if (!this._rootSplitView)
61             return;
62         if (state === "disabled") {
63             this._rootSplitView.toggleResizer(this._rootSplitView.resizerElement(), false);
64             this._rootSplitView.toggleResizer(WebInspector.inspectorView.topResizerElement(), false);
65             this._rootSplitView.hideMain();
66             return;
67         }
68
69         this._rootSplitView.setVertical(state === "left");
70         this._rootSplitView.setSecondIsSidebar(true);
71         this._rootSplitView.toggleResizer(this._rootSplitView.resizerElement(), true);
72         this._rootSplitView.toggleResizer(WebInspector.inspectorView.topResizerElement(), state === "top");
73         this._rootSplitView.showBoth();
74     },
75
76     __proto__: WebInspector.App.prototype
77 };
78
79 /**
80  * @constructor
81  * @implements {WebInspector.StatusBarItem.Provider}
82  */
83 WebInspector.ScreencastApp.StatusBarButtonProvider = function()
84 {
85 }
86
87 WebInspector.ScreencastApp.StatusBarButtonProvider.prototype = {
88     /**
89      * @return {?WebInspector.StatusBarItem}
90      */
91     item: function()
92     {
93         if (!(WebInspector.app instanceof WebInspector.ScreencastApp))
94             return null;
95         return /** @type {!WebInspector.ScreencastApp} */ (WebInspector.app)._toggleScreencastButton;
96     }
97 }