2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.ElementsSidebarPane}
35 WebInspector.PlatformFontsSidebarPane = function()
37 WebInspector.ElementsSidebarPane.call(this, WebInspector.UIString("Fonts"));
38 this.element.classList.add("platform-fonts");
40 this._sectionTitle = createElementWithClass("div", "sidebar-separator");
41 this.element.insertBefore(this._sectionTitle, this.bodyElement);
42 this._sectionTitle.textContent = WebInspector.UIString("Rendered Fonts");
43 this._fontStatsSection = this.bodyElement.createChild("div", "stats-section");
46 WebInspector.PlatformFontsSidebarPane.prototype = {
48 * @param {?WebInspector.DOMNode} node
50 setNode: function(node)
52 WebInspector.ElementsSidebarPane.prototype.setNode.call(this, node);
53 this._updateTarget(node.target());
57 * @param {!WebInspector.Target} target
59 _updateTarget: function(target)
61 if (this._target === target)
64 this._target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.StyleSheetAdded, this.update, this);
65 this._target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.StyleSheetRemoved, this.update, this);
66 this._target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this.update, this);
67 this._target.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged, this.update, this);
68 this._target.domModel.removeEventListener(WebInspector.DOMModel.Events.AttrModified, this.update, this);
69 this._target.domModel.removeEventListener(WebInspector.DOMModel.Events.AttrRemoved, this.update, this);
70 this._target.domModel.removeEventListener(WebInspector.DOMModel.Events.CharacterDataModified, this.update, this);
72 this._target = target;
73 this._target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetAdded, this.update, this);
74 this._target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetRemoved, this.update, this);
75 this._target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this.update, this);
76 this._target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged, this.update, this);
77 this._target.domModel.addEventListener(WebInspector.DOMModel.Events.AttrModified, this.update, this);
78 this._target.domModel.addEventListener(WebInspector.DOMModel.Events.AttrRemoved, this.update, this);
79 this._target.domModel.addEventListener(WebInspector.DOMModel.Events.CharacterDataModified, this.update, this);
83 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback
86 doUpdate: function(finishedCallback)
90 this._target.cssModel.getPlatformFontsForNode(this.node().id, this._refreshUI.bind(this, /** @type {!WebInspector.DOMNode} */ (this.node()), finishedCallback));
94 * @param {!WebInspector.DOMNode} node
95 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback
96 * @param {?string} cssFamilyName
97 * @param {?Array.<!CSSAgent.PlatformFontUsage>} platformFonts
99 _refreshUI: function(node, finishedCallback, cssFamilyName, platformFonts)
101 if (this.node() !== node) {
106 this._fontStatsSection.removeChildren();
108 var isEmptySection = !platformFonts || !platformFonts.length;
109 this._sectionTitle.classList.toggle("hidden", isEmptySection);
110 if (isEmptySection) {
114 platformFonts.sort(function (a, b) {
115 return b.glyphCount - a.glyphCount;
117 for (var i = 0; i < platformFonts.length; ++i) {
118 var fontStatElement = this._fontStatsSection.createChild("div", "font-stats-item");
120 var fontNameElement = fontStatElement.createChild("span", "font-name");
121 fontNameElement.textContent = platformFonts[i].familyName;
123 var fontDelimeterElement = fontStatElement.createChild("span", "delimeter");
124 fontDelimeterElement.textContent = "\u2014";
126 var fontUsageElement = fontStatElement.createChild("span", "font-usage");
127 var usage = platformFonts[i].glyphCount;
128 fontUsageElement.textContent = usage === 1 ? WebInspector.UIString("%d glyph", usage) : WebInspector.UIString("%d glyphs", usage);
133 __proto__: WebInspector.ElementsSidebarPane.prototype