Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/SidebarPane.js

Issue 2174863003: DevTools: traverse widget hierarchy to reveal views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lcean Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved.
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 * @constructor
31 * @param {!Element} container
32 * @param {!WebInspector.View} pane
33 */
34 WebInspector.SidebarPaneTitle = function(container, pane)
35 {
36 this._pane = pane;
37
38 this.element = container.createChild("div", "sidebar-pane-title");
39 this.element.textContent = pane.title();
40 this.element.tabIndex = 0;
41 this.element.addEventListener("click", this._toggleExpanded.bind(this), fals e);
42 this.element.addEventListener("keydown", this._onTitleKeyDown.bind(this), fa lse);
43 }
44
45 WebInspector.SidebarPaneTitle.prototype = {
46 _expand: function()
47 {
48 this.element.classList.add("expanded");
49 this._pane.show(/** @type {!Element} */(this.element.parentElement), /** @type {?Element} */ (this.element.nextSibling));
50 },
51
52 _collapse: function()
53 {
54 this.element.classList.remove("expanded");
55 if (this._pane.element.parentNode === this.element.parentNode)
56 this._pane.detach();
57 },
58
59 _toggleExpanded: function()
60 {
61 if (this.element.classList.contains("expanded"))
62 this._collapse();
63 else
64 this._pane.requestReveal();
65 },
66
67 /**
68 * @param {!Event} event
69 */
70 _onTitleKeyDown: function(event)
71 {
72 if (isEnterKey(event) || event.keyCode === WebInspector.KeyboardShortcut .Keys.Space.code)
73 this._toggleExpanded();
74 }
75 }
76
77 /**
78 * @constructor
79 * @extends {WebInspector.Widget}
80 */
81 WebInspector.SidebarPaneStack = function()
82 {
83 WebInspector.Widget.call(this);
84 this.setMinimumSize(25, 0);
85 this.element.classList.add("sidebar-pane-container");
86 /** @type {!Map.<!WebInspector.View, !WebInspector.SidebarPaneTitle>} */
87 this._titleByPane = new Map();
88 }
89
90 WebInspector.SidebarPaneStack.prototype = {
91 /**
92 * @param {!WebInspector.View} pane
93 */
94 addPane: function(pane)
95 {
96 var paneTitle = new WebInspector.SidebarPaneTitle(this.element, pane);
97 this._titleByPane.set(pane, paneTitle);
98 var toolbarItems = pane.toolbarItems();
99 if (toolbarItems.length) {
100 var toolbar = new WebInspector.Toolbar("", paneTitle.element);
101 for (var item of toolbarItems)
102 toolbar.appendToolbarItem(item);
103 }
104 pane.setRequestVisibleCallback(this._setPaneVisible.bind(this, pane));
105 pane.setRevealCallback(paneTitle._expand.bind(paneTitle));
106 },
107
108 /**
109 * @param {!WebInspector.View} pane
110 * @param {boolean} visible
111 */
112 _setPaneVisible: function(pane, visible)
113 {
114 var title = this._titleByPane.get(pane);
115 if (!title)
116 return;
117
118 title.element.classList.toggle("hidden", !visible);
119 pane.element.classList.toggle("sidebar-hidden-override", !visible);
120 },
121
122 __proto__: WebInspector.Widget.prototype
123 }
124
125 /**
126 * @constructor
127 * @extends {WebInspector.TabbedPane}
128 */
129 WebInspector.SidebarTabbedPane = function()
130 {
131 WebInspector.TabbedPane.call(this);
132 this.element.classList.add("sidebar-pane-container", "sidebar-tabbed-pane");
133 }
134
135 WebInspector.SidebarTabbedPane._toolbarSymbol = Symbol("toolbar");
136
137 WebInspector.SidebarTabbedPane.prototype = {
138 /**
139 * @param {!WebInspector.View} pane
140 */
141 addPane: function(pane)
142 {
143 // Detach first to trigger toolbar cleanup.
144 pane.detach();
145
146 var title = pane.title();
147 var toolbarItems = pane.toolbarItems();
148 if (toolbarItems.length) {
149 var toolbar = new WebInspector.Toolbar("");
150 pane[WebInspector.SidebarTabbedPane._toolbarSymbol] = toolbar;
151 pane.element.insertBefore(toolbar.element, pane.element.firstChild);
152 for (var item of toolbarItems)
153 toolbar.appendToolbarItem(item);
154 }
155 this.appendTab(title, title, pane);
156 pane.setRequestVisibleCallback(this._setPaneVisible.bind(this, pane));
157 pane.setRevealCallback(this.selectTab.bind(this, title));
158 },
159
160 /**
161 * @param {!WebInspector.Widget} widget
162 * @override
163 */
164 childWasDetached: function(widget)
165 {
166 WebInspector.TabbedPane.prototype.childWasDetached.call(this, widget);
167
168 var toolbar = widget[WebInspector.SidebarTabbedPane._toolbarSymbol];
169 if (toolbar)
170 toolbar.element.remove();
171 },
172
173 /**
174 * @param {!WebInspector.View} pane
175 * @param {boolean} visible
176 */
177 _setPaneVisible: function(pane, visible)
178 {
179 var title = pane.title();
180 if (visible) {
181 if (!this.hasTab(title))
182 this.appendTab(title, title, pane);
183 } else {
184 if (this.hasTab(title))
185 this.closeTab(title);
186 }
187 },
188
189 __proto__: WebInspector.TabbedPane.prototype
190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698