Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * 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.
| |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 14 * its contributors may be used to endorse or promote products derived | |
| 15 * from this software without specific prior written permission. | |
| 16 * | |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 /** | |
| 30 * @constructor | |
| 31 * @extends {WebInspector.SidebarPane} | |
| 32 */ | |
| 33 WebInspector.PlatformFontsSidebarPane = function() | |
| 34 { | |
| 35 WebInspector.SidebarPane.call(this, "Fonts"); | |
| 36 this.element.addStyleClass("platform-fonts"); | |
| 37 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModi fied, 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.
| |
| 38 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemo ved, this._innerUpdate, this); | |
| 39 } | |
| 40 | |
| 41 WebInspector.PlatformFontsSidebarPane.MaxElementsInTextMap = 100; | |
| 42 | |
| 43 WebInspector.PlatformFontsSidebarPane.prototype = { | |
| 44 /** | |
| 45 * @param {WebInspector.DOMNode=} node | |
| 46 */ | |
| 47 update: function(node) | |
| 48 { | |
| 49 if (!node) { | |
| 50 this.element.removeChildren(); | |
| 51 delete this._node; | |
| 52 delete this._platformFonts; | |
| 53 delete this._computedStyles; | |
| 54 return; | |
| 55 } | |
| 56 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.
| |
| 57 this._innerUpdate(); | |
| 58 }, | |
| 59 | |
| 60 _innerUpdate: function() | |
| 61 { | |
| 62 if (!this._node) | |
| 63 return; | |
| 64 var callbackBarrier = new CallbackBarrier(); | |
| 65 var platformFontsCallback = callbackBarrier.createCallback(this._platfor mFontsCallback.bind(this)); | |
| 66 var computedStyleCallback = callbackBarrier.createCallback(this._compute dStyleCallback.bind(this)); | |
| 67 callbackBarrier.callWhenDone(this._render.bind(this)); | |
| 68 WebInspector.cssModel.getPlatformFontsForNode(this._node.id, platformFon tsCallback); | |
| 69 WebInspector.cssModel.getComputedStyleAsync(this._node.id, computedStyle Callback); | |
| 70 }, | |
| 71 | |
| 72 /** | |
| 73 * @param {?Array.<CSSAgent.PlatformFontUsage>} platformFonts | |
| 74 */ | |
| 75 _platformFontsCallback: function(platformFonts) | |
| 76 { | |
| 77 if (!platformFonts || !platformFonts.length) { | |
| 78 delete this._platformFonts; | |
| 79 return; | |
| 80 } | |
| 81 | |
| 82 this._platformFonts = platformFonts; | |
| 83 }, | |
| 84 | |
| 85 /** | |
| 86 * @param {?WebInspector.CSSStyleDeclaration} computedStyles | |
| 87 */ | |
| 88 _computedStyleCallback: function(computedStyles) | |
| 89 { | |
| 90 this._computedStyles = computedStyles; | |
| 91 }, | |
| 92 | |
| 93 _render: function() | |
| 94 { | |
| 95 this.element.removeChildren(); | |
| 96 if (!this._platformFonts || !this._computedStyles) | |
| 97 return; | |
| 98 | |
| 99 this._platformFonts.sort(function (a, b) { | |
| 100 return b.glyphCount - a.glyphCount; | |
| 101 }.bind(this)); | |
|
aandrey
2013/08/22 13:05:35
no need to bind
lushnikov
2013/08/22 14:52:39
Done.
| |
| 102 | |
| 103 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.
| |
| 104 cssFontSection.className = "stats-section monospace"; | |
| 105 var cssFontPrefix = cssFontSection.createChild("span"); | |
|
aandrey
2013/08/22 13:05:35
ditto
lushnikov
2013/08/22 14:52:39
Done.
| |
| 106 cssFontPrefix.className = "webkit-css-property"; | |
| 107 cssFontPrefix.textContent = "font-family"; | |
| 108 var cssFontColumn = cssFontSection.createChild("span"); | |
|
aandrey
2013/08/22 13:05:35
use createTextChild()?
lushnikov
2013/08/22 14:52:39
Done.
| |
| 109 cssFontColumn.textContent = ":"; | |
| 110 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.
| |
| 111 cssFontValue.className = "css-font-value"; | |
| 112 cssFontValue.textContent = this._computedStyles.getLiveProperty("font-fa mily").value + ";"; | |
| 113 | |
| 114 var fontStatsSection = document.createElement("div"); | |
| 115 fontStatsSection.className = "stats-section"; | |
| 116 for (var i = 0; i < this._platformFonts.length; ++i) { | |
| 117 var fontStatElement = fontStatsSection.createChild("div"); | |
|
aandrey
2013/08/22 13:05:35
ditto here and elsewhere
lushnikov
2013/08/22 14:52:39
Done.
| |
| 118 fontStatElement.className = "font-stats-item"; | |
| 119 | |
| 120 var fontNameElement = fontStatElement.createChild("span"); | |
| 121 fontNameElement.textContent = this._platformFonts[i].familyName; | |
| 122 fontNameElement.className = "font-name"; | |
| 123 | |
| 124 var fontDelimeterElement = fontStatElement.createChild("span"); | |
| 125 fontDelimeterElement.className = "delimeter"; | |
| 126 fontDelimeterElement.textContent = "—"; | |
| 127 | |
| 128 var fontUsageElement = fontStatElement.createChild("span"); | |
| 129 var usage = this._platformFonts[i].glyphCount; | |
| 130 fontUsageElement.textContent = usage + " glyph" + (usage === 1 ? "" : "s"); | |
| 131 fontUsageElement.className = "font-usage"; | |
| 132 } | |
| 133 this.element.appendChild(fontStatsSection); | |
| 134 }, | |
| 135 | |
| 136 __proto__: WebInspector.SidebarPane.prototype | |
| 137 } | |
| OLD | NEW |