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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /**
5 * @unrestricted
6 */
7 WebInspector.Infobar = class {
8 /**
9 * @param {!WebInspector.Infobar.Type} type
10 * @param {string} text
11 * @param {!WebInspector.Setting=} disableSetting
12 */
13 constructor(type, text, disableSetting) {
14 this.element = createElementWithClass('div', 'flex-none');
15 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element, 'ui/infobar.css');
16 this._contentElement = this._shadowRoot.createChild('div', 'infobar infobar- ' + type);
4 17
5 /** 18 this._mainRow = this._contentElement.createChild('div', 'infobar-main-row');
6 * @constructor 19 this._mainRow.createChild('div', type + '-icon icon');
7 * @param {!WebInspector.Infobar.Type} type 20 this._mainRowText = this._mainRow.createChild('div', 'infobar-main-title');
8 * @param {string} text 21 this._mainRowText.textContent = text;
9 * @param {!WebInspector.Setting=} disableSetting 22 this._detailsRows = this._contentElement.createChild('div', 'infobar-details -rows hidden');
10 */
11 WebInspector.Infobar = function(type, text, disableSetting)
12 {
13 this.element = createElementWithClass("div", "flex-none");
14 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element, "ui/infobar.css");
15 this._contentElement = this._shadowRoot.createChild("div", "infobar infobar- " + type);
16 23
17 this._mainRow = this._contentElement.createChild("div", "infobar-main-row"); 24 this._toggleElement = this._mainRow.createChild('div', 'infobar-toggle hidde n');
18 this._mainRow.createChild("div", type + "-icon icon"); 25 this._toggleElement.addEventListener('click', this._onToggleDetails.bind(thi s), false);
19 this._mainRowText = this._mainRow.createChild("div", "infobar-main-title"); 26 this._toggleElement.textContent = WebInspector.UIString('more');
20 this._mainRowText.textContent = text;
21 this._detailsRows = this._contentElement.createChild("div", "infobar-details -rows hidden");
22
23 this._toggleElement = this._mainRow.createChild("div", "infobar-toggle hidde n");
24 this._toggleElement.addEventListener("click", this._onToggleDetails.bind(thi s), false);
25 this._toggleElement.textContent = WebInspector.UIString("more");
26 27
27 /** @type {?WebInspector.Setting} */ 28 /** @type {?WebInspector.Setting} */
28 this._disableSetting = disableSetting || null; 29 this._disableSetting = disableSetting || null;
29 if (disableSetting) { 30 if (disableSetting) {
30 var disableButton = this._mainRow.createChild("div", "infobar-toggle"); 31 var disableButton = this._mainRow.createChild('div', 'infobar-toggle');
31 disableButton.textContent = WebInspector.UIString("never show"); 32 disableButton.textContent = WebInspector.UIString('never show');
32 disableButton.addEventListener("click", this._onDisable.bind(this), fals e); 33 disableButton.addEventListener('click', this._onDisable.bind(this), false) ;
33 } 34 }
34 35
35 this._closeButton = this._contentElement.createChild("div", "close-button", "dt-close-button"); 36 this._closeButton = this._contentElement.createChild('div', 'close-button', 'dt-close-button');
36 this._closeButton.addEventListener("click", this.dispose.bind(this), false); 37 this._closeButton.addEventListener('click', this.dispose.bind(this), false);
37 38
38 /** @type {?function()} */ 39 /** @type {?function()} */
39 this._closeCallback = null; 40 this._closeCallback = null;
40 }; 41 }
41 42
42 /** 43 /**
43 * @param {!WebInspector.Infobar.Type} type 44 * @param {!WebInspector.Infobar.Type} type
44 * @param {string} text 45 * @param {string} text
45 * @param {!WebInspector.Setting=} disableSetting 46 * @param {!WebInspector.Setting=} disableSetting
46 * @return {?WebInspector.Infobar} 47 * @return {?WebInspector.Infobar}
47 */ 48 */
48 WebInspector.Infobar.create = function(type, text, disableSetting) 49 static create(type, text, disableSetting) {
49 {
50 if (disableSetting && disableSetting.get()) 50 if (disableSetting && disableSetting.get())
51 return null; 51 return null;
52 return new WebInspector.Infobar(type, text, disableSetting); 52 return new WebInspector.Infobar(type, text, disableSetting);
53 }
54
55 dispose() {
56 this.element.remove();
57 this._onResize();
58 if (this._closeCallback)
59 this._closeCallback.call(null);
60 }
61
62 /**
63 * @param {string} text
64 */
65 setText(text) {
66 this._mainRowText.textContent = text;
67 this._onResize();
68 }
69
70 /**
71 * @param {?function()} callback
72 */
73 setCloseCallback(callback) {
74 this._closeCallback = callback;
75 }
76
77 /**
78 * @param {!WebInspector.Widget} parentView
79 */
80 setParentView(parentView) {
81 this._parentView = parentView;
82 }
83
84 _onResize() {
85 if (this._parentView)
86 this._parentView.doResize();
87 }
88
89 _onDisable() {
90 this._disableSetting.set(true);
91 this.dispose();
92 }
93
94 _onToggleDetails() {
95 this._detailsRows.classList.remove('hidden');
96 this._toggleElement.remove();
97 this._onResize();
98 }
99
100 /**
101 * @param {string=} message
102 * @return {!Element}
103 */
104 createDetailsRowMessage(message) {
105 this._toggleElement.classList.remove('hidden');
106 var infobarDetailsRow = this._detailsRows.createChild('div', 'infobar-detail s-row');
107 var detailsRowMessage = infobarDetailsRow.createChild('span', 'infobar-row-m essage');
108 detailsRowMessage.textContent = message || '';
109 return detailsRowMessage;
110 }
53 }; 111 };
54 112
55 113
56 /** @enum {string} */ 114 /** @enum {string} */
57 WebInspector.Infobar.Type = { 115 WebInspector.Infobar.Type = {
58 Warning: "warning", 116 Warning: 'warning',
59 Info: "info" 117 Info: 'info'
60 }; 118 };
61
62 WebInspector.Infobar.prototype = {
63 dispose: function()
64 {
65 this.element.remove();
66 this._onResize();
67 if (this._closeCallback)
68 this._closeCallback.call(null);
69 },
70
71 /**
72 * @param {string} text
73 */
74 setText: function(text)
75 {
76 this._mainRowText.textContent = text;
77 this._onResize();
78 },
79
80 /**
81 * @param {?function()} callback
82 */
83 setCloseCallback: function(callback)
84 {
85 this._closeCallback = callback;
86 },
87
88 /**
89 * @param {!WebInspector.Widget} parentView
90 */
91 setParentView: function(parentView)
92 {
93 this._parentView = parentView;
94 },
95
96 _onResize: function()
97 {
98 if (this._parentView)
99 this._parentView.doResize();
100 },
101
102 _onDisable: function()
103 {
104 this._disableSetting.set(true);
105 this.dispose();
106 },
107
108 _onToggleDetails: function()
109 {
110 this._detailsRows.classList.remove("hidden");
111 this._toggleElement.remove();
112 this._onResize();
113 },
114
115 /**
116 * @param {string=} message
117 * @return {!Element}
118 */
119 createDetailsRowMessage: function(message)
120 {
121 this._toggleElement.classList.remove("hidden");
122 var infobarDetailsRow = this._detailsRows.createChild("div", "infobar-de tails-row");
123 var detailsRowMessage = infobarDetailsRow.createChild("span", "infobar-r ow-message");
124 detailsRowMessage.textContent = message || "";
125 return detailsRowMessage;
126 }
127 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698