blob: 6bfacbc058fe48d66c1528feb90c3ed2cf15891b [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/base/extension_registry.html">
<link rel="import" href="/base/guid.html">
<script>
'use strict';
tv.exportTo('tv.c.trace_model', function() {
/**
* Annotation is a base class that represents all annotation objects that
* can be drawn on the timeline.
*
* @constructor
*/
function Annotation() {
this.guid_ = tv.b.GUID.allocate();
this.view_ = undefined;
};
Annotation.fromDictIfPossible = function(args) {
if (args.typeName === undefined)
throw new Error('Missing typeName argument');
var typeInfo = Annotation.findTypeInfoMatching(function(typeInfo) {
return typeInfo.metadata.typeName === args.typeName;
});
if (typeInfo === undefined)
return undefined;
return typeInfo.constructor.fromDict(args);
};
Annotation.fromDict = function() {
throw new Error('Not implemented');
}
Annotation.prototype = {
get guid() {
return this.guid_;
},
// Invoked by trace model when this annotation is removed.
onRemove: function() {
},
toDict: function() {
throw new Error('Not implemented');
},
getOrCreateView: function(viewport) {
if (!this.view_)
this.view_ = this.createView_(viewport);
return this.view_;
},
createView_: function() {
throw new Error('Not implemented');
}
};
var options = new tv.b.ExtensionRegistryOptions(tv.b. BASIC_REGISTRY_MODE);
options.mandatoryBaseType = Annotation;
tv.b.decorateExtensionRegistry(Annotation, options);
Annotation.addEventListener('will-register', function(e) {
if (!e.typeInfo.constructor.hasOwnProperty('fromDict'))
throw new Error('Must have fromDict method');
if (!e.typeInfo.metadata.typeName)
throw new Error('Registered Annotations must provide typeName');
});
return {
Annotation: Annotation
};
});
</script>