Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / ui / Infobar.js
blob9b10dbb26fe512c55d1bb97fcb722dfe38d10417
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @constructor
7 * @param {!WebInspector.Infobar.Type} type
8 * @param {!WebInspector.Setting=} disableSetting
9 */
10 WebInspector.Infobar = function(type, disableSetting)
12 this.element = createElementWithClass("div");
13 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element);
14 this._shadowRoot.appendChild(WebInspector.Widget.createStyleElement("ui/infobar.css"));
15 this._contentElement = this._shadowRoot.createChild("div", "infobar infobar-" + type);
17 this._contentElement.createChild("label", "icon", "dt-icon-label").type = type + "-icon";
18 this._contentElement.createChild("div", "content").createChild("content");
20 /** @type {?WebInspector.Setting} */
21 this._disableSetting = null;
23 if (disableSetting) {
24 this._disableSetting = disableSetting;
25 disableSetting.addChangeListener(this._updateVisibility, this);
26 var disableButton = this._contentElement.createChild("div", "disable-button");
27 disableButton.textContent = WebInspector.UIString("Never show");
28 disableButton.addEventListener("click", disableSetting.set.bind(disableSetting, true), false);
31 this._closeButton = this._contentElement.createChild("div", "close-button", "dt-close-button");
32 this._closeButton.addEventListener("click", this.close.bind(this), false);
33 /** @type {?function()} */
34 this._closeCallback = null;
36 this.setVisible(false);
39 /** @enum {string} */
40 WebInspector.Infobar.Type = {
41 Warning: "warning",
42 Info: "info"
45 WebInspector.Infobar.prototype = {
46 /**
47 * @param {boolean} visible
49 setVisible: function(visible)
51 this._visible = visible;
52 if (this._disableSetting)
53 visible = visible && !this._disableSetting.get();
54 this.element.classList.toggle("hidden", !visible);
57 _updateVisibility: function()
59 this.setVisible(this._visible);
62 close: function()
64 this.setVisible(false);
65 if (this._closeCallback)
66 this._closeCallback.call(null);
69 /**
70 * @param {?function()} callback
72 setCloseCallback: function(callback)
74 this._closeCallback = callback;