| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | |
| 31 /** | 30 /** |
| 32 * @constructor | 31 * @unrestricted |
| 33 * @extends {WebInspector.ThrottledWidget} | |
| 34 * @param {!WebInspector.ComputedStyleModel} sharedModel | |
| 35 */ | 32 */ |
| 36 WebInspector.PlatformFontsWidget = function(sharedModel) | 33 WebInspector.PlatformFontsWidget = class extends WebInspector.ThrottledWidget { |
| 37 { | 34 /** |
| 38 WebInspector.ThrottledWidget.call(this, true); | 35 * @param {!WebInspector.ComputedStyleModel} sharedModel |
| 39 this.registerRequiredCSS("elements/platformFontsWidget.css"); | 36 */ |
| 37 constructor(sharedModel) { |
| 38 super(true); |
| 39 this.registerRequiredCSS('elements/platformFontsWidget.css'); |
| 40 | 40 |
| 41 this._sharedModel = sharedModel; | 41 this._sharedModel = sharedModel; |
| 42 this._sharedModel.addEventListener(WebInspector.ComputedStyleModel.Events.Co
mputedStyleChanged, this.update, this); | 42 this._sharedModel.addEventListener(WebInspector.ComputedStyleModel.Events.Co
mputedStyleChanged, this.update, this); |
| 43 | 43 |
| 44 this._sectionTitle = createElementWithClass("div", "title"); | 44 this._sectionTitle = createElementWithClass('div', 'title'); |
| 45 this.contentElement.classList.add("platform-fonts"); | 45 this.contentElement.classList.add('platform-fonts'); |
| 46 this.contentElement.appendChild(this._sectionTitle); | 46 this.contentElement.appendChild(this._sectionTitle); |
| 47 this._sectionTitle.textContent = WebInspector.UIString("Rendered Fonts"); | 47 this._sectionTitle.textContent = WebInspector.UIString('Rendered Fonts'); |
| 48 this._fontStatsSection = this.contentElement.createChild("div", "stats-secti
on"); | 48 this._fontStatsSection = this.contentElement.createChild('div', 'stats-secti
on'); |
| 49 } |
| 50 |
| 51 /** |
| 52 * @override |
| 53 * @protected |
| 54 * @return {!Promise.<?>} |
| 55 */ |
| 56 doUpdate() { |
| 57 var cssModel = this._sharedModel.cssModel(); |
| 58 var node = this._sharedModel.node(); |
| 59 if (!node || !cssModel) |
| 60 return Promise.resolve(); |
| 61 |
| 62 return cssModel.platformFontsPromise(node.id).then(this._refreshUI.bind(this
, node)); |
| 63 } |
| 64 |
| 65 /** |
| 66 * @param {!WebInspector.DOMNode} node |
| 67 * @param {?Array.<!CSSAgent.PlatformFontUsage>} platformFonts |
| 68 */ |
| 69 _refreshUI(node, platformFonts) { |
| 70 if (this._sharedModel.node() !== node) |
| 71 return; |
| 72 |
| 73 this._fontStatsSection.removeChildren(); |
| 74 |
| 75 var isEmptySection = !platformFonts || !platformFonts.length; |
| 76 this._sectionTitle.classList.toggle('hidden', isEmptySection); |
| 77 if (isEmptySection) |
| 78 return; |
| 79 |
| 80 platformFonts.sort(function(a, b) { |
| 81 return b.glyphCount - a.glyphCount; |
| 82 }); |
| 83 for (var i = 0; i < platformFonts.length; ++i) { |
| 84 var fontStatElement = this._fontStatsSection.createChild('div', 'font-stat
s-item'); |
| 85 |
| 86 var fontNameElement = fontStatElement.createChild('span', 'font-name'); |
| 87 fontNameElement.textContent = platformFonts[i].familyName; |
| 88 |
| 89 var fontDelimeterElement = fontStatElement.createChild('span', 'font-delim
eter'); |
| 90 fontDelimeterElement.textContent = '\u2014'; |
| 91 |
| 92 var fontOrigin = fontStatElement.createChild('span'); |
| 93 fontOrigin.textContent = platformFonts[i].isCustomFont ? WebInspector.UISt
ring('Network resource') : |
| 94 WebInspector.UISt
ring('Local file'); |
| 95 |
| 96 var fontUsageElement = fontStatElement.createChild('span', 'font-usage'); |
| 97 var usage = platformFonts[i].glyphCount; |
| 98 fontUsageElement.textContent = |
| 99 usage === 1 ? WebInspector.UIString('(%d glyph)', usage) : WebInspecto
r.UIString('(%d glyphs)', usage); |
| 100 } |
| 101 } |
| 49 }; | 102 }; |
| 50 | |
| 51 WebInspector.PlatformFontsWidget.prototype = { | |
| 52 /** | |
| 53 * @override | |
| 54 * @protected | |
| 55 * @return {!Promise.<?>} | |
| 56 */ | |
| 57 doUpdate: function() | |
| 58 { | |
| 59 var cssModel = this._sharedModel.cssModel(); | |
| 60 var node = this._sharedModel.node(); | |
| 61 if (!node || !cssModel) | |
| 62 return Promise.resolve(); | |
| 63 | |
| 64 return cssModel.platformFontsPromise(node.id) | |
| 65 .then(this._refreshUI.bind(this, node)); | |
| 66 }, | |
| 67 | |
| 68 /** | |
| 69 * @param {!WebInspector.DOMNode} node | |
| 70 * @param {?Array.<!CSSAgent.PlatformFontUsage>} platformFonts | |
| 71 */ | |
| 72 _refreshUI: function(node, platformFonts) | |
| 73 { | |
| 74 if (this._sharedModel.node() !== node) | |
| 75 return; | |
| 76 | |
| 77 this._fontStatsSection.removeChildren(); | |
| 78 | |
| 79 var isEmptySection = !platformFonts || !platformFonts.length; | |
| 80 this._sectionTitle.classList.toggle("hidden", isEmptySection); | |
| 81 if (isEmptySection) | |
| 82 return; | |
| 83 | |
| 84 platformFonts.sort(function(a, b) { | |
| 85 return b.glyphCount - a.glyphCount; | |
| 86 }); | |
| 87 for (var i = 0; i < platformFonts.length; ++i) { | |
| 88 var fontStatElement = this._fontStatsSection.createChild("div", "fon
t-stats-item"); | |
| 89 | |
| 90 var fontNameElement = fontStatElement.createChild("span", "font-name
"); | |
| 91 fontNameElement.textContent = platformFonts[i].familyName; | |
| 92 | |
| 93 var fontDelimeterElement = fontStatElement.createChild("span", "font
-delimeter"); | |
| 94 fontDelimeterElement.textContent = "\u2014"; | |
| 95 | |
| 96 var fontOrigin = fontStatElement.createChild("span"); | |
| 97 fontOrigin.textContent = platformFonts[i].isCustomFont ? WebInspecto
r.UIString("Network resource") : WebInspector.UIString("Local file"); | |
| 98 | |
| 99 var fontUsageElement = fontStatElement.createChild("span", "font-usa
ge"); | |
| 100 var usage = platformFonts[i].glyphCount; | |
| 101 fontUsageElement.textContent = usage === 1 ? WebInspector.UIString("
(%d glyph)", usage) : WebInspector.UIString("(%d glyphs)", usage); | |
| 102 } | |
| 103 }, | |
| 104 | |
| 105 __proto__: WebInspector.ThrottledWidget.prototype | |
| 106 }; | |
| OLD | NEW |