blob: 862721f83d86aa8f651c510b0d1bc361fa84733c [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2009 Joseph Pecoraro
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @unrestricted
31 */
32Console.ConsolePanel = class extends UI.Panel {
33 constructor() {
34 super('console');
35 this._view = Console.ConsoleView.instance();
36 }
37
38 /**
39 * @return {!Console.ConsolePanel}
40 */
41 static instance() {
42 return /** @type {!Console.ConsolePanel} */ (self.runtime.sharedInstance(Console.ConsolePanel));
43 }
44
45 /**
46 * @override
47 */
48 wasShown() {
49 super.wasShown();
50 const wrapper = Console.ConsolePanel.WrapperView._instance;
51 if (wrapper && wrapper.isShowing())
52 UI.inspectorView.setDrawerMinimized(true);
53 this._view.show(this.element);
54 }
55
56 /**
57 * @override
58 */
59 willHide() {
60 super.willHide();
61 // The minimized drawer has 0 height, and showing Console inside may set
62 // Console's scrollTop to 0. Unminimize before calling show to avoid this.
63 UI.inspectorView.setDrawerMinimized(false);
64 if (Console.ConsolePanel.WrapperView._instance)
65 Console.ConsolePanel.WrapperView._instance._showViewInWrapper();
66 }
67
68 /**
69 * @override
70 * @return {?UI.SearchableView}
71 */
72 searchableView() {
73 return Console.ConsoleView.instance().searchableView();
74 }
75};
76
77/**
78 * @unrestricted
79 */
80Console.ConsolePanel.WrapperView = class extends UI.VBox {
81 constructor() {
82 super();
83 this.element.classList.add('console-view-wrapper');
84
85 Console.ConsolePanel.WrapperView._instance = this;
86
87 this._view = Console.ConsoleView.instance();
88 }
89
90 /**
91 * @override
92 */
93 wasShown() {
94 if (!Console.ConsolePanel.instance().isShowing())
95 this._showViewInWrapper();
96 else
97 UI.inspectorView.setDrawerMinimized(true);
98 }
99
100 /**
101 * @override
102 */
103 willHide() {
104 UI.inspectorView.setDrawerMinimized(false);
105 }
106
107 _showViewInWrapper() {
108 this._view.show(this.element);
109 }
110};
111
112/**
113 * @implements {Common.Revealer}
114 * @unrestricted
115 */
116Console.ConsolePanel.ConsoleRevealer = class {
117 /**
118 * @override
119 * @param {!Object} object
120 * @return {!Promise}
121 */
122 reveal(object) {
123 const consoleView = Console.ConsoleView.instance();
124 if (consoleView.isShowing()) {
125 consoleView.focus();
126 return Promise.resolve();
127 }
128 UI.viewManager.showView('console-view');
129 return Promise.resolve();
130 }
131};