Chromium Code Reviews| Index: Source/devtools/front_end/ui/StatusBarButton.js |
| diff --git a/Source/devtools/front_end/ui/StatusBarButton.js b/Source/devtools/front_end/ui/StatusBarButton.js |
| index c2b092e2113bc656f9c46eab3bf5340a2868ef84..d53c64a040973ddf7beea1906bc6b3b7d116f015 100644 |
| --- a/Source/devtools/front_end/ui/StatusBarButton.js |
| +++ b/Source/devtools/front_end/ui/StatusBarButton.js |
| @@ -79,6 +79,81 @@ WebInspector.StatusBarItem.prototype = { |
| /** |
| * @constructor |
| * @extends {WebInspector.StatusBarItem} |
| + * @param {!Array.<string>} counters |
| + * @param {string=} className |
| + */ |
| +WebInspector.StatusBarCounter = function(counters, className) |
| +{ |
| + WebInspector.StatusBarItem.call(this, "div"); |
| + this.element.className = "status-bar-item status-bar-counter hidden"; |
| + if (className) |
| + this.element.classList.add(className); |
| + this.element.addEventListener("click", this._clicked.bind(this), false); |
| + this._counters = []; |
|
apavlov
2014/07/21 13:34:06
This should be annotated at least with a @typedef
dgozman
2014/07/21 14:24:34
Nice catch. Done.
|
| + for (var i = 0; i < counters.length; i++) { |
|
apavlov
2014/07/21 13:34:06
++i for consistency
dgozman
2014/07/21 14:24:34
Done.
|
| + var element = this.element.createChild("span", "status-bar-counter-item"); |
| + element.createChild("div", counters[i]); |
| + element.createChild("span"); |
| + this._counters.push({counter: counters[i], element: element, value: 0, title: ""}); |
| + } |
| + this._update(); |
| +} |
| + |
| +WebInspector.StatusBarCounter.prototype = { |
| + /** |
| + * @param {string} counter |
| + * @param {number} value |
| + * @param {string} title |
| + */ |
| + setCounter: function(counter, value, title) |
| + { |
| + for (var i = 0; i < this._counters.length; ++i) { |
| + if (this._counters[i].counter == counter) { |
|
apavlov
2014/07/21 13:34:06
===
dgozman
2014/07/21 14:24:34
Done.
|
| + this._counters[i].value = value; |
| + this._counters[i].title = title; |
| + this._update(); |
| + return; |
| + } |
| + } |
| + }, |
| + |
| + _update: function() |
| + { |
| + var total = 0; |
| + var title = ""; |
| + for (var i = 0; i < this._counters.length; ++i) { |
| + if (!this._counters[i].value) { |
|
apavlov
2014/07/21 13:34:06
this._counters[i].value can be extracted into a va
dgozman
2014/07/21 14:24:34
Done.
|
| + this._counters[i].element.classList.add("hidden"); |
| + continue; |
| + } |
| + this._counters[i].element.style.marginLeft = total ? "6px" : "0"; |
|
apavlov
2014/07/21 13:34:06
can we implement this using classes? This seems a
dgozman
2014/07/21 14:24:35
Done.
|
| + this._counters[i].element.classList.remove("hidden"); |
| + this._counters[i].element.querySelector("span").textContent = this._counters[i].value; |
| + total += this._counters[i].value; |
| + if (this._counters[i].title) { |
| + if (title) |
| + title += ", "; |
| + title += this._counters[i].title; |
| + } |
| + } |
| + this.element.classList.toggle("hidden", !total); |
| + this.element.title = title; |
| + }, |
| + |
| + /** |
| + * @param {!Event} event |
| + */ |
| + _clicked: function(event) |
| + { |
| + this.dispatchEventToListeners("click"); |
| + }, |
| + |
| + __proto__: WebInspector.StatusBarItem.prototype |
| +} |
| + |
| +/** |
| + * @constructor |
| + * @extends {WebInspector.StatusBarItem} |
| * @param {string} text |
| * @param {string=} className |
| */ |
| @@ -426,15 +501,15 @@ WebInspector.StatusBarButton.prototype = { |
| /** |
| * @interface |
| */ |
| -WebInspector.StatusBarButton.Provider = function() |
| +WebInspector.StatusBarItem.Provider = function() |
| { |
| } |
| -WebInspector.StatusBarButton.Provider.prototype = { |
| +WebInspector.StatusBarItem.Provider.prototype = { |
| /** |
| - * @return {?WebInspector.StatusBarButton} |
| + * @return {?WebInspector.StatusBarItem} |
| */ |
| - button: function() {} |
| + item: function() {} |
| } |
| /** |