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

Side by Side Diff: Source/devtools/front_end/elements/PlatformFontsWidget.js

Issue 1204393002: DevTools: [CSS] promisify CSSStyleModel fetching methods (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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
OLDNEW
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
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 * @protected 64 * @protected
65 */ 65 */
66 doUpdate: function(finishedCallback) 66 doUpdate: function(finishedCallback)
67 { 67 {
68 var cssModel = this._sharedModel.cssModel(); 68 var cssModel = this._sharedModel.cssModel();
69 var node = this._sharedModel.node(); 69 var node = this._sharedModel.node();
70 if (!node || !cssModel) { 70 if (!node || !cssModel) {
71 finishedCallback(); 71 finishedCallback();
72 return; 72 return;
73 } 73 }
74 cssModel.getPlatformFontsForNode(node.id, this._refreshUI.bind(this, nod e, finishedCallback)); 74 cssModel.platformFontsPromise(node.id)
75 .then(this._refreshUI.bind(this, node))
76 .then(finishedCallback)
77 .catch(/** @type {function()} */(finishedCallback));
75 }, 78 },
76 79
77 /** 80 /**
78 * @param {!WebInspector.DOMNode} node 81 * @param {!WebInspector.DOMNode} node
79 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback
80 * @param {?Array.<!CSSAgent.PlatformFontUsage>} platformFonts 82 * @param {?Array.<!CSSAgent.PlatformFontUsage>} platformFonts
81 */ 83 */
82 _refreshUI: function(node, finishedCallback, platformFonts) 84 _refreshUI: function(node, platformFonts)
83 { 85 {
84 if (this._sharedModel.node() !== node) { 86 if (this._sharedModel.node() !== node)
85 finishedCallback();
86 return; 87 return;
87 }
88 88
89 this._fontStatsSection.removeChildren(); 89 this._fontStatsSection.removeChildren();
90 90
91 var isEmptySection = !platformFonts || !platformFonts.length; 91 var isEmptySection = !platformFonts || !platformFonts.length;
92 this._sectionTitle.classList.toggle("hidden", isEmptySection); 92 this._sectionTitle.classList.toggle("hidden", isEmptySection);
93 if (isEmptySection) { 93 if (isEmptySection)
94 finishedCallback();
95 return; 94 return;
96 } 95
97 platformFonts.sort(function (a, b) { 96 platformFonts.sort(function (a, b) {
98 return b.glyphCount - a.glyphCount; 97 return b.glyphCount - a.glyphCount;
99 }); 98 });
100 for (var i = 0; i < platformFonts.length; ++i) { 99 for (var i = 0; i < platformFonts.length; ++i) {
101 var fontStatElement = this._fontStatsSection.createChild("div", "fon t-stats-item"); 100 var fontStatElement = this._fontStatsSection.createChild("div", "fon t-stats-item");
102 101
103 var fontNameElement = fontStatElement.createChild("span", "font-name "); 102 var fontNameElement = fontStatElement.createChild("span", "font-name ");
104 fontNameElement.textContent = platformFonts[i].familyName; 103 fontNameElement.textContent = platformFonts[i].familyName;
105 104
106 var fontDelimeterElement = fontStatElement.createChild("span", "deli meter"); 105 var fontDelimeterElement = fontStatElement.createChild("span", "deli meter");
107 fontDelimeterElement.textContent = "\u2014"; 106 fontDelimeterElement.textContent = "\u2014";
108 107
109 var fontUsageElement = fontStatElement.createChild("span", "font-usa ge"); 108 var fontUsageElement = fontStatElement.createChild("span", "font-usa ge");
110 var usage = platformFonts[i].glyphCount; 109 var usage = platformFonts[i].glyphCount;
111 fontUsageElement.textContent = usage === 1 ? WebInspector.UIString(" %d glyph", usage) : WebInspector.UIString("%d glyphs", usage); 110 fontUsageElement.textContent = usage === 1 ? WebInspector.UIString(" %d glyph", usage) : WebInspector.UIString("%d glyphs", usage);
112 } 111 }
113 finishedCallback();
114 }, 112 },
115 113
116 __proto__: WebInspector.ThrottledWidget.prototype 114 __proto__: WebInspector.ThrottledWidget.prototype
117 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698