Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / ui / Section.js
blobc6d8dcabb5f9a66227b78b1651a9d0be45cdc270
1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 /**
31 * @constructor
32 * @param {string|!Node} title
33 * @param {string=} subtitle
35 WebInspector.Section = function(title, subtitle)
37 this.element = createElementWithClass("div", "section");
38 this.element._section = this;
39 this.registerRequiredCSS("ui/section.css");
41 this.headerElement = createElementWithClass("div", "header monospace");
43 this.titleElement = createElementWithClass("div", "title");
45 this.subtitleElement = createElementWithClass("div", "subtitle");
47 this.headerElement.appendChild(this.subtitleElement);
48 this.headerElement.appendChild(this.titleElement);
50 this.headerElement.addEventListener("click", this.handleClick.bind(this), false);
51 this.element.appendChild(this.headerElement);
53 this.title = title;
54 if (subtitle) {
55 this._subtitle = subtitle;
56 this.subtitleElement.textContent = subtitle;
58 this._expanded = false;
61 WebInspector.Section.prototype = {
62 get title()
64 return this._title;
67 set title(x)
69 if (this._title === x)
70 return;
71 this._title = x;
73 if (x instanceof Node) {
74 this.titleElement.removeChildren();
75 this.titleElement.appendChild(x);
76 } else
77 this.titleElement.textContent = x;
80 get subtitle()
82 return this._subtitle;
85 get expanded()
87 return this._expanded;
90 repopulate: function()
92 this._populated = false;
93 if (this._expanded) {
94 this.onpopulate();
95 this._populated = true;
99 /**
100 * @protected
102 onpopulate: function()
104 // Overridden by subclasses.
107 expand: function()
109 if (this._expanded)
110 return;
111 this._expanded = true;
112 this.element.classList.add("expanded");
114 if (!this._populated) {
115 this.onpopulate();
116 this._populated = true;
120 collapse: function()
122 if (!this._expanded)
123 return;
124 this._expanded = false;
125 this.element.classList.remove("expanded");
129 * @param {string} cssFile
131 registerRequiredCSS: function(cssFile)
133 this.element.insertBefore(WebInspector.Widget.createStyleElement(cssFile), this.headerElement);
137 * @param {!Event} event
138 * @protected
140 handleClick: function(event)
142 if (this._doNotExpandOnTitleClick)
143 return;
145 if (this._expanded)
146 this.collapse();
147 else
148 this.expand();
149 event.consume();
152 doNotExpandOnTitleClick: function()
154 this._doNotExpandOnTitleClick = true;
159 * @constructor
160 * @extends {WebInspector.Section}
161 * @param {string|!Node} title
162 * @param {string=} subtitle
164 WebInspector.PropertiesSection = function(title, subtitle)
166 WebInspector.Section.call(this, title, subtitle);
167 this.registerRequiredCSS("ui/propertiesSection.css");
169 this.propertiesTreeOutline = new TreeOutline(true);
170 this.propertiesElement = this.propertiesTreeOutline.element;
171 this.propertiesElement.classList.add("properties", "properties-tree", "monospace");
172 this.propertiesTreeOutline.setFocusable(false);
173 this.propertiesTreeOutline.section = this;
175 this.element.appendChild(this.propertiesElement);
178 WebInspector.PropertiesSection.prototype = {
179 __proto__: WebInspector.Section.prototype