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

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

Issue 2157713002: DevTools: introduce View: a named widget with the toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lcean Created 4 years, 5 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
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 10 matching lines...) Expand all
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 /** 29 /**
30 * @constructor 30 * @constructor
31 * @extends {WebInspector.Widget}
32 * @param {string} title
33 */
34 WebInspector.SidebarPane = function(title)
35 {
36 WebInspector.Widget.call(this);
37 this.setMinimumSize(25, 0);
38 this.element.className = "sidebar-pane"; // Override
39
40 this._title = title;
41 this._expandCallback = null;
42 this._paneVisible = true;
43 }
44
45 WebInspector.SidebarPane.prototype = {
46 /**
47 * @return {!WebInspector.Toolbar}
48 */
49 toolbar: function()
50 {
51 if (!this._toolbar) {
52 this._toolbar = new WebInspector.Toolbar("");
53 this._toolbar.element.addEventListener("click", consumeEvent);
54 this.element.insertBefore(this._toolbar.element, this.element.firstC hild);
55 }
56 return this._toolbar;
57 },
58
59 expandPane: function()
60 {
61 this.onContentReady();
62 },
63
64 onContentReady: function()
65 {
66 if (this._expandCallback)
67 this._expandCallback();
68 else
69 this._expandPending = true;
70 },
71
72 /**
73 * @param {function(boolean)} setVisibleCallback
74 * @param {function()} expandCallback
75 */
76 _attached: function(setVisibleCallback, expandCallback)
77 {
78 this._setVisibleCallback = setVisibleCallback;
79 this._setVisibleCallback(this._paneVisible);
80
81 this._expandCallback = expandCallback;
82 if (this._expandPending) {
83 delete this._expandPending;
84 this._expandCallback();
85 }
86 },
87
88 /**
89 * @param {boolean} visible
90 */
91 setVisible: function(visible)
92 {
93 this._paneVisible = visible;
94 if (this._setVisibleCallback)
95 this._setVisibleCallback(visible)
96 },
97
98 __proto__: WebInspector.Widget.prototype
99 }
100
101 /**
102 * @constructor
103 * @param {!Element} container 31 * @param {!Element} container
104 * @param {!WebInspector.SidebarPane} pane 32 * @param {!WebInspector.View} pane
105 */ 33 */
106 WebInspector.SidebarPaneTitle = function(container, pane) 34 WebInspector.SidebarPaneTitle = function(container, pane)
107 { 35 {
108 this._pane = pane; 36 this._pane = pane;
109 37
110 this.element = container.createChild("div", "sidebar-pane-title"); 38 this.element = container.createChild("div", "sidebar-pane-title");
111 this.element.textContent = pane._title; 39 this.element.textContent = pane.title();
112 this.element.tabIndex = 0; 40 this.element.tabIndex = 0;
113 this.element.addEventListener("click", this._toggleExpanded.bind(this), fals e); 41 this.element.addEventListener("click", this._toggleExpanded.bind(this), fals e);
114 this.element.addEventListener("keydown", this._onTitleKeyDown.bind(this), fa lse); 42 this.element.addEventListener("keydown", this._onTitleKeyDown.bind(this), fa lse);
115 } 43 }
116 44
117 WebInspector.SidebarPaneTitle.prototype = { 45 WebInspector.SidebarPaneTitle.prototype = {
118 _expand: function() 46 _expand: function()
119 { 47 {
120 this.element.classList.add("expanded"); 48 this.element.classList.add("expanded");
121 this._pane.show(this.element.parentElement, /** @type {?Element} */ (thi s.element.nextSibling)); 49 this._pane.show(this.element.parentElement, /** @type {?Element} */ (thi s.element.nextSibling));
122 }, 50 },
123 51
124 _collapse: function() 52 _collapse: function()
125 { 53 {
126 this.element.classList.remove("expanded"); 54 this.element.classList.remove("expanded");
127 if (this._pane.element.parentNode === this.element.parentNode) 55 if (this._pane.element.parentNode === this.element.parentNode)
128 this._pane.detach(); 56 this._pane.detach();
129 }, 57 },
130 58
131 _toggleExpanded: function() 59 _toggleExpanded: function()
132 { 60 {
133 if (this.element.classList.contains("expanded")) 61 if (this.element.classList.contains("expanded"))
134 this._collapse(); 62 this._collapse();
135 else 63 else
136 this._pane.expandPane(); 64 this._pane.requestReveal();
137 }, 65 },
138 66
139 /** 67 /**
140 * @param {!Event} event 68 * @param {!Event} event
141 */ 69 */
142 _onTitleKeyDown: function(event) 70 _onTitleKeyDown: function(event)
143 { 71 {
144 if (isEnterKey(event) || event.keyCode === WebInspector.KeyboardShortcut .Keys.Space.code) 72 if (isEnterKey(event) || event.keyCode === WebInspector.KeyboardShortcut .Keys.Space.code)
145 this._toggleExpanded(); 73 this._toggleExpanded();
146 } 74 }
147 } 75 }
148 76
149 /** 77 /**
150 * @constructor 78 * @constructor
151 * @extends {WebInspector.Widget} 79 * @extends {WebInspector.Widget}
152 */ 80 */
153 WebInspector.SidebarPaneStack = function() 81 WebInspector.SidebarPaneStack = function()
154 { 82 {
155 WebInspector.Widget.call(this); 83 WebInspector.Widget.call(this);
156 this.setMinimumSize(25, 0); 84 this.setMinimumSize(25, 0);
157 this.element.className = "sidebar-pane-stack"; // Override 85 this.element.classList.add("sidebar-pane-container");
158 /** @type {!Map.<!WebInspector.SidebarPane, !WebInspector.SidebarPaneTitle>} */ 86 /** @type {!Map.<!WebInspector.View, !WebInspector.SidebarPaneTitle>} */
159 this._titleByPane = new Map(); 87 this._titleByPane = new Map();
160 } 88 }
161 89
162 WebInspector.SidebarPaneStack.prototype = { 90 WebInspector.SidebarPaneStack.prototype = {
163 /** 91 /**
164 * @param {!WebInspector.SidebarPane} pane 92 * @param {!WebInspector.View} pane
165 */ 93 */
166 addPane: function(pane) 94 addPane: function(pane)
167 { 95 {
168 var paneTitle = new WebInspector.SidebarPaneTitle(this.element, pane); 96 var paneTitle = new WebInspector.SidebarPaneTitle(this.element, pane);
169 this._titleByPane.set(pane, paneTitle); 97 this._titleByPane.set(pane, paneTitle);
170 if (pane._toolbar) 98 var toolbarItems = pane.toolbarItems();
171 paneTitle.element.appendChild(pane._toolbar.element); 99 if (toolbarItems.length) {
172 pane._attached(this._setPaneVisible.bind(this, pane), paneTitle._expand. bind(paneTitle)); 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));
173 }, 106 },
174 107
175 /** 108 /**
176 * @param {!WebInspector.SidebarPane} pane 109 * @param {!WebInspector.View} pane
177 * @param {boolean} visible 110 * @param {boolean} visible
178 */ 111 */
179 _setPaneVisible: function(pane, visible) 112 _setPaneVisible: function(pane, visible)
180 { 113 {
181 var title = this._titleByPane.get(pane); 114 var title = this._titleByPane.get(pane);
182 if (!title) 115 if (!title)
183 return; 116 return;
184 117
185 title.element.classList.toggle("hidden", !visible); 118 title.element.classList.toggle("hidden", !visible);
186 pane.element.classList.toggle("sidebar-pane-hidden", !visible); 119 pane.element.classList.toggle("sidebar-hidden-override", !visible);
187 }, 120 },
188 121
189 __proto__: WebInspector.Widget.prototype 122 __proto__: WebInspector.Widget.prototype
190 } 123 }
191 124
192 /** 125 /**
193 * @constructor 126 * @constructor
194 * @extends {WebInspector.TabbedPane} 127 * @extends {WebInspector.TabbedPane}
195 */ 128 */
196 WebInspector.SidebarTabbedPane = function() 129 WebInspector.SidebarTabbedPane = function()
197 { 130 {
198 WebInspector.TabbedPane.call(this); 131 WebInspector.TabbedPane.call(this);
199 this.element.classList.add("sidebar-tabbed-pane"); 132 this.element.classList.add("sidebar-pane-container", "sidebar-tabbed-pane");
200 } 133 }
201 134
202 WebInspector.SidebarTabbedPane.prototype = { 135 WebInspector.SidebarTabbedPane.prototype = {
203 /** 136 /**
204 * @param {!WebInspector.SidebarPane} pane 137 * @param {!WebInspector.View} pane
205 */ 138 */
206 addPane: function(pane) 139 addPane: function(pane)
207 { 140 {
208 var title = pane._title; 141 var title = pane.title();
142
143 var toolbarItems = pane.toolbarItems();
144 if (toolbarItems.length) {
145 var toolbar = new WebInspector.Toolbar("");
146 pane.element.insertBefore(toolbar.element, pane.element.firstChild);
147 for (var item of toolbarItems)
148 toolbar.appendToolbarItem(item);
149 }
209 this.appendTab(title, title, pane); 150 this.appendTab(title, title, pane);
210 if (pane._toolbar) 151 pane.setRequestVisibleCallback(this._setPaneVisible.bind(this, pane));
211 pane.element.insertBefore(pane._toolbar.element, pane.element.firstC hild); 152 pane.setRevealCallback(this.selectTab.bind(this, title));
212 pane._attached(this._setPaneVisible.bind(this, pane), this.selectTab.bin d(this, title));
213 }, 153 },
214 154
215 /** 155 /**
216 * @param {!WebInspector.SidebarPane} pane 156 * @param {!WebInspector.View} pane
217 * @param {boolean} visible 157 * @param {boolean} visible
218 */ 158 */
219 _setPaneVisible: function(pane, visible) 159 _setPaneVisible: function(pane, visible)
220 { 160 {
221 var title = pane._title; 161 var title = pane.title();
222 if (visible) { 162 if (visible) {
223 if (!this.hasTab(title)) 163 if (!this.hasTab(title))
224 this.appendTab(title, title, pane); 164 this.appendTab(title, title, pane);
225 } else { 165 } else {
226 if (this.hasTab(title)) 166 if (this.hasTab(title))
227 this.closeTab(title); 167 this.closeTab(title);
228 } 168 }
229 }, 169 },
230 170
231 __proto__: WebInspector.TabbedPane.prototype 171 __proto__: WebInspector.TabbedPane.prototype
232 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698