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

Unified Diff: Source/devtools/front_end/ui/StatusBarButton.js

Issue 408853002: [DevTools] Make toolbar counters declarative. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months 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 side-by-side diff with in-line comments
Download patch
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() {}
}
/**
« Source/devtools/front_end/main/Main.js ('K') | « Source/devtools/front_end/settings/module.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698