Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: Source/devtools/front_end/PlatformFontsSidebarPane.js

Issue 22875023: DevTools: Front-end for platform font inspection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: addressed comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/ElementsPanel.js ('k') | Source/devtools/front_end/elementsPanel.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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);
aandrey 2013/08/22 15:22:32 return; otherwise you call setTimeout on every ev
lushnikov 2013/08/22 15:52:46 Still setting timeout is much faster then renderin
51 this._innerUpdateTimeout = setTimeout(this._innerUpdate.bind(this), 100) ;
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._node)
aandrey 2013/08/22 15:22:32 if (this._innerUpdateTimeout) { clear... delet
lushnikov 2013/08/22 15:52:46 Done.
73 return;
74 var callbackBarrier = new CallbackBarrier();
75 var platformFontsCallback = callbackBarrier.createCallback(this._platfor mFontsCallback.bind(this));
76 var computedStyleCallback = callbackBarrier.createCallback(this._compute dStyleCallback.bind(this));
77 callbackBarrier.callWhenDone(this._render.bind(this, this._node));
78 WebInspector.cssModel.getPlatformFontsForNode(this._node.id, platformFon tsCallback);
79 WebInspector.cssModel.getComputedStyleAsync(this._node.id, computedStyle Callback);
80 },
81
82 /**
83 * @param {?Array.<CSSAgent.PlatformFontUsage>} platformFonts
84 */
85 _platformFontsCallback: function(platformFonts)
86 {
87 if (!platformFonts || !platformFonts.length) {
88 delete this._platformFonts;
89 return;
90 }
91
92 this._platformFonts = platformFonts;
aandrey 2013/08/22 15:16:43 this async callback can be called for an old node
lushnikov 2013/08/22 15:52:46 Done.
93 },
94
95 /**
96 * @param {?WebInspector.CSSStyleDeclaration} computedStyles
97 */
98 _computedStyleCallback: function(computedStyles)
99 {
100 this._computedStyles = computedStyles;
aandrey 2013/08/22 15:16:43 ditto
lushnikov 2013/08/22 15:52:46 Done.
101 },
102
103 _render: function(node)
aandrey 2013/08/22 15:16:43 jsdocs plz
lushnikov 2013/08/22 15:52:46 Done.
104 {
105 if (this._node !== node)
106 return;
107 this.element.removeChildren();
108 if (!this._platformFonts || !this._computedStyles)
109 return;
110
111 this._platformFonts.sort(function (a, b) {
112 return b.glyphCount - a.glyphCount;
113 });
114
115 var cssFontSection = this.element.createChild("div", "stats-section mono space");
116 var cssFontPrefix = cssFontSection.createChild("span", "webkit-css-prope rty");
117 cssFontPrefix.textContent = "font-family";
118 cssFontSection.createTextChild(":");
119 var cssFontValue = cssFontSection.createChild("span", "css-font-value");
120 cssFontValue.textContent = this._computedStyles.getLiveProperty("font-fa mily").value + ";";
121
122 var fontStatsSection = document.createElement("div");
123 fontStatsSection.className = "stats-section";
124 for (var i = 0; i < this._platformFonts.length; ++i) {
125 var fontStatElement = fontStatsSection.createChild("div", "font-stat s-item");
126
127 var fontNameElement = fontStatElement.createChild("span", "font-name ");
128 fontNameElement.textContent = this._platformFonts[i].familyName;
129
130 var fontDelimeterElement = fontStatElement.createChild("span", "deli meter");
131 fontDelimeterElement.textContent = "—";
132
133 var fontUsageElement = fontStatElement.createChild("span", "font-usa ge");
134 var usage = this._platformFonts[i].glyphCount;
135 fontUsageElement.textContent = usage + " glyph" + (usage === 1 ? "" : "s");
136 }
137 this.element.appendChild(fontStatsSection);
138 },
139
140 __proto__: WebInspector.SidebarPane.prototype
141 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ElementsPanel.js ('k') | Source/devtools/front_end/elementsPanel.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698