Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / trace_model / event.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/base/guid.html">
9
10 <script>
11 'use strict';
12
13 /**
14  * @fileoverview Provides the Event class.
15  */
16 tv.exportTo('tracing.trace_model', function() {
17
18   /**
19    * The SelectionState enum defines how Events are displayed in the view.
20    */
21   var SelectionState = {
22     NONE: 0,
23     SELECTED: 1,
24     HIGHLIGHTED: 2,
25     DIMMED: 3
26   };
27
28   // Cached values for getCategoryParts.
29   var categoryPartsFor = {};
30
31   /**
32    * Categories are stored in comma-separated form, e.g: 'a,b' meaning
33    * that the event is part of the a and b category.
34    *
35    * This function returns the category split by string, caching the
36    * array for performance.
37    *
38    * Do not mutate the returned array!!!!
39    */
40   function getCategoryParts(category) {
41     var parts = categoryPartsFor[category];
42     if (parts !== undefined)
43       return parts;
44     parts = category.split(',');
45     categoryPartsFor[category] = parts;
46     return parts;
47   }
48
49   /**
50    * An Event is the base type for any non-container, selectable piece
51    * of data in the trace model.
52    *
53    * @constructor
54    */
55   function Event() {
56     this.guid_ = tv.GUID.allocate();
57     this.selectionState = SelectionState.NONE;
58   }
59
60   Event.prototype = {
61     get guid() {
62       return this.guid_;
63     },
64
65     get selected() {
66       return this.selectionState === SelectionState.SELECTED;
67     }
68   };
69
70   Event.decorateSubtype = function(baseConstructor) {
71     if (baseConstructor.register !== undefined ||
72         baseConstructor.unregister !== undefined ||
73         baseConstructor.getConstructor !== undefined) {
74       throw new Error('Already decorated: ' + baseConstructor);
75     }
76
77     baseConstructor.categoryToConstructorMap_ = {};
78     baseConstructor.nameToConstructorMap_ = {};
79
80     baseConstructor.register = function(name, constructor) {
81       if (baseConstructor.nameToConstructorMap_[name])
82         throw new Error('Constructor already registered for ' + name);
83       baseConstructor.nameToConstructorMap_[name] = constructor;
84     };
85
86     baseConstructor.unregister = function(name) {
87       delete baseConstructor.nameToConstructorMap_[name];
88     };
89
90     baseConstructor.registerCategory = function(category, constructor) {
91       if (baseConstructor.categoryToConstructorMap_[category])
92         throw new Error('Constructor already registered for ' + category);
93       baseConstructor.categoryToConstructorMap_[category] = constructor;
94     };
95     baseConstructor.unregisterCategory = function(category, constructor) {
96       delete baseConstructor.categoryToConstructorMap_[category];
97     };
98
99     baseConstructor.getConstructor = function(category, name) {
100       var categoryParts = getCategoryParts(category);
101       for (var i = 0; i < categoryParts.length; i++) {
102         var categoryPart = categoryParts[i];
103         if (baseConstructor.categoryToConstructorMap_[categoryPart])
104           return baseConstructor.categoryToConstructorMap_[categoryPart];
105       }
106       if (baseConstructor.nameToConstructorMap_[name])
107         return baseConstructor.nameToConstructorMap_[name];
108       return baseConstructor;
109     };
110   };
111
112   return {
113     Event: Event,
114     SelectionState: SelectionState
115   };
116 });
117 </script>