OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @constructor */ | 5 /** @constructor */ |
6 function TaskManager() { } | 6 function TaskManager() { } |
7 | 7 |
8 cr.addSingletonGetter(TaskManager); | 8 cr.addSingletonGetter(TaskManager); |
9 | 9 |
10 /* | 10 /* |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 | 190 |
191 var ary = this.dialogDom_.querySelectorAll('[visibleif]'); | 191 var ary = this.dialogDom_.querySelectorAll('[visibleif]'); |
192 for (var i = 0; i < ary.length; i++) { | 192 for (var i = 0; i < ary.length; i++) { |
193 var expr = ary[i].getAttribute('visibleif'); | 193 var expr = ary[i].getAttribute('visibleif'); |
194 if (!eval(expr)) | 194 if (!eval(expr)) |
195 ary[i].hidden = true; | 195 ary[i].hidden = true; |
196 } | 196 } |
197 | 197 |
198 this.initTable_(); | 198 this.initTable_(); |
199 this.initColumnMenu_(); | 199 this.initColumnMenu_(); |
200 this.initTableMenu_(); | |
200 this.table_.redraw(); | 201 this.table_.redraw(); |
201 }, | 202 }, |
202 | 203 |
203 initColumnModel_: function () { | 204 initColumnModel_: function () { |
204 var table_columns = new Array(); | 205 var table_columns = new Array(); |
205 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 206 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { |
206 if (!this.is_column_shown_[i]) | 207 if (!this.is_column_shown_[i]) |
207 continue; | 208 continue; |
208 | 209 |
209 var column = DEFAULT_COLUMNS[i]; | 210 var column = DEFAULT_COLUMNS[i]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 | 252 |
252 cr.ui.contextMenuHandler.addContextMenuProperty(this.table_.header); | 253 cr.ui.contextMenuHandler.addContextMenuProperty(this.table_.header); |
253 this.table_.header.contextMenu = this.columnSelectContextMenu_; | 254 this.table_.header.contextMenu = this.columnSelectContextMenu_; |
254 | 255 |
255 this.document_.addEventListener('command', this.onCommand_.bind(this)); | 256 this.document_.addEventListener('command', this.onCommand_.bind(this)); |
256 this.document_.addEventListener('canExecute', | 257 this.document_.addEventListener('canExecute', |
257 this.onCommandCanExecute_.bind(this)); | 258 this.onCommandCanExecute_.bind(this)); |
258 | 259 |
259 }, | 260 }, |
260 | 261 |
262 initTableMenu_: function () { | |
263 this.table_menu_commands_ = []; | |
264 this.tableContextMenu_ = this.document_.createElement('menu'); | |
265 | |
266 // Creates command element to receive event. | |
267 var command = this.document_.createElement('command'); | |
268 command.id = 'tableContextMenu-inspect'; | |
269 cr.ui.Command.decorate(command); | |
270 this.table_menu_commands_[command.id] = command; | |
271 this.commandsElement_.appendChild(command); | |
272 | |
273 // Creates menuitem element. | |
274 var item = this.document_.createElement('menuitem'); | |
275 item.command = command; | |
276 command.menuitem = item; | |
277 var localized_label = localStrings.getString('INSPECT'); | |
278 item.textContent = (localized_label != "") ? localized_label : "Inspect"; | |
279 this.tableContextMenu_.appendChild(item); | |
280 | |
281 this.document_.body.appendChild(this.tableContextMenu_); | |
282 cr.ui.Menu.decorate(this.tableContextMenu_); | |
283 }, | |
284 | |
261 initTable_: function () { | 285 initTable_: function () { |
262 if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) { | 286 if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) { |
263 console.log('ERROR: some models are not defined.'); | 287 console.log('ERROR: some models are not defined.'); |
264 return; | 288 return; |
265 } | 289 } |
266 | 290 |
267 this.table_ = this.dialogDom_.querySelector('.detail-table'); | 291 this.table_ = this.dialogDom_.querySelector('.detail-table'); |
268 cr.ui.Table.decorate(this.table_); | 292 cr.ui.Table.decorate(this.table_); |
269 | 293 |
270 this.table_.dataModel = this.dataModel_; | 294 this.table_.dataModel = this.dataModel_; |
271 this.table_.selectionModel = this.selectionModel_; | 295 this.table_.selectionModel = this.selectionModel_; |
272 this.table_.columnModel = this.columnModel_; | 296 this.table_.columnModel = this.columnModel_; |
273 | 297 |
274 // Expands height of row when a process has some tasks. | 298 // Expands height of row when a process has some tasks. |
275 this.table_.autoExpands = true; | 299 this.table_.autoExpands = true; |
276 | 300 |
301 this.table_.list.addEventListener('contextmenu', | |
302 this.onTableContextMenuOpened_.bind(this), | |
303 true); | |
304 | |
277 // Sets custom row render function. | 305 // Sets custom row render function. |
278 this.table_.setRenderFunction(this.renderRow_.bind(this)); | 306 this.table_.setRenderFunction(this.renderRow_.bind(this)); |
279 }, | 307 }, |
280 | 308 |
281 renderRow_: function(dataItem, table) { | 309 renderRow_: function(dataItem, table) { |
282 var cm = table.columnModel; | 310 var cm = table.columnModel; |
283 var listItem = new cr.ui.ListItem({label: ''}); | 311 var listItem = new cr.ui.ListItem({label: ''}); |
284 | 312 |
285 listItem.className = 'table-row'; | 313 listItem.className = 'table-row'; |
286 if (this.opt_.isBackgroundMode && dataItem.isBackgroundResource) | 314 if (this.opt_.isBackgroundMode && dataItem.isBackgroundResource) |
287 listItem.className += ' table-background-row'; | 315 listItem.className += ' table-background-row'; |
288 | 316 |
289 for (var i = 0; i < cm.size; i++) { | 317 for (var i = 0; i < cm.size; i++) { |
290 var cell = document.createElement('div'); | 318 var cell = document.createElement('div'); |
291 cell.style.width = cm.getWidth(i) + '%'; | 319 cell.style.width = cm.getWidth(i) + '%'; |
292 cell.className = 'table-row-cell'; | 320 cell.className = 'table-row-cell'; |
293 cell.appendChild( | 321 cell.appendChild( |
294 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table)); | 322 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table)); |
295 | 323 |
296 listItem.appendChild(cell); | 324 listItem.appendChild(cell); |
297 } | 325 } |
326 listItem.data = dataItem; | |
298 | 327 |
299 return listItem; | 328 return listItem; |
300 }, | 329 }, |
301 | 330 |
302 renderColumn_: function(entry, columnId, table) { | 331 renderColumn_: function(entry, columnId, table) { |
303 var container = this.document_.createElement('div'); | 332 var container = this.document_.createElement('div'); |
304 container.id = 'detail-container-' + columnId + '-pid' + entry.processId; | 333 container.id = 'detail-container-' + columnId + '-pid' + entry.processId; |
305 container.className = 'detail-container-' + columnId; | 334 container.className = 'detail-container-' + columnId; |
306 | 335 |
307 if (entry[columnId]) { | 336 if (entry[columnId]) { |
308 for (var i = 0; i < entry[columnId].length; i++) { | 337 for (var i = 0; i < entry[columnId].length; i++) { |
309 var label = document.createElement('div'); | 338 var label = document.createElement('div'); |
310 if (columnId == 'title') { | 339 if (columnId == 'title') { |
311 var image = this.document_.createElement('img'); | 340 var image = this.document_.createElement('img'); |
312 image.className = 'detail-title-image'; | 341 image.className = 'detail-title-image'; |
313 image.src = entry['icon'][i]; | 342 image.src = entry['icon'][i]; |
314 label.appendChild(image); | 343 label.appendChild(image); |
315 var text = this.document_.createElement('div'); | 344 var text = this.document_.createElement('div'); |
316 text.className = 'detail-title-text'; | 345 text.className = 'detail-title-text'; |
317 text.textContent = entry['title'][i]; | 346 text.textContent = entry['title'][i]; |
318 label.appendChild(text); | 347 label.appendChild(text); |
348 | |
349 cr.ui.contextMenuHandler.addContextMenuProperty(label); | |
350 label.contextMenu = this.tableContextMenu_; | |
351 | |
352 label.data = entry; | |
353 label.index_in_group = i; | |
319 } else { | 354 } else { |
320 label.textContent = entry[columnId][i]; | 355 label.textContent = entry[columnId][i]; |
321 } | 356 } |
322 label.id = 'detail-' + columnId + '-pid' + entry.processId + '-' + i; | 357 label.id = 'detail-' + columnId + '-pid' + entry.processId + '-' + i; |
323 label.className = 'detail-' + columnId + ' pid' + entry.processId; | 358 label.className = 'detail-' + columnId + ' pid' + entry.processId; |
324 container.appendChild(label); | 359 container.appendChild(label); |
325 } | 360 } |
326 } | 361 } |
327 return container; | 362 return container; |
328 }, | 363 }, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 }, | 399 }, |
365 | 400 |
366 /** | 401 /** |
367 * Respond to a command being executed. | 402 * Respond to a command being executed. |
368 */ | 403 */ |
369 onCommand_: function(event) { | 404 onCommand_: function(event) { |
370 var command = event.command; | 405 var command = event.command; |
371 if (command.id.substr(0, 18) == 'columnContextMenu-') { | 406 if (command.id.substr(0, 18) == 'columnContextMenu-') { |
372 console.log(command.id.substr(18)); | 407 console.log(command.id.substr(18)); |
373 this.onColumnContextMenu_(command.id.substr(18), command); | 408 this.onColumnContextMenu_(command.id.substr(18), command); |
409 } else if (command.id == 'tableContextMenu-inspect') { | |
410 var contextMenuTarget = this.currentContextMenuTarget_; | |
411 if (contextMenuTarget) { | |
412 this.inspect(contextMenuTarget); | |
413 this.currentContextMenuTarget_ = undefined; | |
414 } | |
374 } | 415 } |
375 }, | 416 }, |
376 | 417 |
377 onCommandCanExecute_: function(event) { | 418 onCommandCanExecute_: function(event) { |
378 event.canExecute = true; | 419 event.canExecute = true; |
379 }, | 420 }, |
380 | 421 |
422 /** | |
423 * Store resourceIndex of target resource of context menu, because resource | |
424 * will be replaced when it is refleshed. | |
425 */ | |
426 onTableContextMenuOpened_: function (e) { | |
427 var command = this.table_menu_commands_['tableContextMenu-inspect']; | |
428 var menuItem = command.menuitem; | |
429 | |
430 // Disabled by default. | |
431 menuItem.disabled = true; | |
432 this.currentContextMenuTarget_ = undefined; | |
433 | |
434 var target = e.target; | |
435 var classes = target.className.split(" "); | |
pfeldman1
2011/10/31 08:17:41
var classes = target.classList; (new HTML5 feature
| |
436 while (target && classes.indexOf('detail-title') == -1) { | |
437 target = target.parentNode; | |
438 classes = target.className.split(" "); | |
439 } | |
440 | |
441 if (!target) | |
442 return; | |
443 | |
444 var index_in_group = target.index_in_group; | |
445 | |
446 var canInspect = target.data['canInspect'][index_in_group]; | |
447 if (canInspect) { | |
448 menuItem.disabled = false; | |
449 this.currentContextMenuTarget_ = | |
450 target.data['uniqueId'][index_in_group]; | |
451 } | |
452 }, | |
453 | |
381 onColumnContextMenu_: function(id, command) { | 454 onColumnContextMenu_: function(id, command) { |
382 var menuitem = command.menuitem; | 455 var menuitem = command.menuitem; |
383 var checked_item_count = 0; | 456 var checked_item_count = 0; |
384 var is_uncheck = 0; | 457 var is_uncheck = 0; |
385 | 458 |
386 // Leaves a item visible when user tries making invisible but it is the | 459 // Leaves a item visible when user tries making invisible but it is the |
387 // last one. | 460 // last one. |
388 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 461 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { |
389 var column = DEFAULT_COLUMNS[i]; | 462 var column = DEFAULT_COLUMNS[i]; |
390 if (column[0] == id && this.is_column_shown_[i]) { | 463 if (column[0] == id && this.is_column_shown_[i]) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 taskmanager.onTaskChange(start, length, tasks); | 517 taskmanager.onTaskChange(start, length, tasks); |
445 } | 518 } |
446 | 519 |
447 function taskRemoved(start, length) { | 520 function taskRemoved(start, length) { |
448 // Sometimes this can get called too early. | 521 // Sometimes this can get called too early. |
449 if (!taskmanager) | 522 if (!taskmanager) |
450 return; | 523 return; |
451 taskmanager.onTaskRemove(start, length); | 524 taskmanager.onTaskRemove(start, length); |
452 } | 525 } |
453 | 526 |
OLD | NEW |