OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/base/extension_registry.html"> | 8 <link rel="import" href="/tracing/base/extension_registry.html"> |
9 <link rel="import" href="/tracing/base/guid.html"> | 9 <link rel="import" href="/tracing/base/guid.html"> |
10 | 10 |
11 <script> | 11 <script> |
12 'use strict'; | 12 'use strict'; |
13 | 13 |
14 tr.exportTo('tr.model', function() { | 14 tr.exportTo('tr.model', function() { |
15 /** | 15 /** |
16 * Annotation is a base class that represents all annotation objects that | 16 * Annotation is a base class that represents all annotation objects that |
17 * can be drawn on the timeline. | 17 * can be drawn on the timeline. |
18 * | 18 * |
19 * @constructor | 19 * @constructor |
20 */ | 20 */ |
21 function Annotation() { | 21 function Annotation() { |
22 this.guid_ = tr.b.GUID.allocateSimple(); | 22 this.guid_ = tr.b.GUID.allocateSimple(); |
23 this.view_ = undefined; | 23 this.view_ = undefined; |
24 } | 24 } |
25 | 25 |
26 Annotation.fromDictIfPossible = function(args) { | 26 Annotation.fromDictIfPossible = function(args) { |
27 if (args.typeName === undefined) | 27 if (args.typeName === undefined) { |
28 throw new Error('Missing typeName argument'); | 28 throw new Error('Missing typeName argument'); |
| 29 } |
29 | 30 |
30 var typeInfo = Annotation.findTypeInfoMatching(function(typeInfo) { | 31 var typeInfo = Annotation.findTypeInfoMatching(function(typeInfo) { |
31 return typeInfo.metadata.typeName === args.typeName; | 32 return typeInfo.metadata.typeName === args.typeName; |
32 }); | 33 }); |
33 | 34 |
34 if (typeInfo === undefined) | 35 if (typeInfo === undefined) return undefined; |
35 return undefined; | |
36 | 36 |
37 return typeInfo.constructor.fromDict(args); | 37 return typeInfo.constructor.fromDict(args); |
38 }; | 38 }; |
39 | 39 |
40 Annotation.fromDict = function() { | 40 Annotation.fromDict = function() { |
41 throw new Error('Not implemented'); | 41 throw new Error('Not implemented'); |
42 }; | 42 }; |
43 | 43 |
44 Annotation.prototype = { | 44 Annotation.prototype = { |
45 get guid() { | 45 get guid() { |
46 return this.guid_; | 46 return this.guid_; |
47 }, | 47 }, |
48 | 48 |
49 // Invoked by trace model when this annotation is removed. | 49 // Invoked by trace model when this annotation is removed. |
50 onRemove: function() { | 50 onRemove: function() { |
51 }, | 51 }, |
52 | 52 |
53 toDict: function() { | 53 toDict: function() { |
54 throw new Error('Not implemented'); | 54 throw new Error('Not implemented'); |
55 }, | 55 }, |
56 | 56 |
57 getOrCreateView: function(viewport) { | 57 getOrCreateView: function(viewport) { |
58 if (!this.view_) | 58 if (!this.view_) { |
59 this.view_ = this.createView_(viewport); | 59 this.view_ = this.createView_(viewport); |
| 60 } |
60 return this.view_; | 61 return this.view_; |
61 }, | 62 }, |
62 | 63 |
63 createView_: function() { | 64 createView_: function() { |
64 throw new Error('Not implemented'); | 65 throw new Error('Not implemented'); |
65 } | 66 } |
66 }; | 67 }; |
67 | 68 |
68 var options = new tr.b.ExtensionRegistryOptions(tr.b. BASIC_REGISTRY_MODE); | 69 var options = new tr.b.ExtensionRegistryOptions(tr.b. BASIC_REGISTRY_MODE); |
69 tr.b.decorateExtensionRegistry(Annotation, options); | 70 tr.b.decorateExtensionRegistry(Annotation, options); |
70 | 71 |
71 Annotation.addEventListener('will-register', function(e) { | 72 Annotation.addEventListener('will-register', function(e) { |
72 if (!e.typeInfo.constructor.hasOwnProperty('fromDict')) | 73 if (!e.typeInfo.constructor.hasOwnProperty('fromDict')) { |
73 throw new Error('Must have fromDict method'); | 74 throw new Error('Must have fromDict method'); |
| 75 } |
74 | 76 |
75 if (!e.typeInfo.metadata.typeName) | 77 if (!e.typeInfo.metadata.typeName) { |
76 throw new Error('Registered Annotations must provide typeName'); | 78 throw new Error('Registered Annotations must provide typeName'); |
| 79 } |
77 }); | 80 }); |
78 | 81 |
79 return { | 82 return { |
80 Annotation, | 83 Annotation, |
81 }; | 84 }; |
82 }); | 85 }); |
83 </script> | 86 </script> |
OLD | NEW |