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

Side by Side Diff: content/browser/resources/media/main/renderManager.js

Issue 18889006: Removed old media-internals page and rewrote it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
OLDNEW
(Empty)
1 var RenderManager = (function () {
2 "use strict";
3
4
5 function timer(millis) {
6 var lastTime = (new Date()).getTime();
7
8 // A function that if called will return true
9 // if |millis| time has passed. If so, it resets
10 // to be used again.
11 var toReturn = function () {
12 var curTime = (new Date()).getTime();
13 if (curTime - lastTime >= millis) {
14 lastTime = curTime;
15 return true;
16 }
17
18 return false;
19 };
20
21 // Forces the next call to the timer to succeeded.
22 toReturn.trigger = function () {
23 lastTime -= millis;
24 return toReturn;
25 };
26
27 // The timer is reset.
28 toReturn.postpone = function () {
29 lastTime = (new Date()).getTime();
30 return toReturn;
31 };
32
33 // The original time that the timer is set for.
34 toReturn.time = millis;
35
36 return toReturn;
37 }
38
39 // A painter is a class that has three methods:
40 // paintNew(playerInfo, div, properties)
41 // paintExist(playerInfo, div, properties)
42 // invalidate(playerInfo, properties)
43 // where |playerInfo| is a PlayerInfo instance, |div|
44 // is the div that is going to be rendered into, and
45 // |properties| is an object containing other properties
46 // that the painter might want.
47 function RenderManager(playerManager) {
48 // A model is an object that contains the following properties
49 this.models = {
50 log: {
51 // The name of the model (used for errors and such)
52 name: "log",
53 // The div that the model can modify anything inside of
54 div: document.querySelector("#log"),
55 // The element (if any) that could be hiding the |div|
56 collapse: document.querySelector("#log-wrapper>.collapse"),
57 // If the element needs to be completely rewritten from scratch
58 dirty: true,
59 // An object containing functions that
60 // write html to the inside of |div|
61 painter: logPainter,
62 // A timer for how often it should be redrawn
63 timer: timer(500).trigger()
64 },
65 graph: {
66 name: "graph",
67 div: document.querySelector("#graph"),
68 collapse: document.querySelector("#graph-wrapper>.collapse"),
69 dirty: true,
70 painter: graphPainter,
71 timer: timer(100).trigger()
72 },
73 prop: {
74 name: "prop",
75 div: document.querySelector("#properties"),
76 collapse: null,
77 dirty: true,
78 painter: propertyPainter,
79 timer: timer(200).trigger()
80 },
81 playerList: {
82 name: "player list",
83 div: document.querySelector("#stream"),
84 collapse: null,
85 dirty: true,
86 painter: playerListPainter,
87 timer: timer(1000).trigger()
88 }
89 };
90
91 // All the models that contain information about a Player.
92 // Non-standard models include the player-list and the system properties
93 this.standardModels = [this.models.log, this.models.graph,
94 this.models.prop];
95
96 // The id of the current player
97 this.cachedId = -1;
98 // The playerInfo instance of the current player
99 this.current = null;
100 // The playerManager that owns this class
101 this.playerManager = playerManager;
102
103 // The text being used to filter logs
104 this.filterText = "";
105
106 // If the user is scrolling through the log, don't update it.
107 this.models.log.div.parentNode.onscroll = function () {
108 this.models.log.timer.postpone();
109 }.bind(this);
110
111 // When <enter> is pressed inside the input, set |this.filterText|.
112 var filterField = document.querySelector("#filter-input");
113 filterField.onkeydown = function (event) {
114 // 13 is the keyCode for <enter>
115 if (event.keyCode === 13) {
116 this.filterText = filterField.value;
117 // We need to trigger a repaint immediately
118 this.models.log.dirty = true;
119 this.models.log.timer.trigger();
120 this.update();
121 }
122 }.bind(this);
123 }
124
125 // Checks to see if a collapsible div is open or not
126 function isOpen(div) {
127 // If there is no parent, we have to assume that
128 // this is viewable
129 if (!div) {
130 return true;
131 }
132
133 return div.className.indexOf("open") !== -1;
134 }
135
136 // Ran when a player is selected in the playerList
137 RenderManager.prototype.select = function (id) {
138 // If we are already viewing it, don't do anything
139 if (this.cachedId === id) {
140 return;
141 }
142 this.cachedId = id;
143 this.current = this.playerManager.players[id];
144
145 // All the models need to be reset and triggered so that they
146 // are redrawn completely and immediately;
147 goog.array.forEach(this.standardModels, function (m) {
148 m.dirty = true;
149 m.timer.trigger();
150 });
151 this.update();
152 };
153
154 // Ran whenever a property is updated
155 RenderManager.prototype.update = function () {
156 // To get passed into the painters
157 var extra = {filterText: this.filterText};
158
159 // If we are actually looking at something
160 if (this.current) {
161 goog.array.forEach(this.standardModels, function (model) {
162 if (model.timer() && isOpen(model.collapse)) {
163 if (model.dirty) {
164 console.warn("writing " + model.name
165 + " from scratch.");
166 model.painter.paintNew(this.current, model.div, extra);
167 model.dirty = false;
168 } else {
169 model.painter.paintExist(this.current,
170 model.div, extra);
171 }
172 }
173 }, this);
174 }
175 };
176
177 // Redraws the playerList
178 RenderManager.prototype.redrawList = function () {
179 var m = this.models.playerList;
180 var prop = {playerManager: this.playerManager};
181
182 m.painter.paintNew(null, m.div, prop);
183 };
184
185 return RenderManager;
186 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698