Permalink
Browse files

Add more extensive type annotations so we get improved type checking.

  • Loading branch information...
bramstein committed Mar 6, 2013
1 parent a60a461 commit 29309ab768078bab58b264ef0c85ba498aa6ca9e
@@ -10,6 +10,7 @@ goog.provide('webfont.AscenderScript');
* });
*
* @constructor
+ * @implements {webfont.FontModule}
*/
webfont.AscenderScript = function(domHelper, configuration) {
this.domHelper_ = domHelper;
View
@@ -27,10 +27,17 @@ goog.scope(function () {
FontWatcher = webfont.FontWatcher,
Size = webfont.Size;
+ /**
+ * @param {string} name
+ * @param {webfont.FontModuleFactory} factory
+ */
WebFont.prototype.addModule = function(name, factory) {
this.fontModuleLoader_.addModuleFactory(name, factory);
};
+ /**
+ * @param {Object} configuration
+ */
WebFont.prototype.load = function(configuration) {
var context = configuration['context'] || this.mainWindow_;
this.domHelper_ = new DomHelper(this.mainWindow_, context);
@@ -45,10 +52,18 @@ goog.scope(function () {
}
};
+ /**
+ * @param {webfont.FontModule} module
+ * @param {webfont.EventDispatcher} eventDispatcher
+ * @param {webfont.FontWatcher} fontWatcher
+ * @param {boolean} support
+ */
WebFont.prototype.isModuleSupportingUserAgent_ = function(module, eventDispatcher,
fontWatcher, support) {
var fontWatchRunnerCtor = module.getFontWatchRunnerCtor ?
- module.getFontWatchRunnerCtor() : webfont.FontWatchRunner;
+ module.getFontWatchRunnerCtor() : webfont.FontWatchRunner,
+ that = this;
+
if (!support) {
var allModulesLoaded = --this.moduleLoading_ == 0;
@@ -63,21 +78,46 @@ goog.scope(function () {
fontWatcher.watch([], {}, {}, fontWatchRunnerCtor, allModulesLoaded);
return;
}
- module.load(goog.bind(this.onModuleReady_, this, eventDispatcher,
- fontWatcher, fontWatchRunnerCtor));
+
+ module.load(function (fontFamilies, fontVariations) {
+ that.onModuleReady_(eventDispatcher, fontWatcher, fontWatchRunnerCtor, fontFamilies, fontVariations);
+ });
};
+ /**
+ * @param {webfont.EventDispatcher} eventDispatcher
+ * @param {webfont.FontWatcher} fontWatcher
+ * @param {function(new:webfont.FontWatchRunner,
+ * function(string, string),
+ * function(string, string),
+ * webfont.DomHelper,
+ * string,
+ * string,
+ * webfont.BrowserInfo,
+ * number=,
+ * Object.<string, boolean>=,
+ * string=)} fontWatchRunnerCtor
+ * @param {webfont.FontFamilies} fontFamilies
+ * @param {webfont.FontVariations=} opt_fontVariations
+ * @param {webfont.FontTestStrings=} opt_fontTestStrings
+ */
WebFont.prototype.onModuleReady_ = function(eventDispatcher, fontWatcher,
- fontWatchRunnerCtor, fontFamilies, opt_fontDescriptions, opt_fontTestStrings) {
+ fontWatchRunnerCtor, fontFamilies, opt_fontVariations, opt_fontTestStrings) {
var allModulesLoaded = --this.moduleLoading_ == 0;
if (allModulesLoaded) {
eventDispatcher.dispatchLoading();
}
- setTimeout(goog.bind(fontWatcher.watch, fontWatcher, fontFamilies, opt_fontDescriptions || {}, opt_fontTestStrings || {}, fontWatchRunnerCtor, allModulesLoaded), 0);
+ setTimeout(function () {
+ fontWatcher.watch(fontFamilies, opt_fontVariations || {}, opt_fontTestStrings || {}, fontWatchRunnerCtor, allModulesLoaded);
+ }, 0);
};
+ /**
+ * @param {webfont.EventDispatcher} eventDispatcher
+ * @param {Object} configuration
+ */
WebFont.prototype.load_ = function(eventDispatcher, configuration) {
var modules = this.fontModuleLoader_.getModules(configuration, this.domHelper_),
timeout = configuration['timeout'],
@@ -1,19 +1,56 @@
goog.provide('webfont.FontModuleLoader');
+goog.provide('webfont.FontModule');
+goog.provide('webfont.FontModuleFactory');
+
+/**
+ * @interface
+ */
+webfont.FontModule = function () {};
+
+goog.scope(function () {
+ var FontModule = webfont.FontModule;
+
+ /**
+ * @param {webfont.UserAgent} userAgent
+ * @param {function(boolean)} support
+ */
+ FontModule.prototype.supportUserAgent = function (userAgent, support) {};
+
+ /**
+ * @param {function(webfont.FontFamilies, webfont.FontVariations=, webfont.FontTestStrings=)} onReady
+ */
+ FontModule.prototype.load = function (onReady) {};
+});
+
+/** @typedef {function(Object, webfont.DomHelper): webfont.FontModule} */
+webfont.FontModuleFactory;
/**
* @constructor
*/
webfont.FontModuleLoader = function() {
+ /**
+ * @type {Object.<string, webfont.FontModuleFactory>}
+ */
this.modules_ = {};
};
goog.scope(function () {
var FontModuleLoader = webfont.FontModuleLoader;
+ /**
+ * @param {string} name
+ * @param {webfont.FontModuleFactory} factory
+ */
FontModuleLoader.prototype.addModuleFactory = function(name, factory) {
this.modules_[name] = factory;
};
+ /**
+ * @param {Object} configuration
+ * @param {webfont.DomHelper} domHelper
+ * @return {Array.<webfont.FontModule>}
+ */
FontModuleLoader.prototype.getModules = function(configuration, domHelper) {
var modules = [];
View
@@ -36,9 +36,16 @@ goog.scope(function () {
* of each family to watch. Described with FVD.
* @param {Object.<string, string>} fontTestStrings The font test strings for
* each family.
- * @param {function(new:webfont.FontWatchRunner, function(string, string),
- * function(string, string), webfont.DomHelper,
- * string, string, webfont.BrowserInfo, number=, Object.<string, boolean>=, string=)} fontWatchRunnerCtor The font watch runner constructor.
+ * @param {function(new:webfont.FontWatchRunner,
+ * function(string, string),
+ * function(string, string),
+ * webfont.DomHelper,
+ * string,
+ * string,
+ * webfont.BrowserInfo,
+ * number=,
+ * Object.<string, boolean>=,
+ * string=)} fontWatchRunnerCtor The font watch runner constructor.
* @param {boolean} last True if this is the last set of families to watch.
*/
FontWatcher.prototype.watch = function(fontFamilies, fontDescriptions,
View
@@ -4,6 +4,21 @@ goog.require('webfont.UserAgentParser');
goog.require('webfont.FontModuleLoader');
goog.require('webfont.WebFont');
+/**
+ * @typedef {Array.<string>}
+ */
+webfont.FontFamilies;
+
+/**
+ * @typedef {Object.<string, Array.<string>>}
+ */
+webfont.FontVariations;
+
+/**
+ * @typedef {Object.<string, Array.<string>>}
+ */
+webfont.FontTestStrings;
+
// Name of the global object.
var globalName = 'WebFont';
View
@@ -9,6 +9,7 @@ goog.provide('webfont.CustomCss');
* });
*
* @constructor
+ * @implements {webfont.FontModule}
*/
webfont.CustomCss = function(domHelper, configuration) {
this.domHelper_ = domHelper;
@@ -4,6 +4,7 @@ goog.require('webfont.FontVariationDescription');
/**
* @constructor
+ * @implements {webfont.FontModule}
*/
webfont.FontdeckScript = function(domHelper, configuration) {
this.domHelper_ = domHelper;
@@ -7,6 +7,7 @@ goog.require('webfont.LastResortWebKitFontWatchRunner');
/**
* @constructor
+ * @implements {webfont.FontModule}
*/
webfont.GoogleFontApi = function(userAgent, domHelper, configuration) {
this.userAgent_ = userAgent;
@@ -75,6 +75,9 @@ goog.scope(function () {
return webKitLastResortFontSizes;
};
+ /**
+ * @override
+ */
LastResortWebKitFontWatchRunner.prototype.check_ = function() {
var sizeA = this.fontRulerA_.getSize();
var sizeB = this.fontRulerB_.getSize();
@@ -10,6 +10,7 @@ projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'//this is your Fonts.com Web fo
/**
* @constructor
+ * @implements {webfont.FontModule}
*/
webfont.MonotypeScript = function (userAgent, domHelper, configuration) {
this.userAgent_ = userAgent;
@@ -2,6 +2,7 @@ goog.provide('webfont.TypekitScript');
/**
* @constructor
+ * @implements {webfont.FontModule}
*/
webfont.TypekitScript = function(domHelper, configuration) {
this.domHelper_ = domHelper;

0 comments on commit 29309ab

Please sign in to comment.