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.ThrottledWidget}
34 * @param {!WebInspector.SharedSidebarModel} sharedModel
36 WebInspector
.PlatformFontsWidget = function(sharedModel
)
38 WebInspector
.ThrottledWidget
.call(this);
39 this.element
.classList
.add("platform-fonts");
41 this._sharedModel
= sharedModel
;
42 this._sharedModel
.addEventListener(WebInspector
.SharedSidebarModel
.Events
.ComputedStyleChanged
, this.update
, this);
44 this._sectionTitle
= createElementWithClass("div", "sidebar-separator");
45 this.element
.appendChild(this._sectionTitle
);
46 this._sectionTitle
.textContent
= WebInspector
.UIString("Rendered Fonts");
47 this._fontStatsSection
= this.element
.createChild("div", "stats-section");
51 * @param {!WebInspector.SharedSidebarModel} sharedModel
52 * @return {!WebInspector.ElementsSidebarViewWrapperPane}
54 WebInspector
.PlatformFontsWidget
.createSidebarWrapper = function(sharedModel
)
56 var widget
= new WebInspector
.PlatformFontsWidget(sharedModel
);
57 return new WebInspector
.ElementsSidebarViewWrapperPane(WebInspector
.UIString("Fonts"), widget
)
60 WebInspector
.PlatformFontsWidget
.prototype = {
64 * @return {!Promise.<?>}
68 var cssModel
= this._sharedModel
.cssModel();
69 var node
= this._sharedModel
.node();
70 if (!node
|| !cssModel
)
71 return Promise
.resolve();
73 return cssModel
.platformFontsPromise(node
.id
)
74 .then(this._refreshUI
.bind(this, node
))
78 * @param {!WebInspector.DOMNode} node
79 * @param {?Array.<!CSSAgent.PlatformFontUsage>} platformFonts
81 _refreshUI: function(node
, platformFonts
)
83 if (this._sharedModel
.node() !== node
)
86 this._fontStatsSection
.removeChildren();
88 var isEmptySection
= !platformFonts
|| !platformFonts
.length
;
89 this._sectionTitle
.classList
.toggle("hidden", isEmptySection
);
93 platformFonts
.sort(function (a
, b
) {
94 return b
.glyphCount
- a
.glyphCount
;
96 for (var i
= 0; i
< platformFonts
.length
; ++i
) {
97 var fontStatElement
= this._fontStatsSection
.createChild("div", "font-stats-item");
99 var fontNameElement
= fontStatElement
.createChild("span", "font-name");
100 fontNameElement
.textContent
= platformFonts
[i
].familyName
;
102 var fontDelimeterElement
= fontStatElement
.createChild("span", "delimeter");
103 fontDelimeterElement
.textContent
= "\u2014";
105 var fontUsageElement
= fontStatElement
.createChild("span", "font-usage");
106 var usage
= platformFonts
[i
].glyphCount
;
107 fontUsageElement
.textContent
= usage
=== 1 ? WebInspector
.UIString("%d glyph", usage
) : WebInspector
.UIString("%d glyphs", usage
);
111 __proto__
: WebInspector
.ThrottledWidget
.prototype