Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 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 | |
| 13 * distribution. | |
| 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. | |
| 17 * | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 /** | |
| 32 * @constructor | |
| 33 * @extends {WebInspector.SidebarPane} | |
| 34 */ | |
| 35 WebInspector.PlatformFontsSidebarPane = function() | |
| 36 { | |
| 37 WebInspector.SidebarPane.call(this, "Fonts"); | |
| 38 this.element.addStyleClass("platform-fonts"); | |
| 39 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModi fied, this._onNodeChange.bind(this)); | |
| 40 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemo ved, this._onNodeChange.bind(this)); | |
| 41 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Characte rDataModified, this._onNodeChange.bind(this)); | |
| 42 } | |
| 43 | |
| 44 WebInspector.PlatformFontsSidebarPane.MaxElementsInTextMap = 100; | |
| 45 | |
| 46 WebInspector.PlatformFontsSidebarPane.prototype = { | |
| 47 _onNodeChange: function() | |
| 48 { | |
| 49 if (this._innerUpdateTimeout) | |
| 50 clearTimeout(this._innerUpdateTimeout); | |
| 51 this._innerUpdateTimeout = setTimeout(this._innerUpdate.bind(this), 100) ; | |
|
aandrey
2013/08/22 18:10:16
If _onNodeChanged is fired every 100ms for some pe
| |
| 52 }, | |
| 53 | |
| 54 /** | |
| 55 * @param {WebInspector.DOMNode=} node | |
| 56 */ | |
| 57 update: function(node) | |
| 58 { | |
| 59 if (!node) { | |
| 60 this.element.removeChildren(); | |
| 61 delete this._node; | |
| 62 delete this._platformFonts; | |
| 63 delete this._computedStyles; | |
| 64 return; | |
| 65 } | |
| 66 this._node = node; | |
| 67 this._innerUpdate(); | |
| 68 }, | |
| 69 | |
| 70 _innerUpdate: function() | |
| 71 { | |
| 72 if (this._innerUpdateTimeout) { | |
| 73 clearTimeout(this._innerUpdateTimeout); | |
| 74 delete this._innerUpdateTimeout; | |
| 75 } | |
| 76 if (!this._node) | |
| 77 return; | |
| 78 var callbackBarrier = new CallbackBarrier(); | |
| 79 var platformFontsCallback = callbackBarrier.createCallback(this._platfor mFontsCallback.bind(this, this._node)); | |
| 80 var computedStyleCallback = callbackBarrier.createCallback(this._compute dStyleCallback.bind(this, this._node)); | |
| 81 callbackBarrier.callWhenDone(this._render.bind(this, this._node)); | |
| 82 WebInspector.cssModel.getPlatformFontsForNode(this._node.id, platformFon tsCallback); | |
|
pfeldman
2013/08/22 16:39:51
Serve font family as a part of this request.
| |
| 83 WebInspector.cssModel.getComputedStyleAsync(this._node.id, computedStyle Callback); | |
|
pfeldman
2013/08/22 16:39:51
This operation is extremely expensive (up to 1 sec
aandrey
2013/08/22 18:30:47
Yeah, you should not call it again until you get t
| |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * @param {WebInspector.DOMNode} node | |
| 88 * @param {?Array.<CSSAgent.PlatformFontUsage>} platformFonts | |
| 89 */ | |
| 90 _platformFontsCallback: function(node, platformFonts) | |
| 91 { | |
| 92 if (this._node !== node) | |
| 93 return; | |
| 94 if (!platformFonts || !platformFonts.length) { | |
| 95 delete this._platformFonts; | |
| 96 return; | |
| 97 } | |
| 98 | |
| 99 this._platformFonts = platformFonts; | |
| 100 }, | |
| 101 | |
| 102 /** | |
| 103 * @param {WebInspector.DOMNode} node | |
| 104 * @param {?WebInspector.CSSStyleDeclaration} computedStyles | |
| 105 */ | |
| 106 _computedStyleCallback: function(node, computedStyles) | |
| 107 { | |
| 108 if (this._node !== node) | |
| 109 return; | |
| 110 this._computedStyles = computedStyles; | |
| 111 }, | |
| 112 | |
| 113 /** | |
| 114 * @param {WebInspector.DOMNode} node | |
| 115 */ | |
| 116 _render: function(node) | |
| 117 { | |
| 118 if (this._node !== node) | |
| 119 return; | |
| 120 this.element.removeChildren(); | |
| 121 if (!this._platformFonts || !this._computedStyles) | |
| 122 return; | |
| 123 | |
| 124 this._platformFonts.sort(function (a, b) { | |
| 125 return b.glyphCount - a.glyphCount; | |
| 126 }); | |
| 127 | |
| 128 var cssFontSection = this.element.createChild("div", "stats-section mono space"); | |
| 129 var cssFontPrefix = cssFontSection.createChild("span", "webkit-css-prope rty"); | |
| 130 cssFontPrefix.textContent = "font-family"; | |
|
pfeldman
2013/08/22 16:39:51
You don't have to re-create this part.
| |
| 131 cssFontSection.createTextChild(":"); | |
| 132 var cssFontValue = cssFontSection.createChild("span", "css-font-value"); | |
| 133 cssFontValue.textContent = this._computedStyles.getLiveProperty("font-fa mily").value + ";"; | |
| 134 | |
| 135 var fontStatsSection = document.createElement("div"); | |
| 136 fontStatsSection.className = "stats-section"; | |
| 137 for (var i = 0; i < this._platformFonts.length; ++i) { | |
| 138 var fontStatElement = fontStatsSection.createChild("div", "font-stat s-item"); | |
| 139 | |
| 140 var fontNameElement = fontStatElement.createChild("span", "font-name "); | |
| 141 fontNameElement.textContent = this._platformFonts[i].familyName; | |
| 142 | |
| 143 var fontDelimeterElement = fontStatElement.createChild("span", "deli meter"); | |
| 144 fontDelimeterElement.textContent = "—"; | |
| 145 | |
| 146 var fontUsageElement = fontStatElement.createChild("span", "font-usa ge"); | |
| 147 var usage = this._platformFonts[i].glyphCount; | |
| 148 fontUsageElement.textContent = usage + " glyph" + (usage === 1 ? "" : "s"); | |
| 149 } | |
| 150 this.element.appendChild(fontStatsSection); | |
| 151 }, | |
| 152 | |
| 153 __proto__: WebInspector.SidebarPane.prototype | |
| 154 } | |
| OLD | NEW |