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

Unified Diff: chrome/browser/resources/task_manager/main.js

Issue 8506003: WebUI TaskManager: Add "Activate page" feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix. Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/task_manager/task_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/task_manager/main.js
diff --git a/chrome/browser/resources/task_manager/main.js b/chrome/browser/resources/task_manager/main.js
index 49eb3b2bb3890014fb322c3e94ba741a4ef78a40..1a29c761b6ba2c92b1307881cedfea364712a339 100644
--- a/chrome/browser/resources/task_manager/main.js
+++ b/chrome/browser/resources/task_manager/main.js
@@ -29,6 +29,9 @@ var DEFAULT_COLUMNS = [
['v8MemoryAllocatedSize', 'JAVASCRIPT_MEMORY_ALLOCATED_COLUMN', 120, false],
];
+var COMMAND_CONTEXTMENU_COLUMN_PREFIX = 'columnContextMenu-';
+var COMMAND_CONTEXTMENU_TABLE_PREFIX = 'tableContextMenu-';
+
var localStrings = new LocalStrings();
TaskManager.prototype = {
@@ -123,6 +126,14 @@ TaskManager.prototype = {
},
/**
+ * Sends command to activate a page.
+ * @public
+ */
+ activatePage: function (uniqueId) {
+ chrome.send('activatePage', [uniqueId]);
+ },
+
+ /**
* Initializes taskmanager.
* @public
*/
@@ -233,7 +244,7 @@ TaskManager.prototype = {
// Creates command element to receive event.
var command = this.document_.createElement('command');
- command.id = 'columnContextMenu-' + column[0];
+ command.id = COMMAND_CONTEXTMENU_COLUMN_PREFIX + column[0];
cr.ui.Command.decorate(command);
this.column_menu_commands_[command.id] = command;
this.commandsElement_.appendChild(command);
@@ -264,20 +275,25 @@ TaskManager.prototype = {
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);
+ var addMenuItem = function (tm, command_id, string_id, default_label) {
+ // Creates command element to receive event.
+ var command = tm.document_.createElement('command');
+ command.id = COMMAND_CONTEXTMENU_TABLE_PREFIX + command_id;
+ cr.ui.Command.decorate(command);
+ tm.table_menu_commands_[command.id] = command;
+ tm.commandsElement_.appendChild(command);
+
+ // Creates menuitem element.
+ var item = tm.document_.createElement('menuitem');
+ item.command = command;
+ command.menuitem = item;
+ var localized_label = localStrings.getString(string_id);
+ item.textContent = localized_label || default_label;
+ tm.tableContextMenu_.appendChild(item);
+ };
+
+ addMenuItem(this, 'inspect', 'INSPECT', "Inspect");
+ addMenuItem(this, 'activate', 'ACTIVATE', "Activate");
this.document_.body.appendChild(this.tableContextMenu_);
cr.ui.Menu.decorate(this.tableContextMenu_);
@@ -350,6 +366,10 @@ TaskManager.prototype = {
cr.ui.contextMenuHandler.addContextMenuProperty(label);
label.contextMenu = this.tableContextMenu_;
+ label.addEventListener('dblclick', (function(uniqueId) {
+ this.activatePage(uniqueId);
+ }).bind(this, entry['uniqueId'][i]));
+
label.data = entry;
label.index_in_group = i;
} else {
@@ -404,15 +424,24 @@ TaskManager.prototype = {
*/
onCommand_: function(event) {
var command = event.command;
- if (command.id.substr(0, 18) == 'columnContextMenu-') {
+ if (command.id.substr(0, COMMAND_CONTEXTMENU_COLUMN_PREFIX.length)
+ == COMMAND_CONTEXTMENU_COLUMN_PREFIX) {
mazda 2011/11/10 05:32:26 I think it's more common to put operator at the en
yoshiki 2011/11/10 08:15:01 Stop substr()-based implement and change to 1 line
console.log(command.id.substr(18));
mazda 2011/11/10 05:32:26 18 -> COMMAND_CONTEXTMENU_COLUMN_PREFIX.length
yoshiki 2011/11/10 08:15:01 ditto On 2011/11/10 05:32:26, mazda wrote:
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;
- }
+ } else if (command.id.substr(0, COMMAND_CONTEXTMENU_TABLE_PREFIX.length)
+ == COMMAND_CONTEXTMENU_TABLE_PREFIX) {
mazda 2011/11/10 05:32:26 Operator position.
yoshiki 2011/11/10 08:15:01 ditto On 2011/11/10 05:32:26, mazda wrote:
+ var target_unique_id = this.currentContextMenuTarget_;
+ var sub_command = command.id.substr(17);
mazda 2011/11/10 05:32:26 17 -> COMMAND_CONTEXTMENU_TABLE_PREFIX.length
yoshiki 2011/11/10 08:15:01 ditto On 2011/11/10 05:32:26, mazda wrote:
+
+ if (!target_unique_id)
+ return;
+
+ if (sub_command == 'inspect')
+ this.inspect(target_unique_id);
+ else if (sub_command == 'activate')
+ this.activatePage(target_unique_id);
+
+ this.currentContextMenuTarget_ = undefined;
}
},
@@ -425,12 +454,15 @@ TaskManager.prototype = {
* will be replaced when it is refleshed.
*/
onTableContextMenuOpened_: function (e) {
- var command = this.table_menu_commands_['tableContextMenu-inspect'];
- var menuItem = command.menuitem;
+ var mc = this.table_menu_commands_;
+ var inspect_menuitem
+ = mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + 'inspect'].menuitem;
mazda 2011/11/10 05:32:26 Operator position.
yoshiki 2011/11/10 08:15:01 Done.
+ var activate_menuitem
+ = mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + 'activate'].menuitem;
mazda 2011/11/10 05:32:26 Operator position.
yoshiki 2011/11/10 08:15:01 Done.
// Disabled by default.
- menuItem.disabled = true;
- this.currentContextMenuTarget_ = undefined;
+ inspect_menuitem.disabled = true;
+ activate_menuitem.disabled = true;
var target = e.target;
var classes = target.classList;
@@ -445,12 +477,16 @@ TaskManager.prototype = {
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];
- }
+ // Sets the uniqueId for current target page under the mouse corsor.
+ this.currentContextMenuTarget_ = target.data['uniqueId'][index_in_group];
+
+ // Enables if the page can be inspected.
+ if (target.data['canInspect'][index_in_group])
+ inspect_menuitem.disabled = false;
+
+ // Enables if the page can be activated.
+ if (target.data['canActivate'][index_in_group])
+ activate_menuitem.disabled = false;
},
onColumnContextMenu_: function(id, command) {
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/task_manager/task_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698