2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
4 * Copyright (C) 2009 Joseph Pecoraro
5 * Copyright (C) 2011 Google Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 WebInspector.Toolbar = function()
37 this.element = document.getElementById("toolbar");
38 this.element.addEventListener("mousedown", this._toolbarDragStart.bind(this), true);
40 this._dropdownButton = document.getElementById("toolbar-dropdown-arrow");
41 this._dropdownButton.addEventListener("click", this._toggleDropdown.bind(this), false);
43 document.getElementById("close-button-left").addEventListener("click", this._onClose, true);
44 document.getElementById("close-button-right").addEventListener("click", this._onClose, true);
47 WebInspector.Toolbar.prototype = {
48 set attached(attached)
51 this.element.addStyleClass("toolbar-small");
53 this.element.removeStyleClass("toolbar-small");
54 this._updateDropdownButtonAndHideDropdown();
59 this._updateDropdownButtonAndHideDropdown();
62 addPanel: function(panel)
64 this.element.appendChild(panel.toolbarItem);
68 _toolbarDragStart: function(event)
70 if ((!WebInspector.attached && WebInspector.platformFlavor() !== WebInspector.PlatformFlavor.MacLeopard && WebInspector.platformFlavor() !== WebInspector.PlatformFlavor.MacSnowLeopard) || WebInspector.port() == "qt")
73 var target = event.target;
74 if (target.hasStyleClass("toolbar-item") && target.hasStyleClass("toggleable"))
77 if (target !== this.element && !target.hasStyleClass("toolbar-item"))
80 this.element.lastScreenX = event.screenX;
81 this.element.lastScreenY = event.screenY;
83 WebInspector.elementDragStart(this.element, this._toolbarDrag.bind(this), this._toolbarDragEnd.bind(this), event, (WebInspector.attached ? "row-resize" : "default"));
86 _toolbarDragEnd: function(event)
88 WebInspector.elementDragEnd(event);
90 delete this.element.lastScreenX;
91 delete this.element.lastScreenY;
94 _toolbarDrag: function(event)
96 if (WebInspector.attached) {
97 var height = window.innerHeight - (event.screenY - this.element.lastScreenY);
99 InspectorFrontendHost.setAttachedWindowHeight(height);
101 var x = event.screenX - this.element.lastScreenX;
102 var y = event.screenY - this.element.lastScreenY;
104 // We cannot call window.moveBy here because it restricts the movement
105 // of the window at the edges.
106 InspectorFrontendHost.moveWindowBy(x, y);
109 this.element.lastScreenX = event.screenX;
110 this.element.lastScreenY = event.screenY;
112 event.preventDefault();
117 WebInspector.close();
120 _setDropdownVisible: function(visible)
122 if (!this._dropdown) {
125 this._dropdown = new WebInspector.ToolbarDropdown();
128 this._dropdown.show();
130 this._dropdown.hide();
133 _toggleDropdown: function()
135 this._setDropdownVisible(!this._dropdown || !this._dropdown.visible);
138 _updateDropdownButtonAndHideDropdown: function()
140 this._setDropdownVisible(false);
142 var toolbar = document.getElementById("toolbar");
143 if (this.element.scrollHeight > this.element.clientHeight)
144 this._dropdownButton.removeStyleClass("hidden");
146 this._dropdownButton.addStyleClass("hidden");
150 WebInspector.Toolbar.createPanelToolbarItem = function(panel)
152 var toolbarItem = document.createElement("button");
153 toolbarItem.className = "toolbar-item toggleable";
154 toolbarItem.panel = panel;
155 toolbarItem.addStyleClass(panel._panelName);
156 function onToolbarItemClicked()
158 WebInspector.toolbar._updateDropdownButtonAndHideDropdown();
159 WebInspector.inspectorView.setCurrentPanel(panel);
161 toolbarItem.addEventListener("click", onToolbarItemClicked, false);
163 var iconElement = toolbarItem.createChild("div", "toolbar-icon");
165 if ("toolbarItemLabel" in panel)
166 toolbarItem.createChild("div", "toolbar-label").textContent = panel.toolbarItemLabel;
168 if (panel === WebInspector.inspectorView.currentPanel())
169 toolbarItem.addStyleClass("toggled-on");
177 WebInspector.ToolbarDropdown = function()
179 this._toolbar = document.getElementById("toolbar");
180 this._arrow = document.getElementById("toolbar-dropdown-arrow");
181 this.element = document.createElement("div");
182 this.element.id = "toolbar-dropdown";
183 this.element.className = "toolbar-small";
184 this._contentElement = this.element.createChild("div", "scrollable-content");
185 this._contentElement.tabIndex = 0;
186 this._contentElement.addEventListener("keydown", this._onKeyDown.bind(this), true);
189 WebInspector.ToolbarDropdown.prototype = {
194 var style = this.element.style;
196 var top = this._arrow.totalOffsetTop() + this._arrow.clientHeight;
197 this._arrow.addStyleClass("dropdown-visible");
198 this.element.style.top = top + "px";
199 this.element.style.left = this._arrow.totalOffsetLeft() + "px";
200 this._contentElement.style.maxHeight = window.innerHeight - top - 20 + "px";
201 this._toolbar.appendChild(this.element);
208 this._arrow.removeStyleClass("dropdown-visible");
209 this.element.parentNode.removeChild(this.element);
210 this._contentElement.removeChildren();
215 return !!this.element.parentNode;
218 _populate: function()
220 var toolbarItems = this._toolbar.querySelectorAll(".toolbar-item.toggleable");
222 for (var i = 0; i < toolbarItems.length; ++i) {
223 if (toolbarItems[i].offsetTop > 0)
224 this._contentElement.appendChild(WebInspector.Toolbar.createPanelToolbarItem(toolbarItems[i].panel));
228 _onKeyDown: function(event)
230 if (event.keyCode !== WebInspector.KeyboardShortcut.Keys.Esc.code)
232 event.stopPropagation();
238 * @type {?WebInspector.Toolbar}
240 WebInspector.toolbar = null;