Commit 9c96421f authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

TaskManager: Added "inspect" on context-menu on the task list.

BUG=101718
TEST=manual


Review URL: http://codereview.chromium.org/8424008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107935 0039d316-1c4b-4281-b951-d872f2087c98
parent bb953fda
......@@ -3664,6 +3664,9 @@ are declared in build/common.gypi.
<message name="IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN" desc="Task manager JavaScript memory allocated column. Shows the amount of memory used by JavaScript within a process">
JavaScript memory
</message>
<message name="IDS_TASK_MANAGER_INSPECT" desc="Menu item initiating resource inspection">
Inspect
</message>
<message name="IDS_TASK_MANAGER_MEM_CELL_TEXT" desc="The value displayed in the memory usage cells.">
<ph name="NUM_KILOBYTES">$1<ex>5,000</ex></ph>K
</message>
......
......@@ -50,6 +50,15 @@ cr.define('cr.ui', function() {
}
},
/**
* The list of table.
*
* @type {cr.ui.list}
*/
get list() {
return this.list_;
},
/**
* The table column model.
*
......
......@@ -197,6 +197,7 @@ TaskManager.prototype = {
this.initTable_();
this.initColumnMenu_();
this.initTableMenu_();
this.table_.redraw();
},
......@@ -258,6 +259,29 @@ TaskManager.prototype = {
},
initTableMenu_: function () {
this.table_menu_commands_ = [];
this.tableContextMenu_ = this.document_.createElement('menu');
// Creates command element to receive event.
var command = this.document_.createElement('command');
command.id = 'tableContextMenu-inspect';
cr.ui.Command.decorate(command);
this.table_menu_commands_[command.id] = command;
this.commandsElement_.appendChild(command);
// Creates menuitem element.
var item = this.document_.createElement('menuitem');
item.command = command;
command.menuitem = item;
var localized_label = localStrings.getString('INSPECT');
item.textContent = (localized_label != "") ? localized_label : "Inspect";
this.tableContextMenu_.appendChild(item);
this.document_.body.appendChild(this.tableContextMenu_);
cr.ui.Menu.decorate(this.tableContextMenu_);
},
initTable_: function () {
if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) {
console.log('ERROR: some models are not defined.');
......@@ -274,6 +298,10 @@ TaskManager.prototype = {
// Expands height of row when a process has some tasks.
this.table_.autoExpands = true;
this.table_.list.addEventListener('contextmenu',
this.onTableContextMenuOpened_.bind(this),
true);
// Sets custom row render function.
this.table_.setRenderFunction(this.renderRow_.bind(this));
},
......@@ -295,6 +323,7 @@ TaskManager.prototype = {
listItem.appendChild(cell);
}
listItem.data = dataItem;
return listItem;
},
......@@ -316,6 +345,12 @@ TaskManager.prototype = {
text.className = 'detail-title-text';
text.textContent = entry['title'][i];
label.appendChild(text);
cr.ui.contextMenuHandler.addContextMenuProperty(label);
label.contextMenu = this.tableContextMenu_;
label.data = entry;
label.index_in_group = i;
} else {
label.textContent = entry[columnId][i];
}
......@@ -371,6 +406,12 @@ TaskManager.prototype = {
if (command.id.substr(0, 18) == 'columnContextMenu-') {
console.log(command.id.substr(18));
this.onColumnContextMenu_(command.id.substr(18), command);
} else if (command.id == 'tableContextMenu-inspect') {
var contextMenuTarget = this.currentContextMenuTarget_;
if (contextMenuTarget) {
this.inspect(contextMenuTarget);
this.currentContextMenuTarget_ = undefined;
}
}
},
......@@ -378,6 +419,38 @@ TaskManager.prototype = {
event.canExecute = true;
},
/**
* Store resourceIndex of target resource of context menu, because resource
* will be replaced when it is refleshed.
*/
onTableContextMenuOpened_: function (e) {
var command = this.table_menu_commands_['tableContextMenu-inspect'];
var menuItem = command.menuitem;
// Disabled by default.
menuItem.disabled = true;
this.currentContextMenuTarget_ = undefined;
var target = e.target;
var classes = target.className.split(" ");
while (target && classes.indexOf('detail-title') == -1) {
target = target.parentNode;
classes = target.className.split(" ");
}
if (!target)
return;
var index_in_group = target.index_in_group;
var canInspect = target.data['canInspect'][index_in_group];
if (canInspect) {
menuItem.disabled = false;
this.currentContextMenuTarget_ =
target.data['uniqueId'][index_in_group];
}
},
onColumnContextMenu_: function(id, command) {
var menuitem = command.menuitem;
var checked_item_count = 0;
......
......@@ -48,6 +48,7 @@ ChromeWebUIDataSource* CreateTaskManagerUIHTMLSource() {
SET_LOCALIZED_STRING(FPS_COLUMN);
SET_LOCALIZED_STRING(SQLITE_MEMORY_USED_COLUMN);
SET_LOCALIZED_STRING(JAVASCRIPT_MEMORY_ALLOCATED_COLUMN);
SET_LOCALIZED_STRING(INSPECT);
source->set_json_path("strings.js");
source->add_resource_path("main.js", IDR_TASK_MANAGER_JS);
source->add_resource_path("includes.js", IDR_TASK_MANAGER_INCLUDES_JS);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment