Chromium Code Reviews| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Sends command to enable taskmanager model. | 117 * Sends command to enable taskmanager model. |
| 118 * @public | 118 * @public |
| 119 */ | 119 */ |
| 120 enableTaskManager: function () { | 120 enableTaskManager: function () { |
| 121 chrome.send('enableTaskManager'); | 121 chrome.send('enableTaskManager'); |
| 122 }, | 122 }, |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * Sends command to activate a page. | |
| 126 * @public | |
| 127 */ | |
| 128 activatePage: function (uniqueId) { | |
| 129 chrome.send('activatePage', [uniqueId]); | |
| 130 }, | |
| 131 | |
| 132 /** | |
| 125 * Initializes taskmanager. | 133 * Initializes taskmanager. |
| 126 * @public | 134 * @public |
| 127 */ | 135 */ |
| 128 initialize: function (dialogDom, opt) { | 136 initialize: function (dialogDom, opt) { |
| 129 if (!dialogDom) { | 137 if (!dialogDom) { |
| 130 console.log('ERROR: dialogDom is not defined.'); | 138 console.log('ERROR: dialogDom is not defined.'); |
| 131 return; | 139 return; |
| 132 } | 140 } |
| 133 | 141 |
| 134 this.opt_ = opt; | 142 this.opt_ = opt; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 this.document_.addEventListener('command', this.onCommand_.bind(this)); | 264 this.document_.addEventListener('command', this.onCommand_.bind(this)); |
| 257 this.document_.addEventListener('canExecute', | 265 this.document_.addEventListener('canExecute', |
| 258 this.onCommandCanExecute_.bind(this)); | 266 this.onCommandCanExecute_.bind(this)); |
| 259 | 267 |
| 260 }, | 268 }, |
| 261 | 269 |
| 262 initTableMenu_: function () { | 270 initTableMenu_: function () { |
| 263 this.table_menu_commands_ = []; | 271 this.table_menu_commands_ = []; |
| 264 this.tableContextMenu_ = this.document_.createElement('menu'); | 272 this.tableContextMenu_ = this.document_.createElement('menu'); |
| 265 | 273 |
| 266 // Creates command element to receive event. | 274 var addMenuItem = function (tm, command_id, string_id, default_label) { |
| 267 var command = this.document_.createElement('command'); | 275 // Creates command element to receive event. |
| 268 command.id = 'tableContextMenu-inspect'; | 276 var command = tm.document_.createElement('command'); |
| 269 cr.ui.Command.decorate(command); | 277 command.id = 'tableContextMenu-' + command_id; |
| 270 this.table_menu_commands_[command.id] = command; | 278 cr.ui.Command.decorate(command); |
| 271 this.commandsElement_.appendChild(command); | 279 tm.table_menu_commands_[command.id] = command; |
| 280 tm.commandsElement_.appendChild(command); | |
| 272 | 281 |
| 273 // Creates menuitem element. | 282 // Creates menuitem element. |
| 274 var item = this.document_.createElement('menuitem'); | 283 var item = tm.document_.createElement('menuitem'); |
| 275 item.command = command; | 284 item.command = command; |
| 276 command.menuitem = item; | 285 command.menuitem = item; |
| 277 var localized_label = localStrings.getString('INSPECT'); | 286 var localized_label = localStrings.getString(string_id); |
| 278 item.textContent = (localized_label != "") ? localized_label : "Inspect"; | 287 item.textContent |
|
mazda
2011/11/09 07:16:14
item.textContent = localized_label || default_labe
yoshiki
2011/11/10 05:09:47
Done.
| |
| 279 this.tableContextMenu_.appendChild(item); | 288 = (localized_label != "") ? localized_label : default_label; |
| 289 tm.tableContextMenu_.appendChild(item); | |
| 290 }; | |
| 291 | |
| 292 addMenuItem(this, 'inspect', 'INSPECT', "Inspect"); | |
| 293 addMenuItem(this, 'activate', 'ACTIVATE', "Activate"); | |
| 280 | 294 |
| 281 this.document_.body.appendChild(this.tableContextMenu_); | 295 this.document_.body.appendChild(this.tableContextMenu_); |
| 282 cr.ui.Menu.decorate(this.tableContextMenu_); | 296 cr.ui.Menu.decorate(this.tableContextMenu_); |
| 283 }, | 297 }, |
| 284 | 298 |
| 285 initTable_: function () { | 299 initTable_: function () { |
| 286 if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) { | 300 if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) { |
| 287 console.log('ERROR: some models are not defined.'); | 301 console.log('ERROR: some models are not defined.'); |
| 288 return; | 302 return; |
| 289 } | 303 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 image.src = entry['icon'][i]; | 356 image.src = entry['icon'][i]; |
| 343 label.appendChild(image); | 357 label.appendChild(image); |
| 344 var text = this.document_.createElement('div'); | 358 var text = this.document_.createElement('div'); |
| 345 text.className = 'detail-title-text'; | 359 text.className = 'detail-title-text'; |
| 346 text.textContent = entry['title'][i]; | 360 text.textContent = entry['title'][i]; |
| 347 label.appendChild(text); | 361 label.appendChild(text); |
| 348 | 362 |
| 349 cr.ui.contextMenuHandler.addContextMenuProperty(label); | 363 cr.ui.contextMenuHandler.addContextMenuProperty(label); |
| 350 label.contextMenu = this.tableContextMenu_; | 364 label.contextMenu = this.tableContextMenu_; |
| 351 | 365 |
| 366 label.addEventListener('dblclick', (function(uniqueId) { | |
| 367 this.activatePage(uniqueId); | |
| 368 }).bind(this, entry['uniqueId'][i])); | |
| 369 | |
| 352 label.data = entry; | 370 label.data = entry; |
| 353 label.index_in_group = i; | 371 label.index_in_group = i; |
| 354 } else { | 372 } else { |
| 355 label.textContent = entry[columnId][i]; | 373 label.textContent = entry[columnId][i]; |
| 356 } | 374 } |
| 357 label.id = 'detail-' + columnId + '-pid' + entry.processId + '-' + i; | 375 label.id = 'detail-' + columnId + '-pid' + entry.processId + '-' + i; |
| 358 label.className = 'detail-' + columnId + ' pid' + entry.processId; | 376 label.className = 'detail-' + columnId + ' pid' + entry.processId; |
| 359 container.appendChild(label); | 377 container.appendChild(label); |
| 360 } | 378 } |
| 361 } | 379 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 }, | 417 }, |
| 400 | 418 |
| 401 /** | 419 /** |
| 402 * Respond to a command being executed. | 420 * Respond to a command being executed. |
| 403 */ | 421 */ |
| 404 onCommand_: function(event) { | 422 onCommand_: function(event) { |
| 405 var command = event.command; | 423 var command = event.command; |
| 406 if (command.id.substr(0, 18) == 'columnContextMenu-') { | 424 if (command.id.substr(0, 18) == 'columnContextMenu-') { |
| 407 console.log(command.id.substr(18)); | 425 console.log(command.id.substr(18)); |
| 408 this.onColumnContextMenu_(command.id.substr(18), command); | 426 this.onColumnContextMenu_(command.id.substr(18), command); |
| 409 } else if (command.id == 'tableContextMenu-inspect') { | 427 } else if (command.id.substr(0, 17) == 'tableContextMenu-') { |
|
mazda
2011/11/09 07:16:14
Please make a constant variable for 'tableContextM
yoshiki
2011/11/10 05:09:47
Done.
| |
| 410 var contextMenuTarget = this.currentContextMenuTarget_; | 428 var target_unique_id = this.currentContextMenuTarget_; |
| 411 if (contextMenuTarget) { | 429 var sub_command = command.id.substr(17); |
| 412 this.inspect(contextMenuTarget); | 430 |
| 431 if (target_unique_id) { | |
|
mazda
2011/11/09 07:16:14
if (!target_unique_id)
return;
if (sub_command
yoshiki
2011/11/10 05:09:47
Done.
| |
| 432 if (sub_command = 'inspect') | |
| 433 this.inspect(target_unique_id); | |
| 434 else if (sub_command == 'activate') | |
| 435 this.activate(target_unique_id); | |
| 436 | |
| 413 this.currentContextMenuTarget_ = undefined; | 437 this.currentContextMenuTarget_ = undefined; |
| 414 } | 438 } |
| 415 } | 439 } |
| 416 }, | 440 }, |
| 417 | 441 |
| 418 onCommandCanExecute_: function(event) { | 442 onCommandCanExecute_: function(event) { |
| 419 event.canExecute = true; | 443 event.canExecute = true; |
| 420 }, | 444 }, |
| 421 | 445 |
| 422 /** | 446 /** |
| 423 * Store resourceIndex of target resource of context menu, because resource | 447 * Store resourceIndex of target resource of context menu, because resource |
| 424 * will be replaced when it is refleshed. | 448 * will be replaced when it is refleshed. |
| 425 */ | 449 */ |
| 426 onTableContextMenuOpened_: function (e) { | 450 onTableContextMenuOpened_: function (e) { |
| 427 var command = this.table_menu_commands_['tableContextMenu-inspect']; | 451 var mc = this.table_menu_commands_; |
| 428 var menuItem = command.menuitem; | 452 var inspect_menuitem = mc['tableContextMenu-inspect'].menuitem; |
| 453 var activate_menuitem = mc['tableContextMenu-activate'].menuitem; | |
| 429 | 454 |
| 430 // Disabled by default. | 455 // Disabled by default. |
| 431 menuItem.disabled = true; | 456 inspect_menuitem.disabled = true; |
| 432 this.currentContextMenuTarget_ = undefined; | 457 activate_menuitem.disabled = true; |
| 433 | 458 |
| 434 var target = e.target; | 459 var target = e.target; |
| 435 var classes = target.classList; | 460 var classes = target.classList; |
| 436 while (target && | 461 while (target && |
| 437 Array.prototype.indexOf.call(classes, 'detail-title') == -1) { | 462 Array.prototype.indexOf.call(classes, 'detail-title') == -1) { |
| 438 target = target.parentNode; | 463 target = target.parentNode; |
| 439 classes = target.classList; | 464 classes = target.classList; |
| 440 } | 465 } |
| 441 | 466 |
| 442 if (!target) | 467 if (!target) |
| 443 return; | 468 return; |
| 444 | 469 |
| 470 // Sets the uniqueId for current target page under the mouse corsor. | |
| 471 this.currentContextMenuTarget_ = target.data['uniqueId'][index_in_group]; | |
| 472 | |
| 445 var index_in_group = target.index_in_group; | 473 var index_in_group = target.index_in_group; |
| 446 | 474 |
| 447 var canInspect = target.data['canInspect'][index_in_group]; | 475 // Enables if the page can be inspected. |
| 448 if (canInspect) { | 476 if (target.data['canInspect'][index_in_group]) |
| 449 menuItem.disabled = false; | 477 inspect_menuitem.disabled = false; |
| 450 this.currentContextMenuTarget_ = | 478 |
| 451 target.data['uniqueId'][index_in_group]; | 479 // Enables if the page can be activated. |
| 452 } | 480 if (target.data['canActivate'][index_in_group]) |
| 481 activate_menuitem.disabled = false; | |
| 453 }, | 482 }, |
| 454 | 483 |
| 455 onColumnContextMenu_: function(id, command) { | 484 onColumnContextMenu_: function(id, command) { |
| 456 var menuitem = command.menuitem; | 485 var menuitem = command.menuitem; |
| 457 var checked_item_count = 0; | 486 var checked_item_count = 0; |
| 458 var is_uncheck = 0; | 487 var is_uncheck = 0; |
| 459 | 488 |
| 460 // Leaves a item visible when user tries making invisible but it is the | 489 // Leaves a item visible when user tries making invisible but it is the |
| 461 // last one. | 490 // last one. |
| 462 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 491 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 taskmanager.onTaskChange(start, length, tasks); | 547 taskmanager.onTaskChange(start, length, tasks); |
| 519 } | 548 } |
| 520 | 549 |
| 521 function taskRemoved(start, length) { | 550 function taskRemoved(start, length) { |
| 522 // Sometimes this can get called too early. | 551 // Sometimes this can get called too early. |
| 523 if (!taskmanager) | 552 if (!taskmanager) |
| 524 return; | 553 return; |
| 525 taskmanager.onTaskRemove(start, length); | 554 taskmanager.onTaskRemove(start, length); |
| 526 } | 555 } |
| 527 | 556 |
| OLD | NEW |