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

Unified Diff: Source/devtools/front_end/PlatformFontsSidebarPane.js

Issue 22875023: DevTools: Front-end for platform font inspection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebasing onto a protocol Created 7 years, 4 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/PlatformFontsSidebarPane.js
diff --git a/Source/devtools/front_end/PlatformFontsSidebarPane.js b/Source/devtools/front_end/PlatformFontsSidebarPane.js
new file mode 100644
index 0000000000000000000000000000000000000000..643a83fb935823c192e2ae4c9c8089cee366bdb5
--- /dev/null
+++ b/Source/devtools/front_end/PlatformFontsSidebarPane.js
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
aandrey 2013/08/22 13:05:35 fix license
lushnikov 2013/08/22 14:52:39 Done.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @constructor
+ * @extends {WebInspector.SidebarPane}
+ */
+WebInspector.PlatformFontsSidebarPane = function()
+{
+ WebInspector.SidebarPane.call(this, "Fonts");
+ this.element.addStyleClass("platform-fonts");
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._innerUpdate, this);
aandrey 2013/08/22 13:05:35 This can be a performance issue. See https://coder
lushnikov 2013/08/22 14:52:39 Added throttling here. Done.
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._innerUpdate, this);
+}
+
+WebInspector.PlatformFontsSidebarPane.MaxElementsInTextMap = 100;
+
+WebInspector.PlatformFontsSidebarPane.prototype = {
+ /**
+ * @param {WebInspector.DOMNode=} node
+ */
+ update: function(node)
+ {
+ if (!node) {
+ this.element.removeChildren();
+ delete this._node;
+ delete this._platformFonts;
+ delete this._computedStyles;
+ return;
+ }
+ this._node = node;
aandrey 2013/08/22 13:05:35 The old callbacks produced by callbackBarrier may
lushnikov 2013/08/22 14:52:39 Done.
+ this._innerUpdate();
+ },
+
+ _innerUpdate: function()
+ {
+ if (!this._node)
+ return;
+ var callbackBarrier = new CallbackBarrier();
+ var platformFontsCallback = callbackBarrier.createCallback(this._platformFontsCallback.bind(this));
+ var computedStyleCallback = callbackBarrier.createCallback(this._computedStyleCallback.bind(this));
+ callbackBarrier.callWhenDone(this._render.bind(this));
+ WebInspector.cssModel.getPlatformFontsForNode(this._node.id, platformFontsCallback);
+ WebInspector.cssModel.getComputedStyleAsync(this._node.id, computedStyleCallback);
+ },
+
+ /**
+ * @param {?Array.<CSSAgent.PlatformFontUsage>} platformFonts
+ */
+ _platformFontsCallback: function(platformFonts)
+ {
+ if (!platformFonts || !platformFonts.length) {
+ delete this._platformFonts;
+ return;
+ }
+
+ this._platformFonts = platformFonts;
+ },
+
+ /**
+ * @param {?WebInspector.CSSStyleDeclaration} computedStyles
+ */
+ _computedStyleCallback: function(computedStyles)
+ {
+ this._computedStyles = computedStyles;
+ },
+
+ _render: function()
+ {
+ this.element.removeChildren();
+ if (!this._platformFonts || !this._computedStyles)
+ return;
+
+ this._platformFonts.sort(function (a, b) {
+ return b.glyphCount - a.glyphCount;
+ }.bind(this));
aandrey 2013/08/22 13:05:35 no need to bind
lushnikov 2013/08/22 14:52:39 Done.
+
+ var cssFontSection = this.element.createChild("div");
aandrey 2013/08/22 13:05:35 this.element.createChild("div", "stats-section mon
lushnikov 2013/08/22 14:52:39 Done.
+ cssFontSection.className = "stats-section monospace";
+ var cssFontPrefix = cssFontSection.createChild("span");
aandrey 2013/08/22 13:05:35 ditto
lushnikov 2013/08/22 14:52:39 Done.
+ cssFontPrefix.className = "webkit-css-property";
+ cssFontPrefix.textContent = "font-family";
+ var cssFontColumn = cssFontSection.createChild("span");
aandrey 2013/08/22 13:05:35 use createTextChild()?
lushnikov 2013/08/22 14:52:39 Done.
+ cssFontColumn.textContent = ":";
+ var cssFontValue = cssFontSection.createChild("span");
aandrey 2013/08/22 13:05:35 cssFontSection.createChild("span", "css-font-value
lushnikov 2013/08/22 14:52:39 Done.
+ cssFontValue.className = "css-font-value";
+ cssFontValue.textContent = this._computedStyles.getLiveProperty("font-family").value + ";";
+
+ var fontStatsSection = document.createElement("div");
+ fontStatsSection.className = "stats-section";
+ for (var i = 0; i < this._platformFonts.length; ++i) {
+ var fontStatElement = fontStatsSection.createChild("div");
aandrey 2013/08/22 13:05:35 ditto here and elsewhere
lushnikov 2013/08/22 14:52:39 Done.
+ fontStatElement.className = "font-stats-item";
+
+ var fontNameElement = fontStatElement.createChild("span");
+ fontNameElement.textContent = this._platformFonts[i].familyName;
+ fontNameElement.className = "font-name";
+
+ var fontDelimeterElement = fontStatElement.createChild("span");
+ fontDelimeterElement.className = "delimeter";
+ fontDelimeterElement.textContent = "—";
+
+ var fontUsageElement = fontStatElement.createChild("span");
+ var usage = this._platformFonts[i].glyphCount;
+ fontUsageElement.textContent = usage + " glyph" + (usage === 1 ? "" : "s");
+ fontUsageElement.className = "font-usage";
+ }
+ this.element.appendChild(fontStatsSection);
+ },
+
+ __proto__: WebInspector.SidebarPane.prototype
+}

Powered by Google App Engine
This is Rietveld 408576698